Can just use the enum as the type for the map but it'd be nicer if I could use a class enum without tons of template BS.

main
Zed A. Shaw 2 weeks ago
parent 3f87d19911
commit da8011cb14
  1. 2
      dinkyecs.hpp
  2. 22
      tests/dinkyecs.cpp

@ -98,7 +98,7 @@ namespace DinkyECS {
}
template<typename Comp>
void send(int event, Entity entity) {
void send(Comp event, Entity entity) {
EventQueue &queue = queue_map_for<Comp>();
queue.push({event, entity});
}

@ -121,29 +121,29 @@ TEST_CASE("confirm ECS system works", "[ecs]") {
});
}
enum FakeEvent {
HIT_EVENT, MISS_EVENT
enum GUIEvent {
HIT, MISS
};
TEST_CASE("confirm that the event system works", "[ecs]") {
DinkyECS::World world;
DinkyECS::Entity gui_ent = world.entity();
DinkyECS::Entity player = world.entity();
DaGUI gui{384};
GUIEvent gui{GUIEvent::HIT};
world.set<DaGUI>(gui_ent, gui);
DaGUI &gui_test = world.get<DaGUI>(gui_ent);
REQUIRE(gui.event == gui_test.event);
world.set<GUIEvent>(gui_ent, gui);
auto &gui_test = world.get<GUIEvent>(gui_ent);
REQUIRE(gui == gui_test);
world.send<DaGUI>(FakeEvent::HIT_EVENT, player);
world.send<GUIEvent>(GUIEvent::HIT, player);
bool ready = world.has_event<DaGUI>();
bool ready = world.has_event<GUIEvent>();
REQUIRE(ready == true);
auto [event, entity] = world.recv<DaGUI>();
REQUIRE(event == FakeEvent::HIT_EVENT);
auto [event, entity] = world.recv<GUIEvent>();
REQUIRE(event == GUIEvent::HIT);
REQUIRE(entity == player);
ready = world.has_event<DaGUI>();
ready = world.has_event<GUIEvent>();
REQUIRE(ready == false);
}

Loading…
Cancel
Save