Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameServer

This commit is contained in:
dean11 2014-02-19 13:50:32 +01:00
commit d4baf33ef5
15 changed files with 396 additions and 70 deletions

View File

@ -215,12 +215,15 @@
<ClCompile Include="DLLMain.cpp" /> <ClCompile Include="DLLMain.cpp" />
<ClCompile Include="GameClientState\GameClientState.cpp" /> <ClCompile Include="GameClientState\GameClientState.cpp" />
<ClCompile Include="GameClientState\GameState.cpp" /> <ClCompile Include="GameClientState\GameState.cpp" />
<ClCompile Include="GameClientState\GameStateUI.cpp" />
<ClCompile Include="GameClientState\GamingUI.cpp" />
<ClCompile Include="GameClientState\LanMenuState.cpp" /> <ClCompile Include="GameClientState\LanMenuState.cpp" />
<ClCompile Include="GameClientState\LobbyAdminState.cpp" /> <ClCompile Include="GameClientState\LobbyAdminState.cpp" />
<ClCompile Include="GameClientState\LobbyState.cpp" /> <ClCompile Include="GameClientState\LobbyState.cpp" />
<ClCompile Include="GameClientState\C_Object.cpp" /> <ClCompile Include="GameClientState\C_Object.cpp" />
<ClCompile Include="GameClientState\MainState.cpp" /> <ClCompile Include="GameClientState\MainState.cpp" />
<ClCompile Include="GameClientState\NetLoadState.cpp" /> <ClCompile Include="GameClientState\NetLoadState.cpp" />
<ClCompile Include="GameClientState\RespawnUI.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="GameClientState\Camera_Basic.h" /> <ClInclude Include="GameClientState\Camera_Basic.h" />
@ -238,10 +241,13 @@
<ClInclude Include="GameClientState\C_obj\C_UIobject.h" /> <ClInclude Include="GameClientState\C_obj\C_UIobject.h" />
<ClInclude Include="GameClientState\GameClientState.h" /> <ClInclude Include="GameClientState\GameClientState.h" />
<ClInclude Include="GameClientState\GameState.h" /> <ClInclude Include="GameClientState\GameState.h" />
<ClInclude Include="GameClientState\GameStateUI.h" />
<ClInclude Include="GameClientState\GamingUI.h" />
<ClInclude Include="GameClientState\LanMenuState.h" /> <ClInclude Include="GameClientState\LanMenuState.h" />
<ClInclude Include="GameClientState\LobbyAdminState.h" /> <ClInclude Include="GameClientState\LobbyAdminState.h" />
<ClInclude Include="GameClientState\MainState.h" /> <ClInclude Include="GameClientState\MainState.h" />
<ClInclude Include="GameClientState\NetLoadState.h" /> <ClInclude Include="GameClientState\NetLoadState.h" />
<ClInclude Include="GameClientState\RespawnUI.h" />
<ClInclude Include="GameClientState\SharedStateContent.h" /> <ClInclude Include="GameClientState\SharedStateContent.h" />
<ClInclude Include="Include\GameClient.h" /> <ClInclude Include="Include\GameClient.h" />
<ClInclude Include="GameClientState\LobbyState.h" /> <ClInclude Include="GameClientState\LobbyState.h" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ShowAllFiles>true</ShowAllFiles> <ShowAllFiles>false</ShowAllFiles>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>

View File

@ -35,7 +35,7 @@ namespace DanBias { namespace Client
/****************************************************************** /******************************************************************
* @param message of the event * @param message of the event
* @return message or GameClientState::event_processed. * @return message or a reference to GameClientState::event_processed.
******************************************************************/ ******************************************************************/
virtual const NetEvent & DataRecieved( const NetEvent &message ); virtual const NetEvent & DataRecieved( const NetEvent &message );
}; };

View File

@ -122,7 +122,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
RBInitData RBData; RBInitData RBData;
RBData.position = position; RBData.position = position;
RBData.rotation = ArrayToQuaternion( rotation ); RBData.rotation = ArrayToQuaternion( rotation );
RBData.scale = Float3( 1 ); RBData.scale = scale;
// !RB DEBUG // !RB DEBUG
if( isMyPlayer ) if( isMyPlayer )
{ {
@ -216,13 +216,16 @@ bool GameState::Render()
dynamicObject = this->privData->dynamicObjects->begin(); dynamicObject = this->privData->dynamicObjects->begin();
for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject )
{ {
if( dynamicObject->second->getBRtype() == RB_Type_Cube) if( dynamicObject->second )
{ {
Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); if( dynamicObject->second->getBRtype() == RB_Type_Cube)
} {
if( dynamicObject->second->getBRtype() == RB_Type_Sphere) Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld());
{ }
Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); if( dynamicObject->second->getBRtype() == RB_Type_Sphere)
{
Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld());
}
} }
} }
} }
@ -479,8 +482,8 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
// if is this player. Remember to change camera // if is this player. Remember to change camera
if( this->privData->myId == decoded.object_ID ) if( this->privData->myId == decoded.object_ID )
{ {
//this->privData->camera.SetPosition( position ); this->privData->camera.SetPosition( position );
//this->privData->camera.SetRotation( rotation ); this->privData->camera.SetRotation( rotation );
this->privData->player.setPos( position ); this->privData->player.setPos( position );
//this->privData->player.setRot( rotation ); //this->privData->player.setRot( rotation );
} }

View File

@ -0,0 +1,17 @@
#include "GameStateUI.h"
using namespace ::DanBias::Client;
using namespace ::Oyster::Network;
GameStateUI::GameStateUI()
{
this->nextState = GameStateUI::UIState_same;
}
GameStateUI::~GameStateUI() { /* Do nothing */ }
const GameStateUI::NetEvent & GameStateUI::DataRecieved( const GameStateUI::NetEvent &message )
{
/* Do nothing */
return message;
}

View File

@ -0,0 +1,58 @@
#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H
#define DANBIAS_CLIENT_GAMECLIENTSTATE_H
#include "Utilities.h"
#include "NetworkClient.h"
namespace DanBias { namespace Client
{
class GameStateUI
{
public:
enum UIState
{
UIState_same,
UIState_gaming,
UIState_main_menu,
UIState_shut_down
};
typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent;
static const NetEvent event_processed;
GameStateUI();
virtual ~GameStateUI();
virtual UIState Update( float deltaTime ) = 0;
virtual bool HaveGUIRender() const = 0;
virtual bool HaveTextRender() const = 0;
virtual void RenderGUI() const = 0;
virtual void RenderText() const = 0;
virtual bool Release() = 0;
/******************************************************************
* @param message of the event
* @return message or a reference to GameStateUI::event_processed.
******************************************************************/
virtual const NetEvent & DataRecieved( const NetEvent &message );
protected:
UIState nextState;
};
} }
namespace Utility { namespace DynamicMemory
{ // template specializationto allowuse of dynamicmemory tools
template<>
inline void SafeDeleteInstance( ::DanBias::Client::GameStateUI *dynamicInstance )
{
if( dynamicInstance )
{
dynamicInstance->Release();
delete dynamicInstance;
}
}
} }
#endif

View File

@ -0,0 +1,153 @@
#include "GamingUI.h"
#include <Protocols.h>
using namespace ::DanBias::Client;
using namespace ::Oyster::Network;
using namespace ::GameLogic;
GamingUI::GamingUI() :
GameStateUI()
{
/* Should never be called! */
this->input = nullptr;
this->netClient = nullptr;
this->camera = nullptr;
}
GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) :
GameStateUI()
{
this->input = input;
this->netClient = connection;
this->camera = camera;
}
GamingUI::~GamingUI() { /* Do nothing */ }
GameStateUI::UIState GamingUI::Update( float deltaTime )
{
return this->nextState;
}
bool GamingUI::HaveGUIRender() const
{
return false; // TODO: change to true when we want UI elements like a crosshair
}
bool GamingUI::HaveTextRender() const
{
return false; // TODO: change to true when we want UI elements like a chat window
}
void GamingUI::RenderGUI() const
{
// TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender
}
void GamingUI::RenderText() const
{
// TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender
}
bool GamingUI::Release()
{
// TODO: Release UI components here.
return true;
}
void GamingUI::ReadKeyInput()
{
if( this->input->IsKeyPressed(DIK_W) )
{
this->netClient->Send( Protocol_PlayerMovementForward() );
}
if( this->input->IsKeyPressed(DIK_S) )
{
this->netClient->Send( Protocol_PlayerMovementBackward() );
}
if( this->input->IsKeyPressed(DIK_A) )
{
this->netClient->Send( Protocol_PlayerMovementLeft() );
}
if( this->input->IsKeyPressed(DIK_D) )
{
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
{
this->camera->YawRight( this->input->GetYaw() * 0.017f );
this->camera->PitchDown( this->input->GetPitch() * 0.017f );
this->camera->UpdateOrientation();
this->netClient->Send( Protocol_PlayerLook(this->camera->GetLook(), this->camera->GetRight()) );
}
// 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;
// jump
if( this->input->IsKeyPressed(DIK_SPACE) )
{
this->netClient->Send( Protocol_PlayerJump() );
}
}

View File

@ -0,0 +1,33 @@
#ifndef DANBIAS_CLIENT_GAMING_UI_H
#define DANBIAS_CLIENT_GAMING_UI_H
#include "GameStateUI.h"
#include "L_inputClass.h"
#include "Camera_FPSV2.h"
namespace DanBias { namespace Client
{
class GamingUI : public GameStateUI
{
public:
GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera );
virtual ~GamingUI();
UIState Update( float deltaTime );
bool HaveGUIRender() const;
bool HaveTextRender() const;
void RenderGUI() const;
void RenderText() const;
bool Release();
private:
InputClass *input;
::Oyster::Network::NetworkClient *netClient;
Camera_FPSV2 *camera;
GamingUI();
void ReadKeyInput();
};
} }
#endif

View File

@ -0,0 +1,58 @@
#include "RespawnUI.h"
using namespace ::DanBias::Client;
using namespace ::Oyster::Network;
using namespace ::Utility::Value;
RespawnUI::RespawnUI() :
GameStateUI()
{
/* Should never be called! */
this->netClient = nullptr;
this->countDown = 0.0f;
}
RespawnUI::RespawnUI( NetworkClient *connection, float delay ) :
GameStateUI()
{
this->netClient = connection;
this->countDown = delay;
}
RespawnUI::~RespawnUI() { /* Do nothing */ }
GameStateUI::UIState RespawnUI::Update( float deltaTime )
{
this->countDown = Max( this->countDown - deltaTime, 0.0f );
return this->nextState;
}
bool RespawnUI::HaveGUIRender() const
{
return false; // TODO: change to true when we want UI elements like a crosshair
}
bool RespawnUI::HaveTextRender() const
{
return false; // TODO: change to true when we want UI elements like a chat window
}
void RespawnUI::RenderGUI() const
{
// TODO: We need?
}
void RespawnUI::RenderText() const
{
// TODO: Text countdown somewhere on screen would be nice
}
bool RespawnUI::Release()
{
// TODO: Release UI components here.
return true;
}

View File

@ -0,0 +1,29 @@
#ifndef DANBIAS_CLIENT_RESPAWN_UI_H
#define DANBIAS_CLIENT_RESPAWN_UI_H
#include "GameStateUI.h"
namespace DanBias { namespace Client
{
class RespawnUI : public GameStateUI
{
public:
RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay );
virtual ~RespawnUI();
UIState Update( float deltaTime );
bool HaveGUIRender() const;
bool HaveTextRender() const;
void RenderGUI() const;
void RenderText() const;
bool Release();
private:
::Oyster::Network::NetworkClient *netClient;
float countDown;
RespawnUI();
};
} }
#endif

View File

@ -74,69 +74,40 @@ namespace GameLogic
Oyster::Network::CustomNetProtocol protocol; Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_PlayerLook :public Oyster::Network::CustomProtocolObject //protocol_Gameplay_PlayerLeftTurn
struct Protocol_PlayerLeftTurn : public ::Oyster::Network::CustomProtocolObject
{ {
// can be swapped to a quaternion later public:
float lookDir[3]; float deltaRadian;
float right[3];
Protocol_PlayerLook() Protocol_PlayerLeftTurn()
{ {
this->protocol[0].value = protocol_Gameplay_PlayerLookDir; this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short;
// LookDir // deltaRadian
this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[1].type = ::Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
// Right
this->protocol[4].type = Oyster::Network::NetAttributeType_Float;
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
memset(&this->lookDir[0], 0, sizeof(float) * 3);
memset(&this->right[0], 0, sizeof(float) * 3);
}
Protocol_PlayerLook(Oyster::Network::CustomNetProtocol& p)
{
this->lookDir[0] = p[1].value.netFloat;
this->lookDir[1] = p[2].value.netFloat;
this->lookDir[2] = p[3].value.netFloat;
this->right[0] = p[4].value.netFloat;
this->right[1] = p[5].value.netFloat;
this->right[2] = p[6].value.netFloat;
}
Protocol_PlayerLook(float l[3], float r[3])
{
this->protocol[0].value = protocol_Gameplay_PlayerLookDir;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
this->protocol[2].type = Oyster::Network::NetAttributeType_Float;
this->protocol[3].type = Oyster::Network::NetAttributeType_Float;
this->protocol[4].type = Oyster::Network::NetAttributeType_Float;
this->protocol[5].type = Oyster::Network::NetAttributeType_Float;
this->protocol[6].type = Oyster::Network::NetAttributeType_Float;
memcpy(&this->lookDir[0], &l[0], sizeof(float) * 3);
memcpy(&this->right[0], &r[0], sizeof(float) * 3);
} }
Oyster::Network::CustomNetProtocol GetProtocol() override Protocol_PlayerLeftTurn( const ::Oyster::Network::CustomNetProtocol &p )
{ {
this->protocol[1].value = this->lookDir[0]; this->deltaRadian = p[1].value.netFloat;
this->protocol[2].value = this->lookDir[1]; }
this->protocol[3].value = this->lookDir[2];
this->protocol[4].value = this->right[0];
this->protocol[5].value = this->right[1];
this->protocol[6].value = this->right[2];
Protocol_PlayerLeftTurn( float deltaRadian )
{
this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn;
this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short;
this->deltaRadian = deltaRadian;
}
::Oyster::Network::CustomNetProtocol GetProtocol() override
{
this->protocol[1].value = this->deltaRadian;
return protocol; return protocol;
} }
private: private:
Oyster::Network::CustomNetProtocol protocol; ::Oyster::Network::CustomNetProtocol protocol;
}; };
struct Protocol_PlayerChangeWeapon :public Oyster::Network::CustomProtocolObject struct Protocol_PlayerChangeWeapon :public Oyster::Network::CustomProtocolObject

View File

@ -47,7 +47,7 @@
#define protocol_Gameplay_PlayerMovementLeft 301 #define protocol_Gameplay_PlayerMovementLeft 301
#define protocol_Gameplay_PlayerMovementForward 302 #define protocol_Gameplay_PlayerMovementForward 302
#define protocol_Gameplay_PlayerMovementBackward 303 #define protocol_Gameplay_PlayerMovementBackward 303
#define protocol_Gameplay_PlayerLookDir 304 #define protocol_Gameplay_PlayerLeftTurn 304
#define protocol_Gameplay_PlayerChangeWeapon 305 #define protocol_Gameplay_PlayerChangeWeapon 305
#define protocol_Gameplay_PlayerShot 306 #define protocol_Gameplay_PlayerShot 306
#define protocol_Gameplay_PlayerJump 307 #define protocol_Gameplay_PlayerJump 307

View File

@ -84,7 +84,7 @@ namespace DanBias
void Gameplay_PlayerMovementBack ( DanBias::GameClient* c ); void Gameplay_PlayerMovementBack ( DanBias::GameClient* c );
void Gameplay_PlayerMovementForth ( DanBias::GameClient* c ); void Gameplay_PlayerMovementForth ( DanBias::GameClient* c );
void Gameplay_PlayerJump ( DanBias::GameClient* c ); void Gameplay_PlayerJump ( DanBias::GameClient* c );
void Gameplay_PlayerLookDir ( GameLogic::Protocol_PlayerLook& p, DanBias::GameClient* c ); void Gameplay_PlayerLeftTurn ( GameLogic::Protocol_PlayerLeftTurn& p, DanBias::GameClient* c );
void Gameplay_PlayerChangeWeapon ( GameLogic::Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ); void Gameplay_PlayerChangeWeapon ( GameLogic::Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c );
void Gameplay_PlayerShot ( GameLogic::Protocol_PlayerShot& p, DanBias::GameClient* c ); void Gameplay_PlayerShot ( GameLogic::Protocol_PlayerShot& p, DanBias::GameClient* c );
void Gameplay_ObjectPickup ( GameLogic::Protocol_ObjectPickup& p, DanBias::GameClient* c ); void Gameplay_ObjectPickup ( GameLogic::Protocol_ObjectPickup& p, DanBias::GameClient* c );

View File

@ -156,7 +156,7 @@ using namespace DanBias;
break; break;
case protocol_Gameplay_PlayerJump: this->Gameplay_PlayerJump ( c ); case protocol_Gameplay_PlayerJump: this->Gameplay_PlayerJump ( c );
break; break;
case protocol_Gameplay_PlayerLookDir: this->Gameplay_PlayerLookDir ( Protocol_PlayerLook (p), c ); case protocol_Gameplay_PlayerLeftTurn: this->Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn (p), c );
break; break;
case protocol_Gameplay_PlayerChangeWeapon: this->Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon (p), c ); case protocol_Gameplay_PlayerChangeWeapon: this->Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon (p), c );
break; break;
@ -203,12 +203,9 @@ using namespace DanBias;
{ {
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_JUMP); c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_JUMP);
} }
void GameSession::Gameplay_PlayerLookDir ( Protocol_PlayerLook& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn& p, DanBias::GameClient* c )
{ {
Oyster::Math3D::Float3 lookDir = p.lookDir; c->GetPlayer()->TurnLeft( p.deltaRadian );
Oyster::Math3D::Float3 right = p.right;
c->GetPlayer()->Rotate(lookDir, right);
} }
void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c )
{ {

View File

@ -7,6 +7,7 @@
#ifndef _INPUTCLASS_H_ #ifndef _INPUTCLASS_H_
#define _INPUTCLASS_H_ #define _INPUTCLASS_H_
#define NOMINMAX
#define DIRECTINPUT_VERSION 0x0800 #define DIRECTINPUT_VERSION 0x0800
#pragma comment(lib, "dinput8.lib") #pragma comment(lib, "dinput8.lib")