GameServer - Merged with GameLogic

This commit is contained in:
Dennis Andersen 2014-02-05 15:16:31 +01:00
commit 201a07f0dc
26 changed files with 291 additions and 135 deletions

View File

@ -5,6 +5,7 @@
#include "../DanBiasGame/Include/DanBiasGame.h" #include "../DanBiasGame/Include/DanBiasGame.h"
#include "../GameProtocols/GeneralProtocols.h" #include "../GameProtocols/GeneralProtocols.h"
#include "..\GameProtocols\Protocols.h" #include "..\GameProtocols\Protocols.h"
#include <Utilities.h>
namespace DanBias namespace DanBias
{ {
@ -113,13 +114,22 @@ namespace DanBias
{ {
if(dynamic_cast<Client::LobbyState*>(gameClientState)) if(dynamic_cast<Client::LobbyState*>(gameClientState))
{ {
GameLogic::Protocol_LobbyStartGame pt(p); int id = p[1].value.netInt;
std::string name = p.Get(19).value.netCharPtr;
Oyster::Math::Float4x4 w;
for(int i = 0; i< 16; i++)
{
w[i] = p[i+3].value.netFloat;
}
gameClientState->Release(); gameClientState->Release();
delete gameClientState; delete gameClientState;
gameClientState = new Client::GameState(); gameClientState = new Client::GameState();
gameClientState->Init(this); gameClientState->Init(this);
((Client::GameState*)gameClientState)->setClientId(pt.clientID); std::wstring temp;
Utility::String::StringToWstring(name, temp);
((Client::GameState*)gameClientState)->InitiatePlayer(id, temp, w);
} }
} }
break; break;

View File

@ -53,15 +53,25 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
GameState::gameStateState GameState::LoadGame() GameState::gameStateState GameState::LoadGame()
{ {
Oyster::Graphics::Definitions::Pointlight plight; Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(0,15,5); plight.Pos = Oyster::Math::Float3(315, 0 ,5);
plight.Color = Oyster::Math::Float3(0,1,0); plight.Color = Oyster::Math::Float3(0.9,0.7,0.2);
plight.Radius = 50; plight.Radius = 100;
plight.Bright = 2; plight.Bright = 0.9;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
plight.Pos = Oyster::Math::Float3(10,15,5); plight.Pos = Oyster::Math::Float3(10,350,5);
plight.Color = Oyster::Math::Float3(1,0,0); plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
plight.Radius = 50; plight.Radius = 200;
plight.Bright = 2; plight.Bright = 0.7;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Oyster::Math::Float3(350,350,5);
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
plight.Radius = 200;
plight.Bright = 0.7;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Oyster::Math::Float3(10,350,350);
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
plight.Radius = 200;
plight.Bright = 0.7;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
plight.Pos = Oyster::Math::Float3(10,-15,5); plight.Pos = Oyster::Math::Float3(10,-15,5);
plight.Color = Oyster::Math::Float3(0,0,1); plight.Color = Oyster::Math::Float3(0,0,1);
@ -78,9 +88,10 @@ bool GameState::LoadModels(std::wstring mapFile)
// open file // open file
// read file // read file
// init models // init models
privData->modelCount = 4; int nrOfBoxex = 5;
myId += privData->modelCount; privData->modelCount = 3 + nrOfBoxex;
int id = 0;
int id = 100;
// add world model // add world model
ModelInitData modelData; ModelInitData modelData;
Oyster::Math3D::Float4x4 translate; Oyster::Math3D::Float4x4 translate;
@ -96,15 +107,20 @@ bool GameState::LoadModels(std::wstring mapFile)
// add box model // add box model
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
modelData.modelPath = L"box.dan";
for(int i =0; i< nrOfBoxex; i ++)
{
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
modelData.modelPath = L"box.dan";
modelData.id = id++; modelData.id = id++;
obj = new C_Player(); 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);
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
}
// add crystal model // add crystal model
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
@ -132,34 +148,6 @@ bool GameState::LoadModels(std::wstring mapFile)
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);
// add player model
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0));
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"char_renderTest.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add player model 2
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0));
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"char_renderTest.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
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)
@ -181,9 +169,21 @@ bool GameState::InitCamera(Oyster::Math::Float3 startPos)
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true; return true;
} }
void GameState::setClientId(int id) void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world)
{ {
myId = id; myId = id;
ModelInitData modelData;
C_Object* obj;
modelData.visible = true;
modelData.world = world;
modelData.modelPath = modelName;
modelData.id = myId;
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
} }
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
{ {
@ -334,7 +334,37 @@ void GameState::readKeyInput(InputClass* KeyInput)
if(!key_Shoot) if(!key_Shoot)
{ {
GameLogic::Protocol_PlayerShot playerShot; GameLogic::Protocol_PlayerShot playerShot;
playerShot.hasShot = true; playerShot.primaryPressed = true;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = false;
privData->nwClient->Send(playerShot);
key_Shoot = true;
}
}
else
key_Shoot = false;
if(KeyInput->IsKeyPressed(DIK_X))
{
if(!key_Shoot)
{
GameLogic::Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = true;
playerShot.utilityPressed = false;
privData->nwClient->Send(playerShot);
key_Shoot = true;
}
}
else
key_Shoot = false;
if(KeyInput->IsKeyPressed(DIK_C))
{
if(!key_Shoot)
{
GameLogic::Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = true;
privData->nwClient->Send(playerShot); privData->nwClient->Send(playerShot);
key_Shoot = true; key_Shoot = true;
} }
@ -343,7 +373,7 @@ void GameState::readKeyInput(InputClass* KeyInput)
key_Shoot = false; key_Shoot = false;
// jump // jump
if(KeyInput->IsKeyPressed(DIK_X)) if(KeyInput->IsKeyPressed(DIK_SPACE))
{ {
if(!key_Jump) if(!key_Jump)
{ {
@ -412,7 +442,7 @@ void GameState::Protocol( ObjPos* pos )
camera->setRight(right); camera->setRight(right);
camera->setUp(up); camera->setUp(up);
//camera->setLook(objForward); camera->setLook(objForward);
up *= 2; up *= 2;
objForward *= -3; objForward *= -3;

View File

@ -37,8 +37,8 @@ public:
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
bool LoadModels(std::wstring mapFile) ; bool LoadModels(std::wstring mapFile) ;
bool InitCamera(Oyster::Math::Float3 startPos) ; bool InitCamera(Oyster::Math::Float3 startPos) ;
void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world);
gameStateState LoadGame(); gameStateState LoadGame();
void setClientId(int id);
void readKeyInput(InputClass* KeyInput); void readKeyInput(InputClass* KeyInput);
bool Render()override; bool Render()override;
bool Release()override; bool Release()override;

View File

@ -41,9 +41,9 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
bool LoginState::LoadModels(std::wstring file) bool LoginState::LoadModels(std::wstring file)
{ {
Oyster::Graphics::Definitions::Pointlight plight; Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(-2,3,0); plight.Pos = Oyster::Math::Float3(0,0,5.4f);
plight.Color = Oyster::Math::Float3(0,1,0); plight.Color = Oyster::Math::Float3(1,1,1);
plight.Radius = 10; plight.Radius = 100;
plight.Bright = 1; plight.Bright = 1;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
// open file // open file
@ -57,10 +57,11 @@ bool LoginState::LoadModels(std::wstring file)
modelData.visible = true; modelData.visible = true;
modelData.modelPath = L"box_2.dan"; modelData.modelPath = L"box_2.dan";
// load models // load models
privData->object[0] = new C_StaticObj(); Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2));
privData->object[0] = new C_DynamicObj();
privData->object[0]->Init(modelData); privData->object[0]->Init(modelData);
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
privData->object[1] = new C_DynamicObj(); privData->object[1] = new C_DynamicObj();

View File

@ -42,7 +42,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
if(hasObject) if(hasObject)
{ {
ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES //ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES
break; break;
} }
ForcePull(usage,dt); ForcePull(usage,dt);

View File

@ -84,7 +84,7 @@ using namespace GameLogic;
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
{ {
damageDone = (int)kineticEnergyLoss * 0.10f; damageDone = (int)kineticEnergyLoss * 0.10f;
player.DamageLife(damageDone); //player.DamageLife(damageDone);
} }
} }
@ -96,6 +96,14 @@ using namespace GameLogic;
{ {
return Physics::ICustomBody::SubscriptMessage_none; return Physics::ICustomBody::SubscriptMessage_none;
} }
Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_player_collision_response;
}
Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
{
return Physics::ICustomBody::SubscriptMessage_none;
}
//Oyster::Physics::ICustomBody::SubscriptMessage //Oyster::Physics::ICustomBody::SubscriptMessage
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{ {

View File

@ -53,6 +53,7 @@ namespace GameLogic
Oyster::Math::Float4x4 GetOrientation() override; Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override; int GetID() const override;
OBJECT_TYPE GetObjectType() const override; OBJECT_TYPE GetObjectType() const override;
int getNrOfDynamicObj()const override;
IObjectData* GetObjectAt(int ID) const override; IObjectData* GetObjectAt(int ID) const override;
Level *level; Level *level;
}; };

View File

@ -100,6 +100,7 @@ namespace GameLogic
class ILevelData :public IObjectData class ILevelData :public IObjectData
{ {
public: public:
virtual int getNrOfDynamicObj()const = 0;
virtual IObjectData* GetObjectAt(int ID) const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0;
}; };

View File

@ -35,7 +35,10 @@ OBJECT_TYPE Game::LevelData::GetObjectType() const
return ((IObjectData*)this->level)->GetObjectType(); return ((IObjectData*)this->level)->GetObjectType();
//return OBJECT_TYPE_UNKNOWN; //return OBJECT_TYPE_UNKNOWN;
} }
int Game::LevelData::getNrOfDynamicObj()const
{
return this->level->getNrOfDynamicObj();
}
IObjectData* Game::LevelData::GetObjectAt(int ID) const IObjectData* Game::LevelData::GetObjectAt(int ID) const
{ {
return this->level->GetObj(ID); return this->level->GetObj(ID);

View File

@ -11,13 +11,15 @@ Game::PlayerData::PlayerData()
sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.size = Oyster::Math::Float3(4,7,4);
sbDesc.mass = 70; sbDesc.mass = 70;
sbDesc.restitutionCoeff = 0.5; sbDesc.restitutionCoeff = 0.5;
sbDesc.frictionCoeff_Static = 0.4;
sbDesc.frictionCoeff_Dynamic = 0.3;
sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0); sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0);
//create rigid body //create rigid body
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
//create player with this rigid body //create player with this rigid body
this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this); this->player->GetRigidBody()->SetCustomTag(this);
/*Oyster::Physics::ICustomBody::State state; /*Oyster::Physics::ICustomBody::State state;
this->player->GetRigidBody()->GetState(state); this->player->GetRigidBody()->GetState(state);

View File

@ -22,6 +22,36 @@ void Level::InitiateLevel(std::string levelPath)
} }
void Level::InitiateLevel(float radius) void Level::InitiateLevel(float radius)
{ {
float heading = Utility::Value::Radian(180.0f);
float attitude = Utility::Value::Radian(0.0f);
float bank = Utility::Value::Radian(0);
double c1 = cos(heading/2);
double s1 = sin(heading/2);
double c2 = cos(attitude/2);
double s2 = sin(attitude/2);
double c3 = cos(bank/2);
double s3 = sin(bank/2);
double c1c2 = c1*c2;
double s1s2 = s1*s2;
double w =c1c2*c3 - s1s2*s3;
double x =c1c2*s3 + s1s2*c3;
double y =s1*c2*c3 + c1*s2*s3;
double z =c1*s2*c3 - s1*c2*s3;
double angle = 2 * acos(w);
double norm = x*x+y*y+z*z;
if (norm < 0.001) { // when all euler angles are zero angle =0 so
// we can set axis to anything to avoid divide by zero
x=1;
y=z=0;
} else {
norm = sqrt(norm);
x /= norm;
y /= norm;
z /= norm;
}
int idCount = 100;
// add level sphere // add level sphere
API::SphericalBodyDescription sbDesc; API::SphericalBodyDescription sbDesc;
@ -31,6 +61,7 @@ void Level::InitiateLevel(float radius)
sbDesc.mass = 10e12f; sbDesc.mass = 10e12f;
sbDesc.frictionCoeff_Static = 0; sbDesc.frictionCoeff_Static = 0;
sbDesc.frictionCoeff_Dynamic = 0; sbDesc.frictionCoeff_Dynamic = 0;
//sbDesc.rotation =
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
ICustomBody::State state; ICustomBody::State state;
@ -51,31 +82,35 @@ void Level::InitiateLevel(float radius)
sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0); sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0);
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); ICustomBody* rigidBody_TestBox;
int nrOfBoxex = 5;
for(int i =0; i< nrOfBoxex; i ++)
{
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(20 ,320,0 + ( i*7),0);
rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[0]); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
rigidBody_TestBox->GetState(state); }
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
rigidBody_TestBox->SetState(state);
// add crystal // add crystal
API::SimpleBodyDescription sbDesc_Crystal; API::SimpleBodyDescription sbDesc_Crystal;
sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0); sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0);
sbDesc_Crystal.ignoreGravity = false; sbDesc_Crystal.ignoreGravity = false;
sbDesc_Crystal.mass = 70; sbDesc_Crystal.mass = 70;
sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0); sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0);
ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release(); ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release();
rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel); rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel);
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[1]); rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
rigidBody_Crystal->GetState(state);
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
rigidBody_Crystal->SetState(state);
// add house // add house
API::SimpleBodyDescription sbDesc_House; API::SimpleBodyDescription sbDesc_House;
@ -90,9 +125,6 @@ void Level::InitiateLevel(float radius)
rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel); rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel);
this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
rigidBody_House->SetCustomTag(this->staticObjects[0]); rigidBody_House->SetCustomTag(this->staticObjects[0]);
rigidBody_House->GetState(state);
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
rigidBody_House->SetState(state);
// add gravitation // add gravitation
@ -118,6 +150,10 @@ void Level::RespawnPlayer(Player *player)
this->teamManager.RespawnPlayerRandom(player); this->teamManager.RespawnPlayerRandom(player);
} }
int Level::getNrOfDynamicObj()
{
return this->dynamicObjects.Size();
}
Object* Level::GetObj( int ID) const Object* Level::GetObj( int ID) const
{ {
for (int i = 0; i< this->dynamicObjects.Size(); i++) for (int i = 0; i< this->dynamicObjects.Size(); i++)

View File

@ -60,6 +60,7 @@ namespace GameLogic
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
int getNrOfDynamicObj();
Object* GetObj( int ID ) const; Object* GetObj( int ID ) const;
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);

View File

@ -156,6 +156,8 @@ void Object::EndFrame()
//error //error
int i =0 ; int i =0 ;
} }
if(currPhysicsState.GetGravityNormal()!= Float3::null) if(currPhysicsState.GetGravityNormal()!= Float3::null)
{ {
Oyster::Math::Float4 axis; Oyster::Math::Float4 axis;
@ -170,6 +172,18 @@ void Object::EndFrame()
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
debug += currPhysicsState.GetGravityNormal(); debug += currPhysicsState.GetGravityNormal();
} }
Oyster::Math::Float3 pos = currPhysicsState.GetCenterPosition();
Oyster::Math::Float3 up = -currPhysicsState.GetGravityNormal();
//300, 0,0,
//1,0,0
if( pos.GetLength() < 303.5f)
{
Oyster::Math::Float moveUp = 303.5 - pos.GetLength();
up *= moveUp;
currPhysicsState.SetCenterPosition(pos + up);
}
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())

View File

@ -6,7 +6,7 @@
using namespace GameLogic; using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
const int MOVE_FORCE = 5000; const int MOVE_FORCE = 500;
Player::Player() Player::Player()
:DynamicObject() :DynamicObject()
{ {
@ -154,11 +154,6 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
{ {
int i =0 ; int i =0 ;
} }
//Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
//Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
//Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
this->lookDir = lookDir.xyz; this->lookDir = lookDir.xyz;
this->dx = lookDir.w; this->dx = lookDir.w;

View File

@ -73,6 +73,9 @@ namespace GameLogic
void BeginFrame(); void BeginFrame();
void EndFrame(); void EndFrame();
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
private: private:
void Jump(); void Jump();

View File

@ -69,25 +69,25 @@
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir> <IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName> <TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)Network\NetworkAPI\;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir> <IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName> <TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)Network\NetworkAPI\;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir> <IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName> <TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
<IncludePath>$(SolutionDir)Network\NetworkAPI\;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir> <OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir> <IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName> <TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
<IncludePath>$(SolutionDir)Network\NetworkAPI\;$(IncludePath)</IncludePath> <IncludePath>$(SolutionDir)Network\NetworkAPI\;$(SolutionDir)Misc;$(IncludePath)</IncludePath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>

View File

@ -12,6 +12,13 @@
#include <DynamicArray.h> #include <DynamicArray.h>
/** OBS!
** It seems like if a string is set in the middle of a data set,
** the reciever will crach when trying to use the protocol.
** Only tested on Protocol_LobbyStartGame.
**/
namespace GameLogic namespace GameLogic
{ {
/* /*
@ -47,34 +54,66 @@ namespace GameLogic
struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject struct Protocol_LobbyStartGame :public Oyster::Network::CustomProtocolObject
{ {
short clientID; // The unuiqe id reprsenting a specific client short clientID; // The unuiqe id reprsenting a specific client
std::string modelName;
float worldMatrix[16];
Protocol_LobbyStartGame() Protocol_LobbyStartGame()
{ {
this->protocol[0].value = protocol_Lobby_Start; int c = 0;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[c].value = protocol_Lobby_Start;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short; this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
} for (int i = 0; i <= 16; i++)
Protocol_LobbyStartGame(short _clientID)
{ {
this->protocol[0].value = protocol_Lobby_Start; this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; }
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
}
Protocol_LobbyStartGame(short _clientID, std::string name, float world[16])
{
int c = 0;
this->protocol[c].value = protocol_Lobby_Start;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
for (int i = 0; i <= 16; i++)
{
this->protocol[c++].type = Oyster::Network::NetAttributeType_Float;
}
this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
clientID = _clientID; clientID = _clientID;
modelName = name;
memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16);
} }
Protocol_LobbyStartGame(Oyster::Network::CustomNetProtocol& o) Protocol_LobbyStartGame(Oyster::Network::CustomNetProtocol& o)
{ {
clientID = o[1].value.netInt; int c = 1;
clientID = o[c++].value.netInt;
for (int i = 0; i <= 16; i++)
{
this->worldMatrix[i] = o[c++].value.netFloat;
}
modelName = o[c++].value.netCharPtr;
} }
Oyster::Network::CustomNetProtocol GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
protocol[1].value = clientID; int c = 1;
protocol[c++].value = clientID;
for (int i = 0; i <= 16; i++)
{
this->protocol[c++].value = this->worldMatrix[i];
}
protocol.Set(c++, this->modelName);
return protocol; return protocol;
} }
private: private:
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_LobbyLogin :public Oyster::Network::CustomProtocolObject struct Protocol_LobbyLogin :public Oyster::Network::CustomProtocolObject

View File

@ -234,6 +234,7 @@ namespace GameLogic
struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject
{ {
//ObjectType type; //ie player, box or whatever
int object_ID; int object_ID;
std::string name; std::string name;
float worldMatrix[16]; float worldMatrix[16];

View File

@ -142,7 +142,9 @@ namespace GameLogic
struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject
{ {
bool hasShot; bool primaryPressed;
bool secondaryPressed;
bool utilityPressed;
Protocol_PlayerShot() Protocol_PlayerShot()
{ {
@ -150,19 +152,27 @@ namespace GameLogic
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[2].type = Oyster::Network::NetAttributeType_Bool;
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
} }
Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p) Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p)
{ {
hasShot = p[1].value.netBool; primaryPressed = p[1].value.netBool;
secondaryPressed = p[2].value.netBool;
utilityPressed = p[3].value.netBool;
} }
const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val) const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val)
{ {
hasShot = val[1].value.netBool; primaryPressed = val[1].value.netBool;
secondaryPressed = val[2].value.netBool;
utilityPressed = val[3].value.netBool;
return *this; return *this;
} }
Oyster::Network::CustomNetProtocol GetProtocol() override Oyster::Network::CustomNetProtocol GetProtocol() override
{ {
this->protocol[1].value = hasShot; this->protocol[1].value = primaryPressed;
this->protocol[2].value = secondaryPressed;
this->protocol[3].value = utilityPressed;
return protocol; return protocol;
} }

View File

@ -200,9 +200,9 @@ namespace DanBias
} }
void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c )
{ {
//c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS);
c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS);
//c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS);
} }
void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c )
{ {

View File

@ -129,7 +129,7 @@ namespace DanBias
} }
else else
{ {
Protocol_LobbyStartGame p(readyList[i]->GetPlayer()->GetID()); Protocol_LobbyStartGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation());
readyList[i]->GetClient()->Send(p); readyList[i]->GetClient()->Send(p);
} }
} }

View File

@ -27,7 +27,7 @@ namespace
ICustomBody::State deuterState; deuter->GetState( deuterState ); ICustomBody::State deuterState; deuter->GetState( deuterState );
// calc from perspective of deuter. // calc from perspective of deuter.
Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed Float4 normal = (worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f )).GetNormalized(); // Init value is only borrowed
if( normal.Dot(normal) > 0.0f ) if( normal.Dot(normal) > 0.0f )
{ {
deuter->GetNormalAt( worldPointOfContact, normal ); deuter->GetNormalAt( worldPointOfContact, normal );
@ -47,9 +47,10 @@ namespace
proto->GetNormalAt( worldPointOfContact, normal ); proto->GetNormalAt( worldPointOfContact, normal );
normal = -normal; normal = -normal;
} }
normal.Normalize();
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ), Float4 protoG = Float4(protoState.GetLinearMomentum( worldPointOfContact.xyz ), 0),
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz ); deuterG = Float4(deuterState.GetLinearMomentum( worldPointOfContact.xyz ), 0);
if( normal != normal ) // debug: trap if( normal != normal ) // debug: trap
const char *breakpoint = "This should never happen"; const char *breakpoint = "This should never happen";
@ -89,6 +90,18 @@ namespace
return; return;
} }
// PLayerHAck
if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_player_collision_response )
{
Float3 linearMomentum = protoState.GetLinearMomentum();
Float3 up = -protoState.GetGravityNormal();
Float3 upForce = (linearMomentum.Dot(up) * up);
Float3 noBounceForce = linearMomentum - upForce;
protoState.SetLinearMomentum(noBounceForce);
proto->SetState(protoState);
return;
}
// calculate and store time interpolation value, for later rebound. // calculate and store time interpolation value, for later rebound.
proto->SetTimeOfContact( worldPointOfContact ); proto->SetTimeOfContact( worldPointOfContact );
@ -100,7 +113,7 @@ namespace
// calc from perspective of proto // calc from perspective of proto
normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f ); normal = (worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f )).GetNormalized();
if( normal.Dot(normal) > 0.0f ) if( normal.Dot(normal) > 0.0f )
{ {
proto->GetNormalAt( worldPointOfContact, normal ); proto->GetNormalAt( worldPointOfContact, normal );

View File

@ -242,7 +242,8 @@ namespace Oyster
{ {
SubscriptMessage_none, SubscriptMessage_none,
SubscriptMessage_kineticLoss, SubscriptMessage_kineticLoss,
SubscriptMessage_ignore_collision_response SubscriptMessage_ignore_collision_response,
SubscriptMessage_player_collision_response
}; };
typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter ); typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter );

View File

@ -300,7 +300,7 @@ namespace Utility
//To wstring //To wstring
::std::wstring & StringToWString( const ::std::string &str, ::std::wstring &wstr ) ::std::wstring & StringToWstring( const ::std::string &str, ::std::wstring &wstr )
{ {
const char *orig = str.c_str(); const char *orig = str.c_str();

View File

@ -19,11 +19,6 @@ struct CustomNetProtocol::PrivateData
~PrivateData() ~PrivateData()
{ {
for (auto i = attributes.begin(); i != attributes.end(); i++)
{
//RemoveAttribute(i);
}
attributes.Clear(); attributes.Clear();
} }
void RemoveAttribute(NetAttributeContainer* i) void RemoveAttribute(NetAttributeContainer* i)
@ -41,17 +36,12 @@ struct CustomNetProtocol::PrivateData
//Do network stuff //Do network stuff
}; };
static int ia = 0;
static int ib = 0;
CustomNetProtocol::CustomNetProtocol() CustomNetProtocol::CustomNetProtocol()
{ {
ia++;
this->privateData = new PrivateData(); this->privateData = new PrivateData();
} }
CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o) CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o)
{ {
ib ++;
this->privateData = new PrivateData(); this->privateData = new PrivateData();
this->privateData->attributes = o.privateData->attributes; this->privateData->attributes = o.privateData->attributes;
} }
@ -62,14 +52,12 @@ const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o)
delete this->privateData; delete this->privateData;
this->privateData = 0; this->privateData = 0;
} }
ib ++;
this->privateData = new PrivateData(); this->privateData = new PrivateData();
this->privateData->attributes = o.privateData->attributes; this->privateData->attributes = o.privateData->attributes;
return *this; return *this;
} }
CustomNetProtocol::~CustomNetProtocol() CustomNetProtocol::~CustomNetProtocol()
{ {
//ia--;
delete this->privateData; delete this->privateData;
this->privateData = 0; this->privateData = 0;
} }

View File

@ -297,10 +297,9 @@ void NetworkClient::Disconnect()
{ {
if(!privateData) return; if(!privateData) return;
this->privateData->sendQueue.Clear();
privateData->connection.Disconnect();
privateData->thread.Terminate(); privateData->thread.Terminate();
privateData->connection.Disconnect();
this->privateData->sendQueue.Clear();
} }