From e3141cd1f907e2e1275fadce5371eff86a8cd5e4 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Thu, 20 Feb 2014 15:45:07 +0100 Subject: [PATCH 01/12] Added move to limbo for custom bodies NO idea if this works --- .../GamePhysics/Implementation/SimpleRigidBody.cpp | 10 ++++++++++ .../GamePhysics/Implementation/SimpleRigidBody.h | 3 +++ Code/Physics/GamePhysics/PhysicsAPI.h | 3 +++ 3 files changed, 16 insertions(+) diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 018c3be0..e2d87ce7 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -412,4 +412,14 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) float SimpleRigidBody::GetLambda() const { return this->rayLambda[0]; +} + +void SimpleRigidBody::MoveToLimbo() +{ + this->rigidBody->setCollisionFlags(this->rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); +} + +void SimpleRigidBody::ReleaseFromLimbo() +{ + this->rigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT); } \ No newline at end of file diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index effd123d..4290b540 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -69,6 +69,9 @@ namespace Oyster float GetLambda() const; + void MoveToLimbo(); + void ReleaseFromLimbo(); + private: btCollisionShape* collisionShape; diff --git a/Code/Physics/GamePhysics/PhysicsAPI.h b/Code/Physics/GamePhysics/PhysicsAPI.h index 72d4a8c6..33dc24a8 100644 --- a/Code/Physics/GamePhysics/PhysicsAPI.h +++ b/Code/Physics/GamePhysics/PhysicsAPI.h @@ -169,6 +169,9 @@ namespace Oyster virtual void CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss) = 0; virtual void CallSubscription_Move() = 0; + virtual void MoveToLimbo() = 0; + virtual void ReleaseFromLimbo() = 0; + /******************************************************** * @return the void pointer set by SetCustomTag. * nullptr if none is set. From dedd0e87c74d9602d9d283575e3081f982eb0781 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Thu, 20 Feb 2014 15:47:11 +0100 Subject: [PATCH 02/12] Added player disconnect protocol. --- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClient/GameClientState/GameState.cpp | 39 +++++++++++++------ Code/Game/GameProtocols/ObjectProtocols.h | 32 +++++++++++++++ .../GameProtocols/ProtocolIdentificationID.h | 2 + .../Implementation/GameSession_Gameplay.cpp | 11 ++++++ 5 files changed, 73 insertions(+), 13 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/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 532bd29d..4313b563 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -188,6 +188,7 @@ bool GameState::Render() if( dynamicObject->second ) { dynamicObject->second->Render(); + } } @@ -513,19 +514,21 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState this->privData->player.updateRBWorld(); // !RB DEBUG } - - C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; - - if( object ) + else { - object->setPos( position ); - object->setRot( rotation ); - object->updateWorld(); - // RB DEBUG - object->setRBPos ( position ); - object->setRBRot ( rotation ); - object->updateRBWorld(); - // !RB DEBUG + C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; + + if( object ) + { + object->setPos( position ); + object->setRot( rotation ); + object->updateWorld(); + // RB DEBUG + object->setRBPos ( position ); + object->setRBRot ( rotation ); + object->updateRBWorld(); + // !RB DEBUG + } } } return GameClientState::event_processed; @@ -584,6 +587,18 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectRespawn: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectDisconnectPlayer: + { + //Removes + Protocol_ObjectDisconnectPlayer decoded(data); + auto object = this->privData->dynamicObjects->find( decoded.objectID ); + if( object != this->privData->dynamicObjects->end() ) + { + object->second = nullptr; + this->privData->dynamicObjects->erase( object ); + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index fc02a4bd..cae7c7f5 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -892,6 +892,38 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectDisconnectPlayer 367 + struct Protocol_ObjectDisconnectPlayer :public Oyster::Network::CustomProtocolObject + { + int objectID; + + Protocol_ObjectDisconnectPlayer() + { + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value.netShort = protocol_Gameplay_ObjectDisconnectPlayer; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = 0; + } + Protocol_ObjectDisconnectPlayer(int objectID) + { + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value.netShort = protocol_Gameplay_ObjectDisconnectPlayer; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = objectID; + } + Protocol_ObjectDisconnectPlayer(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netInt; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = this->objectID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 4394a1a1..cb630012 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -69,6 +69,8 @@ #define protocol_Gameplay_ObjectWeaponEnergy 364 #define protocol_Gameplay_ObjectRespawn 365 #define protocol_Gameplay_ObjectDie 366 +//Disconnect +#define protocol_Gameplay_ObjectDisconnectPlayer 367 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index e2a2961d..0c52dfff 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -61,8 +61,19 @@ using namespace DanBias; switch (e.args.type) { case NetworkClient::ClientEventArgs::EventType_Disconnect: + { + //Send disconnect message to all the other players so the player can be removed from the client. + Protocol_ObjectDisconnectPlayer dp(cl->GetClient()->GetID()); + for(int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i] && this->gClients[i] != cl) + { + this->gClients[i]->GetClient()->Send(dp); + } + } printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); this->gClients[temp]->Invalidate(); + } break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: break; From 41cd83500c12a3212dc95594493d16b01ba3a7bb Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 20 Feb 2014 16:02:53 +0100 Subject: [PATCH 03/12] GL - deleteing cones in attatchmentMassdriver --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 3102b9f2..89de1f3e 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -106,6 +106,8 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float args.pushForce = pushForce; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); + + if(hitCone) delete hitCone; } /******************************************************** @@ -141,6 +143,8 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) args.pushForce = -pushForce; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); + + if(hitCone) delete hitCone; } void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) @@ -150,5 +154,5 @@ void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); - delete hitSphere; + if(hitSphere) delete hitSphere; } From d83e545e58ca6c2dc9e5e91d0739b13c635971e9 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Thu, 20 Feb 2014 16:35:49 +0100 Subject: [PATCH 04/12] Started adding GameUI --- Code/Game/GameClient/GameClient.vcxproj | 2 + Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClientState/Buttons/EventButtonGUI.h | 2 +- .../GameClientState/Buttons/Plane_UI.h | 51 +++++ .../GameClientState/Buttons/Text_UI.h | 41 ++++ .../GameClient/GameClientState/GameState.cpp | 207 +++++------------- .../GameClient/GameClientState/GameState.h | 3 + .../GameClient/GameClientState/GameStateUI.h | 4 +- .../GameClient/GameClientState/GamingUI.cpp | 179 +++++++++------ .../GameClient/GameClientState/GamingUI.h | 19 ++ .../OysterGraphics.vcxproj.user | 2 +- Code/OysterGraphics/Render/GuiRenderer.cpp | 4 +- .../Shader/Passes/Post/PostPass.hlsl | 1 + 13 files changed, 290 insertions(+), 227 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h create mode 100644 Code/Game/GameClient/GameClientState/Buttons/Text_UI.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index c084532d..7f42f218 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -226,6 +226,8 @@ + + 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/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c14d24f2..e598a790 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -113,7 +113,7 @@ namespace DanBias { if(buttonText.size() > 0) { - Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, -0.001f), size, size.y * 0.5f, textColor); + Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, +0.001f), size, size.y * 0.5f, textColor); } } diff --git a/Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h b/Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h new file mode 100644 index 00000000..8293eeb1 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Buttons/Plane_UI.h @@ -0,0 +1,51 @@ +#ifndef DANBIAS_CLIENT_PLANE_UI_H +#define DANBIAS_CLIENT_PLANE_UI_H + +#include "DllInterfaces/GFXAPI.h" + +namespace DanBias +{ + namespace Client + { + class Plane_UI + { + public: + Plane_UI( ) + { + pos = Oyster::Math::Float3::null; + size = Oyster::Math::Float2::null; + tintColor = Oyster::Math::Float4(1); + texture = NULL; + } + Plane_UI( std::wstring textureName, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, Oyster::Math::Float4 tintColor = Oyster::Math::Float4(1)) + : pos(pos), size(size), tintColor(tintColor) + { + CreateTexture(textureName); + } + virtual ~Plane_UI() + { + Oyster::Graphics::API::DeleteTexture(texture); + texture = NULL; + } + void CreateTexture(std::wstring textureName) + { + //Create texture + texture = Oyster::Graphics::API::CreateTexture(textureName); + } + + virtual void RenderTexture() const + { + if(texture) + Oyster::Graphics::API::RenderGuiElement(texture, pos, size, tintColor); + } + private: + Oyster::Math::Float3 pos; + Oyster::Math::Float2 size; + + Oyster::Graphics::API::Texture texture; + Oyster::Math::Float4 tintColor; + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h new file mode 100644 index 00000000..380c73e1 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h @@ -0,0 +1,41 @@ +#ifndef DANBIAS_CLIENT_TEXT_UI_H +#define DANBIAS_CLIENT_TEXT_UI_H + +#include "DllInterfaces/GFXAPI.h" + +namespace DanBias +{ + namespace Client + { + class Text_UI + { + public: + Text_UI( ) + { + pos = Oyster::Math::Float3::null; + size = Oyster::Math::Float2::null; + text = L""; + textColor = Oyster::Math::Float4(1); + } + Text_UI(std::wstring text, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, Oyster::Math::Float4 textColor = Oyster::Math::Float4(1)) + : pos(pos), size(size), text(text), textColor(textColor) + { + } + void RenderText() const + { + if(text.size() > 0) + { + Oyster::Graphics::API::RenderText(text, pos, size, size.y * 0.5f, textColor); + } + } + private: + Oyster::Math::Float3 pos; + Oyster::Math::Float2 size; + + std::wstring text; + Oyster::Math::Float4 textColor; + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 532bd29d..b5c779b6 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -9,6 +9,8 @@ #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" #include "Utilities.h" +#include "GamingUI.h" +#include "RespawnUI.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -107,6 +109,12 @@ bool GameState::Init( SharedStateContent &shared ) light->second->Render(); } + // create UI states + this->gameUI = new GamingUI(this->privData->input, this->privData->nwClient, &this->privData->camera); + this->respawnUI = new RespawnUI(this->privData->nwClient, 20); + this->currGameUI = gameUI; + ((GamingUI*)gameUI)->Init(); + // TODO init respawn return true; } @@ -163,7 +171,22 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { - this->ReadKeyInput(); + GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime ); + switch (UIstate) + { + case DanBias::Client::GameStateUI::UIState_same: + break; + case DanBias::Client::GameStateUI::UIState_gaming: + break; + case DanBias::Client::GameStateUI::UIState_main_menu: + //this->privData->nextState = + break; + case DanBias::Client::GameStateUI::UIState_shut_down: + this->privData->nextState = ClientState_Quit; + break; + default: + break; + } return this->privData->nextState; } @@ -191,13 +214,6 @@ bool GameState::Render() } } - - /*auto light = this->privData->lights->begin(); - for( ; light != this->privData->lights->end(); ++light ) - { - light->second->Render(); - }*/ - #ifdef _DEBUG //RB DEBUG render wire frame if(this->privData->renderWhireframe) @@ -242,6 +258,12 @@ bool GameState::Render() //!RB DEBUG #endif + // render current UI state + if(currGameUI->HaveGUIRender()) + currGameUI->RenderGUI(); + if(currGameUI->HaveTextRender()) + currGameUI->RenderText(); + Oyster::Graphics::API::EndFrame(); return true; } @@ -275,6 +297,21 @@ bool GameState::Release() privData = NULL; } + + if(respawnUI) + { + respawnUI->Release(); + delete respawnUI; + respawnUI = NULL; + } + if(gameUI) + { + gameUI->Release(); + delete gameUI; + gameUI = NULL; + } + currGameUI = NULL; + return true; } @@ -283,151 +320,6 @@ void GameState::ChangeState( ClientState next ) this->privData->nextState = next; } -void GameState::ReadKeyInput() -{ - if( this->privData->input->IsKeyPressed(DIK_W) ) - { - //if(!this->privData->key_forward) - { - this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); - this->privData->key_forward = true; - } - } - else - this->privData->key_forward = false; - - if( this->privData->input->IsKeyPressed(DIK_S) ) - { - //if( !this->privData->key_backward ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); - this->privData->key_backward = true; - } - } - else - this->privData->key_backward = false; - - if( this->privData->input->IsKeyPressed(DIK_A) ) - { - //if( !this->privData->key_strafeLeft ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); - this->privData->key_strafeLeft = true; - } - } - else - this->privData->key_strafeLeft = false; - - if( this->privData->input->IsKeyPressed(DIK_D) ) - { - //if( !this->privData->key_strafeRight ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); - this->privData->key_strafeRight = true; - } - } - else - this->privData->key_strafeRight = false; - - //send delta mouse movement - { - static const float mouseSensitivity = Radian( 1.0f ); - this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity ); - float yaw = this->privData->input->GetYaw(); - //if( yaw != 0.0f ) //This made the camera reset to a specific rotation. - { - this->privData->nwClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) ); - } - } - - // shoot - if( this->privData->input->IsKeyPressed(DIK_Z) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = true; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = false; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - if( this->privData->input->IsKeyPressed(DIK_X) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = true; - playerShot.utilityPressed = false; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - if( this->privData->input->IsKeyPressed(DIK_C) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = true; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - - // jump - if( this->privData->input->IsKeyPressed(DIK_SPACE) ) - { - if(!this->privData->key_Jump) - { - this->privData->nwClient->Send( Protocol_PlayerJump() ); - this->privData->key_Jump = true; - } - } - else - this->privData->key_Jump = false; - - - // DEGUG KEYS - - // Reload shaders - if( this->privData->input->IsKeyPressed(DIK_R) ) - { - if( !this->privData->key_Reload_Shaders ) - { -#ifdef _DEBUG - Graphics::API::ReloadShaders(); -#endif - this->privData->key_Reload_Shaders = true; - } - } - else - this->privData->key_Reload_Shaders = false; - - // toggle wire frame render - if( this->privData->input->IsKeyPressed(DIK_T) ) - { - if( !this->privData->key_Wireframe_Toggle ) - { - this->privData->renderWhireframe = !this->privData->renderWhireframe; - this->privData->key_Wireframe_Toggle = true; - } - } - else - this->privData->key_Wireframe_Toggle = false; - // !DEGUG KEYS - // TODO: implement sub-menu -} - const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) @@ -582,8 +474,13 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectRespawn: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectRespawn: + this->currGameUI = this->gameUI; + return GameClientState::event_processed; + case protocol_Gameplay_ObjectDie: + this->currGameUI = this->respawnUI; + // set countdown + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 8c5ca64e..8935481d 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -3,6 +3,7 @@ #include "GameClientState.h" #include "OysterMath.h" #include +#include "GameStateUI.h" namespace DanBias { namespace Client { @@ -31,6 +32,8 @@ namespace DanBias { namespace Client private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; + GameStateUI *currGameUI, *gameUI, *respawnUI; + }; } } #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.h b/Code/Game/GameClient/GameClientState/GameStateUI.h index 40350211..152a7f04 100644 --- a/Code/Game/GameClient/GameClientState/GameStateUI.h +++ b/Code/Game/GameClient/GameClientState/GameStateUI.h @@ -1,5 +1,5 @@ -#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H -#define DANBIAS_CLIENT_GAMECLIENTSTATE_H +#ifndef DANBIAS_CLIENT_GAMESTATEUI_H +#define DANBIAS_CLIENT_GAMESTATEUI_H #include "Utilities.h" #include "NetworkClient.h" diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 8ff43d88..3c4dd73c 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -6,6 +6,7 @@ using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::GameLogic; using namespace ::Utility::Value; +using namespace ::Oyster::Math; GamingUI::GamingUI() : GameStateUI() @@ -14,6 +15,8 @@ GamingUI::GamingUI() : this->input = nullptr; this->netClient = nullptr; this->camera = nullptr; + this->plane = nullptr; + this->text = nullptr; } GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : @@ -25,35 +28,49 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 * } GamingUI::~GamingUI() { /* Do nothing */ } +bool GamingUI::Init() +{ + // add textures and text + this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); + this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); + return true; +} GameStateUI::UIState GamingUI::Update( float deltaTime ) { + ReadKeyInput(); return this->nextState; } bool GamingUI::HaveGUIRender() const { - return false; // TODO: change to true when we want UI elements like a crosshair + return true; } bool GamingUI::HaveTextRender() const { - return false; // TODO: change to true when we want UI elements like a chat window + return true; } void GamingUI::RenderGUI() const { - // TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender + Oyster::Graphics::API::StartGuiRender(); + this->plane->RenderTexture(); } void GamingUI::RenderText() const { - // TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender + Oyster::Graphics::API::StartTextRender(); + this->text->RenderText(); } bool GamingUI::Release() { // TODO: Release UI components here. + if(this->plane) + delete this->plane; + if(this->text) + delete this->text; return true; } @@ -79,75 +96,107 @@ void GamingUI::ReadKeyInput() this->netClient->Send( Protocol_PlayerMovementRight() ); } -// if( this->input->IsKeyPressed(DIK_R) ) -// { -// if( !this->key_Reload_Shaders ) -// { -//#ifdef _DEBUG -// Graphics::API::ReloadShaders(); -//#endif -// this->key_Reload_Shaders = true; -// } -// } -// else -// this->key_Reload_Shaders = false; - - //send delta mouse movement +//send delta mouse movement { static const float mouseSensitivity = Radian( 1.0f ); this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity ); - this->netClient->Send( Protocol_PlayerLeftTurn(this->input->GetYaw() * mouseSensitivity) ); + float yaw = this->input->GetYaw(); + //if( yaw != 0.0f ) //This made the camera reset to a specific rotation. + { + this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) ); + } } // shoot - //if( this->input->IsKeyPressed(DIK_Z) ) - //{ - // if( !this->key_Shoot ) - // { - // Protocol_PlayerShot playerShot; - // playerShot.primaryPressed = true; - // playerShot.secondaryPressed = false; - // playerShot.utilityPressed = false; - // this->netClient->Send( playerShot ); - // this->key_Shoot = true; - // } - //} - //else - // this->key_Shoot = false; - - //if( this->input->IsKeyPressed(DIK_X) ) - //{ - // if( !this->key_Shoot ) - // { - // Protocol_PlayerShot playerShot; - // playerShot.primaryPressed = false; - // playerShot.secondaryPressed = true; - // playerShot.utilityPressed = false; - // this->netClient->Send( playerShot ); - // this->key_Shoot = true; - // } - //} - //else - // this->key_Shoot = false; - - //if( this->input->IsKeyPressed(DIK_C) ) - //{ - // if( !this->key_Shoot ) - // { - // Protocol_PlayerShot playerShot; - // playerShot.primaryPressed = false; - // playerShot.secondaryPressed = false; - // playerShot.utilityPressed = true; - // this->netClient->Send( playerShot ); - // this->key_Shoot = true; - // } - //} - //else - // this->key_Shoot = false; + if( this->input->IsKeyPressed(DIK_Z) ) + { + if( !this->key_Shoot ) + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = true; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + this->netClient->Send( playerShot ); + this->key_Shoot = true; + } + } + else + this->key_Shoot = false; + if( this->input->IsKeyPressed(DIK_X) ) + { + if( !this->key_Shoot ) + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = true; + playerShot.utilityPressed = false; + this->netClient->Send( playerShot ); + this->key_Shoot = true; + } + } + else + this->key_Shoot = false; + if( this->input->IsKeyPressed(DIK_C) ) + { + if( !this->key_Shoot ) + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = true; + this->netClient->Send( playerShot ); + this->key_Shoot = true; + } + } + else + this->key_Shoot = false; // jump if( this->input->IsKeyPressed(DIK_SPACE) ) { - this->netClient->Send( Protocol_PlayerJump() ); + if(!this->key_Jump) + { + this->netClient->Send( Protocol_PlayerJump() ); + this->key_Jump = true; + } } -} \ No newline at end of file + else + this->key_Jump = false; + + + // DEGUG KEYS + + // Reload shaders + if( this->input->IsKeyPressed(DIK_R) ) + { + if( !this->key_Reload_Shaders ) + { +#ifdef _DEBUG + Oyster::Graphics::API::ReloadShaders(); +#endif + this->key_Reload_Shaders = true; + } + } + else + this->key_Reload_Shaders = false; + + // toggle wire frame render + if( this->input->IsKeyPressed(DIK_T) ) + { + if( !this->key_Wireframe_Toggle ) + { + this->renderWhireframe = !this->renderWhireframe; + this->key_Wireframe_Toggle = true; + } + } + else + this->key_Wireframe_Toggle = false; + + if( this->input->IsKeyPressed(DIK_ESCAPE) ) + { + this->nextState = GameStateUI::UIState_shut_down; + } + // !DEGUG KEYS + // TODO: implement sub-menu +} + diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index 9f93674b..2e7fa5fe 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -4,6 +4,8 @@ #include "GameStateUI.h" #include "L_inputClass.h" #include "Camera_FPSV2.h" +#include "Buttons\Text_UI.h" +#include "Buttons\Plane_UI.h" namespace DanBias { namespace Client { @@ -12,6 +14,7 @@ namespace DanBias { namespace Client public: GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); virtual ~GamingUI(); + bool Init(); UIState Update( float deltaTime ); bool HaveGUIRender() const; @@ -24,6 +27,22 @@ namespace DanBias { namespace Client InputClass *input; ::Oyster::Network::NetworkClient *netClient; Camera_FPSV2 *camera; + Text_UI* text; + Plane_UI* plane; + + bool key_forward; + bool key_backward; + bool key_strafeRight; + bool key_strafeLeft; + bool key_Shoot; + bool key_Jump; + + // DEGUG KEYS + bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS + GamingUI(); void ReadKeyInput(); 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 diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index b71be6d7..98642604 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -56,8 +56,8 @@ namespace Oyster //size.x = size.x / (text.length() * TEXT_SPACING /2); - pos *= 2; - pos -= 1; + pos.xy *= 2; + pos.xy -= 1; pos.y *= -1; diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 258d0f25..2d5790ab 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -40,4 +40,5 @@ void main( uint3 DTid : SV_DispatchThreadID ) //Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(Output.Length*0.5f)].xyz,1); //Output[DTid.xy] = SSAO * float4(1,1,1,1); + //Output[DTid.xy] = Ambient[DTid.xy]; } \ No newline at end of file From 3bee35785abe549f683ac6ceaeb5d93310841492 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Thu, 20 Feb 2014 16:51:14 +0100 Subject: [PATCH 05/12] moved debug buttons to gameState --- .../GameClient/GameClientState/GameState.cpp | 58 ++++++++++++------- .../GameClient/GameClientState/GameState.h | 5 ++ .../GameClient/GameClientState/GamingUI.cpp | 29 ---------- .../GameClient/GameClientState/GamingUI.h | 7 --- 4 files changed, 41 insertions(+), 58 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index ce7a9158..631f4399 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -32,19 +32,6 @@ struct GameState::MyData ::std::map> *dynamicObjects; ::std::map> *lights; - bool key_forward; - bool key_backward; - bool key_strafeRight; - bool key_strafeLeft; - bool key_Shoot; - bool key_Jump; - - // DEGUG KEYS - bool key_Reload_Shaders; - bool key_Wireframe_Toggle; - bool renderWhireframe; - // !DEGUG KEYS - C_Player player; Camera_FPSV2 camera; @@ -75,11 +62,6 @@ bool GameState::Init( SharedStateContent &shared ) this->privData = new MyData(); - this->privData->key_forward = false; - this->privData->key_backward = false; - this->privData->key_strafeRight = false; - this->privData->key_strafeLeft = false; - this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; this->privData->input = shared.input; @@ -100,9 +82,9 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); // DEGUG KEYS - this->privData->key_Reload_Shaders = false; - this->privData->key_Wireframe_Toggle = false; - this->privData->renderWhireframe = false; + this->key_Reload_Shaders = false; + this->key_Wireframe_Toggle = false; + this->renderWhireframe = false; // !DEGUG KEYS auto light = this->privData->lights->begin(); @@ -189,6 +171,9 @@ GameClientState::ClientState GameState::Update( float deltaTime ) default: break; } + // DEBUG keybindings + ReadKeyInput(); + return this->privData->nextState; } @@ -219,7 +204,7 @@ bool GameState::Render() #ifdef _DEBUG //RB DEBUG render wire frame - if(this->privData->renderWhireframe) + if(this->renderWhireframe) { Oyster::Graphics::API::StartRenderWireFrame(); @@ -322,7 +307,36 @@ void GameState::ChangeState( ClientState next ) { this->privData->nextState = next; } +void GameState::ReadKeyInput() +{ + // DEGUG KEYS + // Reload shaders + if( this->privData->input->IsKeyPressed(DIK_R) ) + { + if( !this->key_Reload_Shaders ) + { +#ifdef _DEBUG + Oyster::Graphics::API::ReloadShaders(); +#endif + this->key_Reload_Shaders = true; + } + } + else + this->key_Reload_Shaders = false; + + // toggle wire frame render + if( this->privData->input->IsKeyPressed(DIK_T) ) + { + if( !this->key_Wireframe_Toggle ) + { + this->renderWhireframe = !this->renderWhireframe; + this->key_Wireframe_Toggle = true; + } + } + else + this->key_Wireframe_Toggle = false; +} const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 8935481d..5a9519ad 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -34,6 +34,11 @@ namespace DanBias { namespace Client ::Utility::DynamicMemory::UniquePointer privData; GameStateUI *currGameUI, *gameUI, *respawnUI; + // DEGUG KEYS + bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS }; } } #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 3c4dd73c..b57aff5d 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -163,35 +163,6 @@ void GamingUI::ReadKeyInput() else this->key_Jump = false; - - // DEGUG KEYS - - // Reload shaders - if( this->input->IsKeyPressed(DIK_R) ) - { - if( !this->key_Reload_Shaders ) - { -#ifdef _DEBUG - Oyster::Graphics::API::ReloadShaders(); -#endif - this->key_Reload_Shaders = true; - } - } - else - this->key_Reload_Shaders = false; - - // toggle wire frame render - if( this->input->IsKeyPressed(DIK_T) ) - { - if( !this->key_Wireframe_Toggle ) - { - this->renderWhireframe = !this->renderWhireframe; - this->key_Wireframe_Toggle = true; - } - } - else - this->key_Wireframe_Toggle = false; - if( this->input->IsKeyPressed(DIK_ESCAPE) ) { this->nextState = GameStateUI::UIState_shut_down; diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index 2e7fa5fe..af77fe0b 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -37,13 +37,6 @@ namespace DanBias { namespace Client bool key_Shoot; bool key_Jump; - // DEGUG KEYS - bool key_Reload_Shaders; - bool key_Wireframe_Toggle; - bool renderWhireframe; - // !DEGUG KEYS - - GamingUI(); void ReadKeyInput(); }; From f84c996a523510129f056081c575a6789b1430a7 Mon Sep 17 00:00:00 2001 From: dean11 Date: Thu, 20 Feb 2014 16:52:36 +0100 Subject: [PATCH 06/12] GameLogic - Added disconnect messages and reuse of players --- Code/Game/GameLogic/DynamicObject.cpp | 45 +++++++++++++++++-- Code/Game/GameLogic/DynamicObject.h | 8 ++++ Code/Game/GameLogic/Game.cpp | 11 +++++ Code/Game/GameLogic/Game.h | 4 +- Code/Game/GameLogic/GameAPI.h | 3 ++ Code/Game/GameLogic/Game_PlayerData.cpp | 8 ++++ Code/Game/GameLogic/Player.cpp | 5 +++ Code/Game/GameLogic/Player.h | 2 + Code/Game/GameProtocols/ObjectProtocols.h | 21 ++++----- .../GameProtocols/ProtocolIdentificationID.h | 1 - Code/Game/GameServer/GameClient.h | 1 + .../GameServer/Implementation/GameClient.cpp | 13 +++++- .../Implementation/GameSession_Gameplay.cpp | 35 ++++++++++----- .../Implementation/GameSession_General.cpp | 2 +- 14 files changed, 129 insertions(+), 30 deletions(-) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 6df5bef0..e6d9ff49 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -2,37 +2,76 @@ #include "CollisionManager.h" using namespace GameLogic; +using namespace Oyster::Math; DynamicObject::DynamicObject() :Object() { - + this->isReleased = false; + this->isActive = true; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) { - + this->isReleased = false; + this->isActive = true; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) { - + this->isReleased = false; + this->isActive = true; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) :Object(rigidBody, EventOnCollision, type, objectID) { this->extraDamageOnCollision = extraDamageOnCollision; + this->isReleased = false; + this->isActive = true; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) :Object(rigidBody, EventOnCollision, type, objectID) { this->extraDamageOnCollision = extraDamageOnCollision; + this->isReleased = false; + this->isActive = true; } DynamicObject::~DynamicObject(void) { +} + +void DynamicObject::ReleaseDynamicObject() +{ + //TODO: Inactivate the physics object + if(this->isReleased) return; + + this->isReleased = true; + this->isActive = false; + this->lookDirection = Float3::null; + this->forwardDirection = Float3::null; + this->scale = Float3::null; + this->extraDamageOnCollision = 0; + +} +bool DynamicObject::IsReleased() +{ + return this->isReleased; +} +bool DynamicObject::IsActive() +{ + return this->isActive; +} +void DynamicObject::Inactivate() +{ + this->isActive = false; +} +void DynamicObject::Activate() +{ + this->isActive = true; + this->isReleased = false; } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 2d5fa617..8a32e849 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -22,7 +22,15 @@ namespace GameLogic ~DynamicObject(void); + void ReleaseDynamicObject(); + bool IsReleased(); + bool IsActive(); + void Inactivate(); + void Activate(); + private: + bool isActive; + bool isReleased; }; diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 8dd7ffa6..c599fecf 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -67,6 +67,17 @@ void Game::GetAllPlayerPositions() const Game::PlayerData* Game::CreatePlayer() { + //Se if there is a free player somewhere in our list + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i] && this->players[i]->player->IsReleased()) + { + //We give the body to someone else + this->players[i]->player->Activate(); + return this->players[i]; + } + } + // Find a free space in array or insert at end int insert = InsertObject(this->players, (PlayerData*)0); int freeID = 0; diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 5ab19ba2..8d34a154 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -43,8 +43,8 @@ namespace GameLogic void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) override; void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) override; ObjectSpecialType GetObjectType() const override; - - + void Inactivate() override; + void Release() override; Player *player; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 66cf5ea2..a501a0d9 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -106,6 +106,9 @@ namespace GameLogic * @return The current player state ********************************************************/ virtual PLAYER_STATE GetState() const = 0; + + virtual void Inactivate() = 0; + virtual void Release() = 0; }; class ILevelData :public IObjectData diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 045da742..1f675f6a 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -93,4 +93,12 @@ void Game::PlayerData::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyste void Game::PlayerData::TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) { this->player->TurnLeft(deltaLeftRadians); +} +void Game::PlayerData::Inactivate() +{ + this->player->Inactivate(); +} +void Game::PlayerData::Release() +{ + this->player->ReleaseDynamicObject(); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 5b855785..02e8510c 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -293,6 +293,11 @@ bool Player::IsIdle() return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); } +void Player::Inactivate() +{ + //this-> +} + Oyster::Math::Float3 Player::GetPosition() const { return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 13c6e300..3ddd7f9a 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -63,6 +63,8 @@ namespace GameLogic bool IsJumping(); bool IsIdle(); + void Inactivate(); + Oyster::Math::Float3 GetPosition() const; Oyster::Math::Float3 GetLookDir() const; Oyster::Math::Float4x4 GetOrientation() const; diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index cae7c7f5..22f8213e 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -292,6 +292,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectEnabled 356 struct Protocol_ObjectPositionRotation :public Oyster::Network::CustomProtocolObject { short object_ID; @@ -366,7 +367,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectEnabled 356 + //#define protocol_Gameplay_ObjectEnabled 357 struct Protocol_ObjectEnable :public Oyster::Network::CustomProtocolObject { int objectID; @@ -399,7 +400,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectDisabled 357 + //#define protocol_Gameplay_ObjectDisabled 358 struct Protocol_ObjectDisable :public Oyster::Network::CustomProtocolObject { int objectID; @@ -439,7 +440,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectCreate 358 + //#define protocol_Gameplay_ObjectCreate 359 struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject { //ObjectType type; //ie player, box or whatever @@ -543,7 +544,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectCreatePlayer 359 + //#define protocol_Gameplay_ObjectCreatePlayer 360 struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject { /*1*/ int object_ID; @@ -673,7 +674,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectJoinTeam 360 + //#define protocol_Gameplay_ObjectJoinTeam 361 struct Protocol_ObjectJoinTeam :public Oyster::Network::CustomProtocolObject { int objectID; @@ -713,7 +714,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectLeaveTeam 361 + //#define protocol_Gameplay_ObjectLeaveTeam 362 struct Protocol_ObjectLeaveTeam :public Oyster::Network::CustomProtocolObject { int objectID; @@ -745,7 +746,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectWeaponCooldown 362 + //#define protocol_Gameplay_ObjectWeaponCooldown 363 struct Protocol_ObjectWeaponCooldown :public Oyster::Network::CustomProtocolObject { float seconds; @@ -777,7 +778,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectWeaponEnergy 363 + //#define protocol_Gameplay_ObjectWeaponEnergy 364 struct Protocol_ObjectWeaponEnergy :public Oyster::Network::CustomProtocolObject { float energy; @@ -809,7 +810,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectRespawn 364 + //#define protocol_Gameplay_ObjectRespawn 365 struct Protocol_ObjectRespawn :public Oyster::Network::CustomProtocolObject { float position[3]; @@ -852,7 +853,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectDie 365 + //#define protocol_Gameplay_ObjectDie 366 struct Protocol_ObjectDie :public Oyster::Network::CustomProtocolObject { int objectID; diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index cb630012..79235e2f 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -69,7 +69,6 @@ #define protocol_Gameplay_ObjectWeaponEnergy 364 #define protocol_Gameplay_ObjectRespawn 365 #define protocol_Gameplay_ObjectDie 366 -//Disconnect #define protocol_Gameplay_ObjectDisconnectPlayer 367 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index 497e6c2e..aace26c7 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -55,6 +55,7 @@ namespace DanBias GameLogic::IPlayerData* ReleasePlayer(); Oyster::Network::NetClient ReleaseClient(); + bool IsInvalid(); void Invalidate(); int IncrementFailedProtocol(); void ResetFailedProtocolCount(); diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 3293a383..e8e78ab0 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,12 +25,15 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerclient = 0; - this->player = 0; + if(this->player) + this->player->Inactivate(); + this->isReady = false; this->character = L"crate_colonists.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; + this->client = 0; + this->player = 0; } void GameClient::SetPlayer(GameLogic::IPlayerData* player) @@ -58,8 +61,14 @@ void GameClient::SetState(ClientState state) this->state = state; } +bool GameClient::IsInvalid() +{ + return this->isInvalid; +} void GameClient::Invalidate() { + this->player->Release(); + this->player = 0; this->isInvalid = true; this->isReady = false; this->state = ClientState_Invalid; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 0c52dfff..737ef1c9 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -62,24 +62,30 @@ using namespace DanBias; { case NetworkClient::ClientEventArgs::EventType_Disconnect: { - //Send disconnect message to all the other players so the player can be removed from the client. - Protocol_ObjectDisconnectPlayer dp(cl->GetClient()->GetID()); - for(int i = 0; i < this->gClients.Size(); i++) - { - if(this->gClients[i] && this->gClients[i] != cl) - { - this->gClients[i]->GetClient()->Send(dp); - } - } printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); + Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID()); + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot); + } + this->gClients[temp]->Invalidate(); } break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: + { if(this->gClients[temp]->IncrementFailedProtocol() >= 5/*client->threshold*/) + { + Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID()); + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(i != temp && this->gClients[i]) this->gClients[i]->GetClient()->Send(prot); + } this->gClients[temp]->Invalidate(); + } + } break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: this->ParseProtocol(e.args.data.protocol, cl); @@ -267,10 +273,17 @@ using namespace DanBias; switch (p.status) { case GameLogic::Protocol_General_Status::States_disconected: + { printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); - //TODO: Tell other clients - //Protocol_ + + Protocol_ObjectDisconnectPlayer prot(c->GetPlayer()->GetID()); + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if( this->gClients[i] && c->GetClient()->GetID() != this->gClients[i]->GetClient()->GetID() ) this->gClients[i]->GetClient()->Send(prot); + } + c->Invalidate(); this->Detach(c->GetClient()->GetID()); + } break; case GameLogic::Protocol_General_Status::States_idle: diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 30eabed2..45143e42 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -214,7 +214,7 @@ bool GameSession::Join(gClient gameClient) { for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->gClients[i]) + if(this->gClients[i] && !this->gClients[i]->IsInvalid()) { IPlayerData* temp = this->gClients[i]->GetPlayer(); Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), From 7d887d81b0b9034f479b81006a423f6c5125a7fb Mon Sep 17 00:00:00 2001 From: dean11 Date: Thu, 20 Feb 2014 16:54:24 +0100 Subject: [PATCH 07/12] GameServer - Modified one row --- .../GameServer/Implementation/GameSession_General.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 30eabed2..e2106ac9 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -217,11 +217,18 @@ bool GameSession::Join(gClient gameClient) if(this->gClients[i]) { IPlayerData* temp = this->gClients[i]->GetPlayer(); - Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), + Protocol_ObjectCreatePlayer p1( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), temp->GetID(), false, temp->GetTeamID(), Utility::String::WStringToString(this->gClients[i]->GetAlias(), std::string()), Utility::String::WStringToString(this->gClients[i]->GetCharacter(), std::string())); - nwClient->Send(oc); + nwClient->Send(p1); + + temp = playerData; + Protocol_ObjectCreatePlayer p2( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), + temp->GetID(), false, temp->GetTeamID(), + Utility::String::WStringToString(gameClient->GetAlias(), std::string()), + Utility::String::WStringToString(gameClient->GetCharacter(), std::string())); + this->gClients[i]->GetClient()->Send(p2); } } } From c718dc5a2b7d1fe1873d131f1f48691b82ee16e2 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 21 Feb 2014 09:34:09 +0100 Subject: [PATCH 08/12] Started implementing broadcasting --- .../GameClient/GameClientState/GameState.cpp | 2 +- Code/Network/NetworkAPI/NetworkServer.h | 37 ++++++++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index b4aee882..4cbdf686 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -591,7 +591,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDisconnectPlayer: { - //Removes + //Remove the disconnected player Protocol_ObjectDisconnectPlayer decoded(data); auto object = this->privData->dynamicObjects->find( decoded.objectID ); if( object != this->privData->dynamicObjects->end() ) diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h index 593c3847..82693310 100644 --- a/Code/Network/NetworkAPI/NetworkServer.h +++ b/Code/Network/NetworkAPI/NetworkServer.h @@ -22,16 +22,16 @@ namespace Oyster { struct BroadcastOptions { - //bool broadcast; - //float broadcastInterval; - //std::wstring subnetToBroadcast; - //CustomNetProtocol broadcastMessage; - //BroadcastOptions() - //{ - // broadcast = true; - // broadcastInterval = 1.0f; - // subnetToBroadcast = L"192.168.0.1"; - //} + bool broadcast; + float broadcastInterval; + std::wstring subnetToBroadcast; + CustomNetProtocol broadcastMessage; + BroadcastOptions() + { + broadcast = true; + broadcastInterval = 1.0f; + subnetToBroadcast = L"192.168.0.1"; + } } broadcastOptions; struct MainOptions @@ -117,6 +117,23 @@ namespace Oyster */ int NetworkServer::GetPort(); + + + /*************************************** + Broadcast functions + ***************************************/ + //Set broadcast settings. + void SetBroadcast(CustomNetProtocol& broadcastMessage, float interval = 1.0f, bool enable = true); + + //Set broadcast settings. + void SetBroadcastMessage(CustomNetProtocol& broadcastMessage); + + //Enable/disable broadcast. + void SetBroadcast(bool enable); + + //Set interval between each broadcast message in seconds. + void SetBroadcastInterval(float interval); + private: struct PrivateData; PrivateData* privateData; From 93eb598012a144ff22ba203c9240f857eebdb00c Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 21 Feb 2014 10:48:09 +0100 Subject: [PATCH 09/12] Fixed dynamic objects not being updated on startup. --- Code/Game/GameServer/Implementation/GameSession_General.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 30eabed2..a201167d 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -234,7 +234,7 @@ bool GameSession::Join(gClient gameClient) { //Protocol_ObjectPosition p(movedObject->GetPosition(), id); Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID()); - GameSession::gameSession->Send(p.GetProtocol()); + gameClient->GetClient()->Send(p.GetProtocol()); } } From 0ade5fde25203a31989823135be2195495cae93b Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 21 Feb 2014 10:49:02 +0100 Subject: [PATCH 10/12] GameClient UI base. TODO: make it look pretty --- Code/Game/GameClient/GameClient.vcxproj | 2 + .../GameClientState/Buttons/Text_UI.h | 4 + .../GameClient/GameClientState/GameState.cpp | 98 +++++++++++++++++-- .../GameClient/GameClientState/GameState.h | 5 +- .../GameClient/GameClientState/GamingUI.cpp | 8 +- .../GameClient/GameClientState/GamingUI.h | 3 + .../GameClient/GameClientState/RespawnUI.cpp | 24 ++++- .../GameClient/GameClientState/RespawnUI.h | 7 ++ .../GameClient/GameClientState/StatsUI.cpp | 65 ++++++++++++ .../Game/GameClient/GameClientState/StatsUI.h | 34 +++++++ 10 files changed, 234 insertions(+), 16 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/StatsUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/StatsUI.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 7f42f218..031f967f 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -224,6 +224,7 @@ + @@ -251,6 +252,7 @@ + diff --git a/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h index 380c73e1..d37b347e 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/Text_UI.h @@ -21,6 +21,10 @@ namespace DanBias : pos(pos), size(size), text(text), textColor(textColor) { } + void setText(std::wstring text) + { + this->text = text; + } void RenderText() const { if(text.size() > 0) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 631f4399..078bc74b 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -11,6 +11,7 @@ #include "Utilities.h" #include "GamingUI.h" #include "RespawnUI.h" +#include "StatsUI.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -96,9 +97,11 @@ bool GameState::Init( SharedStateContent &shared ) // create UI states this->gameUI = new GamingUI(this->privData->input, this->privData->nwClient, &this->privData->camera); this->respawnUI = new RespawnUI(this->privData->nwClient, 20); + this->statsUI = new StatsUI(); this->currGameUI = gameUI; ((GamingUI*)gameUI)->Init(); - // TODO init respawn + ((RespawnUI*)respawnUI)->Init(); + ((StatsUI*)statsUI)->Init(); return true; } @@ -246,12 +249,24 @@ bool GameState::Render() //!RB DEBUG #endif - // render current UI state + Oyster::Graphics::API::StartGuiRender(); + // render gui elemnts if(currGameUI->HaveGUIRender()) currGameUI->RenderGUI(); + if(renderStats) + { + if(statsUI->HaveGUIRender()) + statsUI->RenderGUI(); + } + Oyster::Graphics::API::StartTextRender(); if(currGameUI->HaveTextRender()) currGameUI->RenderText(); - + if(renderStats) + { + if(statsUI->HaveTextRender()) + statsUI->RenderText(); + } + Oyster::Graphics::API::EndFrame(); return true; } @@ -298,6 +313,12 @@ bool GameState::Release() delete gameUI; gameUI = NULL; } + if(statsUI) + { + statsUI->Release(); + delete statsUI; + statsUI = NULL; + } currGameUI = NULL; return true; @@ -332,10 +353,33 @@ void GameState::ReadKeyInput() { this->renderWhireframe = !this->renderWhireframe; this->key_Wireframe_Toggle = true; + // DEBUG set you as dead when render wireframe + this->currGameUI = respawnUI; + // !DEBUG } } else + { this->key_Wireframe_Toggle = false; + // DEBUG set you as dead when render wireframe + this->currGameUI = gameUI; + // !DEBUG + } + + // toggle wire frame render + if( this->privData->input->IsKeyPressed(DIK_TAB) ) + { + if( !this->key_showStats ) + { + this->renderStats = true; + this->key_showStats = true; + } + } + else + { + this->renderStats = false; + this->key_showStats = false; + } } const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { @@ -356,8 +400,22 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState switch(ID) { case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectDamage: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectHealthStatus: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectDamage: + { + Protocol_ObjectDamage decoded(data); + if( this->privData->myId == decoded.object_ID ) + { + if(currGameUI == gameUI) + { + ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + } + } + } + return GameClientState::event_processed; + case protocol_Gameplay_ObjectHealthStatus: + { + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectPosition: { Protocol_ObjectPosition decoded(data); @@ -493,12 +551,34 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ - case protocol_Gameplay_ObjectRespawn: - this->currGameUI = this->gameUI; + case protocol_Gameplay_ObjectRespawn: + { + // set player pos + Protocol_ObjectRespawn decoded(data); + // move player. Remember to change camera + this->privData->camera.SetPosition( decoded.position ); + this->privData->player.setPos( decoded.position ); + this->privData->player.updateWorld(); + // RB DEBUG + this->privData->player.setRBPos ( decoded.position ); + this->privData->player.updateRBWorld(); + // !RB DEBUG + + this->currGameUI = this->gameUI; + } return GameClientState::event_processed; case protocol_Gameplay_ObjectDie: - this->currGameUI = this->respawnUI; - // set countdown + { + Protocol_ObjectDie decoded(data); + // if is this player. Remember to change camera + if( this->privData->myId == decoded.objectID ) + { + this->currGameUI = this->respawnUI; + // set countdown + ((RespawnUI*)currGameUI)->SetCountdown( decoded.seconds ); + } + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDisconnectPlayer: { //Removes diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 5a9519ad..8342d558 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -32,13 +32,16 @@ namespace DanBias { namespace Client private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; - GameStateUI *currGameUI, *gameUI, *respawnUI; + GameStateUI *currGameUI, *gameUI, *respawnUI, *statsUI; // DEGUG KEYS bool key_Reload_Shaders; bool key_Wireframe_Toggle; bool renderWhireframe; + bool key_showStats; + bool renderStats; // !DEGUG KEYS + }; } } #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index b57aff5d..03840881 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -30,6 +30,7 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 * GamingUI::~GamingUI() { /* Do nothing */ } bool GamingUI::Init() { + // z value should be between 0.5 - 0.9 so that it will be behind other states // add textures and text this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); @@ -54,13 +55,11 @@ bool GamingUI::HaveTextRender() const void GamingUI::RenderGUI() const { - Oyster::Graphics::API::StartGuiRender(); this->plane->RenderTexture(); } void GamingUI::RenderText() const { - Oyster::Graphics::API::StartTextRender(); this->text->RenderText(); } @@ -73,7 +72,10 @@ bool GamingUI::Release() delete this->text; return true; } - +void GamingUI::SetHPtext( std::wstring hp ) +{ + this->text->setText(hp); +} void GamingUI::ReadKeyInput() { if( this->input->IsKeyPressed(DIK_W) ) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index af77fe0b..36e94262 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -22,11 +22,14 @@ namespace DanBias { namespace Client void RenderGUI() const; void RenderText() const; bool Release(); + void SetHPtext( std::wstring hp ); private: InputClass *input; ::Oyster::Network::NetworkClient *netClient; Camera_FPSV2 *camera; + + // TODO add multiple UI elements Text_UI* text; Plane_UI* plane; diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.cpp b/Code/Game/GameClient/GameClientState/RespawnUI.cpp index 4588d367..21732df6 100644 --- a/Code/Game/GameClient/GameClientState/RespawnUI.cpp +++ b/Code/Game/GameClient/GameClientState/RespawnUI.cpp @@ -3,6 +3,7 @@ using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::Utility::Value; +using namespace ::Oyster::Math; RespawnUI::RespawnUI() : GameStateUI() @@ -17,13 +18,23 @@ RespawnUI::RespawnUI( NetworkClient *connection, float delay ) : { this->netClient = connection; this->countDown = delay; + this->text = nullptr; } RespawnUI::~RespawnUI() { /* Do nothing */ } +bool RespawnUI::Init() +{ + // z value should be between 0.5 - 0.9 so that it will be behind other states + // add textures and text + this->text = new Text_UI(L"DEAD", Float3(0.5f,0.0f,0.5f), Float2(0.2f,0.2f)); + return true; +} GameStateUI::UIState RespawnUI::Update( float deltaTime ) { this->countDown = Max( this->countDown - deltaTime, 0.0f ); + // countDown == 0 + // return UIState_gaming state; return this->nextState; } @@ -34,25 +45,32 @@ bool RespawnUI::HaveGUIRender() const bool RespawnUI::HaveTextRender() const { - return false; // TODO: change to true when we want UI elements like a chat window + return true; // TODO: change to true when we want UI elements like a chat window } void RespawnUI::RenderGUI() const { - // TODO: We need? + // TODO:BLOODY SCREEN } void RespawnUI::RenderText() const { + this->text->RenderText(); // TODO: Text countdown somewhere on screen would be nice } bool RespawnUI::Release() { // TODO: Release UI components here. + if(this->text) + delete this->text; return true; } +void RespawnUI::SetCountdown( float cd ) +{ + this->countDown = cd; + // this text should be rendered +} - diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.h b/Code/Game/GameClient/GameClientState/RespawnUI.h index c45616b7..6e5df64e 100644 --- a/Code/Game/GameClient/GameClientState/RespawnUI.h +++ b/Code/Game/GameClient/GameClientState/RespawnUI.h @@ -2,6 +2,8 @@ #define DANBIAS_CLIENT_RESPAWN_UI_H #include "GameStateUI.h" +#include "Buttons\Text_UI.h" +#include "Buttons\Plane_UI.h" namespace DanBias { namespace Client { @@ -10,18 +12,23 @@ namespace DanBias { namespace Client public: RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay ); virtual ~RespawnUI(); + bool Init(); + // TODO countdown UIState Update( float deltaTime ); bool HaveGUIRender() const; bool HaveTextRender() const; void RenderGUI() const; void RenderText() const; bool Release(); + void SetCountdown( float cd ); private: ::Oyster::Network::NetworkClient *netClient; float countDown; + // TODO add multiple UI elements + Text_UI* text; RespawnUI(); }; } } diff --git a/Code/Game/GameClient/GameClientState/StatsUI.cpp b/Code/Game/GameClient/GameClientState/StatsUI.cpp new file mode 100644 index 00000000..ab07b89d --- /dev/null +++ b/Code/Game/GameClient/GameClientState/StatsUI.cpp @@ -0,0 +1,65 @@ +#include "StatsUI.h" +#include +#include "Utilities.h" + +using namespace ::DanBias::Client; +using namespace ::GameLogic; +using namespace ::Utility::Value; +using namespace ::Oyster::Math; + +StatsUI::StatsUI() : + GameStateUI() +{ + /* Should never be called! */ + this->plane = nullptr; + this->text = nullptr; +} + +StatsUI::~StatsUI() { /* Do nothing */ } +bool StatsUI::Init() +{ + // z value should be between 0.1 - 0.5 so that it will be in front of other states + // add textures and text for player stats + this->plane = new Plane_UI(L"box_tex.png", Float3(0.0f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); + this->text = new Text_UI(L"Stats", Float3(0.0f,0.0f,0.1f), Float2(0.1f,0.1f)); + + return true; +} +GameStateUI::UIState StatsUI::Update( float deltaTime ) +{ + return this->nextState; +} + +bool StatsUI::HaveGUIRender() const +{ + // Set true if UIstate have any plane to render + return true; +} + +bool StatsUI::HaveTextRender() const +{ + // Set true if UIstate have any text to render + return true; +} + +void StatsUI::RenderGUI() const +{ + // render all the planes + this->plane->RenderTexture(); +} + +void StatsUI::RenderText() const +{ + // render all the text + this->text->RenderText(); +} + +bool StatsUI::Release() +{ + // TODO: Release UI components here. + if(this->plane) + delete this->plane; + if(this->text) + delete this->text; + return true; +} diff --git a/Code/Game/GameClient/GameClientState/StatsUI.h b/Code/Game/GameClient/GameClientState/StatsUI.h new file mode 100644 index 00000000..589f956b --- /dev/null +++ b/Code/Game/GameClient/GameClientState/StatsUI.h @@ -0,0 +1,34 @@ +#ifndef DANBIAS_CLIENT_STATS_UI_H +#define DANBIAS_CLIENT_STATS_UI_H + +#include "GameStateUI.h" +#include "Buttons\Text_UI.h" +#include "Buttons\Plane_UI.h" + +namespace DanBias { namespace Client +{ + class StatsUI : public GameStateUI + { + public: + StatsUI(); + virtual ~StatsUI(); + bool Init(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + // TODO add function to add a new players statistics + // TODO add function to remove a players statistics + + private: + // TODO add multiple UI elements + // one for each player ingame + Text_UI* text; + Plane_UI* plane; + }; +} } + +#endif \ No newline at end of file From 54adb19eb89737d135d7410178f02d01dc0d4748 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 21 Feb 2014 10:54:30 +0100 Subject: [PATCH 11/12] Unnecessary get client --- Code/Game/GameServer/Implementation/GameSession_General.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index a201167d..2b8a7d5c 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -234,7 +234,7 @@ bool GameSession::Join(gClient gameClient) { //Protocol_ObjectPosition p(movedObject->GetPosition(), id); Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID()); - gameClient->GetClient()->Send(p.GetProtocol()); + nwClient->Send(p.GetProtocol()); } } From a46ba0efb55be86450e4e02efc4e8c6ecec193c9 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 21 Feb 2014 11:12:24 +0100 Subject: [PATCH 12/12] Added print out for disconnect --- Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 737ef1c9..c919c159 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -78,6 +78,7 @@ using namespace DanBias; { if(this->gClients[temp]->IncrementFailedProtocol() >= 5/*client->threshold*/) { + printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); Protocol_ObjectDisconnectPlayer prot(this->gClients[temp]->GetPlayer()->GetID()); for (unsigned int i = 0; i < this->gClients.Size(); i++) {