GameServer - Merge with gamelogic

This commit is contained in:
Dennis Andersen 2014-01-10 23:36:03 +01:00
commit 2b5a5b2fbd
16 changed files with 217 additions and 39 deletions

View File

@ -23,7 +23,8 @@ namespace DanBias
{ {
Oyster::Network::NetworkClient* nwClient; Oyster::Network::NetworkClient* nwClient;
Client::GameClientState* gameClientState; Client::GameClientState* gameClientState;
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
{ {
int pType = p[0].value.netInt; int pType = p[0].value.netInt;

View File

@ -26,6 +26,7 @@ void C_DynamicObj::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_DynamicObj::setPos(Oyster::Math::Float4x4 world) void C_DynamicObj::setPos(Oyster::Math::Float4x4 world)
{ {

View File

@ -28,7 +28,7 @@ void C_Player::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_Player::setPos(Oyster::Math::Float4x4 world) void C_Player::setPos(Oyster::Math::Float4x4 world)

View File

@ -28,6 +28,7 @@ void C_StaticObj::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_StaticObj::setPos(Oyster::Math::Float4x4 world) void C_StaticObj::setPos(Oyster::Math::Float4x4 world)

View File

@ -24,6 +24,7 @@ void C_UIobject::Init(ModelInitData modelInit)
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->WorldMatrix = modelInit.world; privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible; privData->model->Visible = modelInit.visible;
privData->ID = modelInit.id;
} }
void C_UIobject::setPos(Oyster::Math::Float4x4 world) void C_UIobject::setPos(Oyster::Math::Float4x4 world)

View File

@ -40,6 +40,12 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
} }
GameState::gameStateState GameState::LoadGame() GameState::gameStateState GameState::LoadGame()
{ {
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(0,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 5;
plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight);
LoadModels(L"map"); LoadModels(L"map");
InitCamera(Oyster::Math::Float3(0,0,5.4f)); InitCamera(Oyster::Math::Float3(0,0,5.4f));
return gameStateState_playing; return gameStateState_playing;
@ -56,18 +62,22 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
modelData.visible = true; modelData.visible = true;
modelData.modelPath = L"..\\Content\\worldDummy"; modelData.modelPath = L"..\\Content\\worldDummy";
modelData.id = 0;
// load models // load models
C_Object* obj = new C_Player(); C_Object* obj = new C_Player();
privData->object.push_back(obj); privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2));
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\worldDummy"; modelData.modelPath = L"..\\Content\\worldDummy";
modelData.id ++;
obj = new C_DynamicObj(); obj = new C_DynamicObj();
privData->object.push_back(obj); privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
return true; return true;
} }
bool GameState::InitCamera(Oyster::Math::Float3 startPos) bool GameState::InitCamera(Oyster::Math::Float3 startPos)
@ -209,6 +219,7 @@ void GameState::Protocol( ObjPos* pos )
{ {
world[i] = pos->worldPos[i]; world[i] = pos->worldPos[i];
} }
for (int i = 0; i < privData->object.size(); i++) for (int i = 0; i < privData->object.size(); i++)
{ {
if(privData->object[i]->GetId() == pos->object_ID) if(privData->object[i]->GetId() == pos->object_ID)

View File

@ -157,17 +157,25 @@ namespace DanBias
{ {
case protocol_Gameplay_PlayerNavigation: case protocol_Gameplay_PlayerNavigation:
{ {
Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity;
if(p[1].value.netBool) //bool bForward; if(p[1].value.netBool) //bool bForward;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); world.v[3].x = 2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD);
if(p[2].value.netBool) //bool bBackward; if(p[2].value.netBool) //bool bBackward;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); world.v[3].x = -2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD);
if(p[5].value.netBool) //bool bStrafeRight; if(p[5].value.netBool) //bool bStrafeRight;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); world.v[3].y = 2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT);
if(p[6].value.netBool) //bool bStrafeLeft; if(p[6].value.netBool) //bool bStrafeLeft;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); world.v[3].y = -2;
//c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
//Protocol_ObjectPosition op(c->GetPlayer()->GetOrientation(), c->GetPlayer()->GetID());
//Send(op.GetProtocol()); Protocol_ObjectPosition res(world, 0);
Send(res.GetProtocol());
} }
break; break;
case protocol_Gameplay_PlayerMouseMovement: case protocol_Gameplay_PlayerMouseMovement:

View File

@ -0,0 +1,71 @@
#include "Game.h"
#include "Player.h"
#include "Level.h"
using namespace GameLogic;
struct Game::PrivateData
{
PrivateData()
{
}
~PrivateData()
{
}
Player **players;
Level *level;
}myData;
Game::Game(void)
{
myData = new PrivateData();
}
Game::~Game(void)
{
if(myData)
{
delete myData;
}
}
void Game::MovePlayer(int playerID, const PLAYER_MOVEMENT &movement)
{
}
void Game::PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage)
{
}
void Game::GetPlayerPos(int playerID)
{
}
void Game::GetAllPlayerPos()
{
}
Game::PlayerData Game::CreatePlayer()
{
}
void Game::CreateTeam()
{
}
void Game::NewFrame()
{
}

View File

@ -0,0 +1,88 @@
#ifndef GAME_H
#define GAME_H
#include "GameLogicStates.h"
namespace GameLogic
{
class Game
{
public:
struct PlayerData
{
int playerID;
int teamID;
PlayerData()
{
playerID = 0;
teamID = 0;
}
PlayerData(int playerID,int teamID)
{
this->playerID = playerID;
this->teamID = teamID;
}
~PlayerData()
{
}
};
public:
Game(void);
~Game(void);
/********************************************************
* Moves the chosen player based on input
* @param playerID: ID of the player you want to recieve the message
* @param movement: enum value on what kind of action is to be taken
********************************************************/
void MovePlayer(int playerID, const PLAYER_MOVEMENT &movement);
/********************************************************
* Uses the chosen players weapon based on input
* @param playerID: ID of the player you want to recieve the message
* @param Usage: enum value on what kind of action is to be taken
********************************************************/
void PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage);
/********************************************************
* Gets a specific players position
* @param playerID: ID of the player whos position you want
********************************************************/
void GetPlayerPos(int playerID);
/********************************************************
* Gets the position of all players currently in the game
********************************************************/
void GetAllPlayerPos();
/********************************************************
* Creates a player and returns PlayerData containing ID of the player
********************************************************/
PlayerData CreatePlayer();
/********************************************************
* Creates a team
********************************************************/
void CreateTeam();
/********************************************************
* Runs a update of the gamelogic and physics
********************************************************/
void NewFrame();
private:
struct PrivateData;
PrivateData *myData;
};
}
#endif

View File

@ -173,6 +173,7 @@
<ClInclude Include="AttatchmentSocket.h" /> <ClInclude Include="AttatchmentSocket.h" />
<ClInclude Include="CollisionManager.h" /> <ClInclude Include="CollisionManager.h" />
<ClInclude Include="DynamicObject.h" /> <ClInclude Include="DynamicObject.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="GameLogicDef.h" /> <ClInclude Include="GameLogicDef.h" />
<ClInclude Include="GameLogicStates.h" /> <ClInclude Include="GameLogicStates.h" />
<ClInclude Include="GameMode.h" /> <ClInclude Include="GameMode.h" />
@ -190,6 +191,7 @@
<ClCompile Include="AttatchmentSocket.cpp" /> <ClCompile Include="AttatchmentSocket.cpp" />
<ClCompile Include="CollisionManager.cpp" /> <ClCompile Include="CollisionManager.cpp" />
<ClCompile Include="DynamicObject.cpp" /> <ClCompile Include="DynamicObject.cpp" />
<ClCompile Include="Game.cpp" />
<ClCompile Include="GameMode.cpp" /> <ClCompile Include="GameMode.cpp" />
<ClCompile Include="IAttatchment.cpp" /> <ClCompile Include="IAttatchment.cpp" />
<ClCompile Include="Level.cpp" /> <ClCompile Include="Level.cpp" />

View File

@ -10,7 +10,7 @@ using namespace GameLogic;
struct Level::PrivateData struct Level::PrivateData
{ {
PrivateData() PrivateData()
{ {
} }

View File

@ -23,6 +23,8 @@ Object::Object()
this->objectID = GID(); this->objectID = GID();
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
rigidBody->GetState(state);
} }
Object::Object(void* collisionFunc, OBJECT_TYPE type) Object::Object(void* collisionFunc, OBJECT_TYPE type)
@ -40,13 +42,14 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
this->objectID = GID(); this->objectID = GID();
this->type = type; this->type = type;
rigidBody->GetState(state);
} }
Object::~Object(void) Object::~Object(void)
{ {
} }
OBJECT_TYPE Object::GetType() OBJECT_TYPE Object::GetType()

View File

@ -9,14 +9,8 @@
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include "GameLogicDef.h" #include "GameLogicDef.h"
#include <PhysicsAPI.h>
namespace Oyster
{
namespace Physics
{
class ICustomBody;
}
}
namespace GameLogic namespace GameLogic
{ {
class DANBIAS_GAMELOGIC_DLL Object class DANBIAS_GAMELOGIC_DLL Object
@ -36,6 +30,8 @@ namespace GameLogic
int objectID; int objectID;
protected: protected:
Oyster::Physics::ICustomBody *rigidBody; Oyster::Physics::ICustomBody *rigidBody;
Oyster::Physics::ICustomBody::State state;
}; };
} }

View File

@ -16,7 +16,7 @@ struct Player::PrivateData
teamID = -1; teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE; playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float3(1,0,0); lookDir = Oyster::Math::Float4(1,0,0,0);
} }
~PrivateData() ~PrivateData()
@ -31,7 +31,7 @@ struct Player::PrivateData
int teamID; int teamID;
Weapon *weapon; Weapon *weapon;
PLAYER_STATE playerState; PLAYER_STATE playerState;
Oyster::Math::Float3 lookDir; Oyster::Math::Float4 lookDir;
}myData; }myData;
@ -49,8 +49,6 @@ Player::~Player(void)
void Player::Move(const PLAYER_MOVEMENT &movement) void Player::Move(const PLAYER_MOVEMENT &movement)
{ {
//Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity();
switch(movement) switch(movement)
{ {
case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD: case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD:
@ -77,41 +75,41 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward() void Player::MoveForward()
{ {
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100); state.ApplyLinearImpulse(myData->lookDir * 100);
} }
void Player::MoveBackwards() void Player::MoveBackwards()
{ {
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); state.ApplyLinearImpulse(-myData->lookDir * 100);
} }
void Player::MoveRight() void Player::MoveRight()
{ {
//Do cross product with forward vector and negative gravity vector //Do cross product with forward vector and negative gravity vector
//Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross(myData->lookDir); Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir);
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100); state.ApplyLinearImpulse(r * 100);
} }
void Player::MoveLeft() void Player::MoveLeft()
{ {
//Do cross product with forward vector and negative gravity vector //Do cross product with forward vector and negative gravity vector
//Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross(myData->lookDir); Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir);
//API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100); state.ApplyLinearImpulse(-r * 100);
} }
void Player::UseWeapon(const WEAPON_FIRE &fireInput) void Player::UseWeapon(const WEAPON_FIRE &Usage)
{ {
myData->weapon->Use(fireInput); myData->weapon->Use(Usage);
} }
void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Respawn(Oyster::Math::Float3 spawnPoint)
{ {
//API::Instance().SetCenter(rigidBody,spawnPoint);
myData->life = 100; myData->life = 100;
myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
myData->lookDir = Oyster::Math::Float3(1,0,0); myData->lookDir = Oyster::Math::Float4(1,0,0);
} }
void Player::Jump() void Player::Jump()
{ {
//API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100);
} }
bool Player::IsWalking() bool Player::IsWalking()
@ -129,8 +127,7 @@ bool Player::IsIdle()
Oyster::Math::Float3 Player::GetPos() Oyster::Math::Float3 Player::GetPos()
{ {
//return rigidBody->GetCenter(); return (Oyster::Math::Float3)state.GetCenterPosition();
return Oyster::Math::Float3(0,0,0);
} }
Oyster::Math::Float3 Player::GetLookDir() Oyster::Math::Float3 Player::GetLookDir()

View File

@ -33,7 +33,7 @@ namespace GameLogic
* Uses the weapon based on input * Uses the weapon based on input
* @param fireInput: enum value on what kind of action is to be taken * @param fireInput: enum value on what kind of action is to be taken
********************************************************/ ********************************************************/
void UseWeapon(const WEAPON_FIRE &fireInput); void UseWeapon(const WEAPON_FIRE &Usage);
/******************************************************** /********************************************************
* Respawns the player, this resets several stats and settings on the player * Respawns the player, this resets several stats and settings on the player

View File

@ -34,8 +34,6 @@ namespace GameLogic
bool IsValidSocket(int socketID); bool IsValidSocket(int socketID);
int GetCurrentSocketID(); int GetCurrentSocketID();
private: private:
struct PrivateData; struct PrivateData;