diff --git a/include/Engine/Core/ECaptured.h b/include/Engine/Core/ECaptured.h index 047c5d7d..e0de0f31 100644 --- a/include/Engine/Core/ECaptured.h +++ b/include/Engine/Core/ECaptured.h @@ -1,5 +1,5 @@ -#ifndef ECaptured_h__ -#define ECaptured_h__ +#ifndef Events_Captured_h__ +#define Events_Captured_h__ #include "EventBroker.h" #include "../Core/Entity.h" diff --git a/include/Engine/Network/Client.h b/include/Engine/Network/Client.h index ebf46361..29e9ac9a 100644 --- a/include/Engine/Network/Client.h +++ b/include/Engine/Network/Client.h @@ -32,6 +32,9 @@ #include "../Game/Events/EDashAbility.h" #include "Network/EDisplayServerlist.h" #include "Network/EConnectRequest.h" +#include "Network/EPlayerDisconnected.h" +#include "Game/Events/EReset.h" + class Client : public Network { public: @@ -40,7 +43,7 @@ public: ~Client(); void Connect(std::string address, int port); - void Update() override; + void Update(double dt) override; private: UDPClient m_Unreliable; TCPClient m_Reliable; @@ -74,10 +77,10 @@ private: // Network logic PlayerDefinition m_PlayerDefinitions[8]; SnapshotDefinitions m_NextSnapshot; - double m_DurationOfPingTime; - std::clock_t m_StartPingTime; - std::clock_t m_TimeSinceSentInputs; - unsigned int m_SendInputIntervalMs; + double m_DurationOfPingTime = 0; + double m_StartPingTime = 0; + double m_TimeSinceSentInputs = 0; + double m_SendInputInterval = 0.033; std::vector m_InputCommandBuffer; // Private member functions @@ -100,6 +103,7 @@ private: void parseDoubleJump(Packet& packet); void parseDashEffect(Packet& packet); void parseAmmoPickup(Packet& packet); + void parseRemoveWorld(Packet& packet); void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void parseSnapshot(Packet& packet); void identifyPacketLoss(); @@ -109,7 +113,6 @@ private: void sendLocalPlayerTransform(); void becomePlayer(); void displayServerlist(); - void removeWorld(); void createMainMenu(); // Mapping Logic // Returns if local EntityID exist in map @@ -138,8 +141,8 @@ private: UDPClient m_ServerlistRequest; std::vector m_Serverlist; bool m_SearchingForServers = false; - std::clock_t m_StartSearchTime; - double m_SearchingTime = 200; // Config I guess + double m_TimeSearched = 0; + double m_SearchingTime = 0.2; // Config I guess }; #endif diff --git a/include/Engine/Network/MessageType.h b/include/Engine/Network/MessageType.h index c34f584e..11fb85be 100644 --- a/include/Engine/Network/MessageType.h +++ b/include/Engine/Network/MessageType.h @@ -23,6 +23,7 @@ enum class MessageType OnDashEffect, ServerlistRequest, AmmoPickup, + RemoveWorld, Invalid }; diff --git a/include/Engine/Network/Network.h b/include/Engine/Network/Network.h index 69395a85..b6c47f71 100644 --- a/include/Engine/Network/Network.h +++ b/include/Engine/Network/Network.h @@ -22,7 +22,7 @@ public: Network(World* world, EventBroker* eventBroker); virtual ~Network() { }; - virtual void Update() = 0; + virtual void Update(double dt) = 0; protected: World* m_World; @@ -40,6 +40,7 @@ protected: void saveToFile(); void updateNetworkData(); void popNetworkSegmentOfHeader(Packet& packet); + void removeWorld(); }; #endif \ No newline at end of file diff --git a/include/Engine/Network/Server.h b/include/Engine/Network/Server.h index 6acb7081..67859143 100644 --- a/include/Engine/Network/Server.h +++ b/include/Engine/Network/Server.h @@ -11,6 +11,7 @@ #include "Network/MessageType.h" #include "Network/PlayerDefinition.h" #include "Core/World.h" +#include "Core/EntityFile.h" #include "Core/EventBroker.h" #include "../Network/Network.h" #include "Input/EInputCommand.h" @@ -24,6 +25,8 @@ #include "Core/EPlayerDeath.h" #include "Network/EPlayerConnected.h" #include "Network/EKillDeath.h" +#include "Core/EWin.h" +#include "Game/Events/EReset.h" class Server : public Network { @@ -31,7 +34,7 @@ public: Server(World* world, EventBroker* eventBroker, int port); ~Server(); - void Update() override; + void Update(double dt) override; private: // Network channels @@ -41,6 +44,7 @@ private: // dont forget to set these in the childrens receive logic boost::asio::ip::address m_Address; int m_Port = 27666; + bool m_GameIsOver = false; // Sending messages to client logic std::map m_ConnectedPlayers; std::vector m_PlayersToDisconnect; @@ -48,14 +52,14 @@ private: char readBuffer[BUFFERSIZE] = { 0 }; size_t bytesRead = 0; // time for previouse message - std::clock_t previousePingMessage = std::clock(); - std::clock_t previousSnapshotMessage = std::clock(); - std::clock_t timOutTimer = std::clock(); + double previousPingMessage = 0; + double previousSnapshotMessage = 0; + double timeOutTimer = 0; - // How often we send messages (milliseconds) - float pingIntervalMs; - float snapshotInterval; - int checkTimeOutInterval = 100; + // How often we send messages (seconds) + double pingInterval = 1; + double snapshotInterval = 0.05; + double checkTimeOutInterval = 0.1; int m_NextPlayerID = 0; std::vector m_InputCommandsToBroadcast; //Timers @@ -71,6 +75,7 @@ private: void reliableBroadcast(Packet& packet); void unreliableBroadcast(Packet& packet); void sendSnapshot(); + void createWorldSnapshot(Packet& packet); void addPlayersToPacket(Packet& packet, EntityID entityID); void addChildrenToPacket(Packet& packet, EntityID entityID); void addInputCommandsToPacket(Packet& packet); @@ -83,6 +88,7 @@ private: void kick(PlayerID player); PlayerID getPlayerIDFromEndpoint(); PlayerID getPlayerIDFromEntityID(EntityID entityID); + void resetMap(); void parsePlayerTransform(Packet& packet); void parseOnInputCommand(Packet& packet); void parseClientPing(); @@ -110,6 +116,8 @@ private: bool OnAmmoPickup(const Events::AmmoPickup& e); EventRelay m_EPlayerDeath; bool OnPlayerDeath(const Events::PlayerDeath& e); + EventRelay m_EWin; + bool OnWin(const Events::Win& e); }; #endif diff --git a/include/Game/Events/EReset.h b/include/Game/Events/EReset.h new file mode 100644 index 00000000..70fea123 --- /dev/null +++ b/include/Game/Events/EReset.h @@ -0,0 +1,16 @@ +#ifndef Events_Reset_h__ +#define Events_Reset_h__ + +#include "Core/EventBroker.h" +#include "Core/EntityWrapper.h" + +namespace Events +{ + +struct Reset : Event +{ +}; + +} + +#endif \ No newline at end of file diff --git a/include/Game/Systems/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h index 6211ad49..0cba5401 100644 --- a/include/Game/Systems/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -9,6 +9,7 @@ #include "Engine/Collision/ETrigger.h" #include "Core/ECaptured.h" #include "Core/EWin.h" +#include "Game/Events/EReset.h" #include #include @@ -23,6 +24,7 @@ public: virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; private: + void Init(); //methods which will take care of specific events EventRelay m_ETriggerTouch; bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e); @@ -30,6 +32,8 @@ private: bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); EventRelay m_ECaptured; bool CapturePointSystem::OnCaptured(const Events::Captured& e); + EventRelay m_EReset; + bool CapturePointSystem::OnReset(const Events::Reset& e); void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner); bool m_WinnerWasFound = false; diff --git a/include/Game/Systems/ScoreScreenSystem.h b/include/Game/Systems/ScoreScreenSystem.h index 2559bfb3..6b2bb113 100644 --- a/include/Game/Systems/ScoreScreenSystem.h +++ b/include/Game/Systems/ScoreScreenSystem.h @@ -8,6 +8,8 @@ #include "Core/EPlayerSpawned.h" #include "Network/EPlayerConnected.h" #include "Network/EPlayerDisconnected.h" +#include "Game/Events/EReset.h" +#include "Engine/Input/EInputCommand.h" #include "GLM.h" class ScoreScreenSystem : public PureSystem @@ -25,6 +27,10 @@ public: bool OnPlayerConnected(const Events::PlayerConnected& e); EventRelay m_EPlayerDisconnected; bool OnPlayerDisconnected(const Events::PlayerDisconnected& e); + EventRelay m_EReset; + bool OnReset(const Events::Reset& e); + EventRelay m_EInputCommand; + bool OnInputCommand(const Events::InputCommand& e); private: struct PlayerData { diff --git a/include/Game/Systems/SpectatorCameraSystem.h b/include/Game/Systems/SpectatorCameraSystem.h index bc7aa860..6ba7294d 100644 --- a/include/Game/Systems/SpectatorCameraSystem.h +++ b/include/Game/Systems/SpectatorCameraSystem.h @@ -4,6 +4,7 @@ #include "Core/System.h" #include "Input/EInputCommand.h" #include "Network/EPlayerDisconnected.h" +#include "Game/Events/EReset.h" class SpectatorCameraSystem : public ImpureSystem { @@ -15,11 +16,14 @@ public: private: int m_PickedTeam; bool m_CamSetToTeamPick; + void reset(); EventRelay m_EInputCommand; bool OnInputCommand(const Events::InputCommand& e); EventRelay m_EDisconnect; bool OnDisconnect(const Events::PlayerDisconnected& e); + EventRelay m_EReset; + bool OnReset(const Events::Reset& e); }; #endif \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointGameMode.xml b/resources/Schema/Components/CapturePointGameMode.xml index 3104e71f..f8e04eaf 100644 --- a/resources/Schema/Components/CapturePointGameMode.xml +++ b/resources/Schema/Components/CapturePointGameMode.xml @@ -2,4 +2,5 @@ 0.0 8.0 + 10.0 \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointGameMode.xsd b/resources/Schema/Components/CapturePointGameMode.xsd index 8b81d67a..791b75b1 100644 --- a/resources/Schema/Components/CapturePointGameMode.xsd +++ b/resources/Schema/Components/CapturePointGameMode.xsd @@ -12,6 +12,9 @@ Players will be spawned when RespawnTime reaches this. + + The map will be reset when time reaches 0. + diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index 9b6dc6d9..705872fa 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -1,5 +1,5 @@ #include "Network/Client.h" -#include "Network/EPlayerDisconnected.h" + using namespace boost::asio::ip; Client::Client(World* world, EventBroker* eventBroker) @@ -12,7 +12,7 @@ Client::Client(World* world, EventBroker* eventBroker) auto config = ResourceManager::Load("Config.ini"); m_PlayerName = config->Get("Networking.Name", "Raptorcopter"); - m_SendInputIntervalMs = config->Get("Networking.SendInputIntervalMs", 33); + m_SendInputInterval = config->Get("Networking.SendInputIntervalMs", 33) / 1000.0; LOG_INFO("Client initialized"); m_ServerlistRequest.Connect(m_PlayerName, "192.168.1.255", 32554); @@ -48,7 +48,7 @@ void Client::Connect(std::string address, int port) } } -void Client::Update() +void Client::Update(double dt) { m_EventBroker->Process(); while (m_Unreliable.IsSocketAvailable()) { @@ -85,7 +85,9 @@ void Client::Update() } if (m_SearchingForServers) { - if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) { + m_TimeSearched += dt; + if (m_SearchingTime < m_TimeSearched) { + m_TimeSearched = 0; m_SearchingForServers = false; //displayServerlist(); Events::DisplayServerlist e; @@ -96,9 +98,10 @@ void Client::Update() if (m_IsConnected) { // Don't send 1 input in 1 packet, bunch em up. - if (m_SendInputIntervalMs < (1000 * (std::clock() - m_TimeSinceSentInputs) / (double)CLOCKS_PER_SEC)) { + m_TimeSinceSentInputs += dt; + if (m_SendInputInterval < m_TimeSinceSentInputs) { sendInputCommands(); - m_TimeSinceSentInputs = std::clock(); + m_TimeSinceSentInputs = 0; } // HACK: Send absolute player positions for now to avoid desync until we have reliable messages sendLocalPlayerTransform(); @@ -159,6 +162,9 @@ void Client::parseMessageType(Packet& packet) case MessageType::AmmoPickup: parseAmmoPickup(packet); break; + case MessageType::RemoveWorld: + parseRemoveWorld(packet); + break; default: break; } @@ -336,6 +342,13 @@ void Client::parseAmmoPickup(Packet & packet) m_EventBroker->Publish(e); } +void Client::parseRemoveWorld(Packet & packet) +{ + removeWorld(); + Events::Reset e; + m_EventBroker->Publish(e); +} + void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID) { for (auto field : componentInfo.FieldsInOrder) { @@ -583,7 +596,7 @@ bool Client::OnConnectRequest(const Events::ConnectRequest& e) bool Client::OnSearchForServers(const Events::SearchForServers& e) { m_SearchingForServers = true; - m_StartSearchTime = std::clock(); + m_TimeSearched = 0; m_Serverlist.clear(); Packet packet(MessageType::ServerlistRequest); m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config @@ -706,19 +719,6 @@ void Client::displayServerlist() } } -void Client::removeWorld() -{ - std::vector childrenToBeDeleted; - auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid); - for (auto it = rootEntites.first; it != rootEntites.second; it++) { - childrenToBeDeleted.push_back(it->second); - } - for (int i = 0; i < childrenToBeDeleted.size(); ++i) { - m_World->DeleteEntity(childrenToBeDeleted[i]); - } -} - - void Client::createMainMenu() { auto entityFile = ResourceManager::Load("Schema/Entities/StartMenu.xml"); diff --git a/src/Engine/Network/Network.cpp b/src/Engine/Network/Network.cpp index 6ac5cf69..b69fba09 100644 --- a/src/Engine/Network/Network.cpp +++ b/src/Engine/Network/Network.cpp @@ -9,7 +9,7 @@ Network::Network(World* world, EventBroker* eventBroker) m_TimeoutMs = config->Get("Networking.TimeoutMs", 20000); } -void Network::Update() +void Network::Update(double dt) { updateNetworkData(); } @@ -92,3 +92,15 @@ void Network::popNetworkSegmentOfHeader(Packet & packet) packet.ReadPrimitive(); packet.ReadPrimitive(); } + +void Network::removeWorld() +{ + std::vector childrenToBeDeleted; + auto rootEntites = m_World->GetDirectChildren(EntityID_Invalid); + for (auto it = rootEntites.first; it != rootEntites.second; it++) { + childrenToBeDeleted.push_back(it->second); + } + for (int i = 0; i < childrenToBeDeleted.size(); ++i) { + m_World->DeleteEntity(childrenToBeDeleted[i]); + } +} \ No newline at end of file diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index da230b42..dc40ea3f 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -5,8 +5,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port) , m_ServerlistRequest(13) { ConfigFile* config = ResourceManager::Load("Config.ini"); - snapshotInterval = 1000 * config->Get("Networking.SnapshotInterval", 0.05f); - pingIntervalMs = config->Get("Networking.PingIntervalMs", 1000); + snapshotInterval = config->Get("Networking.SnapshotInterval", 0.05); + pingInterval = config->Get("Networking.PingIntervalMs", 1000) / 1000.0; m_ServerName = config->Get("Networking.Name", "Unnamed"); // Subscribe to events @@ -17,6 +17,7 @@ Server::Server(World* world, EventBroker* eventBroker, int port) EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &Server::OnPlayerDamage); EVENT_SUBSCRIBE_MEMBER(m_EAmmoPickup, &Server::OnAmmoPickup); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDeath, &Server::OnPlayerDeath); + EVENT_SUBSCRIBE_MEMBER(m_EWin, &Server::OnWin); // BindWW if (port == 0) { port = config->Get("Networking.Port", 27666); @@ -30,7 +31,7 @@ Server::~Server() } -void Server::Update() +void Server::Update(double dt) { m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers); @@ -86,26 +87,44 @@ void Server::Update() } m_PlayersToDisconnect.clear(); - std::clock_t currentTime = std::clock(); // Send snapshot - if (snapshotInterval < (1000 * (currentTime - previousSnapshotMessage) / (double)CLOCKS_PER_SEC)) { + previousSnapshotMessage += dt; + if (snapshotInterval < previousSnapshotMessage) { sendSnapshot(); - previousSnapshotMessage = currentTime; + previousSnapshotMessage = 0; } // Send pings each - if (pingIntervalMs < (1000 * (currentTime - previousePingMessage) / (double)CLOCKS_PER_SEC)) { + previousPingMessage += dt; + if (pingInterval < previousPingMessage) { sendPing(); - previousePingMessage = currentTime; + previousPingMessage = 0; } // Time out logic - if (checkTimeOutInterval < (1000 * (currentTime - timOutTimer) / (double)CLOCKS_PER_SEC)) { + timeOutTimer += dt; + if (checkTimeOutInterval < timeOutTimer) { checkForTimeOuts(); - timOutTimer = currentTime; + timeOutTimer = 0; } m_EventBroker->Process(); if (isReadingData) { - Network::Update(); + Network::Update(dt); + } + + if (m_GameIsOver) { + auto pool = m_World->GetComponents("CapturePointGameMode"); + if (pool != nullptr && pool->size() > 0) { + // Take the first CapturePointGameMode component found. + ComponentWrapper& modeComponent = *pool->begin(); + // Decrease timer. + Field timer = modeComponent["ResetCountdown"]; + timer -= dt; + if (timer < 0) { + resetMap(); + } + } else { + resetMap(); + } } } @@ -164,7 +183,7 @@ void Server::reliableBroadcast(Packet& packet) void Server::unreliableBroadcast(Packet& packet) { - m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers); + m_Unreliable.SendToConnectedPlayers(packet, m_ConnectedPlayers); } // Send snapshot fields @@ -173,10 +192,16 @@ void Server::sendSnapshot() Packet packet(MessageType::Snapshot); addInputCommandsToPacket(packet); addPlayersToPacket(packet, EntityID_Invalid); - //addChildrenToPacket(packet, EntityID_Invalid); unreliableBroadcast(packet); } +// Send snapshot fields +void Server::createWorldSnapshot(Packet& packet) +{ + addInputCommandsToPacket(packet); + addChildrenToPacket(packet, EntityID_Invalid); +} + void Server::addInputCommandsToPacket(Packet& packet) { // Number of input commands @@ -379,8 +404,7 @@ void Server::parseTCPConnect(Packet & packet) m_Reliable.Send(connnectPacket, m_ConnectedPlayers.at(playerID)); Packet firstSnapshot(MessageType::Snapshot); - addInputCommandsToPacket(firstSnapshot); - addChildrenToPacket(firstSnapshot, EntityID_Invalid); + createWorldSnapshot(firstSnapshot); m_Reliable.Send(firstSnapshot); // Send notification that a player has connected @@ -542,6 +566,13 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e) return false; } +bool Server::OnWin(const Events::Win & e) +{ + // Postpone the gameover reset + m_GameIsOver = true; + return true; +} + void Server::parseClientPing() { LOG_INFO("%i: Parsing ping", m_PacketID); @@ -663,4 +694,20 @@ PlayerID Server::getPlayerIDFromEntityID(EntityID entityID) } } return -1; +} + +void Server::resetMap() +{ + m_GameIsOver = false; + Events::Reset reset; + m_EventBroker->Publish(reset); + Packet removeMap(MessageType::RemoveWorld); + reliableBroadcast(removeMap); + removeWorld(); + // Hardcoded for now. + auto entityFile = ResourceManager::Load("Schema/Entities/CP_Rocky2.xml"); + entityFile->MergeInto(m_World); + Packet newWorld(MessageType::Snapshot); + createWorldSnapshot(newWorld); + reliableBroadcast(newWorld); } \ No newline at end of file diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index a22234ce..4d76797e 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -232,10 +232,10 @@ void Game::Tick() PerformanceTimer::StartTimerAndStopPrevious("Network"); m_EventBroker->Process(); if (m_NetworkClient != nullptr) { - m_NetworkClient->Update(); + m_NetworkClient->Update(dt); } if (m_NetworkServer != nullptr) { - m_NetworkServer->Update(); + m_NetworkServer->Update(dt); } //m_SoundManager->Update(dt); diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index d466bf27..6739b814 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -10,8 +10,26 @@ CapturePointSystem::CapturePointSystem(SystemParams params) EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); + EVENT_SUBSCRIBE_MEMBER(m_EReset, &CapturePointSystem::OnReset); + Init(); } +} +void CapturePointSystem::Init() +{ + m_WinnerWasFound = false; + //need to track these variables for the captureSystem to work as per design! + m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint; + m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint; + m_RedTeamHomeCapturePoint = m_NotACapturePoint; + m_BlueTeamHomeCapturePoint = m_NotACapturePoint; + m_NumberOfCapturePoints = 0; + m_ResetTimers = false; + m_RecentlyCapturedNeedNextCapturePointNow = false; + m_CapturePointNumberToEntityMap.clear(); + //vectors which will keep track of enter/leave changes + m_ETriggerTouchVector.clear(); + m_ETriggerLeaveVector.clear(); } //here all capturepoints will update their component @@ -24,6 +42,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp if (m_WinnerWasFound) { return; } + if (!capturePointEntity.Valid()) { + return; + } const int capturePointNumber = cCapturePoint["CapturePointNumber"]; const bool hasTeamComponent = capturePointEntity.HasComponent("Team"); @@ -60,7 +81,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } //if we havent received all capturepoints yet, just return - if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { + if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints > m_CapturePointNumberToEntityMap.size()) { m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); return; } @@ -232,10 +253,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp } -void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) { +void CapturePointSystem::ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner) +{ (Field)capturePointModels["Model"]["Visible"] = isOwner; - for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) - { + for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) { if (capModel.HasComponent("Model")) { (Field)capModel["Model"]["Visible"] = isOwner; } @@ -269,3 +290,9 @@ bool CapturePointSystem::OnCaptured(const Events::Captured& e) m_ResetTimers = true; return true; } + +bool CapturePointSystem::OnReset(const Events::Reset& e) +{ + Init(); + return true; +} \ No newline at end of file diff --git a/src/Game/Systems/ScoreScreenSystem.cpp b/src/Game/Systems/ScoreScreenSystem.cpp index f64388d0..02518b8c 100644 --- a/src/Game/Systems/ScoreScreenSystem.cpp +++ b/src/Game/Systems/ScoreScreenSystem.cpp @@ -9,6 +9,8 @@ ScoreScreenSystem::ScoreScreenSystem(SystemParams params) EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &ScoreScreenSystem::OnPlayerSpawn); EVENT_SUBSCRIBE_MEMBER(m_EPlayerConnected, &ScoreScreenSystem::OnPlayerConnected); EVENT_SUBSCRIBE_MEMBER(m_EPlayerDisconnected, &ScoreScreenSystem::OnPlayerDisconnected); + EVENT_SUBSCRIBE_MEMBER(m_EReset, &ScoreScreenSystem::OnReset); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &ScoreScreenSystem::OnInputCommand); } void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& scoreScreen, double dt) @@ -156,3 +158,25 @@ bool ScoreScreenSystem::OnPlayerDisconnected(const Events::PlayerDisconnected& e m_DisconnectedIdentities.push_back(e.PlayerID); return 0; } + +bool ScoreScreenSystem::OnReset(const Events::Reset & e) +{ + for (auto& it : m_PlayerIdentities) { + it.second.Deaths = 0; + it.second.Kills = 0; + it.second.Team = 1; + it.second.Player = EntityWrapper::Invalid; + } + return true; +} + +bool ScoreScreenSystem::OnInputCommand(const Events::InputCommand & e) +{ + if (e.Command != "PickTeam" || e.PlayerID == -1 || e.Value == 0) { + return false; + } + + m_PlayerIdentities.at(e.PlayerID).Team = e.Value; + + return true; +} diff --git a/src/Game/Systems/SpectatorCameraSystem.cpp b/src/Game/Systems/SpectatorCameraSystem.cpp index 23dfb164..ed624c69 100644 --- a/src/Game/Systems/SpectatorCameraSystem.cpp +++ b/src/Game/Systems/SpectatorCameraSystem.cpp @@ -9,6 +9,7 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params) { EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect); + EVENT_SUBSCRIBE_MEMBER(m_EReset, &SpectatorCameraSystem::OnReset); } void SpectatorCameraSystem::Update(double dt) @@ -27,6 +28,14 @@ void SpectatorCameraSystem::Update(double dt) } } +void SpectatorCameraSystem::reset() +{ + m_CamSetToTeamPick = false; + // They will also be set to menu, so unlock mouse just in case they were in game with locked mouse. + Events::UnlockMouse unlock; + m_EventBroker->Publish(unlock); +} + bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e) { // Only the client should do this, and only if player is not spawned. @@ -95,10 +104,13 @@ bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e) // If local player gets disconnected, they should be set to // the spectator camera next time a map loads that has one. if (e.Entity == LocalPlayer.ID) { - m_CamSetToTeamPick = false; - // They will also be set to menu, so unlock mouse just in case they were in game with locked mouse. - Events::UnlockMouse unlock; - m_EventBroker->Publish(unlock); + reset(); } return true; } + +bool SpectatorCameraSystem::OnReset(const Events::Reset & e) +{ + reset(); + return true; +}