From 9c2e78cecaa61b6dab1d9d912a534545b92e9886 Mon Sep 17 00:00:00 2001 From: Sara Date: Tue, 19 Mar 2024 14:14:29 +0100 Subject: [PATCH] feat: projectile can now return itself --- src/projectile.cpp | 14 +++++++++++++- src/projectile.hpp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/projectile.cpp b/src/projectile.cpp index 19d92e1..4643cbe 100644 --- a/src/projectile.cpp +++ b/src/projectile.cpp @@ -1,4 +1,16 @@ #include "projectile.hpp" +#include "projectile_pool.hpp" #include -namespace godot {} +namespace godot { +void IProjectile::return_to_pool() { + if(!this->pool) + return; + Node3D *node = dynamic_cast(this); + if(node) + this->pool->return_projectile(node); +} +void IProjectile::set_projectile_pool(ProjectilePool *pool) { + this->pool = pool; +} +} diff --git a/src/projectile.hpp b/src/projectile.hpp index 0f72db9..0a97670 100644 --- a/src/projectile.hpp +++ b/src/projectile.hpp @@ -10,6 +10,7 @@ class IProjectile { public: virtual void set_weapon_data(Ref data) = 0; void return_to_pool(); + void set_projectile_pool(ProjectilePool *pool); private: ProjectilePool *pool{nullptr}; };