diff --git a/include/Engine/Core/System.h b/include/Engine/Core/System.h index d4b9808b..e21d8c7e 100644 --- a/include/Engine/Core/System.h +++ b/include/Engine/Core/System.h @@ -5,6 +5,7 @@ #include "World.h" #include "EntityWrapper.h" #include "ComponentWrapper.h" +#include "EPlayerSpawned.h" struct SystemParams { @@ -31,13 +32,28 @@ protected: , m_EventBroker(params.EventBroker) , IsClient(params.IsClient) , IsServer(params.IsServer) - { } + { + if (IsClient) { + EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &System::OnPlayerSpawned); + } + } virtual ~System() = default; World* m_World; EventBroker* m_EventBroker; bool IsClient = false; bool IsServer = false; + EntityWrapper LocalPlayer = EntityWrapper::Invalid; + +private: + EventRelay m_EPlayerSpawned; + bool OnPlayerSpawned(Events::PlayerSpawned& e) + { + if (e.PlayerID == -1) { + LocalPlayer = e.Player; + } + return true; + } }; class PureSystem : public virtual System diff --git a/include/Engine/Core/SystemPipeline.h b/include/Engine/Core/SystemPipeline.h index 88ec4fa7..5f7aee0b 100644 --- a/include/Engine/Core/SystemPipeline.h +++ b/include/Engine/Core/SystemPipeline.h @@ -61,6 +61,9 @@ public: dt = 0.0; } + // Process utility events for the System base class + m_EventBroker->Process(); + for (UnorderedSystems& group : m_OrderedSystemGroups) { // Process events for (auto& pair : group.Systems) {