GameServer - Some minor changes
This commit is contained in:
parent
399e0d049c
commit
359c208f57
|
@ -31,6 +31,7 @@ namespace DanBias
|
||||||
*/
|
*/
|
||||||
struct GameDescription
|
struct GameDescription
|
||||||
{
|
{
|
||||||
|
int maxClients;
|
||||||
int mapNumber;
|
int mapNumber;
|
||||||
int gameMode;
|
int gameMode;
|
||||||
int gameTime;
|
int gameTime;
|
||||||
|
|
|
@ -48,12 +48,19 @@ namespace DanBias
|
||||||
bool GameLobby::StartGameSession( )
|
bool GameLobby::StartGameSession( )
|
||||||
{
|
{
|
||||||
GameSession::GameDescription desc;
|
GameSession::GameDescription desc;
|
||||||
|
desc.maxClients = this->description.maxClients;
|
||||||
desc.gameMode = this->description.gameMode;
|
desc.gameMode = this->description.gameMode;
|
||||||
desc.gameTime = this->description.gameTime;
|
desc.gameTime = this->description.gameTime;
|
||||||
desc.mapNumber = this->description.mapNumber;
|
desc.mapNumber = this->description.mapNumber;
|
||||||
desc.owner = this;
|
desc.owner = this;
|
||||||
desc.clients = this->clients;
|
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
|
this->clients.Clear(); //Remove clients from lobby list
|
||||||
|
|
||||||
if(this->gameSession.Create(desc))
|
if(this->gameSession.Create(desc))
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace DanBias
|
||||||
|
|
||||||
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
|
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...
|
//Duh... This was causing alot of problems, it's in the wrong place...
|
||||||
//Need to figure out where to put this frame locker.
|
//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.
|
//We only need to send network packages when necessary, ie not 120 times per frame.
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Queue.h>
|
#include <Queue.h>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#define DELTA_TIME_20 0.05f
|
#define DELTA_TIME_20 0.05f
|
||||||
#define DELTA_TIME_24 0.04166666666666666666666666666667f
|
#define DELTA_TIME_24 0.04166666666666666666666666666667f
|
||||||
|
@ -63,7 +64,8 @@ namespace DanBias
|
||||||
|
|
||||||
/* standard initialization of some data */
|
/* standard initialization of some data */
|
||||||
NetworkSession::clients = desc.clients;
|
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;
|
this->owner = desc.owner;
|
||||||
|
|
||||||
/* Initiate the game instance */
|
/* Initiate the game instance */
|
||||||
|
@ -76,14 +78,17 @@ namespace DanBias
|
||||||
GameLogic::IPlayerData* p = 0;
|
GameLogic::IPlayerData* p = 0;
|
||||||
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
for (unsigned int i = 0; i < desc.clients.Size(); i++)
|
||||||
{
|
{
|
||||||
if( (p = this->gameInstance.CreatePlayer()) )
|
if(desc.clients[i])
|
||||||
{
|
{
|
||||||
desc.clients[i]->SetOwner(this);
|
if( (p = this->gameInstance.CreatePlayer()) )
|
||||||
this->clients.Push(new GameClient(desc.clients[i], p));
|
{
|
||||||
}
|
desc.clients[i]->SetOwner(this);
|
||||||
else
|
this->clients[i] = (new GameClient(desc.clients[i], p));
|
||||||
{
|
}
|
||||||
printf("Failed to create player (%i)\n", i);
|
else
|
||||||
|
{
|
||||||
|
printf("Failed to create player (%i)\n", i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,19 +130,16 @@ namespace DanBias
|
||||||
void GameSession::ThreadEntry( )
|
void GameSession::ThreadEntry( )
|
||||||
{
|
{
|
||||||
//List with clients that we are waiting on..
|
//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
|
//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])
|
if(this->clients[i])
|
||||||
{
|
|
||||||
readyList.Remove(i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
readyList.Push(this->clients[i]);
|
||||||
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation());
|
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)
|
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);
|
client->SetOwner(this);
|
||||||
|
|
||||||
|
@ -188,17 +191,32 @@ namespace DanBias
|
||||||
|
|
||||||
SmartPointer<GameClient> obj = new GameClient(client, player);
|
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])
|
if(!clients[i])
|
||||||
{
|
{
|
||||||
|
NetworkSession::clients[i] = client;
|
||||||
clients[i] = obj;
|
clients[i] = obj;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clients.Push(obj);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ namespace Utility
|
||||||
|
|
||||||
template <typename T> void DynamicArray<T>::Remove(unsigned int index)
|
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];
|
T* temp = new T[this->capacity - 1];
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ namespace Oyster
|
||||||
//bool (1-bit)
|
//bool (1-bit)
|
||||||
bool Unpackb(unsigned char buffer[])
|
bool Unpackb(unsigned char buffer[])
|
||||||
{
|
{
|
||||||
return *buffer;
|
return (bool)(*buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//char (8-bit)
|
//char (8-bit)
|
||||||
|
|
Loading…
Reference in New Issue