--- /dev/null
+#ifndef EVENTS_H_
+#define EVENTS_H_
+
+#include <msp/game/handle.h>
+
+class Collider;
+
+namespace Events {
+
+struct Collision
+{
+ Msp::Game::Handle<Collider> collider1;
+ Msp::Game::Handle<Collider> collider2;
+};
+
+} // namespace Events
+
+#endif
Physics::Physics(Game::Stage &s):
System(s),
+ event_source(stage.get_event_bus()),
observer(stage.get_event_bus())
{
observer.observe<Game::Events::EntityCreated>([this](auto &e){ entity_added(e); });
copy_out<true>(entities[i]);
for(unsigned i=fixture_count; i<entities.size(); ++i)
copy_out<false>(entities[i]);
+
+ for(const Collision &c: collisions)
+ event_source.emit<Events::Collision>(entities[c.body1].entity->get_collider(), entities[c.body2].entity->get_collider());
}
template<bool is_fixture>
#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
{
Msp::LinAl::Vector<float, 2> normal;
};
+ EventSource event_source;
Msp::Game::EventObserver observer;
std::vector<SimulatedEntity> entities;
unsigned fixture_count = 0;