From ba6f7114b516d59f0e41021bb805f5407fae59fd Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Thu, 19 Dec 2013 11:58:42 +0100 Subject: [PATCH] GL - added id in object, vector --- .../DanBiasGame/GameClientState/C_Object.h | 2 + .../GameClientState/C_obj/C_DynamicObj.cpp | 5 ++ .../GameClientState/C_obj/C_DynamicObj.h | 1 + .../GameClientState/C_obj/C_Player.cpp | 5 ++ .../GameClientState/C_obj/C_Player.h | 1 + .../GameClientState/C_obj/C_StaticObj.cpp | 5 ++ .../GameClientState/C_obj/C_StaticObj.h | 1 + .../GameClientState/C_obj/C_UIobject.cpp | 7 ++- .../GameClientState/C_obj/C_UIobject.h | 1 + .../DanBiasGame/GameClientState/GameState.cpp | 62 ++++++++----------- .../DanBiasGame/GameClientState/GameState.h | 3 - Code/Game/DanBiasLauncher/Launcher.cpp | 7 ++- 12 files changed, 56 insertions(+), 44 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.h b/Code/Game/DanBiasGame/GameClientState/C_Object.h index 18859930..1b87174b 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.h +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.h @@ -8,6 +8,7 @@ namespace DanBias struct ModelInitData { + int id; std::wstring modelPath; Oyster::Math::Float4x4 world; bool visible; @@ -24,5 +25,6 @@ public: virtual void Render() = 0; virtual void Release() = 0; + virtual int GetId() = 0; };};}; #endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp index a4ae4840..f47fc9fe 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp @@ -5,6 +5,7 @@ struct C_DynamicObj::myData { myData(){} Oyster::Graphics::Model::Model *model; + int ID; // light // sound // effect @@ -39,4 +40,8 @@ void C_DynamicObj::Release() { Oyster::Graphics::API::DeleteModel(privData->model); delete privData; +} +int C_DynamicObj::GetId() +{ + return privData->ID; } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h index e0ad3be3..ee25a992 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h @@ -18,5 +18,6 @@ public: void Render(); void Release(); + int GetId(); };};}; #endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp index 5fb06d96..86acaf4b 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp @@ -8,6 +8,7 @@ struct C_Player::myData Oyster::Math3D::Float4x4 view; Oyster::Math3D::Float4x4 proj; Oyster::Graphics::Model::Model *model; + int ID; }privData; C_Player::C_Player(void) @@ -44,3 +45,7 @@ void C_Player::Release() Oyster::Graphics::API::DeleteModel(privData->model); delete privData; } +int C_Player::GetId() +{ + return privData->ID; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h index 638bd856..794bf51a 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h @@ -19,6 +19,7 @@ public: void Render(); void Release(); + int GetId(); };};}; #endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp index f96ea56d..c5f2e119 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp @@ -7,6 +7,7 @@ struct C_StaticObj::myData { myData(){} Oyster::Graphics::Model::Model *model; + int ID; // light // sound // effect @@ -42,4 +43,8 @@ void C_StaticObj::Release() { Oyster::Graphics::API::DeleteModel(privData->model); delete privData; +} +int C_StaticObj::GetId() +{ + return privData->ID; } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h index 84fc0599..799c0982 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h @@ -18,5 +18,6 @@ public: void Render(); void Release(); + int GetId(); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp index 5adc3962..226d8ca7 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp @@ -5,9 +5,8 @@ using namespace DanBias::Client; struct C_UIobject::myData { myData(){} - Oyster::Math3D::Float4x4 view; - Oyster::Math3D::Float4x4 proj; Oyster::Graphics::Model::Model *model; + int ID; }privData; C_UIobject::C_UIobject(void) @@ -40,4 +39,8 @@ void C_UIobject::Release() { Oyster::Graphics::API::DeleteModel(privData->model); delete privData; +} +int C_UIobject::GetId() +{ + return privData->ID; } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h index e82b702f..b41fb047 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h @@ -18,5 +18,6 @@ namespace DanBias void Render(); void Release(); + int GetId(); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 1ee9ac8b..5a98758b 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -15,7 +15,7 @@ struct GameState::myData myData(){} Oyster::Math3D::Float4x4 view; Oyster::Math3D::Float4x4 proj; - C_Object* object[3]; + std::vector object; int modelCount; Oyster::Network::NetworkClient* nwClient; gameStateState state; @@ -59,15 +59,17 @@ bool GameState::LoadModels(std::wstring mapFile) modelData.visible = true; modelData.modelPath = L"worldDummy"; // load models - privData->object[0] = new C_Player(); - privData->object[0]->Init(modelData); + C_Object* obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); modelData.world = modelData.world * translate; modelData.modelPath = L"crate"; - privData->object[1] = new C_DynamicObj(); - privData->object[1]->Init(modelData); + obj = new C_DynamicObj(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); return true; } bool GameState::InitCamera(Oyster::Math::Float3 startPos) @@ -174,7 +176,7 @@ bool GameState::Render() } bool GameState::Release() { - for (int i = 0; i < privData->modelCount; i++) + for (int i = 0; i < privData->object.size(); i++) { privData->object[i]->Release(); delete privData->object[i]; @@ -209,7 +211,11 @@ void GameState::Protocol( ObjPos* pos ) { world[i] = pos->worldPos[i]; } - privData->object[pos->object_ID]->setPos(world); + for (int i = 0; i < privData->object.size(); i++) + { + if(privData->object[i]->GetId() == pos->object_ID) + privData->object[i]->setPos(world); + } } void GameState::Protocol( NewObj* pos ) @@ -224,45 +230,29 @@ void GameState::Protocol( NewObj* pos ) modelData.world = world; modelData.visible = true; + modelData.id = pos->object_ID; //not sure if this is good parsing rom char* to wstring const char* path = pos->path; modelData.modelPath = std::wstring(path, path + strlen(path)); // load models - privData->object[pos->object_ID] = new C_Player(); - privData->object[pos->object_ID]->Init(modelData); -} + C_Object* player = new C_Player(); + player->Init(modelData); + + privData->object.push_back(player); -void GameState::Protocol( KeyInput* pos ) -{ - bool key = false; - for (int i = 0; i < 6; i++) - { - key = pos->key[i]; - } } void DanBias::Client::GameState::Protocol( RemoveObj* obj ) { - privData->object[obj->object_ID]->Release( ); -} - -void GameState::PlayerPosProtocol(PlayerPos* pos) -{ - Oyster::Math::Float4x4 world, translate; - - world = Oyster::Math::Float4x4::identity; - translate = Oyster::Math::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2] )); - world = translate; - privData->object[0]->setPos( world ); -} -void GameState::ObjectPosProtocol(ObjPos* pos) -{ - Oyster::Math::Float4x4 world; - for(int i = 0; i<16; i++) + for (int i = 0; i < privData->object.size(); i++) { - world[i] = pos->worldPos[i]; + if(privData->object[i]->GetId() == obj->object_ID) + { + privData->object.at(i)->Release(); + privData->object.erase(privData->object.begin() + i ); + } } - privData->object[1]->setPos(world); + //privData->object[obj->object_ID]->Release( ); } + //void GameState::Protocol(LightPos pos); \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index bc0e8dba..4de73a39 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -34,11 +34,8 @@ public: void Protocol(ProtocolStruct* pos)override; void Protocol(PlayerPos* pos); void Protocol(ObjPos* pos); - void Protocol(KeyInput* pos); void Protocol( NewObj* pos ); void Protocol(RemoveObj* obj); - void PlayerPosProtocol(PlayerPos* pos); - void ObjectPosProtocol(ObjPos* pos); //void Protocol(LightPos pos); }; }; diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 6b82da2a..76597e77 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -5,8 +5,8 @@ #include #include -#include "DanBiasServerAPI.h" -//#include "DanBiasGame.h" +//#include "DanBiasServerAPI.h" +#include "DanBiasGame.h" int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) @@ -29,7 +29,8 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh // Game client starter code goes here DanBias::DanBiasGameDesc gameDesc; gameDesc.port = 15151; - gameDesc.IP = "193.11.184.196"; + //gameDesc.IP = "193.11.184.196"; //Erik + gameDesc.IP = "193.11.186.101"; gameDesc.hinst = hinst; gameDesc.nCmdShow = cmdShow;