diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 25d17123..349c2da6 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -213,7 +213,7 @@ - + @@ -232,7 +232,7 @@ - + diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index ccb80d85..fa988a00 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -5,7 +5,7 @@ #include "GameClientState/GameClientState.h" #include "GameClientState\GameState.h" #include "GameClientState\LobbyState.h" -#include "GameClientState\LoginState.h" +#include "GameClientState\MainState.h" #include "GameClientState\LanMenuState.h" #include #include "NetworkClient.h" @@ -18,7 +18,9 @@ #include "GameClientRecieverFunc.h" #include "../Misc/EventHandler/EventHandler.h" -using namespace Oyster::Event; + +using namespace ::Oyster::Event; +using namespace ::Utility::DynamicMemory; namespace DanBias { @@ -29,20 +31,15 @@ namespace DanBias { public: - DanBiasGamePrivateData() - { + DanBiasGamePrivateData() {} - } - ~DanBiasGamePrivateData() - { - - } + ~DanBiasGamePrivateData() {} public: WindowShell* window; InputClass* inputObj; Utility::WinTimer timer; - GameRecieverObject* recieverObj; + UniquePointer state; bool serverOwner; } data; @@ -69,12 +66,12 @@ namespace DanBias if( FAILED( InitInput() ) ) return DanBiasClientReturn_Error; - m_data->recieverObj = new GameRecieverObject; - m_data->serverOwner = false; + //m_data->serverOwner = false; // Start in lobby state - m_data->recieverObj->gameClientState = new Client::LoginState(); - if(!m_data->recieverObj->gameClientState->Init(m_data->recieverObj)) + m_data->state = new Client::MainState(); + + if( !m_data->state->Init() ) return DanBiasClientReturn_Error; m_data->timer.reset(); diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index 68b46d38..673cbdd1 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -9,7 +9,6 @@ #include "GameClientState\GameClientState.h" #include "GameClientState\GameState.h" - #include namespace DanBias diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.h b/Code/Game/DanBiasGame/GameClientState/C_Object.h index 9c06d2da..4dec19ec 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.h +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.h @@ -5,7 +5,6 @@ namespace DanBias { namespace Client { - struct ModelInitData { int id; @@ -16,34 +15,50 @@ namespace DanBias bool visible; }; -class C_Object -{ -private: - Oyster::Math::Float4x4 world; - Oyster::Math::Float3 position; - Oyster::Math::Quaternion rotation; - Oyster::Math::Float3 scale; - Oyster::Graphics::Model::Model *model; - int id; - void updateWorld(); -public: + class C_Object + { + private: + Oyster::Math::Float4x4 world; + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + Oyster::Graphics::Model::Model *model; + int id; + void updateWorld(); + public: - virtual void Init(ModelInitData modelInit); + virtual void 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; + }; + } +} + +namespace Utility { namespace DynamicMemory +{ // template specializationto allowuse of dynamicmemory tools + 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/DanBiasGame/GameClientState/GameClientState.cpp b/Code/Game/DanBiasGame/GameClientState/GameClientState.cpp index 1fffc85e..d0d811f4 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.cpp @@ -1,12 +1,15 @@ #include "GameClientState.h" using namespace DanBias::Client; +using namespace ::Oyster::Network; GameClientState::GameClientState(void) { } - GameClientState::~GameClientState(void) { } + +void DataRecieved( NetEvent e ) +{ /* do nothing */ } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h index bab3ba57..cfb149aa 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -7,7 +7,7 @@ namespace DanBias { namespace Client { - class GameClientState : public ::Oyster::Network::NetworkClient + class GameClientState { public: enum ClientState @@ -27,6 +27,8 @@ namespace DanBias { namespace Client virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0; virtual bool Render() = 0; virtual bool Release() = 0; + + virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); }; } } #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 7fe91af4..52cb03e0 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -491,7 +491,7 @@ int FindObject( const DynamicArray> &collection, int id ) return -1; } -void GameState::DataRecieved( NetEvent e ) +void GameState::DataRecieved( NetEvent e ) { CustomNetProtocol data = e.args.data.protocol; short ID = data[0].value.netShort; // fetching the id data. diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 1fec5a24..f932bbc2 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -52,7 +52,7 @@ namespace Client bool Render()override; bool Release()override; - void DataRecieved( ::Oyster::Network::NetEvent e ); + void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); }; } } diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp index a1a3a443..12847875 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp @@ -7,11 +7,12 @@ #include "LobbyState.h" #include "GameState.h" -#include "../GameClientRecieverFunc.h" +#include "../Network/NetworkAPI/NetworkClient.h" #include -using namespace DanBias::Client; +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; struct LanMenuState::myData { @@ -21,7 +22,7 @@ struct LanMenuState::myData C_Object* object[2]; int modelCount; - GameRecieverObject* recieverObj; + NetworkClient* recieverObj; bool serverOwner; // UI object diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 631f3989..afb909a5 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -135,7 +135,7 @@ bool LobbyState::Release() using namespace ::Oyster::Network; -void LobbyState::DataRecieved( NetEvent e ) +void LobbyState::DataRecieved( NetEvent e ) { CustomNetProtocol data = e.args.data.protocol; short ID = data[0].value.netShort; // fetching the id data. diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.h b/Code/Game/DanBiasGame/GameClientState/LobbyState.h index 44ffc6e8..56a3ab3b 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.h +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.h @@ -34,7 +34,7 @@ namespace DanBias bool Render(); bool Release(); - void DataRecieved( ::Oyster::Network::NetEvent e ); + void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); }; } } diff --git a/Code/Game/DanBiasGame/GameClientState/MainState.cpp b/Code/Game/DanBiasGame/GameClientState/MainState.cpp index 409d1164..710eebbe 100644 --- a/Code/Game/DanBiasGame/GameClientState/MainState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/MainState.cpp @@ -5,39 +5,44 @@ #include "C_obj/C_StaticObj.h" #include "C_obj/C_DynamicObj.h" #include +#include "NetworkClient.h" -using namespace DanBias::Client; +using namespace ::DanBias::Client; +using namespace ::Oyster::Math3D; +using namespace ::Oyster::Network; +using namespace ::Utility::DynamicMemory; -struct MainState::myData +struct MainState::MyData { - myData(){} - Oyster::Math3D::Float4x4 view; - Oyster::Math3D::Float4x4 proj; - C_Object* object[2]; + MyData() {} + + Float4x4 view; + Float4x4 proj; + + UniquePointer object[2]; int modelCount; - // UI object - // game client* -} privData; + NetworkClient *nwClient; +}; MainState::MainState(void) {} MainState::~MainState(void) {} -bool MainState::Init(Oyster::Network::NetworkClient* nwClient) +bool MainState::Init( NetworkClient* nwClient ) { - privData = new myData(); - this->nwClient = nwClient; + this->privData = new MyData(); + // load models LoadModels(L"UImodels.txt"); - InitCamera(Oyster::Math::Float3(0,0,5.4f)); + InitCamera( Float3(0.0f, 0.0f, 5.4f) ); return true; } bool MainState::LoadModels(std::wstring file) { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(0,0,5); - plight.Color = Oyster::Math::Float3(1,1,1); + plight.Pos = Float3(0,0,5); + plight.Color = Float3(1,1,1); plight.Radius = 100; plight.Bright = 1; Oyster::Graphics::API::AddLight(plight); @@ -48,30 +53,30 @@ bool MainState::LoadModels(std::wstring file) ModelInitData modelData; - modelData.rotation = Oyster::Math::Quaternion::identity; - modelData.scale = Oyster::Math::Float3(1,1,1); + modelData.rotation = Quaternion::identity; + modelData.scale = Float3(1,1,1); modelData.visible = true; modelData.modelPath = L"box.dan"; - modelData.position = Oyster::Math::Float3(2,2,2); + modelData.position = Float3(2,2,2); privData->object[0] = new C_StaticObj(); privData->object[0]->Init(modelData); - modelData.position = Oyster::Math::Float3(-2,0,-2); + modelData.position = Float3(-2,0,-2); privData->object[1] = new C_StaticObj(); privData->object[1]->Init(modelData); return true; } -bool MainState::InitCamera(Oyster::Math::Float3 startPos) +bool MainState::InitCamera(Float3 startPos) { - privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000); - //privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000); + privData->proj = ProjectionMatrix_Perspective(pi/2,1024.0f/768.0f,.1f,1000); + //privData->proj = ProjectionMatrix_Orthographic(1024, 768, 1, 1000); Oyster::Graphics::API::SetProjection(privData->proj); - privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos); - privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); + privData->view = OrientationMatrix_LookAtDirection(Float3(0,0,-1),Float3(0,1,0),startPos); + privData->view = InverseOrientationMatrix(privData->view); return true; } @@ -93,9 +98,9 @@ GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyI DanBias::GameServerAPI::ServerInitiate(desc); DanBias::GameServerAPI::ServerStart(); // my ip - nwClient->Connect(15152, "127.0.0.1"); + this->privData->nwClient->Connect(15152, "127.0.0.1"); - if (!nwClient->IsConnected()) + if (!this->privData->nwClient->IsConnected()) { // failed to connect return ClientState_Same; @@ -106,10 +111,10 @@ GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyI if( KeyInput->IsKeyPressed(DIK_J)) { // game ip - nwClient->Connect(15152, "127.0.0.1"); + this->privData->nwClient->Connect(15152, "127.0.0.1"); //nwClient->Connect(15152, "83.254.217.248"); - if (!nwClient->IsConnected()) + if (!this->privData->nwClient->IsConnected()) { // failed to connect return ClientState_Same; diff --git a/Code/Game/DanBiasGame/GameClientState/MainState.h b/Code/Game/DanBiasGame/GameClientState/MainState.h index 789e9a7b..0e7bf1b6 100644 --- a/Code/Game/DanBiasGame/GameClientState/MainState.h +++ b/Code/Game/DanBiasGame/GameClientState/MainState.h @@ -12,13 +12,12 @@ namespace DanBias class MainState : public GameClientState { private: - Oyster::Network::NetworkClient* nwClient; - struct myData; - myData* privData; + struct MyData; + ::Utility::DynamicMemory::UniquePointer privData; public: MainState(void); ~MainState(void); - bool Init(Oyster::Network::NetworkClient* nwClient); + bool Init( Oyster::Network::NetworkClient* nwClient ); bool LoadModels(std::wstring file); bool InitCamera(Oyster::Math::Float3 startPos); ClientState Update(float deltaTime, InputClass* KeyInput); @@ -26,7 +25,7 @@ namespace DanBias bool Render(); bool Release(); - void DataRecieved( ::Oyster::Network::NetEvent e ); + void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); }; } }