Revert "Disable EventHook system for now for testing."
continuous-integration/drone/push Build is passing Details

This reverts commit 84e03021
This commit is contained in:
Deukhoofd 2020-08-03 17:28:43 +02:00
parent 84e030213d
commit 93b3847b31
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 40 additions and 43 deletions

View File

@ -24,24 +24,21 @@ namespace CreatureLib::Battling {
public: public:
EventHook() : _offset(0), _capacity(defaultSize) { EventHook() : _offset(0), _capacity(defaultSize) {
// auto ptr = calloc(defaultSize, 1); auto ptr = calloc(defaultSize, 1);
// if (ptr == nullptr) { if (ptr == nullptr) {
// THROW_CREATURE("Out of memory."); THROW_CREATURE("Out of memory.");
// } }
// _memory = static_cast<uint8_t*>(ptr); _memory = static_cast<uint8_t*>(ptr);
} }
EventHook(const EventHook&) = delete; EventHook(const EventHook&) = delete;
EventHook& operator=(const EventHook&) = delete; EventHook& operator=(const EventHook&) = delete;
~EventHook() { ~EventHook() { free(_memory); }
// free(_memory);
}
size_t GetPosition() const noexcept { return _offset; } size_t GetPosition() const noexcept { return _offset; }
size_t GetCapacity() const noexcept { return _capacity; } size_t GetCapacity() const noexcept { return _capacity; }
template <class T, class... parameters> void Trigger(parameters... args) { template <class T, class... parameters> void Trigger(parameters... args) {
return;
if (_listeners.size() == 0) if (_listeners.size() == 0)
return; return;
if (_offset + sizeof(T) >= _capacity) { if (_offset + sizeof(T) >= _capacity) {

View File

@ -6,38 +6,38 @@
using namespace CreatureLib::Battling; using namespace CreatureLib::Battling;
// TEST_CASE("Build and use event hook", "[Battling]") { TEST_CASE("Build and use event hook", "[Battling]") {
// auto eventHook = EventHook(); auto eventHook = EventHook();
// std::vector<const EventData*> events; std::vector<const EventData*> events;
// eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); }); eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
// for (size_t i = 0; i < 10; i++) { for (size_t i = 0; i < 10; i++) {
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
// } }
// REQUIRE(events.size() == 10); REQUIRE(events.size() == 10);
// REQUIRE(events[0]->GetKind() == EventDataKind::Damage); REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
//} }
//
// TEST_CASE("Build and use event hook a lot", "[Battling]") { TEST_CASE("Build and use event hook a lot", "[Battling]") {
// auto eventHook = EventHook(); auto eventHook = EventHook();
// std::vector<const EventData*> events; std::vector<const EventData*> events;
// eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); }); eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
// for (size_t i = 0; i < 10000; i++) { for (size_t i = 0; i < 10000; i++) {
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
// } }
// REQUIRE(events.size() == 10000); REQUIRE(events.size() == 10000);
//} }
//
// TEST_CASE("Build and use event hook with different types", "[Battling]") { TEST_CASE("Build and use event hook with different types", "[Battling]") {
// auto eventHook = EventHook(); auto eventHook = EventHook();
// std::vector<const EventData*> events; std::vector<const EventData*> events;
// eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); }); eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
// eventHook.Trigger<FaintEvent>(nullptr); eventHook.Trigger<FaintEvent>(nullptr);
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
// eventHook.Trigger<FaintEvent>(nullptr); eventHook.Trigger<FaintEvent>(nullptr);
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
// eventHook.Trigger<FaintEvent>(nullptr); eventHook.Trigger<FaintEvent>(nullptr);
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
// eventHook.Trigger<FaintEvent>(nullptr); eventHook.Trigger<FaintEvent>(nullptr);
//} }
#endif #endif