GL - gameState merge

This commit is contained in:
lindaandersson 2014-01-27 13:25:09 +01:00
parent 74ac5e2d31
commit 5b984db9ba
2 changed files with 104 additions and 151 deletions

View File

@ -44,7 +44,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameP
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Game\DanBiasServerLauncher\DanBiasServerLauncher.vcxproj", "{060B1890-CBF3-4808-BA99-A4776222093B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Physics lab", "Physics lab\Physics lab.vcxproj", "{5128BD77-6472-4C4A-BE6F-724AD0E589C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -272,18 +272,18 @@ Global
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|Win32.Build.0 = Release|Win32
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.ActiveCfg = Release|x64
{060B1890-CBF3-4808-BA99-A4776222093B}.Release|x64.Build.0 = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Win32.ActiveCfg = Debug|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|Win32.Build.0 = Debug|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|x64.ActiveCfg = Debug|x64
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Debug|x64.Build.0 = Debug|x64
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Mixed Platforms.Build.0 = Release|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.ActiveCfg = Release|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.Build.0 = Release|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.ActiveCfg = Release|x64
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -299,6 +299,5 @@ Global
{8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{060B1890-CBF3-4808-BA99-A4776222093B} = {20720CA7-795C-45AD-A302-9383A6DD503A}
{666FEA52-975F-41CD-B224-B19AF3C0ABBA} = {20720CA7-795C-45AD-A302-9383A6DD503A}
EndGlobalSection
EndGlobal

View File

@ -4,7 +4,7 @@
#include "C_obj/C_DynamicObj.h"
#include <Protocols.h>
#include "NetworkClient.h"
#include "Camera.h"
using namespace DanBias::Client;
@ -17,6 +17,7 @@ struct GameState::myData
int modelCount;
Oyster::Network::NetworkClient* nwClient;
gameStateState state;
}privData;
@ -37,35 +38,22 @@ GameState::~GameState(void)
bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
{
// load models
camera = new Camera;
privData = new myData();
privData->state = gameStateState_loading;
privData->nwClient = nwClient;
privData->state = LoadGame();
return true;
}
GameState::gameStateState GameState::LoadGame()
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(0,15,5);
plight.Pos = Oyster::Math::Float3(0,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 50;
plight.Radius = 5;
plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Oyster::Math::Float3(10,15,5);
plight.Color = Oyster::Math::Float3(1,0,0);
plight.Radius = 50;
plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Oyster::Math::Float3(10,-15,5);
plight.Color = Oyster::Math::Float3(0,0,1);
plight.Radius = 50;
plight.Bright = 2;
Oyster::Graphics::API::AddLight(plight);
LoadModels(L"map");
InitCamera(Oyster::Math::Float3(0,0,20.0f));
InitCamera(Oyster::Math::Float3(0,0,5.4f));
return gameStateState_playing;
}
bool GameState::LoadModels(std::wstring mapFile)
@ -101,15 +89,6 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
modelData.id ++;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
scale.v[0].x = 8;
scale.v[1].y = 8;
scale.v[2].z = 8;
modelData.world = scale; //modelData.world * translate
modelData.modelPath = L"ball.dan";
modelData.id ++;
obj = new C_DynamicObj();
privData->object.push_back(obj);
@ -120,19 +99,10 @@ bool GameState::LoadModels(std::wstring mapFile)
}
bool GameState::InitCamera(Oyster::Math::Float3 startPos)
{
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,-1);
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 20);
camera->LookAt(pos, dir, up);
camera->SetLens(3.14f/2, 1024/768, 1, 1000);
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
camera->UpdateViewMatrix();
privData->view = camera->View();
privData->view = Oyster::Math3D::ViewMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
@ -157,9 +127,84 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
// read server data
// update objects
{
readKeyInput(KeyInput);
camera->UpdateViewMatrix();
bool send = false;
GameLogic::Protocol_PlayerMovement movePlayer;
movePlayer.bForward = false;
movePlayer.bBackward = false;
movePlayer.bStrafeLeft = false;
movePlayer.bStrafeRight = false;
movePlayer.bTurnLeft = false;
movePlayer.bTurnRight = false;
if(KeyInput->IsKeyPressed(DIK_W))
{
if(!key_forward)
{
movePlayer.bForward = true;
send = true;
key_forward = true;
}
}
else
key_forward = false;
if(KeyInput->IsKeyPressed(DIK_S))
{
if(!key_backward)
{
movePlayer.bBackward = true;
send = true;
key_backward = true;
}
}
else
key_backward = false;
if(KeyInput->IsKeyPressed(DIK_A))
{
if(!key_strafeLeft)
{
movePlayer.bStrafeLeft = true;
send = true;
key_strafeLeft = true;
}
}
else
key_strafeLeft = false;
if(KeyInput->IsKeyPressed(DIK_D))
{
if(!key_strafeRight)
{
movePlayer.bStrafeRight = true;
send = true;
key_strafeRight = true;
}
}
else
key_strafeRight = false;
if (privData->nwClient->IsConnected() && send)
{
privData->nwClient->Send(movePlayer);
}
//send delta mouse movement
if (KeyInput->IsMousePressed())
{
GameLogic::Protocol_PlayerMouse deltaMouseMove;
deltaMouseMove.dxMouse = KeyInput->GetYaw();
deltaMouseMove.dyMouse = KeyInput->GetPitch();
//privData->nwClient->Send(deltaMouseMove);
}
// send event data
//
if(KeyInput->IsKeyPressed(DIK_L))
privData->state = GameState::gameStateState_end;
}
break;
case gameStateState_end:
@ -174,12 +219,10 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
}
bool GameState::Render()
{
Oyster::Graphics::API::SetView(camera->View());
//Oyster::Graphics::API::SetProjection(camera->Proj());
//Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection(privData->proj);
Oyster::Graphics::API::NewFrame();
for (unsigned int i = 0; i < privData->object.size(); i++)
for (int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Render();
}
@ -188,7 +231,7 @@ bool GameState::Render()
}
bool GameState::Release()
{
for (unsigned int i = 0; i < privData->object.size(); i++)
for (int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
@ -199,93 +242,6 @@ bool GameState::Release()
privData = NULL;
return true;
}
void GameState::readKeyInput(InputClass* KeyInput)
{
bool send = false;
GameLogic::Protocol_PlayerMovement movePlayer;
movePlayer.bForward = false;
movePlayer.bBackward = false;
movePlayer.bLeft = false;
movePlayer.bRight = false;
if(KeyInput->IsKeyPressed(DIK_W))
{
if(!key_forward)
{
movePlayer.bForward = true;
send = true;
key_forward = true;
}
}
else
key_forward = false;
if(KeyInput->IsKeyPressed(DIK_S))
{
if(!key_backward)
{
movePlayer.bBackward = true;
send = true;
key_backward = true;
}
}
else
key_backward = false;
if(KeyInput->IsKeyPressed(DIK_A))
{
if(!key_strafeLeft)
{
movePlayer.bLeft = true;
send = true;
key_strafeLeft = true;
}
}
else
key_strafeLeft = false;
if(KeyInput->IsKeyPressed(DIK_D))
{
if(!key_strafeRight)
{
movePlayer.bRight = true;
send = true;
key_strafeRight = true;
}
}
else
key_strafeRight = false;
if (privData->nwClient->IsConnected() && send)
{
privData->nwClient->Send(movePlayer);
}
//send delta mouse movement
if (KeyInput->IsMousePressed())
{
camera->Yaw(KeyInput->GetYaw());
camera->Pitch(KeyInput->GetPitch());
camera->UpdateViewMatrix();
GameLogic::Protocol_PlayerLook playerLookDir;
Oyster::Math::Float3 look = camera->GetLook();
playerLookDir.lookDirX = look.x;
playerLookDir.lookDirY = look.y;
playerLookDir.lookDirZ = look.z;
privData->nwClient->Send(playerLookDir);
}
// send event data
//
if(KeyInput->IsKeyPressed(DIK_L))
privData->state = GameState::gameStateState_end;
}
void GameState::Protocol(ProtocolStruct* pos)
{
@ -311,16 +267,14 @@ void GameState::Protocol( ObjPos* pos )
world[i] = pos->worldPos[i];
}
for (unsigned int i = 0; i < privData->object.size(); i++)
for (int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i]->GetId() == pos->object_ID)
{
privData->object[i]->setPos(world);
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
//camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6])));
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
camera->UpdateViewMatrix();
//privData->view = world;
//privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
}
}
@ -352,7 +306,7 @@ void GameState::Protocol( NewObj* newObj )
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
{
for (unsigned int i = 0; i < privData->object.size(); i++)
for (int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i]->GetId() == obj->object_ID)
{