Time for ending the game is now in CapturePointGameMode component. The timer i counted down to 0 and then the map is "Reset".
This commit is contained in:
@@ -43,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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
Server(World* world, EventBroker* eventBroker, int port);
|
||||
~Server();
|
||||
|
||||
void Update() override;
|
||||
void Update(double dt) override;
|
||||
|
||||
private:
|
||||
// Network channels
|
||||
@@ -44,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;
|
||||
@@ -87,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();
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ Server::~Server()
|
||||
|
||||
}
|
||||
|
||||
void Server::Update()
|
||||
void Server::Update(double dt)
|
||||
{
|
||||
m_Reliable.AcceptNewConnections(m_NextPlayerID, m_ConnectedPlayers);
|
||||
|
||||
@@ -106,7 +106,23 @@ void Server::Update()
|
||||
}
|
||||
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.
|
||||
double& timer = (double&)modeComponent["ResetCountdown"];
|
||||
timer -= dt;
|
||||
if (timer < 0) {
|
||||
resetMap();
|
||||
}
|
||||
} else {
|
||||
resetMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +181,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
|
||||
@@ -550,18 +566,8 @@ bool Server::OnPlayerDeath(const Events::PlayerDeath& e)
|
||||
|
||||
bool Server::OnWin(const Events::Win & e)
|
||||
{
|
||||
// Postpone this code and trigger after some time in a update
|
||||
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);
|
||||
// Postpone the gameover reset
|
||||
m_GameIsOver = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -686,4 +692,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
@@ -229,10 +229,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user