GameServer - Some minor changes

This commit is contained in:
Dennis Andersen 2014-02-15 09:29:54 +01:00
parent 399e0d049c
commit 359c208f57
6 changed files with 50 additions and 24 deletions

View File

@ -31,6 +31,7 @@ namespace DanBias
*/
struct GameDescription
{
int maxClients;
int mapNumber;
int gameMode;
int gameTime;

View File

@ -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))

View File

@ -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.

View File

@ -10,6 +10,7 @@
#define NOMINMAX
#include <Windows.h>
#include <Queue.h>
#include <future>
#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<SmartPointer<GameClient>> readyList = this->clients;
DynamicArray<SmartPointer<GameClient>> 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<NetworkClient> 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<GameClient> 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;
}

View File

@ -170,7 +170,7 @@ namespace Utility
template <typename T> void DynamicArray<T>::Remove(unsigned int index)
{
assert(index > (unsigned int) this->size);
assert(index < (unsigned int) this->size);
T* temp = new T[this->capacity - 1];

View File

@ -167,7 +167,7 @@ namespace Oyster
//bool (1-bit)
bool Unpackb(unsigned char buffer[])
{
return *buffer;
return (bool)(*buffer);
}
//char (8-bit)