GL - added setCollisionfunc to object

This commit is contained in:
lindaandersson 2014-01-29 16:01:56 +01:00
parent 446bdd412b
commit 44ba45bcc2
4 changed files with 76 additions and 34 deletions

View File

@ -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<Client::GameState*>(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);
}
};
}

View File

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

View File

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

View File

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