feat: claim projectile will now resize before projectiles run out
This commit is contained in:
parent
46ba8efaad
commit
9099d29672
|
@ -31,15 +31,19 @@ void ProjectilePool::set_data(Ref<PackedScene> data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Node3D *ProjectilePool::claim_projectile() {
|
Node3D *ProjectilePool::claim_projectile() {
|
||||||
|
Node3D *node{this->inactive[0]};
|
||||||
|
this->add_child(node);
|
||||||
|
this->inactive.erase(node);
|
||||||
|
this->active.push_back(node);
|
||||||
if(inactive.is_empty()) {
|
if(inactive.is_empty()) {
|
||||||
size_t const new_count = this->count + this->data->get_projectile_count() * this->data->get_rounds_per_second() * 2;
|
size_t const new_count = this->count + this->data->get_projectile_count() * this->data->get_rounds_per_second() * 2;
|
||||||
for(size_t i{this->count}; i < new_count; ++i)
|
for(size_t i{this->count}; i < new_count; ++i)
|
||||||
this->inactive.push_back(this->instantiate_new());
|
this->inactive.push_back(this->instantiate_new());
|
||||||
|
this->count = new_count;
|
||||||
}
|
}
|
||||||
Node3D *const ret{this->inactive[0]};
|
if(node == nullptr)
|
||||||
this->inactive.remove_at(0);
|
UtilityFunctions::push_error("Failed to spawn node");
|
||||||
this->active.push_back(ret);
|
return node;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectilePool::return_projectile(Node3D *node) {
|
void ProjectilePool::return_projectile(Node3D *node) {
|
||||||
|
|
Loading…
Reference in a new issue