2013-12-18 12:18:01 +01:00
|
|
|
|
#include "GameState.h"
|
2013-12-06 10:38:43 +01:00
|
|
|
|
#include "DllInterfaces/GFXAPI.h"
|
2014-01-14 09:25:22 +01:00
|
|
|
|
#include <Protocols.h>
|
2013-12-19 10:22:32 +01:00
|
|
|
|
#include "NetworkClient.h"
|
2014-02-18 17:42:00 +01:00
|
|
|
|
#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-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
|
2013-12-09 09:23:39 +01:00
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
bool key_forward;
|
|
|
|
|
bool key_backward;
|
|
|
|
|
bool key_strafeRight;
|
|
|
|
|
bool key_strafeLeft;
|
|
|
|
|
bool key_Shoot;
|
|
|
|
|
bool key_Jump;
|
|
|
|
|
|
2014-02-18 15:54:09 +01:00
|
|
|
|
// DEGUG KEYS
|
2014-02-18 12:02:48 +01:00
|
|
|
|
bool key_Reload_Shaders;
|
2014-02-18 15:54:09 +01:00
|
|
|
|
bool key_Wireframe_Toggle;
|
|
|
|
|
bool renderWhireframe;
|
|
|
|
|
// !DEGUG KEYS
|
2014-02-18 12:02:48 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
C_Player player;
|
2014-02-18 17:42:00 +01:00
|
|
|
|
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;
|
2013-12-09 09:23:39 +01:00
|
|
|
|
|
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()
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData = nullptr;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 11:27:43 +01:00
|
|
|
|
GameState::~GameState()
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2014-02-12 16:31:15 +01:00
|
|
|
|
if( this->privData )
|
|
|
|
|
this->Release();
|
2013-12-06 10:38:43 +01:00
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2014-02-17 11:27:43 +01:00
|
|
|
|
bool GameState::Init( SharedStateContent &shared )
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
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();
|
|
|
|
|
|
|
|
|
|
this->privData->key_forward = false;
|
|
|
|
|
this->privData->key_backward = false;
|
|
|
|
|
this->privData->key_strafeRight = false;
|
|
|
|
|
this->privData->key_strafeLeft = false;
|
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-09 18:58:14 +01:00
|
|
|
|
|
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 09:00:02 +01:00
|
|
|
|
gfxOp.AmbientValue = 1.0f;
|
2014-02-19 15:57:52 +01:00
|
|
|
|
Graphics::API::SetOptions(gfxOp);
|
2014-02-04 16:07:10 +01:00
|
|
|
|
|
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
|
|
|
|
|
this->privData->key_Reload_Shaders = false;
|
|
|
|
|
this->privData->key_Wireframe_Toggle = false;
|
|
|
|
|
this->privData->renderWhireframe = false;
|
|
|
|
|
// !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-19 11:31:05 +01:00
|
|
|
|
|
2014-02-19 15:57:52 +01:00
|
|
|
|
|
2013-12-10 11:26:18 +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 )
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
ModelInitData modelData;
|
2014-02-17 16:16:27 +01:00
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.position = position;
|
|
|
|
|
modelData.rotation = ArrayToQuaternion( rotation );
|
|
|
|
|
modelData.scale = scale;
|
|
|
|
|
StringToWstring( modelName, modelData.modelPath );
|
|
|
|
|
modelData.id = id;
|
|
|
|
|
|
2014-02-18 13:31:36 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
RBInitData RBData;
|
|
|
|
|
RBData.position = position;
|
|
|
|
|
RBData.rotation = ArrayToQuaternion( rotation );
|
2014-02-19 13:41:05 +01:00
|
|
|
|
RBData.scale = scale;
|
2014-02-18 15:07:40 +01:00
|
|
|
|
// !RB DEBUG
|
2014-02-17 16:16:27 +01:00
|
|
|
|
if( isMyPlayer )
|
|
|
|
|
{
|
|
|
|
|
if( this->privData->player.Init(modelData) )
|
|
|
|
|
{
|
2014-02-18 13:31:36 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
this->privData->player.InitRB( RBData );
|
2014-02-18 15:07:40 +01:00
|
|
|
|
// !RB DEBUG
|
2014-02-18 13:31:36 +01:00
|
|
|
|
|
2014-02-17 16:16:27 +01:00
|
|
|
|
this->privData->myId = id;
|
|
|
|
|
this->privData->camera.SetPosition( this->privData->player.getPos() );
|
2014-02-18 10:28:46 +01:00
|
|
|
|
Float3 offset = Float3( 0.0f );
|
2014-02-18 12:59:51 +01:00
|
|
|
|
offset.y = this->privData->player.getScale().y * 0.9f;
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
C_DynamicObj *p = new C_DynamicObj();
|
|
|
|
|
if( p->Init(modelData) )
|
|
|
|
|
{
|
2014-02-18 13:31:36 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
this->privData->player.InitRB( RBData );
|
2014-02-18 15:07:40 +01:00
|
|
|
|
// !RB DEBUG
|
2014-02-18 13:31:36 +01:00
|
|
|
|
|
2014-02-17 16:16:27 +01:00
|
|
|
|
(*this->privData->dynamicObjects)[id] = p;
|
|
|
|
|
}
|
|
|
|
|
}
|
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 )
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2014-02-18 10:28:46 +01:00
|
|
|
|
this->ReadKeyInput();
|
2014-02-12 16:31:15 +01:00
|
|
|
|
return this->privData->nextState;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
|
bool GameState::Render()
|
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Oyster::Graphics::API::SetView( this->privData->camera.GetViewMatrix() );
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
2013-12-09 09:23:39 +01:00
|
|
|
|
Oyster::Graphics::API::NewFrame();
|
2014-02-17 14:33:11 +01:00
|
|
|
|
|
|
|
|
|
// for debugging to be replaced with render weapon
|
|
|
|
|
this->privData->player.Render();
|
|
|
|
|
|
|
|
|
|
auto staticObject = this->privData->staticObjects->begin();
|
|
|
|
|
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
staticObject->second->Render();
|
2013-12-10 11:26:18 +01:00
|
|
|
|
}
|
2014-02-17 14:33:11 +01:00
|
|
|
|
|
|
|
|
|
auto dynamicObject = this->privData->dynamicObjects->begin();
|
|
|
|
|
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
|
2014-02-10 14:00:14 +01:00
|
|
|
|
{
|
2014-02-18 15:09:01 +01:00
|
|
|
|
if( dynamicObject->second )
|
|
|
|
|
dynamicObject->second->Render();
|
2014-02-10 14:00:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 13:31:36 +01:00
|
|
|
|
|
2014-02-19 10:59:23 +01:00
|
|
|
|
/*auto light = this->privData->lights->begin();
|
|
|
|
|
for( ; light != this->privData->lights->end(); ++light )
|
2014-02-18 13:31:36 +01:00
|
|
|
|
{
|
2014-02-19 10:59:23 +01:00
|
|
|
|
light->second->Render();
|
|
|
|
|
}*/
|
2014-02-18 13:31:36 +01:00
|
|
|
|
|
2014-02-20 08:43:54 +01:00
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
//RB DEBUG render wire frame
|
|
|
|
|
if(this->privData->renderWhireframe)
|
2014-02-20 09:00:02 +01:00
|
|
|
|
{
|
2014-02-20 08:43:54 +01:00
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
staticObject = this->privData->staticObjects->begin();
|
|
|
|
|
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
|
2014-02-20 09:00:02 +01:00
|
|
|
|
{
|
2014-02-20 08:43:54 +01:00
|
|
|
|
if( staticObject->second->getBRtype() == RB_Type_Cube)
|
2014-02-20 09:00:02 +01:00
|
|
|
|
{
|
2014-02-20 08:43:54 +01:00
|
|
|
|
Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld());
|
2014-02-20 09:00:02 +01:00
|
|
|
|
}
|
2014-02-20 08:43:54 +01:00
|
|
|
|
if( staticObject->second->getBRtype() == RB_Type_Sphere)
|
2014-02-20 09:00:02 +01:00
|
|
|
|
{
|
2014-02-20 08:43:54 +01:00
|
|
|
|
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());
|
|
|
|
|
}
|
2014-02-20 09:00:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-20 08:43:54 +01:00
|
|
|
|
//!RB DEBUG
|
|
|
|
|
#endif
|
2014-02-18 15:07:40 +01:00
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
|
Oyster::Graphics::API::EndFrame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2013-12-06 10:38:43 +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 )
|
|
|
|
|
{
|
|
|
|
|
auto staticObject = this->privData->staticObjects->begin();
|
|
|
|
|
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
|
|
|
|
|
{
|
|
|
|
|
staticObject->second = nullptr;
|
|
|
|
|
}
|
2013-12-10 11:26:18 +01:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
2013-12-06 10:38:43 +01:00
|
|
|
|
return true;
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
|
|
|
|
void GameState::ChangeState( ClientState next )
|
|
|
|
|
{
|
|
|
|
|
this->privData->nextState = next;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
void GameState::ReadKeyInput()
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_W) )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-19 10:55:59 +01:00
|
|
|
|
//if(!this->privData->key_forward)
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( Protocol_PlayerMovementForward() );
|
|
|
|
|
this->privData->key_forward = true;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_forward = false;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_S) )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-19 10:55:59 +01:00
|
|
|
|
//if( !this->privData->key_backward )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( Protocol_PlayerMovementBackward() );
|
|
|
|
|
this->privData->key_backward = true;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_backward = false;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_A) )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-19 10:55:59 +01:00
|
|
|
|
//if( !this->privData->key_strafeLeft )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( Protocol_PlayerMovementLeft() );
|
|
|
|
|
this->privData->key_strafeLeft = true;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_strafeLeft = false;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_D) )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-19 10:55:59 +01:00
|
|
|
|
//if( !this->privData->key_strafeRight )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
|
|
|
|
|
this->privData->key_strafeRight = true;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_strafeRight = false;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
|
|
|
|
|
//send delta mouse movement
|
|
|
|
|
{
|
2014-02-19 14:00:36 +01:00
|
|
|
|
static const float mouseSensitivity = Radian( 1.0f );
|
|
|
|
|
this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity );
|
2014-02-20 11:17:11 +01:00
|
|
|
|
float yaw = this->privData->input->GetYaw();
|
|
|
|
|
if( yaw != 0.0f )
|
|
|
|
|
{
|
|
|
|
|
this->privData->nwClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) );
|
|
|
|
|
}
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
2014-01-30 09:07:56 +01:00
|
|
|
|
|
|
|
|
|
// shoot
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_Z) )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( !this->privData->key_Shoot )
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_PlayerShot playerShot;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
playerShot.primaryPressed = true;
|
|
|
|
|
playerShot.secondaryPressed = false;
|
|
|
|
|
playerShot.utilityPressed = false;
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( playerShot );
|
|
|
|
|
this->privData->key_Shoot = true;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_Shoot = false;
|
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_X) )
|
2014-02-05 11:46:04 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( !this->privData->key_Shoot )
|
2014-02-05 11:46:04 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_PlayerShot playerShot;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
playerShot.primaryPressed = false;
|
|
|
|
|
playerShot.secondaryPressed = true;
|
|
|
|
|
playerShot.utilityPressed = false;
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( playerShot );
|
|
|
|
|
this->privData->key_Shoot = true;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_Shoot = false;
|
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_C) )
|
2014-02-05 11:46:04 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( !this->privData->key_Shoot )
|
2014-02-05 11:46:04 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_PlayerShot playerShot;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
playerShot.primaryPressed = false;
|
|
|
|
|
playerShot.secondaryPressed = false;
|
|
|
|
|
playerShot.utilityPressed = true;
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( playerShot );
|
|
|
|
|
this->privData->key_Shoot = true;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_Shoot = false;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
|
2014-01-30 09:07:56 +01:00
|
|
|
|
// jump
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_SPACE) )
|
2014-01-30 09:07:56 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if(!this->privData->key_Jump)
|
2014-01-30 09:07:56 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->nwClient->Send( Protocol_PlayerJump() );
|
|
|
|
|
this->privData->key_Jump = true;
|
2014-01-30 09:07:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2014-02-17 14:33:11 +01:00
|
|
|
|
this->privData->key_Jump = false;
|
2014-01-30 09:07:56 +01:00
|
|
|
|
|
2014-02-18 15:54:09 +01:00
|
|
|
|
|
|
|
|
|
// DEGUG KEYS
|
|
|
|
|
|
|
|
|
|
// Reload shaders
|
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_R) )
|
|
|
|
|
{
|
|
|
|
|
if( !this->privData->key_Reload_Shaders )
|
|
|
|
|
{
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
Graphics::API::ReloadShaders();
|
|
|
|
|
#endif
|
|
|
|
|
this->privData->key_Reload_Shaders = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this->privData->key_Reload_Shaders = false;
|
|
|
|
|
|
|
|
|
|
// toggle wire frame render
|
|
|
|
|
if( this->privData->input->IsKeyPressed(DIK_T) )
|
|
|
|
|
{
|
|
|
|
|
if( !this->privData->key_Wireframe_Toggle )
|
|
|
|
|
{
|
|
|
|
|
this->privData->renderWhireframe = !this->privData->renderWhireframe;
|
|
|
|
|
this->privData->key_Wireframe_Toggle = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
this->privData->key_Wireframe_Toggle = false;
|
|
|
|
|
// !DEGUG KEYS
|
2014-02-17 14:33:11 +01:00
|
|
|
|
// TODO: implement sub-menu
|
2013-12-16 11:08:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:28:24 +01:00
|
|
|
|
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
|
2013-12-16 11:08:10 +01:00
|
|
|
|
{
|
2014-02-18 17:28:24 +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 );
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:28:24 +01:00
|
|
|
|
// fetching the id data.
|
|
|
|
|
short ID = message.args.data.protocol[0].value.netShort;
|
2014-02-18 16:44:38 +01:00
|
|
|
|
|
2014-02-12 09:54:33 +01:00
|
|
|
|
if( ProtocolIsGameplay(ID) )
|
2013-12-19 11:58:42 +01:00
|
|
|
|
{
|
2014-02-18 17:28:24 +01:00
|
|
|
|
CustomNetProtocol data = message.args.data.protocol;
|
|
|
|
|
|
2014-02-12 09:54:33 +01:00
|
|
|
|
switch(ID)
|
2014-01-16 12:26:14 +01:00
|
|
|
|
{
|
2014-02-12 09:54:33 +01:00
|
|
|
|
case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */
|
|
|
|
|
case protocol_Gameplay_ObjectDamage: break; /** @todo TODO: implement */
|
|
|
|
|
case protocol_Gameplay_ObjectHealthStatus: break; /** @todo TODO: implement */
|
|
|
|
|
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-12 09:54:33 +01:00
|
|
|
|
// if is this player. Remember to change camera
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->myId == decoded.object_ID )
|
|
|
|
|
this->privData->camera.SetPosition( decoded.position );
|
2014-02-12 09:02:44 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position );
|
2014-02-18 15:54:09 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position );
|
|
|
|
|
// !RB DEBUG
|
2014-01-28 15:04:25 +01:00
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
case protocol_Gameplay_ObjectScale:
|
2014-02-12 09:02:44 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_ObjectScale decoded(data);
|
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale );
|
2014-02-18 15:54:09 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale );
|
|
|
|
|
// !RB DEBUG
|
2014-02-12 09:02:44 +01:00
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
case protocol_Gameplay_ObjectRotation:
|
2014-02-12 09:02:44 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_ObjectRotation decoded(data);
|
2014-02-12 09:54:33 +01:00
|
|
|
|
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
|
|
|
|
|
|
|
|
|
|
// if is this player. Remember to change camera
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->myId == decoded.object_ID )
|
2014-02-18 17:42:00 +01:00
|
|
|
|
this->privData->camera.SetRotation( rotation );
|
2014-02-12 09:54:33 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation );
|
2014-02-18 15:54:09 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation );
|
|
|
|
|
// !RB DEBUG
|
2014-02-12 09:02:44 +01:00
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
case protocol_Gameplay_ObjectPositionRotation:
|
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_ObjectPositionRotation decoded(data);
|
2014-02-12 09:54:33 +01:00
|
|
|
|
Float3 position = decoded.position;
|
|
|
|
|
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
|
2013-12-18 12:18:01 +01:00
|
|
|
|
|
2014-02-12 09:54:33 +01:00
|
|
|
|
// if is this player. Remember to change camera
|
2014-02-17 14:33:11 +01:00
|
|
|
|
if( this->privData->myId == decoded.object_ID )
|
2014-02-12 09:54:33 +01:00
|
|
|
|
{
|
2014-02-19 15:47:43 +01:00
|
|
|
|
if( !Within(position.Dot(position), 2500.0f, 90000.0f) )
|
|
|
|
|
{ // HACK: bug trap
|
|
|
|
|
const char *breakPoint = "Something is wrong.";
|
2014-02-20 09:00:02 +01:00
|
|
|
|
position = Float3( 0.0f, 160.0f, 0.0f );
|
2014-02-19 15:47:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-19 13:41:05 +01:00
|
|
|
|
this->privData->camera.SetPosition( position );
|
|
|
|
|
this->privData->camera.SetRotation( rotation );
|
2014-02-19 10:55:59 +01:00
|
|
|
|
this->privData->player.setPos( position );
|
2014-02-19 14:20:46 +01:00
|
|
|
|
this->privData->player.setRot( rotation );
|
2014-02-12 09:54:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID];
|
2014-02-19 11:31:05 +01:00
|
|
|
|
|
2014-02-18 15:09:01 +01:00
|
|
|
|
if( object )
|
|
|
|
|
{
|
|
|
|
|
object->setPos( position );
|
|
|
|
|
object->setRot( rotation );
|
2014-02-19 11:31:05 +01:00
|
|
|
|
// RB DEBUG
|
|
|
|
|
object->setRBPos ( position );
|
|
|
|
|
object->setRBRot ( rotation );
|
|
|
|
|
// !RB DEBUG
|
2014-02-18 15:09:01 +01:00
|
|
|
|
}
|
2014-02-12 09:54:33 +01:00
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */
|
|
|
|
|
case protocol_Gameplay_ObjectDisabled:
|
2014-02-12 09:02:44 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_ObjectDisable decoded(data);
|
2013-12-18 12:18:01 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
auto object = this->privData->dynamicObjects->find( decoded.objectID );
|
|
|
|
|
if( object != this->privData->dynamicObjects->end() )
|
2014-02-12 09:54:33 +01:00
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
object->second = nullptr;
|
|
|
|
|
this->privData->dynamicObjects->erase( object );
|
2014-02-12 09:54:33 +01:00
|
|
|
|
}
|
2014-02-12 09:02:44 +01:00
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
case protocol_Gameplay_ObjectCreate:
|
|
|
|
|
{
|
2014-02-17 14:33:11 +01:00
|
|
|
|
Protocol_ObjectCreate decoded(data);
|
2014-02-12 09:54:33 +01:00
|
|
|
|
C_DynamicObj* object = new C_DynamicObj();
|
2013-12-17 13:39:10 +01:00
|
|
|
|
|
2014-02-12 09:54:33 +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] );
|
2014-02-12 09:54:33 +01:00
|
|
|
|
modelData.scale = Float3( decoded.scale );
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.id = decoded.object_ID;
|
2013-12-18 15:28:47 +01:00
|
|
|
|
|
2014-02-12 09:54:33 +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 );
|
|
|
|
|
|
|
|
|
|
this->privData->player.InitRB( RBData );
|
|
|
|
|
// !RB DEBUG
|
2014-02-12 09:54:33 +01:00
|
|
|
|
|
2014-02-17 14:33:11 +01:00
|
|
|
|
(*this->privData->dynamicObjects)[decoded.object_ID] = object;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
|
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-17 16:16:27 +01:00
|
|
|
|
case protocol_Gameplay_ObjectCreatePlayer:
|
|
|
|
|
{
|
|
|
|
|
Protocol_ObjectCreatePlayer decoded(data);
|
2014-02-18 08:53:52 +01:00
|
|
|
|
this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner );
|
2014-02-17 16:16:27 +01:00
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
return GameClientState::event_processed;
|
2014-02-12 09:54:33 +01:00
|
|
|
|
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: break; /** @todo TODO: implement */
|
|
|
|
|
case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */
|
|
|
|
|
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
|
|
|
|
}
|
2014-02-18 17:28:24 +01:00
|
|
|
|
|
|
|
|
|
return message;
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|