feat: claim projectile will now resize before projectiles run out

This commit is contained in:
Sara 2024-03-20 09:47:51 +01:00
parent 46ba8efaad
commit 9099d29672

View file

@ -31,15 +31,19 @@ void ProjectilePool::set_data(Ref<PackedScene> data) {
}
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()) {
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)
this->inactive.push_back(this->instantiate_new());
this->count = new_count;
}
Node3D *const ret{this->inactive[0]};
this->inactive.remove_at(0);
this->active.push_back(ret);
return ret;
if(node == nullptr)
UtilityFunctions::push_error("Failed to spawn node");
return node;
}
void ProjectilePool::return_projectile(Node3D *node) {