Merge remote-tracking branch 'origin/GameClient' into Physics

This commit is contained in:
Robin Engman 2014-02-21 11:58:59 +01:00
commit 3c25bb62ba
11 changed files with 235 additions and 17 deletions

View File

@ -224,6 +224,7 @@
<ClCompile Include="GameClientState\MainState.cpp" />
<ClCompile Include="GameClientState\NetLoadState.cpp" />
<ClCompile Include="GameClientState\RespawnUI.cpp" />
<ClCompile Include="GameClientState\StatsUI.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientState\Buttons\Plane_UI.h" />
@ -251,6 +252,7 @@
<ClInclude Include="GameClientState\NetLoadState.h" />
<ClInclude Include="GameClientState\RespawnUI.h" />
<ClInclude Include="GameClientState\SharedStateContent.h" />
<ClInclude Include="GameClientState\StatsUI.h" />
<ClInclude Include="Include\GameClient.h" />
<ClInclude Include="GameClientState\LobbyState.h" />
<ClInclude Include="GameClientState\C_Object.h" />

View File

@ -21,6 +21,10 @@ namespace DanBias
: pos(pos), size(size), text(text), textColor(textColor)
{
}
void setText(std::wstring text)
{
this->text = text;
}
void RenderText() const
{
if(text.size() > 0)

View File

@ -11,6 +11,7 @@
#include "Utilities.h"
#include "GamingUI.h"
#include "RespawnUI.h"
#include "StatsUI.h"
using namespace ::DanBias::Client;
using namespace ::Oyster;
@ -96,9 +97,11 @@ bool GameState::Init( SharedStateContent &shared )
// create UI states
this->gameUI = new GamingUI(this->privData->input, this->privData->nwClient, &this->privData->camera);
this->respawnUI = new RespawnUI(this->privData->nwClient, 20);
this->statsUI = new StatsUI();
this->currGameUI = gameUI;
((GamingUI*)gameUI)->Init();
// TODO init respawn
((RespawnUI*)respawnUI)->Init();
((StatsUI*)statsUI)->Init();
return true;
}
@ -246,11 +249,23 @@ bool GameState::Render()
//!RB DEBUG
#endif
// render current UI state
Oyster::Graphics::API::StartGuiRender();
// render gui elemnts
if(currGameUI->HaveGUIRender())
currGameUI->RenderGUI();
if(renderStats)
{
if(statsUI->HaveGUIRender())
statsUI->RenderGUI();
}
Oyster::Graphics::API::StartTextRender();
if(currGameUI->HaveTextRender())
currGameUI->RenderText();
if(renderStats)
{
if(statsUI->HaveTextRender())
statsUI->RenderText();
}
Oyster::Graphics::API::EndFrame();
return true;
@ -298,6 +313,12 @@ bool GameState::Release()
delete gameUI;
gameUI = NULL;
}
if(statsUI)
{
statsUI->Release();
delete statsUI;
statsUI = NULL;
}
currGameUI = NULL;
return true;
@ -332,10 +353,33 @@ void GameState::ReadKeyInput()
{
this->renderWhireframe = !this->renderWhireframe;
this->key_Wireframe_Toggle = true;
// DEBUG set you as dead when render wireframe
this->currGameUI = respawnUI;
// !DEBUG
}
}
else
{
this->key_Wireframe_Toggle = false;
// DEBUG set you as dead when render wireframe
this->currGameUI = gameUI;
// !DEBUG
}
// toggle wire frame render
if( this->privData->input->IsKeyPressed(DIK_TAB) )
{
if( !this->key_showStats )
{
this->renderStats = true;
this->key_showStats = true;
}
}
else
{
this->renderStats = false;
this->key_showStats = false;
}
}
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
{
@ -356,8 +400,22 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
switch(ID)
{
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_ObjectDamage:
{
Protocol_ObjectDamage decoded(data);
if( this->privData->myId == decoded.object_ID )
{
if(currGameUI == gameUI)
{
((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost));
}
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectHealthStatus:
{
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectPosition:
{
Protocol_ObjectPosition decoded(data);
@ -494,11 +552,33 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectRespawn:
this->currGameUI = this->gameUI;
{
// set player pos
Protocol_ObjectRespawn decoded(data);
// move player. Remember to change camera
this->privData->camera.SetPosition( decoded.position );
this->privData->player.setPos( decoded.position );
this->privData->player.updateWorld();
// RB DEBUG
this->privData->player.setRBPos ( decoded.position );
this->privData->player.updateRBWorld();
// !RB DEBUG
this->currGameUI = this->gameUI;
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectDie:
this->currGameUI = this->respawnUI;
// set countdown
{
Protocol_ObjectDie decoded(data);
// if is this player. Remember to change camera
if( this->privData->myId == decoded.objectID )
{
this->currGameUI = this->respawnUI;
// set countdown
((RespawnUI*)currGameUI)->SetCountdown( decoded.seconds );
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectDisconnectPlayer:
{
//Removes

View File

@ -32,13 +32,16 @@ namespace DanBias { namespace Client
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
GameStateUI *currGameUI, *gameUI, *respawnUI;
GameStateUI *currGameUI, *gameUI, *respawnUI, *statsUI;
// DEGUG KEYS
bool key_Reload_Shaders;
bool key_Wireframe_Toggle;
bool renderWhireframe;
bool key_showStats;
bool renderStats;
// !DEGUG KEYS
};
} }
#endif

View File

@ -30,6 +30,7 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *
GamingUI::~GamingUI() { /* Do nothing */ }
bool GamingUI::Init()
{
// z value should be between 0.5 - 0.9 so that it will be behind other states
// add textures and text
this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f));
this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f));
@ -54,13 +55,11 @@ bool GamingUI::HaveTextRender() const
void GamingUI::RenderGUI() const
{
Oyster::Graphics::API::StartGuiRender();
this->plane->RenderTexture();
}
void GamingUI::RenderText() const
{
Oyster::Graphics::API::StartTextRender();
this->text->RenderText();
}
@ -73,7 +72,10 @@ bool GamingUI::Release()
delete this->text;
return true;
}
void GamingUI::SetHPtext( std::wstring hp )
{
this->text->setText(hp);
}
void GamingUI::ReadKeyInput()
{
if( this->input->IsKeyPressed(DIK_W) )

View File

@ -22,11 +22,14 @@ namespace DanBias { namespace Client
void RenderGUI() const;
void RenderText() const;
bool Release();
void SetHPtext( std::wstring hp );
private:
InputClass *input;
::Oyster::Network::NetworkClient *netClient;
Camera_FPSV2 *camera;
// TODO add multiple UI elements
Text_UI* text;
Plane_UI* plane;

View File

@ -3,6 +3,7 @@
using namespace ::DanBias::Client;
using namespace ::Oyster::Network;
using namespace ::Utility::Value;
using namespace ::Oyster::Math;
RespawnUI::RespawnUI() :
GameStateUI()
@ -17,13 +18,23 @@ RespawnUI::RespawnUI( NetworkClient *connection, float delay ) :
{
this->netClient = connection;
this->countDown = delay;
this->text = nullptr;
}
RespawnUI::~RespawnUI() { /* Do nothing */ }
bool RespawnUI::Init()
{
// z value should be between 0.5 - 0.9 so that it will be behind other states
// add textures and text
this->text = new Text_UI(L"DEAD", Float3(0.5f,0.0f,0.5f), Float2(0.2f,0.2f));
return true;
}
GameStateUI::UIState RespawnUI::Update( float deltaTime )
{
this->countDown = Max( this->countDown - deltaTime, 0.0f );
// countDown == 0
// return UIState_gaming state;
return this->nextState;
}
@ -34,25 +45,32 @@ bool RespawnUI::HaveGUIRender() const
bool RespawnUI::HaveTextRender() const
{
return false; // TODO: change to true when we want UI elements like a chat window
return true; // TODO: change to true when we want UI elements like a chat window
}
void RespawnUI::RenderGUI() const
{
// TODO: We need?
// TODO:BLOODY SCREEN
}
void RespawnUI::RenderText() const
{
this->text->RenderText();
// TODO: Text countdown somewhere on screen would be nice
}
bool RespawnUI::Release()
{
// TODO: Release UI components here.
if(this->text)
delete this->text;
return true;
}
void RespawnUI::SetCountdown( float cd )
{
this->countDown = cd;
// this text should be rendered
}

View File

@ -2,6 +2,8 @@
#define DANBIAS_CLIENT_RESPAWN_UI_H
#include "GameStateUI.h"
#include "Buttons\Text_UI.h"
#include "Buttons\Plane_UI.h"
namespace DanBias { namespace Client
{
@ -10,18 +12,23 @@ namespace DanBias { namespace Client
public:
RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay );
virtual ~RespawnUI();
bool Init();
// TODO countdown
UIState Update( float deltaTime );
bool HaveGUIRender() const;
bool HaveTextRender() const;
void RenderGUI() const;
void RenderText() const;
bool Release();
void SetCountdown( float cd );
private:
::Oyster::Network::NetworkClient *netClient;
float countDown;
// TODO add multiple UI elements
Text_UI* text;
RespawnUI();
};
} }

View File

@ -0,0 +1,65 @@
#include "StatsUI.h"
#include <Protocols.h>
#include "Utilities.h"
using namespace ::DanBias::Client;
using namespace ::GameLogic;
using namespace ::Utility::Value;
using namespace ::Oyster::Math;
StatsUI::StatsUI() :
GameStateUI()
{
/* Should never be called! */
this->plane = nullptr;
this->text = nullptr;
}
StatsUI::~StatsUI() { /* Do nothing */ }
bool StatsUI::Init()
{
// z value should be between 0.1 - 0.5 so that it will be in front of other states
// add textures and text for player stats
this->plane = new Plane_UI(L"box_tex.png", Float3(0.0f, 0.0f, 0.5f), Float2(0.3f, 0.1f));
this->text = new Text_UI(L"Stats", Float3(0.0f,0.0f,0.1f), Float2(0.1f,0.1f));
return true;
}
GameStateUI::UIState StatsUI::Update( float deltaTime )
{
return this->nextState;
}
bool StatsUI::HaveGUIRender() const
{
// Set true if UIstate have any plane to render
return true;
}
bool StatsUI::HaveTextRender() const
{
// Set true if UIstate have any text to render
return true;
}
void StatsUI::RenderGUI() const
{
// render all the planes
this->plane->RenderTexture();
}
void StatsUI::RenderText() const
{
// render all the text
this->text->RenderText();
}
bool StatsUI::Release()
{
// TODO: Release UI components here.
if(this->plane)
delete this->plane;
if(this->text)
delete this->text;
return true;
}

View File

@ -0,0 +1,34 @@
#ifndef DANBIAS_CLIENT_STATS_UI_H
#define DANBIAS_CLIENT_STATS_UI_H
#include "GameStateUI.h"
#include "Buttons\Text_UI.h"
#include "Buttons\Plane_UI.h"
namespace DanBias { namespace Client
{
class StatsUI : public GameStateUI
{
public:
StatsUI();
virtual ~StatsUI();
bool Init();
UIState Update( float deltaTime );
bool HaveGUIRender() const;
bool HaveTextRender() const;
void RenderGUI() const;
void RenderText() const;
bool Release();
// TODO add function to add a new players statistics
// TODO add function to remove a players statistics
private:
// TODO add multiple UI elements
// one for each player ingame
Text_UI* text;
Plane_UI* plane;
};
} }
#endif

View File

@ -234,7 +234,7 @@ bool GameSession::Join(gClient gameClient)
{
//Protocol_ObjectPosition p(movedObject->GetPosition(), id);
Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID());
GameSession::gameSession->Send(p.GetProtocol());
nwClient->Send(p.GetProtocol());
}
}