diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 8264f34b..6bb56251 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -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) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 602bd136..cc129620 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -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; } diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index f738bc80..13c67323 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -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; diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj index 3e315b49..ba66aea0 100644 --- a/Code/Game/DanBiasServer/DanBiasServer.vcxproj +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -178,7 +178,6 @@ - @@ -199,7 +198,6 @@ - diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp index cd9695df..e1f03b98 100644 --- a/Code/Game/DanBiasServer/GameServer.cpp +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -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 c = new ClientObject(client); //this->mainLobby->AttachClient(c, this->mainLobby->GetPostbox()); diff --git a/Code/Game/DanBiasServer/Helpers/GameSessionManager.cpp b/Code/Game/DanBiasServer/Helpers/GameSessionManager.cpp index 1bcaa652..76d67729 100644 --- a/Code/Game/DanBiasServer/Helpers/GameSessionManager.cpp +++ b/Code/Game/DanBiasServer/Helpers/GameSessionManager.cpp @@ -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(); } diff --git a/Code/Game/DanBiasServer/Helpers/GameSessionManager.h b/Code/Game/DanBiasServer/Helpers/GameSessionManager.h index eccda1bc..d17ef1b1 100644 --- a/Code/Game/DanBiasServer/Helpers/GameSessionManager.h +++ b/Code/Game/DanBiasServer/Helpers/GameSessionManager.h @@ -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 diff --git a/Code/Game/DanBiasServer/Helpers/ProtocolParser.cpp b/Code/Game/DanBiasServer/Helpers/ProtocolParser.cpp deleted file mode 100644 index b027e54c..00000000 --- a/Code/Game/DanBiasServer/Helpers/ProtocolParser.cpp +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/Code/Game/DanBiasServer/Helpers/ProtocolParser.h b/Code/Game/DanBiasServer/Helpers/ProtocolParser.h deleted file mode 100644 index c72dac95..00000000 --- a/Code/Game/DanBiasServer/Helpers/ProtocolParser.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef DANBIASSERVER_PROTOCOLPARSER_H -#define DANBIASSERVER_PROTOCOLPARSER_H - -#include -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 diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp index ac8d86e4..84b7a3db 100644 --- a/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.cpp @@ -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* 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; diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.h b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h index 4661b82d..4bc65111 100644 --- a/Code/Game/DanBiasServer/ServerObjects/ClientObject.h +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h @@ -19,18 +19,20 @@ namespace DanBias void SetPostbox(Oyster::IPostBox* 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 logicPlayer; + Utility::DynamicMemory::SmartPointer player; Utility::DynamicMemory::SmartPointer client; Oyster::IPostBox* box; }; diff --git a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp index e62de0e5..9e270ebf 100644 --- a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp @@ -3,12 +3,9 @@ #include #include "GameSession.h" #include "ClientObject.h" -#include "..\Helpers\ProtocolParser.h" #include -#define ERIK - using namespace Utility::DynamicMemory; using namespace Oyster::Network; using namespace Oyster; @@ -72,7 +69,7 @@ namespace DanBias } void GameSession::SetPostbox(IPostBox *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) { - 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); + case protocol_Gameplay_PlayerNavigation: + { - Oyster::Math::Float4x4 p; - c.Logic_Object()->GetRigidBody()->GetOrientation(p); + 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: - Protocol_ObjectPosition op(p); - op.object_ID = c.Logic_Object()->GetID(); - this->Send(*op.GetProtocol()); + break; + case protocol_Gameplay_ObjectPosition: + + break; } - break; - case protocol_Gamplay_PlayerMouseMovement: - - break; - case protocol_Gamplay_PlayerPosition: - - break; - case protocol_Gamplay_CreateObject: - - break; - case protocol_Gamplay_ObjectPosition: - - break; + } + else if(ProtocolIsGeneral(p[protocol_INDEX_ID].value.netShort) ) + { + } } - -#ifdef ERIK - //VARIABLES GOES HERE - - -#endif - }//End namespace DanBias diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp index f111f5ec..0e1fed89 100644 --- a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp @@ -1,6 +1,5 @@ #include "MainLobby.h" -#include "..\..\Helpers\ProtocolParser.h" #include "..\ClientObject.h" #include #include diff --git a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp index c269f681..9cceb951 100644 --- a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp @@ -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(); @@ -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(); diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index a549d7c6..8a875d8b 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -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: diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index f3b3f356..6a3c5cb0 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -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 + + enum OBJECT_TYPE { - public: - PLAYER_MOVEMENT() - { - - } - PLAYER_MOVEMENT(int value) - { - 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 diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 748d19c7..f8bf5da0 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -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) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ac42f6c9..5626af82 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -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() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index f6e61fa5..ea6c304b 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -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 diff --git a/Code/Game/GameProtocols/ControlProtocols.h b/Code/Game/GameProtocols/ControlProtocols.h index 93c6b528..4515666e 100644 --- a/Code/Game/GameProtocols/ControlProtocols.h +++ b/Code/Game/GameProtocols/ControlProtocols.h @@ -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 \ No newline at end of file diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index c578f69e..8ec54cea 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -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]; diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index ac23b6b9..43cb4981 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -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 diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index d768cdaa..9b4b2a06 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -28,13 +28,13 @@ using namespace Utility::DynamicMemory; { OYSTER_THREAD_STATE state; // msec; //owner) - return w->owner->DoWork(); - + 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() {