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-01-27 13:56:31 +01:00
|
|
|
|
#include "Camera.h"
|
2014-01-30 14:17:50 +01:00
|
|
|
|
#include <GameServerAPI.h>
|
2014-02-12 14:48:58 +01:00
|
|
|
|
#include "LevelLoader\ObjectDefines.h"
|
2013-12-10 11:26:18 +01:00
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
using namespace GameLogic;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
using namespace DanBias::Client;
|
2014-02-10 14:00:14 +01:00
|
|
|
|
using namespace Oyster::Math;
|
2013-12-09 09:23:39 +01:00
|
|
|
|
struct GameState::myData
|
|
|
|
|
{
|
|
|
|
|
myData(){}
|
2013-12-10 11:26:18 +01:00
|
|
|
|
int modelCount;
|
2013-12-13 12:02:49 +01:00
|
|
|
|
Oyster::Network::NetworkClient* nwClient;
|
2013-12-10 11:26:18 +01:00
|
|
|
|
gameStateState state;
|
2013-12-09 09:23:39 +01:00
|
|
|
|
}privData;
|
|
|
|
|
|
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;
|
2014-02-12 11:35:34 +01:00
|
|
|
|
timer = 0;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GameState::~GameState(void)
|
|
|
|
|
{
|
2014-01-31 22:52:52 +01:00
|
|
|
|
delete this->camera;
|
|
|
|
|
delete this->privData;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
}
|
2013-12-16 09:45:12 +01:00
|
|
|
|
bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2013-12-10 11:26:18 +01:00
|
|
|
|
// load models
|
2014-01-27 13:56:31 +01:00
|
|
|
|
camera = new Camera;
|
2013-12-10 11:26:18 +01:00
|
|
|
|
privData = new myData();
|
|
|
|
|
privData->state = gameStateState_loading;
|
2013-12-16 09:45:12 +01:00
|
|
|
|
privData->nwClient = nwClient;
|
2013-12-10 11:26:18 +01:00
|
|
|
|
privData->state = LoadGame();
|
2014-02-04 11:50:15 +01:00
|
|
|
|
pitch = 0;
|
2014-02-09 18:58:14 +01:00
|
|
|
|
|
2014-02-04 16:07:10 +01:00
|
|
|
|
//tELL SERver ready
|
|
|
|
|
nwClient->Send(GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready));
|
|
|
|
|
|
2013-12-10 11:26:18 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-12-13 12:02:49 +01:00
|
|
|
|
GameState::gameStateState GameState::LoadGame()
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-01-10 10:47:54 +01:00
|
|
|
|
Oyster::Graphics::Definitions::Pointlight plight;
|
2014-02-12 11:35:34 +01:00
|
|
|
|
plight.Pos = Float3(615, 0 ,5);
|
|
|
|
|
plight.Color = Float3(0.9f,0.7f,0.2f);
|
|
|
|
|
plight.Radius = 100;
|
|
|
|
|
plight.Bright = 0.5f;
|
2014-02-05 11:46:04 +01:00
|
|
|
|
Oyster::Graphics::API::AddLight(plight);
|
2014-02-11 15:00:52 +01:00
|
|
|
|
plight.Pos = Float3(10,800,5);
|
2014-02-10 14:00:14 +01:00
|
|
|
|
plight.Color = Float3(0.9f,0.7f,0.3f);
|
2014-02-11 15:00:52 +01:00
|
|
|
|
plight.Radius = 300;
|
|
|
|
|
plight.Bright = 0.5f;
|
2014-01-10 10:47:54 +01:00
|
|
|
|
Oyster::Graphics::API::AddLight(plight);
|
2014-02-14 10:09:03 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
// use level loader
|
2014-02-13 16:33:26 +01:00
|
|
|
|
LoadModels("../Content/Worlds/ccc.bias");
|
2014-01-27 13:56:31 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
// hardcoded objects
|
2014-02-10 14:00:14 +01:00
|
|
|
|
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
|
|
|
|
bool GameState::LoadModels()
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
|
|
|
|
// open file
|
|
|
|
|
// read file
|
|
|
|
|
// init models
|
2014-02-10 12:42:31 +01:00
|
|
|
|
int nrOfBoxex = 5;
|
2014-02-05 15:16:31 +01:00
|
|
|
|
int id = 100;
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
|
|
|
|
// add world model
|
2013-12-09 12:01:36 +01:00
|
|
|
|
ModelInitData modelData;
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
|
|
|
|
modelData.position = Oyster::Math::Float3(0,0,0);
|
|
|
|
|
modelData.rotation = Oyster::Math::Quaternion::identity;
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(2,2,2);
|
|
|
|
|
|
2014-01-30 11:11:45 +01:00
|
|
|
|
modelData.modelPath = L"world_earth.dan";
|
2014-02-04 16:08:28 +01:00
|
|
|
|
modelData.id = id++;
|
2014-01-29 13:18:17 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
2013-12-09 09:23:39 +01:00
|
|
|
|
|
2014-02-12 11:35:34 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
// add box model
|
|
|
|
|
modelData.position = Oyster::Math::Float3(0,0,0);
|
|
|
|
|
modelData.rotation = Oyster::Math::Quaternion::identity;
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
2014-02-05 15:54:48 +01:00
|
|
|
|
modelData.modelPath = L"crate_colonists.dan";
|
2013-12-10 11:26:18 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
2014-02-05 11:46:04 +01:00
|
|
|
|
for(int i =0; i< nrOfBoxex; i ++)
|
|
|
|
|
{
|
2014-02-10 16:28:25 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(4,320,0);
|
2014-02-05 11:46:04 +01:00
|
|
|
|
modelData.id = id++;
|
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
2014-02-05 11:46:04 +01:00
|
|
|
|
}
|
2014-01-10 10:47:54 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
// add crystal model
|
2014-02-12 09:32:13 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(10, 601, 0);
|
2014-02-10 16:28:25 +01:00
|
|
|
|
modelData.modelPath = L"crystalformation_b.dan";
|
|
|
|
|
modelData.id = id++;
|
|
|
|
|
// load models
|
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
|
|
|
|
// add house model
|
2014-02-12 09:32:13 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(-50, 590, 0);
|
2014-02-10 16:28:25 +01:00
|
|
|
|
//Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0));
|
|
|
|
|
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.modelPath = L"building_corporation.dan";
|
|
|
|
|
modelData.id = id++;
|
|
|
|
|
// load models
|
2014-02-12 09:32:13 +01:00
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
2014-02-12 13:37:21 +01:00
|
|
|
|
// add jumppad
|
2014-02-14 10:09:03 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(4, 600.3f, 0);
|
2014-02-12 13:37:21 +01:00
|
|
|
|
modelData.modelPath = L"jumppad_round.dan";
|
|
|
|
|
modelData.id = id++;
|
|
|
|
|
// load models
|
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
|
|
|
|
// add player model
|
2014-02-12 09:32:13 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(0, 602, 0);
|
2014-02-10 16:28:25 +01:00
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = id++;
|
|
|
|
|
// load models
|
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
|
|
|
|
// add player model 2
|
2014-02-12 09:32:13 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(50, 602, 0);
|
2014-02-10 16:28:25 +01:00
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = id++;
|
|
|
|
|
// load models
|
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
2014-02-12 13:37:21 +01:00
|
|
|
|
|
2014-02-10 16:28:25 +01:00
|
|
|
|
|
|
|
|
|
// add sky sphere
|
|
|
|
|
modelData.position = Oyster::Math::Float3(0,0,0);
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(800,800,800);
|
|
|
|
|
modelData.modelPath = L"skysphere.dan";
|
|
|
|
|
modelData.id = id++;
|
|
|
|
|
// load models
|
|
|
|
|
this->dynamicObjects.Push(new C_DynamicObj());
|
2014-02-12 09:32:13 +01:00
|
|
|
|
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
|
2013-12-10 11:26:18 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
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();
|
2014-02-13 16:33:26 +01:00
|
|
|
|
int modelId = 100;
|
2014-02-10 14:00:14 +01:00
|
|
|
|
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;
|
2014-02-12 14:48:58 +01:00
|
|
|
|
modelData.position = staticObjData->position;
|
|
|
|
|
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(staticObjData->rotation), staticObjData->rotation[3]);
|
|
|
|
|
modelData.scale = staticObjData->scale;
|
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.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end());
|
|
|
|
|
modelData.visible = true;
|
2014-02-12 14:48:58 +01:00
|
|
|
|
modelData.position = dynamicObjData->position;
|
|
|
|
|
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(dynamicObjData->rotation), dynamicObjData->rotation[3]);
|
|
|
|
|
modelData.scale = dynamicObjData->scale;
|
2014-02-10 14:00:14 +01:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if(lightData->lightType == GameLogic::LightType_PointLight)
|
|
|
|
|
{
|
|
|
|
|
Oyster::Graphics::Definitions::Pointlight plight;
|
2014-02-12 14:48:58 +01:00
|
|
|
|
plight.Pos = ((GameLogic::BasicLight*)lightData)->position;
|
|
|
|
|
plight.Color = lightData->color;
|
2014-02-10 14:00:14 +01:00
|
|
|
|
plight.Radius = 100;
|
|
|
|
|
plight.Bright = 0.9f;
|
|
|
|
|
Oyster::Graphics::API::AddLight(plight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-14 10:09:03 +01:00
|
|
|
|
|
|
|
|
|
Oyster::Math::Quaternion first = Oyster::Math::Quaternion(Float3(0.3536,0.3536,-0.146), 0.8536);
|
|
|
|
|
Oyster::Math::Quaternion second = Oyster::Math::Quaternion(Float3(0.3536,0.3536,-0.146), 0.8536);
|
|
|
|
|
Oyster::Math::Quaternion result = first * second;
|
|
|
|
|
Oyster::Math::Quaternion total = Oyster::Math::Quaternion(Float3(0.5,0.5,-0.5), 0.5);
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.position = Oyster::Math::Float3(20, 127,0);
|
|
|
|
|
modelData.rotation = first;
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
|
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.position = Oyster::Math::Float3(22, 127,0);
|
|
|
|
|
modelData.rotation = second;
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
|
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.position = Oyster::Math::Float3(24, 127,0);
|
|
|
|
|
modelData.rotation = result;
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
|
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
|
|
|
|
modelData.visible = true;
|
|
|
|
|
modelData.position = Oyster::Math::Float3(26, 127,0);
|
|
|
|
|
modelData.rotation = total;
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
|
|
|
|
modelData.modelPath = L"char_still_sizeref.dan";
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
|
|
|
|
|
this->staticObjects.Push(new C_StaticObj());
|
|
|
|
|
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
|
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
return true;
|
2014-02-05 15:54:48 +01:00
|
|
|
|
|
2013-12-10 11:26:18 +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-10 14:00:14 +01:00
|
|
|
|
Float3 dir = Float3(0,0,1);
|
|
|
|
|
Float3 up = Float3(0,1,0);
|
|
|
|
|
Float3 pos = Float3(0, 0, 20);
|
2014-01-27 13:56:31 +01:00
|
|
|
|
camera->LookAt(pos, dir, up);
|
2014-02-10 14:00:14 +01:00
|
|
|
|
camera->SetLens(pi/4, 1024/768, 1, 1000);
|
2014-01-27 13:56:31 +01:00
|
|
|
|
camera->UpdateViewMatrix();
|
2014-02-10 14:00:14 +01:00
|
|
|
|
Oyster::Graphics::API::SetProjection(camera->Proj());
|
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-05 15:16:31 +01:00
|
|
|
|
void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::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-10 15:54:38 +01:00
|
|
|
|
modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]);
|
2014-02-11 09:17:16 +01:00
|
|
|
|
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1);
|
|
|
|
|
modelData.scale = Oyster::Math::Float3(1,1,1);
|
2014-02-05 15:16:31 +01:00
|
|
|
|
modelData.modelPath = modelName;
|
|
|
|
|
modelData.id = myId;
|
|
|
|
|
|
|
|
|
|
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-11 15:00:52 +01:00
|
|
|
|
|
2014-02-10 14:41:43 +01:00
|
|
|
|
|
2014-02-09 16:42:26 +01:00
|
|
|
|
Oyster::Math::Float3 right = Oyster::Math::Float3(world[0], world[1], world[2]);
|
|
|
|
|
Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]);
|
|
|
|
|
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
|
|
|
|
|
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]);
|
|
|
|
|
|
|
|
|
|
Oyster::Math::Float3 cameraLook = camera->GetLook();
|
|
|
|
|
Oyster::Math::Float3 cameraUp = camera->GetUp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Oyster::Math::Float3 newUp = cameraUp.Dot(up);
|
|
|
|
|
up *= newUp;
|
|
|
|
|
up.Normalize();
|
|
|
|
|
Oyster::Math::Float3 newLook = up.Cross(right);
|
|
|
|
|
newLook.Normalize();*/
|
|
|
|
|
|
|
|
|
|
camera->setRight(right);
|
|
|
|
|
camera->setUp(up);
|
|
|
|
|
camera->setLook(objForward);
|
|
|
|
|
|
|
|
|
|
up *= 2;
|
2014-02-11 10:11:38 +01:00
|
|
|
|
objForward *= 3;
|
2014-02-09 16:42:26 +01:00
|
|
|
|
Oyster::Math::Float3 cameraPos = up + pos + objForward;
|
|
|
|
|
camera->SetPosition(cameraPos);
|
|
|
|
|
|
|
|
|
|
camera->UpdateViewMatrix();
|
2014-02-05 15:16:31 +01:00
|
|
|
|
|
2014-01-31 16:33:16 +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
|
|
|
|
{
|
2013-12-10 11:26:18 +01:00
|
|
|
|
switch (privData->state)
|
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
|
case gameStateState_loading: //Will this ever happen in this scope??
|
2013-12-18 15:28:47 +01:00
|
|
|
|
{
|
|
|
|
|
// load map
|
|
|
|
|
// wait for all players
|
|
|
|
|
LoadGame();
|
2013-12-20 09:42:02 +01:00
|
|
|
|
GameLogic::Protocol_General_Status gameStatus;
|
|
|
|
|
gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
|
2013-12-18 15:28:47 +01:00
|
|
|
|
privData->nwClient->Send(gameStatus);
|
|
|
|
|
privData->state = gameStateState_playing;
|
|
|
|
|
}
|
2013-12-10 11:26:18 +01:00
|
|
|
|
break;
|
|
|
|
|
case gameStateState_playing:
|
|
|
|
|
// read server data
|
|
|
|
|
// update objects
|
2013-12-13 12:02:49 +01:00
|
|
|
|
{
|
2014-02-12 11:35:34 +01:00
|
|
|
|
timer += deltaTime;
|
|
|
|
|
if(timer > 0.03)
|
|
|
|
|
{
|
|
|
|
|
readKeyInput(KeyInput);
|
|
|
|
|
timer = 0;
|
|
|
|
|
}
|
2014-01-27 13:56:31 +01:00
|
|
|
|
camera->UpdateViewMatrix();
|
2014-01-23 08:24:35 +01:00
|
|
|
|
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|
2013-12-10 11:26:18 +01:00
|
|
|
|
break;
|
|
|
|
|
case gameStateState_end:
|
2013-12-09 09:23:39 +01:00
|
|
|
|
return ClientState_Lobby;
|
2013-12-10 11:26:18 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 09:23:39 +01:00
|
|
|
|
// send key input to server.
|
2013-12-06 10:38:43 +01:00
|
|
|
|
return ClientState_Same;
|
|
|
|
|
}
|
2014-02-11 15:00:52 +01:00
|
|
|
|
bool GameState::Render(float dt)
|
2013-12-06 10:38:43 +01:00
|
|
|
|
{
|
2014-01-27 13:56:31 +01:00
|
|
|
|
Oyster::Graphics::API::SetView(camera->View());
|
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();
|
|
|
|
|
}
|
2014-02-11 15:00:52 +01:00
|
|
|
|
Oyster::Graphics::API::StartTextRender();
|
|
|
|
|
std::wstring fps;
|
|
|
|
|
float f = 1/dt;
|
|
|
|
|
fps = std::to_wstring(f);
|
2014-02-14 11:27:52 +01:00
|
|
|
|
//Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.2f,0.05f));
|
2014-02-10 14:00:14 +01:00
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
|
Oyster::Graphics::API::EndFrame();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool GameState::Release()
|
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
/*for (unsigned int i = 0; i < privData->object.size(); i++)
|
2013-12-10 11:26:18 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
privData->object[i]->Release();
|
|
|
|
|
delete privData->object[i];
|
|
|
|
|
privData->object[i] = NULL;
|
|
|
|
|
}*/
|
2013-12-10 11:26:18 +01:00
|
|
|
|
|
2013-12-09 11:05:47 +01:00
|
|
|
|
delete privData;
|
|
|
|
|
privData = NULL;
|
2013-12-06 10:38:43 +01:00
|
|
|
|
return true;
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|
2014-01-27 13:56:31 +01:00
|
|
|
|
void GameState::readKeyInput(InputClass* KeyInput)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_W))
|
|
|
|
|
{
|
2014-02-12 11:35:34 +01:00
|
|
|
|
//if(!key_forward)
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
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))
|
|
|
|
|
{
|
2014-02-12 11:35:34 +01:00
|
|
|
|
//if(!key_backward)
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
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))
|
|
|
|
|
{
|
2014-02-12 11:35:34 +01:00
|
|
|
|
//if(!key_strafeLeft)
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
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))
|
|
|
|
|
{
|
2014-02-12 11:35:34 +01:00
|
|
|
|
//if(!key_strafeRight)
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
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-11 11:46:06 +01:00
|
|
|
|
if (KeyInput->IsMousePressed())
|
2014-01-27 13:56:31 +01:00
|
|
|
|
{
|
2014-02-03 15:52:00 +01:00
|
|
|
|
camera->Yaw(-KeyInput->GetYaw());
|
2014-02-04 16:08:28 +01:00
|
|
|
|
camera->Pitch(KeyInput->GetPitch());
|
|
|
|
|
pitch = KeyInput->GetPitch();
|
2014-02-12 13:11:35 +01:00
|
|
|
|
camera->UpdateViewMatrix();
|
|
|
|
|
Oyster::Math::Float3 look = camera->GetLook();
|
|
|
|
|
Oyster::Math::Float3 right = camera->GetRight();
|
|
|
|
|
GameLogic::Protocol_PlayerLook playerLook(look, right);
|
|
|
|
|
|
|
|
|
|
privData->nwClient->Send(playerLook);
|
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;
|
2014-02-12 11:35:34 +01:00
|
|
|
|
|
2014-02-05 11:46:04 +01:00
|
|
|
|
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;
|
2014-02-12 11:35:34 +01:00
|
|
|
|
|
2014-02-05 11:46:04 +01:00
|
|
|
|
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
|
|
|
|
|
//
|
|
|
|
|
if(KeyInput->IsKeyPressed(DIK_L))
|
|
|
|
|
privData->state = GameState::gameStateState_end;
|
|
|
|
|
}
|
2013-12-13 12:02:49 +01:00
|
|
|
|
|
|
|
|
|
void GameState::Protocol(ProtocolStruct* pos)
|
|
|
|
|
{
|
2013-12-18 15:28:47 +01:00
|
|
|
|
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|
2013-12-16 11:08:10 +01:00
|
|
|
|
|
2013-12-17 13:39:10 +01:00
|
|
|
|
void GameState::Protocol( PlayerPos* pos )
|
2013-12-16 11:08:10 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
//Oyster::Math::Float4x4 world, translate;
|
|
|
|
|
|
|
|
|
|
//world = Oyster::Math::Float4x4::identity;
|
|
|
|
|
//translate = Oyster::Math::Float4x4::identity;
|
|
|
|
|
//translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2]));
|
|
|
|
|
//world = world * translate;
|
|
|
|
|
////privData->object[0]->setPos( world );
|
|
|
|
|
//for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
|
|
|
|
|
//{
|
|
|
|
|
// dynamicObjects[i]->Render();
|
|
|
|
|
//}
|
2013-12-16 11:08:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 13:39:10 +01:00
|
|
|
|
void GameState::Protocol( ObjPos* pos )
|
2013-12-16 11:08:10 +01:00
|
|
|
|
{
|
|
|
|
|
Oyster::Math::Float4x4 world;
|
|
|
|
|
for(int i = 0; i<16; i++)
|
|
|
|
|
{
|
|
|
|
|
world[i] = pos->worldPos[i];
|
|
|
|
|
}
|
2014-02-12 11:35:34 +01:00
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
|
2013-12-19 11:58:42 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
if(dynamicObjects[i]->GetId() == pos->object_ID)
|
2014-01-16 12:26:14 +01:00
|
|
|
|
{
|
2014-02-12 11:35:34 +01:00
|
|
|
|
dynamicObjects[i]->setPos(Float3(world[0], world[1], world[2]));
|
|
|
|
|
dynamicObjects[i]->setRot(Quaternion(Float3(world[3], world[4], world[5]), world[6]));
|
|
|
|
|
//dynamicObjects[i]->setWorld(world);
|
2014-02-04 16:08:28 +01:00
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
if(dynamicObjects[i]->GetId() == myId) // playerobj
|
2014-01-28 15:04:25 +01:00
|
|
|
|
{
|
2014-02-04 16:08:28 +01:00
|
|
|
|
|
2014-02-12 14:48:58 +01:00
|
|
|
|
|
2014-02-12 11:35:34 +01:00
|
|
|
|
Float3 pos = dynamicObjects[i]->getPos();
|
|
|
|
|
Float3 up = dynamicObjects[i]->getWorld().v[1];
|
|
|
|
|
Float3 objForward = dynamicObjects[i]->getWorld().v[2];
|
2014-02-12 13:17:27 +01:00
|
|
|
|
up *= 3;
|
|
|
|
|
objForward *= -4;
|
2014-02-10 14:41:43 +01:00
|
|
|
|
Oyster::Math::Float3 cameraPos = pos + up + objForward;
|
2014-02-12 11:35:34 +01:00
|
|
|
|
camera->SetPosition(cameraPos);
|
2014-01-28 15:04:25 +01:00
|
|
|
|
}
|
2014-01-16 12:26:14 +01:00
|
|
|
|
}
|
2013-12-19 11:58:42 +01:00
|
|
|
|
}
|
2013-12-16 11:08:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-14 09:24:55 +01:00
|
|
|
|
void GameState::Protocol( NewObj* newObj )
|
2013-12-18 12:18:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Oyster::Math::Float4x4 world;
|
|
|
|
|
for(int i = 0; i<16; i++)
|
|
|
|
|
{
|
2014-01-14 09:24:55 +01:00
|
|
|
|
world[i] = newObj->worldPos[i];
|
2013-12-18 12:18:01 +01:00
|
|
|
|
}
|
|
|
|
|
ModelInitData modelData;
|
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
//modelData.world = world;
|
2013-12-18 12:18:01 +01:00
|
|
|
|
modelData.visible = true;
|
2014-01-14 09:24:55 +01:00
|
|
|
|
modelData.id = newObj->object_ID;
|
2013-12-18 15:28:47 +01:00
|
|
|
|
//not sure if this is good parsing rom char* to wstring
|
2014-01-14 09:24:55 +01:00
|
|
|
|
const char* path = newObj->path;
|
2013-12-18 12:18:01 +01:00
|
|
|
|
modelData.modelPath = std::wstring(path, path + strlen(path));
|
|
|
|
|
// load models
|
2014-02-10 14:00:14 +01:00
|
|
|
|
C_DynamicObj* player = new C_DynamicObj();
|
2013-12-19 11:58:42 +01:00
|
|
|
|
player->Init(modelData);
|
2013-12-18 12:18:01 +01:00
|
|
|
|
|
2014-02-10 14:00:14 +01:00
|
|
|
|
dynamicObjects.Push(player);
|
2013-12-17 13:39:10 +01:00
|
|
|
|
|
2013-12-18 15:28:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 11:58:42 +01:00
|
|
|
|
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
|
2013-12-13 12:02:49 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
|
2013-12-16 11:08:10 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
if(dynamicObjects[i]->GetId() == obj->object_ID)
|
2013-12-19 11:58:42 +01:00
|
|
|
|
{
|
2014-02-10 14:00:14 +01:00
|
|
|
|
//dynamicObjects[i]->Release();
|
|
|
|
|
dynamicObjects[i].Release();
|
|
|
|
|
//dynamicObjects.erase(privData->object.begin() + i );
|
2013-12-19 11:58:42 +01:00
|
|
|
|
}
|
2013-12-16 11:08:10 +01:00
|
|
|
|
}
|
2013-12-19 11:58:42 +01:00
|
|
|
|
//privData->object[obj->object_ID]->Release( );
|
2013-12-13 12:02:49 +01:00
|
|
|
|
}
|
2013-12-19 11:58:42 +01:00
|
|
|
|
|
2013-12-13 12:02:49 +01:00
|
|
|
|
//void GameState::Protocol(LightPos pos);
|