Reworked event hook to a system with pre-allocated memory, owned by the battle. This deals with cleaning up event data memory.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -163,4 +163,4 @@ void Battle::AddVolatileScript(const ArbUt::StringView& key) {
|
||||
}
|
||||
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
|
||||
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
|
||||
void Battle::DisplayText(const ArbUt::StringView& text) const { TriggerEventListener(new DisplayTextEvent(text)); }
|
||||
void Battle::DisplayText(const ArbUt::StringView& text) { TriggerEventListener<DisplayTextEvent>(text); }
|
||||
|
||||
@@ -95,10 +95,13 @@ namespace CreatureLib::Battling {
|
||||
void RemoveVolatileScript(Script* script);
|
||||
bool HasVolatileScript(const ArbUt::BasicStringView& name) const { return _volatile.Has(name); }
|
||||
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
|
||||
const EventHook& GetEventHook() const noexcept { return _eventHook; }
|
||||
|
||||
void DisplayText(const ArbUt::StringView& text) const;
|
||||
void DisplayText(const ArbUt::StringView& text);
|
||||
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
|
||||
void TriggerEventListener(EventData* data) const { this->_eventHook.TriggerEvent(data); }
|
||||
template <class T, class... parameters> void TriggerEventListener(parameters... args) {
|
||||
this->_eventHook.Trigger<T>(args...);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ bool Battling::Creature::IsFainted() const noexcept { return this->_currentHealt
|
||||
void Battling::Creature::OnFaint() {
|
||||
// HOOK: On Faint
|
||||
if (_battle != nullptr) {
|
||||
_battle->TriggerEventListener(new FaintEvent(this));
|
||||
_battle->TriggerEventListener<FaintEvent>(this);
|
||||
}
|
||||
_library->GetExperienceLibrary()->HandleExperienceGain(this, _seenOpponents);
|
||||
auto sideIndex = _side->GetCreatureIndex(this);
|
||||
@@ -144,7 +144,7 @@ void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source)
|
||||
auto newHealth = _currentHealth - damage;
|
||||
auto battle = this->GetBattle();
|
||||
if (battle != nullptr) {
|
||||
battle->TriggerEventListener(new DamageEvent(this, source, _currentHealth, newHealth));
|
||||
battle->TriggerEventListener<DamageEvent>(this, source, _currentHealth, newHealth);
|
||||
}
|
||||
_currentHealth = newHealth;
|
||||
|
||||
@@ -164,7 +164,7 @@ void Battling::Creature::Heal(uint32_t amount, bool canRevive) {
|
||||
auto newHealth = _currentHealth + amount;
|
||||
auto battle = this->GetBattle();
|
||||
if (battle != nullptr) {
|
||||
battle->TriggerEventListener(new HealEvent(this, _currentHealth, newHealth));
|
||||
battle->TriggerEventListener<HealEvent>(this, _currentHealth, newHealth);
|
||||
}
|
||||
_currentHealth = newHealth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user