From a4907c8e2e2411f3fd44443d08dcdd8428a6bf67 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 18 Dec 2013 15:28:47 +0100 Subject: [PATCH 1/3] GL - control protocol added --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 30 ++++++++++++--- .../GameClientState/GameClientState.h | 5 +++ .../DanBiasGame/GameClientState/GameState.cpp | 30 ++++++++------- .../DanBiasGame/GameClientState/GameState.h | 1 + Code/Game/GameProtocols/ControlProtocols.h | 38 +++++++++++++++++++ Code/Game/GameProtocols/GameProtocols.vcxproj | 1 + Code/Game/GameProtocols/ObjectProtocols.h | 27 +++++++++++-- Code/Game/GameProtocols/PlayerProtocols.h | 6 +-- .../GameProtocols/ProtocolIdentificationID.h | 12 +++--- 9 files changed, 120 insertions(+), 30 deletions(-) create mode 100644 Code/Game/GameProtocols/ControlProtocols.h diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 2aa4fdbc..51082518 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -6,6 +6,7 @@ #include "GameClientState\GameState.h" #include "GameClientState\LobbyState.h" #include "PlayerProtocols.h" +#include "ControlProtocols.h" #include "NetworkClient.h" #include "../WindowManager/WindowShell.h" @@ -29,9 +30,15 @@ namespace DanBias int pType = p[0].value.netInt; switch (pType) { - case protocol_Gamplay_PlayerNavigation: + case protocol_Status: + { + GameLogic::Protocol_Status::States state; + state = (GameLogic::Protocol_Status::States)p[1].value.netShort; + + } + break; + case protocol_Gameplay_PlayerNavigation: { - Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; for(int i = 0; i< 6; i++) { @@ -44,7 +51,7 @@ namespace DanBias protocolData = NULL; } break; - case protocol_Gamplay_PlayerPosition: + case protocol_Gameplay_PlayerPosition: { Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; for(int i = 0; i< 3; i++) @@ -58,7 +65,7 @@ namespace DanBias } break; - case protocol_Gamplay_CreateObject: + case protocol_Gameplay_CreateObject: { Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; @@ -76,7 +83,19 @@ namespace DanBias protocolData = NULL; } break; - case protocol_Gamplay_ObjectPosition: + case protocol_Gameplay_RemoveObject: + { + Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj; + protocolData->object_ID = p[1].value.netInt; + + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + + delete protocolData; + protocolData = NULL; + } + break; + case protocol_Gameplay_ObjectPosition: { Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; @@ -113,7 +132,6 @@ namespace DanBias } public: - //Client::GameClientState* gameClientState; WindowShell* window; InputClass* inputObj; Utility::WinTimer* timer; diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h index fedf95df..2ba930b7 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -28,6 +28,11 @@ public: char* path; float worldPos[16]; }; + struct RemoveObj :public ProtocolStruct + { + int object_ID; + //particle effect + }; struct KeyInput :public ProtocolStruct { bool key[6]; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 89c320d0..cfbc13cf 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -4,6 +4,7 @@ #include "C_obj/C_DynamicObj.h" #include "NetworkClient.h" #include "PlayerProtocols.h" +#include "ControlProtocols.h" using namespace DanBias::Client; @@ -83,10 +84,15 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI switch (privData->state) { case gameStateState_loading: - // load map - // wait for all players - LoadGame(); - privData->state = gameStateState_playing; + { + // load map + // wait for all players + LoadGame(); + GameLogic::Protocol_Status gameStatus; + gameStatus.status = GameLogic::Protocol_Status::States_ready; + privData->nwClient->Send(gameStatus); + privData->state = gameStateState_playing; + } break; case gameStateState_playing: // read server data @@ -180,15 +186,7 @@ bool GameState::Release() void GameState::Protocol(ProtocolStruct* pos) { - // move message - /* - if ((KeyInput*)pos) - { - } - if((ObjPos*)pos) - ObjectPosProtocol((ObjPos*)pos); - else if((PlayerPos*)pos) - PlayerPosProtocol((PlayerPos*)pos);*/ + } void GameState::Protocol( PlayerPos* pos ) @@ -224,6 +222,7 @@ void GameState::Protocol( NewObj* pos ) modelData.world = world; modelData.visible = true; + //not sure if this is good parsing rom char* to wstring const char* path = pos->path; modelData.modelPath = std::wstring(path, path + strlen(path)); // load models @@ -240,6 +239,11 @@ void GameState::Protocol( KeyInput* pos ) } } +void DanBias::Client::GameState::Protocol( RemoveObj* obj ) +{ + privData->object[obj->object_ID]->Release( ); +} + void GameState::PlayerPosProtocol(PlayerPos* pos) { Oyster::Math::Float4x4 world, translate; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 1da091ea..bc0e8dba 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -36,6 +36,7 @@ public: void Protocol(ObjPos* pos); void Protocol(KeyInput* pos); void Protocol( NewObj* pos ); + void Protocol(RemoveObj* obj); void PlayerPosProtocol(PlayerPos* pos); void ObjectPosProtocol(ObjPos* pos); //void Protocol(LightPos pos); diff --git a/Code/Game/GameProtocols/ControlProtocols.h b/Code/Game/GameProtocols/ControlProtocols.h new file mode 100644 index 00000000..93c6b528 --- /dev/null +++ b/Code/Game/GameProtocols/ControlProtocols.h @@ -0,0 +1,38 @@ +#ifndef GAMELOGIC_CONTROL_PROTOCOLS_H +#define GAMELOGIC_CONTROL_PROTOCOLS_H + +#include +#include "ProtocolIdentificationID.h" + +namespace GameLogic +{ + struct Protocol_Status :public Oyster::Network::CustomProtocolObject + { + enum States + { + States_ready, + States_idle, + States_bussy, + States_disconected, + }; + States status; + + Protocol_Status() + { + this->protocol[0].value = protocol_Status; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = status; + + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; +} +#endif //!GAMELOGIC_CONTROL_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index 12584afb..da83ab6c 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -154,6 +154,7 @@ + diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 50dbf530..38ab11a2 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -17,8 +17,8 @@ namespace GameLogic Protocol_CreateObject() { - this->protocol[0].value = protocol_Gamplay_CreateObject; - this->protocol[0].type = Oyster::Network::NetAttributeType_Int; + this->protocol[0].value = protocol_Gameplay_CreateObject; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; @@ -79,7 +79,7 @@ namespace GameLogic Protocol_ObjectPosition() { - this->protocol[0].value = protocol_Gamplay_ObjectPosition; + this->protocol[0].value = protocol_Gameplay_ObjectPosition; this->protocol[0].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -129,6 +129,27 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; + struct Protocol_RemoveObject :public Oyster::Network::CustomProtocolObject + { + int object_ID; + + Protocol_RemoveObject() + { + this->protocol[0].value = protocol_Gameplay_RemoveObject; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + + this->protocol[1].value = object_ID; + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 159d9403..c578f69e 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -25,7 +25,7 @@ namespace GameLogic Protocol_PlayerMovement() { - this->protocol[0].value = protocol_Gamplay_PlayerNavigation; + this->protocol[0].value = protocol_Gameplay_PlayerNavigation; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; @@ -60,7 +60,7 @@ namespace GameLogic Protocol_PlayerMouse() { - this->protocol[0].value = protocol_Gamplay_PlayerMouseMovement; + this->protocol[0].value = protocol_Gameplay_PlayerMouseMovement; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; @@ -87,7 +87,7 @@ namespace GameLogic Protocol_PlayerPosition() { - this->protocol[0].value = protocol_Gamplay_PlayerPosition; + this->protocol[0].value = protocol_Gameplay_PlayerPosition; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 8e575502..91a960b0 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -7,12 +7,14 @@ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_Gamplay_PlayerNavigation 0 -#define protocol_Gamplay_PlayerMouseMovement 1 -#define protocol_Gamplay_PlayerPosition 2 -#define protocol_Gamplay_CreateObject 3 -#define protocol_Gamplay_ObjectPosition 4 +#define protocol_Gameplay_PlayerNavigation 0 +#define protocol_Gameplay_PlayerMouseMovement 1 +#define protocol_Gameplay_PlayerPosition 2 +#define protocol_Gameplay_CreateObject 3 +#define protocol_Gameplay_RemoveObject 4 +#define protocol_Gameplay_ObjectPosition 5 +#define protocol_Status 50 #define protocol_Lobby_Msg 100 From 0ea08fbd548f1d3ae927cb3fdcd57c1b2d826836 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 19 Dec 2013 10:21:03 +0100 Subject: [PATCH 2/3] gamesession testing --- .../ServerObjects/GameSession.cpp | 35 +++++++- Code/Game/GameLogic/CollisionManager.cpp | 84 +++++++++---------- Code/Game/GameLogic/CollisionManager.h | 7 +- Code/Game/GameLogic/DynamicObject.h | 3 +- Code/Game/GameLogic/GameLogic.vcxproj | 1 + Code/Game/GameLogic/GameLogicStates.h | 67 +++++++++++---- Code/Game/GameLogic/Object.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 25 +++--- .../GameProtocols/ProtocolIdentificationID.h | 12 +-- 9 files changed, 153 insertions(+), 83 deletions(-) diff --git a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp index 1863d7e4..0b1e54c2 100644 --- a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp @@ -4,6 +4,10 @@ #include #include "ClientObject.h" +#include "DynamicObject.h" +#include "CollisionManager.h" +#include "GameLogicStates.h" + #define ERIK @@ -83,6 +87,8 @@ namespace DanBias return true; } + + ////private: void GameSession::Init() { @@ -125,13 +131,20 @@ namespace DanBias #pragma region TESTING + +using namespace GameLogic; + + void ConvertToMovement(ClientObject* reciever, CustomNetProtocol& inputToConvert); + //VARIABLES GOES HERE int i = 0; - GameLogic::Player erik; + DynamicObject* objectBox; void GameSession::EricLogicInitFunc() { - + CollisionManager::BoxCollision(0,0); + + objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX); } void GameSession::EricLogicFrameFunc() { @@ -139,7 +152,25 @@ namespace DanBias } void GameSession::EricsLogicTestingProtocalRecieved(ClientObject* reciever, CustomNetProtocol& protocol) { + switch (protocol[protocol_ID_INDEX].value.netShort) + { + case protocol_Gamplay_PlayerNavigation: + ConvertToMovement(reciever, protocol); + break; + } + } + + void ConvertToMovement(ClientObject* reciever,CustomNetProtocol& inputToConvert) + { + if (inputToConvert[1].value.netBool == true) + { + reciever->Logic_Object()->Move(PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD); + } + if (inputToConvert[2].value.netBool == true) + { + reciever->Logic_Object()->Move(PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD); + } } #pragma endregion diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3d1af2a1..a549d7c6 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -6,54 +6,52 @@ using namespace Oyster; -namespace GameLogic -{ +using namespace GameLogic; - namespace CollisionManager + void PlayerVBox(Player &player, DynamicObject &box); + + + Physics::ICustomBody::SubscriptMessage CollisionManager::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) { + Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); + Object *realObj = (Object*)obj->gameObjectRef; - void PlayerVBox(Player &player, DynamicObject &box); - - - Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) + switch (realObj->GetType().value) { - Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); - Object *realObj = (Object*)obj->gameObjectRef; + case OBJECT_TYPE::OBJECT_TYPE_BOX: + PlayerVBox(*player,(*(DynamicObject*) realObj)); + break; + case OBJECT_TYPE::OBJECT_TYPE_PLAYER: - switch (realObj->GetType()) - { - case OBJECT_TYPE_BOX: - PlayerVBox(*player,(*(DynamicObject*) realObj)); - break; - case OBJECT_TYPE_PLAYER: - - break; - } - - return Physics::ICustomBody::SubscriptMessage_none; + break; } - - void PlayerVBox(Player &player, DynamicObject &box) - { - player.DamageLife(20); - } - - Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) - { - DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef; - Object *realObj = (Object*)obj->gameObjectRef; - switch (realObj->GetType()) - { - case OBJECT_TYPE_BOX: - - break; - case OBJECT_TYPE_PLAYER: - //PlayerVBox(*(Player*)realObj,*box); - break; - } - - return Physics::ICustomBody::SubscriptMessage_none; - } + return Physics::ICustomBody::SubscriptMessage_none; + } + + void PlayerVBox(Player &player, DynamicObject &box) + { + player.DamageLife(20); + } + + Physics::ICustomBody::SubscriptMessage CollisionManager::BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) + { + if(rigidBodyBox == 0) + { + return Physics::ICustomBody::SubscriptMessage::SubscriptMessage_none; + } + DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef; + Object *realObj = (Object*)obj->gameObjectRef; + + switch (realObj->GetType().value) + { + case OBJECT_TYPE::OBJECT_TYPE_BOX: + + break; + case OBJECT_TYPE::OBJECT_TYPE_PLAYER: + //PlayerVBox(*(Player*)realObj,*box); + break; + } + + return Physics::ICustomBody::SubscriptMessage_none; } -} \ No newline at end of file diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index d19ce8e3..18d482b4 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -7,12 +7,13 @@ namespace GameLogic { - namespace CollisionManager + class CollisionManager { + public: //these are the main collision functions //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); - Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); - Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); + static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); + static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); //these are the specific collision case functions //void PlayerVBox(Player &player, DynamicObject &box); diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 70bb8c11..b8709a52 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -4,12 +4,13 @@ #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H #include "Object.h" +#include "GameLogicDef.h" namespace GameLogic { - class DynamicObject : public Object + class DANBIAS_GAMELOGIC_DLL DynamicObject : public Object { public: diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 11ba6e82..500f8bbc 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -174,6 +174,7 @@ + diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 3e72647e..ee53ff04 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -1,23 +1,63 @@ #ifndef GAMELOGICSTATES_H #define GAMELOGICSTATES_H +#include "GameLogicDef.h" namespace GameLogic { - enum PLAYER_STATE + class DANBIAS_GAMELOGIC_DLL PLAYER_STATE { - PLAYER_STATE_JUMPING = 0, - PLAYER_STATE_WALKING = 1, - PLAYER_STATE_IDLE = 2, + 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; + + }; + class DANBIAS_GAMELOGIC_DLL PLAYER_MOVEMENT + { + 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; }; - enum PLAYER_MOVEMENT + class DANBIAS_GAMELOGIC_DLL OBJECT_TYPE { - PLAYER_MOVEMENT_FORWARD = 0, - PLAYER_MOVEMENT_BACKWARD = 1, - PLAYER_MOVEMENT_LEFT = 2, - PLAYER_MOVEMENT_RIGHT = 4, - PLAYER_MOVEMENT_JUMP = 8, + 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; }; enum WEAPON_FIRE @@ -37,12 +77,7 @@ namespace GameLogic WEAPON_STATE_RELOADING = 2, }; - enum OBJECT_TYPE - { - OBJECT_TYPE_PLAYER = 0, - OBJECT_TYPE_BOX = 1, - OBJECT_TYPE_UNKNOWN = 2, - }; + }; #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index c9d1e476..748d19c7 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -20,7 +20,7 @@ Object::Object() rigidBody->gameObjectRef = this; this->objectID = GID(); - this->type = OBJECT_TYPE_UNKNOWN; + this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index b17a1b5b..36d0a197 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 = PLAYER_STATE_IDLE; + playerState.value = PLAYER_STATE::PLAYER_STATE_IDLE; lookDir = Oyster::Math::Float3(1,0,0); } @@ -36,7 +36,7 @@ struct Player::PrivateData }myData; Player::Player() - :Object(CollisionManager::PlayerCollision, OBJECT_TYPE_PLAYER) + :Object(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) { myData = new PrivateData(); } @@ -51,23 +51,23 @@ void Player::Move(const PLAYER_MOVEMENT &movement) { Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity(); - switch(movement) + switch(movement.value) { - case PLAYER_MOVEMENT_FORWARD: + case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD: API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100); break; - case PLAYER_MOVEMENT_BACKWARD: + case PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD: API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); break; - case PLAYER_MOVEMENT_LEFT: + case PLAYER_MOVEMENT::PLAYER_MOVEMENT_LEFT: break; - case PLAYER_MOVEMENT_RIGHT: + case PLAYER_MOVEMENT::PLAYER_MOVEMENT_RIGHT: break; - case PLAYER_MOVEMENT_JUMP: + case PLAYER_MOVEMENT::PLAYER_MOVEMENT_JUMP: Jump(); break; } @@ -82,7 +82,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) { API::Instance().SetCenter(rigidBody,spawnPoint); myData->life = 100; - myData->playerState = PLAYER_STATE_IDLE; + myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; myData->lookDir = Oyster::Math::Float3(1,0,0); } @@ -93,20 +93,21 @@ void Player::Jump() bool Player::IsWalking() { - return (myData->playerState == PLAYER_STATE_WALKING); + return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_WALKING); } bool Player::IsJumping() { - return (myData->playerState == PLAYER_STATE_JUMPING); + return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_JUMPING); } bool Player::IsIdle() { - return (myData->playerState == PLAYER_STATE_IDLE); + return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_IDLE); } Oyster::Math::Float3 Player::GetPos() { return rigidBody->GetCenter(); + return Oyster::Math::Float3(0,0,0); } Oyster::Math::Float3 Player::GetLookDir() diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 8e575502..f35b3ba7 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -7,11 +7,13 @@ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_Gamplay_PlayerNavigation 0 -#define protocol_Gamplay_PlayerMouseMovement 1 -#define protocol_Gamplay_PlayerPosition 2 -#define protocol_Gamplay_CreateObject 3 -#define protocol_Gamplay_ObjectPosition 4 +#define protocol_ID_INDEX 0 + +#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_Lobby_Msg 100 From e68001da0e71b3805e7b92ffee061355ed9a7028 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 19 Dec 2013 11:46:11 +0100 Subject: [PATCH 3/3] testing updated message to client about object creation, message to client about player movement --- .../ServerObjects/GameSession.cpp | 40 +++++++++++++++++-- Code/Game/GameProtocols/ObjectProtocols.h | 2 +- Code/GamePhysics/PhysicsAPI.h | 4 +- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp index e8896878..8a5f54e5 100644 --- a/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/GameSession.cpp @@ -143,9 +143,25 @@ using namespace GameLogic; void GameSession::EricLogicInitFunc() { - //CollisionManager::BoxCollision(0,0); + 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); + } - //objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX); } void GameSession::EricLogicFrameFunc() { @@ -153,13 +169,31 @@ using namespace GameLogic; } void GameSession::EricsLogicTestingProtocalRecieved(ClientObject* reciever, CustomNetProtocol& protocol) { - + bool moved = false; switch (protocol[protocol_ID_INDEX].value.netShort) { case protocol_Gameplay_PlayerNavigation: ConvertToMovement(reciever, protocol); + moved = true; break; } + + if (moved) + { + + Protocol_ObjectPosition playerMovement; + + Oyster::Math::Float4x4 worldMat = reciever->Logic_Object()->GetRigidBody()->GetOrientation(); + playerMovement.object_ID = reciever->Logic_Object()->GetID(); + for (int i = 0; i < 16; i++) + { + playerMovement.worldMatrix[i] = worldMat[i]; + } + + reciever->NetClient_Object()->Send(playerMovement); + } + + } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 9cac85be..7ba023b1 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -11,7 +11,7 @@ namespace GameLogic struct Protocol_CreateObject :public Oyster::Network::CustomProtocolObject { int object_ID; - char path[255]; + char *path; float worldMatrix[16]; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 84a3d639..04d0d3f1 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -232,10 +232,12 @@ namespace Oyster protected: virtual ~API() {} }; - + + //! The root interface for all physical representations processable by the engine. class PHYSICS_DLL_USAGE ICustomBody { + public: enum SubscriptMessage {