Skip to content

Commit

Permalink
feat(engine): Trigger events by IDs.
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Nana <[email protected]>
  • Loading branch information
na2axl committed Nov 2, 2024
1 parent 412f0b9 commit fb2cf46
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion include/SparkyStudios/Audio/Amplitude/Core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ namespace SparkyStudios::Audio::Amplitude
[[nodiscard]] virtual EventCanceler Trigger(EventHandle handle, const Entity& entity) const = 0;

/**
* @brief Triggers the event associated to the given handle.
* @brief Triggers the event associated to the given name.
*
* @tip Triggering an event with its `EventHandle` is faster than using the
* event name as using the name requires an internal lookup.
Expand All @@ -1463,6 +1463,19 @@ namespace SparkyStudios::Audio::Amplitude
*/
[[nodiscard]] virtual EventCanceler Trigger(const AmString& name, const Entity& entity) const = 0;

/**
* @brief Triggers the event associated to the given ID.
*
* @tip Triggering an event with its `EventHandle` is faster than using the
* event ID as using the ID requires an internal lookup.
*
* @param[in] id The ID of event to trigger.
* @param[in] entity The entity on which trigger the event.
*
* @return An `EventCanceler` object which may be used to cancel the execution of the event.
*/
[[nodiscard]] virtual EventCanceler Trigger(AmEventID id, const Entity& entity) const = 0;

#pragma endregion

#pragma region Switches
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,15 @@ namespace SparkyStudios::Audio::Amplitude
return EventCanceler(nullptr);
}

EventCanceler EngineImpl::Trigger(AmEventID id, const Entity& entity) const
{
if (EventHandle handle = GetEventHandle(id))
return Trigger(handle, entity);

amLogError("Cannot trigger event: invalid ID (" AM_ID_CHAR_FMT ").", id);
return EventCanceler(nullptr);
}

void EngineImpl::SetSwitchState(SwitchHandle handle, AmObjectID stateId) const
{
if (handle == nullptr)
Expand Down
1 change: 1 addition & 0 deletions src/Core/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace SparkyStudios::Audio::Amplitude
void StopAll() const override;
[[nodiscard]] EventCanceler Trigger(EventHandle handle, const Entity& entity) const override;
[[nodiscard]] EventCanceler Trigger(const AmString& name, const Entity& entity) const override;
[[nodiscard]] EventCanceler Trigger(AmEventID id, const Entity& entity) const override;
void SetSwitchState(SwitchHandle handle, AmObjectID stateId) const override;
void SetSwitchState(SwitchHandle handle, const AmString& stateName) const override;
void SetSwitchState(SwitchHandle handle, const SwitchState& state) const override;
Expand Down

0 comments on commit fb2cf46

Please sign in to comment.