From 44ba45bcc2d3f27168e685f1ced3e80fbe12bd8a Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 29 Jan 2014 16:01:56 +0100 Subject: [PATCH] GL - added setCollisionfunc to object --- .../Game/DanBiasGame/GameClientRecieverFunc.h | 62 +++++++++---------- Code/Game/GameLogic/Game.cpp | 34 ++++++++++ Code/Game/GameLogic/Object.cpp | 10 +++ Code/Game/GameLogic/Object.h | 4 ++ 4 files changed, 76 insertions(+), 34 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index 76c4926c..6d0f9501 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -14,29 +14,11 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject // receiver function for server messages // parsing protocols and sending it to the gameState - void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override + void ParseGamePlayEvent(Oyster::Network::CustomNetProtocol& p) { - - //if( IsGameplayProtocol(p[protocol_INDEX_ID].value.netShort) ) - //ParseGameplayEvent(e.protocol, e.gameClient); - - //if( IsGeneralProtocol(p[protocol_INDEX_ID].value.netShort) ) - //ParseGeneralEvent(e.protocol, e.gameClient); - int pType = p[0].value.netInt; switch (pType) { - case protocol_General_Status: - { - GameLogic::Protocol_General_Status::States state; - state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort; - if( state == GameLogic::Protocol_General_Status::States_disconected) - { - // server disconnected - DanBiasGame::Release(); - } - } - break; case protocol_Gameplay_PlayerMovement: { Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; @@ -51,19 +33,6 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject protocolData = NULL; } break; - //case protocol_Gameplay_PlayerPosition: - // { - // Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; - // for(int i = 0; i< 3; i++) - // { - // protocolData->playerPos[i] = p[i].value.netFloat; - // } - // if(dynamic_cast(gameClientState)) - // ((Client::GameState*)gameClientState)->Protocol(protocolData); - // delete protocolData; - // protocolData = NULL; - // } - // break; case protocol_Gameplay_ObjectCreate: { @@ -115,10 +84,35 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject default: break; - } - + } + } + void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p) + { + int pType = p[0].value.netInt; + switch (pType) + { + + case protocol_General_Status: + { + GameLogic::Protocol_General_Status::States state; + state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort; + if( state == GameLogic::Protocol_General_Status::States_disconected) + { + // server disconnected + DanBiasGame::Release(); + } + } + break; + } + } + void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override + { + if( IsGameplayProtocol(p[protocol_INDEX_ID].value.netShort) ) + ParseGamePlayEvent(p); + if( IsGeneralProtocol(p[protocol_INDEX_ID].value.netShort) ) + ParseGeneralEvent(p); } }; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index ca666c2f..6bb4cdc9 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -104,6 +104,40 @@ bool Game::NewFrame() { if(this->players[i]->player) this->players[i]->player->EndFrame(); } + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->BeginFrame(); + } + + API::Instance().Update(); + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->EndFrame(); + } + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->BeginFrame(); + } + + API::Instance().Update(); + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->EndFrame(); + } + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->BeginFrame(); + } + + API::Instance().Update(); + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->EndFrame(); + } + //gameInstance.onMoveFnc(this->level); return true; } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 9ec51f1e..36f5890b 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -133,6 +133,16 @@ void Object::EndFrame() this->getState = this->rigidBody->GetState(); this->setState = this->getState; } + +void Object::setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)) +{ + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore)); +} +void Object::setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)) +{ + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); +} + Oyster::Math::Float3 Object::GetPosition() { Oyster::Physics::ICustomBody::State state; diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 24149116..67cf2086 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -37,6 +37,10 @@ namespace GameLogic void BeginFrame(); void EndFrame(); + + void setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)); + void setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)); + static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); private: OBJECT_TYPE type;