29#pragma region static_functions
45 static auto Broadcast(
const std::string& eventName,
const Message* message) -> std::vector<Message>;
59#pragma region overridden_functions
63 return std::make_unique<Messaging>(*
this);
67 auto onUpdate(
float dt) ->
void override;
73 auto load(
const Stream& stream) ->
void override;
74 auto save(
Stream& stream)
const ->
void override;
82#pragma region Messaging_Functions
97 template <
typename classType>
99 const std::string& eventName,
101 const std::string& functionName,
102 classType* pointerToSelf
105 hlg::Debug(
"Messaging is connecting a function of name:{} to the event:{} with the owner"
106 ": {}::{}", functionName, eventName, pointerToSelf->getName(), pointerToSelf->getUUID());
108 std::function<
Message(
const Message*)> functionToCall = std::bind_front(functionToLink, pointerToSelf);
112 functionMap.insert({eventName, connectedFunction});
123#define TH_CONNECT_MESSAGE(event) messaging->connect< TH_CURRENT_CLASS >( #event , & TH_CURRENT_CLASS ::receive##event ,"receive" #event ,this);
131 auto remove(
const std::string& functionToRemove,
GameObject* owner) -> void;
144 auto broadcast(std::string eventName,
const Message* message) -> std::vector<Message>;
163#pragma region member_variables
165 std::unordered_multimap<std::string, th::MemberFunction<Message, const Message*>>
functionMap;
169#pragma region helper_functions
175 const auto& [key, value] = item;
176 return !value.hasValidOwner();
185 auto getFunctionsToCall(
const std::string& eventName,
bool broadcastToNonReceiving) -> std::vector<th::MemberFunction<Message, const Message*>*>;
sys::Json Stream
Definition AudioObject.h:20
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Type
Definition System.h:20
@ Messaging
Definition System.h:26
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
static auto HasParentExpired
Definition Messaging.h:173
std::unordered_multimap< std::string, th::MemberFunction< Message, const Message * > > functionMap
Definition Messaging.h:165
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Messaging.h:61
auto onUpdate(float dt) -> void override
called once every frame.
Definition Messaging.cpp:73
auto remove(const std::string &functionToRemove, GameObject *owner) -> void
Removes all functions with the given name that belong to the given owner Example Call: messagingSyst...
Definition Messaging.cpp:138
Messaging(const Messaging &other)=default
auto getFunctionsToCall(const std::string &eventName, bool broadcastToNonReceiving) -> std::vector< th::MemberFunction< Message, const Message * > * >
helper function for broadcast and forceBroadcast, to collect all functions that will be called
Definition Messaging.cpp:202
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Messaging.cpp:87
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition Messaging.cpp:92
auto broadcastToFunctions(const std::string &eventName, const Message *message, const std::vector< th::MemberFunction< Message, const Message * > * > &functionsToCall) -> std::vector< Message >
helper function that takes a list of functions to call, and broadcasts an event with a message to the...
Definition Messaging.cpp:230
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Messaging.cpp:78
Messaging()
Definition Messaging.cpp:49
auto operator=(Messaging &&other) noexcept -> Messaging &=default
~Messaging() override=default
static auto bindLuaTypes(sol::state &lua) -> void
Definition Messaging.cpp:35
auto broadcast(std::string eventName, const Message *message) -> std::vector< Message >
Calls all functions linked to eventName with the parameter message Example Call: messagingSystem->br...
Definition Messaging.cpp:257
static auto getEnum() -> Type
function required by all systems
Definition Messaging.h:34
auto forceBroadcast(std::string eventName, const Message *message) -> std::vector< Message >
Calls all functions linked to eventName with the parameter message, just like broadcast does,...
Definition Messaging.cpp:272
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Messaging.cpp:82
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Messaging.h:70
static auto Broadcast(const std::string &eventName, const Message *message) -> std::vector< Message >
A helper function that gets the messaging system and calls broadcast on it for you.
Definition Messaging.cpp:28
auto operator=(const Messaging &other) -> Messaging &
Definition Messaging.cpp:59
auto connect(const std::string &eventName, Message(classType::*functionToLink)(const Message *), const std::string &functionName, classType *pointerToSelf) -> void
Attaches a member function to a specific event.
Definition Messaging.h:98
auto removeAll(const GameObject *owner) -> void
Definition Messaging.cpp:157
Definition MemberFunction.h:27
auto Debug(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:69
the type of elements in a basic_json container
Definition GameObject.h:37