Added System::LocalPlayer that is always set to the entity which is the local player, available to all systems.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "EntityWrapper.h"
|
#include "EntityWrapper.h"
|
||||||
#include "ComponentWrapper.h"
|
#include "ComponentWrapper.h"
|
||||||
|
#include "EPlayerSpawned.h"
|
||||||
|
|
||||||
struct SystemParams
|
struct SystemParams
|
||||||
{
|
{
|
||||||
@@ -31,13 +32,28 @@ protected:
|
|||||||
, m_EventBroker(params.EventBroker)
|
, m_EventBroker(params.EventBroker)
|
||||||
, IsClient(params.IsClient)
|
, IsClient(params.IsClient)
|
||||||
, IsServer(params.IsServer)
|
, IsServer(params.IsServer)
|
||||||
{ }
|
{
|
||||||
|
if (IsClient) {
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &System::OnPlayerSpawned);
|
||||||
|
}
|
||||||
|
}
|
||||||
virtual ~System() = default;
|
virtual ~System() = default;
|
||||||
|
|
||||||
World* m_World;
|
World* m_World;
|
||||||
EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
bool IsClient = false;
|
bool IsClient = false;
|
||||||
bool IsServer = 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
|
class PureSystem : public virtual System
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ public:
|
|||||||
dt = 0.0;
|
dt = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process utility events for the System base class
|
||||||
|
m_EventBroker->Process<System>();
|
||||||
|
|
||||||
for (UnorderedSystems& group : m_OrderedSystemGroups) {
|
for (UnorderedSystems& group : m_OrderedSystemGroups) {
|
||||||
// Process events
|
// Process events
|
||||||
for (auto& pair : group.Systems) {
|
for (auto& pair : group.Systems) {
|
||||||
|
|||||||
Reference in New Issue
Block a user