Worked over the holidays

This commit is contained in:
Dennis Andersen 2014-01-07 10:26:09 +01:00
parent 4925256fd1
commit ed202a15a2
69 changed files with 1985 additions and 1207 deletions

View File

@ -3,6 +3,6 @@ illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd tex_crate.png
map_Kd crate.png
Ni 1.00
Ks 0.50 0.50 0.50

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

View File

@ -3,6 +3,6 @@ illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd tex_worldDummy.jpg
map_Kd worldDummy.jpg
Ni 1.00
Ks 0.50 0.50 0.50

View File

@ -24,7 +24,7 @@ namespace DanBias
Oyster::Network::NetworkClient* nwClient;
Client::GameClientState* gameClientState;
void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& p) override
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
{
int pType = p[0].value.netInt;
switch (pType)
@ -159,7 +159,7 @@ namespace DanBias
m_data->recieverObj = new MyRecieverObject;
m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object);
// m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object);
m_data->recieverObj->nwClient->Connect(desc.port, desc.IP);
if (!m_data->recieverObj->nwClient->IsConnected())

View File

@ -17,6 +17,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
// Game client starter code goes here
DanBias::DanBiasGameDesc gameDesc;
gameDesc.port = 15151;
//gameDesc.port = 15152;
//gameDesc.IP = "193.11.184.196";
//gameDesc.IP = "193.11.184.31";
gameDesc.IP = "127.0.0.1";

View File

@ -0,0 +1,68 @@
#define NOMINMAX
#include "AdminInterface.h"
#include <Thread\OysterThread.h>
#include <WindowShell.h>
#include "..\GameServer.h"
#include "..\GameSession\GameSessionManager.h"
#include "..\GameSession\GameSession.h"
#include "..\Helpers\ServerDataReader.h"
#include "..\LobbySessions\LobbyClient.h"
#include "..\LobbySessions\NetworkSession.h"
#include "..\LobbySessions\GameLobby.h"
#include "..\LobbySessions\MainLobby.h"
using namespace Oyster::Network;
using namespace Oyster::Thread;
using namespace DanBias;
struct AdminInstanceData :public IThreadObject
{
bool isCreated;
Oyster::Network::NetworkServer adminServer;
NetworkClient* admin;
NetworkSession* parentInstance;
OysterThread worker;
bool DoWork() override
{
//((GameServer*)parentInstance)->serve
return true;
}
}adminInstanceData;
void AdminArrived(NetworkClient* adm)
{
if(adminInstanceData.admin)
{
delete adm;
return;
}
adminInstanceData.admin = adm;
adminInstanceData.worker.Create(&adminInstanceData, true, true);
}
void AdminInterface::Toggle(bool toggle, NetworkSession* parent)
{
if(toggle)
{
if(!parent) return;
if(adminInstanceData.isCreated) return;
NetworkServer::INIT_DESC desc;
desc.port = 15152;
desc.callbackType = NetworkClientCallbackType_Function;
desc.recvObj.clientConnectFnc = AdminArrived;
if(!adminInstanceData.adminServer.Init(desc)) return;
adminInstanceData.parentInstance = parent;
adminInstanceData.adminServer.Start();
}
else
{
adminInstanceData.adminServer.Shutdown();
}
}

View File

@ -0,0 +1,17 @@
#ifndef DANBIASSERVER_ADMIN_INTERFACE_H
#define DANBIASSERVER_ADMIN_INTERFACE_H
#include <NetworkServer.h>
namespace DanBias
{
class NetworkSession;
//Global admin
class AdminInterface
{
public:
static void Toggle(bool toggle, NetworkSession* parent);
};
}
#endif // !DANBIASSERVER_ADMIN_INTERFACE_H

View File

@ -1,5 +1,8 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#define NOMINMAX
#include <windows.h>
#include <Windows.h>
BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved )
{

View File

@ -173,27 +173,34 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Helpers\GameSessionManager.cpp" />
<ClCompile Include="Include\DanBiasServerAPI.cpp" />
<ClCompile Include="AdminInterface\AdminInterface.cpp" />
<ClCompile Include="GameSession\GameSessionManager.cpp" />
<ClCompile Include="DanBiasServerAPI.cpp" />
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameServer.cpp" />
<ClCompile Include="ServerObjects\ClientObject.cpp" />
<ClCompile Include="ServerObjects\Lobby\GameLobby.cpp" />
<ClCompile Include="ServerObjects\GameSession.cpp" />
<ClCompile Include="ServerObjects\Lobby\MainLobby.cpp" />
<ClCompile Include="ServerObjects\NetworkSession.cpp" />
<ClCompile Include="GameSession\GameClient.cpp" />
<ClCompile Include="LobbySessions\INetworkSession.cpp" />
<ClCompile Include="LobbySessions\LobbyClient.cpp" />
<ClCompile Include="LobbySessions\GameLobby.cpp" />
<ClCompile Include="GameSession\GameSession.cpp" />
<ClCompile Include="LobbySessions\MainLobby.cpp" />
<ClCompile Include="LobbySessions\NetworkSession.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AdminInterface\AdminInterface.h" />
<ClInclude Include="Event\EventManager.h" />
<ClInclude Include="GameServer.h" />
<ClInclude Include="Helpers\GameSessionManager.h" />
<ClInclude Include="Include\DanBiasServerAPI.h" />
<ClInclude Include="Helpers\ServerInitReader.h" />
<ClInclude Include="ServerObjects\ClientObject.h" />
<ClInclude Include="ServerObjects\GameSession.h" />
<ClInclude Include="ServerObjects\Lobby\GameLobby.h" />
<ClInclude Include="ServerObjects\Lobby\MainLobby.h" />
<ClInclude Include="ServerObjects\NetworkSession.h" />
<ClInclude Include="GameSession\GameSessionManager.h" />
<ClInclude Include="DanBiasServerAPI.h" />
<ClInclude Include="Helpers\MapManager.h" />
<ClInclude Include="Helpers\ServerDataReader.h" />
<ClInclude Include="GameSession\GameClient.h" />
<ClInclude Include="GameSession\GameSession.h" />
<ClInclude Include="LobbySessions\INetworkSession.h" />
<ClInclude Include="LobbySessions\LobbyClient.h" />
<ClInclude Include="LobbySessions\GameLobby.h" />
<ClInclude Include="LobbySessions\MainLobby.h" />
<ClInclude Include="LobbySessions\NetworkSession.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GamePhysics\GamePhysics.vcxproj">

View File

@ -2,7 +2,7 @@
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "DanBiasServerAPI.h"
#include "..\GameServer.h"
#include "GameServer.h"
namespace DanBias
{

View File

@ -7,11 +7,14 @@
#include <iostream>
#include "GameServer.h"
#include "Utilities.h"
#include "Helpers\ServerInitReader.h"
#include "Helpers\ServerDataReader.h"
#include "GameSession\GameSessionManager.h"
#include "LobbySessions\LobbyClient.h"
#include "GameSession\GameSession.h"
#include "AdminInterface\AdminInterface.h"
#include <Thread\OysterThread.h>
#include "ServerObjects\ClientObject.h"
#include "ServerObjects\GameSession.h"
#include <Utilities.h>
#include <CollisionManager.h>
@ -19,26 +22,45 @@ namespace DanBias
{
using namespace Oyster::Network;
static GameSession *myTest;
void GameServer::ClientConnectCallback(NetworkClient* client)
void GameServer::NetworkCallback(NetworkClient* client)
{
printf("Client with ID [%i] connected.\n", client->Id());
static GameSession *myTest = 0;
printf("Client with ID [%i] connected.\n", client->GetID());
if(!myTest)
{
myTest = new GameSession();
Utility::DynamicMemory::SmartPointer<ClientObject> c = new ClientObject(client);
DanBias::GameSession::GameSessionDescription desc;
desc.owner = 0;
desc.clients.Push(c);
Utility::DynamicMemory::SmartPointer<LobbyClient> c = new LobbyClient(client);
myTest->Run(desc);
GameSessionDescription desc;
desc.mapName = L"test";
desc.clients.Push(c);
desc.exitDestionation = this->mainLobby;
int sessionId = 0;
if((sessionId = GameSessionManager::AddSession(desc, true)) == 0)
printf("Failed to create a game session");
//myTest = new GameSession();
//
//DanBias::GameSession::GameSessionDescription desc;
//desc.owner = 0;
//desc.clients.Push(c);
//
//if(!myTest->Create(desc)) return;
//myTest->Run();
}
//
//Utility::DynamicMemory::SmartPointer<ClientObject> c = new ClientObject(client);
//this->mainLobby->AttachClient(c, this->mainLobby->GetPostbox());
else
{
Utility::DynamicMemory::SmartPointer<LobbyClient> c = new LobbyClient(client);
myTest->Join(c);
}
//Utility::DynamicMemory::SmartPointer<LobbyClient> c = new LobbyClient(client);
//this->mainLobby->Attach(c, this->mainLobby->GetPostbox());
}
GameServer::GameServer()
: initiated(0)
, running(0)
@ -67,7 +89,7 @@ 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;
//if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error;
this->initiated = true;
return DanBiasServerReturn_Sucess;
@ -79,12 +101,18 @@ namespace DanBias
if(!this->initiated) return DanBiasServerReturn_Error;
if(!this->server->Start()) return DanBiasServerReturn_Error;
//Oyster::Thread::OysterThread ioThread;
//ioThread.Create(this, true,
while (true)
{
if(!WindowShell::Frame()) break;
this->mainLobby->Frame();
if(GetAsyncKeyState(0x51))
break;
}
return DanBiasServerReturn_Sucess;

View File

@ -4,8 +4,8 @@
#ifndef DANBIASSERVER_GAME_SERVER_H
#define DANBIASSERVER_GAME_SERVER_H
#include "Include\DanBiasServerAPI.h"
#include "ServerObjects\Lobby\MainLobby.h"
#include "DanBiasServerAPI.h"
#include "LobbySessions\MainLobby.h"
#include <NetworkServer.h>
#include <NetworkCallbackHelper.h>
@ -23,7 +23,7 @@ namespace DanBias
private:
//static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient);
void ClientConnectCallback(Oyster::Network::NetworkClient* client) override;
void NetworkCallback(Oyster::Network::NetworkClient* client) override;
bool initiated;
bool running;
@ -39,6 +39,9 @@ namespace DanBias
int clients;
};
bool LoadIniFile(InitData&);
private:
friend class AdminInterface;
};
}// End namspace DanBias
#endif // !DANBIASSERVER_DBSERVER_H

View File

@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameClient.h"
#include "..\LobbySessions\NetworkSession.h"
#include <GameProtocols.h>
using namespace Utility::DynamicMemory;
using namespace DanBias;
GameClient::GameClient(SmartPointer<LobbyClient> client, Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
{
this->callbackValue = value;
this->client = client;
this->player = new GameLogic::Player();
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> c;
c.callbackType = Oyster::Callback::CallbackType_Object;
c.value = this;
this->client->SetCallback(c);
}
GameClient::~GameClient()
{
this->client->Disconnect();
this->player.Release();
}
void GameClient::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
{
this->callbackValue = value;
}
GameLogic::Player* GameClient::GetPlayer()
{
return this->player.Get();
}
LobbyClient* GameClient::GetClient()
{
return this->client;
}
void GameClient::ObjectCallback(NetworkSession::NetEvent e)
{
e.gameClient = this;
this->callbackValue(e);
}

View File

@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_CLIENT_OBJECT_H
#define DANBIASSERVER_CLIENT_OBJECT_H
#include "..\LobbySessions\LobbyClient.h"
#include <PostBox\PostBox.h>
#include <Player.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);
virtual~GameClient();
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
GameLogic::Player* GetPlayer();
LobbyClient* GetClient();
private:
Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
Utility::DynamicMemory::SmartPointer<LobbyClient> client;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
void ObjectCallback(NetworkSession::NetEvent) override;
private:
friend class AdminInterface;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_CLIENT_OBJECT_H

View File

@ -0,0 +1,319 @@
/////////////////////////////////////////////////////////////////////
// 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;
}
}
}
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:
{
if(p[1].value.netBool) //bool bForward;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
//Oyster::Math::Float4x4 p;
Protocol_ObjectPosition op;//(c.GetPlayer()->GetRigidBody(), c.GetPlayer()->GetID());
//op.object_ID = c.GetPlayer()->GetID();
Send(op.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", 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

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_GAME_SESSION_H
#define DANBIASSERVER_GAME_SESSION_H
//warning C4150: deletion of pointer to incomplete type, no destructor called
#pragma warning(disable: 4150)
#include "..\LobbySessions\NetworkSession.h"
#include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h>
namespace DanBias
{
class LobbyClient;
class GameClient;
class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession
{
public:
struct GameDescription
{
std::wstring mapName;
NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
};
public:
GameSession();
virtual~GameSession();
/** Initiates and creates a game session. */
bool Create(GameDescription& desc);
/** Runs the game session (ie starts the game loop). */
void Run();
/** Join an existing/running game session
* @param client The client to attach to the session
*/
bool Join(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
/**
*
*/
void CloseSession(bool dissconnectClients = false);
inline bool IsCreated() const { return this->isCreated; }
inline bool IsRunning() const { return this->isRunning; }
private:
void Frame();
void ParseEvents();
void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c);
void Send(Oyster::Network::CustomNetProtocol* p);
private: //overriden Threading functions
bool DoWork ( ) override;
private:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameClient>> clients;
NetworkSession* owner;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
bool isCreated;
bool isRunning;
private:
friend class AdminInterface;
};//End GameSession
}//End namespace DanBias
#endif // !DANBIASSERVER_GAME_SESSION_H

View File

@ -0,0 +1,116 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameSessionManager.h"
#include "..\LobbySessions\LobbyClient.h"
#include "GameSession.h"
#include <DynamicArray.h>
using namespace DanBias;
using namespace Utility::DynamicMemory;
struct GameSessionData
{
DynamicArray< SmartPointer< GameSession > > sessions;
int freeSpot;
int Existst(int session)
{
for (unsigned int i = 0; i < sessions.Size(); i++)
{
if(!sessions[i] && freeSpot == -1) freeSpot = i;
if(sessions[i]->GetID() == session) return i;
}
return -1;
}
int GetFree()
{
for (unsigned int i = 0; i < sessions.Size(); i++)
{
if(!sessions[i])
{
this->freeSpot = i;
return this->freeSpot;
}
}
this->freeSpot = -1;
return this->freeSpot;
}
} gameSessionData;
int GameSessionManager::AddSession(GameSessionDescription& instance, bool run)
{
int k = gameSessionData.GetFree();
SmartPointer<GameSession> gs = new GameSession();
DanBias::GameSession::GameDescription desc;
desc.owner = instance.exitDestionation;
desc.clients = instance.clients;
desc.mapName = instance.mapName;
if(!gs->Create(desc)) return 0;
if(k == -1) gameSessionData.sessions.Push(gs);
else gameSessionData.sessions[k] = gs;
if(run) gs->Run();
return gs->GetID();
}
bool GameSessionManager::StartSession(int session)
{
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return false;
gameSessionData.sessions[i]->Run();
return true;
}
bool GameSessionManager::JoinSession(int session, Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return false;
gameSessionData.sessions[i]->Join(client);
return true;
}
void GameSessionManager::GetSessionInfo(int session, GameSessionInfo& data)
{
memset(&data, 0, sizeof(GameSessionInfo));
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return;
//data.gametime = gameSessionData.sessions[i]->
//data.mapName = gameSessionData.sessions[i]->
//data.numberOfPlayers = gameSessionData.sessions[i]->
}
void GameSessionManager::CloseSession(int session)
{
int i = -1;
if((i = gameSessionData.Existst(session)) != -1) return;
gameSessionData.sessions[i]->CloseSession();
}
int GameSessionManager::GetSessionSize()
{
return gameSessionData.sessions.Size();
}

View File

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_GAME_SEESION_MANAGER_H
#define DANBIASSERVER_GAME_SEESION_MANAGER_H
#include <string>
#include <Utilities.h>
#include <DynamicArray.h>
namespace DanBias
{
class LobbyClient;
class NetworkSession;
struct GameSessionDescription
{
std::wstring mapName;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
NetworkSession* exitDestionation; //The new owner when session dies
};
struct GameSessionInfo
{
std::wstring mapName;
unsigned int numberOfPlayers;
float gametime;
};
class GameSessionManager
{
public:
/**
* Add a new game session.
* On success, the function returns the game instance id number greater than 0.
*/
static int AddSession(GameSessionDescription& instance, bool run);
/**
* Starts an existing game session
* @param session The session id recieved when created.
* @param run Indicates if the game session should start imidiatly when created.
* @return Returns false if session is not found.
*/
static bool StartSession(int session);
/**
* Join an exiting session
* @param session The session id recieved when created.
* @param client The client that is to join a game session
* @return Returns false on failure.
*/
static bool JoinSession(int session, Utility::DynamicMemory::SmartPointer<LobbyClient> client);
/**
* Gets information about a given session
* @param session The session id recieved when created.
* @param sessionInformation The output parameter that will be filled.
*/
static void GetSessionInfo(int session, GameSessionInfo& sessionInformation);
/**
* Close a session.
* @param session The session id recieved when created a session.
*/
static void CloseSession(int session);
/**
* Get total sessions running
* @return Returns the total sessions curently running.
*/
static int GetSessionSize();
private:
friend class AdminInterface;
};
}
#endif // !DANBIASSERVER_GAME_SEESION_MANAGER_H

View File

@ -1,58 +0,0 @@
#include "GameSessionManager.h"
#include "..\ServerObjects\GameSession.h"
#include "DynamicArray.h"
struct GameSessionData
{
Utility::DynamicMemory::DynamicArray<DanBias::GameSession*> sessions;
int freeSpot;
int Existst(DanBias::GameSession* s)
{
for (unsigned int i = 0; i < sessions.Size(); i++)
{
if(!sessions[i] && freeSpot == -1) freeSpot = i;
if(sessions[i] == s) return i;
}
return -1;
}
int GetFree()
{
for (unsigned int i = 0; i < sessions.Size(); i++)
if(!sessions[i])
return i;
return -1;
}
} gameSessionData;
void GameSessionManager::AddSession(DanBias::GameSession* session)
{
if(gameSessionData.Existst(session) == -1)
{
int k = gameSessionData.freeSpot;
if( k == -1) k = gameSessionData.GetFree();
if(k == -1) gameSessionData.sessions.Push(session);
else gameSessionData.sessions[k] = session;
}
}
void GameSessionManager::CloseSession()
{
//int i = gameSessionData.Existst(session);
//
////Moron check...
//if(i == -1) return;
//
////gameSessionData.sessions[i]->Close();
}

View File

@ -1,16 +0,0 @@
#ifndef DANBIASSERVER_GAME_SEESION_MANAGER_H
#define DANBIASSERVER_GAME_SEESION_MANAGER_H
namespace DanBias
{
class GameSession;
}
class GameSessionManager
{
public:
static void AddSession(DanBias::GameSession* session);
static void CloseSession();
};
#endif // !DANBIASSERVER_GAME_SEESION_MANAGER_H

View File

@ -0,0 +1,27 @@
#ifndef DANBIASSERVER_LEVELMANAGER_H
#define DANBIASSERVER_LEVELMANAGER_H
#include "ServerDataReader.h"
#include "..\LobbySessions\LobbyClient.h"
#include "..\LobbySessions\NetworkSession.h"
#include "..\LobbySessions\GameLobby.h"
#include <Utilities.h>
namespace DanBias
{
class MapManager
{
public:
struct MapInitDesc
{
const wchar_t* map;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
};
public:
static bool InitiateMapPack(const MapInitDesc& desc);
};
}
#endif // !DANBIASSERVER_LEVELMANAGER_H

View File

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

View File

@ -0,0 +1,21 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "GameLobby.h"
namespace DanBias
{
GameLobby::GameLobby(Utility::DynamicMemory::SmartPointer<LobbyClient> owner)
{
}
GameLobby::~GameLobby()
{
}
void GameLobby::Release()
{
}
}//End namespace DanBias

View File

@ -0,0 +1,24 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_GAMELOBBY_H
#define DANBIASSERVER_GAMELOBBY_H
#include "NetworkSession.h"
namespace DanBias
{
class GameLobby :public NetworkSession
{
public:
GameLobby(Utility::DynamicMemory::SmartPointer<LobbyClient> owner);
virtual~GameLobby();
void Release();
private:
friend class AdminInterface;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_GAME_LOBBY_H

View File

@ -0,0 +1,18 @@
#include "INetworkSession.h"
#include <GID.h>
INetworkSession::INetworkSession()
:id(GID())
{}
INetworkSession::INetworkSession(const INetworkSession& orig)
{
id = orig.id;
}
const INetworkSession& INetworkSession::operator=(const INetworkSession& orig)
{
id = orig.id;
return *this;
}
INetworkSession::~INetworkSession()
{}

View File

@ -0,0 +1,19 @@
#ifndef DANBIASSERVER_INETWORKSESSION_H
#define DANBIASSERVER_INETWORKSESSION_H
class INetworkSession
{
public:
INetworkSession();
INetworkSession(const INetworkSession& orig);
const INetworkSession& operator=(const INetworkSession& orig);
virtual~INetworkSession();
inline int GetID() const { return this->id; }
private:
int id;
};
#endif // !DANBIASSERVER_INETWORKSESSION_H

View File

@ -0,0 +1,51 @@
#include "LobbyClient.h"
#include <GameProtocols.h>
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster::Callback;
using namespace GameLogic;
namespace DanBias
{
LobbyClient::LobbyClient(SmartPointer<NetworkClient> client)
{
this->client = client;
this->client->SetRecieverObject(this, NetworkProtocolCallbackType_Object);
}
LobbyClient::~LobbyClient()
{
this->callbackValue.callbackType = CallbackType_Unknown;
}
void LobbyClient::Disconnect()
{
this->client->Disconnect();
}
void LobbyClient::SetCallback(OysterCallback<void, NetworkSession::NetEvent> value)
{
this->callbackValue = value;
}
/** This method is NOT threadsafe. */
void LobbyClient::NetworkCallback(CustomNetProtocol& protocol)
{
if(this->callbackValue.callbackType == CallbackType_Unknown) return;
NetworkSession::NetEvent e;
e.sender = this;
e.protocol = protocol;
this->callbackValue(e);
}
void LobbyClient::Disconnected()
{
if(this->callbackValue.callbackType == CallbackType_Unknown) return;
NetworkSession::NetEvent e;
e.sender = this;
e.protocol = *GameLogic::Protocol_General_Status(Protocol_General_Status::States_disconected).GetProtocol();
this->callbackValue(e);
}
}//End namsapce DanBias

View File

@ -0,0 +1,35 @@
#ifndef DANBIASSERVER_LOBBYCLIENT_H
#define DANBIASSERVER_LOBBYCLIENT_H
#include "NetworkSession.h"
#include <NetworkClient.h>
#include <PostBox\PostBox.h>
namespace DanBias
{
class LobbyClient :public Oyster::Network::NetClientEvent
{
public:
LobbyClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client);
virtual~LobbyClient();
void Disconnect();
void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
inline void Send(Oyster::Network::CustomProtocolObject& protocol) { this->client->Send(protocol); }
inline void Send(Oyster::Network::CustomNetProtocol* protocol) { this->client->Send(protocol); }
inline int GetID() const { return this->client->GetID(); }
private:
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> callbackValue;
private:
void NetworkCallback(Oyster::Network::CustomNetProtocol& protocol) override;
void Disconnected() override;
private:
friend class AdminInterface;
};
}//End namspace DanBias
#endif // !DANBIASSERVER_LOBBYCLIENT_H

View File

@ -0,0 +1,109 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "MainLobby.h"
#include "LobbyClient.h"
#include <PlayerProtocols.h>
#include <PostBox\PostBox.h>
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
namespace DanBias
{
MainLobby::MainLobby()
:gameLobby(5)
{
this->box = new PostBox<DanBias::NetworkSession::NetEvent>();
}
MainLobby::~MainLobby()
{
delete this->box;
this->box = 0;
}
void MainLobby::Release()
{
this->CloseSession(true);
}
void MainLobby::Frame()
{
ParseEvents();
}
IPostBox<NetworkSession::NetEvent>* MainLobby::GetPostbox()
{
return this->box;
}
//////// Private
void MainLobby::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
ParseProtocol(e.protocol, e.sender);
}
}
void MainLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c)
{
bool update = false;
switch (p[0].value.netShort)
{
case protocol_Lobby_CreateGame:
{
GameLogic::Protocol_LobbyCreateGame val(p);
CreateGame(val, c);
update = true;
}
break;
case protocol_Lobby_JoinLobby:
{
GameLogic::Protocol_LobbyJoinLobby val(p);
JoinLobby(val, c);
}
break;
case protocol_Lobby_LeaveLobby:
{
Detach(c)->Disconnect();
}
break;
}
if(update) SendUpdate();
}
void MainLobby::CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::LobbyClient* c)
{
for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
{
if(!gameLobby[i])
{
gameLobby[i] = new GameLobby(NetworkSession::Detach(c));
return;
}
}
this->gameLobby.Push(new GameLobby(NetworkSession::Detach(c)));
}
void MainLobby::JoinLobby(GameLogic::Protocol_LobbyJoinLobby& p, DanBias::LobbyClient* c)
{
for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
{
if (this->gameLobby[i]->GetID() == p.LobbyID)
{
this->gameLobby[i]->Attach(Detach(c));
return;
}
}
}
void MainLobby::SendUpdate()
{
//Send Lobbys
GameLogic::Protocol_LobbyUpdate();
}
}//End namespace DanBias

View File

@ -1,7 +1,10 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_MAINLOBBY_H
#define DANBIASSERVER_MAINLOBBY_H
#include "..\NetworkSession.h"
#include "NetworkSession.h"
#include "GameLobby.h"
#include <GameProtocols.h>
#include <PostBox\IPostBox.h>
@ -21,16 +24,19 @@ namespace DanBias
private:
void ParseEvents();
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c);
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::LobbyClient* c);
void CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::ClientObject& c);
//void CreateJoin(GameLogic::Protocol_LobbyJoinGame& p, DanBias::ClientObject& c);
void CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::LobbyClient* c);
void JoinLobby(GameLogic::Protocol_LobbyJoinLobby& p, DanBias::LobbyClient* c);
//void ProtocolRecievedCallback(CustomNetProtocol& protocol) override;
void SendUpdate();
private:
Oyster::IPostBox<NetworkSession::NetEvent> *box;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<GameLobby>> gameLobby;
private:
friend class AdminInterface;
};
}//End namespace DanBias
#endif // !DANBIASGAME_GAMELOBBY_H

View File

@ -0,0 +1,219 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "LobbyClient.h"
#include "NetworkSession.h"
#include <mutex>
namespace DanBias
{
NetworkSession::NetworkSession()
: owner(0)
, clientCount(0)
{}
NetworkSession::NetworkSession(const NetworkSession& orig)
{
this->clients = orig.clients;
this->owner = orig.owner;
this->clientCount = orig.clientCount;
}
const NetworkSession& NetworkSession::operator=(const NetworkSession& orig)
{
this->clients = orig.clients;
this->owner = orig.owner;
this->clientCount = orig.clientCount;
return *this;
}
NetworkSession::~NetworkSession()
{
this->clients.Clear();
this->clientCount = 0;
}
bool NetworkSession::Attach(Utility::DynamicMemory::SmartPointer<LobbyClient> client)
{
clientListLock.lock();
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->clients.Size(); i++)
{
if(!this->clients[i])
k = i;
}
if(k == -1)
{
this->clients.Push(client);
}
else
{
this->clients[k] = client;
}
this->clientCount++;
clientListLock.unlock();
return true;
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::Detach(Oyster::Network::NetworkClient* client)
{
Utility::DynamicMemory::SmartPointer<LobbyClient> val;
clientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetID() == client->GetID())
{
val = this->clients[i];
this->clients[i] = 0;
this->clientCount--;
}
}
clientListLock.unlock();
return val;
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::Detach(const LobbyClient* client)
{
Utility::DynamicMemory::SmartPointer<LobbyClient> val;
clientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetID() == client->GetID())
{
val = this->clients[i];
this->clients[i] = 0;
this->clientCount--;
}
}
clientListLock.unlock();
return val;
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::Detach(const LobbyClient& client)
{
Utility::DynamicMemory::SmartPointer<LobbyClient> val;
clientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetID() == client.GetID())
{
val = this->clients[i];
this->clients[i] = 0;
this->clientCount--;
}
}
clientListLock.unlock();
return val;
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::Detach(short ID)
{
Utility::DynamicMemory::SmartPointer<LobbyClient> val;
clientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetID() == ID)
{
val = this->clients[i];
this->clients[i] = 0;
this->clientCount--;
}
}
clientListLock.unlock();
return val;
}
bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
{
bool returnValue = false;
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i])
{
this->clients[i]->Send(&protocol);
returnValue = true;
}
}
return returnValue;
}
bool NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i] && this->clients[i]->GetID() == ID)
{
this->clients[i]->Send(&protocol);
return true;
}
}
return false;
}
void NetworkSession::SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->SetCallback(value);
}
}
void NetworkSession::CloseSession(bool dissconnectClients)
{
clientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(dissconnectClients) this->clients[i]->Disconnect();
else if(this->owner) this->owner->Attach(this->clients[i]);
}
this->clients.Clear();
clientListLock.unlock();
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::FindClient(int ID)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->GetID() == ID)
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<LobbyClient>();
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::FindClient(LobbyClient& obj)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->GetID() == obj.GetID())
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<LobbyClient>();
}
Utility::DynamicMemory::SmartPointer<LobbyClient> NetworkSession::FindClient(LobbyClient* obj)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->GetID() == obj->GetID())
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<LobbyClient>();
}
}//End namespace DanBias

View File

@ -0,0 +1,91 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_NETWORK_SESSION_H
#define DANBIASSERVER_NETWORK_SESSION_H
//warning C4150: deletion of pointer to incomplete type, no destructor called
#pragma warning(disable : 4150)
#define NOMINMAX
#include "INetworkSession.h"
#include <Utilities.h>
#include <OysterCallback.h>
#include <DynamicArray.h>
#include <PostBox\IPostBox.h>
#include <CustomNetProtocol.h>
#include <NetworkClient.h>
#include <vector>
#include <mutex>
namespace DanBias
{
class LobbyClient;
class GameClient;
class NetworkSession :public INetworkSession
{
public:
struct NetEvent
{
LobbyClient* sender;
GameClient* gameClient;
Oyster::Network::CustomNetProtocol protocol;
NetEvent():sender(0), gameClient(0){}
};
public:
NetworkSession();
NetworkSession(const NetworkSession& orig);
const NetworkSession& operator=(const NetworkSession& orig);
virtual~NetworkSession();
virtual bool Attach(Utility::DynamicMemory::SmartPointer<LobbyClient> client);
virtual Utility::DynamicMemory::SmartPointer<LobbyClient> Detach(Oyster::Network::NetworkClient* client);
virtual Utility::DynamicMemory::SmartPointer<LobbyClient> Detach(const LobbyClient* client);
virtual Utility::DynamicMemory::SmartPointer<LobbyClient> Detach(const LobbyClient& client);
virtual Utility::DynamicMemory::SmartPointer<LobbyClient> Detach(short ID);
Utility::DynamicMemory::SmartPointer<LobbyClient> FindClient(LobbyClient& obj);
Utility::DynamicMemory::SmartPointer<LobbyClient> FindClient(LobbyClient* obj);
Utility::DynamicMemory::SmartPointer<LobbyClient> FindClient(int ID);
/**
* Sends a message to all clients in this session.
*/
virtual bool Send(Oyster::Network::CustomNetProtocol& message);
/**
* Sends a message to a specific client in this session.
*/
virtual bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
/**
* Set the callback to all clients to where a messages is recieved.
*/
virtual void SetCallback(Oyster::Callback::OysterCallback<void, NetworkSession::NetEvent> value);
/**
* Closes the session and sends the clients to given owner session if any.
* If session is null, clients is assumed to already be elsewhere and only releases a reference.
*/
virtual void CloseSession(bool dissconnectClients = false);
/** Set where the clients is returned on closed session. */
inline void SetOwner(NetworkSession* owner) { this->owner = owner; }
protected:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
NetworkSession* owner; //Where clients end up when session is closed.
private:
std::mutex clientListLock;
int clientCount;
private:
friend class AdminInterface;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_NETWORK_SESSION_H

View File

@ -1,53 +0,0 @@
#include "ClientObject.h"
using namespace DanBias;
ClientObject::ClientObject(Oyster::Network::NetworkClient* client)
{
this->client = client;
this->client->SetRecieverObject(this, Oyster::Network::NetworkProtocolCallbackType_Object);
this->box = 0;
}
ClientObject::~ClientObject()
{
this->client->Disconnect();
}
void ClientObject::SetProtocolCallback(Oyster::Network::ProtocolRecieverObject* object)
{
this->GetClient()->SetRecieverObject(object, Oyster::Network::NetworkProtocolCallbackType_Object);
}
void ClientObject::SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box)
{
this->box = box;
}
GameLogic::Player* ClientObject::GetPlayer()
{
return this->player.Get();
}
Oyster::Network::NetworkClient* ClientObject::GetClient()
{
return this->client.Get();
}
void ClientObject::CreatePlayer()
{
if(this->player) return;
this->player = new GameLogic::Player();
}
void ClientObject::ErasePlayer()
{
while(this->player.Release());
}
void ClientObject::ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol)
{
if(!this->box) return;
NetworkSession::NetEvent _event;
_event.protocol = protocol;
_event.reciever = this;
this->box->Post(_event);
}

View File

@ -1,41 +0,0 @@
#ifndef DANBIASSERVER_CLIENT_OBJECT_H
#define DANBIASSERVER_CLIENT_OBJECT_H
#include "NetworkSession.h"
#include "NetworkClient.h"
#include <PostBox\PostBox.h>
#include <Player.h>
namespace DanBias
{
class ClientObject
:public Oyster::Network::ProtocolRecieverObject
{
public:
ClientObject(Oyster::Network::NetworkClient* client);
virtual~ClientObject();
void SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box);
void SetProtocolCallback(Oyster::Network::ProtocolRecieverObject* object);
GameLogic::Player* GetPlayer();
Oyster::Network::NetworkClient* GetClient();
public:
void CreatePlayer();
void ErasePlayer();
private:
/** This method is NOT threadsafe. */
virtual void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override;
private:
Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent>* box;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_CLIENT_OBJECT_H

View File

@ -1,263 +0,0 @@
#include <GameProtocols.h>
#include <PostBox\PostBox.h>
#include "GameSession.h"
#include "ClientObject.h"
#include <GameLogicStates.h>
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
using namespace Oyster::Thread;
using namespace GameLogic;
namespace DanBias
{
GameSession::GameSession()
{
this->box = 0;
}
GameSession::~GameSession()
{
delete this->box;
this->box = 0;
}
void GameSession::Run(GameSessionDescription& desc)
{
if(this->Init(desc))
{
if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return;
this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1);
}
}
void GameSession::Join(Utility::DynamicMemory::SmartPointer<ClientObject> client)
{
AttachClient(client, this->box);
}
////private: overriden NetworkSession functions
void GameSession::AttachClient(SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box )
{
NetworkSession::AttachClient(client, box);
}
void GameSession::Close()
{
}
SmartPointer<ClientObject> GameSession::DetachClient(NetworkClient* client)
{
return SmartPointer<ClientObject>();
}
SmartPointer<ClientObject> GameSession::DetachClient(ClientObject* client)
{
return SmartPointer<ClientObject>();
}
SmartPointer<ClientObject> GameSession::DetachClient(short ID)
{
return SmartPointer<ClientObject>();
}
void GameSession::Send(CustomNetProtocol& protocol)
{
NetworkSession::Send(protocol);
}
void GameSession::Send(CustomNetProtocol& protocol, int ID)
{
NetworkSession::Send(protocol, ID);
}
void GameSession::SetPostbox(IPostBox<NetworkSession::NetEvent> *box)
{
NetworkSession::SetPostbox(box);
}
void GameSession::CloseSession(NetworkSession* clientDestination)
{
}
////private: //overriden Threading functions
void GameSession::ThreadEntry()
{
}
void GameSession::ThreadExit()
{
}
bool GameSession::DoWork ( )
{
this->ParseEvents();
this->Frame();
return true;
}
#ifndef ERIK
////private:
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);
desc.clients[i]->CreatePlayer();
this->clients.Push(desc.clients[i]);
}
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)
{
if( ProtocolIsGameplay(p[protocol_INDEX_ID].value.netShort) )
{
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
//Oyster::Math::Float4x4 p;
//Protocol_ObjectPosition op(c.GetPlayer()->GetRigidBody()->GetOrientation(p));
//op.object_ID = c.GetPlayer()->GetID();
//this->Send(*op.GetProtocol());
}
break;
case protocol_Gameplay_PlayerMouseMovement:
break;
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gameplay_CreateObject:
break;
case protocol_Gameplay_ObjectPosition:
break;
}
}
else if(ProtocolIsGeneral(p[protocol_INDEX_ID].value.netShort) )
{
}
}
#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

@ -1,57 +0,0 @@
#ifndef DANBIASSERVER_GAME_SESSION_H
#define DANBIASSERVER_GAME_SESSION_H
#include "NetworkSession.h"
#include <PostBox\IPostBox.h>
#include <Thread\OysterThread.h>
namespace DanBias
{
class ClientObject;
class GameSession :private NetworkSession, public Oyster::Thread::IThreadObject
{
public:
struct GameSessionDescription
{
NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
};
public:
GameSession();
virtual~GameSession();
void Run(GameSessionDescription& desc);
void Join(Utility::DynamicMemory::SmartPointer<ClientObject> client);
private: //overriden NetworkSession functions
void Close();
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box = 0) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(Oyster::Network::NetworkClient* client) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(ClientObject* client) override;
Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(short ID) override;
void Send(Oyster::Network::CustomNetProtocol& protocol) override;
void Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override;
void SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box) override;
void CloseSession(NetworkSession* clientDestination) override;
private: //overriden Threading functions
void ThreadEntry( ) override;
void ThreadExit( ) override;
bool DoWork ( ) override;
private:
bool Init(GameSessionDescription& desc);
void Frame();
void ParseEvents();
void ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c);
private:
NetworkSession* owner;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box;
Oyster::Thread::OysterThread worker;
};//End GameSession
}//End namespace DanBias
#endif // !DANBIASSERVER_GAME_SESSION_H

View File

@ -1,25 +0,0 @@
#include "GameLobby.h"
namespace DanBias
{
GameLobby::GameLobby(Utility::DynamicMemory::SmartPointer<ClientObject> owner)
{
}
GameLobby::~GameLobby()
{
}
void GameLobby::Release()
{
}
void GameLobby::Join(Utility::DynamicMemory::SmartPointer<ClientObject> client)
{
NetworkSession::AttachClient(client);
}
void GameLobby::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box)
{ }
}//End namespace DanBias

View File

@ -1,24 +0,0 @@
#ifndef DANBIASSERVER_GAMELOBBY_H
#define DANBIASSERVER_GAMELOBBY_H
#include "..\NetworkSession.h"
namespace DanBias
{
class GameLobby :public NetworkSession
{
public:
GameLobby(Utility::DynamicMemory::SmartPointer<ClientObject> owner);
virtual~GameLobby();
void Release();
void Join(Utility::DynamicMemory::SmartPointer<ClientObject> client);
private:
void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box = 0) override;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_GAME_LOBBY_H

View File

@ -1,96 +0,0 @@
#include "MainLobby.h"
#include "..\ClientObject.h"
#include <PlayerProtocols.h>
#include <PostBox\PostBox.h>
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
namespace DanBias
{
MainLobby::MainLobby()
:gameLobby(5)
{
this->box = new PostBox<DanBias::NetworkSession::NetEvent>();
}
MainLobby::~MainLobby()
{
delete this->box;
this->box = 0;
}
void MainLobby::Release()
{
this->CloseSession(0);
}
void MainLobby::Frame()
{
ParseEvents();
}
IPostBox<NetworkSession::NetEvent>* MainLobby::GetPostbox()
{
return this->box;
}
//////// Private
void MainLobby::ParseEvents()
{
if(this->box && !this->box->IsEmpty())
{
NetEvent &e = this->box->Fetch();
ParseProtocol(e.protocol, *e.reciever);
}
}
void MainLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
//switch (p[0].value.netChar)
//{
// case protocol_Lobby_CreateGame:
// {
// GameLogic::Protocol_LobbyCreateGame val(p);
// CreateGame(val, c);
// }
// break;
// case protocol_Lobby_JoinGame:
// {
//
// }
// break;
// case protocol_Lobby_JoinLobby:
// {
//
// }
// break;
// case protocol_Lobby_LeaveLobby:
// {
//
// }
// break;
//}
}
void MainLobby::CreateGame(GameLogic::Protocol_LobbyCreateGame& p, DanBias::ClientObject& c)
{
SmartPointer<ClientObject> sc = NetworkSession::FindClient(c);
NetworkSession::DetachClient(&c);
if(!sc) return;
for (unsigned int i = 0; i < this->gameLobby.Size(); i++)
{
if(!gameLobby[i])
{
gameLobby[i] = new GameLobby(sc);
return;
}
}
this->gameLobby.Push(new GameLobby(sc));
}
}//End namespace DanBias

View File

@ -1,180 +0,0 @@
#include "ClientObject.h"
#include "NetworkSession.h"
#include <mutex>
static std::mutex ClientListLock;
namespace DanBias
{
NetworkSession::NetworkSession()
{ }
NetworkSession::NetworkSession(const NetworkSession& orig)
{
this->clients = orig.clients;
}
const NetworkSession& NetworkSession::operator=(const NetworkSession& orig)
{
this->clients = orig.clients;
return *this;
}
NetworkSession::~NetworkSession()
{
this->clients.Clear();
}
void NetworkSession::AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box)
{
ClientListLock.lock();
int k = -1;
for (unsigned int i = 0; (k == -1) && i < this->clients.Size(); i++)
{
if(!this->clients[i])
k = i;
}
if(k == -1)
{
this->clients.Push(client);
this->clients[this->clients.Size() - 1]->SetPostbox(box);
}
else
{
this->clients[k] = client;
this->clients[k]->SetPostbox(box);
}
ClientListLock.unlock();
}
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::DetachClient(Oyster::Network::NetworkClient* client)
{
Utility::DynamicMemory::SmartPointer<ClientObject> val;
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetClient()->Id() == client->Id())
{
val = this->clients[i];
this->clients[i] = 0;
}
}
ClientListLock.unlock();
return val;
}
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::DetachClient(ClientObject* client)
{
Utility::DynamicMemory::SmartPointer<ClientObject> val;
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetClient()->Id() == client->GetClient()->Id())
{
val = this->clients[i];
this->clients[i] = 0;
}
}
ClientListLock.unlock();
return val;
}
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::DetachClient(short ID)
{
Utility::DynamicMemory::SmartPointer<ClientObject> val;
ClientListLock.lock();
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->GetClient()->Id() == ID)
{
val = this->clients[i];
this->clients[i] = 0;
}
}
ClientListLock.unlock();
return val;
}
void NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->GetClient()->Send(&protocol);
}
}
void NetworkSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->GetClient()->Id() == ID)
{
this->clients[i]->GetClient()->Send(&protocol);
break;
}
}
}
void NetworkSession::SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->SetPostbox(box);
}
}
void NetworkSession::CloseSession(NetworkSession * owner)
{
ClientListLock.lock();
if(!owner)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->GetClient()->Disconnect();
}
}
else
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
owner->AttachClient(this->clients[i]);
}
}
this->clients.Clear();
ClientListLock.unlock();
}
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::FindClient(int ID)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->GetClient()->Id() == ID)
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<ClientObject>();
}
Utility::DynamicMemory::SmartPointer<ClientObject> NetworkSession::FindClient(ClientObject& obj)
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->GetClient()->Id() == obj.GetClient()->Id())
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<ClientObject>();
}
}//End namespace DanBias

View File

@ -1,57 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#ifndef DANBIASSERVER_NETWORK_SESSION_H
#define DANBIASSERVER_NETWORK_SESSION_H
#pragma warning(disable: 4150)
#define NOMINMAX
#include <Utilities.h>
#include <DynamicArray.h>
#include <PostBox\IPostBox.h>
#include <CustomNetProtocol.h>
#include <NetworkClient.h>
#include <vector>
namespace DanBias
{
class ClientObject;
class NetworkSession
{
public:
struct NetEvent
{
ClientObject* reciever;
Oyster::Network::CustomNetProtocol protocol;
};
public:
NetworkSession();
NetworkSession(const NetworkSession& orig);
const NetworkSession& operator=(const NetworkSession& orig);
virtual~NetworkSession();
virtual void AttachClient(Utility::DynamicMemory::SmartPointer<ClientObject> client, Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box = 0);
virtual Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(Oyster::Network::NetworkClient* client);
virtual Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(ClientObject* client);
virtual Utility::DynamicMemory::SmartPointer<ClientObject> DetachClient(short ID);
virtual void Send(Oyster::Network::CustomNetProtocol& protocol);
virtual void Send(Oyster::Network::CustomNetProtocol& protocol, int ID);
//TODO: Do more lobby features
virtual void SetPostbox(Oyster::IPostBox<DanBias::NetworkSession::NetEvent> *box);
virtual void CloseSession(NetworkSession* clientDestination); //<! Closes the session and sends the clients to given sesison. If session is null, clients is kicked from server.
Utility::DynamicMemory::SmartPointer<ClientObject> FindClient(int ID);
Utility::DynamicMemory::SmartPointer<ClientObject> FindClient(ClientObject& obj);
protected:
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<ClientObject>> clients;
};
}//End namespace DanBias
#endif // !DANBIASSERVER_NETWORK_SESSION_H

View File

@ -71,7 +71,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)Game\DanBiasServer\Include;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\DanBiasServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -79,7 +79,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)Game\DanBiasServer\Include;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\DanBiasServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -87,7 +87,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)Game\DanBiasServer\Include;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\DanBiasServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -95,7 +95,7 @@
<OutDir>$(SolutionDir)..\Bin\Executable\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)Game\DanBiasServer\Include;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game\DanBiasServer;C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
<LibraryPath>$(OutDir)..\DLL\;C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -1,7 +1,8 @@
/////////////////////////////////////////////////
// Launcher to launch Danbias server or client //
/////////////////////////////////////////////////
#define NOMINMAX
//////////////////////////////////////////////////
// Launcher to launch Danbias server or client //
// Created by [Dennis Andersen] [2013] //
//////////////////////////////////////////////////
#define NOMINMAX //Blame it on windows
#include <Windows.h>
#include <vld.h>

View File

@ -54,17 +54,19 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
switch(movement)
{
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD:
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
MoveForward();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD:
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
MoveBackwards();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_LEFT:
MoveLeft();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_RIGHT:
MoveRight();
break;
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_JUMP:
@ -84,13 +86,13 @@ void Player::MoveBackwards()
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross(myData->lookDir);
//Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross(myData->lookDir);
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100);
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross(myData->lookDir);
//Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross(myData->lookDir);
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100);
}

View File

@ -19,11 +19,18 @@ namespace GameLogic
Protocol_General_Status()
{
this->protocol[0].value = protocol_General_Status;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_General_Status;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
Protocol_General_Status(States state)
{
this->protocol[protocol_INDEX_ID].value = protocol_General_Status;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->status = state;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = status;
@ -34,55 +41,6 @@ namespace GameLogic
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_General_Ping :public Oyster::Network::CustomProtocolObject
{
Protocol_General_Ping()
{
this->protocol[0].value = protocol_General_Ping;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_General_Disconnect :public Oyster::Network::CustomProtocolObject
{
Protocol_General_Disconnect()
{
this->protocol[0].value = protocol_General_Disconnect;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_General_DisconnectKick :public Oyster::Network::CustomProtocolObject
{
Protocol_General_DisconnectKick()
{
this->protocol[0].value = protocol_General_DisconnectKick;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_General_Text :public Oyster::Network::CustomProtocolObject
{
@ -90,8 +48,8 @@ namespace GameLogic
Protocol_General_Text()
{
this->protocol[0].value = protocol_General_Text;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_General_Text;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override

View File

@ -6,7 +6,4 @@
#include "LobbyProtocols.h"
#include "ControlProtocols.h"
#include "TEST_PROTOCOLS.h"
#endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H

View File

@ -160,7 +160,6 @@
<ClInclude Include="ObjectProtocols.h" />
<ClInclude Include="PlayerProtocols.h" />
<ClInclude Include="ProtocolIdentificationID.h" />
<ClInclude Include="TEST_PROTOCOLS.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -18,8 +18,8 @@ namespace GameLogic
Protocol_LobbyCreateGame()
{
this->protocol[0].value = protocol_Lobby_CreateGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_CreateGame;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
this->protocol[2].type = Oyster::Network::NetAttributeType_Char;
@ -46,8 +46,8 @@ namespace GameLogic
Protocol_LobbyJoinGame()
{
this->protocol[0].value = protocol_Lobby_JoinGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinGame;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
}
@ -67,8 +67,8 @@ namespace GameLogic
Protocol_LobbyStartGame()
{
this->protocol[0].value = protocol_Lobby_StartGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_StartGame;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
}
@ -84,13 +84,23 @@ namespace GameLogic
struct Protocol_LobbyJoinLobby :public Oyster::Network::CustomProtocolObject
{
Protocol_LobbyJoinLobby()
int LobbyID;
Protocol_LobbyJoinLobby(int id = -1)
{
this->protocol[0].value = protocol_Lobby_JoinLobby;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_JoinLobby;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
LobbyID = id;
}
Protocol_LobbyJoinLobby(Oyster::Network::CustomNetProtocol& o)
{
LobbyID = o[1].value.netInt;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = LobbyID;
return &protocol;
}
@ -103,8 +113,8 @@ namespace GameLogic
Protocol_LobbyLeaveLobby()
{
this->protocol[0].value = protocol_Lobby_LeaveLobby;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_LeaveLobby;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
@ -115,6 +125,53 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_LobbyUpdate :public Oyster::Network::CustomProtocolObject
{
struct LobbyUpdateData
{
std::string mapName;
int LobbyId;
};
int count;
LobbyUpdateData* data;
Protocol_LobbyUpdate()
{
this->protocol[protocol_INDEX_ID].value = protocol_Lobby_LeaveLobby;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
}
Protocol_LobbyUpdate( Oyster::Network::CustomNetProtocol* p )
{
count = (*p)[1].value.netInt;
data = new LobbyUpdateData[count];
for (int i = 0; i < count; i++)
{
//data[i].mapName = (*p)[i].value.
}
}
~Protocol_LobbyUpdate()
{
delete [] data;
data = 0;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value.netInt = count;
for (int i = 2; i < count; i++)
{
protocol[i].type = Oyster::Network::NetAttributeType_CharArray;
protocol[i+1].type = Oyster::Network::NetAttributeType_Int;
protocol[i].value.netCharPtr = const_cast<char*>(data[i-2].mapName.c_str());
protocol[i+1].value.netInt = data[i-1].LobbyId;
}
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
}
#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H

View File

@ -17,29 +17,16 @@ namespace GameLogic
Protocol_CreateObject()
{
this->protocol[0].value = protocol_Gameplay_CreateObject;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray;
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
this->protocol[4].type = Oyster::Network::NetAttributeType_Float;
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
this->protocol[15].type = Oyster::Network::NetAttributeType_Float;
this->protocol[16].type = Oyster::Network::NetAttributeType_Float;
this->protocol[17].type = Oyster::Network::NetAttributeType_Float;
this->protocol[18].type = Oyster::Network::NetAttributeType_Float;
for (int i = 3; i <= 18; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
@ -70,7 +57,6 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject
{
int object_ID;
@ -79,52 +65,40 @@ namespace GameLogic
Protocol_ObjectPosition()
{
this->protocol[0].value = protocol_Gameplay_ObjectPosition;
this->protocol[0].type = Oyster::Network::NetAttributeType_Int;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
this->protocol[4].type = Oyster::Network::NetAttributeType_Float;
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
this->protocol[7].type = Oyster::Network::NetAttributeType_Float;
this->protocol[8].type = Oyster::Network::NetAttributeType_Float;
this->protocol[9].type = Oyster::Network::NetAttributeType_Float;
this->protocol[10].type = Oyster::Network::NetAttributeType_Float;
this->protocol[11].type = Oyster::Network::NetAttributeType_Float;
this->protocol[12].type = Oyster::Network::NetAttributeType_Float;
this->protocol[13].type = Oyster::Network::NetAttributeType_Float;
this->protocol[14].type = Oyster::Network::NetAttributeType_Float;
this->protocol[15].type = Oyster::Network::NetAttributeType_Float;
this->protocol[16].type = Oyster::Network::NetAttributeType_Float;
this->protocol[17].type = Oyster::Network::NetAttributeType_Float;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = -1;
memset(&worldMatrix[0], 0, sizeof(float) * 16);
}
Protocol_ObjectPosition(float m[16])
Protocol_ObjectPosition(float m[16], int id)
{
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_ObjectPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
for (int i = 2; i <= 17; i++)
{
this->protocol[i].type = Oyster::Network::NetAttributeType_Float;
}
object_ID = id;
memcpy(&worldMatrix[0], &m[0], sizeof(float)*16);
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = object_ID;
this->protocol[2].value = worldMatrix[1];
this->protocol[3].value = worldMatrix[2];
this->protocol[4].value = worldMatrix[3];
this->protocol[5].value = worldMatrix[4];
this->protocol[6].value = worldMatrix[5];
this->protocol[7].value = worldMatrix[6];
this->protocol[8].value = worldMatrix[7];
this->protocol[9].value = worldMatrix[8];
this->protocol[10].value = worldMatrix[9];
this->protocol[11].value = worldMatrix[10];
this->protocol[12].value = worldMatrix[11];
this->protocol[13].value = worldMatrix[12];
this->protocol[14].value = worldMatrix[13];
this->protocol[15].value = worldMatrix[14];
this->protocol[16].value = worldMatrix[15];
this->protocol[17].value = worldMatrix[16];
for (int i = 2; i <= 17; i++)
{
this->protocol[i].value = worldMatrix[i-2];
}
return &protocol;
}
@ -138,8 +112,8 @@ namespace GameLogic
Protocol_RemoveObject()
{
this->protocol[0].value = protocol_Gameplay_RemoveObject;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_RemoveObject;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Int;
}

View File

@ -25,8 +25,8 @@ namespace GameLogic
Protocol_PlayerMovement()
{
this->protocol[0].value = protocol_Gameplay_PlayerNavigation;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerNavigation;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[2].type = Oyster::Network::NetAttributeType_Bool;
@ -71,8 +71,8 @@ namespace GameLogic
Protocol_PlayerMouse()
{
this->protocol[0].value = protocol_Gameplay_PlayerMouseMovement;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerMouseMovement;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
@ -105,8 +105,8 @@ namespace GameLogic
Protocol_PlayerPosition()
{
this->protocol[0].value = protocol_Gameplay_PlayerPosition;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_PlayerPosition;
this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;

View File

@ -9,30 +9,29 @@
/** Index where the identifier is located(aka protocol identification index) **/
/* Use this as id accesser since it may change in the future. */
#define protocol_INDEX_ID 0
/***********************************/
/********* RESERVERD PROTOCOLS *****/
/********* RESERVERD PROTOCOLS ***************************************************************************************************/
/********** [ 0 - 100 ] *********/
#define protocol_RESERVED_MIN 0
#define protocol_RESERVED_MAX 99
/***********************************/
/********* GENERAL PROTOCOLS *******/
/********* GENERAL PROTOCOLS ***************************************************************************************************/
/***********[ 100 - 200 ]***********/
#define protocol_GeneralMIN 100 /* This defines lower bounds of general protocols (okay to have same value as the first since this should not realy be sent). */
#define protocol_General_Disconnect 100
#define protocol_General_Ping 102
#define protocol_General_Text 103
#define protocol_General_Status 104
#define protocol_General_DisconnectKick 105
#define protocol_GeneralMIN 100 /* This defines lower bounds of general protocols (okay to have same value on first element). */
#define protocol_General_Status 100
#define protocol_General_Text 101
#define protocol_GeneralMAX 199
/***********************************/
/********* LOBBY PROTOCOLS *********/
/********* LOBBY PROTOCOLS ***************************************************************************************************/
/***********[ 200 - 300 ]***********/
#define protocol_LobbyMIN 200
#define protocol_LobbyMIN 200
#define protocol_Lobby_CreateGame 200
#define protocol_Lobby_JoinGame 201
#define protocol_Lobby_StartGame 202
@ -43,7 +42,7 @@
/***********************************/
/********* GAMEPLAY PROTOCOLS ******/
/********* GAMEPLAY PROTOCOLS ***************************************************************************************************/
/***********[ 300 - 400 ]***********/
#define protocol_GameplayMIN 300
#define protocol_Gameplay_PlayerNavigation 300
@ -56,7 +55,7 @@
/************************************/
/*********** PROTOCOL MACROS ********/
/*********** PROTOCOL MACROS ***************************************************************************************************/
/************************************/
inline bool ProtocolIsLobby(short ID) { return (ID >= protocol_LobbyMIN && ID <= protocol_LobbyMAX); }
inline bool ProtocolIsGeneral(short ID) { return (ID >= protocol_GeneralMIN && ID <= protocol_GeneralMAX); }
@ -65,11 +64,8 @@ inline bool ProtocolIsGameplay(short ID) { return (ID >= protocol_GameplayMIN &&
/***********************************/
/*********** TEST PROTOCOLS ********/
/***********[ 1000 - x ]************/
#define PROTOCOL_TEST 1000
/*********** TEST PROTOCOLS *******************************************************************************************************/
/***********[ x - x ]************/
#endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H

View File

@ -1,35 +0,0 @@
#ifndef GAMESERVER_TEST_H
#define GAMESERVER_TEST_H
#include <CustomNetProtocol.h>
#include "ProtocolIdentificationID.h"
namespace GameLogic
{
struct Protocol_TEST :public Oyster::Network::CustomProtocolObject
{
int ProtocolID;
char text;
Protocol_TEST()
{
this->protocol[0].value = ProtocolID = PROTOCOL_TEST;
this->protocol[0].type = Oyster::Network::NetAttributeType_Int;
this->protocol[1].type = Oyster::Network::NetAttributeType_Char;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = text;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
}
#endif // !GAMESERVER_TEST_H

View File

@ -33,11 +33,16 @@ namespace Utility
void Clear();
void Expand(int elements = 0);
void Resize(unsigned int size);
void Swap(unsigned int a, unsigned int b);
unsigned int Size() const;
unsigned int Capacity() const;
private:
void Expand(int elements = 0);
private:
T* data;
int size;
@ -179,8 +184,44 @@ namespace Utility
this->capacity = 0;
}
template <typename T> void DynamicArray<T>::Resize(unsigned int size)
{
if (size == this->capacity) return; //No need to resize
T* temp = new T[size];
for (int i = 0; i < this->size; i++)
{
temp[i] = this->data[i];
}
this->capacity = size;
this->size = size;
delete [] this->data;
this->data = temp;
}
template <typename T> void DynamicArray<T>::Swap(unsigned int a, unsigned int b)
{
T temp = this->data[a];
this->data[a] = this->data[b];
this->data[b] = temp;
}
template <typename T> unsigned int DynamicArray<T>::Size() const
{
return (unsigned int)this->size;
}
template <typename T> unsigned int DynamicArray<T>::Capacity() const
{
return (unsigned int)this->capacity;
}
template <typename T> void DynamicArray<T>::Expand(int elements)
{
if(elements < 1) return;
int newSize = this->size + elements;
if(newSize >= this->capacity)
@ -198,16 +239,6 @@ namespace Utility
}
}
template <typename T> unsigned int DynamicArray<T>::Size() const
{
return (unsigned int)this->size;
}
template <typename T> unsigned int DynamicArray<T>::Capacity() const
{
return (unsigned int)this->capacity;
}
#pragma endregion
}
}

View File

@ -27,19 +27,53 @@ namespace Oyster
CallbackType_PostBox,
CallbackType_Function,
CallbackType_Object,
CallbackType_Unknown,
};
template <typename ReturnVal = void, typename ParamVal = void>
union OysterCallback
union OysterCallbackValue
{
IPostBox<ParamVal>* callbackPostBox;
CallbackObject<ReturnVal, ParamVal> *callbackObject;
typename CallbackFunction<ReturnVal, ParamVal>::FNC callbackFunction;
OysterCallback() { memset(this, 0, sizeof(OysterCallback)); }
OysterCallback(IPostBox<ReturnVal>* postbox) { callbackPostBox = postbox; }
OysterCallback(CallbackObject<ReturnVal, ParamVal>* obj) { callbackObject = obj; }
OysterCallback(typename CallbackFunction<ReturnVal, ParamVal>::FNC function) { callbackFunction = function; }
OysterCallbackValue() { memset(this, 0, sizeof(OysterCallbackValue)); }
OysterCallbackValue(IPostBox<ReturnVal>* postbox) { callbackPostBox = postbox; }
OysterCallbackValue(CallbackObject<ReturnVal, ParamVal>* obj) { callbackObject = obj; }
OysterCallbackValue(typename CallbackFunction<ReturnVal, ParamVal>::FNC function) { callbackFunction = function; }
};
template <typename ReturnVal = void, typename ParamVal = void>
struct OysterCallback
{
OysterCallbackValue<ReturnVal, ParamVal> value;
CallbackType callbackType;
OysterCallback() :callbackType(CallbackType_Unknown){}
bool operator()()
{
return true;
}
bool operator()(ParamVal e)
{
switch (callbackType)
{
case CallbackType_Function:
value.callbackFunction(e);
return true;
break;
case CallbackType_Object:
value.callbackObject->ObjectCallback(e);
return true;
break;
case CallbackType_PostBox:
value.callbackPostBox->Post(e);
return true;
break;
}
return false;
}
};
}
}

View File

@ -11,27 +11,29 @@ namespace Oyster
{
namespace Thread
{
/**
* Inherit this class to get threading compatibility.
*/
class IThreadObject
{
public:
/**
* Override this to get notified when the thread is started.
*/
virtual void ThreadEntry() { }
/**
* Override this to get notified when the thread is about to exit.
*/
virtual void ThreadExit() { }
/**
* This function is required to get threading working.
* Note that this function is NOT thread safe.
* OBS! Do not highjack the looping.
*/
virtual bool DoWork ( ) = 0;
};
//This class was moved to OysterThread.h
///**
//* Inherit this class to get threading compatibility.
//*/
//class IThreadObject
//{
//public:
// /**
// * Override this to get notified when the thread is started.
// */
// virtual void ThreadEntry() { }
// /**
// * Override this to get notified when the thread is about to exit.
// */
// virtual void ThreadExit() { }
// /**
// * This function is required to get threading working.
// * Note that this function is NOT thread safe.
// * OBS! Do not highjack the looping.
// */
// virtual bool DoWork ( ) = 0;
//};
}
}

View File

@ -6,10 +6,34 @@
#define MISC_OYSTER_THREAD_H
#include "IThreadObject.h"
namespace Oyster
{
namespace Thread
{
/**
* Inherit this class to get threading compatibility.
*/
class IThreadObject
{
public:
/**
* Override this to get notified when the thread is started.
*/
virtual void ThreadEntry() { }
/**
* Override this to get notified when the thread is about to exit.
*/
virtual void ThreadExit() { }
/**
* This function is required to get threading working.
* Note that this function is NOT thread safe.
* OBS! Do not highjack the looping.
*/
virtual bool DoWork ( ) = 0;
};
typedef bool (*ThreadFnc)(void);
enum OYSTER_THREAD_ERROR
{
OYSTER_THREAD_ERROR_SUCCESS,
@ -43,12 +67,16 @@ namespace Oyster
virtual~OysterThread();
OYSTER_THREAD_ERROR Create(IThreadObject* worker, bool start, bool detach = false);
OYSTER_THREAD_ERROR Create(ThreadFnc 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 Start();
OYSTER_THREAD_ERROR Stop(bool wait = false);
OYSTER_THREAD_ERROR Pause();
OYSTER_THREAD_ERROR Pause(int mSec);
OYSTER_THREAD_ERROR Resume();
OYSTER_THREAD_ERROR Reset(IThreadObject* worker = 0);
OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0);
OYSTER_THREAD_ERROR SetWorker(ThreadFnc worker = 0);
OYSTER_THREAD_ERROR Terminate(bool wait = true);
OYSTER_THREAD_ERROR Wait();
OYSTER_THREAD_ERROR Wait(int mSec);

View File

@ -4,6 +4,8 @@
#include "OysterThread.h"
#include "..\Utilities.h"
#include "..\OysterCallback.h"
#include <thread>
#include <assert.h>
#include <atomic>
@ -23,13 +25,31 @@ using namespace Utility::DynamicMemory;
OYSTER_THREAD_STATE_NORMAL,
OYSTER_THREAD_STATE_DEAD,
};
struct OwnerContainer
{
Oyster::Callback::CallbackType type;
union OwnerValue
{
IThreadObject* obj;
ThreadFnc fnc;
OwnerValue() { memset(this, 0, sizeof(OwnerValue)); }
OwnerValue(IThreadObject* v) { obj = v; }
OwnerValue(ThreadFnc v) { fnc = v; }
} value;
operator bool()
{
return (value.fnc ||value.obj);
}
};
struct ThreadData
{
OYSTER_THREAD_STATE state; //<! The current thread state.
OYSTER_THREAD_PRIORITY prio; //<! The thread priority
IThreadObject *owner; //<! The worker object.
std::atomic<int> msec; //<! A timer in miliseconds.
OYSTER_THREAD_STATE state; //<! The current thread state.
OYSTER_THREAD_PRIORITY prio; //<! The thread priority
//IThreadObject *owner; //<! The worker object.
//Oyster::Callback::OysterCallback<bool, void> ownerObj; //
OwnerContainer ownerObj; //
std::atomic<int> msec; //<! A timer in miliseconds.
std::timed_mutex threadFunctionLock;
//std::mutex threadWaitFunctionLock;
@ -40,6 +60,7 @@ using namespace Utility::DynamicMemory;
struct RefData
{
//std::mutex threadWaitFunctionLock;
bool isCreated;
ThreadData *threadData;
std::thread workerThread;
@ -51,8 +72,9 @@ using namespace Utility::DynamicMemory;
}
~RefData()
{
Terminate(true);
delete threadData;
//threadWaitFunctionLock.lock();
Terminate(true);
//threadWaitFunctionLock.unlock();
}
OYSTER_THREAD_ERROR Terminate(bool wait)
{
@ -64,7 +86,11 @@ using namespace Utility::DynamicMemory;
{
if(std::this_thread::get_id() != this->workerThread.get_id())
if(this->workerThread.joinable())
{
this->workerThread.join();
this->isCreated = false;
this->threadData = 0;
}
}
else
{
@ -73,7 +99,49 @@ using namespace Utility::DynamicMemory;
}
return OYSTER_THREAD_ERROR_SUCCESS;
}
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, IThreadObject* worker, bool start, bool detach)
//OYSTER_THREAD_ERROR Create(ThreadFunction fnc, IThreadObject* worker, bool start, bool detach)
//{
// if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
//
// threadData = new ThreadData();
// if(start)
// this->threadData->state = OYSTER_THREAD_STATE_NORMAL;
// else
// this->threadData->state = OYSTER_THREAD_STATE_IDLE;
// threadData->owner = worker;
// threadData->prio = OYSTER_THREAD_PRIORITY_3;
//
// workerThread = std::thread(fnc, this->threadData);
//
// if(detach)
// this->workerThread.detach();
//
// isCreated = true;
//
// return OYSTER_THREAD_ERROR_SUCCESS;
//}
//OYSTER_THREAD_ERROR Create(ThreadFunction fnc, Oyster::Callback::OysterCallback<bool, void> worker, bool start, bool detach)
//{
// if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
//
// threadData = new ThreadData();
// if(start)
// this->threadData->state = OYSTER_THREAD_STATE_NORMAL;
// else
// this->threadData->state = OYSTER_THREAD_STATE_IDLE;
// threadData->ownerObj = worker;
// threadData->prio = OYSTER_THREAD_PRIORITY_3;
//
// workerThread = std::thread(fnc, this->threadData);
//
// if(detach)
// this->workerThread.detach();
//
// isCreated = true;
//
// return OYSTER_THREAD_ERROR_SUCCESS;
//}
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach)
{
if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
@ -82,7 +150,7 @@ using namespace Utility::DynamicMemory;
this->threadData->state = OYSTER_THREAD_STATE_NORMAL;
else
this->threadData->state = OYSTER_THREAD_STATE_IDLE;
threadData->owner = worker;
threadData->ownerObj = worker;
threadData->prio = OYSTER_THREAD_PRIORITY_3;
workerThread = std::thread(fnc, this->threadData);
@ -95,11 +163,19 @@ using namespace Utility::DynamicMemory;
return OYSTER_THREAD_ERROR_SUCCESS;
}
};
struct OysterThread::PrivateData
{
SmartPointer<RefData> data;
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, IThreadObject* worker, bool start, bool detach)
PrivateData(){}
~PrivateData()
{
if(data)
if(data->threadData)
memset(&data->threadData->ownerObj, 0, sizeof(OwnerContainer));
}
OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach)
{
if(data) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated;
data = new RefData();
@ -107,6 +183,9 @@ using namespace Utility::DynamicMemory;
}
OYSTER_THREAD_ERROR Terminate(bool wait)
{
if(!data)
return OYSTER_THREAD_ERROR_FAILED;
return data->Terminate(wait);
}
};
@ -131,15 +210,18 @@ using namespace Utility::DynamicMemory;
}
static bool DoWork(ThreadData* w)
{
try
switch (w->ownerObj.type)
{
if(w->owner)
return w->owner->DoWork();
}
catch( ... )
{
printf("Something went wrong on thread with id: [%i]", std::this_thread::get_id());
case Oyster::Callback::CallbackType_Function:
if(w->ownerObj.value.fnc) return w->ownerObj.value.fnc();
break;
case Oyster::Callback::CallbackType_Object:
if(w->ownerObj.value.obj) return w->ownerObj.value.obj->DoWork();
break;
}
return true;
}
static void CheckStatus(ThreadData* w)
@ -154,7 +236,7 @@ using namespace Utility::DynamicMemory;
{
CheckStatus(w);
if(w->owner) w->owner->ThreadEntry();
if(w->ownerObj.value.obj) w->ownerObj.value.obj->ThreadEntry();
while (w->state == OYSTER_THREAD_STATE_NORMAL)
{
@ -163,9 +245,10 @@ using namespace Utility::DynamicMemory;
CheckStatus(w);
}
if(w->owner) w->owner->ThreadExit();
if(w->ownerObj.value.obj) w->ownerObj.value.obj->ThreadExit();
w->state = OYSTER_THREAD_STATE_DEAD;
delete w;
}
};
@ -194,15 +277,52 @@ OysterThread::~OysterThread()
}
OYSTER_THREAD_ERROR OysterThread::Create(IThreadObject* worker, bool start, bool detach)
{
if(!this->privateData) this->privateData = new PrivateData();
OwnerContainer c;
c.type = Oyster::Callback::CallbackType_Object;
c.value = worker;
return this->privateData->Create(ThreadHelp::ThreadingFunction, c, start, detach);
}
OYSTER_THREAD_ERROR OysterThread::Create(ThreadFnc worker, bool start, bool detach)
{
if(!this->privateData) this->privateData = new PrivateData();
OwnerContainer c;
c.type = Oyster::Callback::CallbackType_Function;
c.value = worker;
return this->privateData->Create(ThreadHelp::ThreadingFunction, c, start, detach);
}
/*
OYSTER_THREAD_ERROR OysterThread::Create(Oyster::Callback::CallbackObject<bool, void>* worker, bool start, bool detach)
{
if(!this->privateData)
this->privateData = new PrivateData();
Oyster::Callback::OysterCallback<> temp;
temp.callbackType = Oyster::Callback::CallbackType_Object;
temp.value = worker;
return this->privateData->Create(ThreadHelp::ThreadingFunction, worker, start, detach);
return this->privateData->Create(ThreadHelp::ThreadingFunction, temp, start, detach);
}
OYSTER_THREAD_ERROR OysterThread::Create(Oyster::Callback::CallbackFunction<bool, void>::FNC worker, bool start, bool detach)
{
if(!this->privateData)
this->privateData = new PrivateData();
Oyster::Callback::OysterCallback<> temp;
temp.callbackType = Oyster::Callback::CallbackType_Function;
temp.value = worker;
return this->privateData->Create(ThreadHelp::ThreadingFunction, temp, start, detach);
}
*/
OYSTER_THREAD_ERROR OysterThread::Start()
{
if(!this->privateData->data->threadData->owner)
if(!this->privateData->data->threadData->ownerObj)
return OYSTER_THREAD_ERROR_ThreadHasNoWorker;
if(this->privateData->data->threadData->state == OYSTER_THREAD_STATE_DEAD)
@ -235,9 +355,19 @@ OYSTER_THREAD_ERROR OysterThread::Resume()
return OYSTER_THREAD_ERROR_SUCCESS;
}
OYSTER_THREAD_ERROR OysterThread::Reset(IThreadObject* worker)
OYSTER_THREAD_ERROR OysterThread::SetWorker(IThreadObject* worker)
{
this->privateData->data->threadData->owner = worker;
this->privateData->data->threadData->ownerObj.value = worker;
this->privateData->data->threadData->ownerObj.type = Oyster::Callback::CallbackType_Object;
this->privateData->data->threadData->msec = 0;
return OYSTER_THREAD_ERROR_SUCCESS;;
}
OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker)
{
this->privateData->data->threadData->ownerObj.value = worker;
this->privateData->data->threadData->ownerObj.type = Oyster::Callback::CallbackType_Function;
this->privateData->data->threadData->msec = 0;

View File

@ -68,6 +68,8 @@ namespace Oyster
template < typename Type >
ThreadSafeQueue<Type>::~ThreadSafeQueue()
{
if(!nrOfNodes) return;
stdMutex.lock();
if(this->front != NULL)

View File

@ -10,6 +10,9 @@
#ifndef UTILITIES_H
#define UTILITIES_H
//warning C4150: deletion of pointer to incomplete type, no destructor called
#pragma warning(disable : 4150)
#include <string>
#include <istream>
#include <vector>

View File

@ -7,6 +7,7 @@
#include <memory>
namespace Oyster
{
namespace Network
@ -26,24 +27,46 @@ namespace Oyster
class NetworkClient;
class CustomNetProtocol;
typedef void (*ClientConnectCallbackMethod)(NetworkClient*);
typedef void(*ProtocolRecieverFunction)(CustomNetProtocol& protocol);
struct ClientConnectedObject
{
virtual void ClientConnectCallback(NetworkClient* client) = 0;
};
struct ProtocolRecieverObject
{
virtual void ProtocolRecievedCallback(CustomNetProtocol& protocol) = 0;
virtual void DisconnectedCallback(CustomNetProtocol& protocol) { };
};
template<typename Param>
struct NetRecieverObject
{
virtual void NetworkCallback(Param) = 0;
};
struct NetClientEvent :public NetRecieverObject<CustomNetProtocol&>
{
virtual void NetworkCallback(CustomNetProtocol& protocol) = 0;
virtual void Disconnected() { };
};
typedef NetRecieverObject<NetworkClient*> ClientConnectedObject ;
typedef NetClientEvent ProtocolRecieverObject;
template <typename Param>
struct NetCallbackFunction
{
typedef void (*FNC)(Param);
};
typedef NetCallbackFunction<NetworkClient*>::FNC ClientConnectCallbackMethod;
typedef NetCallbackFunction<CustomNetProtocol&>::FNC ProtocolRecFunction;
struct NetClientMethods
{
typedef void(*Dissconnected)(void);
ProtocolRecFunction recieved;
Dissconnected dissconnected;
void operator()(CustomNetProtocol& obj) { if(recieved) recieved(obj); }
void operator()() { if(dissconnected) dissconnected(); }
};
typedef NetClientMethods ProtocolRecieverFunction;
union RecieverObject
{
ClientConnectCallbackMethod clientConnectFnc; // !< A function pointer for sending or recieving NetworkClient
ProtocolRecieverFunction protocolRecieverFnc; // !< A function pointer for sending or recieving CustomNetProtocol
ClientConnectedObject *clientConnectObject; // !< An object for sending or recieving NetworkClient
ProtocolRecieverObject *protocolRecievedObject; // !< An object for sending or recieving CustomNetProtocol
ProtocolRecieverObject *protocolRecievedObject; // !< An object with collected client events methods.
RecieverObject() { memset(this, 0, sizeof(RecieverObject)); }
RecieverObject(ClientConnectCallbackMethod o) { clientConnectFnc = o; }

View File

@ -84,8 +84,8 @@ struct NetworkClient::PrivateData : public IThreadObject
bool DoWork()
{
if(!this->data)return true;
if(!this->data->connection.IsConnected()) return true;
if(!this->data) return false;
if(!this->data->connection.IsConnected()) return false;
Send();
Recv();
@ -113,6 +113,22 @@ struct NetworkClient::PrivateData : public IThreadObject
SmartPointer<OysterByte> temp = new OysterByte();
this->data->translator.Pack(temp, this->data->sendPostBox->FetchMessage());
errorCode = this->data->connection.Send(temp);
if(errorCode != 0)
{
//Failed
this->data->connection.Disconnect();
this->data->recvObjMutex.lock();
if(this->data->callbackType == NetworkProtocolCallbackType_Function)
{
this->data->recvObj.protocolRecieverFnc();
}
else if(this->data->callbackType == NetworkProtocolCallbackType_Object)
{
this->data->recvObj.protocolRecievedObject->Disconnected();
}
this->data->recvObjMutex.unlock();
}
}
this->data->postBoxMutex.unlock();
@ -141,7 +157,7 @@ struct NetworkClient::PrivateData : public IThreadObject
}
else if(this->data->callbackType == NetworkProtocolCallbackType_Object)
{
this->data->recvObj.protocolRecievedObject->ProtocolRecievedCallback(protocol);
this->data->recvObj.protocolRecievedObject->NetworkCallback(protocol);
}
this->data->recvObjMutex.unlock();
}
@ -178,8 +194,8 @@ NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType
NetworkClient::NetworkClient(RecieverObject recvObj, NetworkProtocolCallbackType type, unsigned int socket)
{
privateData = new PrivateData(socket);
this->privateData->data->recvObj = recvObj;
this->privateData->data->callbackType = type;
this->privateData->data->recvObj = recvObj;
this->privateData->data->thread.Create(this->privateData, true);
}
@ -265,7 +281,7 @@ bool NetworkClient::operator ==(const int& ID)
return this->privateData->data->ID == ID;
}
int NetworkClient::Id() const
int NetworkClient::GetID() const
{
return this->privateData->data->ID;
}

View File

@ -48,7 +48,7 @@ namespace Oyster
bool operator ==(const NetworkClient& obj);
bool operator ==(const int& ID);
int Id() const;
int GetID() const;
private:
struct PrivateData;

View File

@ -115,18 +115,20 @@ void NetworkServer::PrivateData::Stop()
started = false;
thread.Stop();
thread.Stop(true);
}
void NetworkServer::PrivateData::Shutdown()
{
if(listener)
{
listener->Shutdown();
delete listener;
listener = NULL;
}
started = false;
thread.Terminate();
ShutdownWinSock();
}
@ -153,7 +155,7 @@ void NetworkServer::PrivateData::CheckForNewClient()
else if(initDesc.callbackType == NetworkClientCallbackType_Object)
{
Oyster::Network::NetworkClient *client = new Oyster::Network::NetworkClient(clientSocketNum);
initDesc.recvObj.clientConnectObject->ClientConnectCallback(client);
initDesc.recvObj.clientConnectObject->NetworkCallback(client);
}
}
}

View File

@ -108,7 +108,11 @@ int Connection::InitiateClient()
int Connection::Disconnect()
{
return CloseSocket(this->socket);
int val = CloseSocket(this->socket);
this->socket = -1;
this->closed = true;
this->stillSending = false;
return val;
}
int Connection::Send(OysterByte &bytes)

View File

@ -17,6 +17,7 @@ namespace Oyster
virtual ~IListener() {}
virtual bool Init(unsigned int port) = 0;
virtual int Accept() = 0;
virtual void Shutdown() = 0;
};
}

View File

@ -72,7 +72,7 @@ void Listener::Stop()
void Listener::Shutdown()
{
thread.Stop();
thread.Stop(false);
}
void Listener::SetPostBox(Oyster::Network::IPostBox<int>* postBox)

View File

@ -25,11 +25,10 @@ namespace Oyster
Listener(Oyster::Network::IPostBox<int>* postBox);
~Listener();
bool Init(unsigned int port);
bool Init(unsigned int port) override;
bool Init(unsigned int port, bool start);
bool Start();
void Stop();
void Shutdown();
void SetPostBox(IPostBox<int>* postBox);

View File

@ -1,7 +1,5 @@
#include "WindowShell.h"
#include <vector>
// debug window include
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
@ -9,6 +7,8 @@
#pragma region Declarations
#define WINDOW_SHELL_CLASS_NAME L"MainWindowShellClassName"
struct _PrivateDataContainer
{
HINSTANCE hIns;
@ -81,12 +81,12 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
__windowShellData.parent = desc.parent;
__windowShellData.hIns = desc.hInstance;
__windowShellData.windowClassName = L"MainWindowShellClassName";
__windowShellData.windowClassName = WINDOW_SHELL_CLASS_NAME;
#pragma region Register
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
WNDCLASSEXW wc;
wc.cbSize = sizeof(WNDCLASSEXW);
wc.hIconSm = NULL;
wc.style = desc.windowClassStyle;
wc.lpfnWndProc = desc.windowProcCallback;
@ -99,7 +99,7 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
wc.lpszMenuName = NULL;
wc.lpszClassName = __windowShellData.windowClassName;
if( !RegisterClassEx(&wc) )
if( !RegisterClassExW(&wc) )
{
MessageBox(0, L"Failed to register class", L"Initialization error", 0);
return false;
@ -137,7 +137,7 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
if(windowed)
{
__windowShellData.hWnd = CreateWindowEx(
__windowShellData.hWnd = CreateWindowExW(
0,
__windowShellData.windowClassName ,
desc.windowName,
@ -154,7 +154,7 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
}
else
{
__windowShellData.hWnd = CreateWindowEx(
__windowShellData.hWnd = CreateWindowExW(
0,
__windowShellData.windowClassName ,
desc.windowName,
@ -237,10 +237,12 @@ unsigned int WindowShell::GetHeight()
}
bool WindowShell::Frame()
{
if(!__windowShellData.hWnd) return true;
MSG msg = {0};
while (true)
{
if(!__windowShellData.parent)
if(!__windowShellData.parent) //Parent takes care of this
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{