GameServer - Fixed some minor bugs, one that made server crash on exit. Also integrated some of GameLogics new API functions

This commit is contained in:
Dennis Andersen 2014-01-13 12:44:33 +01:00
parent 2b5a5b2fbd
commit ce89e6bc98
30 changed files with 508 additions and 430 deletions

View File

@ -423,14 +423,14 @@ INetworkSession</panel_attributes>
<element>
<id>UMLClass</id>
<coordinates>
<x>170</x>
<y>400</y>
<w>130</w>
<h>90</h>
<x>150</x>
<y>420</y>
<w>160</w>
<h>50</h>
</coordinates>
<panel_attributes>MapManager
--
Manages and makes sure maps are avalible to all clinents.
Manages all map stuff.
elementstyle=wordwrap
</panel_attributes>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="12.1">
<diagram program="umlet" version="12.2">
<zoom_level>12</zoom_level>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>540</x>
<y>456</y>
<w>132</w>
<y>468</y>
<w>336</w>
<h>36</h>
</coordinates>
<panel_attributes>OysterThread</panel_attributes>
@ -16,9 +16,9 @@
<type>com.umlet.element.Class</type>
<coordinates>
<x>372</x>
<y>408</y>
<y>396</y>
<w>120</w>
<h>36</h>
<h>48</h>
</coordinates>
<panel_attributes>/Some class/</panel_attributes>
<additional_attributes/>
@ -29,11 +29,11 @@
<x>336</x>
<y>300</y>
<w>228</w>
<h>132</h>
<h>120</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;&gt;&gt;&gt;-
&lt;&lt;implements&gt;&gt;</panel_attributes>
<additional_attributes>96;108;96;60;204;60</additional_attributes>
<additional_attributes>96;96;96;60;204;60</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
@ -41,52 +41,30 @@
<x>396</x>
<y>408</y>
<w>168</w>
<h>96</h>
<h>108</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;&lt;-
Creates&gt;&gt;</panel_attributes>
<additional_attributes>36;36;36;72;132;72;144;72</additional_attributes>
<additional_attributes>36;36;36;84;132;84;144;84</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>564</x>
<y>372</y>
<x>660</x>
<y>384</y>
<w>60</w>
<h>108</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>36;84;36;36</additional_attributes>
</element>
<element>
<type>com.umlet.element.Class</type>
<coordinates>
<x>540</x>
<y>540</y>
<w>132</w>
<h>36</h>
</coordinates>
<panel_attributes>OysterMutex</panel_attributes>
<additional_attributes/>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>564</x>
<y>456</y>
<w>60</w>
<h>108</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;&lt;-</panel_attributes>
<additional_attributes>36;36;36;84</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>540</x>
<y>312</y>
<w>336</w>
<h>96</h>
<h>108</h>
</coordinates>
<panel_attributes>/&lt;&lt;interface&gt;&gt;/
IThreadObject
@ -123,16 +101,4 @@ bg=red</panel_attributes>
<panel_attributes>lt=-</panel_attributes>
<additional_attributes>36;36;36;108</additional_attributes>
</element>
<element>
<type>com.umlet.element.Relation</type>
<coordinates>
<x>336</x>
<y>408</y>
<w>228</w>
<h>168</h>
</coordinates>
<panel_attributes>lt=&gt;&gt;.
uses</panel_attributes>
<additional_attributes>60;36;60;144;204;144</additional_attributes>
</element>
</diagram>

View File

@ -3,6 +3,5 @@
BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved )
{
//MessageBox(0, L"DanBiasGame Loaded", 0, 0);
return TRUE;
}

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASGAME_DANBIASGAME_H
#define DANBIASGAME_DANBIASGAME_H

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_ADMIN_INTERFACE_H
#define DANBIASSERVER_ADMIN_INTERFACE_H

View File

@ -179,10 +179,13 @@
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameServer.cpp" />
<ClCompile Include="GameSession\GameClient.cpp" />
<ClCompile Include="GameSession\GameSession_Events.cpp" />
<ClCompile Include="GameSession\GameSession_General.cpp" />
<ClCompile Include="GameSession\GameSession_Network.cpp" />
<ClCompile Include="LobbySessions\INetworkSession.cpp" />
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
<ClCompile Include="LobbySessions\GameLobby.cpp" />
<ClCompile Include="GameSession\GameSession.cpp" />
<ClCompile Include="GameSession\GameSession_Logic.cpp" />
<ClCompile Include="LobbySessions\MainLobby.cpp" />
<ClCompile Include="LobbySessions\NetworkSession.cpp" />
</ItemGroup>

View File

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIAS_SERVER_DANBIAS_SERVER_H
#define DANBIAS_SERVER_DANBIAS_SERVER_H

View File

@ -22,6 +22,7 @@ namespace DanBias
{
using namespace Oyster::Network;
GameServer* GameServer::instance = 0;
void GameServer::NetworkCallback(NetworkClient* client)
{
@ -38,7 +39,7 @@ namespace DanBias
desc.clients.Push(c);
desc.exitDestionation = this->mainLobby;
if((sessionId = GameSessionManager::AddSession(desc, true)) == 0)
printf("Failed to create a game session");
printf("Failed to create a game session\n");
myTest = true;
//myTest = new GameSession();
//
@ -68,7 +69,7 @@ namespace DanBias
, maxClients(0)
, mainLobby(0)
, server(0)
{ }
{ this->instance = this; }
GameServer::~GameServer()
{
@ -89,7 +90,6 @@ namespace DanBias
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
//if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
this->initiated = true;
return DanBiasServerReturn_Sucess;
@ -108,10 +108,9 @@ namespace DanBias
{
if(!WindowShell::Frame()) break;
this->mainLobby->Frame();
if(GetAsyncKeyState(0x51))
if(GetAsyncKeyState(0x51)) //Q for exit
break;
}
@ -128,6 +127,11 @@ namespace DanBias
return DanBiasServerReturn_Sucess;
}
NetworkSession* GameServer::MainLobbyInstance()
{
return GameServer::instance->mainLobby;
}
bool GameServer::LoadIniFile(InitData& ini)
{
std::ifstream in;

View File

@ -21,6 +21,8 @@ namespace DanBias
DanBiasServerReturn Run();
DanBiasServerReturn Release();
static NetworkSession* MainLobbyInstance();
private:
//static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient);
void NetworkCallback(Oyster::Network::NetworkClient* client) override;
@ -31,6 +33,7 @@ namespace DanBias
int maxClients;
MainLobby *mainLobby;
Oyster::Network::NetworkServer *server;
static GameServer* instance;
private:
struct InitData

View File

@ -4,16 +4,22 @@
#include "GameClient.h"
#include "..\LobbySessions\NetworkSession.h"
#include <Game.h>
#include <GameProtocols.h>
using namespace Utility::DynamicMemory;
using namespace DanBias;
using namespace GameLogic;
GameClient::GameClient(SmartPointer<LobbyClient> client, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
static int gameClientIDCount = 1;
GameClient::GameClient(SmartPointer<LobbyClient> client, Game::PlayerData player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
{
this->callbackValue = value;
this->client = client;
this->player = new GameLogic::Player();
//this->player = new GameLogic::Player();
this->id = gameClientIDCount++;
this->player = player;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.callbackType = Oyster::Callback::CallbackType_Object;
c.value = this;
@ -22,8 +28,11 @@ GameClient::GameClient(SmartPointer<LobbyClient> client, Oyster::Callback::Oyste
}
GameClient::~GameClient()
{
this->client->Disconnect();
this->player.Release();
if(this->client) this->client->Disconnect();
this->player.playerID = 0;
this->player.teamID = 0;
this->id = -1;
//this->player.Release();
}
void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
@ -31,15 +40,35 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSessi
this->callbackValue = value;
}
GameLogic::Player* GameClient::GetPlayer()
//GameLogic::Player* GameClient::GetPlayer()
//{
// return this->player.Get();
//}
GameLogic::Game::PlayerData* GameClient::GetPlayer()
{
return this->player.Get();
return &this->player;
}
LobbyClient* GameClient::GetClient()
GameLogic::Game::PlayerData GameClient::ReleasePlayer()
{
GameLogic::Game::PlayerData temp = this->player;
this->player.playerID = 0;
this->player.teamID = 0;
return temp;
}
LobbyClient* GameClient::GetClient() const
{
return this->client;
}
Utility::DynamicMemory::SmartPointer<LobbyClient> GameClient::ReleaseClient()
{
SmartPointer<LobbyClient> temp = this->client;
this->client = 0;
return temp;
}
int GameClient::GetID() const
{
return this->id;
}
void GameClient::ObjectCallback(NetworkSession::NetEvent e)
{
e.gameClient = this;

View File

@ -6,28 +6,34 @@
#include "..\LobbySessions\LobbyClient.h"
#include <PostBox\PostBox.h>
#include <Player.h>
#include <Game.h>
namespace DanBias
{
class GameClient: Oyster::Callback::CallbackObject<void, NetworkSession::NetEvent>
{
public:
GameClient(Utility::DynamicMemory::SmartPointer<LobbyClient> client, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
GameClient(Utility::DynamicMemory::SmartPointer<LobbyClient> client, GameLogic::Game::PlayerData player, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
virtual~GameClient();
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
GameLogic::Player* GetPlayer();
LobbyClient* GetClient();
//GameLogic::Player* GetPlayer();
GameLogic::Game::PlayerData* GetPlayer();
GameLogic::Game::PlayerData ReleasePlayer();
LobbyClient* GetClient() const;
Utility::DynamicMemory::SmartPointer<LobbyClient> ReleaseClient();
int GetID() const;
private:
Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
//Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
GameLogic::Game::PlayerData player;
Utility::DynamicMemory::SmartPointer<LobbyClient> client;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
int id;
void ObjectCallback(NetworkSession::NetEvent) override;
private:
friend class AdminInterface;
};

View File

@ -1,326 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
void InsertObject(DynamicArray<SmartPointer<GameClient>>& clients, SmartPointer<GameClient> obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(!clients[i])
{
clients[i] = obj;
return;
}
}
clients.Push(obj);
}
void RemoveObject(DynamicArray<SmartPointer<GameClient>>& clients, DanBias::GameClient* obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(clients[i] && clients[i]->GetClient()->GetID() == obj->GetClient()->GetID())
{
clients[i] = 0;
return;
}
}
}
GameSession::GameSession()
{
this->owner = 0;
this->box = 0;
this->isCreated = false;
this->isRunning = false;
}
GameSession::~GameSession()
{
delete this->box;
this->box = 0;
this->owner = 0;
}
bool GameSession::Create(GameDescription& desc)
{
if(desc.clients.Size() == 0) return false;
if(!desc.owner) return false;
if(!desc.mapName.size()) return false;
if(this->isCreated) return false;
this->clients.Resize(desc.clients.Size());
this->box = new PostBox<NetworkSession::NetEvent>();
this->owner = desc.owner;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
this->clients[i] = new GameClient(desc.clients[i], c);
}
this->isCreated = true;
return true;
}
void GameSession::Run()
{
if(this->isRunning) return;
if(this->clients.Size() > 0)
{
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return;
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2);
this->isRunning = true;
}
}
bool GameSession::Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{
if(!this->isCreated) return false;
Oyster::Callback::OysterCallback<void, DanBias::NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
SmartPointer<GameClient> obj = new GameClient(client, c);
InsertObject(this->clients, obj);
return true;
}
void GameSession::CloseSession(bool dissconnectClients)
{
this->worker.Stop(false);
//NetworkSession::CloseSession(dissconnectClients);
this->isCreated = false;
this->isRunning = false;
}
////private: //overriden Threading functions
bool GameSession::DoWork ( )
{
this->Frame();
return true;
}
#ifndef ERIK
////private:
void GameSession::Frame()
{
this->ParseEvents();
if(GetAsyncKeyState(VK_UP))
{
Protocol_General_Status p(Protocol_General_Status::States_ready);
Send(p.GetProtocol());
Sleep(100);
}
}
void GameSession::ParseEvents()
{
if( !this->box->IsEmpty() )
{
NetworkSession::NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGameplayEvent(e.protocol, e.gameClient);
if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGeneralEvent(e.protocol, e.gameClient);
}
}
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
{
Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
if(p[1].value.netBool) //bool bForward;
world.v[3].x = 2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
world.v[3].x = -2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
world.v[3].y = 2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
world.v[3].y = -2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
Protocol_ObjectPosition res(world, 0);
Send(res.GetProtocol());
}
break;
case protocol_Gameplay_PlayerMouseMovement:
break;
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
break;
}
}
void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_General_Status:
switch (p[1].value.netInt)
{
case GameLogic::Protocol_General_Status::States_bussy:
break;
case GameLogic::Protocol_General_Status::States_disconected:
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
RemoveObject(this->clients, c);
break;
case GameLogic::Protocol_General_Status::States_idle:
break;
case GameLogic::Protocol_General_Status::States_ready:
break;
}
break;
case protocol_General_Text:
break;
}
}
void GameSession::Send(Oyster::Network::CustomNetProtocol* p)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i] && this->clients[i]->GetClient())
this->clients[i]->GetClient()->Send(p);
}
}
#else
#include "DynamicObject.h"
//#include "CollisionManager.h"
//#include "GameLogicStates.h"
//#include <GameProtocols.h>
/*
using namespace GameLogic;
//VARIABLES GOES HERE
DynamicObject* objectBox;
bool GameSession::Init(GameSessionDescription& desc)
{
if(desc.clients.Size() == 0) return false;
this->box = new PostBox<NetEvent>();
this->owner = desc.owner;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
desc.clients[i]->SetPostbox(this->box);
this->clients.Push(desc.clients[i]);
}
CollisionManager::BoxCollision(0,0);
objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX);
Protocol_CreateObject objectCreation;
objectCreation.object_ID = objectBox->GetID();
objectCreation.path = "crate";
Oyster::Math::Float4x4 worldMat = objectBox->GetRigidBody()->GetOrientation();
for (int i = 0; i < 16; i++)
{
objectCreation.worldMatrix[i] = worldMat[i];
}
for (int i = 0; i < clients.Size(); i++)
{
clients[i]->NetClient_Object()->Send(objectCreation);
}
return true;
}
void GameSession::Frame()
{
}
void GameSession::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
ParseProtocol(e.protocol, *e.reciever);
}
}
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
switch (p[0].value.netShort)
{
case protocol_Gamplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
}
break;
case protocol_Gamplay_PlayerMouseMovement:
break;
case protocol_Gamplay_PlayerPosition:
break;
case protocol_Gamplay_CreateObject:
break;
case protocol_Gamplay_ObjectPosition:
break;
}
}
*/
#endif
}//End namespace DanBias

View File

@ -4,12 +4,14 @@
#ifndef DANBIASSERVER_GAME_SESSION_H
#define DANBIASSERVER_GAME_SESSION_H
//warning C4150: deletion of pointer to incomplete type, no destructor called
//warning C4150: deletion of pointer to incomplete type, no destructor called, because of forward decleration and the use of smartpointer.
#pragma warning(disable: 4150)
#include "..\LobbySessions\NetworkSession.h"
#include <WinTimer.h>
#include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h>
#include <Game.h>
namespace DanBias
{
@ -18,6 +20,9 @@ namespace DanBias
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
{
public:
/**
* A container to use when initiating a new session
*/
struct GameDescription
{
std::wstring mapName;
@ -41,31 +46,44 @@ namespace DanBias
bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
/**
*
* Closes the game session
* @param disconnectClients If set to true clients is dissconnected from the server, if false the clients is sent to the given owner of the session.
*/
void CloseSession(bool dissconnectClients = false);
void CloseSession(bool disconnectClients = false);
inline bool IsCreated() const { return this->isCreated; }
inline bool IsRunning() const { return this->isRunning; }
//Private member functions
private:
void Frame();
//Handles all events recieved
void ParseEvents();
//Handles all gameplay events
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Handles all general events
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
//Adds a client to the client list
void AddClient(Utility::DynamicMemory::SmartPointer<GameClient> obj);
//Removes a client from the client list
void RemoveClient(DanBias::GameClient* obj);
//Sends a protocol ta all clients in session
void Send(Oyster::Network::CustomNetProtocol* p);
private: //overriden Threading functions
//Frame function, derived from IThreadObject
bool DoWork ( ) override;
//Sends a client to the owner, if obj is NULL then all clients is sent
void SendToOwner(DanBias::GameClient* obj);
//Do a cleanup on all the private data
void Clean();
//Private member variables
private:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
NetworkSession* owner;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
GameLogic::Game gameInstance;
NetworkSession* owner;
Utility::WinTimer timer;
bool isCreated;
bool isRunning;

View File

@ -0,0 +1,114 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <OysterMath.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
void GameSession::ParseEvents()
{
if( !this->box->IsEmpty() )
{
NetworkSession::NetEvent &e = this->box->Fetch();
if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return;
if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGameplayEvent(e.protocol, e.gameClient);
if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) )
ParseGeneralEvent(e.protocol, e.gameClient);
}
}
void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
{
Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
if(p[1].value.netBool) //bool bForward;
world.v[3].x = 2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
world.v[3].x = -2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
world.v[3].y = 2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
world.v[3].y = -2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
Protocol_ObjectPosition res(world, 0);
Send(res.GetProtocol());
}
break;
case protocol_Gameplay_PlayerMouseMovement:
break;
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
break;
}
}
void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c)
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_General_Status:
switch (p[1].value.netInt)
{
case GameLogic::Protocol_General_Status::States_bussy:
break;
case GameLogic::Protocol_General_Status::States_disconected:
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
this->RemoveClient(c);
break;
case GameLogic::Protocol_General_Status::States_idle:
break;
case GameLogic::Protocol_General_Status::States_ready:
break;
}
break;
case protocol_General_Text:
break;
}
}
}//End namespace DanBias

View File

@ -0,0 +1,167 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include "..\GameServer.h"
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
GameSession::GameSession()
{
this->owner = 0;
this->box = 0;
this->isCreated = false;
this->isRunning = false;
}
GameSession::~GameSession()
{
delete this->box;
this->box = 0;
this->owner = 0;
}
bool GameSession::Create(GameDescription& desc)
{
if(desc.clients.Size() == 0) return false;
if(!desc.owner) return false;
if(!desc.mapName.size()) return false;
if(this->isCreated) return false;
this->clients.Resize(desc.clients.Size());
this->box = new PostBox<NetworkSession::NetEvent>();
this->owner = desc.owner;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
for (unsigned int i = 0; i < desc.clients.Size(); i++)
{
this->clients[i] = new GameClient(desc.clients[i], gameInstance.CreatePlayer(), c);
}
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return false;
this->isCreated = true;
return true;
}
void GameSession::Run()
{
if(this->isRunning) return;
if(this->clients.Size() > 0)
{
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2);
this->isRunning = true;
}
}
bool GameSession::Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{
if(!this->isCreated) return false;
Oyster::Callback::OysterCallback<void, DanBias::NetworkSession::NetEvent> c;
c.value.callbackPostBox = this->box;
c.callbackType = Oyster::Callback::CallbackType_PostBox;
SmartPointer<GameClient> obj = new GameClient(client, this->gameInstance.CreatePlayer(), c);
AddClient(obj);
return true;
}
void GameSession::CloseSession(bool dissconnectClients)
{
if(dissconnectClients)
{
for (int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->GetClient()->Disconnect();
}
}
else
{
this->SendToOwner(0); //Send all clients to the current owner
}
this->Clean();
}
void GameSession::AddClient(SmartPointer<GameClient> obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(!clients[i])
{
clients[i] = obj;
return;
}
}
clients.Push(obj);
}
void GameSession::RemoveClient(DanBias::GameClient* obj)
{
for (unsigned int i = 0; i < clients.Size(); i++)
{
if(clients[i] && clients[i]->GetID() == obj->GetID())
{
clients[i] = 0;
return;
}
}
}
void GameSession::SendToOwner(DanBias::GameClient* obj)
{
DanBias::NetworkSession *s = GameServer::MainLobbyInstance();
if(this->owner) s = this->owner;
if(obj)
{
s->Attach(obj->ReleaseClient());
RemoveClient(obj);
}
else
{
for (int i = 0; i < this->clients.Size(); i++)
{
s->Attach(this->clients[i]->ReleaseClient());
RemoveClient(this->clients[i]);
}
}
}
void GameSession::Clean()
{
this->worker.Terminate();
this->clients.Clear();
delete this->box;
this->box = 0;
this->gameInstance;
this->owner = 0;
this->isCreated = false;
this->isRunning = false;
}
}//End namespace DanBias

View File

@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
bool GameSession::DoWork( )
{
this->gameInstance.NewFrame();
this->ParseEvents();
if(GetAsyncKeyState(VK_UP))
{
Protocol_General_Status p(Protocol_General_Status::States_ready);
Send(p.GetProtocol());
Sleep(100);
}
return this->isRunning;
}
}//End namespace DanBias

View File

@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSession.h"
#include "GameClient.h"
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include <GameLogicStates.h>
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
void GameSession::Send(Oyster::Network::CustomNetProtocol* p)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i] && this->clients[i]->GetClient())
this->clients[i]->GetClient()->Send(p);
}
}
}//End namespace DanBias

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_LEVELMANAGER_H
#define DANBIASSERVER_LEVELMANAGER_H

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_INETWORKSESSION_H
#define DANBIASSERVER_INETWORKSESSION_H

View File

@ -1,3 +1,6 @@
/////////////////////////////////////////
// Created by [Dennis Andersen] [2013] //
/////////////////////////////////////////
#ifndef DANBIASSERVER_LOBBYCLIENT_H
#define DANBIASSERVER_LOBBYCLIENT_H

View File

@ -1,5 +1,5 @@
//////////////////////////////////////////////////
// Launcher to launch Danbias server or client //
// Launcher to launch Danbias server //
// Created by [Dennis Andersen] [2013] //
//////////////////////////////////////////////////
#define NOMINMAX //Blame it on windows

View File

@ -1,6 +1,7 @@
#include "Game.h"
#include "Player.h"
#include "Level.h"
#include <GID.h>
using namespace GameLogic;
@ -57,7 +58,12 @@ void Game::GetAllPlayerPos()
Game::PlayerData Game::CreatePlayer()
{
PlayerData data;
//Yo mammma
data.playerID = GID();
data.teamID = -1;
return data;
}
void Game::CreateTeam()

View File

@ -1,10 +1,16 @@
/////////////////////////////////////////////////////////////////////
// Created by [Erik Persson] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef GAME_H
#define GAME_H
#include "GameLogicDef.h"
#include "GameLogicStates.h"
namespace GameLogic
{
class Game
class DANBIAS_GAMELOGIC_DLL Game
{
public:

View File

@ -132,7 +132,7 @@ Oyster::Math::Float3 Player::GetPos()
Oyster::Math::Float3 Player::GetLookDir()
{
return myData->lookDir;
return myData->lookDir.xyz;
}
int Player::GetTeamID()

View File

@ -4,14 +4,13 @@
#ifndef PLAYER_H
#define PLAYER_H
#include "GameLogicStates.h"
#include "GameLogicDef.h"
#include "OysterMath.h"
#include "Object.h"
namespace GameLogic
{
class DANBIAS_GAMELOGIC_DLL Player : public Object
class Player : public Object
{
public:

View File

@ -71,13 +71,13 @@ namespace Oyster
//OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackObject<bool, void>* worker, bool start, bool detach = false);
//OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach = false);
OYSTER_THREAD_ERROR Start();
OYSTER_THREAD_ERROR Stop(bool wait = false);
OYSTER_THREAD_ERROR Stop();
OYSTER_THREAD_ERROR Pause();
OYSTER_THREAD_ERROR Pause(int mSec);
OYSTER_THREAD_ERROR Resume();
OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0);
OYSTER_THREAD_ERROR SetWorker(ThreadFnc worker = 0);
OYSTER_THREAD_ERROR Terminate(bool wait = true);
OYSTER_THREAD_ERROR Terminate();
OYSTER_THREAD_ERROR Wait();
OYSTER_THREAD_ERROR Wait(int mSec);
OYSTER_THREAD_ERROR Swap(const OysterThread* other);

View File

@ -72,10 +72,10 @@ using namespace Utility::DynamicMemory;
~RefData()
{
//threadWaitFunctionLock.lock();
Terminate(true);
Terminate();
//threadWaitFunctionLock.unlock();
}
OYSTER_THREAD_ERROR Terminate(bool wait)
OYSTER_THREAD_ERROR Terminate()
{
if(!threadData) return OYSTER_THREAD_ERROR_SUCCESS;
@ -129,12 +129,12 @@ using namespace Utility::DynamicMemory;
data = new RefData();
return data->Create(fnc, worker, start, detach);
}
OYSTER_THREAD_ERROR Terminate(bool wait)
OYSTER_THREAD_ERROR Terminate()
{
if(!data)
return OYSTER_THREAD_ERROR_FAILED;
return data->Terminate(wait);
return data->Terminate();
}
};
@ -256,9 +256,9 @@ OYSTER_THREAD_ERROR OysterThread::Start()
return OYSTER_THREAD_ERROR_SUCCESS;
}
OYSTER_THREAD_ERROR OysterThread::Stop(bool wait)
OYSTER_THREAD_ERROR OysterThread::Stop()
{
return this->Terminate(wait);
return this->Terminate();
}
OYSTER_THREAD_ERROR OysterThread::Pause()
{
@ -297,9 +297,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker)
return OYSTER_THREAD_ERROR_SUCCESS;;
}
OYSTER_THREAD_ERROR OysterThread::Terminate(bool wait)
OYSTER_THREAD_ERROR OysterThread::Terminate()
{
return this->privateData->Terminate(wait);
return this->privateData->Terminate();
}
OYSTER_THREAD_ERROR OysterThread::Wait()
{

View File

@ -292,7 +292,8 @@ namespace Utility
this->_ptr = p;
if(p) this->_rc->Incref();
if(p) this->_rc->Incref();
else this->_rc = 0;
}
return *this;
}

View File

@ -115,7 +115,7 @@ void NetworkServer::PrivateData::Stop()
started = false;
thread.Stop(true);
thread.Stop();
}
void NetworkServer::PrivateData::Shutdown()

View File

@ -9,9 +9,11 @@ namespace Oyster
{
namespace Model
{
//struct ModelInfo;
struct Model
{
//! do not Edit, linked to render data
//ModelInfo* info;
void* info;
Oyster::Math::Float4x4 WorldMatrix;
bool Visible;