]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/physics.h
Remove destroyed entities from the physics simulation
[libs/game.git] / examples / bassteroids / source / physics.h
index 096e228095fdc94b131ca4796d505bc8e6cb63ad..1e7bec3e95cb3e2b0f8d6923a5b1816597d28cd0 100644 (file)
@@ -2,16 +2,21 @@
 #define PHYSICS_H_
 
 #include <msp/game/eventobserver.h>
+#include <msp/game/eventsource.h>
 #include <msp/game/events.h>
 #include <msp/game/handle.h>
 #include <msp/game/system.h>
 #include <msp/geometry/angle.h>
 #include <msp/linal/vector.h>
+#include "events.h"
 
 class PhysicalEntity;
 
 class Physics: public Msp::Game::System
 {
+public:
+       using EventSource = Msp::Game::EventSource<Events::Collision>;
+
 private:
        struct SimulatedEntity
        {
@@ -39,6 +44,7 @@ private:
                Msp::LinAl::Vector<float, 2> normal;
        };
 
+       EventSource event_source;
        Msp::Game::EventObserver observer;
        std::vector<SimulatedEntity> entities;
        unsigned fixture_count = 0;
@@ -49,6 +55,7 @@ public:
 
 private:
        void entity_added(const Msp::Game::Events::EntityCreated &);
+       void entity_removed(const Msp::Game::Events::EntityDestroyed &);
 
 public:
        void tick(Msp::Time::TimeDelta) override;