SpectatorCameraSystem handles the overwatch cameras. Set camera to a class pick screen when connecting. Cannot spawn until both team and class has been picked.
Preparations for class aware PlayerSpawnSystem.
This commit is contained in:
@@ -19,6 +19,7 @@ private:
|
||||
{
|
||||
int PlayerID;
|
||||
ComponentInfo::EnumType Team;
|
||||
ComponentInfo::EnumType Class;
|
||||
};
|
||||
|
||||
bool m_NetworkEnabled = false;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef SpectatorCameraSystem_h__
|
||||
#define SpectatorCameraSystem_h__
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "Input/EInputCommand.h"
|
||||
|
||||
class SpectatorCameraSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
SpectatorCameraSystem(SystemParams params);
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
private:
|
||||
int m_PickedTeam;
|
||||
bool m_CamSetToTeamPick;
|
||||
|
||||
EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand& e);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -28,4 +28,5 @@ P=SwitchToPlayer
|
||||
K=TakeDamage,1500
|
||||
F2=PerformanceTimingResetAllTimers
|
||||
F3=PerformanceTimingCreateExcelData
|
||||
F4=SwapToClassPick
|
||||
Comma=SwapToClassPick
|
||||
Period=SwapToTeamPick
|
||||
File diff suppressed because it is too large
Load Diff
@@ -55,12 +55,12 @@
|
||||
<Children>
|
||||
<Entity name="ProgressionHexagon">
|
||||
<Components>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>2</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Fill>
|
||||
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||
</c:Fill>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>2</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
@@ -89,12 +89,12 @@
|
||||
<Children>
|
||||
<Entity name="ProgressionHexagon">
|
||||
<Components>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>3</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Fill>
|
||||
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||
</c:Fill>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>3</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
@@ -123,12 +123,12 @@
|
||||
<Children>
|
||||
<Entity name="ProgressionHexagon">
|
||||
<Components>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>4</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Fill>
|
||||
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||
</c:Fill>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>4</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
@@ -157,13 +157,13 @@
|
||||
<Children>
|
||||
<Entity name="ProgressionHexagon">
|
||||
<Components>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>1</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Fill>
|
||||
<Percentage>0.10332605343919568</Percentage>
|
||||
<Color A="0.699999988" B="0" G="0" R="1"/>
|
||||
</c:Fill>
|
||||
<c:CapturePointHUD>
|
||||
<CapturePointNumber>1</CapturePointNumber>
|
||||
</c:CapturePointHUD>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
@@ -192,10 +192,10 @@
|
||||
<Children>
|
||||
<Entity name="ProgressionHexagon">
|
||||
<Components>
|
||||
<c:CapturePointHUD/>
|
||||
<c:Fill>
|
||||
<Color A="0.699999988" B="1" G="0.200000003" R="0"/>
|
||||
</c:Fill>
|
||||
<c:CapturePointHUD/>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon_Rotated.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
@@ -301,6 +301,79 @@
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="PickTeamCamera">
|
||||
<Components>
|
||||
<c:Camera/>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="PickTeamHUD">
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0" Z="-0.5"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="TeamRedPick">
|
||||
<Components>
|
||||
<c:Button/>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
<Color A="1" B="0" G="0.294117659" R="0.980392158"/>
|
||||
</c:Sprite>
|
||||
<c:InputCmdButton>
|
||||
<Command>PickTeam</Command>
|
||||
<PressValue>2</PressValue>
|
||||
</c:InputCmdButton>
|
||||
<c:Transform>
|
||||
<Position X="0.349999994" Y="0.0500000007" Z="0"/>
|
||||
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="TeamBluePick">
|
||||
<Components>
|
||||
<c:Button/>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
<Color A="1" B="0.980392158" G="0.294117659" R="0"/>
|
||||
</c:Sprite>
|
||||
<c:InputCmdButton>
|
||||
<Command>PickTeam</Command>
|
||||
<PressValue>3</PressValue>
|
||||
</c:InputCmdButton>
|
||||
<c:Transform>
|
||||
<Position X="0.349999994" Y="0.149504215" Z="0"/>
|
||||
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="SpectatorPick">
|
||||
<Components>
|
||||
<c:Button/>
|
||||
<c:Sprite>
|
||||
<DiffuseTexture>Textures/Core/UnitHexagon.png</DiffuseTexture>
|
||||
<GlowMap></GlowMap>
|
||||
</c:Sprite>
|
||||
<c:InputCmdButton>
|
||||
<Command>PickTeam</Command>
|
||||
<PressValue>1</PressValue>
|
||||
</c:InputCmdButton>
|
||||
<c:Transform>
|
||||
<Position X="0.349999994" Y="-0.0500000007" Z="0"/>
|
||||
<Scale X="0.0799999982" Y="0.0799999982" Z="1"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "Game/Systems/KillFeedSystem.h"
|
||||
#include "Game/Systems/BoostSystem.h"
|
||||
#include "Game/Systems/BoostIconsHUDSystem.h"
|
||||
#include "Game/Systems/SpectatorCameraSystem.h"
|
||||
#include "GUI/ButtonSystem.h"
|
||||
#include "GUI/MainMenuSystem.h"
|
||||
|
||||
@@ -155,6 +156,7 @@ Game::Game(int argc, char* argv[])
|
||||
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<BoostIconsHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<SpectatorCameraSystem>(updateOrderLevel);
|
||||
// Populate Octree with collidables
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
|
||||
|
||||
@@ -59,7 +59,7 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
}
|
||||
|
||||
int numSpawnedPlayers = 0;
|
||||
for (auto& req : m_SpawnRequests) {
|
||||
for (auto it = m_SpawnRequests.begin(); it != m_SpawnRequests.end(); ++it) {
|
||||
for (auto& cPlayerSpawn : *playerSpawns) {
|
||||
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
|
||||
if (!spawner.HasComponent("Spawner")) {
|
||||
@@ -69,10 +69,12 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
// If the spawner has a team affiliation, check it
|
||||
if (spawner.HasComponent("Team")) {
|
||||
auto cSpawnerTeam = spawner["Team"];
|
||||
if ((int)cSpawnerTeam["Team"] != req.Team) {
|
||||
// Increase num spawned players if someone picks spectator, since it is valid to pick spectator
|
||||
if ((int)cSpawnerTeam["Team"] != it->Team) {
|
||||
// Increase num spawned players if someone picks spectator or didn't
|
||||
// pick a class yet, since it is valid
|
||||
// but don't spawn anything, goto next spawnrequest.
|
||||
if (req.Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) {
|
||||
// TODO: -1 Signifies no class picked, enum here later?
|
||||
if (it->Class == -1 || it->Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) {
|
||||
++numSpawnedPlayers;
|
||||
break;
|
||||
}
|
||||
@@ -80,18 +82,24 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Choose a different spawner depending on class picked?
|
||||
|
||||
// Spawn the player!
|
||||
EntityWrapper player = SpawnerSystem::Spawn(spawner, EntityWrapper::Invalid, "Player");
|
||||
// Set the player team affiliation
|
||||
player["Team"]["Team"] = req.Team;
|
||||
player["Team"]["Team"] = it->Team;
|
||||
|
||||
// Publish a PlayerSpawned event
|
||||
Events::PlayerSpawned e;
|
||||
e.PlayerID = req.PlayerID;
|
||||
e.PlayerID = it->PlayerID;
|
||||
e.Player = player;
|
||||
e.Spawner = spawner;
|
||||
m_EventBroker->Publish(e);
|
||||
++numSpawnedPlayers;
|
||||
it = m_SpawnRequests.erase(it);
|
||||
break;
|
||||
}
|
||||
if (it == m_SpawnRequests.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -100,12 +108,12 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
} else {
|
||||
LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers);
|
||||
}
|
||||
m_SpawnRequests.clear();
|
||||
}
|
||||
|
||||
bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
{
|
||||
if (e.Command != "PickTeam" && e.Command != "SwapToClassPick") {
|
||||
bool removeRequest = e.Command == "SwapToClassPick" || e.Command == "SwapToTeamPick";
|
||||
if (e.Command != "PickTeam" && e.Command != "PickClass" && !removeRequest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -113,19 +121,6 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
// A dead client should be able to swap to the overwatch camera.
|
||||
if (IsClient && !LocalPlayer.Valid()) {
|
||||
// Set the camera as active, if it exists.
|
||||
// Find the respawn camera or class pick camera.
|
||||
std::string camName = e.Command == "SwapToClassPick" ? "PickClassCamera" : "SpectatorCamera";
|
||||
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
|
||||
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = spectatorCam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
}
|
||||
}
|
||||
|
||||
// Team picks should be processed ONLY server-side!
|
||||
// Don't make a spawn request if we're the client.
|
||||
if (!IsServer && m_NetworkEnabled) {
|
||||
@@ -137,26 +132,38 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
for (; iter != m_SpawnRequests.end(); ++iter) {
|
||||
if (iter->PlayerID == e.PlayerID) {
|
||||
// If player wants to switch class, remove their spawn request.
|
||||
if (e.Command == "SwapToClassPick") {
|
||||
if (removeRequest) {
|
||||
m_SpawnRequests.erase(iter);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.Command == "SwapToClassPick") {
|
||||
// Return if we were only supposed to remove a request, not add one.
|
||||
if (removeRequest) {
|
||||
return true;
|
||||
}
|
||||
//If we get here, add or alter a spawn request.
|
||||
|
||||
if (iter != m_SpawnRequests.end()) {
|
||||
// If player is in queue to spawn, then change their team affiliation in the request.
|
||||
iter->Team = (ComponentInfo::EnumType)e.Value;
|
||||
// If player is in queue to spawn, then change their team affiliation or class in the request.
|
||||
if (e.Command == "PickTeam") {
|
||||
iter->Team = (ComponentInfo::EnumType)e.Value;
|
||||
} else {
|
||||
iter->Class = (ComponentInfo::EnumType)e.Value;
|
||||
}
|
||||
} else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) {
|
||||
// If player is not in queue to spawn, then create a spawn request,
|
||||
// but only if they are spectating and/or just connected.
|
||||
SpawnRequest req;
|
||||
req.PlayerID = e.PlayerID;
|
||||
req.Team = (ComponentInfo::EnumType)e.Value;
|
||||
if (e.Command == "PickTeam") {
|
||||
req.Team = (ComponentInfo::EnumType)e.Value;
|
||||
req.Class = -1; // TODO: -1 Signifies no class picked, enum here later?
|
||||
} else {
|
||||
req.Team = 1; // TODO: 1 Signifies spectator, should probably have real enum here later.
|
||||
req.Class = (ComponentInfo::EnumType)e.Value;
|
||||
}
|
||||
m_SpawnRequests.push_back(req);
|
||||
} else {
|
||||
return false;
|
||||
@@ -210,7 +217,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
|
||||
bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
{
|
||||
//Only spawn request if network is disabled or we are server.
|
||||
// Only spawn request if network is disabled or we are server.
|
||||
if (!IsServer && m_NetworkEnabled) {
|
||||
return false;
|
||||
}
|
||||
@@ -218,7 +225,7 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
return false;
|
||||
}
|
||||
ComponentWrapper cTeam = e.Player["Team"];
|
||||
//A spectator can't die anyway
|
||||
// A spectator can't die anyway
|
||||
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Spectator")) {
|
||||
return false;
|
||||
}
|
||||
@@ -230,6 +237,14 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
SpawnRequest req;
|
||||
req.PlayerID = m_PlayerIDs.at(e.Player.ID);
|
||||
req.Team = cTeam["Team"];
|
||||
// TODO: Better than temp class state code.
|
||||
if (e.Player.HasComponent("DashAbility")) {
|
||||
req.Class = 1; // Assault
|
||||
} else if (e.Player.HasComponent("SprintAbility")) {
|
||||
req.Class = 3; // Sniper
|
||||
} else {
|
||||
req.Class = 2; // Defender
|
||||
}
|
||||
m_SpawnRequests.push_back(req);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "Systems/SpectatorCameraSystem.h"
|
||||
#include "Rendering/ESetCamera.h"
|
||||
|
||||
SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
|
||||
: System(params)
|
||||
, m_CamSetToTeamPick(false)
|
||||
, m_PickedTeam(-1)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
|
||||
}
|
||||
|
||||
void SpectatorCameraSystem::Update(double dt)
|
||||
{
|
||||
if (!m_CamSetToTeamPick && IsClient) {
|
||||
// Find the class pick camera and set them to it, since they need to pick a team before they can leave the screen.
|
||||
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("PickTeamCamera");
|
||||
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
|
||||
m_CamSetToTeamPick = true;
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = spectatorCam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
{
|
||||
// Only the client should do this, and only if player is not spawned.
|
||||
if (!IsClient || LocalPlayer.Valid()) {
|
||||
return false;
|
||||
}
|
||||
bool swapToClass = e.Command == "PickTeam" || e.Command == "SwapToClassPick";
|
||||
if (e.Value == 0 || !swapToClass && e.Command != "SwapToTeamPick" && e.Command != "PickClass") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e.Command == "PickTeam") {
|
||||
m_PickedTeam = e.Value;
|
||||
}
|
||||
|
||||
// If a team has not been picked, they may not exit the pick team screen.
|
||||
if (m_PickedTeam == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A dead client should be able to swap to and between the overwatch cameras.
|
||||
std::string camName;
|
||||
// TODO: 1 Signifies spectator, should probably have real enum here later.
|
||||
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
|
||||
if (swapToClass && m_PickedTeam != 1) {
|
||||
camName = "PickClassCamera";
|
||||
} else if (e.Command == "SwapToTeamPick") {
|
||||
camName = "PickTeamCamera";
|
||||
} else {
|
||||
camName = "SpectatorCamera";
|
||||
}
|
||||
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
|
||||
// Set the camera as active, if it exists.
|
||||
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
|
||||
Events::SetCamera eSetCamera;
|
||||
eSetCamera.CameraEntity = spectatorCam;
|
||||
m_EventBroker->Publish(eSetCamera);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user