This commit is contained in:
Dennis Andersen 2013-12-19 12:34:59 +01:00
commit 934aa6e45a
16 changed files with 239 additions and 96 deletions

View File

@ -6,6 +6,8 @@
#include "GameClientState\GameState.h"
#include "GameClientState\LobbyState.h"
#include "PlayerProtocols.h"
#include "ControlProtocols.h"
#include "GameProtocols.h"
#include "NetworkClient.h"
#include "../WindowManager/WindowShell.h"
@ -29,9 +31,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 +52,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 +66,7 @@ namespace DanBias
}
break;
case protocol_Gamplay_CreateObject:
case protocol_Gameplay_CreateObject:
{
Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj;
@ -76,7 +84,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<Client::GameState*>(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 +133,6 @@ namespace DanBias
}
public:
//Client::GameClientState* gameClientState;
WindowShell* window;
InputClass* inputObj;
Utility::WinTimer* timer;

View File

@ -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];

View File

@ -2,8 +2,11 @@
#include "DllInterfaces/GFXAPI.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_DynamicObj.h"
#include "NetworkClient.h"
#include "PlayerProtocols.h"
#include "ControlProtocols.h"
#include "GameProtocols.h"
#include "NetworkClient.h"
using namespace DanBias::Client;
@ -83,10 +86,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 +188,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 +224,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 +241,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;

View File

@ -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);

View File

@ -6,51 +6,52 @@
using namespace Oyster;
namespace GameLogic
{
using namespace GameLogic;
void PlayerVBox(Player &player, DynamicObject &box);
void PlayerVBox(Player &player, DynamicObject &box);
Physics::ICustomBody::SubscriptMessage CollisionManager::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
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;
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 CollisionManager::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:
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_PLAYER:
//PlayerVBox(*(Player*)realObj,*box);
break;
}
return Physics::ICustomBody::SubscriptMessage_none;
break;
case OBJECT_TYPE::OBJECT_TYPE_PLAYER:
//PlayerVBox(*(Player*)realObj,*box);
break;
}
}
return Physics::ICustomBody::SubscriptMessage_none;
}

View File

@ -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:

View File

@ -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

View File

@ -20,7 +20,7 @@ Object::Object()
rigidBody->gameObjectRef = this;
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;
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()

View File

@ -0,0 +1,38 @@
#ifndef GAMELOGIC_CONTROL_PROTOCOLS_H
#define GAMELOGIC_CONTROL_PROTOCOLS_H
#include <CustomNetProtocol.h>
#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

View File

@ -4,6 +4,7 @@
#include "ObjectProtocols.h"
#include "PlayerProtocols.h"
#include "LobbyProtocols.h"
#include "ControlProtocols.h"
#include "TEST_PROTOCOLS.h"

View File

@ -154,6 +154,7 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ControlProtocols.h" />
<ClInclude Include="GameProtocols.h" />
<ClInclude Include="LobbyProtocols.h" />
<ClInclude Include="ObjectProtocols.h" />

View File

@ -11,14 +11,14 @@ namespace GameLogic
struct Protocol_CreateObject :public Oyster::Network::CustomProtocolObject
{
int object_ID;
char path[255];
char *path;
float worldMatrix[16];
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

View File

@ -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;

View File

@ -8,6 +8,17 @@
/* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */
#define protocol_ID_INDEX 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 *****/

View File

@ -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
{