GameLogic - Final sprint2 merge

This commit is contained in:
Dennis Andersen 2013-12-20 09:42:02 +01:00
parent 694d5576d7
commit 15d6ac8cf9
23 changed files with 263 additions and 287 deletions

View File

@ -31,10 +31,10 @@ namespace DanBias
int pType = p[0].value.netInt;
switch (pType)
{
case protocol_Status:
case protocol_General_Status:
{
GameLogic::Protocol_Status::States state;
state = (GameLogic::Protocol_Status::States)p[1].value.netShort;
GameLogic::Protocol_General_Status::States state;
state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort;
}
break;
@ -184,7 +184,7 @@ namespace DanBias
// Main message loop
while(m_data->window->Frame())
{
float dt = m_data->timer->getElapsedSeconds();
float dt = (float)m_data->timer->getElapsedSeconds();
m_data->timer->reset();
if(Update(dt) != S_OK)

View File

@ -90,8 +90,8 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
// load map
// wait for all players
LoadGame();
GameLogic::Protocol_Status gameStatus;
gameStatus.status = GameLogic::Protocol_Status::States_ready;
GameLogic::Protocol_General_Status gameStatus;
gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
privData->nwClient->Send(gameStatus);
privData->state = gameStateState_playing;
}

View File

@ -17,7 +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.IP = "193.11.184.196";
//gameDesc.IP = "193.11.184.196";
gameDesc.IP = "127.0.0.1";
gameDesc.hinst = hinst;
gameDesc.nCmdShow = cmdShow;

View File

@ -178,7 +178,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Helpers\GameSessionManager.cpp" />
<ClCompile Include="Helpers\ProtocolParser.cpp" />
<ClCompile Include="Include\DanBiasServerAPI.cpp" />
<ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameServer.cpp" />
@ -199,7 +198,6 @@
<ClInclude Include="ServerObjects\Lobby\GameLobby.h" />
<ClInclude Include="ServerObjects\Lobby\MainLobby.h" />
<ClInclude Include="ServerObjects\NetworkSession.h" />
<ClInclude Include="Helpers\ProtocolParser.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GamePhysics\GamePhysics.vcxproj">

View File

@ -23,6 +23,8 @@ namespace DanBias
void GameServer::ClientConnectCallback(NetworkClient* client)
{
printf("Client with ID [%i] connected.\n", client->Id());
if(!myTest)
{
myTest = new GameSession();
@ -33,8 +35,6 @@ namespace DanBias
myTest->Run(desc);
}
//printf("Client connected with socket: %i\n", client->Id());
//
//Utility::DynamicMemory::SmartPointer<ClientObject> c = new ClientObject(client);
//this->mainLobby->AttachClient(c, this->mainLobby->GetPostbox());

View File

@ -41,14 +41,15 @@ void GameSessionManager::AddSession(DanBias::GameSession* session)
}
}
void GameSessionManager::CloseSession(DanBias::GameSession* session)
void GameSessionManager::CloseSession()
{
int i = gameSessionData.Existst(session);
//Moron check...
if(i == -1) return;
//gameSessionData.sessions[i]->Close();
//int i = gameSessionData.Existst(session);
//
////Moron check...
//if(i == -1) return;
//
////gameSessionData.sessions[i]->Close();
}

View File

@ -10,7 +10,7 @@ class GameSessionManager
{
public:
static void AddSession(DanBias::GameSession* session);
static void CloseSession(DanBias::GameSession* session);
static void CloseSession();
};
#endif // !DANBIASSERVER_GAME_SEESION_MANAGER_H

View File

@ -1,75 +0,0 @@
#include "ProtocolParser.h"
using namespace DanBias;
void ParseGeneralP(Oyster::Network::CustomNetProtocol& p, const short &f, ProtocolParser::ProtocolData& d)
{
switch (f)
{
case protocol_General_Disconnect:
break;
case protocol_General_Ping:
break;
case protocol_General_Text:
break;
}
}
void ParseLobbyP(Oyster::Network::CustomNetProtocol& p, const short &f, ProtocolParser::ProtocolData& d)
{
Oyster::Network::CustomNetProtocol* lp;
d.type = f;
switch (f)
{
case protocol_Lobby_CreateGame:
{
//lp = d.p.createGame.GetProtocol();
//d.p.createGame (*lp)[0].value;
}
break;
case protocol_Lobby_JoinGame:
{
lp = d.p.createGame.GetProtocol();
}
break;
case protocol_Lobby_StartGame:
{
lp = d.p.createGame.GetProtocol();
d.p.startGame.gameId = (*lp)[1].value.netChar;
}
break;
case protocol_Lobby_JoinLobby:
{
lp = d.p.createGame.GetProtocol();
}
break;
case protocol_Lobby_LeaveLobby:
{
lp = d.p.createGame.GetProtocol();
}
break;
}
}
ProtocolParser::ProtocolData ProtocolParser::ParseProtocol(Oyster::Network::CustomNetProtocol& p)
{
ProtocolParser::ProtocolData d;
memset(&d, 0, sizeof(ProtocolData));
short f = p[0].value.netShort;
switch (f)
{
case protocol_TypeId_General:
ParseGeneralP(p, f, d);
break;
case protocol_TypeId_Lobby:
ParseLobbyP(p, f, d);
break;
}
return d;
}

View File

@ -1,27 +0,0 @@
#ifndef DANBIASSERVER_PROTOCOLPARSER_H
#define DANBIASSERVER_PROTOCOLPARSER_H
#include <GameProtocols.h>
namespace DanBias
{
class ProtocolParser
{
public:
union ProtocolCollection
{
struct{ GameLogic::Protocol_LobbyCreateGame createGame; };
struct{ GameLogic::Protocol_LobbyJoinGame joinGame; };
struct{ GameLogic::Protocol_LobbyStartGame startGame; };
struct{ GameLogic::Protocol_LobbyJoinLobby joinLobby; };
struct{ GameLogic::Protocol_LobbyLeaveLobby leaveLobby; };
};
struct ProtocolData
{
short type;
ProtocolCollection p;
};
public:
static ProtocolData ParseProtocol(Oyster::Network::CustomNetProtocol& p);
};
}
#endif // !DANBIASSERVER_PROTOCOLPARSER_H

View File

@ -14,31 +14,34 @@ ClientObject::~ClientObject()
}
void ClientObject::SetProtocolCallback(Oyster::Network::ProtocolRecieverObject* object)
{
this->NetClient_Object()->SetRecieverObject(object, Oyster::Network::NetworkProtocolCallbackType_Object);
this->GetClient()->SetRecieverObject(object, Oyster::Network::NetworkProtocolCallbackType_Object);
}
void ClientObject::SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box)
{
this->box = box;
}
GameLogic::Player* ClientObject::Logic_Object()
GameLogic::Player* ClientObject::GetPlayer()
{
return this->logicPlayer;
return this->player.Get();
}
Oyster::Network::NetworkClient* ClientObject::NetClient_Object()
Oyster::Network::NetworkClient* ClientObject::GetClient()
{
return this->client;
return this->client.Get();
}
void ClientObject::CreatePlayer()
{
if(this->logicPlayer) return;
if(this->player) return;
this->logicPlayer = new GameLogic::Player();
this->player = new GameLogic::Player();
}
void ClientObject::ErasePlayer()
{
while(this->player.Release());
}
void ClientObject::ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol)
{
//this->client->Send(&protocol);
if(!this->box) return;
NetworkSession::NetEvent _event;

View File

@ -19,18 +19,20 @@ namespace DanBias
void SetPostbox(Oyster::IPostBox<NetworkSession::NetEvent>* box);
void SetProtocolCallback(Oyster::Network::ProtocolRecieverObject* object);
GameLogic::Player* Logic_Object();
Oyster::Network::NetworkClient* NetClient_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> logicPlayer;
Utility::DynamicMemory::SmartPointer<GameLogic::Player> player;
Utility::DynamicMemory::SmartPointer<Oyster::Network::NetworkClient> client;
Oyster::IPostBox<DanBias::NetworkSession::NetEvent>* box;
};

View File

@ -3,12 +3,9 @@
#include <PostBox\PostBox.h>
#include "GameSession.h"
#include "ClientObject.h"
#include "..\Helpers\ProtocolParser.h"
#include <GameLogicStates.h>
#define ERIK
using namespace Utility::DynamicMemory;
using namespace Oyster::Network;
using namespace Oyster;
@ -72,7 +69,7 @@ namespace DanBias
}
void GameSession::SetPostbox(IPostBox<NetworkSession::NetEvent> *box)
{
NetworkSession::SetPostbox(box);
}
void GameSession::CloseSession(NetworkSession* clientDestination)
{
@ -128,47 +125,46 @@ namespace DanBias
}
void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c)
{
switch (p[0].value.netShort)
if( ProtocolIsGameplay(p[protocol_INDEX_ID].value.netShort) )
{
case protocol_Gamplay_PlayerNavigation:
switch (p[protocol_INDEX_ID].value.netShort)
{
case protocol_Gameplay_PlayerNavigation:
{
if(p[1].value.netBool) //bool bForward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft;
c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
c.GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
Oyster::Math::Float4x4 p;
c.Logic_Object()->GetRigidBody()->GetOrientation(p);
Protocol_ObjectPosition op(p);
op.object_ID = c.Logic_Object()->GetID();
Protocol_ObjectPosition op(c.GetPlayer()->GetRigidBody()->GetOrientation(p));
op.object_ID = c.GetPlayer()->GetID();
this->Send(*op.GetProtocol());
}
break;
case protocol_Gamplay_PlayerMouseMovement:
case protocol_Gameplay_PlayerMouseMovement:
break;
case protocol_Gamplay_PlayerPosition:
case protocol_Gameplay_PlayerPosition:
break;
case protocol_Gamplay_CreateObject:
case protocol_Gameplay_CreateObject:
break;
case protocol_Gamplay_ObjectPosition:
case protocol_Gameplay_ObjectPosition:
break;
}
}
else if(ProtocolIsGeneral(p[protocol_INDEX_ID].value.netShort) )
{
#ifdef ERIK
//VARIABLES GOES HERE
#endif
}
}
}//End namespace DanBias

View File

@ -1,6 +1,5 @@
#include "MainLobby.h"
#include "..\..\Helpers\ProtocolParser.h"
#include "..\ClientObject.h"
#include <PlayerProtocols.h>
#include <PostBox\PostBox.h>

View File

@ -57,7 +57,7 @@ namespace DanBias
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->Id())
if(this->clients[0]->GetClient()->Id() == client->Id())
{
val = this->clients[i];
this->clients[i] = 0;
@ -76,7 +76,7 @@ namespace DanBias
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id())
if(this->clients[0]->GetClient()->Id() == client->GetClient()->Id())
{
val = this->clients[i];
this->clients[i] = 0;
@ -95,7 +95,7 @@ namespace DanBias
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[0]->NetClient_Object()->Id() == ID)
if(this->clients[0]->GetClient()->Id() == ID)
{
val = this->clients[i];
this->clients[i] = 0;
@ -111,16 +111,16 @@ namespace DanBias
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->NetClient_Object()->Send(&protocol);
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]->NetClient_Object()->Id() == ID)
if(this->clients[i]->GetClient()->Id() == ID)
{
this->clients[i]->NetClient_Object()->Send(&protocol);
this->clients[i]->GetClient()->Send(&protocol);
break;
}
}
@ -142,7 +142,7 @@ namespace DanBias
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
this->clients[i]->NetClient_Object()->Disconnect();
this->clients[i]->GetClient()->Disconnect();
}
}
else
@ -162,7 +162,7 @@ namespace DanBias
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->NetClient_Object()->Id() == ID)
if(this->clients[i]->GetClient()->Id() == ID)
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<ClientObject>();
@ -171,7 +171,7 @@ namespace DanBias
{
for (unsigned int i = 0; i < this->clients.Size(); i++)
{
if(this->clients[i]->NetClient_Object()->Id() == obj.NetClient_Object()->Id())
if(this->clients[i]->GetClient()->Id() == obj.GetClient()->Id())
return this->clients[i];
}
return Utility::DynamicMemory::SmartPointer<ClientObject>();

View File

@ -16,7 +16,7 @@ using namespace GameLogic;
Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef));
Object *realObj = (Object*)obj->gameObjectRef;
switch (realObj->GetType().value)
switch (realObj->GetType())
{
case OBJECT_TYPE::OBJECT_TYPE_BOX:
PlayerVBox(*player,(*(DynamicObject*) realObj));
@ -43,7 +43,7 @@ using namespace GameLogic;
DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef;
Object *realObj = (Object*)obj->gameObjectRef;
switch (realObj->GetType().value)
switch (realObj->GetType())
{
case OBJECT_TYPE::OBJECT_TYPE_BOX:

View File

@ -13,61 +13,18 @@ namespace GameLogic
PLAYER_MOVEMENT_RIGHT = 4,
PLAYER_MOVEMENT_JUMP = 8,
};
class DANBIAS_GAMELOGIC_DLL PLAYER_STATE
enum PLAYER_STATE
{
public:
PLAYER_STATE()
{
}
PLAYER_STATE(int value)
{
this->value = value;
}
static const int PLAYER_STATE_JUMPING = 0;
static const int PLAYER_STATE_WALKING = 1;
static const int PLAYER_STATE_IDLE = 2;
int value;
PLAYER_STATE_JUMPING = 0,
PLAYER_STATE_WALKING = 1,
PLAYER_STATE_IDLE = 2,
};
/*
class DANBIAS_GAMELOGIC_DLL PLAYER_MOVEMENT
{
public:
PLAYER_MOVEMENT()
{
}
PLAYER_MOVEMENT(int value)
enum OBJECT_TYPE
{
this->value = value;
}
static const int PLAYER_MOVEMENT_FORWARD = 0;
static const int PLAYER_MOVEMENT_BACKWARD = 1;
static const int PLAYER_MOVEMENT_LEFT = 2;
static const int PLAYER_MOVEMENT_RIGHT = 4;
static const int PLAYER_MOVEMENT_JUMP = 8;
int value;
};
*/
class DANBIAS_GAMELOGIC_DLL OBJECT_TYPE
{
public:
OBJECT_TYPE()
{
}
OBJECT_TYPE(int value)
{
this->value = value;
}
static const int OBJECT_TYPE_PLAYER = 0;
static const int OBJECT_TYPE_BOX = 1;
static const int OBJECT_TYPE_UNKNOWN = 2;
public: int value;
OBJECT_TYPE_PLAYER = 0,
OBJECT_TYPE_BOX = 1,
OBJECT_TYPE_UNKNOWN = 2,
};
enum WEAPON_FIRE

View File

@ -20,8 +20,8 @@ Object::Object()
rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
}
Object::Object(void* collisionFunc, OBJECT_TYPE type)

View File

@ -14,7 +14,7 @@ struct Player::PrivateData
life = 100;
teamID = -1;
playerState.value = PLAYER_STATE::PLAYER_STATE_IDLE;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float3(1,0,0);
}
@ -73,6 +73,27 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
}
}
void Player::MoveForward()
{
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
}
void Player::MoveBackwards()
{
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
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);
API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100);
}
void Player::UseWeapon(const WEAPON_FIRE &fireInput)
{
myData->weapon->Use(fireInput);
@ -93,15 +114,15 @@ void Player::Jump()
bool Player::IsWalking()
{
return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_WALKING);
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
}
bool Player::IsJumping()
{
return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_JUMPING);
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
}
bool Player::IsIdle()
{
return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_IDLE);
return (myData->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
}
Oyster::Math::Float3 Player::GetPos()

View File

@ -23,6 +23,11 @@ namespace GameLogic
********************************************************/
void Move(const PLAYER_MOVEMENT &movement);
void MoveForward();
void MoveBackwards();
void MoveRight();
void MoveLeft();
/********************************************************
* Uses the weapon based on input
* @param fireInput: enum value on what kind of action is to be taken

View File

@ -6,7 +6,7 @@
namespace GameLogic
{
struct Protocol_Status :public Oyster::Network::CustomProtocolObject
struct Protocol_General_Status :public Oyster::Network::CustomProtocolObject
{
enum States
{
@ -17,9 +17,9 @@ namespace GameLogic
};
States status;
Protocol_Status()
Protocol_General_Status()
{
this->protocol[0].value = protocol_Status;
this->protocol[0].value = protocol_General_Status;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
@ -34,5 +34,75 @@ 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
{
char* text;
Protocol_General_Text()
{
this->protocol[0].value = protocol_General_Text;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_CharArray;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value.netCharPtr = text;
return &protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
}
#endif //!GAMELOGIC_CONTROL_PROTOCOLS_H

View File

@ -35,6 +35,17 @@ namespace GameLogic
this->protocol[5].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[6].type = Oyster::Network::NetAttributeType_Bool;
}
const Protocol_PlayerMovement& operator=(Oyster::Network::CustomNetProtocol& val)
{
bForward = val[1].value.netBool;
bBackward = val[2].value.netBool;
bTurnLeft = val[3].value.netBool;
bTurnRight = val[4].value.netBool;
bStrafeRight = val[5].value.netBool;
bStrafeRight = val[6].value.netBool;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = bForward;
@ -67,6 +78,13 @@ namespace GameLogic
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
}
const Protocol_PlayerMouse& operator=(Oyster::Network::CustomNetProtocol& val)
{
dxMouse = val[1].value.netFloat;
dyMouse = val[2].value.netFloat;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = dxMouse;
@ -95,6 +113,14 @@ namespace GameLogic
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
}
const Protocol_PlayerPosition& operator=(Oyster::Network::CustomNetProtocol& val)
{
position[0] = val[1].value.netFloat;
position[1] = val[2].value.netFloat;
position[2] = val[3].value.netFloat;
return *this;
}
Oyster::Network::CustomNetProtocol* GetProtocol() override
{
this->protocol[1].value = position[0];

View File

@ -8,53 +8,60 @@
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
#define protocol_ID_INDEX 0
/** Index where the identifier is located(aka protocol identification index) **/
#define protocol_INDEX_ID 0
#define protocol_Gameplay_PlayerNavigation 300
#define protocol_Gameplay_PlayerMouseMovement 301
#define protocol_Gameplay_PlayerPosition 302
#define protocol_Gameplay_CreateObject 303
#define protocol_Gameplay_RemoveObject 304
#define protocol_Gameplay_ObjectPosition 305
#define protocol_Status 50
/***********************************/
/********* RESERVERD PROTOCOLS *****/
/********** [ 0 - 96 ] *********/
#define protocol_TypeId_Lobby 97
#define protocol_TypeId_General 98
#define protocol_TypeId_Gameplay 99
/********** [ 0 - 100 ] *********/
/***********************************/
/********* GENERAL PROTOCOLS *******/
/***********[ 200 - 300 ]***********/
/***********[ 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 101
#define protocol_General_Text 102
#define protocol_General_Ping 102
#define protocol_General_Text 103
#define protocol_General_Status 104
#define protocol_General_DisconnectKick 105
#define protocol_GeneralMAX 199
/***********************************/
/********* LOBBY PROTOCOLS *********/
/***********[ 100 - 200 ]***********/
/***********[ 200 - 300 ]***********/
#define protocol_LobbyMIN 200
#define protocol_Lobby_CreateGame 200
#define protocol_Lobby_JoinGame 201
#define protocol_Lobby_StartGame 202
#define protocol_Lobby_JoinLobby 203
#define protocol_Lobby_LeaveLobby 204
#define protocol_Lobby_CreateGameLobby 205
#define protocol_LobbyMAX 299
/***********************************/
/********* GAMEPLAY PROTOCOLS ******/
/***********[ 300 - 400 ]***********/
#define protocol_Gamplay_PlayerNavigation 300
#define protocol_Gamplay_PlayerMouseMovement 301
#define protocol_Gamplay_PlayerPosition 302
#define protocol_Gamplay_CreateObject 303
#define protocol_Gamplay_ObjectPosition 304
#define protocol_GameplayMIN 300
#define protocol_Gameplay_PlayerNavigation 300
#define protocol_Gameplay_PlayerMouseMovement 301
#define protocol_Gameplay_PlayerPosition 302
#define protocol_Gameplay_CreateObject 303
#define protocol_Gameplay_RemoveObject 304
#define protocol_Gameplay_ObjectPosition 305
#define protocol_GameplayMAX 399
/************************************/
/*********** 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); }
inline bool ProtocolIsGameplay(short ID) { return (ID >= protocol_GameplayMIN && ID <= protocol_GameplayMAX); }
/***********************************/
@ -62,4 +69,7 @@
/***********[ 1000 - x ]************/
#define PROTOCOL_TEST 1000
#endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H

View File

@ -28,10 +28,10 @@ using namespace Utility::DynamicMemory;
{
OYSTER_THREAD_STATE state; //<! The current thread state.
OYSTER_THREAD_PRIORITY prio; //<! The thread priority
IThreadObject *owner; //<! The worker.
IThreadObject *owner; //<! The worker object.
std::atomic<int> msec; //<! A timer in miliseconds.
//std::timed_mutex threadFunctionLock;
std::timed_mutex threadFunctionLock;
//std::mutex threadWaitFunctionLock;
};
@ -130,10 +130,16 @@ using namespace Utility::DynamicMemory;
}
}
static bool DoWork(ThreadData* w)
{
try
{
if(w->owner)
return w->owner->DoWork();
}
catch( ... )
{
printf("Something went wrong on thread with id: [%i]", std::this_thread::get_id());
}
return true;
}
static void CheckStatus(ThreadData* w)
@ -239,23 +245,7 @@ OYSTER_THREAD_ERROR OysterThread::Reset(IThreadObject* worker)
}
OYSTER_THREAD_ERROR OysterThread::Terminate(bool wait)
{
//this->privateData->data->threadData->state = OYSTER_THREAD_STATE_DEAD;
//
//if(std::this_thread::get_id() == this->privateData->data->workerThread->get_id())
// return OYSTER_THREAD_ERROR_SUCCESS;
//
//if(wait)
//{
// if(this->privateData->data->workerThread->joinable())
// this->privateData->data->workerThread->detach();
//
// this->privateData->data->threadData->threadFunctionLock.lock();
// this->privateData->data->threadData->threadFunctionLock.unlock();
//}
return this->privateData->Terminate(wait);
//return OYSTER_THREAD_ERROR_SUCCESS;
}
OYSTER_THREAD_ERROR OysterThread::Wait()
{