Danbias/Code/Game/GameClient/GameClientState/GameState.cpp

775 lines
20 KiB
C++
Raw Normal View History

2013-12-18 12:18:01 +01:00
#include "GameState.h"
#include "DllInterfaces/GFXAPI.h"
#include <Protocols.h>
2013-12-19 10:22:32 +01:00
#include "NetworkClient.h"
#include "Camera_FPSV2.h"
2014-01-30 14:17:50 +01:00
#include <GameServerAPI.h>
2014-02-19 10:59:23 +01:00
#include "C_Light.h"
2014-02-17 14:33:11 +01:00
#include "C_obj/C_Player.h"
#include "C_obj/C_DynamicObj.h"
#include "C_obj/C_StaticObj.h"
2014-02-17 16:16:27 +01:00
#include "Utilities.h"
2014-02-20 16:35:49 +01:00
#include "GamingUI.h"
#include "RespawnUI.h"
#include "StatsUI.h"
2014-02-25 16:08:45 +01:00
#include <ObjectDefines.h>
2014-02-17 14:33:11 +01:00
2014-02-12 16:31:15 +01:00
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::Oyster::Math3D;
2014-02-17 14:33:11 +01:00
using namespace ::GameLogic;
using namespace ::Utility::DynamicMemory;
2014-02-17 16:16:27 +01:00
using namespace ::Utility::String;
2014-02-18 10:28:46 +01:00
using namespace ::Utility::Value;
2014-02-12 09:02:44 +01:00
2014-02-12 16:31:15 +01:00
struct GameState::MyData
{
2014-02-12 16:31:15 +01:00
MyData(){}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
2014-02-17 11:27:43 +01:00
InputClass *input;
2014-02-17 12:02:18 +01:00
2014-02-17 14:33:11 +01:00
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> *staticObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
2014-02-19 10:59:23 +01:00
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> *lights;
2014-02-17 14:33:11 +01:00
2014-02-21 12:38:25 +01:00
//C_Player player;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Player>> players;
Camera_FPSV2 camera;
2014-02-17 14:33:11 +01:00
int myId;
2014-02-17 12:02:18 +01:00
2014-02-12 09:49:08 +01:00
} privData;
2014-02-17 16:16:27 +01:00
inline Quaternion ArrayToQuaternion( const float source[4] )
{
return Quaternion( Float3(source[0], source[1], source[2]), source[3] );
}
2014-02-17 11:27:43 +01:00
GameState::GameState()
{
2014-02-17 14:33:11 +01:00
this->privData = nullptr;
}
2014-02-17 11:27:43 +01:00
GameState::~GameState()
{
2014-02-12 16:31:15 +01:00
if( this->privData )
this->Release();
}
2014-02-12 16:31:15 +01:00
2014-02-17 11:27:43 +01:00
bool GameState::Init( SharedStateContent &shared )
{
2014-02-17 14:33:11 +01:00
// we may assume that shared.network is properly connected
// and there is content in shared.dynamicObjects and shared.staticObjects
this->privData = new MyData();
2014-02-12 16:31:15 +01:00
this->privData->nextState = GameClientState::ClientState_Same;
2014-02-17 11:27:43 +01:00
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
2014-02-17 14:33:11 +01:00
this->privData->staticObjects = &shared.staticObjects;
this->privData->dynamicObjects = &shared.dynamicObjects;
2014-02-19 10:59:23 +01:00
this->privData->lights = &shared.lights;
2014-02-18 10:28:46 +01:00
Graphics::API::Option gfxOp = Graphics::API::GetOption();
Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y;
2014-02-19 10:59:23 +01:00
this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f );
2014-02-18 10:28:46 +01:00
Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() );
2014-02-20 15:15:54 +01:00
gfxOp.AmbientValue = 0.5f;
2014-02-21 11:49:24 +01:00
gfxOp.GlobalGlowTint = Math::Float3(1,1,1);
2014-02-20 15:15:54 +01:00
gfxOp.GlobalTint = Math::Float3(1,1,1);
2014-02-19 15:57:52 +01:00
Graphics::API::SetOptions(gfxOp);
2014-02-18 10:28:46 +01:00
//tell server ready
2014-02-18 12:59:51 +01:00
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
2014-02-18 10:28:46 +01:00
2014-02-18 15:54:09 +01:00
// DEGUG KEYS
2014-02-20 16:51:14 +01:00
this->key_Reload_Shaders = false;
this->key_Wireframe_Toggle = false;
this->renderWhireframe = false;
2014-02-18 15:54:09 +01:00
// !DEGUG KEYS
2014-02-19 10:59:23 +01:00
auto light = this->privData->lights->begin();
for( ; light != this->privData->lights->end(); ++light )
{
light->second->Render();
}
2014-02-20 16:35:49 +01:00
// create UI states
this->gameUI = new GamingUI(this->privData->input, this->privData->nwClient, &this->privData->camera);
this->respawnUI = new RespawnUI(this->privData->nwClient, 20);
this->statsUI = new StatsUI();
2014-02-20 16:35:49 +01:00
this->currGameUI = gameUI;
((GamingUI*)gameUI)->Init();
((RespawnUI*)respawnUI)->Init();
((StatsUI*)statsUI)->Init();
2014-02-19 15:57:52 +01:00
return true;
}
2014-02-12 16:31:15 +01:00
2014-02-17 16:16:27 +01:00
void GameState::InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3], bool isMyPlayer )
{
ModelInitData modelData;
2014-02-17 16:16:27 +01:00
modelData.visible = true;
modelData.position = position;
modelData.rotation = ArrayToQuaternion( rotation );
modelData.scale = scale;
modelData.id = id;
StringToWstring(modelName,modelData.modelPath);
2014-02-17 16:16:27 +01:00
// RB DEBUG
RBInitData RBData;
RBData.position = position;
RBData.rotation = ArrayToQuaternion( rotation );
2014-02-19 13:41:05 +01:00
RBData.scale = scale;
RBData.type = RB_Type_Cube;
2014-02-18 15:07:40 +01:00
// !RB DEBUG
2014-02-21 12:38:25 +01:00
C_Player *p = new C_Player();
if( p->Init(modelData) )
2014-02-17 16:16:27 +01:00
{
2014-02-21 12:38:25 +01:00
// RB DEBUG
p->InitRB( RBData );
// !RB DEBUG
// start with runing animation
2014-02-25 16:08:45 +01:00
p->playAnimation( L"idle", true );
2014-02-21 12:38:25 +01:00
(this->privData->players)[id] = p;
if( isMyPlayer )
2014-02-17 16:16:27 +01:00
{
this->privData->myId = id;
2014-02-21 12:38:25 +01:00
this->privData->camera.SetPosition( p->getPos() );
2014-02-18 10:28:46 +01:00
Float3 offset = Float3( 0.0f );
// DEBUG position of camera so we can see the player model
offset.y = p->getScale().y * 5.0f;
offset.z = p->getScale().z * -5.0f;
// !DEBUG
2014-02-18 10:28:46 +01:00
this->privData->camera.SetHeadOffset( offset );
2014-02-17 16:16:27 +01:00
this->privData->camera.UpdateOrientation();
}
}
2014-01-31 16:33:16 +01:00
}
2014-02-12 16:31:15 +01:00
2014-02-17 11:27:43 +01:00
GameClientState::ClientState GameState::Update( float deltaTime )
{
2014-02-20 16:35:49 +01:00
GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime );
switch (UIstate)
{
case DanBias::Client::GameStateUI::UIState_same:
break;
case DanBias::Client::GameStateUI::UIState_gaming:
break;
case DanBias::Client::GameStateUI::UIState_main_menu:
//this->privData->nextState =
break;
case DanBias::Client::GameStateUI::UIState_shut_down:
this->privData->nextState = ClientState_Quit;
break;
default:
break;
}
2014-02-20 16:51:14 +01:00
// DEBUG keybindings
ReadKeyInput();
2014-02-12 16:31:15 +01:00
return this->privData->nextState;
}
2014-02-12 16:31:15 +01:00
bool GameState::Render()
{
2014-02-17 14:33:11 +01:00
Oyster::Graphics::API::SetView( this->privData->camera.GetViewMatrix() );
Oyster::Graphics::API::NewFrame();
2014-02-17 14:33:11 +01:00
// for debugging to be replaced with render weapon
2014-02-21 12:38:25 +01:00
auto playerObject = this->privData->players.begin();
for( ; playerObject != this->privData->players.end(); ++playerObject )
{
if(playerObject->second)
{
//if( this->privData->myId != playerObject->second->GetId() )
2014-02-21 12:38:25 +01:00
{
playerObject->second->Render();
}
}
}
2014-02-17 14:33:11 +01:00
auto staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
{
2014-02-17 14:33:11 +01:00
staticObject->second->Render();
}
2014-02-17 14:33:11 +01:00
auto dynamicObject = this->privData->dynamicObjects->begin();
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
{
2014-02-18 15:09:01 +01:00
if( dynamicObject->second )
2014-02-20 12:07:53 +01:00
{
2014-02-18 15:09:01 +01:00
dynamicObject->second->Render();
2014-02-20 15:47:11 +01:00
2014-02-20 12:07:53 +01:00
}
}
#ifdef _DEBUG
//RB DEBUG render wire frame
2014-02-20 16:51:14 +01:00
if(this->renderWhireframe)
{
Oyster::Graphics::API::StartRenderWireFrame();
2014-02-21 12:38:25 +01:00
playerObject = this->privData->players.begin();
for( ; playerObject != this->privData->players.end(); ++playerObject )
{
if(playerObject->second)
2014-02-21 12:38:25 +01:00
{
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());
}
2014-02-21 12:38:25 +01:00
}
}
staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
{
if( staticObject->second->getBRtype() == RB_Type_Cube)
{
Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld());
}
if( staticObject->second->getBRtype() == RB_Type_Sphere)
{
Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld());
}
}
dynamicObject = this->privData->dynamicObjects->begin();
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
{
if( dynamicObject->second )
{
if( dynamicObject->second->getBRtype() == RB_Type_Cube)
{
Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld());
}
if( dynamicObject->second->getBRtype() == RB_Type_Sphere)
{
Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld());
}
}
}
}
//!RB DEBUG
#endif
2014-02-18 15:07:40 +01:00
Oyster::Graphics::API::StartGuiRender();
// render gui elemnts
2014-02-20 16:35:49 +01:00
if(currGameUI->HaveGUIRender())
currGameUI->RenderGUI();
if(renderStats)
{
if(statsUI->HaveGUIRender())
statsUI->RenderGUI();
}
Oyster::Graphics::API::StartTextRender();
2014-02-20 16:35:49 +01:00
if(currGameUI->HaveTextRender())
currGameUI->RenderText();
if(renderStats)
{
if(statsUI->HaveTextRender())
statsUI->RenderText();
}
Oyster::Graphics::API::EndFrame();
return true;
}
2014-02-12 16:31:15 +01:00
bool GameState::Release()
{
2014-02-19 15:57:52 +01:00
Graphics::API::Option o = Graphics::API::GetOption();
2014-02-17 14:33:11 +01:00
if( privData )
{
2014-02-21 12:38:25 +01:00
auto playerObject = this->privData->players.begin();
for( ; playerObject != this->privData->players.end(); ++playerObject )
{
playerObject->second = nullptr;
}
2014-02-17 14:33:11 +01:00
auto staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
{
staticObject->second = nullptr;
}
2014-02-17 14:33:11 +01:00
auto dynamicObject = this->privData->dynamicObjects->begin();
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
{
dynamicObject->second = nullptr;
}
2014-02-19 10:59:23 +01:00
auto light = this->privData->lights->begin();
for( ; light != this->privData->lights->end(); ++light )
{
light->second->Render();
}
2014-02-17 14:33:11 +01:00
this->privData->staticObjects->clear();
this->privData->dynamicObjects->clear();
2014-02-19 10:59:23 +01:00
this->privData->lights->clear();
2014-02-17 14:33:11 +01:00
privData = NULL;
}
2014-02-12 16:31:15 +01:00
2014-02-20 16:35:49 +01:00
if(respawnUI)
2014-01-27 13:56:31 +01:00
{
2014-02-20 16:35:49 +01:00
respawnUI->Release();
delete respawnUI;
respawnUI = NULL;
2014-01-27 13:56:31 +01:00
}
2014-02-20 16:35:49 +01:00
if(gameUI)
{
2014-02-20 16:35:49 +01:00
gameUI->Release();
delete gameUI;
gameUI = NULL;
2014-01-30 09:07:56 +01:00
}
if(statsUI)
{
statsUI->Release();
delete statsUI;
statsUI = NULL;
}
2014-02-20 16:35:49 +01:00
currGameUI = NULL;
2014-02-18 15:54:09 +01:00
2014-02-20 16:35:49 +01:00
return true;
}
2014-02-18 15:54:09 +01:00
2014-02-20 16:35:49 +01:00
void GameState::ChangeState( ClientState next )
{
this->privData->nextState = next;
2013-12-16 11:08:10 +01:00
}
2014-02-20 16:51:14 +01:00
void GameState::ReadKeyInput()
{
// DEGUG KEYS
// Reload shaders
if( this->privData->input->IsKeyPressed(DIK_R) )
{
if( !this->key_Reload_Shaders )
{
#ifdef _DEBUG
Oyster::Graphics::API::ReloadShaders();
#endif
this->key_Reload_Shaders = true;
}
}
else
this->key_Reload_Shaders = false;
2013-12-16 11:08:10 +01:00
2014-02-20 16:51:14 +01:00
// toggle wire frame render
if( this->privData->input->IsKeyPressed(DIK_T) )
{
if( !this->key_Wireframe_Toggle )
{
this->renderWhireframe = !this->renderWhireframe;
this->key_Wireframe_Toggle = true;
// DEBUG set you as dead when render wireframe
this->currGameUI = respawnUI;
// !DEBUG
2014-02-20 16:51:14 +01:00
}
}
else
{
2014-02-20 16:51:14 +01:00
this->key_Wireframe_Toggle = false;
// DEBUG set you as dead when render wireframe
this->currGameUI = gameUI;
// !DEBUG
}
// toggle wire frame render
if( this->privData->input->IsKeyPressed(DIK_TAB) )
{
if( !this->key_showStats )
{
this->renderStats = true;
this->key_showStats = true;
}
}
else
{
this->renderStats = false;
this->key_showStats = false;
}
2014-02-20 16:51:14 +01:00
}
2014-02-21 12:38:25 +01:00
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
2013-12-16 11:08:10 +01:00
{
if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend )
2014-02-18 16:44:38 +01:00
{ // TODO: Reconnect
const char *breakpoint = "temp trap";
this->privData->nwClient->Disconnect();
this->ChangeState( GameClientState::ClientState_Main );
}
// fetching the id data.
short ID = message.args.data.protocol[0].value.netShort;
2014-02-18 16:44:38 +01:00
if( ProtocolIsGameplay(ID) )
2013-12-19 11:58:42 +01:00
{
CustomNetProtocol data = message.args.data.protocol;
switch(ID)
2014-01-16 12:26:14 +01:00
{
2014-02-25 16:08:45 +01:00
case protocol_Gameplay_ObjectPickup:
{
Protocol_ObjectPickup decoded(data);
decoded.object_ID;
C_Object *object;
object = (this->privData->players)[decoded.object_ID];
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.object_ID];
}
if( object )
{
if( this->privData->myId == decoded.object_ID )
{
// I picked up the pickUp!
}
if (decoded.pickup_ID == GameLogic::PickupType::PickupType_Health)
{
// object->PickupHealth();
}
else if (decoded.pickup_ID == GameLogic::PickupType::PickupType_SpeedBoost)
{
// object->PickupSpeed();
}
}
decoded.pickup_ID;
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectDamage:
{
Protocol_ObjectDamage decoded(data);
2014-02-25 16:08:45 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
2014-02-25 16:08:45 +01:00
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
2014-02-25 16:08:45 +01:00
}
if( object )
{
if( this->privData->myId == decoded.objectID )
{
// show that you took dmg
2014-02-25 16:08:45 +01:00
if(currGameUI == gameUI)
{
// set given players HP
2014-02-25 16:08:45 +01:00
((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost));
}
}
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectHealthStatus:
{
// don't know if needed
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectPosition:
{
2014-02-17 14:33:11 +01:00
Protocol_ObjectPosition decoded(data);
2014-02-12 09:02:44 +01:00
2014-02-25 16:08:45 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
2014-02-25 16:08:45 +01:00
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
2014-02-25 16:08:45 +01:00
}
2014-02-12 09:02:44 +01:00
2014-02-25 16:08:45 +01:00
if( object )
{
if( this->privData->myId == decoded.objectID )
2014-02-25 16:08:45 +01:00
{
this->privData->camera.SetPosition( decoded.position );
}
object->setPos( decoded.position );
// RB DEBUG
object->setRBPos ( decoded.position );
// !RB DEBUG
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectScale:
2014-02-12 09:02:44 +01:00
{
2014-02-17 14:33:11 +01:00
Protocol_ObjectScale decoded(data);
2014-02-25 16:08:45 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
2014-02-25 16:08:45 +01:00
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
2014-02-25 16:08:45 +01:00
}
if( object )
{
object->setScale( decoded.scale );
// RB DEBUG
object->setRBScale ( decoded.scale );
// !RB DEBUG
}
2014-02-12 09:02:44 +01:00
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectRotation:
2014-02-12 09:02:44 +01:00
{
2014-02-17 14:33:11 +01:00
Protocol_ObjectRotation decoded(data);
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
2014-02-25 16:08:45 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
2014-02-25 16:08:45 +01:00
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
2014-02-25 16:08:45 +01:00
}
2014-02-25 16:08:45 +01:00
if( object )
{
if( this->privData->myId == decoded.objectID )
2014-02-25 16:08:45 +01:00
{
this->privData->camera.SetRotation( rotation );
}
2014-02-25 16:08:45 +01:00
object->setRot( rotation );
// RB DEBUG
object->setRBRot( rotation );
// !RB DEBUG
}
2014-02-12 09:02:44 +01:00
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectPositionRotation:
{
2014-02-17 14:33:11 +01:00
Protocol_ObjectPositionRotation decoded(data);
Float3 position = decoded.position;
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
2014-02-21 12:38:25 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
2014-02-21 12:38:25 +01:00
if( !object)
{
2014-02-21 12:38:25 +01:00
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
}
2014-02-20 15:47:11 +01:00
2014-02-21 12:38:25 +01:00
if( object )
{
if( this->privData->myId == decoded.objectID )
2014-02-20 15:47:11 +01:00
{
2014-02-21 12:38:25 +01:00
this->privData->camera.SetPosition( position );
this->privData->camera.SetRotation( rotation );
2014-02-20 15:47:11 +01:00
}
2014-02-21 12:38:25 +01:00
object->setPos( position );
object->setRot( rotation );
object->updateWorld();
// RB DEBUG
object->setRBPos ( position );
object->setRBRot ( rotation );
object->updateRBWorld();
// !RB DEBUG
2014-02-18 15:09:01 +01:00
}
}
return GameClientState::event_processed;
2014-02-25 16:08:45 +01:00
case protocol_Gameplay_ObjectEnabled:
{
Protocol_ObjectEnable decoded(data);
C_Object *object;
object = (this->privData->players)[decoded.objectID];
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
}
if( object )
{
object->SetVisible(true);
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectDisabled:
2014-02-12 09:02:44 +01:00
{
2014-02-17 14:33:11 +01:00
Protocol_ObjectDisable decoded(data);
2014-02-25 16:08:45 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
if( !object)
{
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
}
2013-12-18 12:18:01 +01:00
2014-02-25 16:08:45 +01:00
if( object )
{
2014-02-25 16:08:45 +01:00
object->SetVisible(false);
}
2014-02-25 16:08:45 +01:00
/*auto object = this->privData->dynamicObjects->find( decoded.objectID );
if( object != this->privData->dynamicObjects->end() )
{
object->second = nullptr;
this->privData->dynamicObjects->erase( object );
}*/
2014-02-12 09:02:44 +01:00
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectCreate:
{
2014-02-17 14:33:11 +01:00
Protocol_ObjectCreate decoded(data);
C_DynamicObj* object = new C_DynamicObj();
2013-12-17 13:39:10 +01:00
ModelInitData modelData;
{
modelData.position = Float3( decoded.position );
2014-02-18 15:54:09 +01:00
modelData.rotation = Quaternion( Float3(decoded.position), decoded.rotationQ[3] );
modelData.scale = Float3( decoded.scale );
modelData.visible = true;
modelData.id = decoded.objectID;
2013-12-18 15:28:47 +01:00
::Utility::String::StringToWstring( decoded.name, modelData.modelPath );
}
object->Init(modelData);
2014-02-18 15:54:09 +01:00
// RB DEBUG
// Is just using the model position since the rigid body data should never be sent to the client
RBInitData RBData;
RBData.position = decoded.position;
RBData.rotation = ArrayToQuaternion( decoded.position );
RBData.scale = Float3( decoded.scale );
2014-02-21 12:38:25 +01:00
object->InitRB( RBData );
2014-02-18 15:54:09 +01:00
// !RB DEBUG
(*this->privData->dynamicObjects)[decoded.objectID] = object;
}
return GameClientState::event_processed;
2014-02-17 16:16:27 +01:00
case protocol_Gameplay_ObjectCreatePlayer:
{
Protocol_ObjectCreatePlayer decoded(data);
this->InitiatePlayer( decoded.objectID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner );
2014-02-17 16:16:27 +01:00
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectRespawn:
{
Protocol_ObjectRespawn decoded(data);
2014-02-21 12:38:25 +01:00
C_Object *object;
object = (this->privData->players)[decoded.objectID];
if( !object)
2014-02-21 11:23:38 +01:00
{
2014-02-21 12:38:25 +01:00
// if it is not a player
object = (*this->privData->dynamicObjects)[decoded.objectID];
2014-02-21 11:23:38 +01:00
}
2014-02-21 12:38:25 +01:00
if( object )
{
if( this->privData->myId == decoded.objectID )
2014-02-21 11:23:38 +01:00
{
2014-02-21 12:38:25 +01:00
this->privData->camera.SetPosition( decoded.position );
2014-02-21 11:23:38 +01:00
}
2014-02-21 12:38:25 +01:00
object->setPos( decoded.position );
object->updateWorld();
// RB DEBUG
object->setRBPos ( decoded.position );
object->updateRBWorld();
// !RB DEBUG
2014-02-21 11:23:38 +01:00
}
this->currGameUI = this->gameUI;
}
2014-02-20 16:35:49 +01:00
return GameClientState::event_processed;
case protocol_Gameplay_ObjectDie:
{
Protocol_ObjectDie decoded(data);
// if is this player. Remember to change camera
int killerID = decoded.killerID;
int victimID = decoded.objectID;
if( this->privData->myId == decoded.objectID )
{
this->currGameUI = this->respawnUI;
// set countdown
((RespawnUI*)currGameUI)->SetCountdown( decoded.seconds );
}
}
return GameClientState::event_processed;
2014-02-20 15:47:11 +01:00
case protocol_Gameplay_ObjectDisconnectPlayer:
{
2014-02-21 09:34:09 +01:00
//Remove the disconnected player
2014-02-20 15:47:11 +01:00
Protocol_ObjectDisconnectPlayer decoded(data);
auto object = this->privData->dynamicObjects->find( decoded.objectID );
if( object != this->privData->dynamicObjects->end() )
{
object->second = nullptr;
this->privData->dynamicObjects->erase( object );
}
}
2014-02-20 16:35:49 +01:00
return GameClientState::event_processed;
2014-02-25 16:08:45 +01:00
case protocol_Gameplay_ObjectAction:
{
Protocol_ObjectAction decoded(data);
C_Player *player;
player = (this->privData->players)[decoded.objectID];
if( player )
{
if( this->privData->myId == decoded.objectID )
{
// my player animation
//}
//else
//{
// HACK for now animate my char
switch (decoded.animationID)
{
case GameLogic::PlayerAction::PlayerAction_Walk:
player->playAnimation(L"run_forwards", true);
break;
case GameLogic::PlayerAction::PlayerAction_Jump:
player->playAnimation(L"movement", true);
break;
case GameLogic::PlayerAction::PlayerAction_Idle:
player->playAnimation(L"idle", true);
break;
default:
break;
}
}
}
}
return GameClientState::event_processed;
default: break;
}
}
else if( ProtocolIsGeneral(ID) )
{
switch( ID )
{
case protocol_General_Status: break; /** @todo TODO: implement */
case protocol_General_Text: break; /** @todo TODO: implement */
default: break;
}
2013-12-16 11:08:10 +01:00
}
return message;
2013-12-13 12:02:49 +01:00
}