Compare commits

...

8 Commits

Author SHA1 Message Date
Jocke 5ea0f04b20 Added pop up for client when server timeouts. 2016-03-13 16:21:55 +01:00
William Moberg ac20e41a5d Fixed merge conflicts. Scoreboard updates team when a team is picked. Fixed some code standard violations and misspellings. 2016-03-13 14:23:56 +01:00
William Moberg 4f99f6ef74 Merge branch 'master' into RestartMap
# Conflicts:
#	src/Game/Systems/CapturePointSystem.cpp
2016-03-13 13:37:51 +01:00
Jocke b7d88808e2 Redid timers. 2016-03-12 21:38:46 +01:00
Jocke f8f536802f Time for ending the game is now in CapturePointGameMode component. The timer i counted down to 0 and then the map is "Reset". 2016-03-12 20:28:48 +01:00
Jocke 60df30fa59 Scoreboard is now works. 2016-03-12 19:36:12 +01:00
Jocke c544f349fd The logic for removing the world is working but when we send the map again the clients memory usage goes crazy. 2016-03-12 17:49:50 +01:00
Jocke 0c1a2d3160 WIP 2016-03-12 14:31:15 +01:00
18 changed files with 260 additions and 81 deletions
+2 -2
View File
@@ -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"
+26 -22
View File
@@ -10,28 +10,32 @@
#include <boost/asio.hpp>
#include <boost/shared_array.hpp>
#include "Core/World.h"
#include "Core/EntityFile.h"
#include "Core/EventBroker.h"
#include "Core/ConfigFile.h"
#include "Core/EPlayerDeath.h"
#include "Core/EPlayerDamage.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Game/Events/EDoubleJump.h"
#include "Game/Events/EDashAbility.h"
#include "Game/Events/EReset.h"
#include "Input/EInputCommand.h"
#include "imgui/imgui.h"
#include "Network/Network.h"
#include "Network/MessageType.h"
#include "Network/PlayerDefinition.h"
#include "Network/UDPClient.h"
#include "Network/TCPClient.h"
#include "Network/SnapshotDefinitions.h"
#include "Core/World.h"
#include "Core/EntityFile.h"
#include "Core/EventBroker.h"
#include "Core/ConfigFile.h"
#include "Core/EPlayerDeath.h"
#include "Input/EInputCommand.h"
#include "Core/EPlayerDamage.h"
#include "../Game/Events/EDoubleJump.h"
#include "Network/EInterpolate.h"
#include "Network/SnapshotFilter.h"
#include "Core/EPlayerSpawned.h"
#include "Core/EAmmoPickup.h"
#include "Network/ESearchForServers.h"
#include "../Game/Events/EDashAbility.h"
#include "Network/EDisplayServerlist.h"
#include "Network/EConnectRequest.h"
#include "Network/EPlayerDisconnected.h"
#include "Network/ESearchForServers.h"
#include "Network/EInterpolate.h"
#include "Network/SnapshotFilter.h"
class Client : public Network
{
public:
@@ -40,7 +44,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 +78,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<Events::InputCommand> m_InputCommandBuffer;
// Private member functions
@@ -100,6 +104,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 +114,6 @@ private:
void sendLocalPlayerTransform();
void becomePlayer();
void displayServerlist();
void removeWorld();
void createMainMenu();
// Mapping Logic
// Returns if local EntityID exist in map
@@ -138,8 +142,8 @@ private:
UDPClient m_ServerlistRequest;
std::vector<ServerInfo> 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
+1
View File
@@ -23,6 +23,7 @@ enum class MessageType
OnDashEffect,
ServerlistRequest,
AmmoPickup,
RemoveWorld,
Invalid
};
+2 -1
View File
@@ -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
+16 -8
View File
@@ -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<PlayerID, PlayerDefinition> m_ConnectedPlayers;
std::vector<PlayerID> 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<Events::InputCommand> 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<Server, Events::PlayerDeath> m_EPlayerDeath;
bool OnPlayerDeath(const Events::PlayerDeath& e);
EventRelay<Server, Events::Win> m_EWin;
bool OnWin(const Events::Win& e);
};
#endif
+16
View File
@@ -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
@@ -9,6 +9,7 @@
#include "Engine/Collision/ETrigger.h"
#include "Core/ECaptured.h"
#include "Core/EWin.h"
#include "Game/Events/EReset.h"
#include <tuple>
#include <vector>
@@ -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<CapturePointSystem, Events::TriggerTouch> m_ETriggerTouch;
bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e);
@@ -30,6 +32,8 @@ private:
bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e);
EventRelay<CapturePointSystem, Events::Captured> m_ECaptured;
bool CapturePointSystem::OnCaptured(const Events::Captured& e);
EventRelay<CapturePointSystem, Events::Reset> m_EReset;
bool CapturePointSystem::OnReset(const Events::Reset& e);
void ChangeCapturePointModelsVisibility(EntityWrapper &capturePointModels, bool isOwner);
bool m_WinnerWasFound = false;
+6
View File
@@ -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<ScoreScreenSystem, Events::PlayerDisconnected> m_EPlayerDisconnected;
bool OnPlayerDisconnected(const Events::PlayerDisconnected& e);
EventRelay<ScoreScreenSystem, Events::Reset> m_EReset;
bool OnReset(const Events::Reset& e);
EventRelay<ScoreScreenSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
private:
struct PlayerData {
@@ -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<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
EventRelay<SpectatorCameraSystem, Events::PlayerDisconnected> m_EDisconnect;
bool OnDisconnect(const Events::PlayerDisconnected& e);
EventRelay<SpectatorCameraSystem, Events::Reset> m_EReset;
bool OnReset(const Events::Reset& e);
};
#endif
@@ -2,4 +2,5 @@
<CapturePointGameMode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CapturePointGameMode.xsd">
<RespawnTime>0.0</RespawnTime>
<MaxRespawnTime>8.0</MaxRespawnTime>
<ResetCountdown>10.0</ResetCountdown>
</CapturePointGameMode>
@@ -12,6 +12,9 @@
<xs:element name="MaxRespawnTime" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Players will be spawned when RespawnTime reaches this.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ResetCountdown" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>The map will be reset when time reaches 0.</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
+31 -22
View File
@@ -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<ConfigFile>("Config.ini");
m_PlayerName = config->Get<std::string>("Networking.Name", "Raptorcopter");
m_SendInputIntervalMs = config->Get<int>("Networking.SendInputIntervalMs", 33);
m_SendInputInterval = config->Get<int>("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<Client>();
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,16 +98,25 @@ 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();
hasServerTimedOut();
}
//Network::Update();
if (ImGui::BeginPopupModal("Disconnected", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("You have been disconnected from server.\n\n");
ImGui::SetCursorPosX(ImGui::GetContentRegionAvailWidth() - 120);
if (ImGui::Button("OK", ImVec2(120, 0))) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
void Client::parseMessageType(Packet& packet)
@@ -159,6 +170,9 @@ void Client::parseMessageType(Packet& packet)
case MessageType::AmmoPickup:
parseAmmoPickup(packet);
break;
case MessageType::RemoveWorld:
parseRemoveWorld(packet);
break;
default:
break;
}
@@ -190,7 +204,7 @@ void Client::parseTCPConnect(Packet& packet)
packet.WritePrimitive(m_PlayerID);
m_Unreliable.Send(packet);
// LOG_INFO("Sent UDP Connect Server");
// LOG_INFO("Sent UDP Connect Server");
}
void Client::parsePlayerConnected(Packet & packet)
@@ -336,6 +350,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 +604,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
@@ -663,6 +684,7 @@ void Client::hasServerTimedOut()
if (timeSincePing > m_TimeoutMs) {
// Clear everything and go to menu.
LOG_INFO("Server has timed out, returning to menu, Beep Boop.");
ImGui::OpenPopup("Disconnected");
disconnect();
}
}
@@ -706,19 +728,6 @@ void Client::displayServerlist()
}
}
void Client::removeWorld()
{
std::vector<EntityID> 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<EntityFile>("Schema/Entities/StartMenu.xml");
+13 -1
View File
@@ -9,7 +9,7 @@ Network::Network(World* world, EventBroker* eventBroker)
m_TimeoutMs = config->Get<int>("Networking.TimeoutMs", 20000);
}
void Network::Update()
void Network::Update(double dt)
{
updateNetworkData();
}
@@ -92,3 +92,15 @@ void Network::popNetworkSegmentOfHeader(Packet & packet)
packet.ReadPrimitive<int>();
packet.ReadPrimitive<int>();
}
void Network::removeWorld()
{
std::vector<EntityID> 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]);
}
}
+62 -15
View File
@@ -5,8 +5,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
, m_ServerlistRequest(13)
{
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05f);
pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
snapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05);
pingInterval = config->Get<float>("Networking.PingIntervalMs", 1000) / 1000.0;
m_ServerName = config->Get<std::string>("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<float>("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<Server>();
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<double> 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<EntityFile>("Schema/Entities/CP_Rocky2.xml");
entityFile->MergeInto(m_World);
Packet newWorld(MessageType::Snapshot);
createWorldSnapshot(newWorld);
reliableBroadcast(newWorld);
}
+2 -2
View File
@@ -232,10 +232,10 @@ void Game::Tick()
PerformanceTimer::StartTimerAndStopPrevious("Network");
m_EventBroker->Process<MultiplayerSnapshotFilter>();
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);
+31 -4
View File
@@ -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<bool>)capturePointModels["Model"]["Visible"] = isOwner;
for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform"))
{
for (auto& capModel : capturePointModels.ChildrenWithComponent("Transform")) {
if (capModel.HasComponent("Model")) {
(Field<bool>)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;
}
+24
View File
@@ -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;
}
+16 -4
View File
@@ -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;
}