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:
parent
2b5a5b2fbd
commit
ce89e6bc98
|
@ -423,14 +423,14 @@ INetworkSession</panel_attributes>
|
||||||
<element>
|
<element>
|
||||||
<id>UMLClass</id>
|
<id>UMLClass</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>170</x>
|
<x>150</x>
|
||||||
<y>400</y>
|
<y>420</y>
|
||||||
<w>130</w>
|
<w>160</w>
|
||||||
<h>90</h>
|
<h>50</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>MapManager
|
<panel_attributes>MapManager
|
||||||
--
|
--
|
||||||
Manages and makes sure maps are avalible to all clinents.
|
Manages all map stuff.
|
||||||
|
|
||||||
elementstyle=wordwrap
|
elementstyle=wordwrap
|
||||||
</panel_attributes>
|
</panel_attributes>
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?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>
|
<zoom_level>12</zoom_level>
|
||||||
<element>
|
<element>
|
||||||
<type>com.umlet.element.Class</type>
|
<type>com.umlet.element.Class</type>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>540</x>
|
<x>540</x>
|
||||||
<y>456</y>
|
<y>468</y>
|
||||||
<w>132</w>
|
<w>336</w>
|
||||||
<h>36</h>
|
<h>36</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>OysterThread</panel_attributes>
|
<panel_attributes>OysterThread</panel_attributes>
|
||||||
|
@ -16,9 +16,9 @@
|
||||||
<type>com.umlet.element.Class</type>
|
<type>com.umlet.element.Class</type>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>372</x>
|
<x>372</x>
|
||||||
<y>408</y>
|
<y>396</y>
|
||||||
<w>120</w>
|
<w>120</w>
|
||||||
<h>36</h>
|
<h>48</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>/Some class/</panel_attributes>
|
<panel_attributes>/Some class/</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
|
@ -29,11 +29,11 @@
|
||||||
<x>336</x>
|
<x>336</x>
|
||||||
<y>300</y>
|
<y>300</y>
|
||||||
<w>228</w>
|
<w>228</w>
|
||||||
<h>132</h>
|
<h>120</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=>>>>>-
|
<panel_attributes>lt=>>>>>-
|
||||||
<<implements>></panel_attributes>
|
<<implements>></panel_attributes>
|
||||||
<additional_attributes>96;108;96;60;204;60</additional_attributes>
|
<additional_attributes>96;96;96;60;204;60</additional_attributes>
|
||||||
</element>
|
</element>
|
||||||
<element>
|
<element>
|
||||||
<type>com.umlet.element.Relation</type>
|
<type>com.umlet.element.Relation</type>
|
||||||
|
@ -41,52 +41,30 @@
|
||||||
<x>396</x>
|
<x>396</x>
|
||||||
<y>408</y>
|
<y>408</y>
|
||||||
<w>168</w>
|
<w>168</w>
|
||||||
<h>96</h>
|
<h>108</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=<<<<-
|
<panel_attributes>lt=<<<<-
|
||||||
Creates>></panel_attributes>
|
Creates>></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>
|
||||||
<element>
|
<element>
|
||||||
<type>com.umlet.element.Relation</type>
|
<type>com.umlet.element.Relation</type>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>564</x>
|
<x>660</x>
|
||||||
<y>372</y>
|
<y>384</y>
|
||||||
<w>60</w>
|
<w>60</w>
|
||||||
<h>108</h>
|
<h>108</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=<<<-</panel_attributes>
|
<panel_attributes>lt=<<<-</panel_attributes>
|
||||||
<additional_attributes>36;84;36;36</additional_attributes>
|
<additional_attributes>36;84;36;36</additional_attributes>
|
||||||
</element>
|
</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=<<<<-</panel_attributes>
|
|
||||||
<additional_attributes>36;36;36;84</additional_attributes>
|
|
||||||
</element>
|
|
||||||
<element>
|
<element>
|
||||||
<id>UMLClass</id>
|
<id>UMLClass</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>540</x>
|
<x>540</x>
|
||||||
<y>312</y>
|
<y>312</y>
|
||||||
<w>336</w>
|
<w>336</w>
|
||||||
<h>96</h>
|
<h>108</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>/<<interface>>/
|
<panel_attributes>/<<interface>>/
|
||||||
IThreadObject
|
IThreadObject
|
||||||
|
@ -123,16 +101,4 @@ bg=red</panel_attributes>
|
||||||
<panel_attributes>lt=-</panel_attributes>
|
<panel_attributes>lt=-</panel_attributes>
|
||||||
<additional_attributes>36;36;36;108</additional_attributes>
|
<additional_attributes>36;36;36;108</additional_attributes>
|
||||||
</element>
|
</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=>>.
|
|
||||||
uses</panel_attributes>
|
|
||||||
<additional_attributes>60;36;60;144;204;144</additional_attributes>
|
|
||||||
</element>
|
|
||||||
</diagram>
|
</diagram>
|
||||||
|
|
|
@ -3,6 +3,5 @@
|
||||||
|
|
||||||
BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved )
|
BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved )
|
||||||
{
|
{
|
||||||
//MessageBox(0, L"DanBiasGame Loaded", 0, 0);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Created by [Dennis Andersen] [2013] //
|
||||||
|
/////////////////////////////////////////
|
||||||
#ifndef DANBIASGAME_DANBIASGAME_H
|
#ifndef DANBIASGAME_DANBIASGAME_H
|
||||||
#define DANBIASGAME_DANBIASGAME_H
|
#define DANBIASGAME_DANBIASGAME_H
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Created by [Dennis Andersen] [2013] //
|
||||||
|
/////////////////////////////////////////
|
||||||
#ifndef DANBIASSERVER_ADMIN_INTERFACE_H
|
#ifndef DANBIASSERVER_ADMIN_INTERFACE_H
|
||||||
#define DANBIASSERVER_ADMIN_INTERFACE_H
|
#define DANBIASSERVER_ADMIN_INTERFACE_H
|
||||||
|
|
||||||
|
|
|
@ -179,10 +179,13 @@
|
||||||
<ClCompile Include="DLLMain.cpp" />
|
<ClCompile Include="DLLMain.cpp" />
|
||||||
<ClCompile Include="GameServer.cpp" />
|
<ClCompile Include="GameServer.cpp" />
|
||||||
<ClCompile Include="GameSession\GameClient.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\INetworkSession.cpp" />
|
||||||
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
|
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
|
||||||
<ClCompile Include="LobbySessions\GameLobby.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\MainLobby.cpp" />
|
||||||
<ClCompile Include="LobbySessions\NetworkSession.cpp" />
|
<ClCompile Include="LobbySessions\NetworkSession.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Created by [Dennis Andersen] [2013]
|
// Created by [Dennis Andersen] [2013] //
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
#ifndef DANBIAS_SERVER_DANBIAS_SERVER_H
|
#ifndef DANBIAS_SERVER_DANBIAS_SERVER_H
|
||||||
#define DANBIAS_SERVER_DANBIAS_SERVER_H
|
#define DANBIAS_SERVER_DANBIAS_SERVER_H
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
using namespace Oyster::Network;
|
using namespace Oyster::Network;
|
||||||
|
|
||||||
|
GameServer* GameServer::instance = 0;
|
||||||
|
|
||||||
void GameServer::NetworkCallback(NetworkClient* client)
|
void GameServer::NetworkCallback(NetworkClient* client)
|
||||||
{
|
{
|
||||||
|
@ -38,7 +39,7 @@ namespace DanBias
|
||||||
desc.clients.Push(c);
|
desc.clients.Push(c);
|
||||||
desc.exitDestionation = this->mainLobby;
|
desc.exitDestionation = this->mainLobby;
|
||||||
if((sessionId = GameSessionManager::AddSession(desc, true)) == 0)
|
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 = true;
|
||||||
//myTest = new GameSession();
|
//myTest = new GameSession();
|
||||||
//
|
//
|
||||||
|
@ -68,7 +69,7 @@ namespace DanBias
|
||||||
, maxClients(0)
|
, maxClients(0)
|
||||||
, mainLobby(0)
|
, mainLobby(0)
|
||||||
, server(0)
|
, server(0)
|
||||||
{ }
|
{ this->instance = this; }
|
||||||
GameServer::~GameServer()
|
GameServer::~GameServer()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -89,7 +90,6 @@ namespace DanBias
|
||||||
|
|
||||||
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
|
if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error;
|
||||||
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
|
if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error;
|
||||||
//if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
|
|
||||||
|
|
||||||
this->initiated = true;
|
this->initiated = true;
|
||||||
return DanBiasServerReturn_Sucess;
|
return DanBiasServerReturn_Sucess;
|
||||||
|
@ -108,10 +108,9 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
if(!WindowShell::Frame()) break;
|
if(!WindowShell::Frame()) break;
|
||||||
|
|
||||||
|
|
||||||
this->mainLobby->Frame();
|
this->mainLobby->Frame();
|
||||||
|
|
||||||
if(GetAsyncKeyState(0x51))
|
if(GetAsyncKeyState(0x51)) //Q for exit
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +127,11 @@ namespace DanBias
|
||||||
return DanBiasServerReturn_Sucess;
|
return DanBiasServerReturn_Sucess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetworkSession* GameServer::MainLobbyInstance()
|
||||||
|
{
|
||||||
|
return GameServer::instance->mainLobby;
|
||||||
|
}
|
||||||
|
|
||||||
bool GameServer::LoadIniFile(InitData& ini)
|
bool GameServer::LoadIniFile(InitData& ini)
|
||||||
{
|
{
|
||||||
std::ifstream in;
|
std::ifstream in;
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace DanBias
|
||||||
DanBiasServerReturn Run();
|
DanBiasServerReturn Run();
|
||||||
DanBiasServerReturn Release();
|
DanBiasServerReturn Release();
|
||||||
|
|
||||||
|
static NetworkSession* MainLobbyInstance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient);
|
//static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient);
|
||||||
void NetworkCallback(Oyster::Network::NetworkClient* client) override;
|
void NetworkCallback(Oyster::Network::NetworkClient* client) override;
|
||||||
|
@ -31,6 +33,7 @@ namespace DanBias
|
||||||
int maxClients;
|
int maxClients;
|
||||||
MainLobby *mainLobby;
|
MainLobby *mainLobby;
|
||||||
Oyster::Network::NetworkServer *server;
|
Oyster::Network::NetworkServer *server;
|
||||||
|
static GameServer* instance;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct InitData
|
struct InitData
|
||||||
|
|
|
@ -4,16 +4,22 @@
|
||||||
|
|
||||||
#include "GameClient.h"
|
#include "GameClient.h"
|
||||||
#include "..\LobbySessions\NetworkSession.h"
|
#include "..\LobbySessions\NetworkSession.h"
|
||||||
|
#include <Game.h>
|
||||||
#include <GameProtocols.h>
|
#include <GameProtocols.h>
|
||||||
|
|
||||||
using namespace Utility::DynamicMemory;
|
using namespace Utility::DynamicMemory;
|
||||||
using namespace DanBias;
|
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->callbackValue = value;
|
||||||
this->client = client;
|
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;
|
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
|
||||||
c.callbackType = Oyster::Callback::CallbackType_Object;
|
c.callbackType = Oyster::Callback::CallbackType_Object;
|
||||||
c.value = this;
|
c.value = this;
|
||||||
|
@ -22,8 +28,11 @@ GameClient::GameClient(SmartPointer<LobbyClient> client, Oyster::Callback::Oyste
|
||||||
}
|
}
|
||||||
GameClient::~GameClient()
|
GameClient::~GameClient()
|
||||||
{
|
{
|
||||||
this->client->Disconnect();
|
if(this->client) this->client->Disconnect();
|
||||||
this->player.Release();
|
this->player.playerID = 0;
|
||||||
|
this->player.teamID = 0;
|
||||||
|
this->id = -1;
|
||||||
|
//this->player.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
|
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;
|
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;
|
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)
|
void GameClient::ObjectCallback(NetworkSession::NetEvent e)
|
||||||
{
|
{
|
||||||
e.gameClient = this;
|
e.gameClient = this;
|
||||||
|
|
|
@ -6,26 +6,32 @@
|
||||||
|
|
||||||
#include "..\LobbySessions\LobbyClient.h"
|
#include "..\LobbySessions\LobbyClient.h"
|
||||||
#include <PostBox\PostBox.h>
|
#include <PostBox\PostBox.h>
|
||||||
#include <Player.h>
|
#include <Game.h>
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
class GameClient: Oyster::Callback::CallbackObject<void, NetworkSession::NetEvent>
|
class GameClient: Oyster::Callback::CallbackObject<void, NetworkSession::NetEvent>
|
||||||
{
|
{
|
||||||
public:
|
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();
|
virtual~GameClient();
|
||||||
|
|
||||||
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
|
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
|
||||||
|
|
||||||
GameLogic::Player* GetPlayer();
|
//GameLogic::Player* GetPlayer();
|
||||||
LobbyClient* GetClient();
|
GameLogic::Game::PlayerData* GetPlayer();
|
||||||
|
GameLogic::Game::PlayerData ReleasePlayer();
|
||||||
|
|
||||||
|
LobbyClient* GetClient() const;
|
||||||
|
Utility::DynamicMemory::SmartPointer<LobbyClient> ReleaseClient();
|
||||||
|
int GetID() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
|
//Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
|
||||||
|
GameLogic::Game::PlayerData player;
|
||||||
Utility::DynamicMemory::SmartPointer<LobbyClient> client;
|
Utility::DynamicMemory::SmartPointer<LobbyClient> client;
|
||||||
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
|
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
|
||||||
|
int id;
|
||||||
void ObjectCallback(NetworkSession::NetEvent) override;
|
void ObjectCallback(NetworkSession::NetEvent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
#ifndef DANBIASSERVER_GAME_SESSION_H
|
#ifndef DANBIASSERVER_GAME_SESSION_H
|
||||||
#define 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)
|
#pragma warning(disable: 4150)
|
||||||
|
|
||||||
#include "..\LobbySessions\NetworkSession.h"
|
#include "..\LobbySessions\NetworkSession.h"
|
||||||
|
#include <WinTimer.h>
|
||||||
#include <PostBox\IPostBox.h>
|
#include <PostBox\IPostBox.h>
|
||||||
#include <Thread\OysterThread.h>
|
#include <Thread\OysterThread.h>
|
||||||
|
#include <Game.h>
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
|
@ -18,6 +20,9 @@ namespace DanBias
|
||||||
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
|
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* A container to use when initiating a new session
|
||||||
|
*/
|
||||||
struct GameDescription
|
struct GameDescription
|
||||||
{
|
{
|
||||||
std::wstring mapName;
|
std::wstring mapName;
|
||||||
|
@ -41,31 +46,44 @@ namespace DanBias
|
||||||
bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
|
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 IsCreated() const { return this->isCreated; }
|
||||||
inline bool IsRunning() const { return this->isRunning; }
|
inline bool IsRunning() const { return this->isRunning; }
|
||||||
|
|
||||||
|
//Private member functions
|
||||||
private:
|
private:
|
||||||
void Frame();
|
//Handles all events recieved
|
||||||
void ParseEvents();
|
void ParseEvents();
|
||||||
|
//Handles all gameplay events
|
||||||
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
|
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
|
||||||
|
//Handles all general events
|
||||||
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
|
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);
|
void Send(Oyster::Network::CustomNetProtocol* p);
|
||||||
|
//Frame function, derived from IThreadObject
|
||||||
private: //overriden Threading functions
|
|
||||||
bool DoWork ( ) override;
|
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:
|
private:
|
||||||
|
|
||||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
|
||||||
NetworkSession* owner;
|
|
||||||
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
|
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
|
||||||
Oyster::Thread::OysterThread worker;
|
Oyster::Thread::OysterThread worker;
|
||||||
|
GameLogic::Game gameInstance;
|
||||||
|
NetworkSession* owner;
|
||||||
|
Utility::WinTimer timer;
|
||||||
bool isCreated;
|
bool isCreated;
|
||||||
bool isRunning;
|
bool isRunning;
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Created by [Dennis Andersen] [2013] //
|
||||||
|
/////////////////////////////////////////
|
||||||
#ifndef DANBIASSERVER_LEVELMANAGER_H
|
#ifndef DANBIASSERVER_LEVELMANAGER_H
|
||||||
#define DANBIASSERVER_LEVELMANAGER_H
|
#define DANBIASSERVER_LEVELMANAGER_H
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Created by [Dennis Andersen] [2013] //
|
||||||
|
/////////////////////////////////////////
|
||||||
#ifndef DANBIASSERVER_INETWORKSESSION_H
|
#ifndef DANBIASSERVER_INETWORKSESSION_H
|
||||||
#define DANBIASSERVER_INETWORKSESSION_H
|
#define DANBIASSERVER_INETWORKSESSION_H
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// Created by [Dennis Andersen] [2013] //
|
||||||
|
/////////////////////////////////////////
|
||||||
#ifndef DANBIASSERVER_LOBBYCLIENT_H
|
#ifndef DANBIASSERVER_LOBBYCLIENT_H
|
||||||
#define DANBIASSERVER_LOBBYCLIENT_H
|
#define DANBIASSERVER_LOBBYCLIENT_H
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
// Launcher to launch Danbias server or client //
|
// Launcher to launch Danbias server //
|
||||||
// Created by [Dennis Andersen] [2013] //
|
// Created by [Dennis Andersen] [2013] //
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
#define NOMINMAX //Blame it on windows
|
#define NOMINMAX //Blame it on windows
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
|
#include <GID.h>
|
||||||
|
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
|
|
||||||
|
@ -57,7 +58,12 @@ void Game::GetAllPlayerPos()
|
||||||
|
|
||||||
Game::PlayerData Game::CreatePlayer()
|
Game::PlayerData Game::CreatePlayer()
|
||||||
{
|
{
|
||||||
|
PlayerData data;
|
||||||
|
//Yo mammma
|
||||||
|
data.playerID = GID();
|
||||||
|
data.teamID = -1;
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::CreateTeam()
|
void Game::CreateTeam()
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
// Created by [Erik Persson] [2013]
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
|
|
||||||
|
#include "GameLogicDef.h"
|
||||||
#include "GameLogicStates.h"
|
#include "GameLogicStates.h"
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
class Game
|
class DANBIAS_GAMELOGIC_DLL Game
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -132,7 +132,7 @@ Oyster::Math::Float3 Player::GetPos()
|
||||||
|
|
||||||
Oyster::Math::Float3 Player::GetLookDir()
|
Oyster::Math::Float3 Player::GetLookDir()
|
||||||
{
|
{
|
||||||
return myData->lookDir;
|
return myData->lookDir.xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Player::GetTeamID()
|
int Player::GetTeamID()
|
||||||
|
|
|
@ -4,14 +4,13 @@
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
#include "GameLogicStates.h"
|
#include "GameLogicStates.h"
|
||||||
#include "GameLogicDef.h"
|
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
class DANBIAS_GAMELOGIC_DLL Player : public Object
|
class Player : public Object
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -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::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 Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach = false);
|
||||||
OYSTER_THREAD_ERROR Start();
|
OYSTER_THREAD_ERROR Start();
|
||||||
OYSTER_THREAD_ERROR Stop(bool wait = false);
|
OYSTER_THREAD_ERROR Stop();
|
||||||
OYSTER_THREAD_ERROR Pause();
|
OYSTER_THREAD_ERROR Pause();
|
||||||
OYSTER_THREAD_ERROR Pause(int mSec);
|
OYSTER_THREAD_ERROR Pause(int mSec);
|
||||||
OYSTER_THREAD_ERROR Resume();
|
OYSTER_THREAD_ERROR Resume();
|
||||||
OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0);
|
OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0);
|
||||||
OYSTER_THREAD_ERROR SetWorker(ThreadFnc 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();
|
||||||
OYSTER_THREAD_ERROR Wait(int mSec);
|
OYSTER_THREAD_ERROR Wait(int mSec);
|
||||||
OYSTER_THREAD_ERROR Swap(const OysterThread* other);
|
OYSTER_THREAD_ERROR Swap(const OysterThread* other);
|
||||||
|
|
|
@ -72,10 +72,10 @@ using namespace Utility::DynamicMemory;
|
||||||
~RefData()
|
~RefData()
|
||||||
{
|
{
|
||||||
//threadWaitFunctionLock.lock();
|
//threadWaitFunctionLock.lock();
|
||||||
Terminate(true);
|
Terminate();
|
||||||
//threadWaitFunctionLock.unlock();
|
//threadWaitFunctionLock.unlock();
|
||||||
}
|
}
|
||||||
OYSTER_THREAD_ERROR Terminate(bool wait)
|
OYSTER_THREAD_ERROR Terminate()
|
||||||
{
|
{
|
||||||
if(!threadData) return OYSTER_THREAD_ERROR_SUCCESS;
|
if(!threadData) return OYSTER_THREAD_ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -129,12 +129,12 @@ using namespace Utility::DynamicMemory;
|
||||||
data = new RefData();
|
data = new RefData();
|
||||||
return data->Create(fnc, worker, start, detach);
|
return data->Create(fnc, worker, start, detach);
|
||||||
}
|
}
|
||||||
OYSTER_THREAD_ERROR Terminate(bool wait)
|
OYSTER_THREAD_ERROR Terminate()
|
||||||
{
|
{
|
||||||
if(!data)
|
if(!data)
|
||||||
return OYSTER_THREAD_ERROR_FAILED;
|
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;
|
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()
|
OYSTER_THREAD_ERROR OysterThread::Pause()
|
||||||
{
|
{
|
||||||
|
@ -297,9 +297,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker)
|
||||||
|
|
||||||
return OYSTER_THREAD_ERROR_SUCCESS;;
|
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()
|
OYSTER_THREAD_ERROR OysterThread::Wait()
|
||||||
{
|
{
|
||||||
|
|
|
@ -293,6 +293,7 @@ namespace Utility
|
||||||
this->_ptr = p;
|
this->_ptr = p;
|
||||||
|
|
||||||
if(p) this->_rc->Incref();
|
if(p) this->_rc->Incref();
|
||||||
|
else this->_rc = 0;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ void NetworkServer::PrivateData::Stop()
|
||||||
|
|
||||||
started = false;
|
started = false;
|
||||||
|
|
||||||
thread.Stop(true);
|
thread.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkServer::PrivateData::Shutdown()
|
void NetworkServer::PrivateData::Shutdown()
|
||||||
|
|
|
@ -9,9 +9,11 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
namespace Model
|
namespace Model
|
||||||
{
|
{
|
||||||
|
//struct ModelInfo;
|
||||||
struct Model
|
struct Model
|
||||||
{
|
{
|
||||||
//! do not Edit, linked to render data
|
//! do not Edit, linked to render data
|
||||||
|
//ModelInfo* info;
|
||||||
void* info;
|
void* info;
|
||||||
Oyster::Math::Float4x4 WorldMatrix;
|
Oyster::Math::Float4x4 WorldMatrix;
|
||||||
bool Visible;
|
bool Visible;
|
||||||
|
|
Loading…
Reference in New Issue