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-12 09:02:44 +01:00
|
|
|
|
#include "Camera_FPS.h"
|
2014-01-30 14:17:50 +01:00
|
|
|
|
#include <GameServerAPI.h>
|
2013-12-10 11:26:18 +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-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-12 09:49:08 +01:00
|
|
|
|
} privData;
|
2013-12-09 09:23:39 +01:00
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
|
GameState::GameState(void)
|
|
|
|
|
{
|
2014-01-13 12:11:45 +01:00
|
|
|
|
key_forward = false;
|
|
|
|
|
key_backward = false;
|
|
|
|
|
key_strafeRight = false;
|
|
|
|
|
key_strafeLeft = false;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameState::~GameState(void)
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
bool GameState::Init(NetworkClient* nwClient)
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2013-12-10 11:26:18 +01:00
|
|
|
|
// load models
|
2014-02-12 16:31:15 +01:00
|
|
|
|
privData = new MyData();
|
|
|
|
|
|
|
|
|
|
this->privData->nextState = GameClientState::ClientState_Same;
|
|
|
|
|
this->privData->nwClient = nwClient;
|
|
|
|
|
|
|
|
|
|
LoadGame();
|
2014-02-09 18:58:14 +01:00
|
|
|
|
|
2014-02-12 16:31:15 +01:00
|
|
|
|
//tell server ready
|
2014-02-04 16:07:10 +01:00
|
|
|
|
nwClient->Send(GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready));
|
|
|
|
|
|
2013-12-10 11:26:18 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2013-12-13 12:02:49 +01:00
|
|
|
|
GameState::gameStateState GameState::LoadGame()
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-12 16:31:15 +01:00
|
|
|
|
// Oyster::Graphics::Definitions::Pointlight plight;
|
|
|
|
|
// plight.Pos = Float3(315.0f, 0.0f ,5.0f);
|
|
|
|
|
// plight.Color = Float3(0.9f,0.7f,0.2f);
|
|
|
|
|
// plight.Radius = 100.0f;
|
|
|
|
|
// plight.Bright = 0.9f;
|
|
|
|
|
// Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
// plight.Pos = Float3(10.0f,350.0f,5.0f);
|
|
|
|
|
// plight.Color = Float3(0.9f,0.7f,0.3f);
|
|
|
|
|
// plight.Radius = 200.0f;
|
|
|
|
|
// plight.Bright = 0.7f;
|
|
|
|
|
// Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
// plight.Pos = Float3(350.0f,350.0f,5.0f);
|
|
|
|
|
// plight.Color = Float3(0.9f,0.7f,0.3f);
|
|
|
|
|
// plight.Radius = 200.0f;
|
|
|
|
|
// plight.Bright = 0.7f;
|
|
|
|
|
// Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
// plight.Pos = Float3(10.0f,350.0f,350.0f);
|
|
|
|
|
// plight.Color = Float3(0.9f,0.7f,0.3f);
|
|
|
|
|
// plight.Radius = 200.0f;
|
|
|
|
|
// plight.Bright = 0.7f;
|
|
|
|
|
// Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
// plight.Pos = Float3(10.0f,-15.0f,5.0f);
|
|
|
|
|
// plight.Color = Float3(0.0f,0.0f,1.0f);
|
|
|
|
|
// plight.Radius = 50.0f;
|
|
|
|
|
// plight.Bright = 2.0f;
|
|
|
|
|
//
|
|
|
|
|
// Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
//// LoadModels();
|
|
|
|
|
// InitCamera(Float3(0.0f,0.0f,20.0f));
|
|
|
|
|
// // hardcoded objects
|
|
|
|
|
//// LoadModels();
|
|
|
|
|
// Float3 startPos = Float3(0,0,20.0f);
|
|
|
|
|
// InitCamera(startPos);
|
2013-12-10 11:26:18 +01:00
|
|
|
|
return gameStateState_playing;
|
|
|
|
|
}
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
bool GameState::LoadModels(std::string mapFile)
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
GameLogic::LevelLoader levelLoader;
|
|
|
|
|
std::vector<Utility::DynamicMemory::SmartPointer<GameLogic::ObjectTypeHeader>> objects;
|
|
|
|
|
objects = levelLoader.LoadLevel(mapFile);
|
|
|
|
|
|
|
|
|
|
int objCount = objects.size();
|
|
|
|
|
int modelId = 0;
|
|
|
|
|
ModelInitData modelData;
|
|
|
|
|
for (int i = 0; i < objCount; i++)
|
|
|
|
|
{
|
|
|
|
|
GameLogic::ObjectTypeHeader* obj = objects.at(i);
|
|
|
|
|
|
|
|
|
|
switch (obj->typeID)
|
|
|
|
|
{
|
|
|
|
|
case GameLogic::ObjectType::ObjectType_LevelMetaData:
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case GameLogic::ObjectType::ObjectType_Static:
|
|
|
|
|
{
|
|
|
|
|
GameLogic::ObjectHeader* staticObjData = ((GameLogic::ObjectHeader*)obj);
|
|
|
|
|
|
|
|
|
|
modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end());
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
//modelData.position = ;
|
2014-02-12 09:02:44 +01:00
|
|
|
|
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
|
|
|
|
|
//modelData.scale = Float3(2,2,2);
|
2014-02-10 14:00:14 +01:00
|
|
|
|
modelData.id = modelId++;
|
|
|
|
|
|
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GameLogic::ObjectType::ObjectType_Dynamic:
|
|
|
|
|
{
|
|
|
|
|
GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj);
|
|
|
|
|
//modelData.position = ;
|
2014-02-12 09:02:44 +01:00
|
|
|
|
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
|
|
|
|
|
//modelData.scale = Float3(2,2,2);
|
2014-02-10 14:00:14 +01:00
|
|
|
|
modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end());
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.id = modelId++;
|
|
|
|
|
|
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case GameLogic::ObjectType::ObjectType_Light:
|
|
|
|
|
{
|
|
|
|
|
GameLogic::BasicLight* lightData = ((GameLogic::BasicLight*)obj);
|
|
|
|
|
|
2014-02-13 13:30:14 +01:00
|
|
|
|
switch( lightData->lightType )
|
2014-02-10 14:00:14 +01:00
|
|
|
|
{
|
2014-02-13 13:30:14 +01:00
|
|
|
|
case GameLogic::LightType_PointLight:
|
|
|
|
|
{
|
|
|
|
|
//Oyster::Graphics::Definitions::Pointlight plight;
|
|
|
|
|
//plight.Pos = ((GameLogic::PointLight*)lightData)->position;
|
|
|
|
|
//plight.Color = lightData->diffuseColor;
|
|
|
|
|
//plight.Radius = 100;
|
|
|
|
|
//plight.Bright = 0.9f;
|
|
|
|
|
//Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
2014-02-10 14:00:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
myId += modelId++;
|
|
|
|
|
// add player model
|
|
|
|
|
//modelData.position = ;
|
2014-02-12 09:02:44 +01:00
|
|
|
|
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
|
|
|
|
|
//modelData.scale = Float3(2,2,2);
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
// load models
|
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
|
|
|
|
/*C_Player* obj = new C_Player();
|
2014-02-05 15:54:48 +01:00
|
|
|
|
privData->object.push_back(obj);
|
|
|
|
|
privData->object[privData->object.size() -1 ]->Init(modelData);
|
2014-02-09 18:58:14 +01:00
|
|
|
|
*/
|
2013-12-10 11:26:18 +01:00
|
|
|
|
return true;
|
2014-02-05 15:54:48 +01:00
|
|
|
|
|
2013-12-10 11:26:18 +01:00
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
bool GameState::InitCamera(Float3 startPos)
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-12 09:02:44 +01:00
|
|
|
|
camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) );
|
|
|
|
|
camera.SetPerspectiveProjection( pi / 4.0f, 1024.0f/768.0f, 1.0f, 1000.0f );
|
|
|
|
|
camera.UpdateOrientation();
|
|
|
|
|
Oyster::Graphics::API::SetProjection(camera.GetProjectionMatrix());
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2014-02-12 09:02:44 +01:00
|
|
|
|
void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
|
2014-01-31 16:33:16 +01:00
|
|
|
|
{
|
|
|
|
|
myId = id;
|
2014-02-05 15:16:31 +01:00
|
|
|
|
|
|
|
|
|
ModelInitData modelData;
|
|
|
|
|
C_Object* obj;
|
|
|
|
|
modelData.visible = true;
|
2014-02-10 14:41:43 +01:00
|
|
|
|
//modelData.world = world;
|
2014-02-12 09:02:44 +01:00
|
|
|
|
modelData.position = Float3(world[12], world[13], world[14]);
|
|
|
|
|
modelData.rotation = Quaternion(Float3(0,0,0), 1);
|
|
|
|
|
modelData.scale = Float3(1,1,1);
|
2014-02-05 15:16:31 +01:00
|
|
|
|
modelData.modelPath = modelName;
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
|
2014-02-12 09:02:44 +01:00
|
|
|
|
obj = new C_Player();
|
2014-02-10 14:41:43 +01:00
|
|
|
|
this->dynamicObjects.Push(obj);
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
2014-02-09 16:42:26 +01:00
|
|
|
|
|
2014-02-12 09:02:44 +01:00
|
|
|
|
Float3 pos = Float3(world[12], world[13], world[14]);
|
|
|
|
|
|
|
|
|
|
camera.SetPosition( pos );
|
|
|
|
|
camera.UpdateOrientation();
|
2014-01-31 16:33:16 +01:00
|
|
|
|
}
|
2014-02-12 16:31:15 +01:00
|
|
|
|
|
2013-12-09 09:23:39 +01:00
|
|
|
|
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2014-02-12 16:31:15 +01:00
|
|
|
|
//switch (privData->state)
|
|
|
|
|
//{
|
|
|
|
|
//case gameStateState_loading: //Will this ever happen in this scope??
|
|
|
|
|
// {
|
|
|
|
|
// // load map
|
|
|
|
|
// // wait for all players
|
|
|
|
|
// LoadGame();
|
|
|
|
|
// GameLogic::Protocol_General_Status gameStatus;
|
|
|
|
|
// gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
|
|
|
|
|
// privData->nwClient->Send(gameStatus);
|
|
|
|
|
// privData->state = gameStateState_playing;
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
//case gameStateState_playing:
|
|
|
|
|
// // read server data
|
|
|
|
|
// // update objects
|
|
|
|
|
// {
|
|
|
|
|
// readKeyInput(KeyInput);
|
|
|
|
|
// camera.UpdateOrientation();
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
//case gameStateState_end:
|
|
|
|
|
// return ClientState_Lobby;
|
|
|
|
|
// break;
|
|
|
|
|
//default:
|
|
|
|
|
// break;
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//// send key input to server.
|
|
|
|
|
//return ClientState_Same;
|
|
|
|
|
|
|
|
|
|
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-12 09:02:44 +01:00
|
|
|
|
Oyster::Graphics::API::SetView( camera.GetViewMatrix() );
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
2013-12-09 09:23:39 +01:00
|
|
|
|
Oyster::Graphics::API::NewFrame();
|
2014-02-10 14:00:14 +01:00
|
|
|
|
for (unsigned int i = 0; i < staticObjects.Size(); i++)
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
staticObjects[i]->Render();
|
2013-12-10 11:26:18 +01:00
|
|
|
|
}
|
2014-02-10 14:00:14 +01:00
|
|
|
|
for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
|
|
|
|
|
{
|
|
|
|
|
dynamicObjects[i]->Render();
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2013-12-10 11:26:18 +01:00
|
|
|
|
|
2013-12-09 11:05:47 +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-01-27 13:56:31 +01:00
|
|
|
|
void GameState::readKeyInput(InputClass* KeyInput)
|
|
|
|
|
{
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_W))
|
|
|
|
|
{
|
|
|
|
|
if(!key_forward)
|
|
|
|
|
{
|
2014-02-11 10:21:47 +01:00
|
|
|
|
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementForward());
|
2014-01-27 13:56:31 +01:00
|
|
|
|
key_forward = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_forward = false;
|
|
|
|
|
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_S))
|
|
|
|
|
{
|
|
|
|
|
if(!key_backward)
|
|
|
|
|
{
|
2014-02-11 10:21:47 +01:00
|
|
|
|
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementBackward());
|
2014-01-27 13:56:31 +01:00
|
|
|
|
key_backward = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_backward = false;
|
|
|
|
|
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_A))
|
|
|
|
|
{
|
|
|
|
|
if(!key_strafeLeft)
|
|
|
|
|
{
|
2014-02-11 10:21:47 +01:00
|
|
|
|
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementLeft());
|
2014-01-27 13:56:31 +01:00
|
|
|
|
key_strafeLeft = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_strafeLeft = false;
|
|
|
|
|
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_D))
|
|
|
|
|
{
|
|
|
|
|
if(!key_strafeRight)
|
|
|
|
|
{
|
2014-02-11 10:21:47 +01:00
|
|
|
|
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementRight());
|
2014-01-27 13:56:31 +01:00
|
|
|
|
key_strafeRight = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_strafeRight = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//send delta mouse movement
|
2014-02-07 13:09:44 +01:00
|
|
|
|
//if (KeyInput->IsMousePressed())
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-12 09:02:44 +01:00
|
|
|
|
camera.YawRight( -KeyInput->GetYaw() );
|
|
|
|
|
camera.PitchUp( KeyInput->GetPitch() );
|
|
|
|
|
camera.UpdateOrientation();
|
|
|
|
|
|
2014-01-27 13:56:31 +01:00
|
|
|
|
GameLogic::Protocol_PlayerLook playerLookDir;
|
2014-02-12 09:02:44 +01:00
|
|
|
|
Float4 look = camera.GetLook();
|
2014-02-03 15:52:00 +01:00
|
|
|
|
|
2014-02-12 09:02:44 +01:00
|
|
|
|
privData->nwClient->Send( playerLookDir );
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
2014-01-30 09:07:56 +01:00
|
|
|
|
|
|
|
|
|
// shoot
|
2014-01-27 13:56:31 +01:00
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_Z))
|
|
|
|
|
{
|
|
|
|
|
if(!key_Shoot)
|
|
|
|
|
{
|
|
|
|
|
GameLogic::Protocol_PlayerShot playerShot;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
playerShot.primaryPressed = true;
|
|
|
|
|
playerShot.secondaryPressed = false;
|
|
|
|
|
playerShot.utilityPressed = false;
|
|
|
|
|
privData->nwClient->Send(playerShot);
|
|
|
|
|
key_Shoot = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_Shoot = false;
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_X))
|
|
|
|
|
{
|
|
|
|
|
if(!key_Shoot)
|
|
|
|
|
{
|
|
|
|
|
GameLogic::Protocol_PlayerShot playerShot;
|
|
|
|
|
playerShot.primaryPressed = false;
|
|
|
|
|
playerShot.secondaryPressed = true;
|
|
|
|
|
playerShot.utilityPressed = false;
|
|
|
|
|
privData->nwClient->Send(playerShot);
|
|
|
|
|
key_Shoot = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_Shoot = false;
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_C))
|
|
|
|
|
{
|
|
|
|
|
if(!key_Shoot)
|
|
|
|
|
{
|
|
|
|
|
GameLogic::Protocol_PlayerShot playerShot;
|
|
|
|
|
playerShot.primaryPressed = false;
|
|
|
|
|
playerShot.secondaryPressed = false;
|
|
|
|
|
playerShot.utilityPressed = true;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
privData->nwClient->Send(playerShot);
|
|
|
|
|
key_Shoot = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_Shoot = false;
|
|
|
|
|
|
2014-01-30 09:07:56 +01:00
|
|
|
|
// jump
|
2014-02-05 11:46:04 +01:00
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_SPACE))
|
2014-01-30 09:07:56 +01:00
|
|
|
|
{
|
|
|
|
|
if(!key_Jump)
|
|
|
|
|
{
|
2014-02-11 10:21:47 +01:00
|
|
|
|
privData->nwClient->Send(GameLogic::Protocol_PlayerJump());
|
2014-01-30 09:07:56 +01:00
|
|
|
|
key_Jump = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
key_Jump = false;
|
|
|
|
|
|
2014-01-27 13:56:31 +01:00
|
|
|
|
// send event data
|
|
|
|
|
//
|
2014-02-12 16:31:15 +01:00
|
|
|
|
//if(KeyInput->IsKeyPressed(DIK_L))
|
|
|
|
|
// privData->state = GameState::gameStateState_end;
|
2014-01-27 13:56:31 +01:00
|
|
|
|
}
|
2013-12-13 12:02:49 +01:00
|
|
|
|
|
2014-02-12 09:02:44 +01:00
|
|
|
|
using namespace ::Oyster::Network;
|
|
|
|
|
using namespace ::Utility::DynamicMemory;
|
2013-12-16 11:08:10 +01:00
|
|
|
|
|
2014-02-12 09:02:44 +01:00
|
|
|
|
// returns -1 if none found
|
|
|
|
|
int FindObject( const DynamicArray<SmartPointer<C_Object>> &collection, int id )
|
2013-12-16 11:08:10 +01:00
|
|
|
|
{
|
2014-02-12 09:02:44 +01:00
|
|
|
|
int num = collection.Size();
|
|
|
|
|
for( int i = 0; i < num; ++i ) if( id == collection[i]->GetId() )
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
2013-12-16 11:08:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 10:43:06 +01:00
|
|
|
|
void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
2013-12-16 11:08:10 +01:00
|
|
|
|
{
|
2014-02-12 09:02:44 +01:00
|
|
|
|
CustomNetProtocol data = e.args.data.protocol;
|
|
|
|
|
short ID = data[0].value.netShort; // fetching the id data.
|
|
|
|
|
|
2014-02-12 09:54:33 +01:00
|
|
|
|
if( ProtocolIsGameplay(ID) )
|
2013-12-19 11:58:42 +01:00
|
|
|
|
{
|
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:
|
|
|
|
|
{
|
|
|
|
|
GameLogic::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
|
|
|
|
|
if( this->myId == decoded.object_ID )
|
|
|
|
|
camera.SetPosition( decoded.position );
|
2014-02-12 09:02:44 +01:00
|
|
|
|
|
2014-02-12 09:54:33 +01:00
|
|
|
|
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
|
|
|
|
if( i > -1 )
|
|
|
|
|
this->dynamicObjects[i]->setPos( decoded.position );
|
2014-01-28 15:04:25 +01:00
|
|
|
|
}
|
2014-02-12 09:54:33 +01:00
|
|
|
|
break;
|
|
|
|
|
case protocol_Gameplay_ObjectScale:
|
2014-02-12 09:02:44 +01:00
|
|
|
|
{
|
2014-02-12 09:54:33 +01:00
|
|
|
|
GameLogic::Protocol_ObjectScale decoded(data);
|
|
|
|
|
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
|
|
|
|
if( i > -1 )
|
|
|
|
|
this->dynamicObjects[i]->setScale( decoded.scale );
|
2014-02-12 09:02:44 +01:00
|
|
|
|
}
|
2014-02-12 09:54:33 +01:00
|
|
|
|
break;
|
|
|
|
|
case protocol_Gameplay_ObjectRotation:
|
2014-02-12 09:02:44 +01:00
|
|
|
|
{
|
2014-02-12 09:54:33 +01:00
|
|
|
|
GameLogic::Protocol_ObjectRotation decoded(data);
|
|
|
|
|
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
|
|
|
|
|
|
|
|
|
|
// if is this player. Remember to change camera
|
|
|
|
|
if( this->myId == decoded.object_ID )
|
|
|
|
|
camera.SetAngular( QuaternionToAngularAxis(rotation).xyz );
|
|
|
|
|
|
|
|
|
|
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
|
|
|
|
if( i > -1 )
|
|
|
|
|
this->dynamicObjects[i]->setRot( rotation );
|
2014-02-12 09:02:44 +01:00
|
|
|
|
}
|
2014-02-12 09:54:33 +01:00
|
|
|
|
break;
|
|
|
|
|
case protocol_Gameplay_ObjectPositionRotation:
|
|
|
|
|
{
|
|
|
|
|
GameLogic::Protocol_ObjectPositionRotation decoded(data);
|
|
|
|
|
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
|
|
|
|
|
if( this->myId == decoded.object_ID )
|
|
|
|
|
{
|
|
|
|
|
camera.SetPosition( position );
|
|
|
|
|
camera.SetAngular( QuaternionToAngularAxis(rotation).xyz );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int i = FindObject( this->dynamicObjects, decoded.object_ID );
|
|
|
|
|
if( i > -1 )
|
|
|
|
|
{
|
|
|
|
|
this->dynamicObjects[i]->setPos( position );
|
|
|
|
|
this->dynamicObjects[i]->setRot( rotation );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */
|
|
|
|
|
case protocol_Gameplay_ObjectDisabled:
|
2014-02-12 09:02:44 +01:00
|
|
|
|
{
|
2014-02-12 09:54:33 +01:00
|
|
|
|
GameLogic::Protocol_ObjectDisable decoded(data);
|
2013-12-18 12:18:01 +01:00
|
|
|
|
|
2014-02-12 09:54:33 +01:00
|
|
|
|
int i = FindObject( this->dynamicObjects, decoded.objectID );
|
|
|
|
|
if( i > -1 )
|
|
|
|
|
{
|
|
|
|
|
this->dynamicObjects[i].Release();
|
|
|
|
|
this->dynamicObjects.Pop(i);
|
|
|
|
|
}
|
2014-02-12 09:02:44 +01:00
|
|
|
|
}
|
2014-02-12 09:54:33 +01:00
|
|
|
|
break;
|
|
|
|
|
case protocol_Gameplay_ObjectCreate:
|
|
|
|
|
{
|
|
|
|
|
GameLogic::Protocol_ObjectCreate decoded(data);
|
|
|
|
|
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 );
|
|
|
|
|
modelData.rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
dynamicObjects.Push(object);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case protocol_Gameplay_ObjectCreatePlayer: break; /** @todo TODO: implement */
|
|
|
|
|
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
|
|
|
|
}
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|