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

View File

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

View File

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