From 359c208f57193444550d1d2b1cb8330bb4887fce Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Sat, 15 Feb 2014 09:29:54 +0100 Subject: [PATCH] GameServer - Some minor changes --- Code/Game/GameServer/GameSession.h | 1 + .../GameServer/Implementation/GameLobby.cpp | 7 +++ .../Implementation/GameSession_Gameplay.cpp | 2 +- .../Implementation/GameSession_General.cpp | 60 ++++++++++++------- Code/Misc/DynamicArray.h | 2 +- Code/Misc/Packing/Packing.cpp | 2 +- 6 files changed, 50 insertions(+), 24 deletions(-) diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 80d43a19..b7980605 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -31,6 +31,7 @@ namespace DanBias */ struct GameDescription { + int maxClients; int mapNumber; int gameMode; int gameTime; diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index b5fa8f40..e88da318 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -48,12 +48,19 @@ namespace DanBias bool GameLobby::StartGameSession( ) { GameSession::GameDescription desc; + desc.maxClients = this->description.maxClients; desc.gameMode = this->description.gameMode; desc.gameTime = this->description.gameTime; desc.mapNumber = this->description.mapNumber; desc.owner = this; desc.clients = this->clients; + if(desc.gameTime == 0.0f) + desc.gameTime = (60.0f * 10.0f); //note: Default game time length should be fetched from somewhere. + + if(desc.maxClients == 0) + desc.maxClients = 10; //note: Default should be fetched somewhere else.. + this->clients.Clear(); //Remove clients from lobby list if(this->gameSession.Create(desc)) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index b7d11e42..bbbfff62 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -85,7 +85,7 @@ namespace DanBias void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) { - float dt = GameSession::gameSession->networkTimer.getElapsedSeconds(); + float dt = (float)GameSession::gameSession->networkTimer.getElapsedSeconds(); //Duh... This was causing alot of problems, it's in the wrong place... //Need to figure out where to put this frame locker. //We only need to send network packages when necessary, ie not 120 times per frame. diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index d6e6106c..97cb1f7e 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -10,6 +10,7 @@ #define NOMINMAX #include #include +#include #define DELTA_TIME_20 0.05f #define DELTA_TIME_24 0.04166666666666666666666666666667f @@ -63,7 +64,8 @@ namespace DanBias /* standard initialization of some data */ NetworkSession::clients = desc.clients; - this->clients.Reserve(desc.clients.Size()); + NetworkSession::clients.Resize((unsigned int)desc.maxClients); + this->clients.Resize((unsigned int)desc.maxClients); this->owner = desc.owner; /* Initiate the game instance */ @@ -76,14 +78,17 @@ namespace DanBias GameLogic::IPlayerData* p = 0; for (unsigned int i = 0; i < desc.clients.Size(); i++) { - if( (p = this->gameInstance.CreatePlayer()) ) + if(desc.clients[i]) { - desc.clients[i]->SetOwner(this); - this->clients.Push(new GameClient(desc.clients[i], p)); - } - else - { - printf("Failed to create player (%i)\n", i); + if( (p = this->gameInstance.CreatePlayer()) ) + { + desc.clients[i]->SetOwner(this); + this->clients[i] = (new GameClient(desc.clients[i], p)); + } + else + { + printf("Failed to create player (%i)\n", i); + } } } @@ -125,19 +130,16 @@ namespace DanBias void GameSession::ThreadEntry( ) { //List with clients that we are waiting on.. - DynamicArray> readyList = this->clients; + DynamicArray> readyList;// = this->clients; //First we need to clean invalid clients, if any, and tell them to start loading game data - for (unsigned int i = 0; i < readyList.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(!readyList[i]) - { - readyList.Remove(i); - } - else + if(this->clients[i]) { + readyList.Push(this->clients[i]); Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation()); - readyList[i]->GetClient()->Send(p); + readyList[readyList.Size() - 1]->GetClient()->Send(p); } } @@ -179,7 +181,8 @@ namespace DanBias bool GameSession::Attach(Utility::DynamicMemory::SmartPointer client) { - if(!this->isCreated) return false; + if(!this->isCreated) return false; + if(this->GetClientCount() == this->clients.Capacity()) return false; client->SetOwner(this); @@ -187,17 +190,32 @@ namespace DanBias if(!player) return false; SmartPointer obj = new GameClient(client, player); - - for (unsigned int i = 0; i < clients.Size(); i++) + + // Send the chosen mesh name + Protocol_LobbyCreateGame lcg(obj->GetPlayer()->GetID(), "char_white.dan", obj->GetPlayer()->GetOrientation()); + obj->GetClient()->Send(lcg); + + // Send the player data only + for (unsigned int i = 0; i < this->clients.Capacity(); i++) + { + if(this->clients[i]) + { + Protocol_ObjectCreate oc(this->clients[i]->GetPlayer()->GetOrientation(), this->clients[i]->GetPlayer()->GetID(), "char_white.dan"); + this->clients[i]->GetClient()->Send(oc); + } + } + + obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0)); + + for (unsigned int i = 0; i < this->clients.Size(); i++) { if(!clients[i]) { + NetworkSession::clients[i] = client; clients[i] = obj; return true; } } - - clients.Push(obj); return true; } diff --git a/Code/Misc/DynamicArray.h b/Code/Misc/DynamicArray.h index 8b4c98da..9d7bbc30 100644 --- a/Code/Misc/DynamicArray.h +++ b/Code/Misc/DynamicArray.h @@ -170,7 +170,7 @@ namespace Utility template void DynamicArray::Remove(unsigned int index) { - assert(index > (unsigned int) this->size); + assert(index < (unsigned int) this->size); T* temp = new T[this->capacity - 1]; diff --git a/Code/Misc/Packing/Packing.cpp b/Code/Misc/Packing/Packing.cpp index 30064b0a..df168f70 100644 --- a/Code/Misc/Packing/Packing.cpp +++ b/Code/Misc/Packing/Packing.cpp @@ -167,7 +167,7 @@ namespace Oyster //bool (1-bit) bool Unpackb(unsigned char buffer[]) { - return *buffer; + return (bool)(*buffer); } //char (8-bit)