gamesession testing

This commit is contained in:
Erik Persson 2013-12-19 10:21:03 +01:00
parent 92b3525587
commit 0ea08fbd54
9 changed files with 153 additions and 83 deletions

View File

@ -4,6 +4,10 @@
#include <PostBox\PostBox.h> #include <PostBox\PostBox.h>
#include "ClientObject.h" #include "ClientObject.h"
#include "DynamicObject.h"
#include "CollisionManager.h"
#include "GameLogicStates.h"
#define ERIK #define ERIK
@ -83,6 +87,8 @@ namespace DanBias
return true; return true;
} }
////private: ////private:
void GameSession::Init() void GameSession::Init()
{ {
@ -125,13 +131,20 @@ namespace DanBias
#pragma region TESTING #pragma region TESTING
using namespace GameLogic;
void ConvertToMovement(ClientObject* reciever, CustomNetProtocol& inputToConvert);
//VARIABLES GOES HERE //VARIABLES GOES HERE
int i = 0; int i = 0;
GameLogic::Player erik; DynamicObject* objectBox;
void GameSession::EricLogicInitFunc() void GameSession::EricLogicInitFunc()
{ {
CollisionManager::BoxCollision(0,0);
objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX);
} }
void GameSession::EricLogicFrameFunc() void GameSession::EricLogicFrameFunc()
{ {
@ -139,7 +152,25 @@ namespace DanBias
} }
void GameSession::EricsLogicTestingProtocalRecieved(ClientObject* reciever, CustomNetProtocol& protocol) 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 #pragma endregion

View File

@ -6,54 +6,52 @@
using namespace Oyster; 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); switch (realObj->GetType().value)
Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
{ {
Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); case OBJECT_TYPE::OBJECT_TYPE_BOX:
Object *realObj = (Object*)obj->gameObjectRef; PlayerVBox(*player,(*(DynamicObject*) realObj));
break;
case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
switch (realObj->GetType()) break;
{
case OBJECT_TYPE_BOX:
PlayerVBox(*player,(*(DynamicObject*) realObj));
break;
case OBJECT_TYPE_PLAYER:
break;
}
return Physics::ICustomBody::SubscriptMessage_none;
} }
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()) return Physics::ICustomBody::SubscriptMessage_none;
{ }
case OBJECT_TYPE_BOX:
void PlayerVBox(Player &player, DynamicObject &box)
break; {
case OBJECT_TYPE_PLAYER: player.DamageLife(20);
//PlayerVBox(*(Player*)realObj,*box); }
break;
} Physics::ICustomBody::SubscriptMessage CollisionManager::BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_none; 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;
} }
}

View File

@ -7,12 +7,13 @@
namespace GameLogic namespace GameLogic
{ {
namespace CollisionManager class CollisionManager
{ {
public:
//these are the main collision functions //these are the main collision functions
//typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); //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); static 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 BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj);
//these are the specific collision case functions //these are the specific collision case functions
//void PlayerVBox(Player &player, DynamicObject &box); //void PlayerVBox(Player &player, DynamicObject &box);

View File

@ -4,12 +4,13 @@
#ifndef DYNAMICOBJECT_H #ifndef DYNAMICOBJECT_H
#define DYNAMICOBJECT_H #define DYNAMICOBJECT_H
#include "Object.h" #include "Object.h"
#include "GameLogicDef.h"
namespace GameLogic namespace GameLogic
{ {
class DynamicObject : public Object class DANBIAS_GAMELOGIC_DLL DynamicObject : public Object
{ {
public: public:

View File

@ -174,6 +174,7 @@
<ClInclude Include="CollisionManager.h" /> <ClInclude Include="CollisionManager.h" />
<ClInclude Include="DynamicObject.h" /> <ClInclude Include="DynamicObject.h" />
<ClInclude Include="GameLogicDef.h" /> <ClInclude Include="GameLogicDef.h" />
<ClInclude Include="GameLogicStates.h" />
<ClInclude Include="GameMode.h" /> <ClInclude Include="GameMode.h" />
<ClInclude Include="IAttatchment.h" /> <ClInclude Include="IAttatchment.h" />
<ClInclude Include="Level.h" /> <ClInclude Include="Level.h" />

View File

@ -1,23 +1,63 @@
#ifndef GAMELOGICSTATES_H #ifndef GAMELOGICSTATES_H
#define GAMELOGICSTATES_H #define GAMELOGICSTATES_H
#include "GameLogicDef.h"
namespace GameLogic namespace GameLogic
{ {
enum PLAYER_STATE class DANBIAS_GAMELOGIC_DLL PLAYER_STATE
{ {
PLAYER_STATE_JUMPING = 0, public:
PLAYER_STATE_WALKING = 1, PLAYER_STATE()
PLAYER_STATE_IDLE = 2, {
}
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, public:
PLAYER_MOVEMENT_BACKWARD = 1, OBJECT_TYPE()
PLAYER_MOVEMENT_LEFT = 2, {
PLAYER_MOVEMENT_RIGHT = 4,
PLAYER_MOVEMENT_JUMP = 8, }
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 enum WEAPON_FIRE
@ -37,12 +77,7 @@ namespace GameLogic
WEAPON_STATE_RELOADING = 2, WEAPON_STATE_RELOADING = 2,
}; };
enum OBJECT_TYPE
{
OBJECT_TYPE_PLAYER = 0,
OBJECT_TYPE_BOX = 1,
OBJECT_TYPE_UNKNOWN = 2,
};
}; };
#endif #endif

View File

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

View File

@ -14,7 +14,7 @@ struct Player::PrivateData
life = 100; life = 100;
teamID = -1; teamID = -1;
playerState = PLAYER_STATE_IDLE; playerState.value = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float3(1,0,0); lookDir = Oyster::Math::Float3(1,0,0);
} }
@ -36,7 +36,7 @@ struct Player::PrivateData
}myData; }myData;
Player::Player() Player::Player()
:Object(CollisionManager::PlayerCollision, OBJECT_TYPE_PLAYER) :Object(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
{ {
myData = new PrivateData(); myData = new PrivateData();
} }
@ -51,23 +51,23 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
{ {
Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity(); 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); API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100);
break; break;
case PLAYER_MOVEMENT_BACKWARD: case PLAYER_MOVEMENT::PLAYER_MOVEMENT_BACKWARD:
API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100);
break; break;
case PLAYER_MOVEMENT_LEFT: case PLAYER_MOVEMENT::PLAYER_MOVEMENT_LEFT:
break; break;
case PLAYER_MOVEMENT_RIGHT: case PLAYER_MOVEMENT::PLAYER_MOVEMENT_RIGHT:
break; break;
case PLAYER_MOVEMENT_JUMP: case PLAYER_MOVEMENT::PLAYER_MOVEMENT_JUMP:
Jump(); Jump();
break; break;
} }
@ -82,7 +82,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint)
{ {
API::Instance().SetCenter(rigidBody,spawnPoint); API::Instance().SetCenter(rigidBody,spawnPoint);
myData->life = 100; myData->life = 100;
myData->playerState = PLAYER_STATE_IDLE; myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
myData->lookDir = Oyster::Math::Float3(1,0,0); myData->lookDir = Oyster::Math::Float3(1,0,0);
} }
@ -93,20 +93,21 @@ void Player::Jump()
bool Player::IsWalking() bool Player::IsWalking()
{ {
return (myData->playerState == PLAYER_STATE_WALKING); return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_WALKING);
} }
bool Player::IsJumping() bool Player::IsJumping()
{ {
return (myData->playerState == PLAYER_STATE_JUMPING); return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_JUMPING);
} }
bool Player::IsIdle() bool Player::IsIdle()
{ {
return (myData->playerState == PLAYER_STATE_IDLE); return (myData->playerState.value == PLAYER_STATE::PLAYER_STATE_IDLE);
} }
Oyster::Math::Float3 Player::GetPos() Oyster::Math::Float3 Player::GetPos()
{ {
return rigidBody->GetCenter(); return rigidBody->GetCenter();
return Oyster::Math::Float3(0,0,0);
} }
Oyster::Math::Float3 Player::GetLookDir() Oyster::Math::Float3 Player::GetLookDir()

View File

@ -7,11 +7,13 @@
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
#define protocol_Gamplay_PlayerNavigation 0 #define protocol_ID_INDEX 0
#define protocol_Gamplay_PlayerMouseMovement 1
#define protocol_Gamplay_PlayerPosition 2 #define protocol_Gamplay_PlayerNavigation 300
#define protocol_Gamplay_CreateObject 3 #define protocol_Gamplay_PlayerMouseMovement 301
#define protocol_Gamplay_ObjectPosition 4 #define protocol_Gamplay_PlayerPosition 302
#define protocol_Gamplay_CreateObject 303
#define protocol_Gamplay_ObjectPosition 304
#define protocol_Lobby_Msg 100 #define protocol_Lobby_Msg 100