From 5bedd85584c6252f411655e6320b78feed35414c Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sat, 4 Jul 2020 16:42:11 -0500 Subject: [PATCH] Make Entity::Update call UpdateComponents by default instead of an event --- examples/snake/src/main.cpp | 4 ---- include/simpleengine/entity.h | 8 ++++---- include/simpleengine/events/entity_event.h | 9 +++------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/examples/snake/src/main.cpp b/examples/snake/src/main.cpp index 2031ac5..a923524 100644 --- a/examples/snake/src/main.cpp +++ b/examples/snake/src/main.cpp @@ -84,10 +84,6 @@ public: shape.move(offset); } - void Update(const float& delta_time) override { - - } - void Render(sf::RenderTarget* target) override { target->draw(shape); } diff --git a/include/simpleengine/entity.h b/include/simpleengine/entity.h index 25bcb16..89e0501 100644 --- a/include/simpleengine/entity.h +++ b/include/simpleengine/entity.h @@ -28,19 +28,19 @@ namespace simpleengine { virtual void Move(const float& delta_time, const float& dir_x, const float& dir_y) {}; virtual void Move(const float& delta_time, const sf::Vector2f& offset) {}; virtual void Move(const sf::Vector2f& offset) {}; - virtual void Update(const float& delta_time) = 0; + virtual void Render(sf::RenderTarget* target) = 0; + virtual void Update(const float& delta_time) { + UpdateComponents(delta_time); + }; // Called when the entity is about to be destroyed. // Make sure to call this in your extending Entity. virtual void Destroying(); - void DestroyLater(); // In most cases, this will be ran next EntityEvent::Update() const bool& IsGettingDestroyed() const; - // If your event does not extend from EntityEvent, you will need to execute this yourself inside Event::Update. void UpdateComponents(const float& delta_time); - void AddComponent(std::unique_ptr component); std::shared_ptr GetShared() { diff --git a/include/simpleengine/events/entity_event.h b/include/simpleengine/events/entity_event.h index 95f00e3..273286d 100644 --- a/include/simpleengine/events/entity_event.h +++ b/include/simpleengine/events/entity_event.h @@ -18,16 +18,13 @@ namespace simpleengine { } void CheckForQuit() override { - + if (entity->IsGettingDestroyed()) { + quit = true; + } } void Update(const float& delta_time) override { entity->Update(delta_time); - entity->UpdateComponents(delta_time); - - if (entity->IsGettingDestroyed()) { - quit = true; - } } void Render(sf::RenderTarget* target) override {