From cc4ab57ca793d163cdb58a51a82e36bf8ccf139e Mon Sep 17 00:00:00 2001 From: KosmX <kosmx.mc@gmail.com> Date: Wed, 12 May 2021 11:50:02 +0200 Subject: [PATCH] use modern functional instead of c style function pointer --- MeleeWeapon.cpp | 3 ++- MeleeWeapon.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MeleeWeapon.cpp b/MeleeWeapon.cpp index de3f819..12e6585 100644 --- a/MeleeWeapon.cpp +++ b/MeleeWeapon.cpp @@ -10,7 +10,7 @@ namespace weapons { { return victim->damage(this->getDamage(), *victim); } - bool MeleeWeapon::damageIf(std::shared_ptr<LivingEntity>& user, bool(*predicate)(std::shared_ptr<Entity> self, std::shared_ptr<Entity> other)) + bool MeleeWeapon::damageIf(std::shared_ptr<LivingEntity>& user, std::function<bool(std::shared_ptr<Entity>, std::shared_ptr<Entity>)> predicate) { bool bl = false; for(auto& entity : GameClient::getInstance().getEntities()){ @@ -28,6 +28,7 @@ namespace weapons { { if (this->cooldown != 0) return false; this->cooldown = this->cooldownTime; + damageIf() } void MeleeWeapon::setPos(const olc::vf2d& newPos) { diff --git a/MeleeWeapon.h b/MeleeWeapon.h index e106c09..db48151 100644 --- a/MeleeWeapon.h +++ b/MeleeWeapon.h @@ -9,7 +9,7 @@ namespace weapons { protected: virtual int getDamage() const; virtual bool damageEntity(std::shared_ptr<LivingEntity> user, std::shared_ptr<Entity>& victim); - virtual bool damageIf(std::shared_ptr<LivingEntity>& user, bool(*predicate)(std::shared_ptr<Entity> self, std::shared_ptr<Entity> other)); + virtual bool damageIf(std::shared_ptr<LivingEntity>& user, std::function<bool(std::shared_ptr<Entity> self, std::shared_ptr<Entity> other)> predicate); //virtual bool(*getPredicator())(std::shared_ptr<Entity>, std::shared_ptr<Entity>) = 0; virtual std::function<bool(std::shared_ptr<Entity>, std::shared_ptr<Entity>)> getPredicator() = 0; -- GitLab