27#pragma region static_functions
43 static auto Broadcast(
const std::string& eventName,
const Message* message) -> std::vector<Message>;
55#pragma region overridden_functions
59 return std::make_unique<Messaging>(*
this);
63 auto onUpdate(
float dt) ->
void override;
70 auto save(
Stream& stream)
const ->
void override;
78#pragma region Messaging_Functions
93 template <
typename classType>
95 const std::string& eventName,
97 const std::string& functionName,
98 classType* pointerToSelf
101 hlg::Debug(
"Messaging is connecting a function of name:{} to the event:{} with the owner"
102 ": {}::{}", functionName, eventName, pointerToSelf->getName(), pointerToSelf->getUUID());
104 std::function<
Message(
const Message*)> functionToCall = std::bind_front(functionToLink, pointerToSelf);
108 functionMap.insert({eventName, connectedFunction});
117 auto remove(
const std::string& functionToRemove,
GameObject* owner) -> void;
128 auto broadcast(
const std::string& eventName,
const Message* message) -> std::vector<Message>;
131#pragma region member_variables
133 std::unordered_multimap<std::string, th::MemberFunction<Message, const Message*>>
functionMap;
137#pragma region helper_functions
143 const auto& [key, value] = item;
144 return !value.hasValidOwner();
sys::Json Stream
Definition AudioObject.h:20
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
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:141
std::unordered_multimap< std::string, th::MemberFunction< Message, const Message * > > functionMap
Definition Messaging.h:133
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Messaging.h:57
auto onUpdate(float dt) -> void override
called once every frame.
Definition Messaging.cpp:59
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:124
Messaging(const Messaging &other)=default
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Messaging.cpp:73
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition Messaging.cpp:78
auto broadcast(const std::string &eventName, const Message *message) -> std::vector< Message >
Calls all functions linked to eventName with the parameter message Example Call: messagingSystem->em...
Definition Messaging.cpp:187
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Messaging.cpp:68
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Messaging.cpp:64
Messaging()
Definition Messaging.cpp:35
auto operator=(Messaging &&other) noexcept -> Messaging &=default
~Messaging() override=default
static auto getEnum() -> Type
function required by all systems
Definition Messaging.h:32
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Messaging.h:66
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:26
auto operator=(const Messaging &other) -> Messaging &
Definition Messaging.cpp:45
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:94
auto removeAll(const GameObject *owner) -> void
Definition Messaging.cpp:143
Definition MemberFunction.h:27
auto Debug(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:62
the type of elements in a basic_json container
Definition GameObject.h:32