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

This commit is contained in:
Erik Persson 2014-02-21 09:48:54 +01:00
commit 623359dd66
15 changed files with 288 additions and 227 deletions

View File

@ -226,6 +226,8 @@
<ClCompile Include="GameClientState\RespawnUI.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientState\Buttons\Plane_UI.h" />
<ClInclude Include="GameClientState\Buttons\Text_UI.h" />
<ClInclude Include="GameClientState\Camera_Basic.h" />
<ClInclude Include="GameClientState\Buttons\ButtonEllipse.h" />
<ClInclude Include="GameClientState\Buttons\EventButtonGUI.h" />

View File

@ -113,7 +113,7 @@ namespace DanBias
{
if(buttonText.size() > 0)
{
Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, -0.001f), size, size.y * 0.5f, textColor);
Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, +0.001f), size, size.y * 0.5f, textColor);
}
}

View File

@ -0,0 +1,51 @@
#ifndef DANBIAS_CLIENT_PLANE_UI_H
#define DANBIAS_CLIENT_PLANE_UI_H
#include "DllInterfaces/GFXAPI.h"
namespace DanBias
{
namespace Client
{
class Plane_UI
{
public:
Plane_UI( )
{
pos = Oyster::Math::Float3::null;
size = Oyster::Math::Float2::null;
tintColor = Oyster::Math::Float4(1);
texture = NULL;
}
Plane_UI( std::wstring textureName, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, Oyster::Math::Float4 tintColor = Oyster::Math::Float4(1))
: pos(pos), size(size), tintColor(tintColor)
{
CreateTexture(textureName);
}
virtual ~Plane_UI()
{
Oyster::Graphics::API::DeleteTexture(texture);
texture = NULL;
}
void CreateTexture(std::wstring textureName)
{
//Create texture
texture = Oyster::Graphics::API::CreateTexture(textureName);
}
virtual void RenderTexture() const
{
if(texture)
Oyster::Graphics::API::RenderGuiElement(texture, pos, size, tintColor);
}
private:
Oyster::Math::Float3 pos;
Oyster::Math::Float2 size;
Oyster::Graphics::API::Texture texture;
Oyster::Math::Float4 tintColor;
};
}
}
#endif

View File

@ -0,0 +1,41 @@
#ifndef DANBIAS_CLIENT_TEXT_UI_H
#define DANBIAS_CLIENT_TEXT_UI_H
#include "DllInterfaces/GFXAPI.h"
namespace DanBias
{
namespace Client
{
class Text_UI
{
public:
Text_UI( )
{
pos = Oyster::Math::Float3::null;
size = Oyster::Math::Float2::null;
text = L"";
textColor = Oyster::Math::Float4(1);
}
Text_UI(std::wstring text, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, Oyster::Math::Float4 textColor = Oyster::Math::Float4(1))
: pos(pos), size(size), text(text), textColor(textColor)
{
}
void RenderText() const
{
if(text.size() > 0)
{
Oyster::Graphics::API::RenderText(text, pos, size, size.y * 0.5f, textColor);
}
}
private:
Oyster::Math::Float3 pos;
Oyster::Math::Float2 size;
std::wstring text;
Oyster::Math::Float4 textColor;
};
}
}
#endif

View File

@ -9,6 +9,8 @@
#include "C_obj/C_DynamicObj.h"
#include "C_obj/C_StaticObj.h"
#include "Utilities.h"
#include "GamingUI.h"
#include "RespawnUI.h"
using namespace ::DanBias::Client;
using namespace ::Oyster;
@ -30,19 +32,6 @@ struct GameState::MyData
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> *lights;
bool key_forward;
bool key_backward;
bool key_strafeRight;
bool key_strafeLeft;
bool key_Shoot;
bool key_Jump;
// DEGUG KEYS
bool key_Reload_Shaders;
bool key_Wireframe_Toggle;
bool renderWhireframe;
// !DEGUG KEYS
C_Player player;
Camera_FPSV2 camera;
@ -73,11 +62,6 @@ bool GameState::Init( SharedStateContent &shared )
this->privData = new MyData();
this->privData->key_forward = false;
this->privData->key_backward = false;
this->privData->key_strafeRight = false;
this->privData->key_strafeLeft = false;
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
@ -98,9 +82,9 @@ bool GameState::Init( SharedStateContent &shared )
this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) );
// DEGUG KEYS
this->privData->key_Reload_Shaders = false;
this->privData->key_Wireframe_Toggle = false;
this->privData->renderWhireframe = false;
this->key_Reload_Shaders = false;
this->key_Wireframe_Toggle = false;
this->renderWhireframe = false;
// !DEGUG KEYS
auto light = this->privData->lights->begin();
@ -109,6 +93,12 @@ bool GameState::Init( SharedStateContent &shared )
light->second->Render();
}
// 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->currGameUI = gameUI;
((GamingUI*)gameUI)->Init();
// TODO init respawn
return true;
}
@ -165,7 +155,25 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
GameClientState::ClientState GameState::Update( float deltaTime )
{
this->ReadKeyInput();
GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime );
switch (UIstate)
{
case DanBias::Client::GameStateUI::UIState_same:
break;
case DanBias::Client::GameStateUI::UIState_gaming:
break;
case DanBias::Client::GameStateUI::UIState_main_menu:
//this->privData->nextState =
break;
case DanBias::Client::GameStateUI::UIState_shut_down:
this->privData->nextState = ClientState_Quit;
break;
default:
break;
}
// DEBUG keybindings
ReadKeyInput();
return this->privData->nextState;
}
@ -194,16 +202,9 @@ bool GameState::Render()
}
}
/*auto light = this->privData->lights->begin();
for( ; light != this->privData->lights->end(); ++light )
{
light->second->Render();
}*/
#ifdef _DEBUG
//RB DEBUG render wire frame
if(this->privData->renderWhireframe)
if(this->renderWhireframe)
{
Oyster::Graphics::API::StartRenderWireFrame();
@ -245,6 +246,12 @@ bool GameState::Render()
//!RB DEBUG
#endif
// render current UI state
if(currGameUI->HaveGUIRender())
currGameUI->RenderGUI();
if(currGameUI->HaveTextRender())
currGameUI->RenderText();
Oyster::Graphics::API::EndFrame();
return true;
}
@ -278,6 +285,21 @@ bool GameState::Release()
privData = NULL;
}
if(respawnUI)
{
respawnUI->Release();
delete respawnUI;
respawnUI = NULL;
}
if(gameUI)
{
gameUI->Release();
delete gameUI;
gameUI = NULL;
}
currGameUI = NULL;
return true;
}
@ -285,152 +307,36 @@ void GameState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
void GameState::ReadKeyInput()
{
if( this->privData->input->IsKeyPressed(DIK_W) )
{
//if(!this->privData->key_forward)
{
this->privData->nwClient->Send( Protocol_PlayerMovementForward() );
this->privData->key_forward = true;
}
}
else
this->privData->key_forward = false;
if( this->privData->input->IsKeyPressed(DIK_S) )
{
//if( !this->privData->key_backward )
{
this->privData->nwClient->Send( Protocol_PlayerMovementBackward() );
this->privData->key_backward = true;
}
}
else
this->privData->key_backward = false;
if( this->privData->input->IsKeyPressed(DIK_A) )
{
//if( !this->privData->key_strafeLeft )
{
this->privData->nwClient->Send( Protocol_PlayerMovementLeft() );
this->privData->key_strafeLeft = true;
}
}
else
this->privData->key_strafeLeft = false;
if( this->privData->input->IsKeyPressed(DIK_D) )
{
//if( !this->privData->key_strafeRight )
{
this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
this->privData->key_strafeRight = true;
}
}
else
this->privData->key_strafeRight = false;
//send delta mouse movement
{
static const float mouseSensitivity = Radian( 1.0f );
this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity );
float yaw = this->privData->input->GetYaw();
//if( yaw != 0.0f ) //This made the camera reset to a specific rotation.
{
this->privData->nwClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) );
}
}
// shoot
if( this->privData->input->IsKeyPressed(DIK_Z) )
{
if( !this->privData->key_Shoot )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = true;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = false;
this->privData->nwClient->Send( playerShot );
this->privData->key_Shoot = true;
}
}
else
this->privData->key_Shoot = false;
if( this->privData->input->IsKeyPressed(DIK_X) )
{
if( !this->privData->key_Shoot )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = true;
playerShot.utilityPressed = false;
this->privData->nwClient->Send( playerShot );
this->privData->key_Shoot = true;
}
}
else
this->privData->key_Shoot = false;
if( this->privData->input->IsKeyPressed(DIK_C) )
{
if( !this->privData->key_Shoot )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = true;
this->privData->nwClient->Send( playerShot );
this->privData->key_Shoot = true;
}
}
else
this->privData->key_Shoot = false;
// jump
if( this->privData->input->IsKeyPressed(DIK_SPACE) )
{
if(!this->privData->key_Jump)
{
this->privData->nwClient->Send( Protocol_PlayerJump() );
this->privData->key_Jump = true;
}
}
else
this->privData->key_Jump = false;
// DEGUG KEYS
// Reload shaders
if( this->privData->input->IsKeyPressed(DIK_R) )
{
if( !this->privData->key_Reload_Shaders )
if( !this->key_Reload_Shaders )
{
#ifdef _DEBUG
Graphics::API::ReloadShaders();
Oyster::Graphics::API::ReloadShaders();
#endif
this->privData->key_Reload_Shaders = true;
this->key_Reload_Shaders = true;
}
}
else
this->privData->key_Reload_Shaders = false;
this->key_Reload_Shaders = false;
// toggle wire frame render
if( this->privData->input->IsKeyPressed(DIK_T) )
{
if( !this->privData->key_Wireframe_Toggle )
if( !this->key_Wireframe_Toggle )
{
this->privData->renderWhireframe = !this->privData->renderWhireframe;
this->privData->key_Wireframe_Toggle = true;
this->renderWhireframe = !this->renderWhireframe;
this->key_Wireframe_Toggle = true;
}
}
else
this->privData->key_Wireframe_Toggle = false;
// !DEGUG KEYS
// TODO: implement sub-menu
this->key_Wireframe_Toggle = false;
}
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
{
if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend )
@ -587,8 +493,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
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 */
case protocol_Gameplay_ObjectRespawn:
this->currGameUI = this->gameUI;
return GameClientState::event_processed;
case protocol_Gameplay_ObjectDie:
this->currGameUI = this->respawnUI;
// set countdown
case protocol_Gameplay_ObjectDisconnectPlayer:
{
//Removes

View File

@ -3,6 +3,7 @@
#include "GameClientState.h"
#include "OysterMath.h"
#include <string>
#include "GameStateUI.h"
namespace DanBias { namespace Client
{
@ -31,6 +32,13 @@ namespace DanBias { namespace Client
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
GameStateUI *currGameUI, *gameUI, *respawnUI;
// DEGUG KEYS
bool key_Reload_Shaders;
bool key_Wireframe_Toggle;
bool renderWhireframe;
// !DEGUG KEYS
};
} }
#endif

View File

@ -1,5 +1,5 @@
#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H
#define DANBIAS_CLIENT_GAMECLIENTSTATE_H
#ifndef DANBIAS_CLIENT_GAMESTATEUI_H
#define DANBIAS_CLIENT_GAMESTATEUI_H
#include "Utilities.h"
#include "NetworkClient.h"

View File

@ -6,6 +6,7 @@ using namespace ::DanBias::Client;
using namespace ::Oyster::Network;
using namespace ::GameLogic;
using namespace ::Utility::Value;
using namespace ::Oyster::Math;
GamingUI::GamingUI() :
GameStateUI()
@ -14,6 +15,8 @@ GamingUI::GamingUI() :
this->input = nullptr;
this->netClient = nullptr;
this->camera = nullptr;
this->plane = nullptr;
this->text = nullptr;
}
GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) :
@ -25,35 +28,49 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *
}
GamingUI::~GamingUI() { /* Do nothing */ }
bool GamingUI::Init()
{
// 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));
return true;
}
GameStateUI::UIState GamingUI::Update( float deltaTime )
{
ReadKeyInput();
return this->nextState;
}
bool GamingUI::HaveGUIRender() const
{
return false; // TODO: change to true when we want UI elements like a crosshair
return true;
}
bool GamingUI::HaveTextRender() const
{
return false; // TODO: change to true when we want UI elements like a chat window
return true;
}
void GamingUI::RenderGUI() const
{
// TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender
Oyster::Graphics::API::StartGuiRender();
this->plane->RenderTexture();
}
void GamingUI::RenderText() const
{
// TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender
Oyster::Graphics::API::StartTextRender();
this->text->RenderText();
}
bool GamingUI::Release()
{
// TODO: Release UI components here.
if(this->plane)
delete this->plane;
if(this->text)
delete this->text;
return true;
}
@ -79,75 +96,78 @@ void GamingUI::ReadKeyInput()
this->netClient->Send( Protocol_PlayerMovementRight() );
}
// if( this->input->IsKeyPressed(DIK_R) )
// {
// if( !this->key_Reload_Shaders )
// {
//#ifdef _DEBUG
// Graphics::API::ReloadShaders();
//#endif
// this->key_Reload_Shaders = true;
// }
// }
// else
// this->key_Reload_Shaders = false;
//send delta mouse movement
//send delta mouse movement
{
static const float mouseSensitivity = Radian( 1.0f );
this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity );
this->netClient->Send( Protocol_PlayerLeftTurn(this->input->GetYaw() * mouseSensitivity) );
float yaw = this->input->GetYaw();
//if( yaw != 0.0f ) //This made the camera reset to a specific rotation.
{
this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) );
}
}
// shoot
//if( this->input->IsKeyPressed(DIK_Z) )
//{
// if( !this->key_Shoot )
// {
// Protocol_PlayerShot playerShot;
// playerShot.primaryPressed = true;
// playerShot.secondaryPressed = false;
// playerShot.utilityPressed = false;
// this->netClient->Send( playerShot );
// this->key_Shoot = true;
// }
//}
//else
// this->key_Shoot = false;
//if( this->input->IsKeyPressed(DIK_X) )
//{
// if( !this->key_Shoot )
// {
// Protocol_PlayerShot playerShot;
// playerShot.primaryPressed = false;
// playerShot.secondaryPressed = true;
// playerShot.utilityPressed = false;
// this->netClient->Send( playerShot );
// this->key_Shoot = true;
// }
//}
//else
// this->key_Shoot = false;
//if( this->input->IsKeyPressed(DIK_C) )
//{
// if( !this->key_Shoot )
// {
// Protocol_PlayerShot playerShot;
// playerShot.primaryPressed = false;
// playerShot.secondaryPressed = false;
// playerShot.utilityPressed = true;
// this->netClient->Send( playerShot );
// this->key_Shoot = true;
// }
//}
//else
// this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_Z) )
{
if( !this->key_Shoot )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = true;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = false;
this->netClient->Send( playerShot );
this->key_Shoot = true;
}
}
else
this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_X) )
{
if( !this->key_Shoot )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = true;
playerShot.utilityPressed = false;
this->netClient->Send( playerShot );
this->key_Shoot = true;
}
}
else
this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_C) )
{
if( !this->key_Shoot )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = true;
this->netClient->Send( playerShot );
this->key_Shoot = true;
}
}
else
this->key_Shoot = false;
// jump
if( this->input->IsKeyPressed(DIK_SPACE) )
{
this->netClient->Send( Protocol_PlayerJump() );
if(!this->key_Jump)
{
this->netClient->Send( Protocol_PlayerJump() );
this->key_Jump = true;
}
}
else
this->key_Jump = false;
if( this->input->IsKeyPressed(DIK_ESCAPE) )
{
this->nextState = GameStateUI::UIState_shut_down;
}
// !DEGUG KEYS
// TODO: implement sub-menu
}

View File

@ -4,6 +4,8 @@
#include "GameStateUI.h"
#include "L_inputClass.h"
#include "Camera_FPSV2.h"
#include "Buttons\Text_UI.h"
#include "Buttons\Plane_UI.h"
namespace DanBias { namespace Client
{
@ -12,6 +14,7 @@ namespace DanBias { namespace Client
public:
GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera );
virtual ~GamingUI();
bool Init();
UIState Update( float deltaTime );
bool HaveGUIRender() const;
@ -24,6 +27,15 @@ namespace DanBias { namespace Client
InputClass *input;
::Oyster::Network::NetworkClient *netClient;
Camera_FPSV2 *camera;
Text_UI* text;
Plane_UI* plane;
bool key_forward;
bool key_backward;
bool key_strafeRight;
bool key_strafeLeft;
bool key_Shoot;
bool key_Jump;
GamingUI();
void ReadKeyInput();

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>

View File

@ -56,8 +56,8 @@ namespace Oyster
//size.x = size.x / (text.length() * TEXT_SPACING /2);
pos *= 2;
pos -= 1;
pos.xy *= 2;
pos.xy -= 1;
pos.y *= -1;

View File

@ -43,4 +43,5 @@ void main( uint3 DTid : SV_DispatchThreadID )
//Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(Output.Length*0.5f)].xyz,1);
//Output[DTid.xy] = SSAO * float4(1,1,1,1);
//Output[DTid.xy] = Ambient[DTid.xy];
}

View File

@ -413,3 +413,13 @@ float SimpleRigidBody::GetLambda() const
{
return this->rayLambda[0];
}
void SimpleRigidBody::MoveToLimbo()
{
this->rigidBody->setCollisionFlags(this->rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
}
void SimpleRigidBody::ReleaseFromLimbo()
{
this->rigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
}

View File

@ -69,6 +69,9 @@ namespace Oyster
float GetLambda() const;
void MoveToLimbo();
void ReleaseFromLimbo();
private:
btCollisionShape* collisionShape;

View File

@ -169,6 +169,9 @@ namespace Oyster
virtual void CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss) = 0;
virtual void CallSubscription_Move() = 0;
virtual void MoveToLimbo() = 0;
virtual void ReleaseFromLimbo() = 0;
/********************************************************
* @return the void pointer set by SetCustomTag.
* nullptr if none is set.