libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
EventAction.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <stdint.h>
5#include <variant>
6
7#include "ship/core/Action.h"
9
10namespace Ship {
11
19using EventActionCppCallback = std::function<bool(EventID, uintptr_t)>;
20
26using EventActionRawCallback = bool (*)(EventID, uintptr_t);
27
35using EventActionCallback = std::variant<std::monostate, EventActionCppCallback, uintptr_t>;
36
46class EventAction : public Action {
47 public:
53 EventAction(EventID eventId, std::shared_ptr<Tickable> tickable);
54
62 EventAction(EventID eventId, std::shared_ptr<Tickable> tickable, EventActionCppCallback callback,
63 uintptr_t callbackPointerData = 0);
64
72 EventAction(EventID eventId, std::shared_ptr<Tickable> tickable, uintptr_t callback,
73 uintptr_t callbackPointerData = 0);
74
75 virtual ~EventAction() = default;
76
79
81 bool HasCallback() const;
82
84 bool GetHasCppCallback() const;
85
87 bool GetHasRawCallback() const;
88
95
102
109 EventAction& SetCallback(const EventActionCallback& callback, uintptr_t callbackPointerData);
110
117
124 EventAction& SetCallback(EventActionCppCallback callback, uintptr_t callbackPointerData);
125
131 EventAction& SetCallback(uintptr_t callback);
132
139 EventAction& SetCallback(uintptr_t callback, uintptr_t callbackPointerData);
140
146
148 uintptr_t GetCallbackPointerData() const;
149
155 EventAction& SetCallbackPointerData(uintptr_t callbackPointerData);
156
157 protected:
162 bool ActionRan() override;
163
164 private:
165 EventID mEventId;
166 EventActionCallback mCallback;
167 uintptr_t mCallbackPointerData;
168};
169
170} // namespace Ship
int32_t EventID
Numeric identifier for an event. -1 is uninitialized, IDs < -1 are internally registered,...
Definition EventTypes.h:8
Represents a discrete, repeatable operation run by a Tickable.
Definition Action.h:35
Action specialization for event-driven dispatch.
Definition EventAction.h:46
bool HasCallback() const
Returns true when a callback override is configured.
EventAction & SetCallback(uintptr_t callback, uintptr_t callbackPointerData)
Configures a C-style callback override.
bool ActionRan() override
Dispatches callback override when present, else delegates to TickableComponent::ActionRan().
EventAction(EventID eventId, std::shared_ptr< Tickable > tickable)
Constructs an EventAction for the given EventID.
EventAction & SetCallback(const EventActionCallback &callback, uintptr_t callbackPointerData)
Configures callback override from callback variant.
EventAction(EventID eventId, std::shared_ptr< Tickable > tickable, EventActionCppCallback callback, uintptr_t callbackPointerData=0)
Constructs an EventAction with a C++ callback override.
EventAction & SetCallback(EventActionCppCallback callback, uintptr_t callbackPointerData)
Configures a C++ callback override.
EventAction & SetCallback(uintptr_t callback)
Configures a C-style callback override.
bool GetHasCppCallback() const
Returns true when callback target is the C++ callback form.
EventAction & SetCallback(const EventActionCallback &callback)
Configures callback override from callback variant.
virtual ~EventAction()=default
EventAction & ClearCallback()
Clears callback override and restores fallback dispatch.
uintptr_t GetCallbackPointerData() const
Returns the callback pointer-sized data used by both callback forms.
EventAction(EventID eventId, std::shared_ptr< Tickable > tickable, uintptr_t callback, uintptr_t callbackPointerData=0)
Constructs an EventAction with a C-style callback override.
bool GetHasRawCallback() const
Returns true when callback target is the raw function-pointer form.
const EventActionCallback & GetCallback() const
Returns the currently configured callback target.
EventID GetEventId() const
Returns the EventID this action corresponds to.
EventAction & SetCallback(EventActionCppCallback callback)
Configures a C++ callback override.
EventAction & SetCallbackPointerData(uintptr_t callbackPointerData)
Updates callback pointer-sized data without changing callback target.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
std::function< bool(EventID, uintptr_t)> EventActionCppCallback
C++ callback signature for EventAction dispatch.
Definition EventAction.h:19
bool(*)(EventID, uintptr_t) EventActionRawCallback
C-style callback signature for EventAction dispatch.
Definition EventAction.h:26
std::variant< std::monostate, EventActionCppCallback, uintptr_t > EventActionCallback
Stored callback target for EventAction.
Definition EventAction.h:35