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

This commit is contained in:
Deukhoofd 2020-08-02 10:14:56 +02:00
parent d55a9e8494
commit 84e030213d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 43 additions and 40 deletions

View File

@ -24,21 +24,24 @@ 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() { free(_memory); } ~EventHook() {
// 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