Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
Particle.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#include "Particle.hpp"
4
6
8 particles_.resize(capacity);
9 free_list_.reserve(capacity);
10 for (u32 i = capacity; i > 0; --i) {
11 free_list_.push_back(i - 1);
12 }
13}
14
16 if (free_list_.empty()) {
17 return nullptr;
18 }
19 u32 index = free_list_.back();
20 free_list_.pop_back();
21 particles_[index] = Particle{};
22 particles_[index].alive = true;
23 if (++next_generation_ == 0) ++next_generation_;
24 particles_[index].generation = next_generation_;
25 alive_count_++;
26 return &particles_[index];
27}
28
30 if (!particle || !particle->alive) {
31 return;
32 }
33 u32 index = static_cast<u32>(particle - particles_.data());
34 particle->alive = false;
35 free_list_.push_back(index);
36 alive_count_--;
37}
38
40 for (auto& p : particles_) {
41 p.alive = false;
42 }
43 free_list_.clear();
44 for (u32 i = capacity_; i > 0; --i) {
45 free_list_.push_back(i - 1);
46 }
47 alive_count_ = 0;
48}
49
51 if (index >= particles_.size() || !particles_[index].alive) {
52 return;
53 }
54 particles_[index].alive = false;
55 free_list_.push_back(index);
56 alive_count_--;
57}
58
59} // namespace esengine::particle
void deallocate(Particle *particle)
Definition Particle.cpp:29
void deallocateByIndex(u32 index)
Deallocate a particle by its pool index.
Definition Particle.cpp:50
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45