2013-12-06 10:38:43 +01:00
|
|
|
#include "GameState.h"
|
|
|
|
#include "DllInterfaces/GFXAPI.h"
|
2013-12-10 11:26:18 +01:00
|
|
|
#include "Obj/C_Player.h"
|
|
|
|
#include "Obj/C_DynamicObj.h"
|
2013-12-13 12:02:49 +01:00
|
|
|
#include "NetworkClient.h"
|
|
|
|
#include "PlayerProtocols.h"
|
2013-12-10 11:26:18 +01:00
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
using namespace DanBias::Client;
|
2013-12-09 09:23:39 +01:00
|
|
|
|
|
|
|
struct GameState::myData
|
|
|
|
{
|
|
|
|
myData(){}
|
|
|
|
Oyster::Math3D::Float4x4 view;
|
|
|
|
Oyster::Math3D::Float4x4 proj;
|
2013-12-10 11:26:18 +01:00
|
|
|
C_Object* object[3];
|
|
|
|
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-13 12:02:49 +01:00
|
|
|
|
2013-12-09 09:23:39 +01:00
|
|
|
}privData;
|
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
GameState::GameState(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GameState::~GameState(void)
|
|
|
|
{
|
2013-12-09 11:05:47 +01:00
|
|
|
|
2013-12-06 10:38:43 +01:00
|
|
|
}
|
|
|
|
bool GameState::Init()
|
|
|
|
{
|
2013-12-10 11:26:18 +01:00
|
|
|
// load models
|
|
|
|
privData = new myData();
|
|
|
|
privData->state = gameStateState_loading;
|
|
|
|
privData->state = LoadGame();
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-13 12:02:49 +01:00
|
|
|
GameState::gameStateState GameState::LoadGame()
|
2013-12-10 11:26:18 +01:00
|
|
|
{
|
|
|
|
LoadModels(L"map");
|
|
|
|
InitCamera(Oyster::Math::Float3(0,0,5.4f));
|
|
|
|
return gameStateState_playing;
|
|
|
|
}
|
|
|
|
bool GameState::LoadModels(std::wstring mapFile)
|
|
|
|
{
|
|
|
|
// open file
|
|
|
|
// read file
|
|
|
|
// init models
|
|
|
|
privData->modelCount = 2;
|
|
|
|
|
2013-12-09 12:01:36 +01:00
|
|
|
ModelInitData modelData;
|
|
|
|
|
|
|
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
|
|
|
modelData.visible = true;
|
|
|
|
modelData.modelPath = L"worldDummy";
|
2013-12-09 09:23:39 +01:00
|
|
|
// load models
|
2013-12-10 11:26:18 +01:00
|
|
|
privData->object[0] = new C_Player();
|
|
|
|
privData->object[0]->Init(modelData);
|
2013-12-09 09:23:39 +01:00
|
|
|
|
2013-12-10 11:26:18 +01:00
|
|
|
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2));
|
|
|
|
modelData.world = modelData.world * translate;
|
|
|
|
modelData.modelPath = L"crate";
|
|
|
|
|
|
|
|
privData->object[1] = new C_DynamicObj();
|
|
|
|
privData->object[1]->Init(modelData);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool GameState::InitCamera(Oyster::Math::Float3 startPos)
|
|
|
|
{
|
2013-12-09 09:23:39 +01:00
|
|
|
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
|
2013-12-10 11:26:18 +01:00
|
|
|
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
|
2013-12-09 09:23:39 +01:00
|
|
|
Oyster::Graphics::API::SetProjection(privData->proj);
|
|
|
|
|
2013-12-10 11:26:18 +01:00
|
|
|
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
|
2013-12-09 09:23:39 +01:00
|
|
|
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
|
2013-12-06 10:38:43 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-10 11:26:18 +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)
|
|
|
|
{
|
|
|
|
case gameStateState_loading:
|
|
|
|
// load map
|
|
|
|
// wait for all players
|
|
|
|
LoadGame();
|
|
|
|
privData->state = gameStateState_playing;
|
|
|
|
break;
|
|
|
|
case gameStateState_playing:
|
|
|
|
// read server data
|
|
|
|
// update objects
|
2013-12-11 12:14:00 +01:00
|
|
|
// Client.send(obj);
|
2013-12-13 12:02:49 +01:00
|
|
|
{
|
|
|
|
GameLogic::Protocol_PlayerMovement movePlayer;
|
|
|
|
|
|
|
|
//privData->nwClient->Send(movePlayer);
|
2013-12-11 12:14:00 +01:00
|
|
|
|
2013-12-10 11:26:18 +01:00
|
|
|
if(KeyInput->IsKeyPressed(DIK_L))
|
|
|
|
privData->state = GameState::gameStateState_end;
|
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;
|
|
|
|
}
|
|
|
|
bool GameState::Render()
|
|
|
|
{
|
2013-12-09 09:23:39 +01:00
|
|
|
Oyster::Graphics::API::SetView(privData->view);
|
2013-12-10 11:26:18 +01:00
|
|
|
Oyster::Graphics::API::SetProjection(privData->proj);
|
2013-12-09 09:23:39 +01:00
|
|
|
Oyster::Graphics::API::NewFrame();
|
2013-12-10 11:26:18 +01:00
|
|
|
for (int i = 0; i < privData->modelCount; i++)
|
|
|
|
{
|
|
|
|
privData->object[i]->Render();
|
|
|
|
}
|
2013-12-06 10:38:43 +01:00
|
|
|
Oyster::Graphics::API::EndFrame();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool GameState::Release()
|
|
|
|
{
|
2013-12-10 11:26:18 +01:00
|
|
|
for (int i = 0; i < privData->modelCount; i++)
|
|
|
|
{
|
|
|
|
privData->object[i]->Release();
|
|
|
|
delete privData->object[i];
|
|
|
|
privData->object[i] = NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void GameState::Protocol(ProtocolStruct* pos)
|
|
|
|
{
|
|
|
|
if((ObjPos*)pos)
|
|
|
|
ObjectPosProtocol((ObjPos*)pos);
|
|
|
|
else if((PlayerPos*)pos)
|
|
|
|
PlayerPosProtocol((PlayerPos*)pos);
|
|
|
|
}
|
|
|
|
void GameState::PlayerPosProtocol(PlayerPos* pos)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void GameState::ObjectPosProtocol(ObjPos* pos)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
//void GameState::Protocol(LightPos pos);
|