Render players with run animation

This commit is contained in:
lindaandersson 2014-02-21 12:38:25 +01:00
parent 7de0a2ba1b
commit 38717f011c
4 changed files with 95 additions and 110 deletions

View File

@ -103,7 +103,6 @@ namespace DanBias
float dt = (float)data.timer.getElapsedSeconds(); float dt = (float)data.timer.getElapsedSeconds();
data.timer.reset(); data.timer.reset();
Graphics::API::Update( dt );
data.capFrame += dt; data.capFrame += dt;
if(data.capFrame > 0.03f) if(data.capFrame > 0.03f)
@ -115,6 +114,8 @@ namespace DanBias
case Result_error: return DanBiasClientReturn_Error; case Result_error: return DanBiasClientReturn_Error;
default: break; default: break;
} }
Graphics::API::Update( data.capFrame );
if(Render() != S_OK) if(Render() != S_OK)
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
data.capFrame -= 0.03f; data.capFrame -= 0.03f;

View File

@ -33,7 +33,8 @@ struct GameState::MyData
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects; ::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> *lights; ::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> *lights;
C_Player player; //C_Player player;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Player>> players;
Camera_FPSV2 camera; Camera_FPSV2 camera;
int myId; int myId;
@ -123,37 +124,30 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
RBData.scale = scale; RBData.scale = scale;
RBData.type = RB_Type_Cube; RBData.type = RB_Type_Cube;
// !RB DEBUG // !RB DEBUG
if( isMyPlayer ) C_Player *p = new C_Player();
if( p->Init(modelData) )
{ {
if( this->privData->player.Init(modelData) ) // RB DEBUG
{ p->InitRB( RBData );
// RB DEBUG // !RB DEBUG
this->privData->player.InitRB( RBData ); // start with runing animation
// !RB DEBUG p->playAnimation( L"run_forwards", true );
(this->privData->players)[id] = p;
if( isMyPlayer )
{
this->privData->myId = id; this->privData->myId = id;
this->privData->camera.SetPosition( this->privData->player.getPos() ); this->privData->camera.SetPosition( p->getPos() );
Float3 offset = Float3( 0.0f ); Float3 offset = Float3( 0.0f );
// DEBUG position of camera so we can see the player model // DEBUG position of camera so we can see the player model
//offset.y = this->privData->player.getScale().y * 5.0f; //offset.y = p->getScale().y * 5.0f;
//offset.z = this->privData->player.getScale().z * -5.0f; //offset.z = p->getScale().z * -5.0f;
// !DEBUG // !DEBUG
this->privData->camera.SetHeadOffset( offset ); this->privData->camera.SetHeadOffset( offset );
this->privData->camera.UpdateOrientation(); this->privData->camera.UpdateOrientation();
} }
} }
else
{
C_DynamicObj *p = new C_DynamicObj();
if( p->Init(modelData) )
{
// RB DEBUG
this->privData->player.InitRB( RBData );
// !RB DEBUG
(*this->privData->dynamicObjects)[id] = p;
}
}
} }
GameClientState::ClientState GameState::Update( float deltaTime ) GameClientState::ClientState GameState::Update( float deltaTime )
@ -187,7 +181,17 @@ bool GameState::Render()
Oyster::Graphics::API::NewFrame(); Oyster::Graphics::API::NewFrame();
// for debugging to be replaced with render weapon // for debugging to be replaced with render weapon
this->privData->player.Render(); auto playerObject = this->privData->players.begin();
for( ; playerObject != this->privData->players.end(); ++playerObject )
{
if(playerObject->second)
{
if( this->privData->myId != playerObject->second->GetId() )
{
playerObject->second->Render();
}
}
}
auto staticObject = this->privData->staticObjects->begin(); auto staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
@ -211,11 +215,18 @@ bool GameState::Render()
{ {
Oyster::Graphics::API::StartRenderWireFrame(); Oyster::Graphics::API::StartRenderWireFrame();
Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); playerObject = this->privData->players.begin();
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); for( ; playerObject != this->privData->players.end(); ++playerObject )
Oyster::Math3D::Float4x4 world = translation * scale; {
Oyster::Graphics::API::RenderDebugCube( world ); if( playerObject->second->getBRtype() == RB_Type_Cube)
Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); {
Oyster::Graphics::API::RenderDebugCube( playerObject->second->getRBWorld());
}
if( playerObject->second->getBRtype() == RB_Type_Sphere)
{
Oyster::Graphics::API::RenderDebugSphere( playerObject->second->getRBWorld());
}
}
staticObject = this->privData->staticObjects->begin(); staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
@ -276,6 +287,12 @@ bool GameState::Release()
Graphics::API::Option o = Graphics::API::GetOption(); Graphics::API::Option o = Graphics::API::GetOption();
if( privData ) if( privData )
{ {
auto playerObject = this->privData->players.begin();
for( ; playerObject != this->privData->players.end(); ++playerObject )
{
playerObject->second = nullptr;
}
auto staticObject = this->privData->staticObjects->begin(); auto staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
{ {
@ -381,6 +398,7 @@ void GameState::ReadKeyInput()
this->key_showStats = false; this->key_showStats = false;
} }
} }
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
{ {
if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend )
@ -459,42 +477,29 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
Protocol_ObjectPositionRotation decoded(data); Protocol_ObjectPositionRotation decoded(data);
Float3 position = decoded.position; Float3 position = decoded.position;
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
C_Object *object;
// if is this player. Remember to change camera object = (this->privData->players)[decoded.object_ID];
if( this->privData->myId == decoded.object_ID ) if( !object)
{ {
if( !Within(position.Dot(position), 2500.0f, 90000.0f) ) // if it is not a player
{ // HACK: bug trap object = (*this->privData->dynamicObjects)[decoded.object_ID];
const char *breakPoint = "Something is wrong.";
position = Float3( 0.0f, 160.0f, 0.0f );
}
this->privData->camera.SetPosition( position );
this->privData->camera.SetRotation( rotation );
this->privData->player.setPos( position );
this->privData->player.setRot( rotation );
this->privData->player.updateWorld();
// RB DEBUG
this->privData->player.setRBPos ( position );
this->privData->player.setRBRot ( rotation );
this->privData->player.updateRBWorld();
// !RB DEBUG
} }
else
{
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID];
if( object ) if( object )
{
if( this->privData->myId == decoded.object_ID )
{ {
object->setPos( position ); this->privData->camera.SetPosition( position );
object->setRot( rotation ); this->privData->camera.SetRotation( rotation );
object->updateWorld();
// RB DEBUG
object->setRBPos ( position );
object->setRBRot ( rotation );
object->updateRBWorld();
// !RB DEBUG
} }
object->setPos( position );
object->setRot( rotation );
object->updateWorld();
// RB DEBUG
object->setRBPos ( position );
object->setRBRot ( rotation );
object->updateRBWorld();
// !RB DEBUG
} }
} }
return GameClientState::event_processed; return GameClientState::event_processed;
@ -534,7 +539,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
RBData.rotation = ArrayToQuaternion( decoded.position ); RBData.rotation = ArrayToQuaternion( decoded.position );
RBData.scale = Float3( decoded.scale ); RBData.scale = Float3( decoded.scale );
this->privData->player.InitRB( RBData ); object->InitRB( RBData );
// !RB DEBUG // !RB DEBUG
(*this->privData->dynamicObjects)[decoded.object_ID] = object; (*this->privData->dynamicObjects)[decoded.object_ID] = object;
@ -555,30 +560,26 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
{ {
Protocol_ObjectRespawn decoded(data); Protocol_ObjectRespawn decoded(data);
if( this->privData->myId == decoded.objectID ) C_Object *object;
object = (this->privData->players)[decoded.objectID];
if( !object)
{ {
// move player. Remember to change camera // if it is not a player
this->privData->camera.SetPosition( decoded.position ); object = (*this->privData->dynamicObjects)[decoded.objectID];
this->privData->player.setPos( decoded.position );
this->privData->player.updateWorld();
// RB DEBUG
this->privData->player.setRBPos ( decoded.position );
this->privData->player.updateRBWorld();
// !RB DEBUG
} }
else
{
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.objectID];
if( object ) if( object )
{
if( this->privData->myId == decoded.objectID )
{ {
object->setPos( decoded.position ); this->privData->camera.SetPosition( decoded.position );
object->updateWorld();
// RB DEBUG
object->setRBPos ( decoded.position );
object->updateRBWorld();
// !RB DEBUG
} }
object->setPos( decoded.position );
object->updateWorld();
// RB DEBUG
object->setRBPos ( decoded.position );
object->updateRBWorld();
// !RB DEBUG
} }
this->currGameUI = this->gameUI; this->currGameUI = this->gameUI;
} }

View File

@ -19,7 +19,7 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointer<Oyster::Network::Net
this->client = nwClient; this->client = nwClient;
this->player = 0; this->player = 0;
isReady = false; isReady = false;
this->character = L"crate_colonists.dan"; this->character = L"char_orca.dan";
this->alias = L"Unknown"; this->alias = L"Unknown";
this->secondsSinceLastResponse = 0.0f; this->secondsSinceLastResponse = 0.0f;
} }
@ -29,7 +29,7 @@ GameClient::~GameClient()
this->player->Inactivate(); this->player->Inactivate();
this->isReady = false; this->isReady = false;
this->character = L"crate_colonists.dan"; this->character = L"char_orca.dan";
this->alias = L"Unknown"; this->alias = L"Unknown";
this->secondsSinceLastResponse = 0.0f; this->secondsSinceLastResponse = 0.0f;
this->client = 0; this->client = 0;

View File

@ -62,31 +62,24 @@ using namespace DanBias;
{ {
case NetworkClient::ClientEventArgs::EventType_Disconnect: case NetworkClient::ClientEventArgs::EventType_Disconnect:
{ {
printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); //Send disconnect message to all the other players so the player can be removed from the client.
Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID()); Protocol_ObjectDisconnectPlayer dp(cl->GetClient()->GetID());
for (unsigned int i = 0; i < this->gClients.Size(); i++) for(int i = 0; i < this->gClients.Size(); i++)
{ {
if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot); if(this->gClients[i] && this->gClients[i] != cl)
{
this->gClients[i]->GetClient()->Send(dp);
}
} }
printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str());
this->gClients[temp]->Invalidate(); this->gClients[temp]->Invalidate();
} }
break; break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve:
break; break;
case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend:
{
if(this->gClients[temp]->IncrementFailedProtocol() >= 5/*client->threshold*/) if(this->gClients[temp]->IncrementFailedProtocol() >= 5/*client->threshold*/)
{
printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str());
Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID());
for (unsigned int i = 0; i < this->gClients.Size(); i++)
{
if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot);
}
this->gClients[temp]->Invalidate(); this->gClients[temp]->Invalidate();
}
}
break; break;
case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved:
this->ParseProtocol(e.args.data.protocol, cl); this->ParseProtocol(e.args.data.protocol, cl);
@ -150,9 +143,6 @@ using namespace DanBias;
Oyster::Math::Float3 temp = movedObject->GetPosition(); Oyster::Math::Float3 temp = movedObject->GetPosition();
if(temp.x < -300)
id = 0;
GameSession::gameSession->Send(p.GetProtocol()); GameSession::gameSession->Send(p.GetProtocol());
//} //}
} }
@ -231,7 +221,7 @@ using namespace DanBias;
void GameSession::Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn& p, DanBias::GameClient* c )
{ {
c->GetPlayer()->TurnLeft( p.deltaRadian ); c->GetPlayer()->TurnLeft( p.deltaRadian );
c->GetPlayer()->SetLookDir(p.lookdir); c->GetPlayer()->SetLookDir( p.lookdir ) ;
} }
void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c )
{ {
@ -275,17 +265,10 @@ using namespace DanBias;
switch (p.status) switch (p.status)
{ {
case GameLogic::Protocol_General_Status::States_disconected: case GameLogic::Protocol_General_Status::States_disconected:
{
printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID());
//TODO: Tell other clients
Protocol_ObjectDisconnectPlayer prot(c->GetPlayer()->GetID()); //Protocol_
for (unsigned int i = 0; i < this->gClients.Size(); i++)
{
if( this->gClients[i] && c->GetClient()->GetID() != this->gClients[i]->GetClient()->GetID() ) this->gClients[i]->GetClient()->Send(prot);
}
c->Invalidate();
this->Detach(c->GetClient()->GetID()); this->Detach(c->GetClient()->GetID());
}
break; break;
case GameLogic::Protocol_General_Status::States_idle: case GameLogic::Protocol_General_Status::States_idle: