Added System::LocalPlayer that is always set to the entity which is the local player, available to all systems.

This commit is contained in:
2016-02-09 16:06:39 +01:00
parent d3bc48f5f7
commit c69a80f5ba
2 changed files with 20 additions and 1 deletions
+17 -1
View File
@@ -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<System, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(Events::PlayerSpawned& e)
{
if (e.PlayerID == -1) {
LocalPlayer = e.Player;
}
return true;
}
};
class PureSystem : public virtual System
+3
View File
@@ -61,6 +61,9 @@ public:
dt = 0.0;
}
// Process utility events for the System base class
m_EventBroker->Process<System>();
for (UnorderedSystems& group : m_OrderedSystemGroups) {
// Process events
for (auto& pair : group.Systems) {