From 0ea08fbd548f1d3ae927cb3fdcd57c1b2d826836 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 19 Dec 2013 10:21:03 +0100 Subject: [PATCH] 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