Merge remote-tracking branch 'origin/Networking' into Networking
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include "Events/ESpawnerSpawn.h"
|
#include "Events/ESpawnerSpawn.h"
|
||||||
#include "Events/EPlayerSpawned.h"
|
#include "Events/EPlayerSpawned.h"
|
||||||
#include "Rendering/ESetCamera.h"
|
#include "Rendering/ESetCamera.h"
|
||||||
|
#include "Core/ConfigFile.h"
|
||||||
|
|
||||||
class PlayerSpawnSystem : public ImpureSystem
|
class PlayerSpawnSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
@@ -19,8 +20,11 @@ private:
|
|||||||
ComponentInfo::EnumType Team;
|
ComponentInfo::EnumType Team;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool m_NetworkEnabled = false;
|
||||||
|
std::vector<SpawnRequest> m_SpawnRequests;
|
||||||
|
|
||||||
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
EventRelay<PlayerSpawnSystem, Events::InputCommand> m_OnInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
EventRelay<PlayerSpawnSystem, Events::PlayerSpawned> m_OnPlayerSpawnerd;
|
||||||
std::vector<SpawnRequest> m_SpawnRequests;
|
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||||
};
|
};
|
||||||
@@ -4,6 +4,8 @@ PlayerSpawnSystem::PlayerSpawnSystem(World* m_World, EventBroker* eventBroker)
|
|||||||
: System(m_World, eventBroker)
|
: System(m_World, eventBroker)
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_OnInputCommand, &PlayerSpawnSystem::OnInputCommand);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerSpawnerd, &PlayerSpawnSystem::OnPlayerSpawned);
|
||||||
|
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSpawnSystem::Update(double dt)
|
void PlayerSpawnSystem::Update(double dt)
|
||||||
@@ -39,13 +41,6 @@ void PlayerSpawnSystem::Update(double dt)
|
|||||||
e.Spawner = spawner;
|
e.Spawner = spawner;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
|
|
||||||
// Set the camera to the correct entity
|
|
||||||
EntityWrapper cameraEntity = player.FirstChildByName("Camera");
|
|
||||||
if (cameraEntity.Valid()) {
|
|
||||||
Events::SetCamera e;
|
|
||||||
e.CameraEntity = cameraEntity;
|
|
||||||
m_EventBroker->Publish(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_SpawnRequests.clear();
|
m_SpawnRequests.clear();
|
||||||
@@ -57,6 +52,12 @@ bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Team picks should be processed ONLY server-side!
|
||||||
|
// Don't make a spawn request if PlayerID is -1, i.e. we're the client.
|
||||||
|
if (e.PlayerID == -1 && m_NetworkEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.Value != 0) {
|
if (e.Value != 0) {
|
||||||
SpawnRequest req;
|
SpawnRequest req;
|
||||||
req.PlayerID = e.PlayerID;
|
req.PlayerID = e.PlayerID;
|
||||||
@@ -67,3 +68,17 @@ bool PlayerSpawnSystem::OnInputCommand(const Events::InputCommand& e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||||
|
{
|
||||||
|
// When a player is actually spawned (since the actual spawning is handled on the server)
|
||||||
|
|
||||||
|
// Set the camera to the correct entity
|
||||||
|
EntityWrapper cameraEntity = e.Player.FirstChildByName("Camera");
|
||||||
|
if (cameraEntity.Valid()) {
|
||||||
|
Events::SetCamera e;
|
||||||
|
e.CameraEntity = cameraEntity;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user