From aa2518a4f6a7ea511b11352ebec0387c87ea7868 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 11:27:43 +0100 Subject: [PATCH 01/39] Patch --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 33 ++++---- .../GameClientState/Buttons/EventButtonGUI.h | 4 +- .../GameClient/GameClientState/C_Object.cpp | 6 +- .../GameClient/GameClientState/C_Object.h | 78 ++++++++++++------- .../GameClientState/GameClientState.cpp | 4 +- .../GameClientState/GameClientState.h | 11 ++- .../GameClient/GameClientState/GameState.cpp | 14 ++-- .../GameClient/GameClientState/GameState.h | 4 +- .../GameClientState/LanMenuState.cpp | 12 +-- .../GameClient/GameClientState/LanMenuState.h | 4 +- .../GameClientState/LevelLoader/LevelLoader.h | 2 +- .../GameClientState/LevelLoader/LevelParser.h | 2 +- .../GameClientState/LevelLoader/Loader.h | 2 +- .../GameClientState/LobbyAdminState.cpp | 12 +-- .../GameClientState/LobbyAdminState.h | 4 +- .../GameClient/GameClientState/LobbyState.cpp | 12 +-- .../GameClient/GameClientState/LobbyState.h | 8 +- .../GameClient/GameClientState/MainState.cpp | 16 ++-- .../GameClient/GameClientState/MainState.h | 14 ++-- .../GameClientState/NetLoadState.cpp | 17 +++- .../GameClient/GameClientState/NetLoadState.h | 4 +- .../GameClientState/SharedStateContent.h | 28 +++++++ 22 files changed, 182 insertions(+), 109 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/SharedStateContent.h diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 21d5589f..244568c2 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -18,12 +18,15 @@ #include "WinTimer.h" #include "vld.h" -#include "EventHandler/EventHandler.h" +#include "../Misc/EventHandler/EventHandler.h" + +#include "GameClientState\SharedStateContent.h" using namespace ::Oyster; using namespace ::Oyster::Event; using namespace ::Oyster::Network; using namespace ::Utility::DynamicMemory; +using namespace ::DanBias::Client; void ClientEventFunction( NetEvent e ); @@ -32,15 +35,17 @@ namespace DanBias #pragma region Game Data class DanBiasGamePrivateData { - public: WindowShell* window; - InputClass* inputObj; + InputClass inputObj; Utility::WinTimer timer; - UniquePointer state; - NetworkClient networkClient; - bool serverOwner; + UniquePointer state; + SharedStateContent sharedStateContent; + NetworkClient networkClient; + + + bool serverOwner; float capFrame; DanBiasGamePrivateData() @@ -72,10 +77,13 @@ namespace DanBias data.networkClient.SetMessagePump( ClientEventFunction ); + data.sharedStateContent.network = &data.networkClient; + data.sharedStateContent.input = &data.inputObj; + // Start in main menu state data.state = new Client::MainState(); - if( !data.state->Init( &data.networkClient ) ) + if( !data.state->Init( data.sharedStateContent ) ) return DanBiasClientReturn_Error; data.timer.reset(); @@ -140,8 +148,7 @@ namespace DanBias //------------------------------------------------------------------------------------- HRESULT DanBiasGame::InitInput() { - data.inputObj = new InputClass; - if(!data.inputObj->Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth())) + if(!data.inputObj.Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth())) { MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); return E_FAIL; @@ -164,7 +171,7 @@ namespace DanBias float mouseNormalisedY = (float)(mousePos.y - windowVertex.top); mouseNormalisedY /= (float)(windowVertex.bottom - windowVertex.top); - data.inputObj->Update( mouseNormalisedX, mouseNormalisedY ); + data.inputObj.Update( mouseNormalisedX, mouseNormalisedY ); } if( data.serverOwner ) @@ -174,7 +181,7 @@ namespace DanBias DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same; - state = data.state->Update( deltaTime, data.inputObj ); + state = data.state->Update( deltaTime ); if( state != Client::GameClientState::ClientState_Same ) { @@ -217,7 +224,7 @@ namespace DanBias if( stateChanged ) { - data.state->Init( &data.networkClient ); // send game client + data.state->Init( data.sharedStateContent ); // send game client } } return Result_continue; @@ -235,8 +242,6 @@ namespace DanBias if( data.networkClient.IsConnected() ) data.networkClient.Disconnect(); - delete data.inputObj; - data.state = nullptr; EventHandler::Instance().Clean(); Graphics::API::Clean(); diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c770cb9c..d4981c23 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -5,8 +5,8 @@ #ifndef DANBIAS_CLIENT_EVENT_BUTTON_GUI_H #define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H -#include "EventHandler/EventButton.h" -#include "DllInterfaces/GFXAPI.h" +#include "../Misc/EventHandler/EventButton.h" +#include "../OysterGraphics/DllInterfaces/GFXAPI.h" diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index d44d9201..92b55c53 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -100,5 +100,9 @@ void C_Object::Render() } void C_Object::Release() { - Oyster::Graphics::API::DeleteModel(model); + if( this->model ) + { + Oyster::Graphics::API::DeleteModel(model); + this->model = nullptr; + } } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index ae9dc3a5..20e0eb60 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -16,37 +16,55 @@ namespace DanBias bool visible; }; -class C_Object -{ -private: - Oyster::Math::Float4x4 world; - Oyster::Math::Float3 position; - Oyster::Math::Quaternion rotation; - Oyster::Math::Float3 scale; + class C_Object + { + private: + Oyster::Math::Float4x4 world; + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; - int id; - void updateWorld(); -protected: - Oyster::Graphics::Model::Model *model; -public: - C_Object(); - virtual ~C_Object(); - virtual bool Init(ModelInitData modelInit); + int id; + void updateWorld(); + protected: + Oyster::Graphics::Model::Model *model; + public: + C_Object(); + virtual ~C_Object(); + virtual bool Init(ModelInitData modelInit); - void setWorld(Oyster::Math::Float4x4 world); - Oyster::Math::Float4x4 getWorld() const; - void setPos(Oyster::Math::Float3 newPos); - Oyster::Math::Float3 getPos() const; - void addPos(Oyster::Math::Float3 deltaPos); - void setRot(Oyster::Math::Quaternion newRot); - Oyster::Math::Quaternion getRotation() const; - void addRot(Oyster::Math::Quaternion deltaRot); - void setScale(Oyster::Math::Float3 newScale); - void addScale(Oyster::Math::Float3 deltaScale); - Oyster::Math::Float3 getScale() const; + void setWorld(Oyster::Math::Float4x4 world); + Oyster::Math::Float4x4 getWorld() const; + void setPos(Oyster::Math::Float3 newPos); + Oyster::Math::Float3 getPos() const; + void addPos(Oyster::Math::Float3 deltaPos); + void setRot(Oyster::Math::Quaternion newRot); + Oyster::Math::Quaternion getRotation() const; + void addRot(Oyster::Math::Quaternion deltaRot); + void setScale(Oyster::Math::Float3 newScale); + void addScale(Oyster::Math::Float3 deltaScale); + Oyster::Math::Float3 getScale() const; + + virtual void Render(); + virtual void Release(); + virtual int GetId() const; + }; + } +} + +#include "Utilities.h" + +namespace Utility { namespace DynamicMemory +{ + template<> + inline void SafeDeleteInstance( ::DanBias::Client::C_Object *dynamicInstance ) + { + if( dynamicInstance ) + { + dynamicInstance->Release(); + delete dynamicInstance; + } + } +} } - virtual void Render(); - virtual void Release(); - virtual int GetId() const; -};};}; #endif diff --git a/Code/Game/GameClient/GameClientState/GameClientState.cpp b/Code/Game/GameClient/GameClientState/GameClientState.cpp index 9db00f9d..dab88b2e 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.cpp +++ b/Code/Game/GameClient/GameClientState/GameClientState.cpp @@ -3,9 +3,9 @@ using namespace DanBias::Client; using namespace ::Oyster::Network; -GameClientState::GameClientState(void) {} +GameClientState::GameClientState() {} -GameClientState::~GameClientState(void) {} +GameClientState::~GameClientState() {} void GameClientState::DataRecieved( NetEvent e ) { /* do nothing */ } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 9317413e..3822c7b0 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -2,8 +2,7 @@ #define DANBIAS_CLIENT_GAMECLIENTSTATE_H #define NOMINMAX -#include "L_inputClass.h" -#include "NetworkClient.h" +#include "SharedStateContent.h" namespace DanBias { namespace Client { @@ -24,10 +23,10 @@ namespace DanBias { namespace Client }; public: - GameClientState(void); - virtual ~GameClientState(void); - virtual bool Init(Oyster::Network::NetworkClient* nwClient) = 0; - virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0; + GameClientState(); + virtual ~GameClientState(); + virtual bool Init( SharedStateContent &shared ) = 0; + virtual ClientState Update( float deltaTime ) = 0; virtual bool Render() = 0; virtual bool Release() = 0; virtual void ChangeState( ClientState next ) = 0; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 66ca6c12..349eaaeb 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -15,9 +15,10 @@ struct GameState::MyData MyData(){} GameClientState::ClientState nextState; NetworkClient *nwClient; + InputClass *input; } privData; -GameState::GameState(void) +GameState::GameState() { key_forward = false; key_backward = false; @@ -25,24 +26,25 @@ GameState::GameState(void) key_strafeLeft = false; } -GameState::~GameState(void) +GameState::~GameState() { if( this->privData ) this->Release(); } -bool GameState::Init(NetworkClient* nwClient) +bool GameState::Init( SharedStateContent &shared ) { // load models privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + this->privData->nwClient = shared.network; + this->privData->input = shared.input; LoadGame(); //tell server ready - nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) ); + this->privData->nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) ); return true; } @@ -180,7 +182,7 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world) camera.UpdateOrientation(); } -GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) +GameClientState::ClientState GameState::Update( float deltaTime ) { //switch (privData->state) //{ diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 6366bb8c..5a3b3c1a 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -25,8 +25,8 @@ namespace DanBias { namespace Client GameState(void); ~GameState(void); - bool Init(Oyster::Network::NetworkClient* nwClient); - GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; + bool Init( SharedStateContent &shared ); + GameClientState::ClientState Update( float deltaTime ) override; bool LoadModels(std::string mapFile); bool InitCamera(Oyster::Math::Float3 startPos) ; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 6a836a36..7faf5d55 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -28,6 +28,7 @@ struct LanMenuState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; + InputClass *input; Graphics::API::Texture background; EventButtonCollection guiElements; @@ -46,12 +47,13 @@ LanMenuState::~LanMenuState() this->Release(); } -bool LanMenuState::Init(Network::NetworkClient* nwClient) +bool LanMenuState::Init( SharedStateContent &shared ) { this->privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + this->privData->nwClient = shared.network; + this->privData->input = shared.input; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); @@ -80,12 +82,12 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient) return true; } -GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput) +GameClientState::ClientState LanMenuState::Update( float deltaTime ) { MouseInput mouseState; { - KeyInput->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = KeyInput->IsMousePressed(); + this->privData->input->GetMousePos( mouseState.x, mouseState.y ); + mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); } EventHandler::Instance().Update( mouseState ); diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.h b/Code/Game/GameClient/GameClientState/LanMenuState.h index 8f3e8e67..57889eee 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.h +++ b/Code/Game/GameClient/GameClientState/LanMenuState.h @@ -14,8 +14,8 @@ namespace DanBias LanMenuState(); virtual ~LanMenuState(); - virtual bool Init(Oyster::Network::NetworkClient* nwClient); - virtual ClientState Update(float deltaTime, InputClass* KeyInput); + bool Init( SharedStateContent &shared ); + virtual ClientState Update( float deltaTime ); virtual bool Render(); virtual bool Release(); diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h index aa67c4f5..184a7005 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h @@ -7,7 +7,7 @@ #include #include -#include "Utilities.h" +#include "../Misc/Utilities.h" #include "ObjectDefines.h" namespace GameLogic diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h index 8f2a9150..346b75b5 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h @@ -4,7 +4,7 @@ #include #include #include "ObjectDefines.h" -#include "Utilities.h" +#include "../Misc/Utilities.h" namespace GameLogic { diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h b/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h index 0433194e..198c2a87 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h @@ -5,7 +5,7 @@ #ifndef LOADER_H #define LOADER_H -#include "Resource\OysterResource.h" +#include "..\Misc\Resource\OysterResource.h" #include namespace GameLogic diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index c157226e..6cc1f15f 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -22,6 +22,7 @@ struct LobbyAdminState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; + InputClass *input; Graphics::API::Texture background; EventButtonCollection guiElements; } privData; @@ -36,12 +37,13 @@ LobbyAdminState::~LobbyAdminState(void) this->Release(); } -bool LobbyAdminState::Init(NetworkClient* nwClient) +bool LobbyAdminState::Init( SharedStateContent &shared ) { privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + this->privData->nwClient = shared.network; + this->privData->input = shared.input; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); @@ -57,7 +59,7 @@ bool LobbyAdminState::Init(NetworkClient* nwClient) return true; } -GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass* KeyInput) +GameClientState::ClientState LobbyAdminState::Update( float deltaTime ) { // Wishlist: // picking @@ -70,8 +72,8 @@ GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass MouseInput mouseState; { - KeyInput->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = KeyInput->IsMousePressed(); + this->privData->input->GetMousePos( mouseState.x, mouseState.y ); + mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); } EventHandler::Instance().Update( mouseState ); diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.h b/Code/Game/GameClient/GameClientState/LobbyAdminState.h index 06a9aced..49ae9274 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.h +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.h @@ -24,8 +24,8 @@ namespace DanBias LobbyAdminState(); ~LobbyAdminState(); - bool Init( Oyster::Network::NetworkClient* nwClient ); - ClientState Update( float deltaTime, InputClass* KeyInput ); + bool Init( SharedStateContent &shared ); + ClientState Update( float deltaTime ); bool Render(); bool Release(); void ChangeState( ClientState next ); diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 47a3cebb..6c5b2606 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -22,6 +22,7 @@ struct LobbyState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; + InputClass *input; Graphics::API::Texture background; EventButtonCollection guiElements; } privData; @@ -36,12 +37,13 @@ LobbyState::~LobbyState(void) this->Release(); } -bool LobbyState::Init(NetworkClient* nwClient) +bool LobbyState::Init( SharedStateContent &shared ) { privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + this->privData->nwClient = shared.network; + this->privData->input = shared.input; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); @@ -57,7 +59,7 @@ bool LobbyState::Init(NetworkClient* nwClient) return true; } -GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput) +GameClientState::ClientState LobbyState::Update( float deltaTime ) { // Wishlist: // picking @@ -70,8 +72,8 @@ GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* Key MouseInput mouseState; { - KeyInput->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = KeyInput->IsMousePressed(); + this->privData->input->GetMousePos( mouseState.x, mouseState.y ); + mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); } EventHandler::Instance().Update( mouseState ); diff --git a/Code/Game/GameClient/GameClientState/LobbyState.h b/Code/Game/GameClient/GameClientState/LobbyState.h index 7b6e5909..694aaa38 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.h +++ b/Code/Game/GameClient/GameClientState/LobbyState.h @@ -23,11 +23,11 @@ namespace DanBias class LobbyState : public GameClientState { public: - LobbyState(void); - ~LobbyState(void); + LobbyState(); + ~LobbyState(); - bool Init( Oyster::Network::NetworkClient* nwClient ); - ClientState Update( float deltaTime, InputClass* KeyInput ); + bool Init( SharedStateContent &shared ); + ClientState Update( float deltaTime ); bool Render(); bool Release(); void ChangeState( ClientState next ); diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 81794252..1fd1d813 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -24,6 +24,7 @@ struct MainState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; + InputClass *input; Graphics::API::Texture background; EventButtonCollection guiElements; }; @@ -32,20 +33,21 @@ void OnButtonInteract_Create( Oyster::Event::ButtonEvent& e ); void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ); void OnButtonInteract_Quit( Oyster::Event::ButtonEvent& e ); -MainState::MainState(void) {} +MainState::MainState() {} -MainState::~MainState(void) +MainState::~MainState() { if( this->privData ) this->Release(); } -bool MainState::Init( NetworkClient* nwClient ) +bool MainState::Init( SharedStateContent &shared ) { this->privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + this->privData->nwClient = shared.network; + this->privData->input = shared.input; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); @@ -67,12 +69,12 @@ bool MainState::Init( NetworkClient* nwClient ) return true; } -GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput) +GameClientState::ClientState MainState::Update( float deltaTime ) { MouseInput mouseState; { - KeyInput->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = KeyInput->IsMousePressed(); + this->privData->input->GetMousePos( mouseState.x, mouseState.y ); + mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); } EventHandler::Instance().Update( mouseState ); diff --git a/Code/Game/GameClient/GameClientState/MainState.h b/Code/Game/GameClient/GameClientState/MainState.h index 7255e917..22589686 100644 --- a/Code/Game/GameClient/GameClientState/MainState.h +++ b/Code/Game/GameClient/GameClientState/MainState.h @@ -11,18 +11,18 @@ namespace DanBias { class MainState : public GameClientState { - private: - struct MyData; - ::Utility::DynamicMemory::UniquePointer privData; public: - MainState(void); - ~MainState(void); - bool Init( Oyster::Network::NetworkClient* nwClient ); - ClientState Update(float deltaTime, InputClass* KeyInput); + MainState(); + ~MainState(); + bool Init( SharedStateContent &shared ); + ClientState Update( float deltaTime ); bool Render(); bool Release(); void ChangeState( ClientState next ); + private: + struct MyData; + ::Utility::DynamicMemory::UniquePointer privData; }; } } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index c8fd1e64..ac7dd78b 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -13,6 +13,7 @@ struct NetLoadState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; + Graphics::API::Texture background; bool loading; }; @@ -24,28 +25,36 @@ NetLoadState::~NetLoadState(void) this->Release(); } -bool NetLoadState::Init( NetworkClient* nwClient ) +bool NetLoadState::Init( SharedStateContent &shared ) { this->privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + this->privData->nwClient = shared.network; + this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->loading = false; // we may assume that nwClient is properly connected to the server // signals querry to server for loading instructions - nwClient->Send( Protocol_QuerryGameType() ); + this->privData->nwClient->Send( Protocol_QuerryGameType() ); return true; } -GameClientState::ClientState NetLoadState::Update(float deltaTime, InputClass* KeyInput) +GameClientState::ClientState NetLoadState::Update( float deltaTime ) { return this->privData->nextState; } bool NetLoadState::Render() { + Graphics::API::NewFrame(); + Graphics::API::StartGuiRender(); + + Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); + + Graphics::API::EndFrame(); + return true; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.h b/Code/Game/GameClient/GameClientState/NetLoadState.h index ff2d1acc..ea9f9f6a 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.h +++ b/Code/Game/GameClient/GameClientState/NetLoadState.h @@ -14,8 +14,8 @@ namespace DanBias NetLoadState( ); virtual ~NetLoadState( ); - bool Init( Oyster::Network::NetworkClient* nwClient ); - ClientState Update( float deltaTime, InputClass* KeyInput ); + bool Init( SharedStateContent &shared ); + ClientState Update( float deltaTime ); bool Render(); bool Release(); diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h new file mode 100644 index 00000000..567be2fa --- /dev/null +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -0,0 +1,28 @@ +/******************************************************************** + * Created by Dan Andersson, 2014 + * Contains a shared memory struct. + * Whihc reference passed seamlessly between the game states + * at their Init calls. + ********************************************************************/ + +#ifndef SHAREDSTATECONTENT_H +#define SHAREDSTATECONTENT_H + +#include +#include "Utilities.h" +#include "C_Object.h" +#include "NetworkClient.h" +#include "L_inputClass.h" + +namespace DanBias { namespace Client +{ + struct SharedStateContent + { + public: + ::std::map> scene; + ::Oyster::Network::NetworkClient *network; + InputClass* input; + }; +} } + +#endif \ No newline at end of file From 29f66d2874eb31e5acc3b1664ac913869ca8d7b0 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 11:50:51 +0100 Subject: [PATCH 02/39] Fixed build errors in GameClient --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 2 +- Code/Game/GameClient/GameClient.vcxproj | 18 ++++++++++++++---- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClientState/Buttons/EventButtonGUI.h | 6 ++---- .../GameClientState/LevelLoader/LevelLoader.h | 2 +- .../GameClientState/LevelLoader/LevelParser.h | 2 +- .../GameClientState/LevelLoader/Loader.h | 2 +- .../GameClientState/NetLoadState.cpp | 2 ++ 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 244568c2..392e917f 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -18,7 +18,7 @@ #include "WinTimer.h" #include "vld.h" -#include "../Misc/EventHandler/EventHandler.h" +#include "EventHandler/EventHandler.h" #include "GameClientState\SharedStateContent.h" diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 0691fef1..a87f61e4 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -111,7 +111,7 @@ Windows true - Misc\Misc_$(PlatformShortName)D.lib;WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + %(AdditionalDependencies) NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -128,7 +128,7 @@ Windows true - Misc\Misc_$(PlatformShortName)D.lib;WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + %(AdditionalDependencies) NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -149,7 +149,7 @@ true true true - Misc\Misc_$(PlatformShortName).lib;WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies) + %(AdditionalDependencies) NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs) @@ -170,14 +170,23 @@ true true true - Misc\Misc_$(PlatformShortName).lib;WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies) + %(AdditionalDependencies) NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs) + + {7e3990d2-3d94-465c-b58d-64a74b3ecf9b} + {f10cbc03-9809-4cba-95d8-327c287b18ee} + + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + + {35aea3c0-e0a7-4e1e-88cd-514aa5a442b1} + {460d625f-2ac9-4559-b809-0ba89ceaedf4} @@ -233,6 +242,7 @@ + diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index d4981c23..04af2e5a 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -5,10 +5,8 @@ #ifndef DANBIAS_CLIENT_EVENT_BUTTON_GUI_H #define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H -#include "../Misc/EventHandler/EventButton.h" -#include "../OysterGraphics/DllInterfaces/GFXAPI.h" - - +#include "EventHandler/EventButton.h" +#include "DllInterfaces/GFXAPI.h" namespace DanBias { diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h index 184a7005..aa67c4f5 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h @@ -7,7 +7,7 @@ #include #include -#include "../Misc/Utilities.h" +#include "Utilities.h" #include "ObjectDefines.h" namespace GameLogic diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h index 346b75b5..8f2a9150 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h @@ -4,7 +4,7 @@ #include #include #include "ObjectDefines.h" -#include "../Misc/Utilities.h" +#include "Utilities.h" namespace GameLogic { diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h b/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h index 198c2a87..0433194e 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h @@ -5,7 +5,7 @@ #ifndef LOADER_H #define LOADER_H -#include "..\Misc\Resource\OysterResource.h" +#include "Resource\OysterResource.h" #include namespace GameLogic diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index ac7dd78b..3463182e 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -1,9 +1,11 @@ #include "NetLoadState.h" #include "NetworkClient.h" +#include "OysterMath.h" #include "../Game/GameProtocols/Protocols.h" using namespace ::DanBias::Client; using namespace ::Oyster; +using namespace ::Oyster::Math; using namespace ::Oyster::Network; using namespace ::GameLogic; From 013546f07676c4b2054dc31a43b4e85a91a2654a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 12:02:18 +0100 Subject: [PATCH 03/39] minor edit --- Code/Game/GameClient/GameClientState/GameState.cpp | 4 ++++ Code/Game/GameClient/GameClientState/SharedStateContent.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 349eaaeb..1691a470 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -16,6 +16,10 @@ struct GameState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; InputClass *input; + + ::std::map> *staticObjects; + ::std::map> *dynamicObjects; + } privData; GameState::GameState() diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index 567be2fa..2fabb1ac 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -19,7 +19,8 @@ namespace DanBias { namespace Client struct SharedStateContent { public: - ::std::map> scene; + ::std::map> staticObjects; + ::std::map> dynamicObjects; ::Oyster::Network::NetworkClient *network; InputClass* input; }; From 51a856958527e490f1afb47ce33e3de16cd85cbc Mon Sep 17 00:00:00 2001 From: lanariel Date: Mon, 17 Feb 2014 13:05:35 +0100 Subject: [PATCH 04/39] Color is now Float4 with RGBA --- .../GameClientState/Buttons/ButtonEllipse.h | 8 ++++---- .../GameClientState/Buttons/ButtonRectangle.h | 8 ++++---- .../GameClientState/Buttons/EventButtonGUI.h | 14 +++++++------- .../GameClient/GameClientState/Buttons/TextField.h | 4 ++-- .../GameClient/GameClientState/LanMenuState.cpp | 6 +++--- .../GameClient/GameClientState/LobbyAdminState.cpp | 2 +- .../Game/GameClient/GameClientState/LobbyState.cpp | 2 +- Code/Game/GameClient/GameClientState/MainState.cpp | 6 +++--- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 4 ++-- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 4 ++-- Code/OysterGraphics/Render/GuiRenderer.cpp | 8 ++++---- Code/OysterGraphics/Render/GuiRenderer.h | 4 ++-- Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl | 2 +- Code/OysterGraphics/Shader/Passes/2D/Header.hlsli | 2 +- 14 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h index 694683e7..7d9a9a5d 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonEllipse.h @@ -21,19 +21,19 @@ namespace DanBias ButtonEllipse() : EventButtonGUI(), radius(0) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, + ButtonEllipse(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h index 6afb77c1..f4dd69e1 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h @@ -21,19 +21,19 @@ namespace DanBias ButtonRectangle() : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, + ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) {} diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c770cb9c..ee22fe26 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -33,30 +33,30 @@ namespace DanBias { public: EventButtonGUI() - : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(0, 0, 0) + : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(1, 1, 1, 1) {} - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Oyster::Math::Float3 pos, + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float3 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) { CreateTexture(textureName); @@ -79,7 +79,7 @@ namespace DanBias if(EventButton::Enabled()) { // let the using dev decide what is rendered - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f)); //Render att xPos and yPos //With width and height @@ -127,7 +127,7 @@ namespace DanBias Oyster::Graphics::API::Texture texture; std::wstring buttonText; - Oyster::Math::Float3 textColor; + Oyster::Math::Float4 textColor; }; } } diff --git a/Code/Game/GameClient/GameClientState/Buttons/TextField.h b/Code/Game/GameClient/GameClientState/Buttons/TextField.h index af9c4346..c1fa79ac 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/TextField.h +++ b/Code/Game/GameClient/GameClientState/Buttons/TextField.h @@ -20,7 +20,7 @@ namespace DanBias { namespace Client { public: TextField(); - TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height ); + TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height ); virtual ~TextField(); virtual void RenderText(); @@ -62,7 +62,7 @@ namespace DanBias { namespace Client } template - TextField::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize ) + TextField::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize ) : ButtonRectangle( backgroundTexture, L"", textColor, owner, pos, size, resize ) { this->fontHeight = 0.025f; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 6a836a36..ba8aee42 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -56,7 +56,7 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); // create guiElements - this->privData->connectIP = new TextField( L"earth_md.png", Float3(1.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); + this->privData->connectIP = new TextField( L"earth_md.png", Float4(1.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); this->privData->connectIP->ReserveLines( 1 ); this->privData->connectIP->AppendText( L"127.0.0.1" ); this->privData->connectIP->SetFontHeight( 0.08f ); @@ -66,10 +66,10 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient) this->privData->guiElements.AddButton( this->privData->connectIP ); ButtonRectangle *guiElements; - guiElements = new ButtonRectangle( L"earth_md.png", L"Connect", Float3(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); + guiElements = new ButtonRectangle( L"earth_md.png", L"Connect", Float4(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); this->privData->guiElements.AddButton( guiElements ); - guiElements = new ButtonRectangle( L"earth_md.png", L"Exit", Float3(1.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); + guiElements = new ButtonRectangle( L"earth_md.png", L"Exit", Float4(1.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); this->privData->guiElements.AddButton( guiElements ); // bind guiElements collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index c157226e..b2349c2b 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -48,7 +48,7 @@ bool LobbyAdminState::Init(NetworkClient* nwClient) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 47a3cebb..cbfc7eed 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -48,7 +48,7 @@ bool LobbyState::Init(NetworkClient* nwClient) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 81794252..ef4b844a 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -52,13 +52,13 @@ bool MainState::Init( NetworkClient* nwClient ) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Create", Float3(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Create", Float4(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); - button = new ButtonRectangle( L"skysphere_md.png", L"Join", Float3(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"skysphere_md.png", L"Join", Float4(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); - button = new ButtonRectangle( L"plane_texture_md.png", L"Quit", Float3(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"plane_texture_md.png", L"Quit", Float4(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index f3bd12fd..f4ce303f 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -161,7 +161,7 @@ namespace Oyster Render::Gui::Begin2DRender(); } - void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color) + void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float4 color) { Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color); } @@ -196,7 +196,7 @@ namespace Oyster Render::Gui::Begin2DTextRender(); } - void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color) + void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float4 color) { Render::Gui::RenderText(text, Pos, Size, FontSize, color); } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index e2cea318..eea53939 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -57,13 +57,13 @@ namespace Oyster static void StartGuiRender(); //! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system - static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); + static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float4 Color = Math::Float4(1,1,1,1)); //! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame() static void StartTextRender(); //! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system - static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 Color = Math::Float3(1,1,1)); + static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float4 Color = Math::Float4(1,1,1,1)); //! @brief Performs light calculations, post effects and presents the scene static void EndFrame(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index 8eda0bf5..b17fdfef 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -16,7 +16,7 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass); } - void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float3 color) + void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float4 color) { Core::deviceContext->PSSetShaderResources(0,1,&tex); @@ -37,7 +37,7 @@ namespace Oyster Render::Resources::Gui::Data.Unmap(); data = Render::Resources::Color.Map(); - memcpy(data,&color,sizeof(Math::Float3)); + memcpy(data,&color,sizeof(Math::Float4)); Render::Resources::Color.Unmap(); @@ -50,7 +50,7 @@ namespace Oyster Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass); } - void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 color) + void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float4 color) { //size.x = size.x / (text.length() * TEXT_SPACING /2); @@ -81,7 +81,7 @@ namespace Oyster Definitions::Text2D tmpInst; data = Render::Resources::Color.Map(); - memcpy(data,&color,sizeof(Math::Float3)); + memcpy(data,&color,sizeof(Math::Float4)); Render::Resources::Color.Unmap(); void* dest = Resources::Gui::Text::Vertex.Map(); diff --git a/Code/OysterGraphics/Render/GuiRenderer.h b/Code/OysterGraphics/Render/GuiRenderer.h index 3e4a8de0..64d6fdd3 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.h +++ b/Code/OysterGraphics/Render/GuiRenderer.h @@ -12,9 +12,9 @@ namespace Oyster { public: static void Begin2DRender(); - static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); + static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float4 tint = Math::Float4(1,1,1,1)); static void Begin2DTextRender(); - static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 tint = Math::Float3(1,1,1)); + static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float4 tint = Math::Float4(1,1,1,1)); }; } } diff --git a/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl b/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl index c28fd642..0c8d3c68 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl +++ b/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl @@ -2,5 +2,5 @@ float4 main(Pixel2DIn input) : SV_Target0 { - return Material.Sample(LinearSampler,input.Uv) * float4(Color,1); + return Material.Sample(LinearSampler,input.Uv) * Color; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli b/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli index 4b507644..f84483f5 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli @@ -10,7 +10,7 @@ cbuffer EveryObject2D : register(b0) cbuffer ColorData : register(b0) { - float3 Color; + float4 Color; }; struct Pixel2DIn From b93e20e9423a59682f8e70aac18feb45a9b6e14f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 14:33:11 +0100 Subject: [PATCH 05/39] Bunch of implementations --- .../GameClient/GameClientState/GameState.cpp | 413 ++++++------------ .../GameClient/GameClientState/GameState.h | 29 +- .../GameClientState/LanMenuState.cpp | 4 +- .../GameClientState/NetLoadState.cpp | 89 +++- .../GameClientState/SharedStateContent.h | 6 +- 5 files changed, 234 insertions(+), 307 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1691a470..29cfec03 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -5,10 +5,16 @@ #include "Camera_FPS.h" #include +#include "C_obj/C_Player.h" +#include "C_obj/C_DynamicObj.h" +#include "C_obj/C_StaticObj.h" + using namespace ::DanBias::Client; using namespace ::Oyster; using namespace ::Oyster::Network; using namespace ::Oyster::Math3D; +using namespace ::GameLogic; +using namespace ::Utility::DynamicMemory; struct GameState::MyData { @@ -17,17 +23,26 @@ struct GameState::MyData NetworkClient *nwClient; InputClass *input; - ::std::map> *staticObjects; - ::std::map> *dynamicObjects; + ::std::map> *staticObjects; + ::std::map> *dynamicObjects; + + bool key_forward; + bool key_backward; + bool key_strafeRight; + bool key_strafeLeft; + bool key_Shoot; + bool key_Jump; + + C_Player player; + Camera_FPS camera; + + int myId; } privData; GameState::GameState() { - key_forward = false; - key_backward = false; - key_strafeRight = false; - key_strafeLeft = false; + this->privData = nullptr; } GameState::~GameState() @@ -38,202 +53,69 @@ GameState::~GameState() bool GameState::Init( SharedStateContent &shared ) { - // load models - privData = new MyData(); + // we may assume that shared.network is properly connected + // and there is content in shared.dynamicObjects and shared.staticObjects + + 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; - - LoadGame(); + this->privData->staticObjects = &shared.staticObjects; + this->privData->dynamicObjects = &shared.dynamicObjects; //tell server ready - this->privData->nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) ); + this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); return true; } -GameState::gameStateState GameState::LoadGame() +void GameState::InitiatePlayer( int id, std::wstring modelName, Float4x4 world ) { - - return gameStateState_playing; -} - -bool GameState::LoadModels(std::string mapFile) -{ - GameLogic::LevelLoader levelLoader; - std::vector> objects; - objects = levelLoader.LoadLevel(mapFile); - - int objCount = objects.size(); - int modelId = 0; - ModelInitData modelData; - for (int i = 0; i < objCount; i++) - { - GameLogic::ObjectTypeHeader* obj = objects.at(i); - - switch (obj->typeID) - { - case GameLogic::ObjectType::ObjectType_LevelMetaData: - - break; - case GameLogic::ObjectType::ObjectType_Static: - { - GameLogic::ObjectHeader* staticObjData = ((GameLogic::ObjectHeader*)obj); - - modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end()); - modelData.visible = true; - //modelData.position = ; - //modelData.rotation = Quaternion(Float3(2,2,-2), 1); - //modelData.scale = Float3(2,2,2); - modelData.id = modelId++; - - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - } - break; - case GameLogic::ObjectType::ObjectType_Dynamic: - { - GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj); - //modelData.position = ; - //modelData.rotation = Quaternion(Float3(2,2,-2), 1); - //modelData.scale = Float3(2,2,2); - modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end()); - modelData.visible = true; - modelData.id = modelId++; - - this->dynamicObjects.Push(new C_DynamicObj()); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); - } - break; - case GameLogic::ObjectType::ObjectType_Light: - { - GameLogic::BasicLight* lightData = ((GameLogic::BasicLight*)obj); - - switch( lightData->lightType ) - { - case GameLogic::LightType_PointLight: - { - //Oyster::Graphics::Definitions::Pointlight plight; - //plight.Pos = ((GameLogic::PointLight*)lightData)->position; - //plight.Color = lightData->diffuseColor; - //plight.Radius = 100; - //plight.Bright = 0.9f; - //Oyster::Graphics::API::AddLight(plight); - } - break; - default: break; - } - } - break; - default: - break; - } - } - myId += modelId++; - // add player model - //modelData.position = ; - //modelData.rotation = Quaternion(Float3(2,2,-2), 1); - //modelData.scale = Float3(2,2,2); - - - modelData.visible = true; - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; - // load models - this->dynamicObjects.Push(new C_DynamicObj()); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); - - /*C_Player* obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - */ - return true; - -} - -bool GameState::InitCamera(Float3 startPos) -{ - camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) ); - camera.SetPerspectiveProjection( pi / 4.0f, 1024.0f/768.0f, 1.0f, 1000.0f ); - camera.UpdateOrientation(); - Oyster::Graphics::API::SetProjection(camera.GetProjectionMatrix()); - - return true; -} - -void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world) -{ - myId = id; + this->privData->myId = id; ModelInitData modelData; - C_Object* obj; modelData.visible = true; - //modelData.world = world; modelData.position = Float3(world[12], world[13], world[14]); modelData.rotation = Quaternion(Float3(0,0,0), 1); modelData.scale = Float3(1,1,1); modelData.modelPath = modelName; - modelData.id = myId; - - obj = new C_Player(); - this->dynamicObjects.Push(obj); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + modelData.id = this->privData->myId; + this->privData->player.Init( modelData ); - Float3 pos = Float3(world[12], world[13], world[14]); - - camera.SetPosition( pos ); - camera.UpdateOrientation(); + this->privData->camera.SetPosition( this->privData->player.getPos() ); + this->privData->camera.UpdateOrientation(); } GameClientState::ClientState GameState::Update( float deltaTime ) { - //switch (privData->state) - //{ - //case gameStateState_loading: //Will this ever happen in this scope?? - // { - // // load map - // // wait for all players - // LoadGame(); - // GameLogic::Protocol_General_Status gameStatus; - // gameStatus.status = GameLogic::Protocol_General_Status::States_ready; - // privData->nwClient->Send(gameStatus); - // privData->state = gameStateState_playing; - // } - // break; - //case gameStateState_playing: - // // read server data - // // update objects - // { - // readKeyInput(KeyInput); - // camera.UpdateOrientation(); - // } - // break; - //case gameStateState_end: - // return ClientState_Lobby; - // break; - //default: - // break; - //} - // - //// send key input to server. - //return ClientState_Same; - return this->privData->nextState; } bool GameState::Render() { - Oyster::Graphics::API::SetView( camera.GetViewMatrix() ); + Oyster::Graphics::API::SetView( this->privData->camera.GetViewMatrix() ); Oyster::Graphics::API::NewFrame(); - for (unsigned int i = 0; i < staticObjects.Size(); i++) + + // for debugging to be replaced with render weapon + this->privData->player.Render(); + + auto staticObject = this->privData->staticObjects->begin(); + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { - staticObjects[i]->Render(); + staticObject->second->Render(); } - for (unsigned int i = 0; i < dynamicObjects.Size(); i++) + + auto dynamicObject = this->privData->dynamicObjects->begin(); + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - dynamicObjects[i]->Render(); + dynamicObject->second->Render(); } Oyster::Graphics::API::EndFrame(); @@ -242,8 +124,25 @@ bool GameState::Render() bool GameState::Release() { + if( privData ) + { + auto staticObject = this->privData->staticObjects->begin(); + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + { + staticObject->second = nullptr; + } - privData = NULL; + auto dynamicObject = this->privData->dynamicObjects->begin(); + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) + { + dynamicObject->second = nullptr; + } + + this->privData->staticObjects->clear(); + this->privData->dynamicObjects->clear(); + + privData = NULL; + } return true; } @@ -252,138 +151,119 @@ void GameState::ChangeState( ClientState next ) this->privData->nextState = next; } -void GameState::readKeyInput(InputClass* KeyInput) +void GameState::ReadKeyInput() { - if(KeyInput->IsKeyPressed(DIK_W)) + if( this->privData->input->IsKeyPressed(DIK_W) ) { - if(!key_forward) + if(!this->privData->key_forward) { - privData->nwClient->Send(GameLogic::Protocol_PlayerMovementForward()); - key_forward = true; + this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); + this->privData->key_forward = true; } } else - key_forward = false; + this->privData->key_forward = false; - if(KeyInput->IsKeyPressed(DIK_S)) + if( this->privData->input->IsKeyPressed(DIK_S) ) { - if(!key_backward) + if( !this->privData->key_backward ) { - privData->nwClient->Send(GameLogic::Protocol_PlayerMovementBackward()); - key_backward = true; + this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); + this->privData->key_backward = true; } } else - key_backward = false; + this->privData->key_backward = false; - if(KeyInput->IsKeyPressed(DIK_A)) + if( this->privData->input->IsKeyPressed(DIK_A) ) { - if(!key_strafeLeft) + if( !this->privData->key_strafeLeft ) { - privData->nwClient->Send(GameLogic::Protocol_PlayerMovementLeft()); - key_strafeLeft = true; + this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); + this->privData->key_strafeLeft = true; } } else - key_strafeLeft = false; + this->privData->key_strafeLeft = false; - if(KeyInput->IsKeyPressed(DIK_D)) + if( this->privData->input->IsKeyPressed(DIK_D) ) { - if(!key_strafeRight) + if( !this->privData->key_strafeRight ) { - privData->nwClient->Send(GameLogic::Protocol_PlayerMovementRight()); - key_strafeRight = true; + this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); + this->privData->key_strafeRight = true; } } else - key_strafeRight = false; + this->privData->key_strafeRight = false; //send delta mouse movement - //if (KeyInput->IsMousePressed()) { - camera.YawRight( -KeyInput->GetYaw() ); - camera.PitchUp( KeyInput->GetPitch() ); - camera.UpdateOrientation(); + this->privData->camera.YawRight( -this->privData->input->GetYaw() ); + this->privData->camera.PitchUp( this->privData->input->GetPitch() ); + this->privData->camera.UpdateOrientation(); - GameLogic::Protocol_PlayerLook playerLookDir; - Float4 look = camera.GetLook(); - - privData->nwClient->Send( playerLookDir ); + privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) ); } // shoot - if(KeyInput->IsKeyPressed(DIK_Z)) + if( this->privData->input->IsKeyPressed(DIK_Z) ) { - if(!key_Shoot) + if( !this->privData->key_Shoot ) { - GameLogic::Protocol_PlayerShot playerShot; + Protocol_PlayerShot playerShot; playerShot.primaryPressed = true; playerShot.secondaryPressed = false; playerShot.utilityPressed = false; - privData->nwClient->Send(playerShot); - key_Shoot = true; + this->privData->nwClient->Send( playerShot ); + this->privData->key_Shoot = true; } } else - key_Shoot = false; - if(KeyInput->IsKeyPressed(DIK_X)) + this->privData->key_Shoot = false; + if( this->privData->input->IsKeyPressed(DIK_X) ) { - if(!key_Shoot) + if( !this->privData->key_Shoot ) { - GameLogic::Protocol_PlayerShot playerShot; + Protocol_PlayerShot playerShot; playerShot.primaryPressed = false; playerShot.secondaryPressed = true; playerShot.utilityPressed = false; - privData->nwClient->Send(playerShot); - key_Shoot = true; + this->privData->nwClient->Send( playerShot ); + this->privData->key_Shoot = true; } } else - key_Shoot = false; - if(KeyInput->IsKeyPressed(DIK_C)) + this->privData->key_Shoot = false; + if( this->privData->input->IsKeyPressed(DIK_C) ) { - if(!key_Shoot) + if( !this->privData->key_Shoot ) { - GameLogic::Protocol_PlayerShot playerShot; + Protocol_PlayerShot playerShot; playerShot.primaryPressed = false; playerShot.secondaryPressed = false; playerShot.utilityPressed = true; - privData->nwClient->Send(playerShot); - key_Shoot = true; + this->privData->nwClient->Send( playerShot ); + this->privData->key_Shoot = true; } } else - key_Shoot = false; + this->privData->key_Shoot = false; // jump - if(KeyInput->IsKeyPressed(DIK_SPACE)) + if( this->privData->input->IsKeyPressed(DIK_SPACE) ) { - if(!key_Jump) + if(!this->privData->key_Jump) { - privData->nwClient->Send(GameLogic::Protocol_PlayerJump()); - key_Jump = true; + this->privData->nwClient->Send( Protocol_PlayerJump() ); + this->privData->key_Jump = true; } } else - key_Jump = false; + this->privData->key_Jump = false; - // send event data - // - //if(KeyInput->IsKeyPressed(DIK_L)) - // privData->state = GameState::gameStateState_end; -} - -using namespace ::Oyster::Network; -using namespace ::Utility::DynamicMemory; - -// returns -1 if none found -int FindObject( const DynamicArray> &collection, int id ) -{ - int num = collection.Size(); - for( int i = 0; i < num; ++i ) if( id == collection[i]->GetId() ) - return i; - return -1; + // TODO: implement sub-menu } void GameState::DataRecieved( NetEvent e ) @@ -400,76 +280,67 @@ void GameState::DataRecieved( NetEventmyId == decoded.object_ID ) - camera.SetPosition( decoded.position ); + if( this->privData->myId == decoded.object_ID ) + this->privData->camera.SetPosition( decoded.position ); - int i = FindObject( this->dynamicObjects, decoded.object_ID ); - if( i > -1 ) - this->dynamicObjects[i]->setPos( decoded.position ); + (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); } break; case protocol_Gameplay_ObjectScale: { - GameLogic::Protocol_ObjectScale decoded(data); - int i = FindObject( this->dynamicObjects, decoded.object_ID ); - if( i > -1 ) - this->dynamicObjects[i]->setScale( decoded.scale ); + Protocol_ObjectScale decoded(data); + (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); } break; case protocol_Gameplay_ObjectRotation: { - GameLogic::Protocol_ObjectRotation decoded(data); + Protocol_ObjectRotation decoded(data); Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); // if is this player. Remember to change camera - if( this->myId == decoded.object_ID ) - camera.SetAngular( AngularAxis(rotation) ); + if( this->privData->myId == decoded.object_ID ) + this->privData->camera.SetAngular( AngularAxis(rotation) ); - int i = FindObject( this->dynamicObjects, decoded.object_ID ); - if( i > -1 ) - this->dynamicObjects[i]->setRot( rotation ); + (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); } break; case protocol_Gameplay_ObjectPositionRotation: { - GameLogic::Protocol_ObjectPositionRotation decoded(data); + Protocol_ObjectPositionRotation decoded(data); Float3 position = decoded.position; Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); // if is this player. Remember to change camera - if( this->myId == decoded.object_ID ) + if( this->privData->myId == decoded.object_ID ) { - camera.SetPosition( position ); - camera.SetAngular( AngularAxis(rotation) ); + this->privData->camera.SetPosition( position ); + this->privData->camera.SetAngular( AngularAxis(rotation) ); } - int i = FindObject( this->dynamicObjects, decoded.object_ID ); - if( i > -1 ) - { - this->dynamicObjects[i]->setPos( position ); - this->dynamicObjects[i]->setRot( rotation ); - } + C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; + object->setPos( position ); + object->setRot( rotation ); } break; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDisabled: { - GameLogic::Protocol_ObjectDisable decoded(data); + Protocol_ObjectDisable decoded(data); - int i = FindObject( this->dynamicObjects, decoded.objectID ); - if( i > -1 ) + auto object = this->privData->dynamicObjects->find( decoded.objectID ); + if( object != this->privData->dynamicObjects->end() ) { - this->dynamicObjects[i].Release(); - this->dynamicObjects.Pop(i); + object->second = nullptr; + this->privData->dynamicObjects->erase( object ); } } break; case protocol_Gameplay_ObjectCreate: { - GameLogic::Protocol_ObjectCreate decoded(data); + Protocol_ObjectCreate decoded(data); C_DynamicObj* object = new C_DynamicObj(); ModelInitData modelData; @@ -484,7 +355,7 @@ void GameState::DataRecieved( NetEventInit(modelData); - dynamicObjects.Push(object); + (*this->privData->dynamicObjects)[decoded.object_ID] = object; } break; diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 5a3b3c1a..29ea2f1e 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -4,13 +4,6 @@ #include "OysterMath.h" #include -#include "Camera_FPS.h" -#include "LevelLoader/LevelLoader.h" -#include "C_obj/C_Player.h" -#include "C_obj/C_DynamicObj.h" -#include "C_obj/C_StaticObj.h" -#include "DynamicArray.h" - namespace DanBias { namespace Client { class GameState : public GameClientState @@ -27,12 +20,8 @@ namespace DanBias { namespace Client ~GameState(void); bool Init( SharedStateContent &shared ); GameClientState::ClientState Update( float deltaTime ) override; - - bool LoadModels(std::string mapFile); - bool InitCamera(Oyster::Math::Float3 startPos) ; - void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world); - gameStateState LoadGame(); - void readKeyInput(InputClass* KeyInput); + void InitiatePlayer( int id, std::wstring modelName, Oyster::Math::Float4x4 world ); + void ReadKeyInput(); bool Render()override; bool Release()override; @@ -43,20 +32,6 @@ namespace DanBias { namespace Client private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; - - bool key_forward; - bool key_backward; - bool key_strafeRight; - bool key_strafeLeft; - bool key_Shoot; - bool key_Jump; - Camera_FPS camera; - - int myId; - - Utility::DynamicMemory::DynamicArray> staticObjects; - Utility::DynamicMemory::DynamicArray> dynamicObjects; - //Utility::DynamicMemory::DynamicArray> playObjects; }; } } #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 3051c097..0615f209 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -123,8 +123,8 @@ void LanMenuState::ChangeState( ClientState next ) { case GameClientState::ClientState_Lobby: // attempt to connect to lobby - //if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) - // return; // TODO: temporary commented out + if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) + return; break; default: break; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 3463182e..8274472d 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -1,13 +1,18 @@ #include "NetLoadState.h" #include "NetworkClient.h" #include "OysterMath.h" -#include "../Game/GameProtocols/Protocols.h" +#include "Protocols.h" +#include "LevelLoader\LevelLoader.h" +#include "Utilities.h" +#include "C_obj\C_StaticObj.h" +#include "C_obj\C_DynamicObj.h" using namespace ::DanBias::Client; using namespace ::Oyster; using namespace ::Oyster::Math; using namespace ::Oyster::Network; using namespace ::GameLogic; +using namespace ::Utility::String; struct NetLoadState::MyData { @@ -16,9 +21,17 @@ struct NetLoadState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; Graphics::API::Texture background; + ::std::map> *staticObjects; + ::std::map> *dynamicObjects; + bool loading; }; +inline Quaternion ArrayToQuaternion( float source[4] ) +{ + return Quaternion( Float3(source[0], source[1], source[2]), source[3] ); +} + NetLoadState::NetLoadState(void) {} NetLoadState::~NetLoadState(void) @@ -31,9 +44,12 @@ bool NetLoadState::Init( SharedStateContent &shared ) { this->privData = new MyData(); - this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = shared.network; - this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->nextState = GameClientState::ClientState_Same; + this->privData->nwClient = shared.network; + this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->dynamicObjects = &shared.dynamicObjects; + this->privData->staticObjects = &shared.staticObjects; + this->privData->loading = false; // we may assume that nwClient is properly connected to the server @@ -82,6 +98,7 @@ void NetLoadState::DataRecieved( NetEventprivData->loading ) { this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName ); + this->ChangeState( ClientState_Game ); } } @@ -89,7 +106,69 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) { this->privData->loading = true; - // TODO: ask Sam about level loader + LevelLoader loader; + auto objects = loader.LoadLevel( fileName ); + auto object = objects.begin(); + ObjectHeader *oh; + + int objectID = 100; // first 100 is reserved for players. This is how the server does it. + + for( ; object != objects.end(); ++object ) + { + ++objectID; + oh = (ObjectHeader*)&*object; + switch( oh->typeID ) + { + case ObjectType::ObjectType_Static: + { + ModelInitData desc; + desc.id = objectID; + StringToWstring( oh->ModelFile, desc.modelPath ); + desc.position = oh->position; + desc.rotation = ArrayToQuaternion( oh->rotation ); + desc.scale = oh->scale; + desc.visible = true; + + C_StaticObj *staticObject = new C_StaticObj(); + if( staticObject->Init( desc ) ) + { + (*this->privData->staticObjects)[objectID] = staticObject; + } + else + { + delete staticObject; + } + } + break; + case ObjectType::ObjectType_Dynamic: + { + ModelInitData desc; + desc.id = objectID; + StringToWstring( oh->ModelFile, desc.modelPath ); + desc.position = oh->position; + desc.rotation = ArrayToQuaternion( oh->rotation ); + desc.scale = oh->scale; + desc.visible = true; + + C_DynamicObj *dynamicObject = new C_DynamicObj(); + if( dynamicObject->Init( desc ) ) + { + (*this->privData->dynamicObjects)[objectID] = dynamicObject; + } + else + { + delete dynamicObject; + } + } + break; + case ObjectType::ObjectType_Light: + { + /* TODO: implement light into the leveformat */ + } + break; + default: break; + } + } this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index 2fabb1ac..da9dc759 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -11,6 +11,8 @@ #include #include "Utilities.h" #include "C_Object.h" +#include "C_obj\C_StaticObj.h" +#include "C_obj\C_DynamicObj.h" #include "NetworkClient.h" #include "L_inputClass.h" @@ -19,8 +21,8 @@ namespace DanBias { namespace Client struct SharedStateContent { public: - ::std::map> staticObjects; - ::std::map> dynamicObjects; + ::std::map> staticObjects; + ::std::map> dynamicObjects; ::Oyster::Network::NetworkClient *network; InputClass* input; }; From 2bc7c9f65f4088547f4b712fa3e0878d1e20a488 Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 17 Feb 2014 15:11:12 +0100 Subject: [PATCH 06/39] GameServer - added more features to object protocols --- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- Code/Game/GameLogic/GameLogic.vcxproj.user | 2 +- Code/Game/GameProtocols/ObjectProtocols.h | 54 +++++++++++++++---- .../GameServer/Implementation/GameLobby.cpp | 3 -- .../GameServer/Implementation/GameServer.cpp | 4 -- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) diff --git a/Code/Game/GameLogic/GameLogic.vcxproj.user b/Code/Game/GameLogic/GameLogic.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj.user +++ b/Code/Game/GameLogic/GameLogic.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 70e24883..e3449022 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -476,7 +476,21 @@ namespace GameLogic } Protocol_ObjectCreate( Oyster::Network::CustomNetProtocol& p ) { - /** @todo TODO: not implemented */ + this->object_ID = p[1].value.netInt; + this->name.assign(p[2].value.netCharPtr); + + this->position[0] = p[3].value.netFloat; + this->position[1] = p[4].value.netFloat; + this->position[2] = p[5].value.netFloat; + + this->rotationQ[0] = p[6].value.netFloat; + this->rotationQ[1] = p[7].value.netFloat; + this->rotationQ[2] = p[8].value.netFloat; + this->rotationQ[3] = p[9].value.netFloat; + + this->scale[0] = p[10].value.netFloat; + this->scale[1] = p[11].value.netFloat; + this->scale[2] = p[12].value.netFloat; } Protocol_ObjectCreate(float p[3], float r[4], float s[3], int id, char *path) { @@ -538,7 +552,7 @@ namespace GameLogic std::string name; std::string meshName; float position[3]; - float rotation[3]; + float rotationQ[4]; float scale[3]; Protocol_ObjectCreatePlayer() @@ -569,9 +583,25 @@ namespace GameLogic } Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { + this->object_ID = p[1].value.netInt; + this->teamId = this->protocol[2].value.netInt; + this->name.assign(p[3].value.netCharPtr); + this->meshName.assign(p[4].value.netCharPtr); + + this->position[0] = p[5].value.netFloat; + this->position[1] = p[6].value.netFloat; + this->position[2] = p[7].value.netFloat; + this->rotationQ[0] = p[8].value.netFloat; + this->rotationQ[1] = p[9].value.netFloat; + this->rotationQ[2] = p[10].value.netFloat; + this->rotationQ[3] = p[11].value.netFloat; + + this->scale[0] = p[12].value.netFloat; + this->scale[1] = p[13].value.netFloat; + this->scale[2] = p[14].value.netFloat; } - Protocol_ObjectCreatePlayer(float position[3], float rotation[3], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName) + Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName) { this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; @@ -592,17 +622,18 @@ namespace GameLogic this->protocol[8].type = Oyster::Network::NetAttributeType_Float; this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float; - //SCALE this->protocol[11].type = Oyster::Network::NetAttributeType_Float; + //SCALE this->protocol[12].type = Oyster::Network::NetAttributeType_Float; this->protocol[13].type = Oyster::Network::NetAttributeType_Float; + this->protocol[14].type = Oyster::Network::NetAttributeType_Float; this->object_ID = ObjectID; this->teamId = teamID; this->name = name; this->meshName = meshName; memcpy(&this->position[0], &position[0], sizeof(float)*3); - memcpy(&this->rotation[0], &rotation[0], sizeof(float)*3); + memcpy(&this->rotationQ[0], &rotation[0], sizeof(float)*4); memcpy(&this->scale[0], &scale[0], sizeof(float)*3); } Oyster::Network::CustomNetProtocol GetProtocol() override @@ -618,13 +649,14 @@ namespace GameLogic this->protocol[6].value = this->position[1]; this->protocol[7].value = this->position[2]; //ROTATION - this->protocol[8].value = this->rotation[0]; - this->protocol[9].value = this->rotation[1]; - this->protocol[10].value = this->rotation[2]; + this->protocol[8].value = this->rotationQ[0]; + this->protocol[9].value = this->rotationQ[1]; + this->protocol[10].value = this->rotationQ[2]; + this->protocol[11].value = this->rotationQ[3]; //SCALE - this->protocol[11].value = this->scale[0]; - this->protocol[12].value = this->scale[1]; - this->protocol[13].value = this->scale[2]; + this->protocol[12].value = this->scale[0]; + this->protocol[13].value = this->scale[1]; + this->protocol[14].value = this->scale[2]; return protocol; } diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 1b8b63ec..82599677 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -15,18 +15,15 @@ namespace DanBias { GameLobby::GameLobby() { } - GameLobby::~GameLobby() { this->clients.Clear(); } - void GameLobby::Release() { NetworkSession::CloseSession(true); this->gameSession.CloseSession(true); } - void GameLobby::Update() { this->ProcessClients(); diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 4fd6e03c..087fa7ff 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -61,8 +61,6 @@ void GameServerAPI::ServerStart() { timer.reset(); server.Start(); - - } void GameServerAPI::ServerStop() { @@ -113,8 +111,6 @@ void GameServerAPI::NotifyWhenClientConnect(ClientConnectedNotify func) { if(!func) clientConnectedCallback = DefaultClientConnectedNotify; else clientConnectedCallback = func; - - } void GameServerAPI::NotifyWhenClientDisconnect(ClientDisconnectedNotify func) { From 12623d1b167bed917d140030fb371946f2e828d3 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 16:16:27 +0100 Subject: [PATCH 07/39] Bunch of implementations --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 6 +-- Code/Game/GameClient/GameClient.vcxproj | 8 +-- .../GameClient/GameClientState/GameState.cpp | 50 ++++++++++++++----- .../GameClient/GameClientState/GameState.h | 3 +- .../GameClientState/NetLoadState.cpp | 13 +++-- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 392e917f..81650049 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -99,9 +99,6 @@ namespace DanBias data.timer.reset(); Graphics::API::Update( dt ); - - if(data.networkClient.IsConnected()) - data.networkClient.Update(); data.capFrame += dt; if(data.capFrame > 0.03) @@ -118,6 +115,9 @@ namespace DanBias data.capFrame = 0; } + if(data.networkClient.IsConnected()) + data.networkClient.Update(); + } return DanBiasClientReturn_Success; } diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index a87f61e4..3daafff3 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -112,7 +112,7 @@ Windows true %(AdditionalDependencies) - NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;GameClient_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -129,7 +129,7 @@ Windows true %(AdditionalDependencies) - NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;GameClient_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -150,7 +150,7 @@ true true %(AdditionalDependencies) - NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;GameClient_$(PlatformShortName).dll;%(DelayLoadDLLs) @@ -171,7 +171,7 @@ true true %(AdditionalDependencies) - NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs) + NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;GameClient_$(PlatformShortName).dll;%(DelayLoadDLLs) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 29cfec03..38ded541 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -8,6 +8,7 @@ #include "C_obj/C_Player.h" #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" +#include "Utilities.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -15,6 +16,7 @@ using namespace ::Oyster::Network; using namespace ::Oyster::Math3D; using namespace ::GameLogic; using namespace ::Utility::DynamicMemory; +using namespace ::Utility::String; struct GameState::MyData { @@ -40,6 +42,11 @@ struct GameState::MyData } privData; +inline Quaternion ArrayToQuaternion( const float source[4] ) +{ + return Quaternion( Float3(source[0], source[1], source[2]), source[3] ); +} + GameState::GameState() { this->privData = nullptr; @@ -75,21 +82,33 @@ bool GameState::Init( SharedStateContent &shared ) return true; } -void GameState::InitiatePlayer( int id, std::wstring modelName, Float4x4 world ) +void GameState::InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3], bool isMyPlayer ) { - this->privData->myId = id; - ModelInitData modelData; - modelData.visible = true; - modelData.position = Float3(world[12], world[13], world[14]); - modelData.rotation = Quaternion(Float3(0,0,0), 1); - modelData.scale = Float3(1,1,1); - modelData.modelPath = modelName; - modelData.id = this->privData->myId; - this->privData->player.Init( modelData ); + modelData.visible = true; + modelData.position = position; + modelData.rotation = ArrayToQuaternion( rotation ); + modelData.scale = scale; + StringToWstring( modelName, modelData.modelPath ); + modelData.id = id; - this->privData->camera.SetPosition( this->privData->player.getPos() ); - this->privData->camera.UpdateOrientation(); + if( isMyPlayer ) + { + if( this->privData->player.Init(modelData) ) + { + this->privData->myId = id; + this->privData->camera.SetPosition( this->privData->player.getPos() ); + this->privData->camera.UpdateOrientation(); + } + } + else + { + C_DynamicObj *p = new C_DynamicObj(); + if( p->Init(modelData) ) + { + (*this->privData->dynamicObjects)[id] = p; + } + } } GameClientState::ClientState GameState::Update( float deltaTime ) @@ -359,7 +378,12 @@ void GameState::DataRecieved( NetEventInitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotation, decoded.scale, decoded.owner ); + } + break; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 29ea2f1e..e3ced125 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -20,9 +20,8 @@ namespace DanBias { namespace Client ~GameState(void); bool Init( SharedStateContent &shared ); GameClientState::ClientState Update( float deltaTime ) override; - void InitiatePlayer( int id, std::wstring modelName, Oyster::Math::Float4x4 world ); + void InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3] ); void ReadKeyInput(); - bool Render()override; bool Release()override; void ChangeState( ClientState next ); diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 8274472d..f50db40c 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -27,7 +27,7 @@ struct NetLoadState::MyData bool loading; }; -inline Quaternion ArrayToQuaternion( float source[4] ) +inline Quaternion ArrayToQuaternion( const float source[4] ) { return Quaternion( Float3(source[0], source[1], source[2]), source[3] ); } @@ -99,6 +99,7 @@ void NetLoadState::DataRecieved( NetEventLoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName ); this->ChangeState( ClientState_Game ); + this->privData->loading = false; } } @@ -109,18 +110,20 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) LevelLoader loader; auto objects = loader.LoadLevel( fileName ); auto object = objects.begin(); - ObjectHeader *oh; + ObjectTypeHeader *oth; int objectID = 100; // first 100 is reserved for players. This is how the server does it. for( ; object != objects.end(); ++object ) { ++objectID; - oh = (ObjectHeader*)&*object; - switch( oh->typeID ) + oth = (ObjectTypeHeader*)(*object._Ptr); + switch( oth->typeID ) { case ObjectType::ObjectType_Static: { + ObjectHeader *oh = (ObjectHeader*)oth; + ModelInitData desc; desc.id = objectID; StringToWstring( oh->ModelFile, desc.modelPath ); @@ -142,6 +145,8 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) break; case ObjectType::ObjectType_Dynamic: { + ObjectHeader *oh = (ObjectHeader*)oth; + ModelInitData desc; desc.id = objectID; StringToWstring( oh->ModelFile, desc.modelPath ); From 830b448690b04e288ae42c10c47f496e05629add Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 17 Feb 2014 16:17:07 +0100 Subject: [PATCH 08/39] Temp --- Code/Game/GameProtocols/ObjectProtocols.h | 93 +++---- Code/Game/GameServer/GameLobby.h | 3 +- .../GameServer/Implementation/GameLobby.cpp | 229 +++++++++--------- .../GameLobby_ProtocolParser.cpp | 31 ++- .../Implementation/GameSession_General.cpp | 1 + 5 files changed, 199 insertions(+), 158 deletions(-) diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index e3449022..ff6aa6e5 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -546,14 +546,14 @@ namespace GameLogic //#define protocol_Gameplay_ObjectCreatePlayer 359 struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject { - //ObjectType type; //ie player, box or whatever - int object_ID; - int teamId; - std::string name; - std::string meshName; - float position[3]; - float rotationQ[4]; - float scale[3]; + /*1*/ int object_ID; + /*2*/ int teamId; + /*3*/ bool owner; + /*4*/ std::string name; + /*5*/ std::string meshName; + /*6 - 8*/ float position[3]; + /*9 - 11*/ float rotationQ[4]; + /*12 - 14*/ float scale[3]; Protocol_ObjectCreatePlayer() { @@ -564,44 +564,47 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + //OWNER + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; //PLAYER-NAME - this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; - //MESH-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; + //MESH-NAME + this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray; //POSITION - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; this->protocol[6].type = Oyster::Network::NetAttributeType_Float; this->protocol[7].type = Oyster::Network::NetAttributeType_Float; - //ROTATION this->protocol[8].type = Oyster::Network::NetAttributeType_Float; + //ROTATION this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float; - //SCALE this->protocol[11].type = Oyster::Network::NetAttributeType_Float; + //SCALE this->protocol[12].type = Oyster::Network::NetAttributeType_Float; this->protocol[13].type = Oyster::Network::NetAttributeType_Float; + this->protocol[14].type = Oyster::Network::NetAttributeType_Float; } Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { this->object_ID = p[1].value.netInt; this->teamId = this->protocol[2].value.netInt; - this->name.assign(p[3].value.netCharPtr); - this->meshName.assign(p[4].value.netCharPtr); + this->owner = this->protocol[3].value.netBool; + this->name.assign(p[4].value.netCharPtr); + this->meshName.assign(p[5].value.netCharPtr); - this->position[0] = p[5].value.netFloat; - this->position[1] = p[6].value.netFloat; - this->position[2] = p[7].value.netFloat; + this->position[0] = p[6].value.netFloat; + this->position[1] = p[7].value.netFloat; + this->position[2] = p[8].value.netFloat; - this->rotationQ[0] = p[8].value.netFloat; - this->rotationQ[1] = p[9].value.netFloat; - this->rotationQ[2] = p[10].value.netFloat; - this->rotationQ[3] = p[11].value.netFloat; + this->rotationQ[0] = p[9].value.netFloat; + this->rotationQ[1] = p[10].value.netFloat; + this->rotationQ[2] = p[11].value.netFloat; + this->rotationQ[3] = p[12].value.netFloat; - this->scale[0] = p[12].value.netFloat; - this->scale[1] = p[13].value.netFloat; - this->scale[2] = p[14].value.netFloat; + this->scale[0] = p[13].value.netFloat; + this->scale[1] = p[14].value.netFloat; + this->scale[2] = p[15].value.netFloat; } - Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, int teamID, std::string name, std::string meshName) + Protocol_ObjectCreatePlayer(float position[3], float rotation[4], float scale[3], int ObjectID, bool owner, int teamID, std::string name, std::string meshName) { this->protocol[0].value = protocol_Gameplay_ObjectCreatePlayer; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; @@ -610,26 +613,29 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + //OWNER + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; //PLAYER-NAME - this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; - //MESH-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; + //MESH-NAME + this->protocol[5].type = Oyster::Network::NetAttributeType_CharArray; //POSITION - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; this->protocol[6].type = Oyster::Network::NetAttributeType_Float; this->protocol[7].type = Oyster::Network::NetAttributeType_Float; - //ROTATION this->protocol[8].type = Oyster::Network::NetAttributeType_Float; + //ROTATION this->protocol[9].type = Oyster::Network::NetAttributeType_Float; this->protocol[10].type = Oyster::Network::NetAttributeType_Float; this->protocol[11].type = Oyster::Network::NetAttributeType_Float; - //SCALE this->protocol[12].type = Oyster::Network::NetAttributeType_Float; + //SCALE this->protocol[13].type = Oyster::Network::NetAttributeType_Float; this->protocol[14].type = Oyster::Network::NetAttributeType_Float; + this->protocol[15].type = Oyster::Network::NetAttributeType_Float; this->object_ID = ObjectID; this->teamId = teamID; + this->owner = owner; this->name = name; this->meshName = meshName; memcpy(&this->position[0], &position[0], sizeof(float)*3); @@ -641,22 +647,23 @@ namespace GameLogic this->protocol[1].value = this->object_ID; this->protocol[2].value = this->teamId; - this->protocol.Set(3, this->name); - this->protocol.Set(4, this->meshName); + this->protocol[3].value = this->owner; + this->protocol.Set(4, this->name); + this->protocol.Set(5, this->meshName); //POSITION - this->protocol[5].value = this->position[0]; - this->protocol[6].value = this->position[1]; - this->protocol[7].value = this->position[2]; + this->protocol[6].value = this->position[0]; + this->protocol[7].value = this->position[1]; + this->protocol[8].value = this->position[2]; //ROTATION - this->protocol[8].value = this->rotationQ[0]; - this->protocol[9].value = this->rotationQ[1]; - this->protocol[10].value = this->rotationQ[2]; - this->protocol[11].value = this->rotationQ[3]; + this->protocol[9].value = this->rotationQ[0]; + this->protocol[10].value = this->rotationQ[1]; + this->protocol[11].value = this->rotationQ[2]; + this->protocol[12].value = this->rotationQ[3]; //SCALE - this->protocol[12].value = this->scale[0]; - this->protocol[13].value = this->scale[1]; - this->protocol[14].value = this->scale[2]; + this->protocol[13].value = this->scale[0]; + this->protocol[14].value = this->scale[1]; + this->protocol[15].value = this->scale[2]; return protocol; } diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 86cd498a..d0cbbcc3 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -41,11 +41,12 @@ namespace DanBias //void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create: void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: //void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join: - void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: + void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh: void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData: void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData: void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: + void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: private: void ClientEventCallback(Oyster::Network::NetEvent e) override; diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 82599677..6f4f0a47 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -11,127 +11,132 @@ using namespace Oyster::Network; using namespace Oyster; using namespace GameLogic; -namespace DanBias +using namespace DanBias; + +GameLobby::GameLobby() +{ } +GameLobby::~GameLobby() +{ + this->clients.Clear(); +} +void GameLobby::Release() +{ + NetworkSession::CloseSession(true); + this->gameSession.CloseSession(true); +} +void GameLobby::Update() { - GameLobby::GameLobby() - { } - GameLobby::~GameLobby() - { - this->clients.Clear(); - } - void GameLobby::Release() - { - NetworkSession::CloseSession(true); - this->gameSession.CloseSession(true); - } - void GameLobby::Update() + for (unsigned int i = 0; i < this->clients.Size(); i++) { - this->ProcessClients(); - } - void GameLobby::SetGameDesc(const LobbyLevelData& desc) - { - this->description.gameMode = desc.gameMode; - this->description.gameTime = desc.gameTime; - this->description.mapNumber = desc.mapNumber; - this->description.maxClients = desc.maxClients; - } - void GameLobby::GetGameDesc(LobbyLevelData& desc) - { - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; - desc.maxClients = this->description.maxClients; - } - bool GameLobby::StartGameSession( ) - { - //Check if all clients is ready - if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size()) + if(this->clients[i]) { - GameSession::GameDescription desc; - desc.maxClients = this->description.maxClients; - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; - desc.owner = this; - desc.clients = this->clients; + this->clients[i]->Update(); + } + } +} +void GameLobby::SetGameDesc(const LobbyLevelData& desc) +{ + this->description.gameMode = desc.gameMode; + this->description.gameTime = desc.gameTime; + this->description.mapNumber = desc.mapNumber; + this->description.maxClients = desc.maxClients; +} +void GameLobby::GetGameDesc(LobbyLevelData& desc) +{ + desc.gameMode = this->description.gameMode; + desc.gameTime = this->description.gameTime; + desc.mapNumber = this->description.mapNumber; + desc.maxClients = this->description.maxClients; +} +bool GameLobby::StartGameSession( ) +{ +//Check if all clients is ready + if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size()) + { + GameSession::GameDescription desc; + desc.maxClients = this->description.maxClients; + desc.gameMode = this->description.gameMode; + desc.gameTime = this->description.gameTime; + desc.mapNumber = this->description.mapNumber; + desc.owner = this; + desc.clients = this->clients; - if(desc.gameTime == 0.0f) - desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. + if(desc.gameTime == 0.0f) + desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. - if(desc.maxClients == 0) - desc.maxClients = 10; //note: should be fetched somewhere else.. + if(desc.maxClients == 0) + desc.maxClients = 10; //note: should be fetched somewhere else.. - this->clients.Clear(); //Remove clients from lobby list + this->clients.Clear(); //Remove clients from lobby list - if(this->gameSession.Create(desc)) - { - this->gameSession.Run(); + if(this->gameSession.Create(desc)) + { + this->gameSession.Run(); - return true; + return true; + } + } + else + { + //? + } + return false; +} + +void GameLobby::ClientEventCallback(NetEvent e) +{ + switch (e.args.type) + { + case NetworkClient::ClientEventArgs::EventType_Disconnect: + + break; + case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: + + break; + case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: + printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); + e.sender->Disconnect(); + this->readyList.Remove(e.sender); + this->clients.Remove(e.sender); + break; + case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: + printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); + this->ParseProtocol(e.args.data.protocol, e.sender); + break; + } +} +void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) +{ + printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); + + if(this->gameSession) + { + Attach(client); + } + else + { + Attach(client); + Protocol_LobbyClientData p1; + Protocol_LobbyGameData p2; + + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) + { + Protocol_LobbyClientData::PlayerData t; + t.id = this->clients[i]->GetID(); + t.ip = this->clients[i]->GetIpAddress(); + t.team = 0; + t.name = "Dennis är kung tycker Erik!"; + p1.list.Push(t); } } - else - { - //? - } - return false; + p2.majorVersion = 1; + p2.minorVersion = 0; + p2.mapName = "Dennis är kung tycker Erik!"; + + client->Send(p1.GetProtocol()); + client->Send(p2.GetProtocol()); } +} - void GameLobby::ClientEventCallback(NetEvent e) - { - switch (e.args.type) - { - case NetworkClient::ClientEventArgs::EventType_Disconnect: - - break; - case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: - - break; - case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: - printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); - e.sender->Disconnect(); - this->readyList.Remove(e.sender); - this->clients.Remove(e.sender); - break; - case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: - printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); - this->ParseProtocol(e.args.data.protocol, e.sender); - break; - } - } - void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) - { - printf("New client(%i) connected - %s \n", client->GetID(), client->GetIpAddress().c_str()); - - if(this->gameSession) - { - this->gameSession.Attach(client); - } - else - { - Attach(client); - Protocol_LobbyClientData p1; - Protocol_LobbyGameData p2; - - for (unsigned int i = 0; i < this->clients.Size(); i++) - { - if(this->clients[i]) - { - Protocol_LobbyClientData::PlayerData t; - t.id = this->clients[i]->GetID(); - t.ip = this->clients[i]->GetIpAddress(); - t.team = 0; - t.name = "Dennis är kung tycker Erik!"; - p1.list.Push(t); - } - } - p2.majorVersion = 1; - p2.minorVersion = 0; - p2.mapName = "Dennis är kung tycker Erik!"; - - client->Send(p1.GetProtocol()); - client->Send(p2.GetProtocol()); - } - } - -}//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index 7493cb5a..d49f83fc 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -18,11 +18,11 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie break; //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); //break; - case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); + case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); break; //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); //break; - case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); + case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); break; case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); break; @@ -32,6 +32,8 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie break; case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); break; + case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + break; } } @@ -112,4 +114,29 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: this->readyList.Remove(c); } } +void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) +{ + NetClient temp; + bool found = false; + //find client in waiting list + for (unsigned int i = 0; !found && i < this->clients.Size(); i++) + { + if(this->clients[i]->GetID() == c->GetID()) + { + temp = this->clients[i]; + found = true; + } + } + + //Something is wrong + if(!found) + { + c->Disconnect(); + } + else + { + //Send game data + this->gameSession.Attach(temp); + } +} diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 647cee4a..cf82cc61 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -209,6 +209,7 @@ namespace DanBias { IPlayerData* p = this->clients[i]->GetPlayer(); Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); + //Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); this->clients[i]->GetClient()->Send(oc); } } From 112f45463aad359580033a9152ce935dab8e34c9 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 16:18:21 +0100 Subject: [PATCH 09/39] Oops .. Forgot to save this one for the previous commit --- Code/Game/GameClient/GameClientState/GameState.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index e3ced125..035ad566 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -20,7 +20,7 @@ namespace DanBias { namespace Client ~GameState(void); bool Init( SharedStateContent &shared ); GameClientState::ClientState Update( float deltaTime ) override; - void InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3] ); + void InitiatePlayer( int id, const std::string &modelName, const float position[3], const float rotation[4], const float scale[3], bool isMyPlayer ); void ReadKeyInput(); bool Render()override; bool Release()override; From 6f368b45657c305085172a6e779e73f323a0f3d0 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 08:53:52 +0100 Subject: [PATCH 10/39] compilation error dealt with --- Code/Game/GameClient/GameClientState/GameState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 38ded541..2ae8ae21 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -381,7 +381,7 @@ void GameState::DataRecieved( NetEventInitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotation, decoded.scale, decoded.owner ); + this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); } break; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ From 5b4758d2ae478bd3b9d1913bd78a069e643b4592 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 18 Feb 2014 08:55:38 +0100 Subject: [PATCH 11/39] Broekn --- .../GameClientState/NetLoadState.cpp | 2 +- Code/Game/GameProtocols/LobbyProtocols.h | 68 ++-- Code/Game/GameServer/GameClient.h | 20 +- Code/Game/GameServer/GameLobby.h | 25 +- Code/Game/GameServer/GameSession.h | 14 +- .../GameServer/Implementation/GameClient.cpp | 55 +-- .../GameServer/Implementation/GameLobby.cpp | 8 +- .../GameLobby_ProtocolParser.cpp | 62 +-- .../Implementation/GameSession_Gameplay.cpp | 6 +- .../Implementation/GameSession_General.cpp | 354 ++++++++++-------- Code/Network/NetworkAPI/NetworkClient.h | 8 +- 11 files changed, 306 insertions(+), 316 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 3463182e..ab492797 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -81,7 +81,7 @@ void NetLoadState::DataRecieved( NetEventprivData->loading ) { - this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName ); + this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName ); } } diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h index 71202898..26909bbf 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -41,61 +41,41 @@ namespace GameLogic struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject { - short clientID; // The unuiqe id reprsenting a specific client - std::string modelName; - float worldMatrix[16]; - + char majorVersion; + char minorVersion; + std::string mapName; + Protocol_LobbyCreateGame() { - int c = 0; - this->protocol[c].value = protocol_Lobby_CreateGame; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].type = Oyster::Network::NetAttributeType_Float; - } - this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray; + this->protocol[0].value = protocol_Lobby_CreateGame; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + this->protocol[2].type = Oyster::Network::NetAttributeType_Char; + this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; } - Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16]) + Protocol_LobbyCreateGame(char majorVersion, char minorVersion, std::string name) { - int c = 0; - this->protocol[c].value = protocol_Lobby_CreateGame; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_CreateGame; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + this->protocol[2].type = Oyster::Network::NetAttributeType_Char; + this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].type = Oyster::Network::NetAttributeType_Float; - } - - this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray; - - clientID = _clientID; - modelName = name; - memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16); + this->majorVersion = majorVersion; + this->minorVersion = minorVersion; + this->mapName = name; } Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o) { - int c = 1; - clientID = o[c++].value.netInt; - for (int i = 0; i <= 16; i++) - { - this->worldMatrix[i] = o[c++].value.netFloat; - } - modelName.assign(o[c++].value.netCharPtr); + this->majorVersion = o[1].value.netChar; + this->minorVersion = o[2].value.netChar; + this->mapName.assign(o[3].value.netCharPtr); } Oyster::Network::CustomNetProtocol GetProtocol() override { - int c = 1; - protocol[c++].value = clientID; - - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].value = this->worldMatrix[i]; - } - protocol.Set(c++, this->modelName); + protocol[1].value = this->majorVersion; + protocol[2].value = this->minorVersion; + protocol.Set(3, this->mapName); return protocol; } diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index a9c33cf3..09b3bc40 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -25,19 +25,31 @@ namespace DanBias Utility::DynamicMemory::SmartPointer GetClient(); Utility::DynamicMemory::SmartPointer ReleaseClient(); - float GetSinceLastResponse() const; - bool IsReady() const; - bool Equals(const Oyster::Network::NetworkClient* c); + inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } + inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->GetID()); } + inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; } + inline std::wstring GetAlias() const { return this->alias; } + inline std::wstring GetCharacter() const { return this->character; } + inline bool IsReady() const { return this->isReady; } + inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } + + + void SetPlayer(GameLogic::IPlayerData* player); void SetReadyState(bool isReady); + void SetAlias(std::wstring alias); + void SetCharacter(std::wstring character); void SetSinceLastResponse(float seconds); private: GameLogic::IPlayerData* player; Utility::DynamicMemory::SmartPointer client; + bool isReady; float secondsSinceLastResponse; - }; + std::wstring alias; + std::wstring character; + }; }//End namespace DanBias #endif // !DANBIASSERVER_CLIENT_OBJECT_H diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index d0cbbcc3..ac4db486 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -36,25 +36,24 @@ namespace DanBias private: void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c); - void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status: - void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text: - //void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create: - void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: - //void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join: - void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: - void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh: - void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData: - void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData: - void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: - void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: + void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status: + void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text: + void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: + void LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: + void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh: + void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData: + void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData: + void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: + void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: private: void ClientEventCallback(Oyster::Network::NetEvent e) override; void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) override; private: - Utility::WinTimer timer; - float refreshFrequency; + //Utility::WinTimer timer; + //float refreshFrequency; + Utility::DynamicMemory::LinkedList readyList; GameSession gameSession; LobbyLevelData description; diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 3d86ea78..8cd04048 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -31,10 +31,10 @@ namespace DanBias */ struct GameDescription { - int maxClients; - int mapNumber; - int gameMode; - int gameTime; + unsigned int maxClients; + std::string mapName; + std::string gameMode; + int gameTimeMinutes; Oyster::Network::NetworkSession* owner; Utility::DynamicMemory::DynamicArray clients; }; @@ -61,14 +61,14 @@ namespace DanBias //Private member functions private: - // TODO: find out what this method does.. + // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent e) override; - //Sends a client to the owner, if obj is NULL then all clients is sent + //Sends a client to the owner, if param is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); //Derived from IThreadObject - void ThreadEntry() override; + void ThreadEntry( ) override; bool DoWork ( ) override; diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 3956fe57..6e68b1e8 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -12,51 +12,26 @@ using namespace DanBias; using namespace GameLogic; -GameClient::GameClient(SmartPointer client, GameLogic::IPlayerData* player) +GameClient::GameClient() { - this->client = client; - this->player = player; + this->player = 0; isReady = false; + this->character = L"Unknown"; + this->alias = L"Unknown"; + this->secondsSinceLastResponse = 0.0f; } GameClient::~GameClient() { - this->client->Disconnect(); this->player = 0; - isReady = false; + this->isReady = false; + this->character = L"Unknown"; + this->alias = L"Unknown"; + this->secondsSinceLastResponse = 0.0f; } -GameLogic::IPlayerData* GameClient::GetPlayer() +void GameClient::SetPlayer(GameLogic::IPlayerData* player) { - return this->player; -} -GameLogic::IPlayerData* GameClient::ReleasePlayer() -{ - GameLogic::IPlayerData *temp = this->player; - this->player = 0; - return temp; -} -SmartPointer GameClient::GetClient() -{ - return this->client; -} -SmartPointer GameClient::ReleaseClient() -{ - SmartPointer temp = this->client; - this->client = 0; - return temp; -} - -float GameClient::GetSinceLastResponse() const -{ - return this->secondsSinceLastResponse; -} -bool GameClient::IsReady() const -{ - return this->isReady; -} -bool GameClient::Equals(const NetworkClient* c) -{ - return (c->GetID() == this->client->GetID()); + this->player = player; } void GameClient::SetReadyState(bool r) { @@ -66,5 +41,13 @@ void GameClient::SetSinceLastResponse(float s) { this->secondsSinceLastResponse = s; } +void GameClient::SetAlias(std::wstring alias) +{ + this->alias = alias; +} +void GameClient::SetCharacter(std::wstring character) +{ + this->character = character; +} diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 6f4f0a47..2a297e2f 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -56,13 +56,13 @@ bool GameLobby::StartGameSession( ) GameSession::GameDescription desc; desc.maxClients = this->description.maxClients; desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; + desc.gameTimeMinutes = this->description.gameTime; + //desc.mapName = this->description.mapNumber; desc.owner = this; desc.clients = this->clients; - if(desc.gameTime == 0.0f) - desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. + if(desc.gameTimeMinutes == 0) + desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. if(desc.maxClients == 0) desc.maxClients = 10; //note: should be fetched somewhere else.. diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index d49f83fc..81758480 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -12,27 +12,23 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie { switch (p[0].value.netShort) { - case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c); + case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c); break; - case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); + case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); break; - //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); - //break; - case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); + case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); break; - //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); - //break; - case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); + case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c); break; - case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); + case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); break; - case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); + case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); break; - case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); + case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); break; - case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); break; - case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c); break; } } @@ -59,37 +55,40 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net } void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c) { + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) + { + this->clients[i]->Send(p); + } + } printf(p.text.c_str()); } -//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c) -//{ -// -//} void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c) { if(this->sessionOwner->GetClient()->GetID() == c->GetID()) { - + //Send countdown timer before lobby shuts down + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + this->clients[i]->Send(Protocol_LobbyStartGame(3.0f)); + } } else { //Someone else tried to start the server.. } } -//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c) -//{ -// //for (unsigned int i = 0; i < this->gameLobby.Size(); i++) -// //{ -// // if (this->gameLobby[i]->GetID() == p.value) -// // { -// // this->gameLobby[i]->Attach(Detach(c)); -// // return; -// // } -// //} -//} -void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c) +void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c) { - + //for (unsigned int i = 0; i < this->gameLobby.Size(); i++) + //{ + // if (this->gameLobby[i]->GetID() == p.value) + // { + // this->gameLobby[i]->Attach(Detach(c)); + // return; + // } + //} } void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c) { @@ -112,6 +111,7 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: else { this->readyList.Remove(c); + } } void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index ca1572a1..d0cf5190 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -19,11 +19,8 @@ using namespace Oyster; using namespace Oyster::Network; using namespace Oyster::Thread; using namespace GameLogic; +using namespace DanBias; -namespace DanBias -{ - Utility::WinTimer testTimer; - int testID = -1; bool GameSession::DoWork( ) { @@ -246,7 +243,6 @@ namespace DanBias printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str()); } -}//End namespace DanBias diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index cf82cc61..cd89dc9a 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -24,217 +24,243 @@ using namespace Oyster; using namespace Oyster::Network; using namespace Oyster::Thread; using namespace GameLogic; +using namespace DanBias; -namespace DanBias +GameSession* GameSession::gameSession = nullptr; + +GameSession::GameSession() + :gameInstance(GameAPI::Instance()) { - GameSession* GameSession::gameSession = nullptr; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; + this->gameSession = this; + this->logicFrameTime = DELTA_TIME_20; + this->networkFrameTime = DELTA_TIME_20; + this->networkTimer.reset(); + this->logicTimer.reset(); - GameSession::GameSession() - :gameInstance(GameAPI::Instance()) + memset(&this->description, 0, sizeof(GameDescription)); +} + +GameSession::~GameSession() +{ + this->worker.Terminate(); + this->clients.Clear(); + this->gameInstance; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; +} + +bool GameSession::Create(GameDescription& desc) +{ + this->description = desc; +/* Do some error checking */ + if(desc.clients.Size() == 0) return false; + if(!desc.owner) return false; + if(this->isCreated) return false; + +/* standard initialization of some data */ + NetworkSession::clients = desc.clients; + NetworkSession::clients.Resize((unsigned int)desc.maxClients); + this->clients.Resize((unsigned int)desc.maxClients); + this->owner = desc.owner; + +/* Initiate the game instance */ + if(!this->gameInstance.Initiate()) { - this->owner = 0; - this->isCreated = false; - this->isRunning = false; - this->gameSession = this; - this->logicFrameTime = DELTA_TIME_20; - this->networkFrameTime = DELTA_TIME_20; - this->networkTimer.reset(); - this->logicTimer.reset(); - - memset(&this->description, 0, sizeof(GameDescription)); + printf("Failed to initiate the game instance\n"); } - GameSession::~GameSession() +/* Create the players in the game instance */ + GameLogic::IPlayerData* p = 0; + for (unsigned int i = 0; i < desc.clients.Size(); i++) { - this->worker.Terminate(); - this->clients.Clear(); - this->gameInstance; - this->owner = 0; - this->isCreated = false; - this->isRunning = false; - } - - bool GameSession::Create(GameDescription& desc) - { - this->description = desc; - /* Do some error checking */ - if(desc.clients.Size() == 0) return false; - if(!desc.owner) return false; - if(this->isCreated) return false; - - /* standard initialization of some data */ - NetworkSession::clients = desc.clients; - NetworkSession::clients.Resize((unsigned int)desc.maxClients); - this->clients.Resize((unsigned int)desc.maxClients); - this->owner = desc.owner; - - /* Initiate the game instance */ - if(!this->gameInstance.Initiate()) + if(desc.clients[i]) { - printf("Failed to initiate the game instance\n"); - } - - /* Create the players in the game instance */ - GameLogic::IPlayerData* p = 0; - for (unsigned int i = 0; i < desc.clients.Size(); i++) - { - if(desc.clients[i]) + if( (p = this->gameInstance.CreatePlayer()) ) { - if( (p = this->gameInstance.CreatePlayer()) ) - { - desc.clients[i]->SetOwner(this); - this->clients[i] = (new GameClient(desc.clients[i], p)); - } - else - { - printf("Failed to create player (%i)\n", i); - } + desc.clients[i]->SetOwner(this); + this->clients[i] = (new GameClient(desc.clients[i], p)); + } + else + { + printf("Failed to create player (%i)\n", i); } } - - /* Create the game level */ - if(!(this->levelData = this->gameInstance.CreateLevel())) - { - printf("Level not created!"); - return false; - } - - /* Set some game instance data options */ - this->gameInstance.SetSubscription(GameSession::ObjectMove); - this->gameInstance.SetSubscription(GameSession::ObjectDisabled); - this->gameInstance.SetFPS(60); - - this->description.clients.Clear(); - - this->isCreated = true; - - /* Create the worker thread */ - if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS) - return false; - - return this->isCreated; } - void GameSession::Run() +/* Create the game level */ + if(!(this->levelData = this->gameInstance.CreateLevel())) { - if(this->isRunning) return; - - if(this->clients.Size() > 0) - { - this->worker.Start(); - this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); - this->isRunning = true; - } + printf("Level not created!"); + return false; } - void GameSession::ThreadEntry( ) - { - //List with clients that we are waiting on.. - DynamicArray> readyList;// = this->clients; +/* Set some game instance data options */ + this->gameInstance.SetSubscription(GameSession::ObjectMove); + this->gameInstance.SetSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetFPS(60); - //First we need to clean invalid clients, if any, and tell them to start loading game data - for (unsigned int i = 0; i < this->clients.Size(); i++) + this->description.clients.Clear(); + + this->isCreated = true; + + /* Create the worker thread */ + if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS) + return false; + + return this->isCreated; +} + +void GameSession::Run() +{ + if(this->isRunning) return; + + if(this->clients.Size() > 0) + { + this->worker.Start(); + this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); + this->isRunning = true; + } +} + +void GameSession::ThreadEntry( ) +{ +//List with clients that we are waiting on.. + DynamicArray> readyList;// = this->clients; + +//First we need to clean invalid clients, if any, and tell them to start loading game data + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) { - if(this->clients[i]) - { - if(this->clients[i]->IsReady()) - { - readyList.Push(this->clients[i]); - Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation()); - readyList[readyList.Size() - 1]->GetClient()->Send(p); - } - } + readyList.Push(this->clients[i]); + Protocol_LobbyCreateGame p((char)1, (char)0, this->description.mapName); + readyList[readyList.Size() - 1]->GetClient()->Send(p); } + } - unsigned int readyCounter = readyList.Size(); + unsigned int readyCounter = readyList.Size(); - //Sync with clients - while (readyCounter != 0) +//Sync with clients + while (readyCounter != 0) + { + this->ProcessClients(); + for (unsigned int i = 0; i < readyList.Size(); i++) { - this->ProcessClients(); - for (unsigned int i = 0; i < readyList.Size(); i++) + if(readyList[i] && readyList[i]->IsReady()) { - if(readyList[i] && readyList[i]->IsReady()) + //Need to send information about other players, to all players + for (unsigned int k = 0; k < this->clients.Size(); k++) { - //Need to send information about other players, to all players - for (unsigned int k = 0; k < this->clients.Size(); k++) + if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) { - if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) - { - //Protocol_ObjectCreatePlayer - Protocol_ObjectCreate p( this->clients[k]->GetPlayer()->GetPosition(), - this->clients[k]->GetPlayer()->GetRotation(), - this->clients[k]->GetPlayer()->GetScale(), - this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later.. - readyList[i]->GetClient()->Send(p); - } + IPlayerData* pl = this->clients[k]->GetPlayer(); + Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), + pl->GetID(), true, this->clients[k]->GetPlayer()->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + readyList[i]->GetClient()->Send(p); } - - readyCounter-- ; - readyList[i] = 0; } + + readyCounter-- ; + readyList[i] = 0; } - Sleep(5); //TODO: This might not be needed here. } + Sleep(5); //TODO: This might not be needed here. + } +//Sync with clients before starting countdown + + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) + { + this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + } + } +} + +bool GameSession::Attach(Utility::DynamicMemory::SmartPointer networkClient) +{ + if(!this->isCreated) return false; + if(this->GetClientCount() == this->clients.Capacity()) return false; + + networkClient->SetOwner(this); + + IPlayerData* playerData = this->gameInstance.CreatePlayer(); + if(!playerData) return false; + + SmartPointer gameClient = new GameClient(networkClient, playerData); + NetworkClient* nwClient = gameClient->GetClient(); + +// Send the level information + { + Protocol_LobbyCreateGame lcg((char)1, (char)0, this->description.mapName); + nwClient->Send(lcg); + } + +// Send the player data only + { + Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(), + playerData->GetID(), true, playerData->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + nwClient->Send(oc); + } + +// Send information about other clients + { for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->clients[i]) + if(clients[i]) { - this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + IPlayerData* temp = clients[i]->GetPlayer(); + Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), + temp->GetID(), false, temp->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + nwClient->Send(oc); } } } - bool GameSession::Attach(Utility::DynamicMemory::SmartPointer client) +//TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client { - if(!this->isCreated) return false; - if(this->GetClientCount() == this->clients.Capacity()) return false; - client->SetOwner(this); + } - IPlayerData* player = this->gameInstance.CreatePlayer(); - if(!player) return false; - - SmartPointer obj = new GameClient(client, player); - - // Send the chosen mesh name - Protocol_LobbyCreateGame lcg(obj->GetPlayer()->GetID(), "char_white.dan", obj->GetPlayer()->GetOrientation()); - obj->GetClient()->Send(lcg); - - // Send the player data only - for (unsigned int i = 0; i < this->clients.Capacity(); i++) - { - if(this->clients[i]) - { - IPlayerData* p = this->clients[i]->GetPlayer(); - Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); - //Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); - this->clients[i]->GetClient()->Send(oc); - } - } - - obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0)); - - for (unsigned int i = 0; i < this->clients.Size(); i++) +// Insert the new client to the update list + { + bool added = false; + for (unsigned int i = 0; !added && i < this->clients.Size(); i++) { if(!clients[i]) { - NetworkSession::clients[i] = client; - clients[i] = obj; - return true; + NetworkSession::clients[i] = networkClient; + clients[i] = gameClient; + added = true; } } - - return true; + if(!added) + { + NetworkSession::clients.Push( networkClient ); + clients.Push( gameClient ); + } } - - void GameSession::CloseSession( bool dissconnectClients ) +// Send the start signal { - this->worker.Terminate(); - NetworkSession::CloseSession(true); - this->clients.Clear(); + nwClient->Send(GameLogic::Protocol_LobbyStartGame(0)); } -}//End namespace DanBias + return true; +} + +void GameSession::CloseSession( bool dissconnectClients ) +{ + this->worker.Terminate(); + NetworkSession::CloseSession(true); + this->clients.Clear(); +} + diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 58d81360..6f037117 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -133,13 +133,7 @@ namespace Oyster */ virtual void DataRecieved(NetEvent e); - /** ! Deprecate ! - * Do not use this furthermore, instead use void DataRecieved(NetEvent e); - * @see DataRecieved - */ - //virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p); - - virtual std::string GetIpAddress(); + std::string GetIpAddress(); private: NetworkClient(const NetworkClient& obj); From 197067687e6f4cc7a9e3be7e44644732f58390df Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 09:32:10 +0100 Subject: [PATCH 12/39] Added Gui Transparancy, Get Options provides Resolution.xy --- .../GameClientState/Buttons/ButtonRectangle.h | 40 +++++++---- .../GameClientState/Buttons/EventButtonGUI.h | 68 +++++++++++-------- .../GameClientState/Buttons/TextField.h | 6 +- .../GameClientState/LanMenuState.cpp | 8 +-- .../GameClientState/LobbyAdminState.cpp | 2 +- .../GameClient/GameClientState/LobbyState.cpp | 2 +- .../GameClient/GameClientState/MainState.cpp | 19 ++++-- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 15 ++++ Code/OysterGraphics/DllInterfaces/GFXAPI.h | 17 +++++ .../OysterGraphics/Render/DefaultRenderer.cpp | 3 +- Code/OysterGraphics/Render/GuiRenderer.cpp | 6 +- Code/OysterGraphics/Render/Resources.cpp | 37 ++++++++++ Code/OysterGraphics/Render/Resources.h | 1 + .../Shader/Passes/2D/2DGeometry.hlsl | 8 +-- .../Shader/Passes/2D/Text/2DTextGeometry.hlsl | 8 +-- 15 files changed, 174 insertions(+), 66 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h index f4dd69e1..7f3db825 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/GameClient/GameClientState/Buttons/ButtonRectangle.h @@ -21,21 +21,37 @@ namespace DanBias ButtonRectangle() : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, owner, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + func, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, owner, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + func, owner, pos, size, resize) {} - ButtonRectangle(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButtonGUI(textureName, buttonText, textColor, func, owner, userData, pos, size, resize) + ButtonRectangle(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButtonGUI(textureName, buttonText, + textColor, backColor, hoverColor, pressedColor, + func, owner, userData, pos, size, resize) {} virtual ~ButtonRectangle() {} diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c6b54a7e..3ae09043 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -30,32 +30,40 @@ namespace DanBias class EventButtonGUI : public Oyster::Event::EventButton { public: - EventButtonGUI() - : EventButton(), pos(0, 0), size(0, 0), texture(NULL), buttonText(""), textColor(1, 1, 1, 1) - {} - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(func), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, Oyster::Math::Float3 pos, - Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, Oyster::Math::Float3 pos, + Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(func, owner), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); } - EventButtonGUI(std::wstring textureName, std::wstring buttonText, Oyster::Math::Float4 textColor, EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height) - : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), textColor(textColor) + EventButtonGUI(std::wstring textureName, std::wstring buttonText, + Oyster::Math::Float4 textColor, Oyster::Math::Float4 backColor, Oyster::Math::Float4 hoverColor, Oyster::Math::Float4 pressedColor, + EventFunc func, Owner owner, void* userData, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_None) + : EventButton(func, owner, userData), pos(pos), size(size), texture(NULL), buttonText(buttonText), + textColor(textColor), backColor(backColor), hoverColor(hoverColor), pressedColor(pressedColor) { CreateTexture(textureName); if(resize != ResizeAspectRatio_None) ResizeWithAspectRatio(resize); @@ -77,23 +85,23 @@ namespace DanBias if(EventButton::Enabled()) { // let the using dev decide what is rendered - Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f)); + //Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float4(1.0f, 1.0f, 1.0f, 1.0f)); //Render att xPos and yPos //With width and height - //if(EventButton::GetState() == ButtonState_None) - //{ - // Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f)); - //} - //else if(EventButton::GetState() == ButtonState_Hover) - //{ - // Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f)); - //} - //else - //{ - // Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f)); - //} + if(EventButton::GetState() == ButtonState_None) + { + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, backColor); + } + else if(EventButton::GetState() == ButtonState_Hover) + { + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, hoverColor); + } + else + { + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, pressedColor); + } } } @@ -102,7 +110,7 @@ namespace DanBias { if(buttonText.size() > 0) { - Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, 0.0f), size*2.0f, 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); } } @@ -126,6 +134,10 @@ namespace DanBias std::wstring buttonText; Oyster::Math::Float4 textColor; + + Oyster::Math::Float4 backColor; + Oyster::Math::Float4 hoverColor; + Oyster::Math::Float4 pressedColor; }; } } diff --git a/Code/Game/GameClient/GameClientState/Buttons/TextField.h b/Code/Game/GameClient/GameClientState/Buttons/TextField.h index c1fa79ac..18e5d23b 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/TextField.h +++ b/Code/Game/GameClient/GameClientState/Buttons/TextField.h @@ -20,7 +20,7 @@ namespace DanBias { namespace Client { public: TextField(); - TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height ); + TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, ::Oyster::Math::Float4 backColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize = ResizeAspectRatio_Height ); virtual ~TextField(); virtual void RenderText(); @@ -62,8 +62,8 @@ namespace DanBias { namespace Client } template - TextField::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize ) - : ButtonRectangle( backgroundTexture, L"", textColor, owner, pos, size, resize ) + TextField::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float4 textColor, ::Oyster::Math::Float4 backColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize ) + : ButtonRectangle( backgroundTexture, L"", textColor, backColor, backColor, backColor, owner, pos, size, resize ) { this->fontHeight = 0.025f; this->lineSpacing = 0.001f; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 3051c097..cb07aa55 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -55,10 +55,10 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->nwClient = shared.network; this->privData->input = shared.input; - this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); // create guiElements - this->privData->connectIP = new TextField( L"earth_md.png", Float4(1.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); + this->privData->connectIP = new TextField( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); this->privData->connectIP->ReserveLines( 1 ); this->privData->connectIP->AppendText( L"127.0.0.1" ); this->privData->connectIP->SetFontHeight( 0.08f ); @@ -68,10 +68,10 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->guiElements.AddButton( this->privData->connectIP ); ButtonRectangle *guiElements; - guiElements = new ButtonRectangle( L"earth_md.png", L"Connect", Float4(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); + guiElements = new ButtonRectangle( L"color_white.png", L"Connect", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); this->privData->guiElements.AddButton( guiElements ); - guiElements = new ButtonRectangle( L"earth_md.png", L"Exit", Float4(1.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); + guiElements = new ButtonRectangle( L"color_white.png", L"Exit", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None ); this->privData->guiElements.AddButton( guiElements ); // bind guiElements collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index b05e90dc..070d8b48 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -50,7 +50,7 @@ bool LobbyAdminState::Init( SharedStateContent &shared ) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f),Float4(0.0f),Float4(0.0f),Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 23b27e3f..a6d03527 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -50,7 +50,7 @@ bool LobbyState::Init( SharedStateContent &shared ) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float4(1.0f), Float4(0.0f), Float4(0.0f), Float4(0.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index d71b050e..f34b9ad6 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -49,18 +49,22 @@ bool MainState::Init( SharedStateContent &shared ) this->privData->nwClient = shared.network; this->privData->input = shared.input; - this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); // create buttons ButtonRectangle *button; + Float4 TextCol = Float4(1.0f,0.0f,1.0f,1.0f); + Float4 BackCol = Float4(1.0f,1.0f,1.0f,0.5f); + Float4 HoverCol = Float4(0.0f,1.0f,0.0f,1.0f); + Float4 PressCol = Float4(0.0f,0.0f,1.0f,1.0f); - button = new ButtonRectangle( L"earth_md.png", L"Create", Float4(1.0f), OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"color_white.png", L"Create",TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Create, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f)); this->privData->guiElements.AddButton( button ); - button = new ButtonRectangle( L"skysphere_md.png", L"Join", Float4(1.0f), OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"color_white.png", L"Join", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Join, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.1f)); this->privData->guiElements.AddButton( button ); - button = new ButtonRectangle( L"plane_texture_md.png", L"Quit", Float4(1.0f), OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"color_white.png", L"Quit", TextCol, BackCol, HoverCol, PressCol, OnButtonInteract_Quit, this, Float3(0.5f, 0.8f, 0.5f), Float2(0.3f, 0.1f)); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler @@ -73,6 +77,11 @@ GameClientState::ClientState MainState::Update( float deltaTime ) { MouseInput mouseState; { + bool test = this->privData->input->IsMousePressed(); + if(test) + { + int i = 0; + }; this->privData->input->GetMousePos( mouseState.x, mouseState.y ); mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); } @@ -87,7 +96,7 @@ bool MainState::Render() Graphics::API::NewFrame(); Graphics::API::StartGuiRender(); - Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); + Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) ); this->privData->guiElements.RenderTexture(); Graphics::API::StartTextRender(); diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index f4ce303f..75bc3c70 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -19,6 +19,10 @@ namespace Oyster Math::Float4x4 Projection; std::vector Lights; float deltaTime; +#ifdef _DEBUG + Model::Model* cube; + Model::Model* sphere; +#endif } API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion) @@ -33,6 +37,12 @@ namespace Oyster Render::Resources::Init(); Render::Preparations::Basic::SetViewPort(); +#ifdef _DEBUG + //fix load model + cube = CreateModel(L"debug_cube.dan"); + sphere = CreateModel(L"debug_sphere.dan"); + +#endif return API::Sucsess; } @@ -145,6 +155,10 @@ namespace Oyster Render::Resources::InitShaders(); return State::Sucsess; } + + void API::StartRenderWireFrame() + { + } #endif API::Option API::GetOption() @@ -153,6 +167,7 @@ namespace Oyster o.BytesUsed = Core::UsedMem; o.modelPath = Core::modelPath; o.texturePath = Core::texturePath; + o.Resolution = Core::resolution; return o; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index eea53939..e123e59a 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -27,6 +27,12 @@ namespace Oyster struct Option { std::wstring modelPath, texturePath; + //between 0-1 + float AmbientValue; + + Math::Float2 Resolution; + + //Bytes on the GPU int BytesUsed; }; typedef void* Texture; @@ -34,6 +40,17 @@ namespace Oyster static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); #ifdef _DEBUG static State ReloadShaders(); + + //should be called after rendered normal models, before GUI or Text rendering + static void StartRenderWireFrame(); + + //Render a unit cube with the presented WorldMatrix + static void RenderDebugCube(Math::Matrix world); + + //Render a unit Sphere with the presented WorldMatrix + static void RenderDebugSphere(Math::Matrix world); + + static void StartRenderFullModel(); #endif //! @todo Memory Leaks diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index c0c2990e..7e8d08cd 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -16,7 +16,8 @@ namespace Oyster void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights) { - Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1)); + Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); + Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass); Lights[1]; diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index b17fdfef..02e202e4 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -9,7 +9,7 @@ namespace Oyster namespace Render { const int TEXT_NR_LETTERS=95; - const float TEXT_SPACING=1.8f; + const float TEXT_SPACING=2.0f; void Gui::Begin2DRender() { @@ -20,8 +20,8 @@ namespace Oyster { Core::deviceContext->PSSetShaderResources(0,1,&tex); - pos *= 2; - pos -= 1; + pos.xy *= 2; + pos.xy -= 1; pos.y *= -1; Definitions::GuiData gd; diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 0c5bf592..82ace315 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -62,6 +62,7 @@ namespace Oyster ID3D11BlendState* Resources::RenderStates::bs = NULL; ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL; + ID3D11DepthStencilView* Resources::Gui::depth = NULL; #pragma endregion @@ -304,6 +305,7 @@ namespace Oyster ID3D11Texture1D *pTexture1; Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1 ); + Core::UsedMem += T1desc.Width * 16; Core::device->CreateShaderResourceView( pTexture1, 0, &Light::SSAOKernel ); pTexture1->Release(); @@ -323,8 +325,33 @@ namespace Oyster ID3D11Texture2D *pTexture2; Core::device->CreateTexture2D( &T2desc, &rnd, &pTexture2 ); + Core::UsedMem += T2desc.Height * T2desc.Width * 16; Core::device->CreateShaderResourceView( (pTexture2), 0, &Light::SSAORandom ); pTexture2->Release(); + + //create Depth Buffer + D3D11_TEXTURE2D_DESC dTDesc; + dTDesc.MipLevels=1; + dTDesc.ArraySize=1; + dTDesc.Format = DXGI_FORMAT_D32_FLOAT; + dTDesc.Usage = D3D11_USAGE_DEFAULT; + dTDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; + dTDesc.CPUAccessFlags=0; + dTDesc.MiscFlags=0; + dTDesc.Height = Core::resolution.y; + dTDesc.Width = Core::resolution.x; + dTDesc.SampleDesc.Count=1; + dTDesc.SampleDesc.Quality=0; + + ID3D11Texture2D* depthstencil; + Core::device->CreateTexture2D(&dTDesc,0,&depthstencil); + Core::UsedMem += dTDesc.Height * dTDesc.Width * 4; + Core::device->CreateDepthStencilView(depthstencil,NULL,&Gui::depth); + depthstencil->Release(); + + + D3D11_DEPTH_STENCIL_DESC dDesc; + return Core::Init::Success; } @@ -390,10 +417,13 @@ namespace Oyster Gui::Pass.Shaders.Vertex = GetShader::Vertex(L"2D"); Gui::Pass.Shaders.Pixel = GetShader::Pixel(L"2D"); Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D"); + Gui::Pass.RTV.push_back(GBufferRTV[2]); Gui::Pass.CBuffers.Geometry.push_back(Gui::Data); Gui::Pass.CBuffers.Pixel.push_back(Color); + Gui::Pass.depth = Gui::depth; + D3D11_INPUT_ELEMENT_DESC indesc2D[] = { { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, @@ -405,6 +435,7 @@ namespace Oyster Gui::Pass.RenderStates.SampleCount = 1; Gui::Pass.RenderStates.SampleState = RenderStates::ss; Gui::Pass.RenderStates.BlendState = RenderStates::bs; + Gui::Pass.RenderStates.DepthStencil = RenderStates::dsState; ////---------------- Blur Pass Setup ---------------------------- Blur::HorPass.Shaders.Compute = GetShader::Compute(L"BlurHor"); @@ -442,9 +473,13 @@ namespace Oyster Gui::Text::Pass.CBuffers.Pixel.push_back(Color); Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font); Gui::Text::Pass.RTV.push_back(GBufferRTV[2]); + + Gui::Text::Pass.depth = Gui::depth; + Gui::Text::Pass.RenderStates.SampleCount = 1; Gui::Text::Pass.RenderStates.SampleState = RenderStates::ss; Gui::Text::Pass.RenderStates.BlendState = RenderStates::bs; + Gui::Text::Pass.RenderStates.DepthStencil = RenderStates::dsState; return Core::Init::Success; } @@ -510,6 +545,8 @@ namespace Oyster SAFE_RELEASE(Gui::Text::Pass.RenderStates.BlendState); SAFE_RELEASE(Gui::Text::Pass.IAStage.Layout); + + SAFE_RELEASE(Gui::depth); } } } diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index 6b4e140e..665ab8dc 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -64,6 +64,7 @@ namespace Oyster { static Core::PipelineManager::RenderPass Pass; static Core::Buffer Data; + static ID3D11DepthStencilView* depth; struct Text { static Core::PipelineManager::RenderPass Pass; diff --git a/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl b/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl index 86fea579..56b6294f 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl +++ b/Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl @@ -4,19 +4,19 @@ void main(point Vertex2DIn input[1],inout TriangleStream Quads) { Pixel2DIn output; - output.Pos = mul(float4(-1,-1,1,1) ,Translation); + output.Pos = mul(float4(-1,-1,0,1) ,Translation); output.Uv = float2(0,1); Quads.Append(output); - output.Pos = mul(float4(-1,1,1,1), Translation); + output.Pos = mul(float4(-1,1,0,1), Translation); output.Uv = float2(0,0); Quads.Append(output); - output.Pos = mul(float4(1,-1,1,1), Translation); + output.Pos = mul(float4(1,-1,0,1), Translation); output.Uv = float2(1,1); Quads.Append(output); - output.Pos = mul(float4(1,1,1,1), Translation); + output.Pos = mul(float4(1,1,0,1), Translation); output.Uv = float2(1,0); Quads.Append(output); } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl b/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl index 4e0bed02..feefbed7 100644 --- a/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl +++ b/Code/OysterGraphics/Shader/Passes/2D/Text/2DTextGeometry.hlsl @@ -7,22 +7,22 @@ void main(point Text2DIn input[1],inout TriangleStream Quads) float endoff=startoff+input[0].coff; Pixel2DIn output; - output.Pos = mul(float4(-1,-1,1,1), Translation); + output.Pos = mul(float4(-1,-1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(startoff,1); Quads.Append(output); - output.Pos = mul(float4(-1,1,1,1), Translation); + output.Pos = mul(float4(-1,1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(startoff,0); Quads.Append(output); - output.Pos = mul(float4(1,-1,1,1), Translation); + output.Pos = mul(float4(1,-1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(endoff,1); Quads.Append(output); - output.Pos = mul(float4(1,1,1,1), Translation); + output.Pos = mul(float4(1,1,0,1), Translation); output.Pos.x += input[0].Pos; output.Uv = float2(endoff,0); Quads.Append(output); From 05cc76e9d6811f4d63013b1e13ae5337e836e098 Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 09:33:21 +0100 Subject: [PATCH 13/39] Added .user to gitIgnore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d5d239c2..57ccce7f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ Bin/DLL/ Bin/Executable/ Obj/ External/ +Code/Game/GameClient/GameClient.vcxproj.user From 80b203737a3755838435584721ed585da15478ee Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 09:56:28 +0100 Subject: [PATCH 14/39] Debug WireFrame to verify --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 34 +++++++++++++++++++ .../OysterGraphics/Render/DefaultRenderer.cpp | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 75bc3c70..ec0be45e 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -22,6 +22,8 @@ namespace Oyster #ifdef _DEBUG Model::Model* cube; Model::Model* sphere; + + ID3D11RasterizerState* wire; #endif } @@ -42,6 +44,19 @@ namespace Oyster cube = CreateModel(L"debug_cube.dan"); sphere = CreateModel(L"debug_sphere.dan"); + D3D11_RASTERIZER_DESC desc; + desc.CullMode = D3D11_CULL_BACK; + desc.FillMode = D3D11_FILL_WIREFRAME; + desc.FrontCounterClockwise = false; + desc.DepthBias = 0; + desc.DepthBiasClamp = 0; + desc.DepthClipEnable = true; + desc.SlopeScaledDepthBias = 0; + desc.ScissorEnable = false; + desc.MultisampleEnable = false; + desc.AntialiasedLineEnable = false; + + Core::device->CreateRasterizerState(&desc,&wire); #endif return API::Sucsess; } @@ -123,6 +138,11 @@ namespace Oyster void API::Clean() { +#ifdef _DEBUG + DeleteModel(cube); + DeleteModel(sphere); + SAFE_RELEASE(wire); +#endif DeleteTexture(Render::Resources::Gui::Text::Font); SAFE_DELETE(Core::viewPort); Core::loader.Clean(); @@ -137,6 +157,7 @@ namespace Oyster SAFE_RELEASE(Core::swapChain); SAFE_RELEASE(Core::deviceContext); SAFE_RELEASE(Core::device); + } void API::AddLight(Definitions::Pointlight light) @@ -158,6 +179,19 @@ namespace Oyster void API::StartRenderWireFrame() { + Core::deviceContext->RSSetState(wire); + } + + void API::RenderDebugCube(Math::Matrix world) + { + cube->WorldMatrix = world; + Render::DefaultRenderer::RenderScene(cube,1,View,Projection); + } + + void API::RenderDebugSphere(Math::Matrix world) + { + sphere->WorldMatrix = world; + Render::DefaultRenderer::RenderScene(sphere,1,View,Projection); } #endif diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 7e8d08cd..fbf11f08 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -58,7 +58,7 @@ namespace Oyster if(models[i].Visible) { Definitions::PerModel pm; - pm.WV = View * models[i].WorldMatrix; + pm.WV = View * models[i].WorldMatrix.GetInverse().GetTranspose(); pm.WVP = Projection * pm.WV; Model::ModelInfo* info = models[i].info; From 55e3aaaabca6b32cfe872b3f12f4251389290ec8 Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 10:19:59 +0100 Subject: [PATCH 15/39] Fixed proper start and some more option modifications --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 6 ++++-- .../Definitions/GraphicalDefinition.h | 3 +-- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 21 +++++++++++++++++-- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 2 +- .../OysterGraphics/Render/DefaultRenderer.cpp | 8 ------- .../Shader/Passes/Post/PostPass.hlsl | 6 ++---- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 81650049..e6f95f79 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -136,9 +136,11 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - Oyster::Graphics::API::SetOptions(p); + p.Resolution = Oyster::Math::Float2( 1024, 768); + //! @todo fix proper amb value + p.AmbientValue = 1.0f; - if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess) + if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, p) != Oyster::Graphics::API::Sucsess) return E_FAIL; return S_OK; } diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index ffd2869a..fcfd865c 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -61,8 +61,7 @@ namespace Oyster struct PostData { - int x; - int y; + float Amb; }; struct Text2D diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index ec0be45e..bdfa0bde 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -27,9 +27,11 @@ namespace Oyster #endif } - API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion) + API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, API::Option o) { - Core::resolution = resulotion; + Core::resolution = o.Resolution; + Core::modelPath = o.modelPath; + Core::texturePath = o.texturePath; if(Core::Init::FullInit(Window, MSAA_Quality, Fullscreen) == Core::Init::Fail) { @@ -38,6 +40,13 @@ namespace Oyster Render::Resources::Gui::Text::Font = (ID3D11ShaderResourceView*)API::CreateTexture(L"font_generic.png"); Render::Resources::Init(); + Definitions::PostData pd; + pd.Amb = o.AmbientValue; + + void* data = Render::Resources::Post::Data.Map(); + memcpy(data,&pd,sizeof(Definitions::PostData)); + Render::Resources::Post::Data.Unmap(); + Render::Preparations::Basic::SetViewPort(); #ifdef _DEBUG //fix load model @@ -102,6 +111,14 @@ namespace Oyster { Core::modelPath = option.modelPath; Core::texturePath = option.texturePath; + + Definitions::PostData pd; + pd.Amb = option.AmbientValue; + + void* data = Render::Resources::Post::Data.Map(); + memcpy(data,&pd,sizeof(Definitions::PostData)); + Render::Resources::Post::Data.Unmap(); + return API::Sucsess; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index e123e59a..71e12662 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -37,7 +37,7 @@ namespace Oyster }; typedef void* Texture; - static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); + static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Option options); #ifdef _DEBUG static State ReloadShaders(); diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index fbf11f08..097fcedb 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -39,14 +39,6 @@ namespace Oyster data = Resources::Light::PointLightsData.Map(); memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); Resources::Light::PointLightsData.Unmap(); - - Definitions::PostData pd; - pd.x = (int)lc.Pixels.x; - pd.y = (int)lc.Pixels.y; - - data = Resources::Post::Data.Map(); - memcpy(data, &pd, sizeof(Definitions::PostData)); - Resources::Post::Data.Unmap(); } void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime) diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 0c6ad9ca..346913d8 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -8,11 +8,9 @@ SamplerState S1 : register(s0); cbuffer Size : register(b0) { - int2 Pixels; + float AmbFactor; } -#define AmbFactor 0.1f; - float4 SuperSample(float4 Glow, uint3 DTid) { // Line X @@ -36,7 +34,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) Glow = SuperSample(Glow,DTid); float4 GUI; - uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0); + uint2 index = DTid.xy/2 + uint2((uint)Output.Length.x/(uint)2,0); float3 PostLight = Amb.xyz * AmbFactor; PostLight = PostLight + Light.xyz + Glow; GUI = float4(Ambient[index]); From b2e98f12078f456bfc53ef96c668ba955d7889e2 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 10:28:46 +0100 Subject: [PATCH 16/39] Debug hack + actual fixings --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 9 ++++-- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClient/GameClientState/Camera_FPS.cpp | 3 +- .../GameClient/GameClientState/GameState.cpp | 28 ++++++++++++++++--- .../GameClientState/NetLoadState.cpp | 5 +++- .../OysterGraphics.vcxproj.user | 2 +- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index e6f95f79..b978597c 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -64,7 +64,12 @@ namespace DanBias { WindowShell::CreateConsoleWindow(); //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) - if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC())) + + WindowShell::WINDOW_INIT_DESC winDesc; + winDesc.windowSize.x = 1280; + winDesc.windowSize.y = 720; + + if(! data.window->CreateWin(winDesc) ) return DanBiasClientReturn_Error; if( FAILED( InitDirect3D() ) ) @@ -136,7 +141,7 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - p.Resolution = Oyster::Math::Float2( 1024, 768); + p.Resolution = Oyster::Math::Float2( 1280.0f, 720.0f ); //! @todo fix proper amb value p.AmbientValue = 1.0f; diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/Camera_FPS.cpp b/Code/Game/GameClient/GameClientState/Camera_FPS.cpp index 8c87970b..56a026e3 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPS.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPS.cpp @@ -112,7 +112,8 @@ void Camera_FPS::StrafeLeft( Float distance ) void Camera_FPS::PitchUp( Float radian ) { - this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); + //this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); + this->pitchUp = this->pitchUp + radian; // debug hack this->head.SetAngular( this->body.angularAxis + this->pitchUp * this->body.direction.v[0] ); } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 2ae8ae21..f590f366 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -17,6 +17,7 @@ using namespace ::Oyster::Math3D; using namespace ::GameLogic; using namespace ::Utility::DynamicMemory; using namespace ::Utility::String; +using namespace ::Utility::Value; struct GameState::MyData { @@ -76,9 +77,24 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; - //tell server ready - this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); + Graphics::API::Option gfxOp = Graphics::API::GetOption(); + Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; + this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); + //tell server ready + //this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); + + // Debugg hack + this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); + Graphics::Definitions::Pointlight light; + light.Pos = Float3( 0,132,0); + light.Color = Float3( 1.0f ); + light.Bright = 1.0f; + light.Radius = 1000.0f; + Graphics::API::AddLight( light ); + // end debug hack + return true; } @@ -98,6 +114,9 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); + Float3 offset = Float3( 0.0f ); + offset.y = this->privData->player.getScale().y + 0.5f; // debug hack +0.5f + this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); } } @@ -113,6 +132,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { + this->ReadKeyInput(); return this->privData->nextState; } @@ -219,8 +239,8 @@ void GameState::ReadKeyInput() //send delta mouse movement { - this->privData->camera.YawRight( -this->privData->input->GetYaw() ); - this->privData->camera.PitchUp( this->privData->input->GetPitch() ); + this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); + this->privData->camera.PitchDown( this->privData->input->GetPitch() * 0.017f ); this->privData->camera.UpdateOrientation(); privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) ); diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index f50db40c..7443344e 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -54,8 +54,11 @@ bool NetLoadState::Init( SharedStateContent &shared ) // we may assume that nwClient is properly connected to the server // signals querry to server for loading instructions - this->privData->nwClient->Send( Protocol_QuerryGameType() ); + //this->privData->nwClient->Send( Protocol_QuerryGameType() ); + // debugg + this->LoadGame( "..//Content//Worlds//2ofAll_updated.bias"); + this->ChangeState( ClientState_Game ); return true; } diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 9a0b0ae0..3f030911 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@  - true + false \ No newline at end of file From fc19938f1b952e71b8494baee3195c1f485cb5c8 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 10:40:27 +0100 Subject: [PATCH 17/39] =?UTF-8?q?P=C3=A4r's=20fix=20i=20RenderScene?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/OysterGraphics/Render/DefaultRenderer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 097fcedb..22b71df7 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -50,8 +50,8 @@ namespace Oyster if(models[i].Visible) { Definitions::PerModel pm; - pm.WV = View * models[i].WorldMatrix.GetInverse().GetTranspose(); - pm.WVP = Projection * pm.WV; + pm.WV = View * models[i].WorldMatrix.GetTranspose().GetInverse(); + pm.WVP = Projection * View * models[i].WorldMatrix; Model::ModelInfo* info = models[i].info; From c8c0bb9bc4c9a7976732286dfd75dbbe25539e2f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 11:06:11 +0100 Subject: [PATCH 18/39] Clamp fixed --- Code/Misc/Utilities/Utilities.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Code/Misc/Utilities/Utilities.h b/Code/Misc/Utilities/Utilities.h index c259a845..b97d62d7 100644 --- a/Code/Misc/Utilities/Utilities.h +++ b/Code/Misc/Utilities/Utilities.h @@ -337,7 +337,11 @@ namespace Utility template inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max ) - { return value < min ? Max( value, max ) : min; } + { + if( value < min ) return min; + if( value > max ) return max; + return value; + } template inline ValueType Average( const ValueType &valueA, const ValueType &valueB ) From 0bd5d68da44d3b68ae3493b9dd1b129d46f3f6a8 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 11:12:47 +0100 Subject: [PATCH 19/39] Removed some debug lines --- Code/Game/GameClient/GameClientState/Camera_FPS.cpp | 3 +-- Code/Game/GameClient/GameClientState/GameState.cpp | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Camera_FPS.cpp b/Code/Game/GameClient/GameClientState/Camera_FPS.cpp index 56a026e3..8c87970b 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPS.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPS.cpp @@ -112,8 +112,7 @@ void Camera_FPS::StrafeLeft( Float distance ) void Camera_FPS::PitchUp( Float radian ) { - //this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); - this->pitchUp = this->pitchUp + radian; // debug hack + this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); this->head.SetAngular( this->body.angularAxis + this->pitchUp * this->body.direction.v[0] ); } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index f590f366..4a364ec7 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -87,12 +87,6 @@ bool GameState::Init( SharedStateContent &shared ) // Debugg hack this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); - Graphics::Definitions::Pointlight light; - light.Pos = Float3( 0,132,0); - light.Color = Float3( 1.0f ); - light.Bright = 1.0f; - light.Radius = 1000.0f; - Graphics::API::AddLight( light ); // end debug hack return true; From f6f183d6e7453c399063160a45a833ebbd55fa16 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 11:34:24 +0100 Subject: [PATCH 20/39] GameServer - Added inititiate protocols --- Code/Game/GameServer/GameClient.h | 34 ++++-- Code/Game/GameServer/GameLobby.h | 19 ++- Code/Game/GameServer/GameServerAPI.h | 17 +-- Code/Game/GameServer/GameSession.h | 19 +-- .../GameServer/Implementation/GameClient.cpp | 25 +++- .../GameServer/Implementation/GameLobby.cpp | 98 +++++++++++++--- .../GameLobby_ProtocolParser.cpp | 37 +++--- .../GameServer/Implementation/GameServer.cpp | 51 ++++---- .../Implementation/GameSession_Gameplay.cpp | 22 ++-- .../Implementation/GameSession_General.cpp | 110 ++++++++++-------- .../StandaloneGameServerCLI.cpp | 26 +++-- .../StandaloneGameServerCLI.h | 8 +- Code/Network/NetworkAPI/NetworkSession.h | 4 +- 13 files changed, 311 insertions(+), 159 deletions(-) diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index 09b3bc40..422df933 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -5,6 +5,7 @@ #define DANBIASSERVER_CLIENT_OBJECT_H #include +#include #include #include #include @@ -17,22 +18,21 @@ namespace DanBias class GameClient { public: - GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::IPlayerData* player); + GameClient(Utility::DynamicMemory::SmartPointer nwClient); virtual~GameClient(); - GameLogic::IPlayerData* GetPlayer(); - GameLogic::IPlayerData* ReleasePlayer(); - Utility::DynamicMemory::SmartPointer GetClient(); - Utility::DynamicMemory::SmartPointer ReleaseClient(); - inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } - inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->GetID()); } + inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); } - inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; } - inline std::wstring GetAlias() const { return this->alias; } - inline std::wstring GetCharacter() const { return this->character; } - inline bool IsReady() const { return this->isReady; } - inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } + inline bool Equals(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } + inline bool Equals(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); } + + inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; } + inline std::wstring GetAlias() const { return this->alias; } + inline std::wstring GetCharacter() const { return this->character; } + inline bool IsReady() const { return this->isReady; } + inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } + Oyster::Network::NetClient GetClient() const { return this->client; } void SetPlayer(GameLogic::IPlayerData* player); @@ -41,6 +41,13 @@ namespace DanBias void SetCharacter(std::wstring character); void SetSinceLastResponse(float seconds); + GameLogic::IPlayerData* ReleasePlayer(); + Oyster::Network::NetClient ReleaseClient(); + + //NetworkSpecific + void SetOwner(Oyster::Network::NetworkSession* owner); + void UpdateClient(); + private: GameLogic::IPlayerData* player; Utility::DynamicMemory::SmartPointer client; @@ -52,4 +59,7 @@ namespace DanBias std::wstring character; }; }//End namespace DanBias + +typedef Utility::DynamicMemory::SmartPointer gClient; + #endif // !DANBIASSERVER_CLIENT_OBJECT_H diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index ac4db486..9281dcd6 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -15,11 +15,18 @@ namespace DanBias { struct LobbyLevelData { - int mapNumber; int maxClients; - int gameMode; - int gameTime; - std::string gameName; + int gameTimeInMinutes; + std::wstring gameMode; + std::wstring mapName; + std::wstring gameName; + LobbyLevelData() + : maxClients(10) + , gameTimeInMinutes(10) + , gameMode(L"unknown") + , mapName(L"unknown") + , gameName(L"unknown") + { } }; class GameLobby :public Oyster::Network::NetworkSession { @@ -49,6 +56,8 @@ namespace DanBias private: void ClientEventCallback(Oyster::Network::NetEvent e) override; void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) override; + void ProcessClients() override; + bool Attach(Utility::DynamicMemory::SmartPointer client) override; private: //Utility::WinTimer timer; @@ -58,7 +67,7 @@ namespace DanBias GameSession gameSession; LobbyLevelData description; Utility::DynamicMemory::SmartPointer sessionOwner; - + Utility::DynamicMemory::DynamicArray> gClients; }; }//End namespace DanBias #endif // !DANBIASGAME_GAMELOBBY_H diff --git a/Code/Game/GameServer/GameServerAPI.h b/Code/Game/GameServer/GameServerAPI.h index a9e8c63f..eb5316c4 100644 --- a/Code/Game/GameServer/GameServerAPI.h +++ b/Code/Game/GameServer/GameServerAPI.h @@ -55,15 +55,18 @@ namespace DanBias static void NotifyWhenClientConnect(ClientConnectedNotify func); static void NotifyWhenClientDisconnect(ClientDisconnectedNotify func); - static void GameSetMapName(const wchar_t* val); - static void GameSetMaxClients(const int& val); - static void GameSetGameMode(const wchar_t* val); static void GameSetGameTime(const int& val); - static int GameGetMapId(); - static int GameGetMaxClients(); - static int GameGetGameMode(); + static void GameSetMaxClients(const int& val); + static void GameSetGameName(const wchar_t* val); + static void GameSetMapName(const wchar_t* val); + static void GameSetGameMode(const wchar_t* val); + static int GameGetGameTime(); - static const char* GameGetGameName(); + static int GameGetMaxClients(); + static const wchar_t* GameGetGameMode(); + static const wchar_t* GameGetGameName(); + static const wchar_t* GameGetMapName(); + static bool GameStart(); diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 8cd04048..200bed9b 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -32,11 +32,11 @@ namespace DanBias struct GameDescription { unsigned int maxClients; - std::string mapName; - std::string gameMode; + std::wstring mapName; + std::wstring gameMode; int gameTimeMinutes; Oyster::Network::NetworkSession* owner; - Utility::DynamicMemory::DynamicArray clients; + Utility::DynamicMemory::DynamicArray> clients; }; public: @@ -52,17 +52,19 @@ namespace DanBias /** Join an existing/running game session * @param client The client to attach to the session */ - bool Attach(Oyster::Network::NetClient client) override; - void CloseSession( bool dissconnectClients ) override; + bool Join(gClient client); + + //void CloseSession( bool dissconnectClients ) override; inline bool IsCreated() const { return this->isCreated; } inline bool IsRunning() const { return this->isRunning; } - operator bool() { return (this->isCreated && this->isCreated); } + operator bool() { return (this->isCreated && this->isRunning); } //Private member functions private: // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent e) override; + void ProcessClients() override; //Sends a client to the owner, if param is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); @@ -98,8 +100,8 @@ namespace DanBias //Private member variables private: - Utility::DynamicMemory::DynamicArray> clients; - Utility::DynamicMemory::SmartPointer sessionOwner; + Utility::DynamicMemory::DynamicArray gClients; + gClient sessionOwner; Oyster::Thread::OysterThread worker; GameLogic::GameAPI& gameInstance; GameLogic::ILevelData *levelData; @@ -115,6 +117,7 @@ namespace DanBias //TODO: Remove this uggly hax static GameSession* gameSession; + };//End GameSession }//End namespace DanBias #endif // !DANBIASSERVER_GAME_SESSION_H \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 6e68b1e8..7ef4a338 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -12,8 +12,9 @@ using namespace DanBias; using namespace GameLogic; -GameClient::GameClient() +GameClient::GameClient(Utility::DynamicMemory::SmartPointer nwClient) { + this->client = nwClient; this->player = 0; isReady = false; this->character = L"Unknown"; @@ -51,3 +52,25 @@ void GameClient::SetCharacter(std::wstring character) } +void GameClient::SetOwner(Oyster::Network::NetworkSession* owner) +{ + this->client->SetOwner(owner); +} +void GameClient::UpdateClient() +{ + this->client->Update(); +} + + +IPlayerData* GameClient::ReleasePlayer() +{ + IPlayerData* temp = this->player; + this->player = 0; + return temp; +} +NetClient GameClient::ReleaseClient() +{ + NetClient temp = this->client; + this->client = 0; + return temp; +} diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 2a297e2f..f2467750 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -14,7 +14,7 @@ using namespace GameLogic; using namespace DanBias; GameLobby::GameLobby() -{ } +{ } GameLobby::~GameLobby() { this->clients.Clear(); @@ -37,16 +37,33 @@ void GameLobby::Update() void GameLobby::SetGameDesc(const LobbyLevelData& desc) { this->description.gameMode = desc.gameMode; - this->description.gameTime = desc.gameTime; - this->description.mapNumber = desc.mapNumber; + this->description.gameName = desc.gameName; + this->description.mapName = desc.mapName; + this->description.gameTimeInMinutes = desc.gameTimeInMinutes; this->description.maxClients = desc.maxClients; + + if(this->gClients.Size() > (unsigned int)desc.maxClients) + { + //Kick overflow + for (unsigned int i = (unsigned int)desc.maxClients - 1; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->GetClient()->Disconnect(); + } + } + } + this->gClients.Resize((unsigned int)desc.maxClients); + } void GameLobby::GetGameDesc(LobbyLevelData& desc) { - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; + desc.gameTimeInMinutes = this->description.gameTimeInMinutes; desc.maxClients = this->description.maxClients; + desc.mapName = this->description.mapName; + desc.gameName = this->description.gameName; + desc.gameMode = this->description.gameMode; + } bool GameLobby::StartGameSession( ) { @@ -56,10 +73,10 @@ bool GameLobby::StartGameSession( ) GameSession::GameDescription desc; desc.maxClients = this->description.maxClients; desc.gameMode = this->description.gameMode; - desc.gameTimeMinutes = this->description.gameTime; + desc.gameTimeMinutes = this->description.gameTimeInMinutes; //desc.mapName = this->description.mapNumber; desc.owner = this; - desc.clients = this->clients; + desc.clients = this->gClients; if(desc.gameTimeMinutes == 0) desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. @@ -67,7 +84,7 @@ bool GameLobby::StartGameSession( ) if(desc.maxClients == 0) desc.maxClients = 10; //note: should be fetched somewhere else.. - this->clients.Clear(); //Remove clients from lobby list + this->gClients.Clear(); //Remove clients from lobby list if(this->gameSession.Create(desc)) { @@ -96,8 +113,8 @@ void GameLobby::ClientEventCallback(NetEventGetID(), e.sender->GetIpAddress().c_str()); e.sender->Disconnect(); - this->readyList.Remove(e.sender); - this->clients.Remove(e.sender); + //this->readyList.Remove(e.sender); + //this->gClients.Remove(e.sender); break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); @@ -111,21 +128,30 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointergameSession) { - Attach(client); + if(!this->Attach(client)) + { + client->Disconnect(); + } } else { - Attach(client); + if(!this->Attach(client)) + { + //Send message that lobby full + client->Disconnect(); + return; + } + Protocol_LobbyClientData p1; Protocol_LobbyGameData p2; - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { Protocol_LobbyClientData::PlayerData t; - t.id = this->clients[i]->GetID(); - t.ip = this->clients[i]->GetIpAddress(); + t.id = client->GetID(); + t.ip = client->GetIpAddress(); t.team = 0; t.name = "Dennis är kung tycker Erik!"; p1.list.Push(t); @@ -139,4 +165,42 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointerSend(p2.GetProtocol()); } } +void GameLobby::ProcessClients() +{ + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->UpdateClient(); + } + } +} +bool GameLobby::Attach(Utility::DynamicMemory::SmartPointer client) +{ + if(this->clientCount = this->description.maxClients) return false; + + bool added = false; + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(!this->gClients[i]) + { + added = true; + this->gClients[i] = new GameClient(client); + } + } + + if(!added) + { + this->gClients.Push(new GameClient(client)); + } + return true; +} + + + + + + + + diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index 81758480..ebcfb8bf 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -116,27 +116,34 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: } void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) { - NetClient temp; - bool found = false; - - //find client in waiting list - for (unsigned int i = 0; !found && i < this->clients.Size(); i++) + if(this->gameSession) { - if(this->clients[i]->GetID() == c->GetID()) + gClient temp; + bool found = false; + + //find client in waiting list + for (unsigned int i = 0; !found && i < this->clients.Size(); i++) { - temp = this->clients[i]; - found = true; + if(this->gClients[i]->GetClient()->GetID() == c->GetID()) + { + temp = this->gClients[i]; + found = true; + } } - } - //Something is wrong - if(!found) - { - c->Disconnect(); + //Something is wrong + if(!found) + { + c->Disconnect(); + } + else + { + //Send game data + this->gameSession.Join(temp); + } } else { - //Send game data - this->gameSession.Attach(temp); + } } diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 087fa7ff..8fbf2111 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -118,65 +118,74 @@ void GameServerAPI::NotifyWhenClientDisconnect(ClientDisconnectedNotify func) else clientDisconnectedCallback = func; } -void GameServerAPI::GameSetMapName(const wchar_t* val) +void GameServerAPI::GameSetMapName(const wchar_t* val) { LobbyLevelData d; lobby.GetGameDesc(d); - //d.mapNumber = val; //TODO: implement + d.mapName = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetMaxClients(const int& val) +void GameServerAPI::GameSetGameMode(const wchar_t* val) +{ + LobbyLevelData d; + lobby.GetGameDesc(d); + d.gameMode = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetGameName(const wchar_t* val) +{ + LobbyLevelData d; + lobby.GetGameDesc(d); + d.gameName = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetMaxClients(const int& val) { LobbyLevelData d; lobby.GetGameDesc(d); d.maxClients = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetGameMode(const wchar_t* val) +void GameServerAPI::GameSetGameTime(const int& val) { LobbyLevelData d; lobby.GetGameDesc(d); - //d.gameMode = val; //TODO: implement + d.gameTimeInMinutes = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetGameTime(const int& val) + +const wchar_t* GameServerAPI::GameGetMapName() { LobbyLevelData d; lobby.GetGameDesc(d); - d.gameTime = val; - lobby.SetGameDesc(d); + return d.mapName.c_str(); } -int GameServerAPI::GameGetMapId() -{ - LobbyLevelData d; - lobby.GetGameDesc(d); - return d.mapNumber; -} -int GameServerAPI::GameGetMaxClients() +int GameServerAPI::GameGetMaxClients() { LobbyLevelData d; lobby.GetGameDesc(d); return d.maxClients; } -int GameServerAPI::GameGetGameMode() +const wchar_t* GameServerAPI::GameGetGameMode() { LobbyLevelData d; lobby.GetGameDesc(d); - return d.gameMode; + return d.gameMode.c_str(); } -int GameServerAPI::GameGetGameTime() +int GameServerAPI::GameGetGameTime() { LobbyLevelData d; lobby.GetGameDesc(d); - return d.gameTime; + return d.gameTimeInMinutes; } -const char* GameServerAPI::GameGetGameName() +const wchar_t* GameServerAPI::GameGetGameName() { LobbyLevelData d; lobby.GetGameDesc(d); return d.gameName.c_str(); } -bool GameServerAPI::GameStart() + +bool GameServerAPI::GameStart() { if(lobby.StartGameSession()) { diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index d0cf5190..c3319eb3 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -43,9 +43,9 @@ using namespace DanBias; { int temp = -1; //Find the idiot - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]->Equals(e.sender)) + if(this->gClients[i]->Equals(e.sender)) { temp = i; } @@ -56,7 +56,7 @@ using namespace DanBias; this->Detach(e.sender)->Disconnect(); return; } - SmartPointer cl = this->clients[temp]; + SmartPointer cl = this->gClients[temp]; switch (e.args.type) { @@ -70,15 +70,21 @@ using namespace DanBias; break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); - testID = 2; - if(cl->GetPlayer()->GetID() == testID)//TODO: TEST - { - testTimer.reset(); - } this->ParseProtocol(e.args.data.protocol, cl); break; } } + void GameSession::ProcessClients() + { + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->UpdateClient(); + } + } + } + void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) { diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index cd89dc9a..d0ad30f4 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -3,6 +3,7 @@ ///////////////////////////////////////////////////////////////////// #include "..\GameSession.h" #include "..\GameClient.h" +#include "..\GameLobby.h" #include #include #include @@ -62,9 +63,16 @@ bool GameSession::Create(GameDescription& desc) if(this->isCreated) return false; /* standard initialization of some data */ - NetworkSession::clients = desc.clients; - NetworkSession::clients.Resize((unsigned int)desc.maxClients); - this->clients.Resize((unsigned int)desc.maxClients); + this->gClients.Resize((unsigned int)desc.maxClients); + for (unsigned int i = 0; i < desc.clients.Size(); i++) + { + if(desc.clients[i]) + { + this->clientCount++; + this->gClients[i] = desc.clients[i]; + this->gClients[i]->SetOwner(this); + } + } this->owner = desc.owner; /* Initiate the game instance */ @@ -75,14 +83,13 @@ bool GameSession::Create(GameDescription& desc) /* Create the players in the game instance */ GameLogic::IPlayerData* p = 0; - for (unsigned int i = 0; i < desc.clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(desc.clients[i]) + if(this->gClients[i]) { if( (p = this->gameInstance.CreatePlayer()) ) { - desc.clients[i]->SetOwner(this); - this->clients[i] = (new GameClient(desc.clients[i], p)); + this->gClients[i]->SetPlayer(p); } else { @@ -129,15 +136,15 @@ void GameSession::Run() void GameSession::ThreadEntry( ) { //List with clients that we are waiting on.. - DynamicArray> readyList;// = this->clients; + DynamicArray readyList;// = this->clients; //First we need to clean invalid clients, if any, and tell them to start loading game data - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { - readyList.Push(this->clients[i]); - Protocol_LobbyCreateGame p((char)1, (char)0, this->description.mapName); + readyList.Push(this->gClients[i]); + Protocol_LobbyCreateGame p((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); readyList[readyList.Size() - 1]->GetClient()->Send(p); } } @@ -153,13 +160,13 @@ void GameSession::ThreadEntry( ) if(readyList[i] && readyList[i]->IsReady()) { //Need to send information about other players, to all players - for (unsigned int k = 0; k < this->clients.Size(); k++) + for (unsigned int k = 0; k < this->gClients.Size(); k++) { - if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) + if((this->gClients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->gClients[k]->GetClient()->GetID()) { - IPlayerData* pl = this->clients[k]->GetPlayer(); + IPlayerData* pl = this->gClients[k]->GetPlayer(); Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), - pl->GetID(), true, this->clients[k]->GetPlayer()->GetTeamID(), + pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(), /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); readyList[i]->GetClient()->Send(p); } @@ -173,32 +180,31 @@ void GameSession::ThreadEntry( ) } //Sync with clients before starting countdown - - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { - this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + this->gClients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5.0f)); } } } -bool GameSession::Attach(Utility::DynamicMemory::SmartPointer networkClient) +bool GameSession::Join(gClient gameClient) { if(!this->isCreated) return false; - if(this->GetClientCount() == this->clients.Capacity()) return false; + if(this->GetClientCount() == this->gClients.Capacity()) return false; - networkClient->SetOwner(this); + gameClient->SetOwner(this); IPlayerData* playerData = this->gameInstance.CreatePlayer(); if(!playerData) return false; - SmartPointer gameClient = new GameClient(networkClient, playerData); + gameClient->SetPlayer(playerData); NetworkClient* nwClient = gameClient->GetClient(); // Send the level information { - Protocol_LobbyCreateGame lcg((char)1, (char)0, this->description.mapName); + Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); nwClient->Send(lcg); } @@ -212,11 +218,11 @@ bool GameSession::Attach(Utility::DynamicMemory::SmartPointer net // Send information about other clients { - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(clients[i]) + if(this->gClients[i]) { - IPlayerData* temp = clients[i]->GetPlayer(); + IPlayerData* temp = this->gClients[i]->GetPlayer(); Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), temp->GetID(), false, temp->GetTeamID(), /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); @@ -227,40 +233,44 @@ bool GameSession::Attach(Utility::DynamicMemory::SmartPointer net //TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client { - + } // Insert the new client to the update list + bool added = false; { - bool added = false; - for (unsigned int i = 0; !added && i < this->clients.Size(); i++) + for (unsigned int i = 0; !added && i < this->gClients.Size(); i++) { - if(!clients[i]) + if(!this->gClients[i]) { - NetworkSession::clients[i] = networkClient; - clients[i] = gameClient; + this->gClients[i] = gameClient; + // Send the start signal + { + nwClient->Send(GameLogic::Protocol_LobbyStartGame(0)); + } added = true; + this->clientCount++; } } - if(!added) - { - NetworkSession::clients.Push( networkClient ); - clients.Push( gameClient ); - } - } -// Send the start signal - { - nwClient->Send(GameLogic::Protocol_LobbyStartGame(0)); } - return true; + return added; } -void GameSession::CloseSession( bool dissconnectClients ) -{ - this->worker.Terminate(); - NetworkSession::CloseSession(true); - this->clients.Clear(); -} +//DynamicArray GameSession::CloseSession( bool dissconnectClients ) +//{ +// this->worker.Terminate(); +// //TODO: Send clients to lobby +// +// //for (unsigned int i = 0; i < this->gClients.Size(); i++) +// //{ +// // if(this->gClients[i]) +// // { +// // ((GameLobby*)this->owner)-> this->gClients[i] +// // } +// //} +// +// this->gClients.Clear(); +//} diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp index 3a10b6ce..0c913a56 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp @@ -72,26 +72,32 @@ void StandaloneGameServerCLI::GameSetMapName(String^ value) pin_ptr wch = PtrToStringChars(value); DanBias::GameServerAPI::GameSetMapName(wch); } +void StandaloneGameServerCLI::GameSetGameMode(String^ value) +{ + pin_ptr wch = PtrToStringChars(value); + DanBias::GameServerAPI::GameSetGameMode(wch); +} +void StandaloneGameServerCLI::GameSetGameName(String^ value) +{ + pin_ptr wch = PtrToStringChars(value); + DanBias::GameServerAPI::GameSetGameName(wch); +} void StandaloneGameServerCLI::GameSetMaxClients(const int val) { DanBias::GameServerAPI::GameSetMaxClients(val); } -void StandaloneGameServerCLI::GameSetGameMode(String^ value) -{ - pin_ptr wch = PtrToStringChars(value); - DanBias::GameServerAPI::GameSetGameMode(wch); -} + void StandaloneGameServerCLI::GameSetGameTime(const int val) { DanBias::GameServerAPI::GameSetGameTime(val); } -int StandaloneGameServerCLI::GameGetMapId() +String^ StandaloneGameServerCLI::GameGetMapName() { - return DanBias::GameServerAPI::GameGetMapId(); + return gcnew String( DanBias::GameServerAPI::GameGetMapName()); } int StandaloneGameServerCLI::GameGetMaxClients() @@ -99,9 +105,9 @@ int StandaloneGameServerCLI::GameGetMaxClients() return DanBias::GameServerAPI::GameGetMaxClients(); } -int StandaloneGameServerCLI::GameGetGameMode() +String^ StandaloneGameServerCLI::GameGetGameMode() { - return DanBias::GameServerAPI::GameGetGameMode(); + return gcnew String( DanBias::GameServerAPI::GameGetGameMode()); } int StandaloneGameServerCLI::GameGetGameTime() @@ -111,7 +117,7 @@ int StandaloneGameServerCLI::GameGetGameTime() String^ StandaloneGameServerCLI::GameGetGameName() { - return gcnew String(DanBias::GameServerAPI::GameGetGameName()); + return gcnew String( DanBias::GameServerAPI::GameGetGameName()); } bool StandaloneGameServerCLI::GameStart() diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h index 3fdd0713..d71a23b8 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h @@ -47,13 +47,15 @@ namespace System { namespace Windows { namespace Interop bool ServerIsRunning(); void GameSetMapName(String^ val); - void GameSetMaxClients(const int val); void GameSetGameMode(String^ val); + void GameSetGameName(String^ val); + void GameSetMaxClients(const int val); void GameSetGameTime(const int val); - int GameGetMapId(); + int GameGetMaxClients(); - int GameGetGameMode(); int GameGetGameTime(); + System::String^ GameGetMapName(); + System::String^ GameGetGameMode(); System::String^ GameGetGameName(); bool GameStart(); }; diff --git a/Code/Network/NetworkAPI/NetworkSession.h b/Code/Network/NetworkAPI/NetworkSession.h index f0677c77..b4e8e8fe 100644 --- a/Code/Network/NetworkAPI/NetworkSession.h +++ b/Code/Network/NetworkAPI/NetworkSession.h @@ -98,9 +98,9 @@ namespace Oyster protected: NetClientList clients; - - private: int clientCount; + + private: struct PrivateSessionData; PrivateSessionData* data; }; From cec27408966d688d822a1ea906ba011d8f26ccd1 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 11:56:36 +0100 Subject: [PATCH 21/39] GameServer - Fixed minor miss with inheritance --- Code/Game/GameServer/GameSession.h | 2 ++ .../Implementation/GameSession_Gameplay.cpp | 27 +++++++++++++++++++ .../Implementation/GameSession_General.cpp | 9 ++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 200bed9b..e6c8a4f9 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -65,6 +65,8 @@ namespace DanBias // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent e) override; void ProcessClients() override; + bool Send(Oyster::Network::CustomNetProtocol& message) override; + bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override; //Sends a client to the owner, if param is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index c3319eb3..61ccf9c8 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -84,6 +84,33 @@ using namespace DanBias; } } } + bool GameSession::Send(Oyster::Network::CustomNetProtocol& message) + { + bool returnValue = false; + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->GetClient()->Send(message); + returnValue = true; + } + } + + return returnValue; + + } + bool GameSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID) + { + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i] && this->gClients[i]->GetClient()->GetID() == ID) + { + this->gClients[i]->GetClient()->Send(protocol); + return true; + } + } + return false; + } void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index d0ad30f4..43f088dd 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -233,7 +233,14 @@ bool GameSession::Join(gClient gameClient) //TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client { - + DynamicArray objects; + this->levelData->GetAllDynamicObjects(objects); + for (unsigned int i = 0; i < objects.Size(); i++) + { + //Protocol_ObjectPosition p(movedObject->GetPosition(), id); + Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID()); + GameSession::gameSession->Send(p.GetProtocol()); + } } // Insert the new client to the update list From f9f4d551237ff8deedc35dd75993dd94245e7f64 Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 12:02:48 +0100 Subject: [PATCH 22/39] Graphics fix --- .../GameClient/GameClientState/GameState.cpp | 16 ++++++++++++++++ Code/OysterGraphics/Render/Resources.cpp | 2 +- .../Shader/Passes/Blur/BlurHor.hlsl | 2 +- .../Shader/Passes/Blur/BlurVert.hlsl | 6 +++--- .../Shader/Passes/Post/PostPass.hlsl | 6 ++---- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index f590f366..ba9bf034 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -36,6 +36,8 @@ struct GameState::MyData bool key_Shoot; bool key_Jump; + bool key_Reload_Shaders; + C_Player player; Camera_FPS camera; @@ -236,6 +238,20 @@ void GameState::ReadKeyInput() else this->privData->key_strafeRight = false; + if( this->privData->input->IsKeyPressed(DIK_R) ) + { + if( !this->privData->key_Reload_Shaders ) + { + //this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); +#ifdef _DEBUG + Graphics::API::ReloadShaders(); +#endif + this->privData->key_Reload_Shaders = true; + } + } + else + this->privData->key_Reload_Shaders = false; + //send delta mouse movement { diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 82ace315..514960cf 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -160,7 +160,7 @@ namespace Oyster D3D11_RASTERIZER_DESC rdesc; rdesc.CullMode = D3D11_CULL_BACK; rdesc.FillMode = D3D11_FILL_SOLID; - rdesc.FrontCounterClockwise = false; + rdesc.FrontCounterClockwise = true; rdesc.DepthBias = 0; rdesc.DepthBiasClamp = 0; rdesc.DepthClipEnable = true; diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl index aeb89bda..a6843985 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurHor.hlsl @@ -27,7 +27,7 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask); + outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask); //outTex[ThreadID.xy + Start] = inTex[ThreadID.xy + Start]; } diff --git a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl index 24f873db..2933283e 100644 --- a/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Blur/BlurVert.hlsl @@ -11,10 +11,10 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID } if(gThreadID.y >= N-blurRadius) { - int y = min(ThreadID.y+blurRadius, Stop.y-1); + int y = min(ThreadID.y +blurRadius, Stop.y-1); gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start]; } - gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)]; + gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)]; GroupMemoryBarrierWithGroupSync(); @@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID blurCol +=Weights[i + blurRadius] * gCache[k]; } - outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);; + outTex[min(ThreadID.xy + Start, Stop-1)] = blurCol * BlurMask + inTex[min(ThreadID.xy + Start, Stop-1)] * ( float4(1,1,1,1) - BlurMask);; //outTex[ThreadID.xy + Start] = inTex[ThreadID.xy+ Start]; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 346913d8..decf5526 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -18,7 +18,7 @@ float4 SuperSample(float4 Glow, uint3 DTid) index += float2(0,Output.Length.y/2); index = index / Output.Length; Glow = Ambient.SampleLevel(S1, index,1); - Glow = Glow * Glow.w*10; + Glow = Glow; return Glow; } @@ -28,10 +28,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) { float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float4 Amb = float4(Ambient[DTid.xy/2].xyz /* * Ambient[DTid.xy/2].w*/, 0); - //float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; - - Glow = SuperSample(Glow,DTid); float4 GUI; uint2 index = DTid.xy/2 + uint2((uint)Output.Length.x/(uint)2,0); @@ -42,4 +39,5 @@ void main( uint3 DTid : SV_DispatchThreadID ) Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1); //Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(0,Output.Length.y*0.5f)].xyz,1); + //Output[DTid.xy] = Ambient[DTid.xy]; } \ No newline at end of file From 2e75d168a105b5676c6ce3f7deaebb8258fd5e55 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 12:03:54 +0100 Subject: [PATCH 23/39] New Cameras V2 is quaternion based --- Code/Game/GameClient/GameClient.vcxproj | 4 + .../GameClientState/Camera_BasicV2.cpp | 117 +++++++++++ .../GameClientState/Camera_BasicV2.h | 42 ++++ .../GameClientState/Camera_FPSV2.cpp | 182 ++++++++++++++++++ .../GameClient/GameClientState/Camera_FPSV2.h | 62 ++++++ Code/Misc/OysterMath/Quaternion.h | 7 + 6 files changed, 414 insertions(+) create mode 100644 Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp create mode 100644 Code/Game/GameClient/GameClientState/Camera_BasicV2.h create mode 100644 Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp create mode 100644 Code/Game/GameClient/GameClientState/Camera_FPSV2.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 3daafff3..349a88ec 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -201,7 +201,9 @@ + + @@ -226,7 +228,9 @@ + + diff --git a/Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp b/Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp new file mode 100644 index 00000000..8454b3bd --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_BasicV2.cpp @@ -0,0 +1,117 @@ +#include "Camera_BasicV2.h" + +using namespace ::Oyster::Math3D; + +Camera_BasicV2::Camera_BasicV2() +{ + this->translation = Float3::null; + this->rotation = Quaternion::identity; + this->projection = Float4x4::identity; +} + +Camera_BasicV2::Camera_BasicV2( const Float3 &position, const Quaternion &rotation, const Float4x4 &projection ) +{ + this->translation = position; + this->rotation = rotation; + this->projection = projection; +} + +Camera_BasicV2::~Camera_BasicV2() {} + +Camera_BasicV2 & Camera_BasicV2::operator = ( const Camera_BasicV2 &camera ) +{ + this->translation = camera.translation; + this->rotation = camera.rotation; + this->projection = camera.projection; + return *this; +} + +void Camera_BasicV2::SetPosition( const Float3 &translation ) +{ + this->translation = translation; +} + +void Camera_BasicV2::SetRotation( const Quaternion &rotation ) +{ + this->rotation = rotation; +} + +void Camera_BasicV2::SetAngular( const Float3 &axis ) +{ + this->rotation = Rotation( axis ); +} + +void Camera_BasicV2::SetProjection( const Float4x4 &matrix ) +{ + this->projection = matrix; +} + +void Camera_BasicV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip ) +{ + ProjectionMatrix_Orthographic( width, height, nearClip, farClip, this->projection ); +} + +void Camera_BasicV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip ) +{ + ProjectionMatrix_Perspective( verticalFoV, aspectRatio, nearClip, farClip, this->projection ); +} + +void Camera_BasicV2::Move( const Float3 &deltaPosition ) +{ + this->translation += deltaPosition; +} + +void Camera_BasicV2::Rotate( const Quaternion &deltaRotation ) +{ + this->rotation *= deltaRotation; +} + +void Camera_BasicV2::Rotate( const Float3 &deltaAngularAxis ) +{ + this->rotation *= Rotation( deltaAngularAxis ); +} + +const Float3 & Camera_BasicV2::GetPosition() const +{ + return this->translation; +} + +Float3 & Camera_BasicV2::GetAngularAxis( Float3 &targetMem ) const +{ + return targetMem = AngularAxis( this->rotation ); +} + +Float3 Camera_BasicV2::GetNormalOf( const Float3 &axis ) const +{ + return WorldAxisOf( this->rotation, axis ); +} + +const Quaternion & Camera_BasicV2::GetRotation() const +{ + return this->rotation; +} + +Float3x3 & Camera_BasicV2::GetRotationMatrix( Float3x3 &targetMem ) const +{ + return RotationMatrix( this->rotation, targetMem ); +} + +Float4x4 & Camera_BasicV2::GetRotationMatrix( Float4x4 &targetMem ) const +{ + return RotationMatrix( this->rotation, targetMem ); +} + +Float4x4 & Camera_BasicV2::GetViewMatrix( Float4x4 &targetMem ) const +{ + return ViewMatrix( this->rotation, this->translation, targetMem ); +} + +const Float4x4 & Camera_BasicV2::GetProjectionMatrix() const +{ + return this->projection; +} + +Float4x4 & Camera_BasicV2::GetViewsProjMatrix( Float4x4 &targetMem ) const +{ + return TransformMatrix( this->projection, this->GetViewMatrix(), targetMem ); +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Camera_BasicV2.h b/Code/Game/GameClient/GameClientState/Camera_BasicV2.h new file mode 100644 index 00000000..aaa9d491 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_BasicV2.h @@ -0,0 +1,42 @@ +#ifndef CAMERA_BASIC_V2_H +#define CAMERA_BASIC_V2_H + +#include "OysterMath.h" + +class Camera_BasicV2 +{ +public: + Camera_BasicV2(); + Camera_BasicV2( const ::Oyster::Math::Float3 &position, const ::Oyster::Math::Quaternion &rotation, const ::Oyster::Math::Float4x4 &projection ); + virtual ~Camera_BasicV2(); + + Camera_BasicV2 & operator = ( const Camera_BasicV2 &camera ); + + void SetPosition( const ::Oyster::Math::Float3 &translation ); + void SetRotation( const ::Oyster::Math::Quaternion &rotation ); + void SetAngular( const ::Oyster::Math::Float3 &axis ); + void SetProjection( const ::Oyster::Math::Float4x4 &matrix ); + void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip ); + void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip ); + + void Move( const ::Oyster::Math::Float3 &deltaPosition ); + void Rotate( const ::Oyster::Math::Quaternion &deltaRotation ); + void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis ); + + const ::Oyster::Math::Float3 & GetPosition() const; + ::Oyster::Math::Float3 & GetAngularAxis( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; + ::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const; + const ::Oyster::Math::Quaternion & GetRotation() const; + ::Oyster::Math::Float3x3 & GetRotationMatrix( ::Oyster::Math::Float3x3 &targetMem ) const; + ::Oyster::Math::Float4x4 & GetRotationMatrix( ::Oyster::Math::Float4x4 &targetMem ) const; + ::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const; + ::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + + private: + ::Oyster::Math::Float3 translation; + mutable ::Oyster::Math::Quaternion rotation; + ::Oyster::Math::Float4x4 projection; +}; + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp new file mode 100644 index 00000000..b1863242 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -0,0 +1,182 @@ +#include "Camera_FPSV2.h" +#include "Utilities.h" + +using namespace ::Oyster::Math3D; +using namespace ::Utility::Value; + +Camera_FPSV2::Camera_FPSV2() +{ // this->head is default set to identity uniformprojection at origo + this->pitchUp = 0.0f; + this->headOffset = + this->body.translation = Float3::null; + this->body.rotation = Quaternion::identity; +} + +Camera_FPSV2::~Camera_FPSV2() {} + +Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera ) +{ + this->head = camera.head; + this->pitchUp = camera.pitchUp; + this->headOffset = camera.headOffset; + this->body.translation = camera.body.translation; + this->body.rotation = camera.body.rotation; + return *this; +} + +void Camera_FPSV2::SetHeadOffset( const Float3 &translation ) +{ + this->head.Move( translation - this->headOffset ); + this->headOffset = translation; +} + +void Camera_FPSV2::SetPosition( const Float3 &translation ) +{ + this->head.Move( translation - this->body.translation ); + this->body.translation = translation; +} + +void Camera_FPSV2::SetAngular( const Float3 &axis ) +{ + this->body.rotation = Rotation( axis ); + this->head.SetRotation( this->body.rotation ); + this->pitchUp = 0.0f; +} + +void Camera_FPSV2::SetProjection( const Float4x4 &matrix ) +{ + this->head.SetProjection( matrix ); +} + +void Camera_FPSV2::SetOrthographicProjection( Float width, Float height, Float nearClip, Float farClip ) +{ + this->head.SetOrthographicProjection( width, height, nearClip, farClip ); +} + +void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRatio, Float nearClip, Float farClip ) +{ + this->head.SetPerspectiveProjection( verticalFoV, aspectRatio, nearClip, farClip ); +} + +void Camera_FPSV2::UpdateOrientation() +{ + Float4x4 orientation; + OrientationMatrix( this->body.rotation, this->body.translation, orientation ); + + this->head.SetPosition( (orientation * Float4(this->headOffset, 1.0f)).xyz ); +} + +void Camera_FPSV2::SnapUpToNormal( const Float3 &normal ) +{ + this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) ); + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) ); +} + +void Camera_FPSV2::Move( const Float3 &deltaPosition ) +{ + this->head.Move( deltaPosition ); + this->body.translation += deltaPosition; +} + +void Camera_FPSV2::Rotate( const Quaternion &deltaRotation ) +{ + this->head.Rotate( deltaRotation ); + this->body.rotation *= deltaRotation; +} + +void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis ) +{ + this->Rotate( Rotation(deltaAngularAxis) ); +} + +void Camera_FPSV2::MoveForward( Float distance ) +{ + this->MoveBackward( -distance ); +} + +void Camera_FPSV2::MoveBackward( Float distance ) +{ + this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_z) ); +} + +void Camera_FPSV2::StrafeRight( Float distance ) +{ + this->Move( distance * WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ); +} + +void Camera_FPSV2::StrafeLeft( Float distance ) +{ + this->StrafeRight( -distance ); +} + +void Camera_FPSV2::PitchUp( Float radian ) +{ + this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) ); +} + +void Camera_FPSV2::PitchDown( Float radian ) +{ + this->PitchUp( -radian ); +} + +void Camera_FPSV2::YawRight( Float radian ) +{ + this->YawLeft( -radian ); +} + +void Camera_FPSV2::YawLeft( Float radian ) +{ + Quaternion deltaRotation = Rotation( radian, WorldAxisOf(this->body.rotation, Float3::standard_unit_y) ); + this->Rotate( deltaRotation ); +} + +const Float3 & Camera_FPSV2::GetHeadOffset() const +{ + return this->headOffset; +} + +const Float3 & Camera_FPSV2::GetPosition() const +{ + return this->body.translation; +} + +Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const +{ + return this->head.GetViewMatrix( targetMem ); +} + +const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const +{ + return this->head.GetProjectionMatrix(); +} + +Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const +{ + return this->head.GetViewsProjMatrix( targetMem ); +} + +Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const +{ + return this->head.GetNormalOf( axis ); +} + +Float3 Camera_FPSV2::GetRight() const +{ + return WorldAxisOf( this->body.rotation, Float3::standard_unit_x ); +} + +Float3 Camera_FPSV2::GetUp() const +{ + return WorldAxisOf( this->body.rotation, Float3::standard_unit_y ); +} + +Float3 Camera_FPSV2::GetLook() const +{ + return this->head.GetNormalOf( -Float3::standard_unit_z ); +} + +Float3 Camera_FPSV2::GetForward() const +{ + return WorldAxisOf( this->body.rotation, -Float3::standard_unit_z ); +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h new file mode 100644 index 00000000..968053c7 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h @@ -0,0 +1,62 @@ +#ifndef CAMERA_FPSV2_H +#define CAMERA_FPSV2_H + +#include "OysterMath.h" +#include "Camera_BasicV2.h" + +class Camera_FPSV2 +{ +public: + Camera_FPSV2(); + virtual ~Camera_FPSV2(); + + Camera_FPSV2 & operator = ( const Camera_FPSV2 &camera ); + + void SetHeadOffset( const ::Oyster::Math::Float3 &translation ); + void SetPosition( const ::Oyster::Math::Float3 &translation ); + void SetAngular( const ::Oyster::Math::Float3 &axis ); + void SetProjection( const ::Oyster::Math::Float4x4 &matrix ); + void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip ); + void SetPerspectiveProjection( ::Oyster::Math::Float verticalFoV, ::Oyster::Math::Float aspectRatio, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip ); + + void UpdateOrientation(); + + void SnapUpToNormal( const ::Oyster::Math::Float3 &normal ); + + void Move( const ::Oyster::Math::Float3 &deltaPosition ); + void Rotate( const ::Oyster::Math::Quaternion &deltaRotation ); + void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis ); + + void MoveForward( ::Oyster::Math::Float distance ); + void MoveBackward( ::Oyster::Math::Float distance ); + void StrafeRight( ::Oyster::Math::Float distance ); + void StrafeLeft( ::Oyster::Math::Float distance ); + + void PitchUp( ::Oyster::Math::Float radian ); + void PitchDown( ::Oyster::Math::Float radian ); + void YawRight( ::Oyster::Math::Float radian ); + void YawLeft( ::Oyster::Math::Float radian ); + + const ::Oyster::Math::Float3 & GetHeadOffset() const; + const ::Oyster::Math::Float3 & GetPosition() const; + ::Oyster::Math::Float4x4 & GetViewMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + const ::Oyster::Math::Float4x4 & GetProjectionMatrix() const; + ::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; + ::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const; + ::Oyster::Math::Float3 GetRight() const; + ::Oyster::Math::Float3 GetUp() const; + ::Oyster::Math::Float3 GetLook() const; + ::Oyster::Math::Float3 GetForward() const; + +private: + Camera_BasicV2 head; + ::Oyster::Math::Float pitchUp; + ::Oyster::Math::Float3 headOffset; + struct + { + ::Oyster::Math::Float3 translation; + ::Oyster::Math::Quaternion rotation; + } body; +}; + +#endif \ No newline at end of file diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index da790f75..f5ea5951 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -36,6 +36,7 @@ namespace LinearAlgebra const ScalarType & operator [] ( int i ) const; Quaternion & operator = ( const Quaternion &quaternion ); + Quaternion & operator *= ( const Quaternion &quaternion ); Quaternion & operator *= ( const ScalarType &scalar ); Quaternion & operator /= ( const ScalarType &scalar ); Quaternion & operator += ( const Quaternion &quaternion ); @@ -112,6 +113,12 @@ namespace LinearAlgebra return *this; } + template + Quaternion & Quaternion::operator *= ( const Quaternion &quaternion ) + { + return *this = *this * quaternion; + } + template Quaternion & Quaternion::operator *= ( const ScalarType &scalar ) { From 500ac117a7429e64e17a7335c250daa3d7f936f2 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 12:59:51 +0100 Subject: [PATCH 24/39] removed debug lines --- Code/Game/GameClient/GameClientState/GameState.cpp | 8 ++------ Code/Game/GameClient/GameClientState/NetLoadState.cpp | 5 +---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 910afeb9..7118191e 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -85,11 +85,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready - //this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); - - // Debugg hack - this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); - // end debug hack + this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); return true; } @@ -111,7 +107,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); Float3 offset = Float3( 0.0f ); - offset.y = this->privData->player.getScale().y + 0.5f; // debug hack +0.5f + offset.y = this->privData->player.getScale().y * 0.9f; this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 7443344e..f50db40c 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -54,11 +54,8 @@ bool NetLoadState::Init( SharedStateContent &shared ) // we may assume that nwClient is properly connected to the server // signals querry to server for loading instructions - //this->privData->nwClient->Send( Protocol_QuerryGameType() ); + this->privData->nwClient->Send( Protocol_QuerryGameType() ); - // debugg - this->LoadGame( "..//Content//Worlds//2ofAll_updated.bias"); - this->ChangeState( ClientState_Game ); return true; } From e00ddb30c9a606d3e9ab81c46947b942709cb79a Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 13:12:08 +0100 Subject: [PATCH 25/39] Fixed server-client communication --- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- Code/Game/GameServer/GameLobby.h | 7 +- Code/Game/GameServer/GameServerAPI.h | 7 +- Code/Game/GameServer/GameSession.h | 4 +- .../GameServer/Implementation/GameLobby.cpp | 55 ++-- .../GameServer/Implementation/GameServer.cpp | 11 +- .../Implementation/GameSession_General.cpp | 18 +- .../StandaloneGameServerCLI.cpp | 13 +- .../StandaloneGameServerCLI.h | 3 +- .../StandAloneLauncher/Form1.Designer.cs | 271 ++++++++++-------- .../LanServer/StandAloneLauncher/Form1.cs | 13 +- 11 files changed, 234 insertions(+), 170 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 9281dcd6..7b9a46d7 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -38,7 +38,12 @@ namespace DanBias void SetGameDesc(const LobbyLevelData& desc); void GetGameDesc(LobbyLevelData& desc); - bool StartGameSession(); + /** + * If param is true, the server will start a game session regardless of clients connected. + */ + bool StartGameSession( bool forceStart ); + + int GetGameSessionClientCount(); private: void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c); diff --git a/Code/Game/GameServer/GameServerAPI.h b/Code/Game/GameServer/GameServerAPI.h index eb5316c4..0a5a8a88 100644 --- a/Code/Game/GameServer/GameServerAPI.h +++ b/Code/Game/GameServer/GameServerAPI.h @@ -66,8 +66,13 @@ namespace DanBias static const wchar_t* GameGetGameMode(); static const wchar_t* GameGetGameName(); static const wchar_t* GameGetMapName(); + static int GetConnectedClientCount(); - static bool GameStart(); + /* Starts a game + * @param forceStart If forceStart is true, server will start with or without clients. + * If there are clients not "ready" the will be stareted anyways. + */ + static bool GameStart(bool forceStart); };//End class DanBiasServer diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index e6c8a4f9..28e8bde3 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -44,7 +44,7 @@ namespace DanBias virtual~GameSession(); /** Initiates and creates a game session. */ - bool Create(GameDescription& desc); + bool Create(GameDescription& desc, bool forceStart); /** Runs the game session (ie starts the game loop). */ void Run(); @@ -58,7 +58,7 @@ namespace DanBias inline bool IsCreated() const { return this->isCreated; } inline bool IsRunning() const { return this->isRunning; } - operator bool() { return (this->isCreated && this->isRunning); } + operator bool() { return (this->isCreated && this->isRunning); } //Private member functions private: diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index f2467750..b95402e2 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -65,40 +65,47 @@ void GameLobby::GetGameDesc(LobbyLevelData& desc) desc.gameMode = this->description.gameMode; } -bool GameLobby::StartGameSession( ) +bool GameLobby::StartGameSession( bool forceStart ) { -//Check if all clients is ready - if(this->GetClientCount() && this->GetClientCount() == this->readyList.Size()) +//Check if all clients is ready, in not force start + if(!forceStart) { - GameSession::GameDescription desc; - desc.maxClients = this->description.maxClients; - desc.gameMode = this->description.gameMode; - desc.gameTimeMinutes = this->description.gameTimeInMinutes; - //desc.mapName = this->description.mapNumber; - desc.owner = this; - desc.clients = this->gClients; + if(!this->GetClientCount()) + { /*None connected*/ return false;} + else if( this->GetClientCount() != this->readyList.Size() ) + { /*Not enough connected*/ return false; } + } - if(desc.gameTimeMinutes == 0) - desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. + GameSession::GameDescription desc; + desc.maxClients = this->description.maxClients; + desc.gameMode = this->description.gameMode; + desc.gameTimeMinutes = this->description.gameTimeInMinutes; + desc.mapName = this->description.mapName; + desc.owner = this; + desc.clients = this->gClients; - if(desc.maxClients == 0) - desc.maxClients = 10; //note: should be fetched somewhere else.. + if(desc.gameTimeMinutes == 0) + desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. - this->gClients.Clear(); //Remove clients from lobby list + if(desc.maxClients == 0) + desc.maxClients = 10; //note: should be fetched somewhere else.. + + this->gClients.Clear(); //Remove clients from lobby list - if(this->gameSession.Create(desc)) - { - this->gameSession.Run(); - - return true; - } - } - else + if(this->gameSession.Create(desc, forceStart)) { - //? + this->gameSession.Run(); + + return true; } + + return false; } +int GameLobby::GetGameSessionClientCount() +{ + return this->gameSession.GetClientCount(); +} void GameLobby::ClientEventCallback(NetEvent e) { diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 8fbf2111..f003fc50 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -184,12 +184,15 @@ const wchar_t* GameServerAPI::GameGetGameName() lobby.GetGameDesc(d); return d.gameName.c_str(); } - -bool GameServerAPI::GameStart() +int GameServerAPI::GetConnectedClientCount() { - if(lobby.StartGameSession()) + return lobby.GetGameSessionClientCount(); +} + +bool GameServerAPI::GameStart( bool forceStart ) +{ + if(lobby.StartGameSession( forceStart )) { - return true; } return false; diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 43f088dd..07d2dcd4 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -54,13 +54,13 @@ GameSession::~GameSession() this->isRunning = false; } -bool GameSession::Create(GameDescription& desc) +bool GameSession::Create(GameDescription& desc, bool forceStart) { this->description = desc; /* Do some error checking */ - if(desc.clients.Size() == 0) return false; - if(!desc.owner) return false; - if(this->isCreated) return false; + if(!forceStart && desc.clients.Size() == 0) return false; + if(!desc.owner) return false; + if(this->isCreated) return false; /* standard initialization of some data */ this->gClients.Resize((unsigned int)desc.maxClients); @@ -125,12 +125,10 @@ void GameSession::Run() { if(this->isRunning) return; - if(this->clients.Size() > 0) - { - this->worker.Start(); - this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); - this->isRunning = true; - } + this->worker.Start(); + this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); + this->isRunning = true; + } void GameSession::ThreadEntry( ) diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp index 0c913a56..1065a28a 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp @@ -120,7 +120,14 @@ String^ StandaloneGameServerCLI::GameGetGameName() return gcnew String( DanBias::GameServerAPI::GameGetGameName()); } -bool StandaloneGameServerCLI::GameStart() +bool StandaloneGameServerCLI::GameStart(bool f) { - return DanBias::GameServerAPI::GameStart(); -} \ No newline at end of file + return DanBias::GameServerAPI::GameStart(f); +} +int StandaloneGameServerCLI::GetClientsConnectedCount() +{ + return DanBias::GameServerAPI::GetConnectedClientCount(); +} + + + diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h index d71a23b8..576a7433 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h @@ -57,7 +57,8 @@ namespace System { namespace Windows { namespace Interop System::String^ GameGetMapName(); System::String^ GameGetGameMode(); System::String^ GameGetGameName(); - bool GameStart(); + bool GameStart( bool forceStart ); + int GetClientsConnectedCount(); }; } } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs index df569295..103a047f 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs @@ -36,30 +36,32 @@ this.label_listenPort = new System.Windows.Forms.Label(); this.panel_serverOptions = new System.Windows.Forms.Panel(); this.panel_commands = new System.Windows.Forms.Panel(); + this.mapName = new System.Windows.Forms.TextBox(); + this.timeLimit = new System.Windows.Forms.NumericUpDown(); + this.gameModes = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.forceStart = new System.Windows.Forms.CheckBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.nrOfClients = new System.Windows.Forms.NumericUpDown(); + this.buttonStartGame = new System.Windows.Forms.Button(); this.panel_clientArea = new System.Windows.Forms.Panel(); this.ServerInfoTextArea = new System.Windows.Forms.RichTextBox(); this.splitter1 = new System.Windows.Forms.Splitter(); this.clientInfoBox = new System.Windows.Forms.ListBox(); - this.buttonStartGame = new System.Windows.Forms.Button(); - this.nrOfClients = new System.Windows.Forms.NumericUpDown(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.gameModes = new System.Windows.Forms.ComboBox(); - this.timeLimit = new System.Windows.Forms.NumericUpDown(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.mapName = new System.Windows.Forms.TextBox(); + this.labelClientsConnected = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.listenPort)).BeginInit(); this.panel_serverOptions.SuspendLayout(); this.panel_commands.SuspendLayout(); - this.panel_clientArea.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.timeLimit)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit(); + this.panel_clientArea.SuspendLayout(); this.SuspendLayout(); // // serverToggle // - this.serverToggle.Location = new System.Drawing.Point(9, 81); + this.serverToggle.Location = new System.Drawing.Point(9, 106); this.serverToggle.Name = "serverToggle"; this.serverToggle.Size = new System.Drawing.Size(75, 23); this.serverToggle.TabIndex = 0; @@ -111,7 +113,7 @@ this.listenPort.Size = new System.Drawing.Size(95, 20); this.listenPort.TabIndex = 5; this.listenPort.Value = new decimal(new int[] { - 2048, + 15151, 0, 0, 0}); @@ -135,7 +137,7 @@ this.panel_serverOptions.Controls.Add(this.label_serverName); this.panel_serverOptions.Location = new System.Drawing.Point(12, 12); this.panel_serverOptions.Name = "panel_serverOptions"; - this.panel_serverOptions.Size = new System.Drawing.Size(183, 113); + this.panel_serverOptions.Size = new System.Drawing.Size(183, 141); this.panel_serverOptions.TabIndex = 6; // // panel_commands @@ -144,17 +146,137 @@ this.panel_commands.Controls.Add(this.timeLimit); this.panel_commands.Controls.Add(this.gameModes); this.panel_commands.Controls.Add(this.label3); + this.panel_commands.Controls.Add(this.forceStart); this.panel_commands.Controls.Add(this.label2); this.panel_commands.Controls.Add(this.label4); + this.panel_commands.Controls.Add(this.labelClientsConnected); this.panel_commands.Controls.Add(this.label1); this.panel_commands.Controls.Add(this.nrOfClients); this.panel_commands.Controls.Add(this.buttonStartGame); - this.panel_commands.Location = new System.Drawing.Point(12, 131); + this.panel_commands.Location = new System.Drawing.Point(12, 159); this.panel_commands.Name = "panel_commands"; - this.panel_commands.Size = new System.Drawing.Size(183, 230); + this.panel_commands.Size = new System.Drawing.Size(183, 202); this.panel_commands.TabIndex = 7; this.panel_commands.Visible = false; // + // mapName + // + this.mapName.Location = new System.Drawing.Point(78, 7); + this.mapName.Name = "mapName"; + this.mapName.Size = new System.Drawing.Size(98, 20); + this.mapName.TabIndex = 12; + this.mapName.Text = "Unknown"; + // + // timeLimit + // + this.timeLimit.Location = new System.Drawing.Point(109, 94); + this.timeLimit.Minimum = new decimal(new int[] { + 5, + 0, + 0, + 0}); + this.timeLimit.Name = "timeLimit"; + this.timeLimit.Size = new System.Drawing.Size(68, 20); + this.timeLimit.TabIndex = 11; + this.timeLimit.ThousandsSeparator = true; + this.timeLimit.Value = new decimal(new int[] { + 15, + 0, + 0, + 0}); + // + // gameModes + // + this.gameModes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.gameModes.FormattingEnabled = true; + this.gameModes.Items.AddRange(new object[] { + "Free-for-all", + "Team death-match"}); + this.gameModes.Location = new System.Drawing.Point(78, 66); + this.gameModes.Name = "gameModes"; + this.gameModes.Size = new System.Drawing.Size(99, 21); + this.gameModes.TabIndex = 10; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(8, 96); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(95, 13); + this.label3.TabIndex = 9; + this.label3.Text = "Time limit (minutes)"; + // + // forceStart + // + this.forceStart.AutoSize = true; + this.forceStart.Checked = true; + this.forceStart.CheckState = System.Windows.Forms.CheckState.Checked; + this.forceStart.Location = new System.Drawing.Point(12, 120); + this.forceStart.Name = "forceStart"; + this.forceStart.Size = new System.Drawing.Size(115, 17); + this.forceStart.TabIndex = 1; + this.forceStart.Text = "Ignore empty lobby"; + this.forceStart.UseVisualStyleBackColor = true; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(8, 69); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(64, 13); + this.label2.TabIndex = 9; + this.label2.Text = "Game mode"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(9, 15); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(57, 13); + this.label4.TabIndex = 8; + this.label4.Text = "Map name"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(8, 38); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 13); + this.label1.TabIndex = 8; + this.label1.Text = "Client limit"; + // + // nrOfClients + // + this.nrOfClients.Location = new System.Drawing.Point(78, 36); + this.nrOfClients.Maximum = new decimal(new int[] { + 20, + 0, + 0, + 0}); + this.nrOfClients.Minimum = new decimal(new int[] { + 2, + 0, + 0, + 0}); + this.nrOfClients.Name = "nrOfClients"; + this.nrOfClients.Size = new System.Drawing.Size(39, 20); + this.nrOfClients.TabIndex = 7; + this.nrOfClients.Value = new decimal(new int[] { + 10, + 0, + 0, + 0}); + // + // buttonStartGame + // + this.buttonStartGame.Location = new System.Drawing.Point(9, 176); + this.buttonStartGame.Name = "buttonStartGame"; + this.buttonStartGame.Size = new System.Drawing.Size(75, 23); + this.buttonStartGame.TabIndex = 6; + this.buttonStartGame.Text = "Start game"; + this.buttonStartGame.UseVisualStyleBackColor = true; + this.buttonStartGame.Click += new System.EventHandler(this.buttonStartGame_Click); + // // panel_clientArea // this.panel_clientArea.Controls.Add(this.ServerInfoTextArea); @@ -197,110 +319,14 @@ this.clientInfoBox.Size = new System.Drawing.Size(303, 147); this.clientInfoBox.TabIndex = 0; // - // buttonStartGame + // labelClientsConnected // - this.buttonStartGame.Location = new System.Drawing.Point(53, 195); - this.buttonStartGame.Name = "buttonStartGame"; - this.buttonStartGame.Size = new System.Drawing.Size(75, 23); - this.buttonStartGame.TabIndex = 6; - this.buttonStartGame.Text = "Start game"; - this.buttonStartGame.UseVisualStyleBackColor = true; - this.buttonStartGame.Click += new System.EventHandler(this.buttonStartGame_Click); - // - // nrOfClients - // - this.nrOfClients.Location = new System.Drawing.Point(78, 36); - this.nrOfClients.Maximum = new decimal(new int[] { - 20, - 0, - 0, - 0}); - this.nrOfClients.Minimum = new decimal(new int[] { - 2, - 0, - 0, - 0}); - this.nrOfClients.Name = "nrOfClients"; - this.nrOfClients.Size = new System.Drawing.Size(39, 20); - this.nrOfClients.TabIndex = 7; - this.nrOfClients.Value = new decimal(new int[] { - 2, - 0, - 0, - 0}); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(8, 38); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(53, 13); - this.label1.TabIndex = 8; - this.label1.Text = "Client limit"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(8, 69); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(64, 13); - this.label2.TabIndex = 9; - this.label2.Text = "Game mode"; - // - // gameModes - // - this.gameModes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.gameModes.FormattingEnabled = true; - this.gameModes.Items.AddRange(new object[] { - "Free-for-all", - "Team death-match"}); - this.gameModes.Location = new System.Drawing.Point(78, 66); - this.gameModes.Name = "gameModes"; - this.gameModes.Size = new System.Drawing.Size(99, 21); - this.gameModes.TabIndex = 10; - // - // timeLimit - // - this.timeLimit.Location = new System.Drawing.Point(109, 94); - this.timeLimit.Minimum = new decimal(new int[] { - 5, - 0, - 0, - 0}); - this.timeLimit.Name = "timeLimit"; - this.timeLimit.Size = new System.Drawing.Size(68, 20); - this.timeLimit.TabIndex = 11; - this.timeLimit.ThousandsSeparator = true; - this.timeLimit.Value = new decimal(new int[] { - 5, - 0, - 0, - 0}); - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(8, 96); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(95, 13); - this.label3.TabIndex = 9; - this.label3.Text = "Time limit (minutes)"; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(9, 15); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(57, 13); - this.label4.TabIndex = 8; - this.label4.Text = "Map name"; - // - // mapName - // - this.mapName.Location = new System.Drawing.Point(78, 7); - this.mapName.Name = "mapName"; - this.mapName.Size = new System.Drawing.Size(98, 20); - this.mapName.TabIndex = 12; + this.labelClientsConnected.AutoSize = true; + this.labelClientsConnected.Location = new System.Drawing.Point(9, 149); + this.labelClientsConnected.Name = "labelClientsConnected"; + this.labelClientsConnected.Size = new System.Drawing.Size(104, 13); + this.labelClientsConnected.TabIndex = 8; + this.labelClientsConnected.Text = "Clients connected: 0"; // // Form1 // @@ -312,14 +338,15 @@ this.Controls.Add(this.panel_serverOptions); this.Name = "Form1"; this.Text = "Form1"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClosingEvent); ((System.ComponentModel.ISupportInitialize)(this.listenPort)).EndInit(); this.panel_serverOptions.ResumeLayout(false); this.panel_serverOptions.PerformLayout(); this.panel_commands.ResumeLayout(false); this.panel_commands.PerformLayout(); - this.panel_clientArea.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.timeLimit)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit(); + this.panel_clientArea.ResumeLayout(false); this.ResumeLayout(false); } @@ -347,6 +374,8 @@ private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox mapName; + private System.Windows.Forms.CheckBox forceStart; + private System.Windows.Forms.Label labelClientsConnected; } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.cs index 1240c333..28a83c72 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.cs @@ -20,7 +20,7 @@ namespace StandAloneLauncher public Form1() { InitializeComponent(); - + this.gameModes.SelectedIndex = 0; } @@ -38,6 +38,7 @@ namespace StandAloneLauncher //Do some stuff this.gameServer.ServerUpdate(); + this.labelClientsConnected.Text = "Clients connected: " + this.gameServer.GetClientsConnectedCount().ToString(); } } @@ -89,7 +90,7 @@ namespace StandAloneLauncher this.gameServer.GameSetGameTime((int)this.timeLimit.Value); //this.gameServer.GameSetMapId(0); this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value); - if (!this.gameServer.GameStart()) + if (!this.gameServer.GameStart( this.forceStart.Checked )) { this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n"); } @@ -98,5 +99,13 @@ namespace StandAloneLauncher this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n"); } } + + private void FormClosingEvent(object sender, FormClosingEventArgs e) + { + if (serverIsRunning) + { + this.gameServer.ServerStop(); + } + } } } From 3f4038a12daebcc5bcd060b7404de17311a1528f Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 13:43:32 +0100 Subject: [PATCH 26/39] Backface change and enable render wireframe --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + Code/OysterGraphics/Render/Resources.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..96e2bbe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -197,6 +197,7 @@ namespace Oyster void API::StartRenderWireFrame() { Core::deviceContext->RSSetState(wire); + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); } void API::RenderDebugCube(Math::Matrix world) diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 514960cf..124b1bf1 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -338,8 +338,8 @@ namespace Oyster dTDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; dTDesc.CPUAccessFlags=0; dTDesc.MiscFlags=0; - dTDesc.Height = Core::resolution.y; - dTDesc.Width = Core::resolution.x; + dTDesc.Height = (UINT)Core::resolution.y; + dTDesc.Width = (UINT)Core::resolution.x; dTDesc.SampleDesc.Count=1; dTDesc.SampleDesc.Quality=0; From be8b7537b5e570569fc5a1e51b956e3b9e3b68e0 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 18 Feb 2014 13:47:40 +0100 Subject: [PATCH 27/39] GL - merging --- Code/Game/GameLogic/CollisionManager.cpp | 6 +++--- Code/Game/GameLogic/Game_LevelData.cpp | 4 +++- Code/Game/GameLogic/Game_PlayerData.cpp | 2 -- Code/Game/GameLogic/Level.cpp | 14 +++++++------- Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 4 ++-- .../GamePhysics/Implementation/SimpleRigidBody.cpp | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 0b817975..5d1a95ec 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -170,12 +170,12 @@ using namespace GameLogic; void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage) { - int damageDone = 0; - int forceThreashHold = 200000; + Oyster::Math::Float damageDone = 0; + Oyster::Math::Float forceThreashHold = 200000; if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough { - damageDone = (int)(kineticEnergyLoss * 0.10f); + damageDone = (kineticEnergyLoss * 0.10f); damageDone += ExtraDamage; //player.DamageLife(damageDone); } diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 80220d5f..e82a3834 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -54,8 +54,10 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const { - for(int i = 0; i < level->dynamicObjects.Size(); i++) + + for(int i = 0; i < (int)level->dynamicObjects.Size(); i++) { mem[i] = level->dynamicObjects[i]; } + } \ No newline at end of file diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 1b725b02..e7a77bbd 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -27,9 +27,7 @@ Game::PlayerData::PlayerData() } Game::PlayerData::PlayerData(int playerID,int teamID) { - Oyster::Physics::ICustomBody* rigidBody; this->player = new Player(); - } Game::PlayerData::~PlayerData() { diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 030f0eca..4d3cf703 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -63,9 +63,9 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_RedExplosiveBox: { - int dmg = 50; + Oyster::Math::Float dmg = 50; Oyster::Math::Float force = 50; - int radie = 50; + Oyster::Math::Float radie = 50; gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); } break; @@ -353,7 +353,7 @@ void Level::InitiateLevel(float radius) int offset = 0; for(int i =0; i< nrOfBoxex; i ++) { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); + rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); } @@ -385,16 +385,16 @@ void Level::InitiateLevel(float radius) }*/ // add crystal - ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); // add house - ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++)); // add jumppad - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); } @@ -419,7 +419,7 @@ int Level::getNrOfDynamicObj() } Object* Level::GetObj( int ID) const { - for (int i = 0; i < this->dynamicObjects.Size(); i++) + for (int i = 0; i < (int)this->dynamicObjects.Size(); i++) { if(this->dynamicObjects[i]->GetID() == ID) return this->dynamicObjects[i]; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index 826a52be..dfee72a7 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -119,7 +119,7 @@ namespace GameLogic int temp; - for(int i = 0; i < tempSize; i++) + for(int i = 0; i < (int)tempSize; i++) { memcpy(&temp, &buffer[start], 4); start += 4; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 79f34245..80969b29 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -90,7 +90,7 @@ void Player::BeginFrame() forwardDir.Normalize(); rightDir.Normalize(); Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); - Oyster::Math::Float walkSpeed = this->moveSpeed*0.2; + Oyster::Math::Float walkSpeed = this->moveSpeed*0.2f; if (key_forward > 0.001) { @@ -122,7 +122,7 @@ void Player::BeginFrame() if (key_forward <= 0.001 && key_backward <= 0.001 && key_strafeRight <= 0.001 && key_strafeLeft <= 0.001 && key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.7f) { /* Dampen when on the ground and not being moved by the player */ - linearVelocity *= 0.2; + linearVelocity *= 0.2f; this->rigidBody->SetLinearVelocity (linearVelocity); } else diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index f7cf6cce..4cdb282d 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -300,11 +300,11 @@ Float4x4 SimpleRigidBody::GetView( const ::Oyster::Math::Float3 &offset ) const Float3 SimpleRigidBody::GetGravity() const { - return this->rigidBody->getGravity(); + return (Float3)this->rigidBody->getGravity(); } Float3 SimpleRigidBody::GetLinearVelocity() const { - return this->rigidBody->getLinearVelocity(); + return (Float3)this->rigidBody->getLinearVelocity(); } From e72f2224be66a3c9fa02193107c23b1afdb568be Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 18 Feb 2014 14:09:18 +0100 Subject: [PATCH 28/39] Removed Misc\Misc from additionalDependencies. --- Code/Game/GameClient/GameClient.vcxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 0691fef1..8e2cfe69 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -111,7 +111,7 @@ Windows true - Misc\Misc_$(PlatformShortName)D.lib;WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -128,7 +128,7 @@ Windows true - Misc\Misc_$(PlatformShortName)D.lib;WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -149,7 +149,7 @@ true true true - Misc\Misc_$(PlatformShortName).lib;WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies) + WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies) NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs) @@ -170,7 +170,7 @@ true true true - Misc\Misc_$(PlatformShortName).lib;WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies) + WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies) NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs) From 86ef521abd7422d435fea25e290e20869af8f833 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 18 Feb 2014 14:10:12 +0100 Subject: [PATCH 29/39] LevelLoader - Added new CollisionGeometry_TriangleMesh. --- Code/Game/GameLogic/LevelLoader/ObjectDefines.h | 16 ++++++++++++++++ .../GameLogic/LevelLoader/ParseFunctions.cpp | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 01d17c3e..131b2938 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -52,6 +52,7 @@ namespace GameLogic CollisionGeometryType_Box, CollisionGeometryType_Sphere, CollisionGeometryType_Cylinder, + CollisionGeometryType_TriangleMesh, CollisionGeometryType_Count, CollisionGeometryType_Unknown = -1 @@ -161,6 +162,12 @@ namespace GameLogic float radius; }; + struct BoundingVolumeTriangleMesh : public BoundingVolumeBase + { + //Null terminated + wchar_t* filename; + }; + struct BoundingVolume { CollisionGeometryType geoType; @@ -169,7 +176,16 @@ namespace GameLogic LevelLoaderInternal::BoundingVolumeBox box; LevelLoaderInternal::BoundingVolumeSphere sphere; LevelLoaderInternal::BoundingVolumeCylinder cylinder; + LevelLoaderInternal::BoundingVolumeTriangleMesh triangleMesh; }; + + virtual ~BoundingVolume() + { + if(geoType == CollisionGeometryType_TriangleMesh) + { + delete[] triangleMesh.filename; + } + } }; } diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index dfee72a7..daa62752 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -175,6 +175,17 @@ namespace GameLogic start += sizeof(volume.cylinder); break; + case CollisionGeometryType_TriangleMesh: + //Get string size + memcpy(&tempSize, &buf[start], sizeof(tempSize)); + start += sizeof(tempSize); + + //Get actual string + volume.triangleMesh.filename = new wchar_t[tempSize+1]; + memcpy(volume.triangleMesh.filename, &buf[start], tempSize); + volume.triangleMesh.filename[tempSize] = '\0'; + break; + default: break; } From 3218e7b8470481ed2bb3605b6eda19c8fb0c70df Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 15:08:47 +0100 Subject: [PATCH 30/39] Connect to Dennis --- Code/Game/GameClient/GameClientState/LanMenuState.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 6d3d991b..11ca95da 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -60,7 +60,8 @@ bool LanMenuState::Init( SharedStateContent &shared ) // create guiElements this->privData->connectIP = new TextField( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); this->privData->connectIP->ReserveLines( 1 ); - this->privData->connectIP->AppendText( L"127.0.0.1" ); + //this->privData->connectIP->AppendText( L"127.0.0.1" ); + this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server this->privData->connectIP->SetFontHeight( 0.08f ); this->privData->connectIP->SetLineSpacing( 0.005f ); this->privData->connectIP->SetTopAligned(); From 996f66099054910769a7a2cbff25132055bbdd9a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 15:09:01 +0100 Subject: [PATCH 31/39] Fixes and bugtraps --- Code/Game/GameClient/GameClientState/GameState.cpp | 10 +++++++--- Code/Game/GameClient/GameClientState/NetLoadState.cpp | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7118191e..3576ae65 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -146,7 +146,8 @@ bool GameState::Render() auto dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - dynamicObject->second->Render(); + if( dynamicObject->second ) + dynamicObject->second->Render(); } Oyster::Graphics::API::EndFrame(); @@ -366,8 +367,11 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]; - object->setPos( position ); - object->setRot( rotation ); + if( object ) + { + object->setPos( position ); + object->setRot( rotation ); + } } break; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index d120cac2..9a88072c 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -101,13 +101,17 @@ void NetLoadState::DataRecieved( NetEventChangeState( ClientState_Game ); this->privData->loading = false; } + else + { // HACK: Debug trap + const char *breakPoint = "Being greedy."; + } } void NetLoadState::LoadGame( const ::std::string &fileName ) { this->privData->loading = true; - LevelLoader loader; + LevelLoader loader( "..\\Content\\Worlds\\" ); auto objects = loader.LoadLevel( fileName ); auto object = objects.begin(); ObjectTypeHeader *oth; From 22f9daf0d8d03c5ce74f92903abecdc7a0a7a890 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 16:38:08 +0100 Subject: [PATCH 32/39] Connection between server and client is stable --- Code/Game/GameLogic/Game_LevelData.cpp | 1 + Code/Game/GameServer/GameClient.h | 13 +++- Code/Game/GameServer/GameLobby.h | 3 + .../GameServer/Implementation/GameClient.cpp | 11 ++- .../GameServer/Implementation/GameLobby.cpp | 14 ++-- .../GameLobby_ProtocolParser.cpp | 71 +++++++++++++------ .../Implementation/GameSession_Gameplay.cpp | 4 +- .../Implementation/GameSession_General.cpp | 12 ++-- .../StandAloneLauncher/Form1.Designer.cs | 63 +++++++++------- .../LanServer/StandAloneLauncher/Form1.cs | 10 +-- .../Utilities/Resource/OResourceHandler.cpp | 2 + Code/Network/NetworkAPI/NetworkClient.cpp | 4 ++ 12 files changed, 141 insertions(+), 67 deletions(-) diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 80220d5f..62fb3cc5 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -54,6 +54,7 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const { + mem.Resize(level->dynamicObjects.Size()); for(int i = 0; i < level->dynamicObjects.Size(); i++) { mem[i] = level->dynamicObjects[i]; diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index 422df933..6fcf6b05 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -17,6 +17,13 @@ namespace DanBias */ class GameClient { + public: + enum ClientState + { + ClientState_CreatingGame, + ClientState_Ready, + }; + public: GameClient(Utility::DynamicMemory::SmartPointer nwClient); virtual~GameClient(); @@ -33,6 +40,7 @@ namespace DanBias inline bool IsReady() const { return this->isReady; } inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } Oyster::Network::NetClient GetClient() const { return this->client; } + ClientState GetState() const { return this->state; } void SetPlayer(GameLogic::IPlayerData* player); @@ -40,6 +48,7 @@ namespace DanBias void SetAlias(std::wstring alias); void SetCharacter(std::wstring character); void SetSinceLastResponse(float seconds); + void SetState(ClientState state); GameLogic::IPlayerData* ReleasePlayer(); Oyster::Network::NetClient ReleaseClient(); @@ -50,13 +59,15 @@ namespace DanBias private: GameLogic::IPlayerData* player; - Utility::DynamicMemory::SmartPointer client; + Oyster::Network::NetClient client; bool isReady; float secondsSinceLastResponse; std::wstring alias; std::wstring character; + + ClientState state; }; }//End namespace DanBias diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index 7b9a46d7..f62baa63 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -58,6 +58,9 @@ namespace DanBias void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: + private: + int FindClient(Oyster::Network::NetworkClient* c); + private: void ClientEventCallback(Oyster::Network::NetEvent e) override; void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) override; diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 7ef4a338..81066450 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -50,6 +50,10 @@ void GameClient::SetCharacter(std::wstring character) { this->character = character; } +void GameClient::SetState(ClientState state) +{ + this->state = state; +} void GameClient::SetOwner(Oyster::Network::NetworkSession* owner) @@ -58,7 +62,12 @@ void GameClient::SetOwner(Oyster::Network::NetworkSession* owner) } void GameClient::UpdateClient() { - this->client->Update(); + switch (this->state) + { + case ClientState_Ready: + this->client->Update(); + break; + } } diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index b95402e2..cadfa53a 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -17,7 +17,7 @@ GameLobby::GameLobby() { } GameLobby::~GameLobby() { - this->clients.Clear(); + this->gClients.Clear(); } void GameLobby::Release() { @@ -26,11 +26,11 @@ void GameLobby::Release() } void GameLobby::Update() { - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { - this->clients[i]->Update(); + this->gClients[i]->GetClient()->Update(); } } } @@ -119,7 +119,7 @@ void GameLobby::ClientEventCallback(NetEventGetID(), e.sender->GetIpAddress().c_str()); - e.sender->Disconnect(); + //e.sender->Disconnect(); //this->readyList.Remove(e.sender); //this->gClients.Remove(e.sender); break; @@ -184,7 +184,9 @@ void GameLobby::ProcessClients() } bool GameLobby::Attach(Utility::DynamicMemory::SmartPointer client) { - if(this->clientCount = this->description.maxClients) return false; + if(this->clientCount == this->description.maxClients) return false; + + client->SetOwner(this); bool added = false; for (unsigned int i = 0; i < this->gClients.Size(); i++) diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index ebcfb8bf..2c4f148a 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -40,26 +40,46 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net { case Protocol_General_Status::States_ready: { - + int temp = FindClient(c); + if(temp != -1 ) + { + switch (this->gClients[temp]->GetState()) + { + case GameClient::ClientState_CreatingGame: + { + this->gameSession.Join(this->gClients[temp]); + this->gClients[temp] = 0; + } + break; + } + } + else + { + c->Disconnect(); + } } + break; case Protocol_General_Status::States_idle: { } + break; case Protocol_General_Status::States_leave: + break; case Protocol_General_Status::States_disconected: { Detach(c)->Disconnect(); } + break; } } void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c) { - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { - this->clients[i]->Send(p); + this->gClients[i]->GetClient()->Send(p); } } printf(p.text.c_str()); @@ -69,9 +89,9 @@ void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Ne if(this->sessionOwner->GetClient()->GetID() == c->GetID()) { //Send countdown timer before lobby shuts down - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - this->clients[i]->Send(Protocol_LobbyStartGame(3.0f)); + this->gClients[i]->GetClient()->Send(Protocol_LobbyStartGame(3.0f)); } } else @@ -118,32 +138,41 @@ void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyste { if(this->gameSession) { - gClient temp; - bool found = false; - - //find client in waiting list - for (unsigned int i = 0; !found && i < this->clients.Size(); i++) - { - if(this->gClients[i]->GetClient()->GetID() == c->GetID()) - { - temp = this->gClients[i]; - found = true; - } - } + int temp = FindClient(c); //Something is wrong - if(!found) + if(temp == -1) { c->Disconnect(); } else { //Send game data - this->gameSession.Join(temp); + Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); + c->Send(lcg); + this->gClients[temp]->SetState(GameClient::ClientState_CreatingGame); } } else { - + // Nothing.- } } + + +int GameLobby::FindClient(Oyster::Network::NetworkClient* c) +{ + int temp = -1; + + //find client in waiting list + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]->GetClient()->GetID() == c->GetID()) + { + temp = i; + break; + } + } + + return temp; +} \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 61ccf9c8..6a9c09c2 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -45,7 +45,7 @@ using namespace DanBias; //Find the idiot for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->gClients[i]->Equals(e.sender)) + if(this->gClients[i] && this->gClients[i]->Equals(e.sender)) { temp = i; } @@ -78,7 +78,7 @@ using namespace DanBias; { for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->gClients[i]) + if(this->gClients[i] ) { this->gClients[i]->UpdateClient(); } diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 07d2dcd4..8b5bd8cb 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -199,18 +199,12 @@ bool GameSession::Join(gClient gameClient) gameClient->SetPlayer(playerData); NetworkClient* nwClient = gameClient->GetClient(); - -// Send the level information - { - Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); - nwClient->Send(lcg); - } // Send the player data only { Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(), playerData->GetID(), true, playerData->GetTeamID(), - /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); nwClient->Send(oc); } @@ -223,7 +217,7 @@ bool GameSession::Join(gClient gameClient) IPlayerData* temp = this->gClients[i]->GetPlayer(); Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), temp->GetID(), false, temp->GetTeamID(), - /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); nwClient->Send(oc); } } @@ -259,6 +253,8 @@ bool GameSession::Join(gClient gameClient) } } + gameClient->SetState(GameClient::ClientState_Ready); + return added; } diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs index 103a047f..bd168c3c 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs @@ -43,6 +43,7 @@ this.forceStart = new System.Windows.Forms.CheckBox(); this.label2 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); + this.labelClientsConnected = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.nrOfClients = new System.Windows.Forms.NumericUpDown(); this.buttonStartGame = new System.Windows.Forms.Button(); @@ -50,13 +51,14 @@ this.ServerInfoTextArea = new System.Windows.Forms.RichTextBox(); this.splitter1 = new System.Windows.Forms.Splitter(); this.clientInfoBox = new System.Windows.Forms.ListBox(); - this.labelClientsConnected = new System.Windows.Forms.Label(); + this.panel_CommanArea = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.listenPort)).BeginInit(); this.panel_serverOptions.SuspendLayout(); this.panel_commands.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.timeLimit)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit(); this.panel_clientArea.SuspendLayout(); + this.panel_CommanArea.SuspendLayout(); this.SuspendLayout(); // // serverToggle @@ -135,9 +137,10 @@ this.panel_serverOptions.Controls.Add(this.label_listenPort); this.panel_serverOptions.Controls.Add(this.lanBroadcast); this.panel_serverOptions.Controls.Add(this.label_serverName); - this.panel_serverOptions.Location = new System.Drawing.Point(12, 12); + this.panel_serverOptions.Dock = System.Windows.Forms.DockStyle.Top; + this.panel_serverOptions.Location = new System.Drawing.Point(0, 0); this.panel_serverOptions.Name = "panel_serverOptions"; - this.panel_serverOptions.Size = new System.Drawing.Size(183, 141); + this.panel_serverOptions.Size = new System.Drawing.Size(200, 141); this.panel_serverOptions.TabIndex = 6; // // panel_commands @@ -153,19 +156,19 @@ this.panel_commands.Controls.Add(this.label1); this.panel_commands.Controls.Add(this.nrOfClients); this.panel_commands.Controls.Add(this.buttonStartGame); - this.panel_commands.Location = new System.Drawing.Point(12, 159); + this.panel_commands.Location = new System.Drawing.Point(3, 150); this.panel_commands.Name = "panel_commands"; - this.panel_commands.Size = new System.Drawing.Size(183, 202); + this.panel_commands.Size = new System.Drawing.Size(191, 202); this.panel_commands.TabIndex = 7; this.panel_commands.Visible = false; // // mapName // - this.mapName.Location = new System.Drawing.Point(78, 7); + this.mapName.Location = new System.Drawing.Point(75, 10); this.mapName.Name = "mapName"; - this.mapName.Size = new System.Drawing.Size(98, 20); + this.mapName.Size = new System.Drawing.Size(113, 20); this.mapName.TabIndex = 12; - this.mapName.Text = "Unknown"; + this.mapName.Text = "2ofAll_updated.bias"; // // timeLimit // @@ -194,7 +197,7 @@ "Team death-match"}); this.gameModes.Location = new System.Drawing.Point(78, 66); this.gameModes.Name = "gameModes"; - this.gameModes.Size = new System.Drawing.Size(99, 21); + this.gameModes.Size = new System.Drawing.Size(110, 21); this.gameModes.TabIndex = 10; // // label3 @@ -236,6 +239,15 @@ this.label4.TabIndex = 8; this.label4.Text = "Map name"; // + // labelClientsConnected + // + this.labelClientsConnected.AutoSize = true; + this.labelClientsConnected.Location = new System.Drawing.Point(9, 149); + this.labelClientsConnected.Name = "labelClientsConnected"; + this.labelClientsConnected.Size = new System.Drawing.Size(104, 13); + this.labelClientsConnected.TabIndex = 8; + this.labelClientsConnected.Text = "Clients connected: 0"; + // // label1 // this.label1.AutoSize = true; @@ -282,9 +294,10 @@ this.panel_clientArea.Controls.Add(this.ServerInfoTextArea); this.panel_clientArea.Controls.Add(this.splitter1); this.panel_clientArea.Controls.Add(this.clientInfoBox); - this.panel_clientArea.Location = new System.Drawing.Point(202, 12); + this.panel_clientArea.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel_clientArea.Location = new System.Drawing.Point(200, 0); this.panel_clientArea.Name = "panel_clientArea"; - this.panel_clientArea.Size = new System.Drawing.Size(303, 349); + this.panel_clientArea.Size = new System.Drawing.Size(535, 616); this.panel_clientArea.TabIndex = 8; // // ServerInfoTextArea @@ -297,7 +310,7 @@ this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 152); this.ServerInfoTextArea.Name = "ServerInfoTextArea"; this.ServerInfoTextArea.ReadOnly = true; - this.ServerInfoTextArea.Size = new System.Drawing.Size(303, 197); + this.ServerInfoTextArea.Size = new System.Drawing.Size(535, 464); this.ServerInfoTextArea.TabIndex = 1; this.ServerInfoTextArea.Text = ""; // @@ -306,7 +319,7 @@ this.splitter1.Dock = System.Windows.Forms.DockStyle.Top; this.splitter1.Location = new System.Drawing.Point(0, 147); this.splitter1.Name = "splitter1"; - this.splitter1.Size = new System.Drawing.Size(303, 5); + this.splitter1.Size = new System.Drawing.Size(535, 5); this.splitter1.TabIndex = 2; this.splitter1.TabStop = false; // @@ -316,26 +329,26 @@ this.clientInfoBox.FormattingEnabled = true; this.clientInfoBox.Location = new System.Drawing.Point(0, 0); this.clientInfoBox.Name = "clientInfoBox"; - this.clientInfoBox.Size = new System.Drawing.Size(303, 147); + this.clientInfoBox.Size = new System.Drawing.Size(535, 147); this.clientInfoBox.TabIndex = 0; // - // labelClientsConnected + // panel_CommanArea // - this.labelClientsConnected.AutoSize = true; - this.labelClientsConnected.Location = new System.Drawing.Point(9, 149); - this.labelClientsConnected.Name = "labelClientsConnected"; - this.labelClientsConnected.Size = new System.Drawing.Size(104, 13); - this.labelClientsConnected.TabIndex = 8; - this.labelClientsConnected.Text = "Clients connected: 0"; + this.panel_CommanArea.Controls.Add(this.panel_commands); + this.panel_CommanArea.Controls.Add(this.panel_serverOptions); + this.panel_CommanArea.Dock = System.Windows.Forms.DockStyle.Left; + this.panel_CommanArea.Location = new System.Drawing.Point(0, 0); + this.panel_CommanArea.Name = "panel_CommanArea"; + this.panel_CommanArea.Size = new System.Drawing.Size(200, 616); + this.panel_CommanArea.TabIndex = 9; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(517, 373); + this.ClientSize = new System.Drawing.Size(735, 616); this.Controls.Add(this.panel_clientArea); - this.Controls.Add(this.panel_commands); - this.Controls.Add(this.panel_serverOptions); + this.Controls.Add(this.panel_CommanArea); this.Name = "Form1"; this.Text = "Form1"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClosingEvent); @@ -347,6 +360,7 @@ ((System.ComponentModel.ISupportInitialize)(this.timeLimit)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit(); this.panel_clientArea.ResumeLayout(false); + this.panel_CommanArea.ResumeLayout(false); this.ResumeLayout(false); } @@ -376,6 +390,7 @@ private System.Windows.Forms.TextBox mapName; private System.Windows.Forms.CheckBox forceStart; private System.Windows.Forms.Label labelClientsConnected; + private System.Windows.Forms.Panel panel_CommanArea; } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.cs index 28a83c72..58deb2a9 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Interop; using System.Runtime.InteropServices; +using System.Threading; +using System.Timers; namespace StandAloneLauncher { @@ -30,18 +32,17 @@ namespace StandAloneLauncher return true; } + public void Run() { while (this.Created) { Application.DoEvents(); - - //Do some stuff this.gameServer.ServerUpdate(); this.labelClientsConnected.Text = "Clients connected: " + this.gameServer.GetClientsConnectedCount().ToString(); } } - + private void button1_serverToggle_Click(object sender, EventArgs e) { if (this.serverIsRunning) @@ -88,8 +89,9 @@ namespace StandAloneLauncher { //this.gameServer.GameSetGameMode(this.gameModes.SelectedText); this.gameServer.GameSetGameTime((int)this.timeLimit.Value); - //this.gameServer.GameSetMapId(0); + this.gameServer.GameSetMapName(this.mapName.Text); this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value); + if (!this.gameServer.GameStart( this.forceStart.Checked )) { this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n"); diff --git a/Code/Misc/Utilities/Resource/OResourceHandler.cpp b/Code/Misc/Utilities/Resource/OResourceHandler.cpp index 52d93af0..cc297f67 100644 --- a/Code/Misc/Utilities/Resource/OResourceHandler.cpp +++ b/Code/Misc/Utilities/Resource/OResourceHandler.cpp @@ -52,6 +52,8 @@ OHRESOURCE OysterResource::LoadResource(const wchar_t* filename, ResourceType ty } } + if(!resourceData) return 0; + return resourceData->GetResourceHandle(); } OHRESOURCE OysterResource::LoadResource(const wchar_t filename[], CustomLoadFunction loadFnc, int customId, bool force) diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 96d149f3..69872fc1 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -96,6 +96,10 @@ struct NetworkClient::PrivateData : public IThreadObject //printf("\t(%i)\n", this->sendQueue.Size()); OysterByte temp; CustomNetProtocol p = this->sendQueue.Pop(); + + if(p[0].value.netShort == 304) + int i = 0; + this->translator.Pack(temp, p); errorCode = this->connection.Send(temp); From a6f740e1f80dec8fb096a0e959fa00ac46933e69 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 16:44:38 +0100 Subject: [PATCH 33/39] bunch of stuff --- Code/Game/GameClient/GameClientState/GameState.cpp | 9 ++++++++- Code/Game/GameClient/GameClientState/LanMenuState.cpp | 10 ++++++++++ Code/Game/GameClient/GameClientState/LanMenuState.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 3576ae65..9a0bd4db 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -314,9 +314,16 @@ void GameState::ReadKeyInput() void GameState::DataRecieved( NetEvent e ) { + if( e.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) + { // TODO: Reconnect + const char *breakpoint = "temp trap"; + this->privData->nwClient->Disconnect(); + this->ChangeState( GameClientState::ClientState_Main ); + } + CustomNetProtocol data = e.args.data.protocol; short ID = data[0].value.netShort; // fetching the id data. - + if( ProtocolIsGameplay(ID) ) { switch(ID) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 11ca95da..178739d3 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -133,6 +133,16 @@ void LanMenuState::ChangeState( ClientState next ) this->privData->nextState = next; } +void LanMenuState::DataRecieved( NetEvent e ) +{ + if( e.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) + { // TODO: Reconnect + const char *breakpoint = "temp trap"; + this->privData->nwClient->Disconnect(); + this->ChangeState( GameClientState::ClientState_Same ); + } +} + void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ) { switch( e.state ) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.h b/Code/Game/GameClient/GameClientState/LanMenuState.h index 57889eee..9c6a8ec4 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.h +++ b/Code/Game/GameClient/GameClientState/LanMenuState.h @@ -21,6 +21,8 @@ namespace DanBias virtual bool Release(); void ChangeState( ClientState next ); + void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; From 02b467be18e6ded0dbbb7bfa32cee89ae97bb923 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 17:04:27 +0100 Subject: [PATCH 34/39] const related edits in CustomNetProtocol Should be none impact besides positive ones --- Code/Network/NetworkAPI/CustomNetProtocol.cpp | 23 +++++++++++++++++-- Code/Network/NetworkAPI/CustomNetProtocol.h | 8 ++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index ecb57bf9..90fb100d 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -40,12 +40,13 @@ CustomNetProtocol::CustomNetProtocol() { this->privateData = new PrivateData(); } -CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o) +CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) { this->privateData = new PrivateData(); this->privateData->attributes = o.privateData->attributes; } -const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o) + +CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o) { if(this->privateData) { @@ -56,11 +57,29 @@ const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o) this->privateData->attributes = o.privateData->attributes; return *this; } + CustomNetProtocol::~CustomNetProtocol() { delete this->privateData; this->privateData = 0; } + +const NetAttributeContainer& CustomNetProtocol::operator[](int ID) const +{ + //if(!this->privateData) this->privateData = new PrivateData(); + if((unsigned int)ID >= this->privateData->attributes.Size()) + { + NetAttributeContainer temp; + + temp.type = NetAttributeType_UNKNOWN; + memset(&temp.value, 0, sizeof(NetAttributeValue)); + + this->privateData->attributes.Push(ID, temp); + } + + return this->privateData->attributes[ID]; +} + NetAttributeContainer& CustomNetProtocol::operator[](int ID) { //if(!this->privateData) this->privateData = new PrivateData(); diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index 48feb3a9..24df6ebf 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -130,10 +130,12 @@ namespace Oyster public: CustomNetProtocol(); ~CustomNetProtocol(); - CustomNetProtocol(CustomNetProtocol& o); - const CustomNetProtocol& operator=(CustomNetProtocol& o); + CustomNetProtocol( const CustomNetProtocol& o); + CustomNetProtocol& operator=(const CustomNetProtocol& o); + + const NetAttributeContainer& operator[](int ID) const; + NetAttributeContainer& operator[](int ID); - NetAttributeContainer& operator[](int ID); void Set(int id, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type); void Set(int ID, std::string s); const NetAttributeContainer& Get(int id); From a85b803e5cbfea72144ea478db457c560fb092ae Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 17:28:24 +0100 Subject: [PATCH 35/39] GameClientState Patch virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); changed to virtual const NetEvent & DataRecieved( const NetEvent &message ); /****************************************************************** * @param message of the event * @return message or GameClientState::event_processed. ******************************************************************/ --- .../GameClientState/GameClientState.cpp | 9 +++++-- .../GameClientState/GameClientState.h | 10 +++++-- .../GameClient/GameClientState/GameState.cpp | 26 +++++++++++-------- .../GameClient/GameClientState/GameState.h | 2 +- .../GameClientState/LanMenuState.cpp | 10 ------- .../GameClient/GameClientState/LanMenuState.h | 2 -- .../GameClientState/LobbyAdminState.cpp | 7 ++--- .../GameClientState/LobbyAdminState.h | 4 +-- .../GameClient/GameClientState/LobbyState.cpp | 8 +++--- .../GameClient/GameClientState/LobbyState.h | 2 +- .../GameClientState/NetLoadState.cpp | 17 +++++++----- .../GameClient/GameClientState/NetLoadState.h | 2 +- 12 files changed, 55 insertions(+), 44 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameClientState.cpp b/Code/Game/GameClient/GameClientState/GameClientState.cpp index dab88b2e..add8c15b 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.cpp +++ b/Code/Game/GameClient/GameClientState/GameClientState.cpp @@ -3,9 +3,14 @@ using namespace DanBias::Client; using namespace ::Oyster::Network; +const GameClientState::NetEvent GameClientState::event_processed = GameClientState::NetEvent(); + GameClientState::GameClientState() {} GameClientState::~GameClientState() {} -void GameClientState::DataRecieved( NetEvent e ) -{ /* do nothing */ } \ No newline at end of file +const GameClientState::NetEvent & GameClientState::DataRecieved( const GameClientState::NetEvent &message ) +{ + /* do nothing */ + return message; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 3822c7b0..9891a16c 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -22,7 +22,9 @@ namespace DanBias { namespace Client ClientState_Quit }; - public: + typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent; + static const NetEvent event_processed; + GameClientState(); virtual ~GameClientState(); virtual bool Init( SharedStateContent &shared ) = 0; @@ -31,7 +33,11 @@ namespace DanBias { namespace Client virtual bool Release() = 0; virtual void ChangeState( ClientState next ) = 0; - virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + /****************************************************************** + * @param message of the event + * @return message or GameClientState::event_processed. + ******************************************************************/ + virtual const NetEvent & DataRecieved( const NetEvent &message ); }; } } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 9a0bd4db..c6d77f76 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -312,20 +312,22 @@ void GameState::ReadKeyInput() // TODO: implement sub-menu } -void GameState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { - if( e.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) + if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) { // TODO: Reconnect const char *breakpoint = "temp trap"; this->privData->nwClient->Disconnect(); this->ChangeState( GameClientState::ClientState_Main ); } - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; if( ProtocolIsGameplay(ID) ) { + CustomNetProtocol data = message.args.data.protocol; + switch(ID) { case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ @@ -341,13 +343,13 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: { Protocol_ObjectRotation decoded(data); @@ -359,7 +361,7 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: { Protocol_ObjectPositionRotation decoded(data); @@ -380,7 +382,7 @@ void GameState::DataRecieved( NetEventsetRot( rotation ); } } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDisabled: { @@ -393,7 +395,7 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects->erase( object ); } } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectCreate: { Protocol_ObjectCreate decoded(data); @@ -414,13 +416,13 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID] = object; } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectCreatePlayer: { Protocol_ObjectCreatePlayer decoded(data); this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ @@ -439,4 +441,6 @@ void GameState::DataRecieved( NetEvent e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 178739d3..11ca95da 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -133,16 +133,6 @@ void LanMenuState::ChangeState( ClientState next ) this->privData->nextState = next; } -void LanMenuState::DataRecieved( NetEvent e ) -{ - if( e.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) - { // TODO: Reconnect - const char *breakpoint = "temp trap"; - this->privData->nwClient->Disconnect(); - this->ChangeState( GameClientState::ClientState_Same ); - } -} - void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ) { switch( e.state ) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.h b/Code/Game/GameClient/GameClientState/LanMenuState.h index 9c6a8ec4..57889eee 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.h +++ b/Code/Game/GameClient/GameClientState/LanMenuState.h @@ -21,8 +21,6 @@ namespace DanBias virtual bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); - private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index 070d8b48..43419e88 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -112,10 +112,10 @@ void LobbyAdminState::ChangeState( ClientState next ) using namespace ::Oyster::Network; -void LobbyAdminState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & LobbyAdminState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; // Block irrelevant messages. if( ProtocolIsLobby(ID) ) @@ -141,6 +141,7 @@ void LobbyAdminState::DataRecieved( NetEvent& e ) diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.h b/Code/Game/GameClient/GameClientState/LobbyAdminState.h index 49ae9274..7e201e94 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.h +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.h @@ -29,8 +29,8 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); - + const NetEvent & DataRecieved( const NetEvent &message ); + private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index a6d03527..0b117016 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -112,10 +112,10 @@ void LobbyState::ChangeState( ClientState next ) using namespace ::Oyster::Network; -void LobbyState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & LobbyState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; // Block irrelevant messages. if( ProtocolIsLobby(ID) ) @@ -141,6 +141,8 @@ void LobbyState::DataRecieved( NetEvent& e ) diff --git a/Code/Game/GameClient/GameClientState/LobbyState.h b/Code/Game/GameClient/GameClientState/LobbyState.h index 694aaa38..496c54ed 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.h +++ b/Code/Game/GameClient/GameClientState/LobbyState.h @@ -31,7 +31,7 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 9a88072c..29906d77 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -90,20 +90,25 @@ void NetLoadState::ChangeState( ClientState next ) this->privData->nextState = next; } -void NetLoadState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & NetLoadState::DataRecieved( const GameClientState::NetEvent &message ) { // fetching the id data. - short ID = e.args.data.protocol[0].value.netShort; + short ID = message.args.data.protocol[0].value.netShort; - if( ID == protocol_Lobby_CreateGame && !this->privData->loading ) + if( ID == protocol_Lobby_CreateGame ) { - this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName ); - this->ChangeState( ClientState_Game ); - this->privData->loading = false; + if( !this->privData->loading ) + { + this->LoadGame( Protocol_LobbyCreateGame(message.args.data.protocol).mapName ); + this->ChangeState( ClientState_Game ); + this->privData->loading = false; + } + return GameClientState::event_processed; } else { // HACK: Debug trap const char *breakPoint = "Being greedy."; + return message; } } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.h b/Code/Game/GameClient/GameClientState/NetLoadState.h index ea9f9f6a..16e32867 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.h +++ b/Code/Game/GameClient/GameClientState/NetLoadState.h @@ -21,7 +21,7 @@ namespace DanBias bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; From 00fe2e6aa74a7d3f308040cb172764231f18bc2b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 17:42:00 +0100 Subject: [PATCH 36/39] Camera swap Trying the quaternion based one instead --- Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp | 10 +++++++--- Code/Game/GameClient/GameClientState/Camera_FPSV2.h | 1 + Code/Game/GameClient/GameClientState/GameState.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp index b1863242..12506d3c 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -36,11 +36,15 @@ void Camera_FPSV2::SetPosition( const Float3 &translation ) this->body.translation = translation; } +void Camera_FPSV2::SetRotation( const Quaternion &rotation ) +{ + this->body.rotation = rotation; + this->head.SetRotation( rotation * Rotation(this->pitchUp, this->GetNormalOf(Float3::standard_unit_x) ) ); +} + void Camera_FPSV2::SetAngular( const Float3 &axis ) { - this->body.rotation = Rotation( axis ); - this->head.SetRotation( this->body.rotation ); - this->pitchUp = 0.0f; + this->SetRotation( Rotation(axis) ); } void Camera_FPSV2::SetProjection( const Float4x4 &matrix ) diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h index 968053c7..7f66b185 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h @@ -14,6 +14,7 @@ public: void SetHeadOffset( const ::Oyster::Math::Float3 &translation ); void SetPosition( const ::Oyster::Math::Float3 &translation ); + void SetRotation( const ::Oyster::Math::Quaternion &rotation ); void SetAngular( const ::Oyster::Math::Float3 &axis ); void SetProjection( const ::Oyster::Math::Float4x4 &matrix ); void SetOrthographicProjection( ::Oyster::Math::Float width, ::Oyster::Math::Float height, ::Oyster::Math::Float nearClip, ::Oyster::Math::Float farClip ); diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index c6d77f76..bfd15532 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -2,7 +2,7 @@ #include "DllInterfaces/GFXAPI.h" #include #include "NetworkClient.h" -#include "Camera_FPS.h" +#include "Camera_FPSV2.h" #include #include "C_obj/C_Player.h" @@ -39,7 +39,7 @@ struct GameState::MyData bool key_Reload_Shaders; C_Player player; - Camera_FPS camera; + Camera_FPSV2 camera; int myId; @@ -357,7 +357,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState // if is this player. Remember to change camera if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetAngular( AngularAxis(rotation) ); + this->privData->camera.SetRotation( rotation ); (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); } @@ -372,7 +372,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState if( this->privData->myId == decoded.object_ID ) { this->privData->camera.SetPosition( position ); - this->privData->camera.SetAngular( AngularAxis(rotation) ); + this->privData->camera.SetRotation( rotation ); } C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; From 8a0dbe969c15cefa47d20d9bfacabac9c27788fc Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 18 Feb 2014 21:24:21 +0100 Subject: [PATCH 37/39] GameLogic - Added filename to paramater when initiating a level, Also changed some string to wstrings --- Code/Game/GameLogic/Game.cpp | 6 ++---- Code/Game/GameLogic/Game.h | 2 +- Code/Game/GameLogic/GameAPI.h | 2 +- Code/Game/GameLogic/Level.cpp | 2 +- Code/Game/GameLogic/Level.h | 2 +- Code/Game/GameLogic/LevelLoader/LevelLoader.cpp | 16 ++++++++-------- Code/Game/GameLogic/LevelLoader/LevelLoader.h | 10 +++++----- Code/Game/GameLogic/LevelLoader/LevelParser.cpp | 10 ++++++++-- Code/Game/GameLogic/LevelLoader/LevelParser.h | 4 ++-- Code/Game/GameLogic/LevelLoader/Loader.cpp | 6 +++--- Code/Game/GameLogic/LevelLoader/Loader.h | 2 +- .../GameLogic/LevelLoader/ParseFunctions.cpp | 3 ++- 12 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 900799e3..ba294349 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -76,14 +76,12 @@ Game::PlayerData* Game::CreatePlayer() return this->players[i]; } -Game::LevelData* Game::CreateLevel() +Game::LevelData* Game::CreateLevel(const wchar_t mapName[255]) { if(this->level) return this->level; this->level = new LevelData(); - //this->level->level->InitiateLevel(1000); - this->level->level->InitiateLevel("../Content/Worlds/ccc.bias"); - + this->level->level->InitiateLevel(mapName); return this->level; } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 9c21ec1b..6623756f 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -72,7 +72,7 @@ namespace GameLogic void GetAllPlayerPositions() const override; PlayerData* CreatePlayer() override; - LevelData* CreateLevel() override; + LevelData* CreateLevel(const wchar_t mapName[255] ) override; void CreateTeam() override; bool NewFrame() override; void SetFPS( int FPS ) override; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 3325115f..65d606d8 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -139,7 +139,7 @@ namespace GameLogic /** Creates a level * @return Returns a ILevelData container to use for level manipulation */ - virtual ILevelData* CreateLevel( void ) = 0; + virtual ILevelData* CreateLevel( const wchar_t mapName[255] ) = 0; /** Creates a team * @return ? diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 4d3cf703..3c289766 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -197,7 +197,7 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic); return rigidBody; } -void Level::InitiateLevel(std::string levelPath) +void Level::InitiateLevel(std::wstring levelPath) { LevelLoader ll; std::vector> objects; diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 623d04b2..18d650e8 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -30,7 +30,7 @@ namespace GameLogic * Initiates a level for players to play on * @param levelPath: Path to a file that contains all information on the level ********************************************************/ - void InitiateLevel(std::string levelPath); + void InitiateLevel(std::wstring levelPath); void InitiateLevel(float radius); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index 8fe880f3..205da712 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -11,17 +11,17 @@ using namespace GameLogic::LevelFileLoader; struct LevelLoader::PrivData { LevelParser parser; - std::string folderPath; + std::wstring folderPath; }; LevelLoader::LevelLoader() : pData(new PrivData) { //standard path - pData->folderPath = ""; + pData->folderPath = L""; } -LevelLoader::LevelLoader(std::string folderPath) +LevelLoader::LevelLoader(std::wstring folderPath) : pData(new PrivData) { pData->folderPath = folderPath; @@ -31,22 +31,22 @@ LevelLoader::~LevelLoader() { } -std::vector> LevelLoader::LoadLevel(std::string fileName) +std::vector> LevelLoader::LoadLevel(std::wstring fileName) { return pData->parser.Parse(pData->folderPath + fileName); } -LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) +LevelMetaData LevelLoader::LoadLevelHeader(std::wstring fileName) { return pData->parser.ParseHeader(pData->folderPath + fileName); } -std::string LevelLoader::GetFolderPath() +std::wstring LevelLoader::GetFolderPath() { return this->pData->folderPath; } -void LevelLoader::SetFolderPath(std::string folderPath) +void LevelLoader::SetFolderPath(std::wstring folderPath) { - + this->pData->folderPath = folderPath; } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h index aa67c4f5..c14e2c4c 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -20,7 +20,7 @@ namespace GameLogic /*********************************************************** * Lets you set the standard folderpath for the levels ********************************************************/ - LevelLoader(std::string folderPath); + LevelLoader(std::wstring folderPath); ~LevelLoader(); /******************************************************** @@ -28,24 +28,24 @@ namespace GameLogic * @param fileName: Path/name to the level-file that you want to load. * @return: Returns all structs with objects and information about the level. ********************************************************/ - std::vector> LoadLevel(std::string fileName); + std::vector> LoadLevel(std::wstring fileName); /******************************************************** * Just for fast access for the meta information about the level. * @param fileName: Path to the level-file that you want to load. * @return: Returns the meta information about the level. ********************************************************/ - LevelMetaData LoadLevelHeader(std::string fileName); //. + LevelMetaData LoadLevelHeader(std::wstring fileName); //. /*********************************************************** * @return: Returns the current standard folder path ********************************************************/ - std::string GetFolderPath(); + std::wstring GetFolderPath(); /*********************************************************** * Sets the standard folder path ********************************************************/ - void SetFolderPath(std::string folderPath); + void SetFolderPath(std::wstring folderPath); private: struct PrivData; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 1e33361d..061e2c08 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -20,7 +20,7 @@ LevelParser::~LevelParser() { } -std::vector> LevelParser::Parse(std::string filename) +std::vector> LevelParser::Parse(std::wstring filename) { int bufferSize = 0; int counter = 0; @@ -32,6 +32,12 @@ std::vector> LevelParser::Parse(std::string filen Loader loader; char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); + // Check if file was loaded, else return empty vector + if(bufferSize == 0) + { + return std::vector>(); + } + //Read format version LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); @@ -215,7 +221,7 @@ std::vector> LevelParser::Parse(std::string filen } //för meta information om leveln. -LevelMetaData LevelParser::ParseHeader(std::string filename) +LevelMetaData LevelParser::ParseHeader(std::wstring filename) { int bufferSize = 0; int counter = 0; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h index 8f2a9150..d0cb1f03 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.h @@ -17,10 +17,10 @@ namespace GameLogic ~LevelParser(); // - std::vector> Parse(std::string filename); + std::vector> Parse(std::wstring filename); // - LevelMetaData ParseHeader(std::string filename); + LevelMetaData ParseHeader(std::wstring filename); private: LevelLoaderInternal::FormatVersion formatVersion; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp index 3e15315c..19ffa0f1 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -9,13 +9,13 @@ using namespace GameLogic::LevelFileLoader; using namespace Oyster::Resource; using namespace std; -char* Loader::LoadFile(std::string fileName, int &size) +char* Loader::LoadFile(std::wstring fileName, int &size) { //convert from string to wstring - std::wstring temp(fileName.begin(), fileName.end()); + //std::wstring temp(fileName.begin(), fileName.end()); //convert from wstring to wchar then loads the file - char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + char* buffer = (char*)OysterResource::LoadResource(fileName.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); size = OysterResource::GetResourceSize(buffer); return buffer; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h index 0433194e..6deb8900 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ b/Code/Game/GameLogic/LevelLoader/Loader.h @@ -17,7 +17,7 @@ namespace GameLogic public: Loader (){}; ~Loader(){}; - char* LoadFile(std::string fileName, int &size); + char* LoadFile(std::wstring fileName, int &size); //TODO: //Add functionality to load physicsObjects (hitboxes) diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index daa62752..76d7d6c3 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -5,6 +5,7 @@ #include "ParseFunctions.h" #include "Packing/Packing.h" #include "Loader.h" +#include "Utilities.h" #include using namespace Oyster::Packing; @@ -149,7 +150,7 @@ namespace GameLogic //Läs in filen. int fileLength = 0; Loader loader; - char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength); + char* buf = loader.LoadFile(L"../Content/Worlds/cgf/" + Utility::String::StringToWstring(fileName, wstring()), fileLength); start = 0; LevelLoaderInternal::FormatVersion version; From af15157283dbfb99d55394ee255013ac6129ad74 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Wed, 19 Feb 2014 00:20:01 +0100 Subject: [PATCH 38/39] GameLogic - Added default path to level data --- Code/Game/GameLogic/Level.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 969d332d..4106dabf 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -200,6 +200,7 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) bool Level::InitiateLevel(std::wstring levelPath) { LevelLoader ll; + ll.SetFolderPath(L"..\\Content\\Worlds\\"); std::vector> objects; objects = ll.LoadLevel(levelPath); From c2ef8350cfa7288bc3093c307952f3a41eb8ef9e Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 19 Feb 2014 10:15:52 +0100 Subject: [PATCH 39/39] GL - players created with unique ids --- Code/Game/GameLogic/Game.cpp | 39 +++++++++++++++++-------- Code/Game/GameLogic/Game_PlayerData.cpp | 18 +++++++++--- Code/Misc/Utilities/Utilities.h | 6 +--- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index ba294349..8b77dea4 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -68,12 +68,33 @@ void Game::GetAllPlayerPositions() const Game::PlayerData* Game::CreatePlayer() { // Find a free space in array or insert at end - int i = InsertObject(this->players, (PlayerData*)0); + int insert = InsertObject(this->players, (PlayerData*)0); + int freeID = 0; + bool found = false; - this->players[i] = new PlayerData(); - this->players[i]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + for(int i = 0; i < 100; i++) + { + found = true; + freeID = i; - return this->players[i]; + for(int j = 0; j < players.Size(); j++) + { + + if(this->players[j] && this->players[j]->GetID() == freeID) + { + found = false; + } + + if(!found) break; + } + + if(found) break; + } + + this->players[insert] = new PlayerData(freeID, 0); // user constructor with objectID and teamID + this->players[insert]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + + return this->players[insert]; } Game::LevelData* Game::CreateLevel(const wchar_t mapName[255]) @@ -95,21 +116,15 @@ bool Game::NewFrame() { for (unsigned int i = 0; i < this->players.Size(); i++) { - if(this->players[i]->player) this->players[i]->player->BeginFrame(); + if(this->players[i] && this->players[i]->player) this->players[i]->player->BeginFrame(); } API::Instance().UpdateWorld(); for (unsigned int i = 0; i < this->players.Size(); i++) { - if(this->players[i]->player) this->players[i]->player->EndFrame(); - gameInstance.onMoveFnc(this->players[i]); + if(this->players[i] && this->players[i]->player) this->players[i]->player->EndFrame(); } - for (unsigned int i = 0; i < this->level->level->dynamicObjects.Size(); i++) - { - gameInstance.onMoveFnc(this->level->level->dynamicObjects[i]); - } - return true; } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index e7a77bbd..3858d370 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -21,13 +21,23 @@ Game::PlayerData::PlayerData() rigidBody->SetAngularFactor(0.0f); //create player with this rigid body this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0); - - //this->player->GetRigidBody()->SetCustomTag(this); - player->EndFrame(); } Game::PlayerData::PlayerData(int playerID,int teamID) { - this->player = new Player(); + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); + + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); + Oyster::Math::Float mass = 60; + Oyster::Math::Float restitutionCoeff = 0.5f; + Oyster::Math::Float frictionCoeff_Static = 0.4f; + Oyster::Math::Float frictionCoeff_Dynamic = 0.3f; + //sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0); + + //create rigid body + Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); + rigidBody->SetAngularFactor(0.0f); + //create player with this rigid body + this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,playerID,teamID); } Game::PlayerData::~PlayerData() { diff --git a/Code/Misc/Utilities/Utilities.h b/Code/Misc/Utilities/Utilities.h index b97d62d7..c259a845 100644 --- a/Code/Misc/Utilities/Utilities.h +++ b/Code/Misc/Utilities/Utilities.h @@ -337,11 +337,7 @@ namespace Utility template inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max ) - { - if( value < min ) return min; - if( value > max ) return max; - return value; - } + { return value < min ? Max( value, max ) : min; } template inline ValueType Average( const ValueType &valueA, const ValueType &valueB )