Disable EventHook system for now for testing.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d55a9e8494
commit
84e030213d
|
@ -24,21 +24,24 @@ namespace CreatureLib::Battling {
|
|||
|
||||
public:
|
||||
EventHook() : _offset(0), _capacity(defaultSize) {
|
||||
auto ptr = calloc(defaultSize, 1);
|
||||
if (ptr == nullptr) {
|
||||
THROW_CREATURE("Out of memory.");
|
||||
}
|
||||
_memory = static_cast<uint8_t*>(ptr);
|
||||
// auto ptr = calloc(defaultSize, 1);
|
||||
// if (ptr == nullptr) {
|
||||
// THROW_CREATURE("Out of memory.");
|
||||
// }
|
||||
// _memory = static_cast<uint8_t*>(ptr);
|
||||
}
|
||||
EventHook(const EventHook&) = delete;
|
||||
EventHook& operator=(const EventHook&) = delete;
|
||||
|
||||
~EventHook() { free(_memory); }
|
||||
~EventHook() {
|
||||
// free(_memory);
|
||||
}
|
||||
|
||||
size_t GetPosition() const noexcept { return _offset; }
|
||||
size_t GetCapacity() const noexcept { return _capacity; }
|
||||
|
||||
template <class T, class... parameters> void Trigger(parameters... args) {
|
||||
return;
|
||||
if (_listeners.size() == 0)
|
||||
return;
|
||||
if (_offset + sizeof(T) >= _capacity) {
|
||||
|
|
|
@ -6,38 +6,38 @@
|
|||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
TEST_CASE("Build and use event hook", "[Battling]") {
|
||||
auto eventHook = EventHook();
|
||||
std::vector<const EventData*> events;
|
||||
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
}
|
||||
REQUIRE(events.size() == 10);
|
||||
REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
|
||||
}
|
||||
|
||||
TEST_CASE("Build and use event hook a lot", "[Battling]") {
|
||||
auto eventHook = EventHook();
|
||||
std::vector<const EventData*> events;
|
||||
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
||||
for (size_t i = 0; i < 10000; i++) {
|
||||
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
}
|
||||
REQUIRE(events.size() == 10000);
|
||||
}
|
||||
|
||||
TEST_CASE("Build and use event hook with different types", "[Battling]") {
|
||||
auto eventHook = EventHook();
|
||||
std::vector<const EventData*> events;
|
||||
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
||||
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
eventHook.Trigger<FaintEvent>(nullptr);
|
||||
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
eventHook.Trigger<FaintEvent>(nullptr);
|
||||
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
eventHook.Trigger<FaintEvent>(nullptr);
|
||||
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
eventHook.Trigger<FaintEvent>(nullptr);
|
||||
}
|
||||
// TEST_CASE("Build and use event hook", "[Battling]") {
|
||||
// auto eventHook = EventHook();
|
||||
// std::vector<const EventData*> events;
|
||||
// eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
||||
// for (size_t i = 0; i < 10; i++) {
|
||||
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
// }
|
||||
// REQUIRE(events.size() == 10);
|
||||
// REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
|
||||
//}
|
||||
//
|
||||
// TEST_CASE("Build and use event hook a lot", "[Battling]") {
|
||||
// auto eventHook = EventHook();
|
||||
// std::vector<const EventData*> events;
|
||||
// eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
||||
// for (size_t i = 0; i < 10000; i++) {
|
||||
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
// }
|
||||
// REQUIRE(events.size() == 10000);
|
||||
//}
|
||||
//
|
||||
// TEST_CASE("Build and use event hook with different types", "[Battling]") {
|
||||
// auto eventHook = EventHook();
|
||||
// std::vector<const EventData*> events;
|
||||
// eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
||||
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
// eventHook.Trigger<FaintEvent>(nullptr);
|
||||
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
// eventHook.Trigger<FaintEvent>(nullptr);
|
||||
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
// eventHook.Trigger<FaintEvent>(nullptr);
|
||||
// eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
||||
// eventHook.Trigger<FaintEvent>(nullptr);
|
||||
//}
|
||||
#endif
|
Loading…
Reference in New Issue