From bfa748047ff73e7d2209d9a370f41ed85e484c7d Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 13:31:36 +0100 Subject: [PATCH 01/21] GL - added RigidBody data on client for debuging output --- .../GameClient/GameClientState/C_Object.cpp | 75 ++++++++++++++----- .../GameClient/GameClientState/C_Object.h | 36 +++++++-- .../GameClient/GameClientState/GameState.cpp | 47 ++++++++++++ .../GameClientState/NetLoadState.cpp | 39 +++++++++- 4 files changed, 172 insertions(+), 25 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index 92b55c53..dc22f34d 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -31,32 +31,27 @@ void C_Object::updateWorld() { Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); - //Oyster::Math3D::Float4x4 scale = Oyster::Math3D::; - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Matrix::identity; - scale.v[0].x = this->scale[0]; - scale.v[1].y = this->scale[1]; - scale.v[2].z = this->scale[2]; + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); world = translation * rot * scale; model->WorldMatrix = world; } -void C_Object::setWorld(Oyster::Math::Float4x4 world) -{ - model->WorldMatrix = world; -} Oyster::Math::Float4x4 C_Object::getWorld() const { + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); + Oyster::Math3D::Float4x4 world = translation * rot * scale; + return world; } void C_Object::setPos(Oyster::Math::Float3 newPos) { this->position = newPos; - updateWorld(); } void C_Object::addPos(Oyster::Math::Float3 deltaPos) { this->position += deltaPos; - updateWorld(); } Oyster::Math::Float3 C_Object::getPos() const { @@ -65,12 +60,6 @@ Oyster::Math::Float3 C_Object::getPos() const void C_Object::setRot(Oyster::Math::Quaternion newRot) { this->rotation = newRot; - updateWorld(); -} -void C_Object::addRot(Oyster::Math::Quaternion deltaRot) -{ - this->rotation += deltaRot; - updateWorld(); } Oyster::Math::Quaternion C_Object::getRotation() const { @@ -79,12 +68,10 @@ Oyster::Math::Quaternion C_Object::getRotation() const void C_Object::setScale(Oyster::Math::Float3 newScale) { this->scale = newScale; - updateWorld(); } void C_Object::addScale(Oyster::Math::Float3 deltaScale) { this->scale += deltaScale; - updateWorld(); } Oyster::Math::Float3 C_Object::getScale() const { @@ -105,4 +92,54 @@ void C_Object::Release() Oyster::Graphics::API::DeleteModel(model); this->model = nullptr; } +} + + + +//////////////////////////////////////////////// +// RB DEBUG +//////////////////////////////////////////////// +bool C_Object::InitRB(RBInitData RBInit) +{ + RBposition = RBInit.position; + RBrotation = RBInit.rotation; + RBscale = RBInit.scale; + return true; +} +Oyster::Math::Float4x4 C_Object::getRBWorld() const +{ + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->RBposition); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->RBrotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->RBscale); + Oyster::Math3D::Float4x4 world = translation * rot * scale; + + return world; +} +void C_Object::setRBPos(Oyster::Math::Float3 newPos) +{ + this->RBposition = newPos; +} +Oyster::Math::Float3 C_Object::getRBPos() const +{ + return this->RBposition; +} +void C_Object::setRBRot(Oyster::Math::Quaternion newRot) +{ + this->RBrotation = newRot; +} +Oyster::Math::Quaternion C_Object::getRBRotation() const +{ + return this->RBrotation; +} +void C_Object::setRBScale(Oyster::Math::Float3 newScale) +{ + this->RBscale = newScale; +} +Oyster::Math::Float3 C_Object::getRBScale() const +{ + return this->RBscale; +} +RB_Type C_Object::getBRtype()const +{ + return this->type; } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index 20e0eb60..d0b86a41 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -5,7 +5,11 @@ namespace DanBias { namespace Client { - + enum RB_Type + { + RB_Type_Cube, + RB_Type_Sphere + }; struct ModelInitData { int id; @@ -15,6 +19,13 @@ namespace DanBias Oyster::Math::Float3 scale; bool visible; }; + struct RBInitData + { + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + RB_Type type; + }; class C_Object { @@ -23,28 +34,43 @@ namespace DanBias Oyster::Math::Float3 position; Oyster::Math::Quaternion rotation; Oyster::Math::Float3 scale; + + // RB DEBUG + Oyster::Math::Float3 RBposition; + Oyster::Math::Quaternion RBrotation; + Oyster::Math::Float3 RBscale; + RB_Type type; int id; - void updateWorld(); + protected: Oyster::Graphics::Model::Model *model; public: C_Object(); virtual ~C_Object(); virtual bool Init(ModelInitData modelInit); - - void setWorld(Oyster::Math::Float4x4 world); + void updateWorld(); + //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; + // RB DEBUG + bool InitRB(RBInitData modelInit); + Oyster::Math::Float4x4 getRBWorld() const; + void setRBPos(Oyster::Math::Float3 newPos); + Oyster::Math::Float3 getRBPos() const; + void setRBRot(Oyster::Math::Quaternion newRot); + Oyster::Math::Quaternion getRBRotation() const; + void setRBScale(Oyster::Math::Float3 newScale); + Oyster::Math::Float3 getRBScale() const; + RB_Type getBRtype()const; virtual void Render(); virtual void Release(); virtual int GetId() const; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index f590f366..cf35b7c1 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -108,10 +108,19 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa StringToWstring( modelName, modelData.modelPath ); modelData.id = id; + // RB DEBUG + RBInitData RBData; + RBData.position = position; + RBData.rotation = ArrayToQuaternion( rotation ); + RBData.scale = Float3( 3 ); + if( isMyPlayer ) { if( this->privData->player.Init(modelData) ) { + // RB DEBUG + this->privData->player.InitRB( RBData ); + this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); Float3 offset = Float3( 0.0f ); @@ -125,6 +134,9 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa C_DynamicObj *p = new C_DynamicObj(); if( p->Init(modelData) ) { + // RB DEBUG + this->privData->player.InitRB( RBData ); + (*this->privData->dynamicObjects)[id] = p; } } @@ -157,6 +169,41 @@ bool GameState::Render() dynamicObject->second->Render(); } + // RB DEBUG render wire frame + Oyster::Graphics::API::StartRenderWireFrame(); + + + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 2, 2, 2)); + Oyster::Math3D::Float4x4 world = translation * scale; + Oyster::Graphics::API::RenderDebugCube( world ); + Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + + + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + { + if( staticObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); + } + if( staticObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); + } + } + + + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) + { + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } + } Oyster::Graphics::API::EndFrame(); return true; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 7443344e..706e0d53 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -134,10 +134,29 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) desc.rotation = ArrayToQuaternion( oh->rotation ); desc.scale = oh->scale; desc.visible = true; - + C_StaticObj *staticObject = new C_StaticObj(); if( staticObject->Init( desc ) ) { + + // RB DEBUG + RBInitData RBData; + if(oh->boundingVolume.geoType == CollisionGeometryType_Box) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + staticObject->InitRB( RBData ); + } + + if(oh->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + staticObject->InitRB( RBData ); + } + (*this->privData->staticObjects)[objectID] = staticObject; } else @@ -161,6 +180,24 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) C_DynamicObj *dynamicObject = new C_DynamicObj(); if( dynamicObject->Init( desc ) ) { + // RB DEBUG + RBInitData RBData; + if(oh->boundingVolume.geoType == CollisionGeometryType_Box) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + dynamicObject->InitRB( RBData ); + } + + if(oh->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + dynamicObject->InitRB( RBData ); + } + (*this->privData->dynamicObjects)[objectID] = dynamicObject; } else From 0971bc407e74a94ccab21617481bbe6dfc24b6d6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 14:23:38 +0100 Subject: [PATCH 02/21] Small fix --- Code/Game/GameClient/GameClientState/GameState.cpp | 6 +++--- Code/OysterGraphics/FileLoader/ModelLoader.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 79f3c471..1afba43d 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,7 +81,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Math::pi/8, aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -108,7 +108,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBInitData RBData; RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); - RBData.scale = Float3( 3 ); + RBData.scale = Float3( 1 ); if( isMyPlayer ) { @@ -170,7 +170,7 @@ bool GameState::Render() Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 2, 2, 2)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); Oyster::Math3D::Float4x4 world = translation * scale; Oyster::Graphics::API::RenderDebugCube( world ); Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index ba0928cc..0c7125fd 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -700,7 +700,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, return hr; } //todo check calc - int TexSize = twidth * theight * bpp; + int TexSize = twidth * theight * (int)bpp; Oyster::Graphics::Core::UsedMem += TexSize; if ( autogen ) From e8b0e75ed7773623e1fef3bbb0cbb305f0be101e Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 15:07:40 +0100 Subject: [PATCH 03/21] Render rigid body from lvl format --- .../GameClient/GameClientState/C_Object.cpp | 8 +++++- .../GameClient/GameClientState/C_Object.h | 25 ++++++++++++------- .../GameClient/GameClientState/GameState.cpp | 12 ++++++--- .../GameClientState/NetLoadState.cpp | 6 +++++ Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index dc22f34d..ccea9a86 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -9,6 +9,10 @@ C_Object::C_Object() id = 0; model = NULL; + + // RB DEBUG + type = RB_Type_None; + // !RB DEBUG } C_Object::~C_Object() { @@ -104,6 +108,7 @@ bool C_Object::InitRB(RBInitData RBInit) RBposition = RBInit.position; RBrotation = RBInit.rotation; RBscale = RBInit.scale; + type = RBInit.type; return true; } Oyster::Math::Float4x4 C_Object::getRBWorld() const @@ -142,4 +147,5 @@ Oyster::Math::Float3 C_Object::getRBScale() const RB_Type C_Object::getBRtype()const { return this->type; -} \ No newline at end of file +} +// !RB DEBUG \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index d0b86a41..dcc2731c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -5,11 +5,22 @@ namespace DanBias { namespace Client { + // RB DEBUG enum RB_Type { RB_Type_Cube, - RB_Type_Sphere + RB_Type_Sphere, + RB_Type_None, }; + struct RBInitData + { + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + RB_Type type; + }; + // !RB DEBUG + struct ModelInitData { int id; @@ -19,13 +30,6 @@ namespace DanBias Oyster::Math::Float3 scale; bool visible; }; - struct RBInitData - { - Oyster::Math::Float3 position; - Oyster::Math::Quaternion rotation; - Oyster::Math::Float3 scale; - RB_Type type; - }; class C_Object { @@ -40,7 +44,8 @@ namespace DanBias Oyster::Math::Quaternion RBrotation; Oyster::Math::Float3 RBscale; RB_Type type; - + // !RB DEBUG + int id; protected: @@ -71,6 +76,8 @@ namespace DanBias void setRBScale(Oyster::Math::Float3 newScale); Oyster::Math::Float3 getRBScale() const; RB_Type getBRtype()const; + // !RB DEBUG + virtual void Render(); virtual void Release(); virtual int GetId() const; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1afba43d..ba333061 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,7 +81,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Math::pi/8, aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Math::pi/2, aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -109,6 +109,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); RBData.scale = Float3( 1 ); + // !RB DEBUG if( isMyPlayer ) { @@ -116,6 +117,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { // RB DEBUG this->privData->player.InitRB( RBData ); + // !RB DEBUG this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); @@ -132,6 +134,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { // RB DEBUG this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[id] = p; } @@ -168,14 +171,13 @@ bool GameState::Render() // RB DEBUG render wire frame Oyster::Graphics::API::StartRenderWireFrame(); - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); Oyster::Math3D::Float4x4 world = translation * scale; Oyster::Graphics::API::RenderDebugCube( world ); Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); - + staticObject = this->privData->staticObjects->begin(); for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { if( staticObject->second->getBRtype() == RB_Type_Cube) @@ -188,7 +190,7 @@ bool GameState::Render() } } - + dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { if( dynamicObject->second->getBRtype() == RB_Type_Cube) @@ -200,6 +202,8 @@ bool GameState::Render() Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); } } + // !RB DEBUG + Oyster::Graphics::API::EndFrame(); return true; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 706e0d53..2fe143d6 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -146,6 +146,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; staticObject->InitRB( RBData ); } @@ -154,8 +155,10 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; staticObject->InitRB( RBData ); } + // !RB DEBUG (*this->privData->staticObjects)[objectID] = staticObject; } @@ -187,6 +190,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; dynamicObject->InitRB( RBData ); } @@ -195,8 +199,10 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; dynamicObject->InitRB( RBData ); } + // !RB DEBUG (*this->privData->dynamicObjects)[objectID] = dynamicObject; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..96e2bbe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -197,6 +197,7 @@ namespace Oyster void API::StartRenderWireFrame() { Core::deviceContext->RSSetState(wire); + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); } void API::RenderDebugCube(Math::Matrix world) From 60d44d76d8d5ef19aaf54ca67403a87f50d8d0bf Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 15:20:53 +0100 Subject: [PATCH 04/21] using new models --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..cd164f1c 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -24,6 +24,8 @@ namespace Oyster Model::Model* sphere; ID3D11RasterizerState* wire; + + ID3D11ShaderResourceView* debugSRV; #endif } @@ -50,8 +52,14 @@ namespace Oyster Render::Preparations::Basic::SetViewPort(); #ifdef _DEBUG //fix load model - cube = CreateModel(L"debug_cube.dan"); - sphere = CreateModel(L"debug_sphere.dan"); + + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + + cube = CreateModel(L"generic_cube.dan"); + cube->Tint = Math::Float3(0.0f,0.0f,1.0f); + sphere = CreateModel(L"generic_sphere.dan"); + D3D11_RASTERIZER_DESC desc; desc.CullMode = D3D11_CULL_BACK; @@ -196,6 +204,7 @@ namespace Oyster void API::StartRenderWireFrame() { + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); Core::deviceContext->RSSetState(wire); } From 02312c53a4f55135e9b3a9829285b361d7ba225a Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 15:41:59 +0100 Subject: [PATCH 05/21] changed debug models and tinted pink spheres --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 93052730..ccb811c1 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -59,6 +59,7 @@ namespace Oyster cube = CreateModel(L"generic_cube.dan"); cube->Tint = Math::Float3(0.0f,0.0f,1.0f); sphere = CreateModel(L"generic_sphere.dan"); + sphere->Tint = Math::Float3(1.0f,0.5f,182/255.0f); D3D11_RASTERIZER_DESC desc; From 611e75b5052c420f3449cb36d3b1fff56b9dd741 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 15:54:09 +0100 Subject: [PATCH 06/21] Toggle wireframe with "T" --- .../GameClient/GameClientState/GameState.cpp | 134 ++++++++++++------ 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index ba333061..66b8fc61 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -36,7 +36,11 @@ struct GameState::MyData bool key_Shoot; bool key_Jump; + // DEGUG KEYS bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS C_Player player; Camera_FPS camera; @@ -90,7 +94,12 @@ bool GameState::Init( SharedStateContent &shared ) // Debugg hack this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); // end debug hack - + // DEGUG KEYS + this->privData->key_Reload_Shaders = false; + this->privData->key_Wireframe_Toggle = false; + this->privData->renderWhireframe = false; + // !DEGUG KEYS + return true; } @@ -169,37 +178,40 @@ bool GameState::Render() } // RB DEBUG render wire frame - Oyster::Graphics::API::StartRenderWireFrame(); - - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); - Oyster::Math3D::Float4x4 world = translation * scale; - Oyster::Graphics::API::RenderDebugCube( world ); - Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); - - staticObject = this->privData->staticObjects->begin(); - for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + if(this->privData->renderWhireframe) { - if( staticObject->second->getBRtype() == RB_Type_Cube) - { - Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); - } - if( staticObject->second->getBRtype() == RB_Type_Sphere) - { - Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); - } - } + Oyster::Graphics::API::StartRenderWireFrame(); - dynamicObject = this->privData->dynamicObjects->begin(); - for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) - { - if( dynamicObject->second->getBRtype() == RB_Type_Cube) + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); + Oyster::Math3D::Float4x4 world = translation * scale; + Oyster::Graphics::API::RenderDebugCube( world ); + Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + + staticObject = this->privData->staticObjects->begin(); + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { - Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + if( staticObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); + } + if( staticObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); + } } - if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + + dynamicObject = this->privData->dynamicObjects->begin(); + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } } } // !RB DEBUG @@ -283,21 +295,6 @@ void GameState::ReadKeyInput() else this->privData->key_strafeRight = false; - if( this->privData->input->IsKeyPressed(DIK_R) ) - { - if( !this->privData->key_Reload_Shaders ) - { - //this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); -#ifdef _DEBUG - Graphics::API::ReloadShaders(); -#endif - this->privData->key_Reload_Shaders = true; - } - } - else - this->privData->key_Reload_Shaders = false; - - //send delta mouse movement { this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); @@ -363,6 +360,35 @@ void GameState::ReadKeyInput() 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 } @@ -387,12 +413,18 @@ void GameState::DataRecieved( NetEventprivData->camera.SetPosition( decoded.position ); (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectRotation: @@ -405,6 +437,9 @@ void GameState::DataRecieved( NetEventprivData->camera.SetAngular( AngularAxis(rotation) ); (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectPositionRotation: @@ -423,6 +458,10 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]; object->setPos( position ); object->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( position ); + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ @@ -446,7 +485,7 @@ void GameState::DataRecieved( NetEventInit(modelData); + // RB DEBUG + // Is just using the model position since the rigid body data should never be sent to the client + RBInitData RBData; + RBData.position = decoded.position; + RBData.rotation = ArrayToQuaternion( decoded.position ); + RBData.scale = Float3( decoded.scale ); + + this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[decoded.object_ID] = object; From 6ef0a7caa676b74a0e661138f3fe8368261563ca Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 10:59:23 +0100 Subject: [PATCH 07/21] Added lights to client --- Code/Game/GameClient/GameClient.vcxproj | 2 + .../GameClient/GameClientState/C_Light.cpp | 37 +++++++++++++++++++ .../Game/GameClient/GameClientState/C_Light.h | 29 +++++++++++++++ .../GameClient/GameClientState/GameState.cpp | 25 ++++++++++++- .../GameClientState/NetLoadState.cpp | 26 ++++++++++++- .../GameClientState/SharedStateContent.h | 2 + .../OysterGraphics.vcxproj.user | 2 +- 7 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/C_Light.cpp create mode 100644 Code/Game/GameClient/GameClientState/C_Light.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 3daafff3..7a962975 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -202,6 +202,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/Code/Game/GameClient/GameClientState/C_Light.cpp b/Code/Game/GameClient/GameClientState/C_Light.cpp new file mode 100644 index 00000000..17016ae5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.cpp @@ -0,0 +1,37 @@ +#include "C_Light.h" +using namespace DanBias::Client; +C_Light::C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ) +{ + this->pointLightDesc = pointLightDesc; + this->id = id; +} +C_Light::~C_Light() +{ + +} +Oyster::Graphics::Definitions::Pointlight C_Light::getLightDesc() const +{ + return this->pointLightDesc; +} +void C_Light::setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ) +{ + this->pointLightDesc = pointLightDesc; +} +Oyster::Math::Float3 C_Light::getPos() const +{ + return this->pointLightDesc.Pos; +} +void C_Light::setPos( Oyster::Math::Float3 newPos) +{ + this->pointLightDesc.Pos = newPos; +} + +int C_Light::GetId() const +{ + return this->id; +} +void C_Light::Render() +{ + // will be changed to new API + Oyster::Graphics::API::AddLight(pointLightDesc); +} diff --git a/Code/Game/GameClient/GameClientState/C_Light.h b/Code/Game/GameClient/GameClientState/C_Light.h new file mode 100644 index 00000000..4802339d --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_CLIGHT_H +#define DANBIAS_CLIENT_CLIGHT_H +#include "DllInterfaces/GFXAPI.h" +namespace DanBias +{ + namespace Client + { + class C_Light + { + private: + Oyster::Graphics::Definitions::Pointlight pointLightDesc; + int id; + + public: + C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ); + virtual ~C_Light(); + + Oyster::Graphics::Definitions::Pointlight getLightDesc() const; + void setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ); + + Oyster::Math::Float3 getPos() const; + void setPos( Oyster::Math::Float3 newPos); + void Render(); + int GetId() const; + }; + } +} + +#endif diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 66b8fc61..59a16f6b 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -4,7 +4,7 @@ #include "NetworkClient.h" #include "Camera_FPS.h" #include - +#include "C_Light.h" #include "C_obj/C_Player.h" #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" @@ -28,6 +28,7 @@ struct GameState::MyData ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool key_forward; bool key_backward; @@ -82,10 +83,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->input = shared.input; this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; + this->privData->lights = &shared.lights; Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Math::pi/2, aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -100,6 +102,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->renderWhireframe = false; // !DEGUG KEYS + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } return true; } @@ -177,6 +184,13 @@ bool GameState::Render() dynamicObject->second->Render(); } + + /*auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + }*/ + // RB DEBUG render wire frame if(this->privData->renderWhireframe) { @@ -236,8 +250,15 @@ bool GameState::Release() dynamicObject->second = nullptr; } + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } + this->privData->staticObjects->clear(); this->privData->dynamicObjects->clear(); + this->privData->lights->clear(); privData = NULL; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 2fe143d6..2f8fbe6c 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -6,6 +6,7 @@ #include "Utilities.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -23,6 +24,7 @@ struct NetLoadState::MyData Graphics::API::Texture background; ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool loading; }; @@ -49,6 +51,7 @@ bool NetLoadState::Init( SharedStateContent &shared ) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->dynamicObjects = &shared.dynamicObjects; this->privData->staticObjects = &shared.staticObjects; + this->privData->lights = &shared.lights; this->privData->loading = false; @@ -214,12 +217,33 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) break; case ObjectType::ObjectType_Light: { - /* TODO: implement light into the leveformat */ + BasicLight *light = (BasicLight*)oth; + Graphics::Definitions::Pointlight pointLight; + + pointLight.Color = light->color; + pointLight.Pos = light->position; + pointLight.Bright = light->intensity; + pointLight.Radius = light->raduis; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; } break; default: break; } } + // DEBUG added a static light for testing + Graphics::Definitions::Pointlight pointLight; + pointLight.Color = Float3(1,1,0); + pointLight.Pos = Float3( 0,132, 10); + pointLight.Bright = 2; + pointLight.Radius = 50; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; + this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index da9dc759..49d01775 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -13,6 +13,7 @@ #include "C_Object.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" #include "NetworkClient.h" #include "L_inputClass.h" @@ -23,6 +24,7 @@ namespace DanBias { namespace Client public: ::std::map> staticObjects; ::std::map> dynamicObjects; + ::std::map> lights; ::Oyster::Network::NetworkClient *network; InputClass* input; }; diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 3f030911..9a0b0ae0 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@  - false + true \ No newline at end of file From 7f8c10292efd509b56e42f602d5b8957a566f939 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 19 Feb 2014 11:00:16 +0100 Subject: [PATCH 08/21] Moved LevelLoader to a seperate lib project. --- Code/DanBias.sln | 37 +++ Code/Game/GameClient/GameClient.vcxproj | 20 +- .../GameClientState/LanMenuState.cpp | 3 + .../GameClientState/NetLoadState.cpp | 2 +- Code/Game/GameLogic/GameAPI.h | 2 +- Code/Game/GameLogic/GameLogic.vcxproj | 20 +- Code/Game/GameLogic/Level.h | 2 +- .../GameLogic/LevelLoader/LevelLoader.cpp | 52 --- Code/Game/GameLogic/LevelLoader/LevelLoader.h | 56 ---- .../GameLogic/LevelLoader/LevelParser.cpp | 314 ------------------ Code/Game/GameLogic/LevelLoader/LevelParser.h | 31 -- Code/Game/GameLogic/LevelLoader/Loader.cpp | 22 -- Code/Game/GameLogic/LevelLoader/Loader.h | 28 -- .../GameLogic/LevelLoader/ObjectDefines.h | 274 --------------- .../GameLogic/LevelLoader/ParseFunctions.cpp | 183 ---------- .../GameLogic/LevelLoader/ParseFunctions.h | 28 -- .../LevelLoader/LevelLoader.cpp | 0 .../LevelLoader/LevelLoader.h | 0 Code/Game/LevelLoader/LevelLoader.vcxproj | 165 +++++++++ .../Game/LevelLoader/LevelLoader.vcxproj.user | 22 ++ .../LevelLoader/LevelParser.cpp | 2 +- .../LevelLoader/LevelParser.h | 0 .../LevelLoader/Loader.cpp | 0 .../GameClientState => }/LevelLoader/Loader.h | 0 .../LevelLoader/ObjectDefines.h | 3 +- .../LevelLoader/ParseFunctions.cpp | 2 +- .../LevelLoader/ParseFunctions.h | 0 Code/Network/NetworkAPI/NetworkClient.cpp | 18 +- 28 files changed, 265 insertions(+), 1021 deletions(-) delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelLoader.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelLoader.h delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelParser.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelParser.h delete mode 100644 Code/Game/GameLogic/LevelLoader/Loader.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/Loader.h delete mode 100644 Code/Game/GameLogic/LevelLoader/ObjectDefines.h delete mode 100644 Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/ParseFunctions.h rename Code/Game/{GameClient/GameClientState => }/LevelLoader/LevelLoader.cpp (100%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/LevelLoader.h (100%) create mode 100644 Code/Game/LevelLoader/LevelLoader.vcxproj create mode 100644 Code/Game/LevelLoader/LevelLoader.vcxproj.user rename Code/Game/{GameClient/GameClientState => }/LevelLoader/LevelParser.cpp (99%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/LevelParser.h (100%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/Loader.cpp (100%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/Loader.h (100%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/ObjectDefines.h (98%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/ParseFunctions.cpp (99%) rename Code/Game/{GameClient/GameClientState => }/LevelLoader/ParseFunctions.h (100%) diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 80a76dea..e14d2c37 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -45,6 +45,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameClient", "Game\GameClie EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Utilities", "Misc\Utilities\Utilities.vcxproj", "{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LevelLoader", "Game\LevelLoader\LevelLoader.vcxproj", "{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -679,6 +681,40 @@ Global {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.RelWithDebInfo|x64.Build.0 = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.RelWithDebInfo|x86.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Win32.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Win32.Build.0 = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x64.ActiveCfg = Debug|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x64.Build.0 = Debug|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x86.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x86.Build.0 = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Any CPU.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Any CPU.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Mixed Platforms.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Win32.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Win32.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x64.ActiveCfg = Release|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x64.Build.0 = Release|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x86.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x86.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -692,6 +728,7 @@ Global {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} = {20720CA7-795C-45AD-A302-9383A6DD503A} {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} {2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63} = {20720CA7-795C-45AD-A302-9383A6DD503A} {C4C76A8D-44C5-4452-9F61-39C7E01CBDB4} = {F156EEBC-0195-4020-8700-4433208DE12B} {3EA5F14D-2A71-4588-A69D-87C4571C580F} = {F156EEBC-0195-4020-8700-4433208DE12B} {7E3990D2-3D94-465C-B58D-64A74B3ECF9B} = {1322B12B-5E37-448A-AAAF-F637460DCB23} diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 349a88ec..05c87021 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -106,7 +106,7 @@ Disabled DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -123,7 +123,7 @@ Disabled DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -142,7 +142,7 @@ true DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -163,7 +163,7 @@ true DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -196,6 +196,9 @@ {143bd516-20a1-4890-a3e4-f8bfd02220e7} + + {6391e709-d9fa-4fef-a3b9-4343db5a0c63} + @@ -212,10 +215,6 @@ - - - - @@ -238,11 +237,6 @@ - - - - - diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 11ca95da..38a3446e 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -126,6 +126,9 @@ void LanMenuState::ChangeState( ClientState next ) // attempt to connect to lobby if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) return; + //this->privData->nwClient->Disconnect(); + //if( !this->privData->nwClient->Reconnect() ) + //return; break; default: break; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 29906d77..44a14359 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -2,7 +2,7 @@ #include "NetworkClient.h" #include "OysterMath.h" #include "Protocols.h" -#include "LevelLoader\LevelLoader.h" +#include "LevelLoader.h" #include "Utilities.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 3325115f..1cc35444 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -12,7 +12,7 @@ #include "GameLogicDef.h" #include "GameLogicStates.h" #include -#include "LevelLoader\ObjectDefines.h" +#include "..\LevelLoader\ObjectDefines.h" #include "DynamicArray.h" diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index ad129c3b..52b7722b 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -99,7 +99,7 @@ Level3 Disabled true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -113,7 +113,7 @@ Level3 Disabled true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -129,7 +129,7 @@ true true true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -147,7 +147,7 @@ true true true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -172,12 +172,7 @@ - - - - - @@ -198,11 +193,7 @@ - - - - @@ -223,6 +214,9 @@ {3ea5f14d-2a71-4588-a69d-87c4571c580f} + + {6391e709-d9fa-4fef-a3b9-4343db5a0c63} + diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 623d04b2..6149b2fb 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -14,7 +14,7 @@ #include "PhysicsAPI.h" #include "TeamManager.h" #include "DynamicArray.h" -#include "LevelLoader/LevelLoader.h" +#include "LevelLoader.h" namespace GameLogic { diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp deleted file mode 100644 index 8fe880f3..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ /dev/null @@ -1,52 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "LevelLoader.h" -#include "LevelParser.h" - -using namespace GameLogic; -using namespace GameLogic::LevelFileLoader; - -struct LevelLoader::PrivData -{ - LevelParser parser; - std::string folderPath; -}; - -LevelLoader::LevelLoader() - : pData(new PrivData) -{ - //standard path - pData->folderPath = ""; -} - -LevelLoader::LevelLoader(std::string folderPath) - : pData(new PrivData) -{ - pData->folderPath = folderPath; -} - -LevelLoader::~LevelLoader() -{ -} - -std::vector> LevelLoader::LoadLevel(std::string fileName) -{ - return pData->parser.Parse(pData->folderPath + fileName); -} - -LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) -{ - return pData->parser.ParseHeader(pData->folderPath + fileName); -} - -std::string LevelLoader::GetFolderPath() -{ - return this->pData->folderPath; -} - -void LevelLoader::SetFolderPath(std::string folderPath) -{ - -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h deleted file mode 100644 index aa67c4f5..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef LEVELLOADER_H -#define LEVELLOADER_H - -#include -#include -#include "Utilities.h" -#include "ObjectDefines.h" - -namespace GameLogic -{ - class LevelLoader - { - - public: - LevelLoader(); - /*********************************************************** - * Lets you set the standard folderpath for the levels - ********************************************************/ - LevelLoader(std::string folderPath); - ~LevelLoader(); - - /******************************************************** - * Loads the level and objects from file. - * @param fileName: Path/name to the level-file that you want to load. - * @return: Returns all structs with objects and information about the level. - ********************************************************/ - std::vector> LoadLevel(std::string fileName); - - /******************************************************** - * Just for fast access for the meta information about the level. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns the meta information about the level. - ********************************************************/ - LevelMetaData LoadLevelHeader(std::string fileName); //. - - /*********************************************************** - * @return: Returns the current standard folder path - ********************************************************/ - std::string GetFolderPath(); - - /*********************************************************** - * Sets the standard folder path - ********************************************************/ - void SetFolderPath(std::string folderPath); - - private: - struct PrivData; - Utility::DynamicMemory::SmartPointer pData; - }; -} - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp deleted file mode 100644 index 1e33361d..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ /dev/null @@ -1,314 +0,0 @@ -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "LevelParser.h" -#include "Loader.h" -#include "ParseFunctions.h" - -using namespace GameLogic; -using namespace ::LevelFileLoader; -using namespace Utility::DynamicMemory; - -LevelParser::LevelParser() -{ - formatVersion.formatVersionMajor = 3; - formatVersion.formatVersionMinor = 0; -} - -LevelParser::~LevelParser() -{ -} - -std::vector> LevelParser::Parse(std::string filename) -{ - int bufferSize = 0; - int counter = 0; - bool loadCgf; - - std::vector> objects; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - //Read format version - LevelLoaderInternal::FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); - counter += sizeof(levelFormatVersion); - if(this->formatVersion != levelFormatVersion) - { - //Returns an empty vector, because it will most likely fail to read the level format. - return objects; - } - - while(counter < bufferSize) - { - loadCgf = true; - //Get typeID - ObjectType typeID; - ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - switch((int)typeID) - { - case ObjectType_LevelMetaData: - { - SmartPointer header = new LevelMetaData; - ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); - objects.push_back(header); - break; - } - - case ObjectType_SpawnPoint: - { - loadCgf = false; - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - SpawnPointAttributes* spawn = new SpawnPointAttributes; - - spawn->typeID = header->typeID; - - for(int i = 0; i < 3; i++) - { - spawn->position[i] = header->position[i]; - } - - delete header; - //objects.push_back(header); - objects.push_back(spawn); - break; - } - - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. - //Unless they are changed to not be the same. - case ObjectType_Static: case ObjectType_Dynamic: - { - //Get specialType. - ObjectSpecialType specialType; - ParseObject(&buffer[counter+4], &specialType, sizeof(typeID)); - - switch(specialType) - { - //there is no difference when parsing these specialTypes. - case ObjectSpecialType_CrystalShard: - case ObjectSpecialType_CrystalFormation: - case ObjectSpecialType_Spike: - case ObjectSpecialType_SpikeBox: - case ObjectSpecialType_RedExplosiveBox: - case ObjectSpecialType_StandardBox: - case ObjectSpecialType_Stone: - case ObjectSpecialType_Building: - { - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - objects.push_back(header); - - break; - } - - case ObjectSpecialType_JumpPad: - { - JumpPadAttributes* header = new JumpPadAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - //Read the spec - ParseObject(&buffer[counter], header->direction, 16); - counter += 16; - objects.push_back(header); - - break; - } - - case ObjectSpecialType_Portal: - { - PortalAttributes* header = new PortalAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - ParseObject(&buffer[counter], header->destination, 12); - counter += 12; - objects.push_back(header); - - break; - } - - case ObjectSpecialType_World: - { - WorldAttributes* header = new WorldAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - ParseObject(&buffer[counter], &header->worldSize, 8); - counter += 8; - objects.push_back(header); - break; - } - - case ObjectSpecialType_Sky: - { - loadCgf = false; - SkyAttributes* header = new SkyAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - ParseObject(&buffer[counter], &header->skySize, 4); - counter += 4; - objects.push_back(header); - break; - } - - default: - //Couldn't find specialType - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - - //Get Light type - ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - - //We only support PointLight for now. - BasicLight* header = new BasicLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - /*switch(lightType) - { - case LightType_PointLight: - { - PointLight* header = new PointLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_DirectionalLight: - { - DirectionalLight* header = new DirectionalLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_SpotLight: - { - SpotLight* header = new SpotLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - default: - //Undefined LightType. - break; - } - break;*/ - } - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return objects; -} - -//för meta information om leveln. -LevelMetaData LevelParser::ParseHeader(std::string filename) -{ - int bufferSize = 0; - int counter = 0; - - LevelMetaData levelHeader; - levelHeader.typeID = ObjectType::ObjectType_Unknown; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - //Read format version - LevelLoaderInternal::FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); - counter += sizeof(levelFormatVersion); - if(this->formatVersion != levelFormatVersion) - { - //Do something if it's not the same version - - //Returns an empty levelHeader with ObjectType_Unknown. - //Because it will not be able to read another version of the level format. - return levelHeader; - } - - //Find the header in the returned string. - while(counter < bufferSize) - { - ObjectType typeID; - ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - - switch(typeID) - { - case ObjectType_LevelMetaData: - ParseLevelMetaData(&buffer[counter], levelHeader, counter); - return levelHeader; - break; - - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. - case ObjectType_Static: case ObjectType_Dynamic: - { - ObjectHeader header; - ParseObject(&buffer[counter], &header, counter); - - switch(header.specialTypeID) - { - case ObjectSpecialType_JumpPad: - counter += sizeof(16); - break; - case ObjectSpecialType_Portal: - counter += sizeof(12); - break; - default: - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - - //We only support pointlight for now. - counter += sizeof(BasicLight); - /* - switch(lightType) - { - case LightType_PointLight: - { - counter += sizeof(PointLight); - break; - } - case LightType_DirectionalLight: - { - counter += sizeof(DirectionalLight); - break; - } - case LightType_SpotLight: - { - counter += sizeof(SpotLight); - break; - } - default: - //Undefined LightType. - break; - }*/ - } - - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return levelHeader; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h deleted file mode 100644 index 8f2a9150..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef LEVEL_PARSER_H -#define LEVEL_PARSER_H - -#include -#include -#include "ObjectDefines.h" -#include "Utilities.h" - -namespace GameLogic -{ - namespace LevelFileLoader - { - class LevelParser - { - public: - LevelParser(); - ~LevelParser(); - - // - std::vector> Parse(std::string filename); - - // - LevelMetaData ParseHeader(std::string filename); - - private: - LevelLoaderInternal::FormatVersion formatVersion; - - }; - } -} -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp deleted file mode 100644 index 3e15315c..00000000 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ /dev/null @@ -1,22 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "Loader.h" -#include - -using namespace GameLogic::LevelFileLoader; -using namespace Oyster::Resource; -using namespace std; - -char* Loader::LoadFile(std::string fileName, int &size) -{ - //convert from string to wstring - std::wstring temp(fileName.begin(), fileName.end()); - - //convert from wstring to wchar then loads the file - char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); - - size = OysterResource::GetResourceSize(buffer); - return buffer; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h deleted file mode 100644 index 0433194e..00000000 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ /dev/null @@ -1,28 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef LOADER_H -#define LOADER_H - -#include "Resource\OysterResource.h" -#include - -namespace GameLogic -{ - namespace LevelFileLoader - { - class Loader - { - public: - Loader (){}; - ~Loader(){}; - char* LoadFile(std::string fileName, int &size); - - //TODO: - //Add functionality to load physicsObjects (hitboxes) - }; - } -} - -#endif; \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h deleted file mode 100644 index 01d17c3e..00000000 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ /dev/null @@ -1,274 +0,0 @@ -#ifndef OBJECT_DEFINES_H -#define OBJECT_DEFINES_H - -#include -#include - -namespace GameLogic -{ - /************************************ - Enums - *************************************/ - - enum ObjectType - { - ObjectType_LevelMetaData, - ObjectType_Static, - ObjectType_Dynamic, - ObjectType_Light, - ObjectType_SpawnPoint, - //Etc - - ObjectType_NUM_OF_TYPES, - - ObjectType_Unknown = -1 - }; - - enum ObjectSpecialType - { - ObjectSpecialType_None, - ObjectSpecialType_Sky, - ObjectSpecialType_World, //Always the main celestial body - ObjectSpecialType_Building, - ObjectSpecialType_Stone, - ObjectSpecialType_StandardBox, - ObjectSpecialType_RedExplosiveBox, - ObjectSpecialType_SpikeBox, - ObjectSpecialType_Spike, - ObjectSpecialType_CrystalFormation, - ObjectSpecialType_CrystalShard, - ObjectSpecialType_JumpPad, - ObjectSpecialType_Portal, - ObjectSpecialType_Player, - ObjectSpecialType_Generic, - - - ObjectSpecialType_Count, - ObjectSpecialType_Unknown = -1 - }; - - enum CollisionGeometryType - { - CollisionGeometryType_Box, - CollisionGeometryType_Sphere, - CollisionGeometryType_Cylinder, - - CollisionGeometryType_Count, - CollisionGeometryType_Unknown = -1 - }; - - //Only supports Pointlight right now. - enum LightType - { - LightType_PointLight, - //LightType_DirectionalLight, - //LightType_SpotLight, - - LightType_Count, - LightType_Unknown = -1 - }; - - //Should this be moved somewhere else? - enum GameMode - { - GameMode_FreeForAll, - GameMode_TeamDeathMatch, - //Etc - - GameMode_Count, - GameMode_Unknown = -1 - }; - - enum WorldSize - { - WorldSize_Tiny, - WorldSize_Small, - WorldSize_Medium, - WorldSize_Big, - WorldSize_Humongous, - - WorldSize_Count, - WorldSize_Unknown = -1 - }; - - - /************************************ - Structs - *************************************/ - namespace LevelLoaderInternal - { - struct FormatVersion - { - unsigned int formatVersionMajor; - unsigned int formatVersionMinor; - - FormatVersion() - : formatVersionMajor(0), formatVersionMinor(0) - {} - - FormatVersion(unsigned int major, unsigned int minor) - : formatVersionMajor(major), formatVersionMinor(minor) - {} - - bool operator ==(const FormatVersion& obj) - { - return (this->formatVersionMajor == obj.formatVersionMajor && this->formatVersionMinor == obj.formatVersionMinor); - } - - bool operator !=(const FormatVersion& obj) - { - return !(*this == obj); - } - }; - } - - struct ObjectTypeHeader - { - ObjectType typeID; - - //Unless this is here the object destructor wont be called. - virtual ~ObjectTypeHeader(){} - }; - - namespace LevelLoaderInternal - { - const FormatVersion boundingVolumeVersion(2, 0); - - struct BoundingVolumeBase - { - CollisionGeometryType geoType; - float position[3]; - float rotation[4]; - float frictionCoeffStatic; - float frictionCoeffDynamic; - float restitutionCoeff; - float mass; - }; - - struct BoundingVolumeBox : public BoundingVolumeBase - { - float size[3]; - }; - - struct BoundingVolumeSphere : public BoundingVolumeBase - { - float radius; - }; - - struct BoundingVolumeCylinder : public BoundingVolumeBase - { - float length; - float radius; - }; - - struct BoundingVolume - { - CollisionGeometryType geoType; - union - { - LevelLoaderInternal::BoundingVolumeBox box; - LevelLoaderInternal::BoundingVolumeSphere sphere; - LevelLoaderInternal::BoundingVolumeCylinder cylinder; - }; - }; - - } - - struct LevelMetaData : public ObjectTypeHeader - { - std::string levelName; - unsigned int levelVersion; - std::string levelDescription; - std::string levelAuthor; - unsigned int maxNumberOfPlayer; - WorldSize worldSize; - std::string overviewPicturePath; - std::vector gameModesSupported; - - virtual ~LevelMetaData(){} - - }; - - struct ObjectHeader : public ObjectTypeHeader - { - //Special type id for special objects: portal, jumppad, exploding objects, etc. - ObjectSpecialType specialTypeID; - //Model, - std::string ModelFile; - //Position - float position[3]; - //Rotation Quaternion - float rotation[4]; - //Scale - float scale[3]; - - ::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume; - - virtual ~ObjectHeader(){} - }; - - struct SpawnPointAttributes : public ObjectTypeHeader - { - ObjectSpecialType specialTypeID; - float position[3]; - }; - /************************************ - Special objects - *************************************/ - - struct JumpPadAttributes : public ObjectHeader - { - float direction[3]; - float power; - }; - - struct PortalAttributes : public ObjectHeader - { - float destination[3]; - }; - - struct WorldAttributes : public ObjectHeader - { - float worldSize; - float atmoSphereSize; - }; - - struct SkyAttributes : public ObjectHeader - { - float skySize; - }; - - - - /************************************ - Lights - *************************************/ - - struct BasicLight : public ObjectTypeHeader - { - LightType lightType; //Is not used right now - float color[3]; - float position[3]; - float raduis; - float intensity; - }; - /* We only support pointlight right now. - struct PointLight : public BasicLight - { - float position[3]; - }; - - struct DirectionalLight : public BasicLight - { - float direction[3]; - }; - - struct SpotLight : public BasicLight - { - float direction[3]; - float range; - float attenuation[3]; - };*/ -} - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp deleted file mode 100644 index 826a52be..00000000 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ /dev/null @@ -1,183 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "ParseFunctions.h" -#include "Packing/Packing.h" -#include "Loader.h" -#include - -using namespace Oyster::Packing; -using namespace GameLogic::LevelFileLoader; -using namespace GameLogic; -using namespace std; - -namespace GameLogic -{ - namespace LevelFileLoader - { - //can parse any struct if the struct doesnt contain strings or char[] - void ParseObject(char* buffer, void *header, int size) - { - memcpy(header, buffer, size); - } - - void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf) - { - char tempName[128]; - unsigned int tempSize = 0; - int start = 0; - - memcpy(&header.typeID, &buffer[start], 4); - start += 4; - - memcpy(&header.specialTypeID, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.ModelFile.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - //The reset of the object struct - //3 float[3], 1 float - memcpy(&header.position, &buffer[start], 40); - start += 40; - - //if loadCgf : Read path for bounding volume - if(loadCgf) - { - ParseBoundingVolume(&buffer[start], header.boundingVolume, start); - } - - //else make sure the counter counts the name so we can jump over the string in the buffer. - else - { - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - - string fileName; - fileName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - } - - size += start; - } - - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) - { - int start = 0; - unsigned int tempSize; - char tempName[128]; - - memcpy(&header.typeID, &buffer[start], 4); - start += 4; - - memcpy(&tempSize , &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&header.levelVersion, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start +=4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelDescription.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelAuthor.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&header.maxNumberOfPlayer, &buffer[start], 4); - start += 4; - - memcpy(&header.worldSize, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - int temp; - - for(int i = 0; i < tempSize; i++) - { - memcpy(&temp, &buffer[start], 4); - start += 4; - header.gameModesSupported.push_back((GameMode)temp); - } - - size += start; - } - - void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size) - { - int start = 0; - int tempSize = 0; - char tempName[128]; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - - string fileName; - fileName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - size += start; - - //Läs in filen. - int fileLength = 0; - Loader loader; - char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength); - - start = 0; - LevelLoaderInternal::FormatVersion version; - memcpy(&version, &buf[0], sizeof(version)); - start += 8; - - memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - - switch(volume.geoType) - { - case CollisionGeometryType_Box: - memcpy(&volume.box, &buf[start], sizeof(volume.box)); - start += sizeof(volume.box); - break; - - case CollisionGeometryType_Sphere: - memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere)); - start += sizeof(volume.sphere); - break; - - case CollisionGeometryType_Cylinder: - memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder)); - start += sizeof(volume.cylinder); - break; - - default: - break; - } - } - } -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h deleted file mode 100644 index 0fc6dbc6..00000000 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ /dev/null @@ -1,28 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef PARSERFUNCTIONS_H -#define PARSERFUNCTIONS_H -#include "ObjectDefines.h" - -namespace GameLogic -{ - namespace LevelFileLoader - { - /* - These functions will copy data from where the buffer pointer points. - header is the destination where the data will be copied. - size is either the size of the data to be copied (if it is NOT sent by reference). - Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. - - */ - void ParseObject(char* buffer, void *header, int size); - void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf); - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); - void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); - } -} - - -#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.cpp b/Code/Game/LevelLoader/LevelLoader.cpp similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.cpp rename to Code/Game/LevelLoader/LevelLoader.cpp diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/LevelLoader/LevelLoader.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h rename to Code/Game/LevelLoader/LevelLoader.h diff --git a/Code/Game/LevelLoader/LevelLoader.vcxproj b/Code/Game/LevelLoader/LevelLoader.vcxproj new file mode 100644 index 00000000..7f748c5f --- /dev/null +++ b/Code/Game/LevelLoader/LevelLoader.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63} + LevelLoader + + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + true + v110 + Unicode + + + StaticLibrary + false + v110 + true + Unicode + + + StaticLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + + + $(SolutionDir)..\External\Lib\$(ProjectName)\ + $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + + + + Level3 + Disabled + true + $(SolutionDir)Misc\Utilities; + + + true + + + + + Level3 + Disabled + true + $(SolutionDir)Misc\Utilities; + + + true + + + + + Level3 + MaxSpeed + true + true + true + $(SolutionDir)Misc\Utilities; + + + true + true + true + + + + + + + + + Level3 + MaxSpeed + true + true + true + $(SolutionDir)Misc\Utilities; + + + true + true + true + + + + + + + + + + + + + + + + + + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + + + + + \ No newline at end of file diff --git a/Code/Game/LevelLoader/LevelLoader.vcxproj.user b/Code/Game/LevelLoader/LevelLoader.vcxproj.user new file mode 100644 index 00000000..2e28d6f7 --- /dev/null +++ b/Code/Game/LevelLoader/LevelLoader.vcxproj.user @@ -0,0 +1,22 @@ + + + + true + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp similarity index 99% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.cpp rename to Code/Game/LevelLoader/LevelParser.cpp index 2fbf5df3..0c450f71 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -98,7 +98,7 @@ std::vector> LevelParser::Parse(std::string filen case ObjectSpecialType_Spike: case ObjectSpecialType_SpikeBox: case ObjectSpecialType_RedExplosiveBox: - case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_StandardBox: case ObjectSpecialType_Stone: case ObjectSpecialType_Building: { diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h b/Code/Game/LevelLoader/LevelParser.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h rename to Code/Game/LevelLoader/LevelParser.h diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.cpp b/Code/Game/LevelLoader/Loader.cpp similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/Loader.cpp rename to Code/Game/LevelLoader/Loader.cpp diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h b/Code/Game/LevelLoader/Loader.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/Loader.h rename to Code/Game/LevelLoader/Loader.h diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h similarity index 98% rename from Code/Game/GameClient/GameClientState/LevelLoader/ObjectDefines.h rename to Code/Game/LevelLoader/ObjectDefines.h index bb2ae439..918fb4e6 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -31,7 +31,7 @@ namespace GameLogic ObjectSpecialType_World, //Always the main celestial body ObjectSpecialType_Building, ObjectSpecialType_Stone, - ObjectSpecialType_StandarsBox, + ObjectSpecialType_StandardBox, ObjectSpecialType_RedExplosiveBox, ObjectSpecialType_SpikeBox, ObjectSpecialType_Spike, @@ -40,6 +40,7 @@ namespace GameLogic ObjectSpecialType_JumpPad, ObjectSpecialType_Portal, ObjectSpecialType_Player, + ObjectSpecialType_Generic, ObjectSpecialType_Count, diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp similarity index 99% rename from Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.cpp rename to Code/Game/LevelLoader/ParseFunctions.cpp index 59f967de..b6b57d83 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -117,7 +117,7 @@ namespace GameLogic int temp; - for(int i = 0; i < tempSize; i++) + for(int i = 0; i < (int)tempSize; i++) { memcpy(&temp, &buffer[start], 4); start += 4; diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.h b/Code/Game/LevelLoader/ParseFunctions.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.h rename to Code/Game/LevelLoader/ParseFunctions.h diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 6f2998e9..5bd10165 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -319,7 +319,23 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) bool NetworkClient::Reconnect() { - return this->privateData->connection.Reconnect(); + if(this->IsConnected()) + return false; + //if(this->privateData) + //return false; + if(!this->privateData) this->privateData = new PrivateData(); + + int result = this->privateData->connection.Reconnect(); + + if(result != 0) + { + return false; + } + this->privateData->owner = 0; + this->privateData->parent = this; + this->privateData->thread.Start(); + + return true; } void NetworkClient::Disconnect() From 58117ad425d6a5e698a95bb04200afd473c8f687 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 19 Feb 2014 11:22:14 +0100 Subject: [PATCH 09/21] asd --- Code/Game/GameLogic/GameLogic.vcxproj.user | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/GameLogic.vcxproj.user b/Code/Game/GameLogic/GameLogic.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj.user +++ b/Code/Game/GameLogic/GameLogic.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) From f1cd73425c37067b48471b98011fb04b602fadd6 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 19 Feb 2014 11:38:36 +0100 Subject: [PATCH 10/21] Removed old LevelLoader, it's now in a seperate project. --- .../GameLogic/LevelLoader/LevelLoader.cpp | 52 --- Code/Game/GameLogic/LevelLoader/LevelLoader.h | 56 --- .../GameLogic/LevelLoader/LevelParser.cpp | 320 ------------------ Code/Game/GameLogic/LevelLoader/LevelParser.h | 31 -- Code/Game/GameLogic/LevelLoader/Loader.cpp | 22 -- Code/Game/GameLogic/LevelLoader/Loader.h | 28 -- .../GameLogic/LevelLoader/ObjectDefines.h | 290 ---------------- .../GameLogic/LevelLoader/ParseFunctions.cpp | 195 ----------- Code/Game/LevelLoader/LevelLoader.cpp | 2 +- 9 files changed, 1 insertion(+), 995 deletions(-) delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelLoader.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelLoader.h delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelParser.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/LevelParser.h delete mode 100644 Code/Game/GameLogic/LevelLoader/Loader.cpp delete mode 100644 Code/Game/GameLogic/LevelLoader/Loader.h delete mode 100644 Code/Game/GameLogic/LevelLoader/ObjectDefines.h delete mode 100644 Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp deleted file mode 100644 index 205da712..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ /dev/null @@ -1,52 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "LevelLoader.h" -#include "LevelParser.h" - -using namespace GameLogic; -using namespace GameLogic::LevelFileLoader; - -struct LevelLoader::PrivData -{ - LevelParser parser; - std::wstring folderPath; -}; - -LevelLoader::LevelLoader() - : pData(new PrivData) -{ - //standard path - pData->folderPath = L""; -} - -LevelLoader::LevelLoader(std::wstring folderPath) - : pData(new PrivData) -{ - pData->folderPath = folderPath; -} - -LevelLoader::~LevelLoader() -{ -} - -std::vector> LevelLoader::LoadLevel(std::wstring fileName) -{ - return pData->parser.Parse(pData->folderPath + fileName); -} - -LevelMetaData LevelLoader::LoadLevelHeader(std::wstring fileName) -{ - return pData->parser.ParseHeader(pData->folderPath + fileName); -} - -std::wstring LevelLoader::GetFolderPath() -{ - return this->pData->folderPath; -} - -void LevelLoader::SetFolderPath(std::wstring folderPath) -{ - this->pData->folderPath = folderPath; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h deleted file mode 100644 index c14e2c4c..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef LEVELLOADER_H -#define LEVELLOADER_H - -#include -#include -#include "Utilities.h" -#include "ObjectDefines.h" - -namespace GameLogic -{ - class LevelLoader - { - - public: - LevelLoader(); - /*********************************************************** - * Lets you set the standard folderpath for the levels - ********************************************************/ - LevelLoader(std::wstring folderPath); - ~LevelLoader(); - - /******************************************************** - * Loads the level and objects from file. - * @param fileName: Path/name to the level-file that you want to load. - * @return: Returns all structs with objects and information about the level. - ********************************************************/ - std::vector> LoadLevel(std::wstring fileName); - - /******************************************************** - * Just for fast access for the meta information about the level. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns the meta information about the level. - ********************************************************/ - LevelMetaData LoadLevelHeader(std::wstring fileName); //. - - /*********************************************************** - * @return: Returns the current standard folder path - ********************************************************/ - std::wstring GetFolderPath(); - - /*********************************************************** - * Sets the standard folder path - ********************************************************/ - void SetFolderPath(std::wstring folderPath); - - private: - struct PrivData; - Utility::DynamicMemory::SmartPointer pData; - }; -} - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp deleted file mode 100644 index 2d23f069..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ /dev/null @@ -1,320 +0,0 @@ -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "LevelParser.h" -#include "Loader.h" -#include "ParseFunctions.h" - -using namespace GameLogic; -using namespace ::LevelFileLoader; -using namespace Utility::DynamicMemory; - -LevelParser::LevelParser() -{ - formatVersion.formatVersionMajor = 3; - formatVersion.formatVersionMinor = 0; -} - -LevelParser::~LevelParser() -{ -} - -std::vector> LevelParser::Parse(std::wstring filename) -{ - int bufferSize = 0; - int counter = 0; - bool loadCgf; - - std::vector> objects; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - // Check if file was loaded, else return empty vector - if(!buffer) - { - return std::vector>(); - } - - //Read format version - LevelLoaderInternal::FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); - counter += sizeof(levelFormatVersion); - if(this->formatVersion != levelFormatVersion) - { - //Returns an empty vector, because it will most likely fail to read the level format. - return objects; - } - - while(counter < bufferSize) - { - loadCgf = true; - //Get typeID - ObjectType typeID; - ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - switch((int)typeID) - { - case ObjectType_LevelMetaData: - { - SmartPointer header = new LevelMetaData; - ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); - objects.push_back(header); - break; - } - - case ObjectType_SpawnPoint: - { - loadCgf = false; - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - SpawnPointAttributes* spawn = new SpawnPointAttributes; - - spawn->typeID = header->typeID; - - for(int i = 0; i < 3; i++) - { - spawn->position[i] = header->position[i]; - } - - delete header; - //objects.push_back(header); - objects.push_back(spawn); - break; - } - - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. - //Unless they are changed to not be the same. - case ObjectType_Static: case ObjectType_Dynamic: - { - //Get specialType. - ObjectSpecialType specialType; - ParseObject(&buffer[counter+4], &specialType, sizeof(typeID)); - - switch(specialType) - { - //there is no difference when parsing these specialTypes. - case ObjectSpecialType_CrystalShard: - case ObjectSpecialType_CrystalFormation: - case ObjectSpecialType_Spike: - case ObjectSpecialType_SpikeBox: - case ObjectSpecialType_RedExplosiveBox: - case ObjectSpecialType_StandardBox: - case ObjectSpecialType_Stone: - case ObjectSpecialType_Building: - { - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - objects.push_back(header); - - break; - } - - case ObjectSpecialType_JumpPad: - { - JumpPadAttributes* header = new JumpPadAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - //Read the spec - ParseObject(&buffer[counter], header->direction, 16); - counter += 16; - objects.push_back(header); - - break; - } - - case ObjectSpecialType_Portal: - { - PortalAttributes* header = new PortalAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - ParseObject(&buffer[counter], header->destination, 12); - counter += 12; - objects.push_back(header); - - break; - } - - case ObjectSpecialType_World: - { - WorldAttributes* header = new WorldAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - ParseObject(&buffer[counter], &header->worldSize, 8); - counter += 8; - objects.push_back(header); - break; - } - - case ObjectSpecialType_Sky: - { - loadCgf = false; - SkyAttributes* header = new SkyAttributes; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - ParseObject(&buffer[counter], &header->skySize, 4); - counter += 4; - objects.push_back(header); - break; - } - - default: - //Couldn't find specialType - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - - //Get Light type - ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - - //We only support PointLight for now. - BasicLight* header = new BasicLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - /*switch(lightType) - { - case LightType_PointLight: - { - PointLight* header = new PointLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_DirectionalLight: - { - DirectionalLight* header = new DirectionalLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_SpotLight: - { - SpotLight* header = new SpotLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - default: - //Undefined LightType. - break; - } - break;*/ - } - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return objects; -} - -//för meta information om leveln. -LevelMetaData LevelParser::ParseHeader(std::wstring filename) -{ - int bufferSize = 0; - int counter = 0; - - LevelMetaData levelHeader; - levelHeader.typeID = ObjectType::ObjectType_Unknown; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - //Read format version - LevelLoaderInternal::FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); - counter += sizeof(levelFormatVersion); - if(this->formatVersion != levelFormatVersion) - { - //Do something if it's not the same version - - //Returns an empty levelHeader with ObjectType_Unknown. - //Because it will not be able to read another version of the level format. - return levelHeader; - } - - //Find the header in the returned string. - while(counter < bufferSize) - { - ObjectType typeID; - ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - - switch(typeID) - { - case ObjectType_LevelMetaData: - ParseLevelMetaData(&buffer[counter], levelHeader, counter); - return levelHeader; - break; - - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. - case ObjectType_Static: case ObjectType_Dynamic: - { - ObjectHeader header; - ParseObject(&buffer[counter], &header, counter); - - switch(header.specialTypeID) - { - case ObjectSpecialType_JumpPad: - counter += sizeof(16); - break; - case ObjectSpecialType_Portal: - counter += sizeof(12); - break; - default: - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - - //We only support pointlight for now. - counter += sizeof(BasicLight); - /* - switch(lightType) - { - case LightType_PointLight: - { - counter += sizeof(PointLight); - break; - } - case LightType_DirectionalLight: - { - counter += sizeof(DirectionalLight); - break; - } - case LightType_SpotLight: - { - counter += sizeof(SpotLight); - break; - } - default: - //Undefined LightType. - break; - }*/ - } - - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return levelHeader; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h deleted file mode 100644 index d0cb1f03..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef LEVEL_PARSER_H -#define LEVEL_PARSER_H - -#include -#include -#include "ObjectDefines.h" -#include "Utilities.h" - -namespace GameLogic -{ - namespace LevelFileLoader - { - class LevelParser - { - public: - LevelParser(); - ~LevelParser(); - - // - std::vector> Parse(std::wstring filename); - - // - LevelMetaData ParseHeader(std::wstring filename); - - private: - LevelLoaderInternal::FormatVersion formatVersion; - - }; - } -} -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp deleted file mode 100644 index 19ffa0f1..00000000 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ /dev/null @@ -1,22 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "Loader.h" -#include - -using namespace GameLogic::LevelFileLoader; -using namespace Oyster::Resource; -using namespace std; - -char* Loader::LoadFile(std::wstring fileName, int &size) -{ - //convert from string to wstring - //std::wstring temp(fileName.begin(), fileName.end()); - - //convert from wstring to wchar then loads the file - char* buffer = (char*)OysterResource::LoadResource(fileName.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); - - size = OysterResource::GetResourceSize(buffer); - return buffer; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h deleted file mode 100644 index 6deb8900..00000000 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ /dev/null @@ -1,28 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef LOADER_H -#define LOADER_H - -#include "Resource\OysterResource.h" -#include - -namespace GameLogic -{ - namespace LevelFileLoader - { - class Loader - { - public: - Loader (){}; - ~Loader(){}; - char* LoadFile(std::wstring fileName, int &size); - - //TODO: - //Add functionality to load physicsObjects (hitboxes) - }; - } -} - -#endif; \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h deleted file mode 100644 index 131b2938..00000000 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ /dev/null @@ -1,290 +0,0 @@ -#ifndef OBJECT_DEFINES_H -#define OBJECT_DEFINES_H - -#include -#include - -namespace GameLogic -{ - /************************************ - Enums - *************************************/ - - enum ObjectType - { - ObjectType_LevelMetaData, - ObjectType_Static, - ObjectType_Dynamic, - ObjectType_Light, - ObjectType_SpawnPoint, - //Etc - - ObjectType_NUM_OF_TYPES, - - ObjectType_Unknown = -1 - }; - - enum ObjectSpecialType - { - ObjectSpecialType_None, - ObjectSpecialType_Sky, - ObjectSpecialType_World, //Always the main celestial body - ObjectSpecialType_Building, - ObjectSpecialType_Stone, - ObjectSpecialType_StandardBox, - ObjectSpecialType_RedExplosiveBox, - ObjectSpecialType_SpikeBox, - ObjectSpecialType_Spike, - ObjectSpecialType_CrystalFormation, - ObjectSpecialType_CrystalShard, - ObjectSpecialType_JumpPad, - ObjectSpecialType_Portal, - ObjectSpecialType_Player, - ObjectSpecialType_Generic, - - - ObjectSpecialType_Count, - ObjectSpecialType_Unknown = -1 - }; - - enum CollisionGeometryType - { - CollisionGeometryType_Box, - CollisionGeometryType_Sphere, - CollisionGeometryType_Cylinder, - CollisionGeometryType_TriangleMesh, - - CollisionGeometryType_Count, - CollisionGeometryType_Unknown = -1 - }; - - //Only supports Pointlight right now. - enum LightType - { - LightType_PointLight, - //LightType_DirectionalLight, - //LightType_SpotLight, - - LightType_Count, - LightType_Unknown = -1 - }; - - //Should this be moved somewhere else? - enum GameMode - { - GameMode_FreeForAll, - GameMode_TeamDeathMatch, - //Etc - - GameMode_Count, - GameMode_Unknown = -1 - }; - - enum WorldSize - { - WorldSize_Tiny, - WorldSize_Small, - WorldSize_Medium, - WorldSize_Big, - WorldSize_Humongous, - - WorldSize_Count, - WorldSize_Unknown = -1 - }; - - - /************************************ - Structs - *************************************/ - namespace LevelLoaderInternal - { - struct FormatVersion - { - unsigned int formatVersionMajor; - unsigned int formatVersionMinor; - - FormatVersion() - : formatVersionMajor(0), formatVersionMinor(0) - {} - - FormatVersion(unsigned int major, unsigned int minor) - : formatVersionMajor(major), formatVersionMinor(minor) - {} - - bool operator ==(const FormatVersion& obj) - { - return (this->formatVersionMajor == obj.formatVersionMajor && this->formatVersionMinor == obj.formatVersionMinor); - } - - bool operator !=(const FormatVersion& obj) - { - return !(*this == obj); - } - }; - } - - struct ObjectTypeHeader - { - ObjectType typeID; - - //Unless this is here the object destructor wont be called. - virtual ~ObjectTypeHeader(){} - }; - - namespace LevelLoaderInternal - { - const FormatVersion boundingVolumeVersion(2, 0); - - struct BoundingVolumeBase - { - CollisionGeometryType geoType; - float position[3]; - float rotation[4]; - float frictionCoeffStatic; - float frictionCoeffDynamic; - float restitutionCoeff; - float mass; - }; - - struct BoundingVolumeBox : public BoundingVolumeBase - { - float size[3]; - }; - - struct BoundingVolumeSphere : public BoundingVolumeBase - { - float radius; - }; - - struct BoundingVolumeCylinder : public BoundingVolumeBase - { - float length; - float radius; - }; - - struct BoundingVolumeTriangleMesh : public BoundingVolumeBase - { - //Null terminated - wchar_t* filename; - }; - - struct BoundingVolume - { - CollisionGeometryType geoType; - union - { - LevelLoaderInternal::BoundingVolumeBox box; - LevelLoaderInternal::BoundingVolumeSphere sphere; - LevelLoaderInternal::BoundingVolumeCylinder cylinder; - LevelLoaderInternal::BoundingVolumeTriangleMesh triangleMesh; - }; - - virtual ~BoundingVolume() - { - if(geoType == CollisionGeometryType_TriangleMesh) - { - delete[] triangleMesh.filename; - } - } - }; - - } - - struct LevelMetaData : public ObjectTypeHeader - { - std::string levelName; - unsigned int levelVersion; - std::string levelDescription; - std::string levelAuthor; - unsigned int maxNumberOfPlayer; - WorldSize worldSize; - std::string overviewPicturePath; - std::vector gameModesSupported; - - virtual ~LevelMetaData(){} - - }; - - struct ObjectHeader : public ObjectTypeHeader - { - //Special type id for special objects: portal, jumppad, exploding objects, etc. - ObjectSpecialType specialTypeID; - //Model, - std::string ModelFile; - //Position - float position[3]; - //Rotation Quaternion - float rotation[4]; - //Scale - float scale[3]; - - ::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume; - - virtual ~ObjectHeader(){} - }; - - struct SpawnPointAttributes : public ObjectTypeHeader - { - ObjectSpecialType specialTypeID; - float position[3]; - }; - /************************************ - Special objects - *************************************/ - - struct JumpPadAttributes : public ObjectHeader - { - float direction[3]; - float power; - }; - - struct PortalAttributes : public ObjectHeader - { - float destination[3]; - }; - - struct WorldAttributes : public ObjectHeader - { - float worldSize; - float atmoSphereSize; - }; - - struct SkyAttributes : public ObjectHeader - { - float skySize; - }; - - - - /************************************ - Lights - *************************************/ - - struct BasicLight : public ObjectTypeHeader - { - LightType lightType; //Is not used right now - float color[3]; - float position[3]; - float raduis; - float intensity; - }; - /* We only support pointlight right now. - struct PointLight : public BasicLight - { - float position[3]; - }; - - struct DirectionalLight : public BasicLight - { - float direction[3]; - }; - - struct SpotLight : public BasicLight - { - float direction[3]; - float range; - float attenuation[3]; - };*/ -} - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp deleted file mode 100644 index 76d7d6c3..00000000 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ /dev/null @@ -1,195 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "ParseFunctions.h" -#include "Packing/Packing.h" -#include "Loader.h" -#include "Utilities.h" -#include - -using namespace Oyster::Packing; -using namespace GameLogic::LevelFileLoader; -using namespace GameLogic; -using namespace std; - -namespace GameLogic -{ - namespace LevelFileLoader - { - //can parse any struct if the struct doesnt contain strings or char[] - void ParseObject(char* buffer, void *header, int size) - { - memcpy(header, buffer, size); - } - - void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf) - { - char tempName[128]; - unsigned int tempSize = 0; - int start = 0; - - memcpy(&header.typeID, &buffer[start], 4); - start += 4; - - memcpy(&header.specialTypeID, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.ModelFile.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - //The reset of the object struct - //3 float[3], 1 float - memcpy(&header.position, &buffer[start], 40); - start += 40; - - //if loadCgf : Read path for bounding volume - if(loadCgf) - { - ParseBoundingVolume(&buffer[start], header.boundingVolume, start); - } - - //else make sure the counter counts the name so we can jump over the string in the buffer. - else - { - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - - string fileName; - fileName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - } - - size += start; - } - - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) - { - int start = 0; - unsigned int tempSize; - char tempName[128]; - - memcpy(&header.typeID, &buffer[start], 4); - start += 4; - - memcpy(&tempSize , &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&header.levelVersion, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start +=4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelDescription.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelAuthor.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&header.maxNumberOfPlayer, &buffer[start], 4); - start += 4; - - memcpy(&header.worldSize, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - int temp; - - for(int i = 0; i < (int)tempSize; i++) - { - memcpy(&temp, &buffer[start], 4); - start += 4; - header.gameModesSupported.push_back((GameMode)temp); - } - - size += start; - } - - void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size) - { - int start = 0; - int tempSize = 0; - char tempName[128]; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - - string fileName; - fileName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - size += start; - - //Läs in filen. - int fileLength = 0; - Loader loader; - char* buf = loader.LoadFile(L"../Content/Worlds/cgf/" + Utility::String::StringToWstring(fileName, wstring()), fileLength); - - start = 0; - LevelLoaderInternal::FormatVersion version; - memcpy(&version, &buf[0], sizeof(version)); - start += 8; - - memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - - switch(volume.geoType) - { - case CollisionGeometryType_Box: - memcpy(&volume.box, &buf[start], sizeof(volume.box)); - start += sizeof(volume.box); - break; - - case CollisionGeometryType_Sphere: - memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere)); - start += sizeof(volume.sphere); - break; - - case CollisionGeometryType_Cylinder: - memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder)); - start += sizeof(volume.cylinder); - break; - - case CollisionGeometryType_TriangleMesh: - //Get string size - memcpy(&tempSize, &buf[start], sizeof(tempSize)); - start += sizeof(tempSize); - - //Get actual string - volume.triangleMesh.filename = new wchar_t[tempSize+1]; - memcpy(volume.triangleMesh.filename, &buf[start], tempSize); - volume.triangleMesh.filename[tempSize] = '\0'; - break; - - default: - break; - } - } - } -} \ No newline at end of file diff --git a/Code/Game/LevelLoader/LevelLoader.cpp b/Code/Game/LevelLoader/LevelLoader.cpp index 8fe880f3..82583696 100644 --- a/Code/Game/LevelLoader/LevelLoader.cpp +++ b/Code/Game/LevelLoader/LevelLoader.cpp @@ -48,5 +48,5 @@ std::string LevelLoader::GetFolderPath() void LevelLoader::SetFolderPath(std::string folderPath) { - + this->pData->folderPath = folderPath; } \ No newline at end of file From 932ef429c2e8e0e541a192c52e8bb899c7daf2bf Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 12:09:42 +0100 Subject: [PATCH 11/21] GameClient - removed hardcoding for lvl, use 2ofAll map for correct world. Init player gets wrong scale and isMyPlayer. Need to verify camera on client --- .../GameClient/GameClientState/GameState.cpp | 6 +--- .../GameClientState/NetLoadState.cpp | 19 ------------- Code/Game/GameLogic/Game_PlayerData.cpp | 2 +- Code/Game/GameLogic/Level.cpp | 28 +------------------ 4 files changed, 3 insertions(+), 52 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 5d756cf4..41518db6 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -93,9 +93,6 @@ bool GameState::Init( SharedStateContent &shared ) //tell server ready this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); - // Debugg hack - this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); - // end debug hack // DEGUG KEYS this->privData->key_Reload_Shaders = false; this->privData->key_Wireframe_Toggle = false; @@ -127,7 +124,6 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBData.rotation = ArrayToQuaternion( rotation ); RBData.scale = Float3( 1 ); // !RB DEBUG - if( isMyPlayer ) { if( this->privData->player.Init(modelData) ) @@ -483,7 +479,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState // if is this player. Remember to change camera if( this->privData->myId == decoded.object_ID ) { - this->privData->camera.SetPosition( position ); + //this->privData->camera.SetPosition( position ); //this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); //this->privData->player.setRot( rotation ); diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 1c4fbf65..b2475cc6 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -144,14 +144,6 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) desc.scale = oh->scale; desc.visible = true; - // HACK: untill the world is right in lvl format - if( oh->specialTypeID == ObjectSpecialType_World) - { - desc.position = Float3(0,0,0); - desc.rotation = Quaternion::identity; - desc.scale = Float3(300,300,300); - } - C_StaticObj *staticObject = new C_StaticObj(); if( staticObject->Init( desc ) ) { @@ -248,16 +240,5 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) } } - // DEBUG added a static light for testing - Graphics::Definitions::Pointlight pointLight; - pointLight.Color = Float3(1,1,0); - pointLight.Pos = Float3( 0,132, 10); - pointLight.Bright = 2; - pointLight.Radius = 50; - - C_Light *newLight = new C_Light( pointLight, objectID ); - - (*this->privData->lights)[objectID] = newLight; - this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index ca0746e8..9ff82b2b 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -24,7 +24,7 @@ Game::PlayerData::PlayerData() } Game::PlayerData::PlayerData(int playerID,int teamID) { - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(-50,180,0); Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); Oyster::Math::Float mass = 60; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index a3a1c07f..b3a8b101 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -242,34 +242,8 @@ bool Level::InitiateLevel(std::wstring levelPath) ICustomBody* rigidBody_Static = NULL; - // HACK: untill the world is right in lvl format - if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World) - { - Oyster::Math::Float3 rigidWorldPos; - Oyster::Math::Float4 rigidWorldRotation; - float rigidBodyMass; - float rigidBodyRadius; - - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = Oyster::Math::Float3(0,0,0); - //scales the position so the collision geomentry is in the right place - - //offset the rigidRotation from modelspace to worldspace; - - rigidWorldRotation = Oyster::Math::Float4(0,0,0,1); - - //mass scaled - rigidBodyMass = 0; - - //Radius scaled - rigidBodyRadius = 150; - - //create the rigid body - rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, 1,1,1); - - } // collision shape - else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) { rigidBody_Static = InitRigidBodySphere(staticObjData); } From 8816efafc83b234b9139756eb9690fbde58dc600 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 13:15:19 +0100 Subject: [PATCH 12/21] GameState pre-work for subStates --- Code/Game/GameClient/GameClient.vcxproj | 6 + Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClientState/GameClientState.h | 2 +- .../GameClientState/GameStateUI.cpp | 17 ++ .../GameClient/GameClientState/GameStateUI.h | 58 +++++++ .../GameClient/GameClientState/GamingUI.cpp | 153 ++++++++++++++++++ .../GameClient/GameClientState/GamingUI.h | 33 ++++ .../GameClient/GameClientState/RespawnUI.cpp | 58 +++++++ .../GameClient/GameClientState/RespawnUI.h | 29 ++++ Code/Misc/Input/L_inputClass.h | 1 + 10 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/GameStateUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/GameStateUI.h create mode 100644 Code/Game/GameClient/GameClientState/GamingUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/GamingUI.h create mode 100644 Code/Game/GameClient/GameClientState/RespawnUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/RespawnUI.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 349a88ec..082a9344 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -211,6 +211,8 @@ + + @@ -221,6 +223,7 @@ + @@ -237,6 +240,8 @@ + + @@ -246,6 +251,7 @@ + diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 9891a16c..d336e196 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -35,7 +35,7 @@ namespace DanBias { namespace Client /****************************************************************** * @param message of the event - * @return message or GameClientState::event_processed. + * @return message or a reference to GameClientState::event_processed. ******************************************************************/ virtual const NetEvent & DataRecieved( const NetEvent &message ); }; diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.cpp b/Code/Game/GameClient/GameClientState/GameStateUI.cpp new file mode 100644 index 00000000..6b8b7ed5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GameStateUI.cpp @@ -0,0 +1,17 @@ +#include "GameStateUI.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; + +GameStateUI::GameStateUI() +{ + this->nextState = GameStateUI::UIState_same; +} + +GameStateUI::~GameStateUI() { /* Do nothing */ } + +const GameStateUI::NetEvent & GameStateUI::DataRecieved( const GameStateUI::NetEvent &message ) +{ + /* Do nothing */ + return message; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.h b/Code/Game/GameClient/GameClientState/GameStateUI.h new file mode 100644 index 00000000..40350211 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GameStateUI.h @@ -0,0 +1,58 @@ +#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H +#define DANBIAS_CLIENT_GAMECLIENTSTATE_H + +#include "Utilities.h" +#include "NetworkClient.h" + +namespace DanBias { namespace Client +{ + class GameStateUI + { + public: + enum UIState + { + UIState_same, + UIState_gaming, + + + UIState_main_menu, + UIState_shut_down + }; + + typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent; + static const NetEvent event_processed; + + GameStateUI(); + virtual ~GameStateUI(); + virtual UIState Update( float deltaTime ) = 0; + virtual bool HaveGUIRender() const = 0; + virtual bool HaveTextRender() const = 0; + virtual void RenderGUI() const = 0; + virtual void RenderText() const = 0; + virtual bool Release() = 0; + + /****************************************************************** + * @param message of the event + * @return message or a reference to GameStateUI::event_processed. + ******************************************************************/ + virtual const NetEvent & DataRecieved( const NetEvent &message ); + + protected: + UIState nextState; + }; +} } + +namespace Utility { namespace DynamicMemory +{ // template specializationto allowuse of dynamicmemory tools + template<> + inline void SafeDeleteInstance( ::DanBias::Client::GameStateUI *dynamicInstance ) + { + if( dynamicInstance ) + { + dynamicInstance->Release(); + delete dynamicInstance; + } + } +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp new file mode 100644 index 00000000..a2edc28f --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -0,0 +1,153 @@ +#include "GamingUI.h" +#include + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; +using namespace ::GameLogic; + +GamingUI::GamingUI() : + GameStateUI() +{ + /* Should never be called! */ + this->input = nullptr; + this->netClient = nullptr; + this->camera = nullptr; +} + +GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : + GameStateUI() +{ + this->input = input; + this->netClient = connection; + this->camera = camera; +} + +GamingUI::~GamingUI() { /* Do nothing */ } + +GameStateUI::UIState GamingUI::Update( float deltaTime ) +{ + return this->nextState; +} + +bool GamingUI::HaveGUIRender() const +{ + return false; // TODO: change to true when we want UI elements like a crosshair +} + +bool GamingUI::HaveTextRender() const +{ + return false; // TODO: change to true when we want UI elements like a chat window +} + +void GamingUI::RenderGUI() const +{ + // TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender +} + +void GamingUI::RenderText() const +{ + // TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender +} + +bool GamingUI::Release() +{ + // TODO: Release UI components here. + return true; +} + +void GamingUI::ReadKeyInput() +{ + if( this->input->IsKeyPressed(DIK_W) ) + { + this->netClient->Send( Protocol_PlayerMovementForward() ); + } + + if( this->input->IsKeyPressed(DIK_S) ) + { + this->netClient->Send( Protocol_PlayerMovementBackward() ); + } + + if( this->input->IsKeyPressed(DIK_A) ) + { + this->netClient->Send( Protocol_PlayerMovementLeft() ); + } + + if( this->input->IsKeyPressed(DIK_D) ) + { + this->netClient->Send( Protocol_PlayerMovementRight() ); + } + +// if( this->input->IsKeyPressed(DIK_R) ) +// { +// if( !this->key_Reload_Shaders ) +// { +//#ifdef _DEBUG +// Graphics::API::ReloadShaders(); +//#endif +// this->key_Reload_Shaders = true; +// } +// } +// else +// this->key_Reload_Shaders = false; + + //send delta mouse movement + { + this->camera->YawRight( this->input->GetYaw() * 0.017f ); + this->camera->PitchDown( this->input->GetPitch() * 0.017f ); + this->camera->UpdateOrientation(); + + this->netClient->Send( Protocol_PlayerLook(this->camera->GetLook(), this->camera->GetRight()) ); + } + + // shoot + //if( this->input->IsKeyPressed(DIK_Z) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = true; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = false; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + //if( this->input->IsKeyPressed(DIK_X) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = true; + // playerShot.utilityPressed = false; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + //if( this->input->IsKeyPressed(DIK_C) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = true; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + // jump + if( this->input->IsKeyPressed(DIK_SPACE) ) + { + this->netClient->Send( Protocol_PlayerJump() ); + } +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h new file mode 100644 index 00000000..9f93674b --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -0,0 +1,33 @@ +#ifndef DANBIAS_CLIENT_GAMING_UI_H +#define DANBIAS_CLIENT_GAMING_UI_H + +#include "GameStateUI.h" +#include "L_inputClass.h" +#include "Camera_FPSV2.h" + +namespace DanBias { namespace Client +{ + class GamingUI : public GameStateUI + { + public: + GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); + virtual ~GamingUI(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + + private: + InputClass *input; + ::Oyster::Network::NetworkClient *netClient; + Camera_FPSV2 *camera; + + GamingUI(); + void ReadKeyInput(); + }; +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.cpp b/Code/Game/GameClient/GameClientState/RespawnUI.cpp new file mode 100644 index 00000000..4588d367 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/RespawnUI.cpp @@ -0,0 +1,58 @@ +#include "RespawnUI.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; +using namespace ::Utility::Value; + +RespawnUI::RespawnUI() : + GameStateUI() +{ + /* Should never be called! */ + this->netClient = nullptr; + this->countDown = 0.0f; +} + +RespawnUI::RespawnUI( NetworkClient *connection, float delay ) : + GameStateUI() +{ + this->netClient = connection; + this->countDown = delay; +} + +RespawnUI::~RespawnUI() { /* Do nothing */ } + +GameStateUI::UIState RespawnUI::Update( float deltaTime ) +{ + this->countDown = Max( this->countDown - deltaTime, 0.0f ); + return this->nextState; +} + +bool RespawnUI::HaveGUIRender() const +{ + return false; // TODO: change to true when we want UI elements like a crosshair +} + +bool RespawnUI::HaveTextRender() const +{ + return false; // TODO: change to true when we want UI elements like a chat window +} + +void RespawnUI::RenderGUI() const +{ + // TODO: We need? +} + +void RespawnUI::RenderText() const +{ + // TODO: Text countdown somewhere on screen would be nice +} + +bool RespawnUI::Release() +{ + // TODO: Release UI components here. + return true; +} + + + + diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.h b/Code/Game/GameClient/GameClientState/RespawnUI.h new file mode 100644 index 00000000..c45616b7 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/RespawnUI.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_RESPAWN_UI_H +#define DANBIAS_CLIENT_RESPAWN_UI_H + +#include "GameStateUI.h" + +namespace DanBias { namespace Client +{ + class RespawnUI : public GameStateUI + { + public: + RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay ); + virtual ~RespawnUI(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + + private: + ::Oyster::Network::NetworkClient *netClient; + float countDown; + + RespawnUI(); + }; +} } + +#endif \ No newline at end of file diff --git a/Code/Misc/Input/L_inputClass.h b/Code/Misc/Input/L_inputClass.h index 8ed8e528..5511102a 100644 --- a/Code/Misc/Input/L_inputClass.h +++ b/Code/Misc/Input/L_inputClass.h @@ -7,6 +7,7 @@ #ifndef _INPUTCLASS_H_ #define _INPUTCLASS_H_ +#define NOMINMAX #define DIRECTINPUT_VERSION 0x0800 #pragma comment(lib, "dinput8.lib") From 3fe02213423f4e5625b7d0c26fdebb9e315fb430 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 13:41:05 +0100 Subject: [PATCH 13/21] GameClient - fixed render RB --- .../GameClient/GameClientState/GameState.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 41518db6..7ab0aeac 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -122,7 +122,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBInitData RBData; RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); - RBData.scale = Float3( 1 ); + RBData.scale = scale; // !RB DEBUG if( isMyPlayer ) { @@ -216,13 +216,16 @@ bool GameState::Render() dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - if( dynamicObject->second->getBRtype() == RB_Type_Cube) + if( dynamicObject->second ) { - Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); - } - if( dynamicObject->second->getBRtype() == RB_Type_Sphere) - { - Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } } } } @@ -479,8 +482,8 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState // if is this player. Remember to change camera if( this->privData->myId == decoded.object_ID ) { - //this->privData->camera.SetPosition( position ); - //this->privData->camera.SetRotation( rotation ); + this->privData->camera.SetPosition( position ); + this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); //this->privData->player.setRot( rotation ); } From b25a08ff901bba661546adf0d3888a051f3cb774 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 13:57:00 +0100 Subject: [PATCH 14/21] Fix in lvl loader - can now load shere RB --- Code/Game/LevelLoader/ParseFunctions.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp index b6b57d83..09adb298 100644 --- a/Code/Game/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -152,10 +152,9 @@ namespace GameLogic start = 0; LevelLoaderInternal::FormatVersion version; memcpy(&version, &buf[0], sizeof(version)); - start += 4; + start += 8; memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - start += sizeof(volume.geoType); switch(volume.geoType) { From 3520062577bd0a2b476bd729cfffaf523c9ffb4c Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 19 Feb 2014 13:59:59 +0100 Subject: [PATCH 15/21] Implemented TurnLeft function --- Code/Game/GameLogic/Player.cpp | 8 ++++++-- Code/Game/GameLogic/Player.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 00d098fa..b067d036 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -33,6 +33,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 100; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::Player(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, int teamID) @@ -53,6 +55,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 20; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::~Player(void) @@ -229,8 +233,8 @@ void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D: } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - //TODO: Conver delta radians to something that phyhsics use... - //this->rigidBody->; + this->rotationUp += deltaRadians; + this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); } void Player::Jump() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 73737d60..13c6e300 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -96,6 +96,8 @@ namespace GameLogic Oyster::Math::Float moveSpeed; Oyster::Math::Float3 previousMoveSpeed; + Oyster::Math::Float rotationUp; + bool hasTakenDamage; float invincibleCooldown; From cd4e5ae0ec8c7ee97679eca8c57604f39d95ec5b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:00:36 +0100 Subject: [PATCH 16/21] compilation error fixes --- Code/Game/GameClient/GameClientState/GameState.cpp | 8 +++----- Code/Game/GameClient/GameClientState/GamingUI.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7ab0aeac..af5f467e 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -319,11 +319,9 @@ void GameState::ReadKeyInput() //send delta mouse movement { - this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); - this->privData->camera.PitchDown( this->privData->input->GetPitch() * 0.017f ); - this->privData->camera.UpdateOrientation(); - - privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) ); + static const float mouseSensitivity = Radian( 1.0f ); + this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity ); + this->privData->nwClient->Send( Protocol_PlayerLeftTurn(this->privData->input->GetYaw() * mouseSensitivity) ); } // shoot diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index a2edc28f..8ff43d88 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -1,9 +1,11 @@ #include "GamingUI.h" #include +#include "Utilities.h" using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::GameLogic; +using namespace ::Utility::Value; GamingUI::GamingUI() : GameStateUI() @@ -92,11 +94,9 @@ void GamingUI::ReadKeyInput() //send delta mouse movement { - this->camera->YawRight( this->input->GetYaw() * 0.017f ); - this->camera->PitchDown( this->input->GetPitch() * 0.017f ); - this->camera->UpdateOrientation(); - - this->netClient->Send( Protocol_PlayerLook(this->camera->GetLook(), this->camera->GetRight()) ); + static const float mouseSensitivity = Radian( 1.0f ); + this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity ); + this->netClient->Send( Protocol_PlayerLeftTurn(this->input->GetYaw() * mouseSensitivity) ); } // shoot From 8917caf08af4b8078998c9b0ffa9a78b5074880c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:20:46 +0100 Subject: [PATCH 17/21] removed debug comment --- Code/Game/GameClient/GameClientState/GameState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index af5f467e..ed04c009 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -483,7 +483,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState this->privData->camera.SetPosition( position ); this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); - //this->privData->player.setRot( rotation ); + this->privData->player.setRot( rotation ); } C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; From 717e95bdfe6b87cecf83ac68ab2a9c26f27a19cf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 19 Feb 2014 14:49:20 +0100 Subject: [PATCH 18/21] Network - Added reconnect with the last address you connected on. --- .../GameClientState/LanMenuState.cpp | 3 --- Code/Game/LevelLoader/LevelParser.cpp | 2 -- Code/Game/LevelLoader/ParseFunctions.cpp | 3 +-- Code/Network/NetworkAPI/NetworkClient.cpp | 18 ++++++++++-------- .../Network/NetworkDependencies/Connection.cpp | 4 ++-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 7bd709cc..8c096617 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -126,9 +126,6 @@ void LanMenuState::ChangeState( ClientState next ) // attempt to connect to lobby if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) return; - //this->privData->nwClient->Disconnect(); - //if( !this->privData->nwClient->Reconnect() ) - //return; break; default: break; } diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 0c450f71..5f5a5341 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -157,8 +157,6 @@ std::vector> LevelParser::Parse(std::string filen break; } //this is a hotfix, fix so you only load the relevant data when the file is updated - - default: //Couldn't find specialType break; diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp index b6b57d83..09adb298 100644 --- a/Code/Game/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -152,10 +152,9 @@ namespace GameLogic start = 0; LevelLoaderInternal::FormatVersion version; memcpy(&version, &buf[0], sizeof(version)); - start += 4; + start += 8; memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - start += sizeof(volume.geoType); switch(volume.geoType) { diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 5bd10165..fc561845 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -290,9 +290,12 @@ bool NetworkClient::Connect(ConnectionInfo& socket) bool NetworkClient::Connect(unsigned short port, const char serverIP[]) { - if(this->IsConnected()) return false; - if(this->privateData) return false; - if(!this->privateData) this->privateData = new PrivateData(); + //Return true if you are already connected. + if(this->IsConnected()) + return true; + + if(!this->privateData) + this->privateData = new PrivateData(); int result = this->privateData->connection.Connect(port, serverIP, false); @@ -319,10 +322,10 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) bool NetworkClient::Reconnect() { + //Return true if you are already connected. if(this->IsConnected()) - return false; - //if(this->privateData) - //return false; + return true; + if(!this->privateData) this->privateData = new PrivateData(); int result = this->privateData->connection.Reconnect(); @@ -342,11 +345,10 @@ void NetworkClient::Disconnect() { if(!privateData) return; - privateData->thread.Terminate(); + privateData->thread.Stop(); privateData->connection.Disconnect(); this->privateData->sendQueue.Clear(); this->privateData->recieveQueue.Clear(); - } void NetworkClient::Send(CustomProtocolObject& protocol) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index a9abf75c..2cd992a2 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -91,14 +91,14 @@ int Connection::Reconnect() if(this->socket == -1 || this->socket == 0) InitiateSocket(); struct hostent *hostEnt; - if((hostEnt = gethostbyname(lastConnectAddr.c_str())) == NULL) + if((hostEnt = gethostbyname(this->lastConnectAddr.c_str())) == NULL) { return WSAGetLastError(); } struct sockaddr_in server; server.sin_family = AF_INET; - server.sin_port = htons(lastConnectPort); + server.sin_port = htons(this->lastConnectPort); server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr; SetBlockingMode(true); From 706395680f6d1914dd4a1d05fc269ff1a365bd23 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:51:37 +0100 Subject: [PATCH 19/21] Added bunch of Quaternion functions Needed one of them to create a bug trap --- Code/Misc/OysterMath/Quaternion.h | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index f5ea5951..b2390a2d 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -49,7 +49,16 @@ namespace LinearAlgebra Quaternion operator - ( const Quaternion &quaternion ) const; Quaternion operator - ( ) const; + Quaternion & Conjugate( ); + Quaternion & Normalize( ); + Quaternion & Inverse( ); + Quaternion GetConjugate( ) const; + Quaternion GetNormalized( ) const; + Quaternion GetInversed( ) const; + ScalarType GetNorm( ) const; + ScalarType GetModulus( ) const; + }; /////////////////////////////////////////////////////////////////////////////////// @@ -205,11 +214,54 @@ namespace LinearAlgebra return Quaternion(-this->imaginary, -this->real); } + template + inline Quaternion & Quaternion::Conjugate( ) + { + this->imaginary = -this->imaginary; + return *this; + } + + template + inline Quaternion & Quaternion::Normalize( ) + { + return *this /= this->GetModulus(); + } + + template + inline Quaternion & Quaternion::Inverse( ) + { + return this->Conjugate() /= this->GetNorm(); + } + template inline Quaternion Quaternion::GetConjugate( ) const { return Quaternion(-this->imaginary, this->real ); } + + template + inline Quaternion Quaternion::GetNormalized( ) const + { + return *this / this->GetModulus(); + } + + template + inline Quaternion Quaternion::GetInversed( ) const + { + return this->GetConjugate() /= this->GetNorm(); + } + + template + inline ScalarType Quaternion::GetNorm( ) const + { + return this->imaginary.Dot(this->imaginary) + this->real * this->real; + } + + template + inline ScalarType Quaternion::GetModulus( ) const + { + return (ScalarType)::std::sqrt( this->GetNorm() ); + } } #endif \ No newline at end of file From 4104ae8df7e4a5e0d502b2c82e1d448fe6affa27 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 15:00:28 +0100 Subject: [PATCH 20/21] Camera_FPSV2 fix + Added bug trap Camera_FPSV2::SetRotation Though it caught no bugs --- Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp index 12506d3c..3af0cae5 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -38,8 +38,13 @@ void Camera_FPSV2::SetPosition( const Float3 &translation ) void Camera_FPSV2::SetRotation( const Quaternion &rotation ) { + if( !Within(rotation.GetNorm(), .99f, 1.01f) ) + { // HACK: bug trap + const char *breakPoint = "Caught an invalid rotation!"; + } + this->body.rotation = rotation; - this->head.SetRotation( rotation * Rotation(this->pitchUp, this->GetNormalOf(Float3::standard_unit_x) ) ); + this->head.SetRotation( rotation * Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x) ) ); } void Camera_FPSV2::SetAngular( const Float3 &axis ) @@ -116,7 +121,7 @@ void Camera_FPSV2::StrafeLeft( Float distance ) void Camera_FPSV2::PitchUp( Float radian ) { this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); - this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) ); +// this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) ); } void Camera_FPSV2::PitchDown( Float radian ) From a9f554448cb94c1d4a620c4c83c62fc399af9b1d Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 15:20:50 +0100 Subject: [PATCH 21/21] some edits in Camera_FPSV2 --- .../GameClientState/Camera_FPSV2.cpp | 40 +++++++++++++++++-- .../GameClient/GameClientState/Camera_FPSV2.h | 3 +- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp index 3af0cae5..f2f3c1ad 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -10,6 +10,7 @@ Camera_FPSV2::Camera_FPSV2() this->headOffset = this->body.translation = Float3::null; this->body.rotation = Quaternion::identity; + this->pitchHaveChanged = false; } Camera_FPSV2::~Camera_FPSV2() {} @@ -21,6 +22,7 @@ Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera ) this->headOffset = camera.headOffset; this->body.translation = camera.body.translation; this->body.rotation = camera.body.rotation; + this->pitchHaveChanged = camera.pitchHaveChanged; return *this; } @@ -45,6 +47,7 @@ void Camera_FPSV2::SetRotation( const Quaternion &rotation ) this->body.rotation = rotation; this->head.SetRotation( rotation * Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; } void Camera_FPSV2::SetAngular( const Float3 &axis ) @@ -69,6 +72,12 @@ void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRati void Camera_FPSV2::UpdateOrientation() { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + Float4x4 orientation; OrientationMatrix( this->body.rotation, this->body.translation, orientation ); @@ -78,7 +87,8 @@ void Camera_FPSV2::UpdateOrientation() void Camera_FPSV2::SnapUpToNormal( const Float3 &normal ) { this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) ); - this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) ); + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; } void Camera_FPSV2::Move( const Float3 &deltaPosition ) @@ -89,8 +99,8 @@ void Camera_FPSV2::Move( const Float3 &deltaPosition ) void Camera_FPSV2::Rotate( const Quaternion &deltaRotation ) { - this->head.Rotate( deltaRotation ); this->body.rotation *= deltaRotation; + this->pitchHaveChanged = true; } void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis ) @@ -121,7 +131,7 @@ void Camera_FPSV2::StrafeLeft( Float distance ) void Camera_FPSV2::PitchUp( Float radian ) { this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); -// this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) ); + this->pitchHaveChanged = true; } void Camera_FPSV2::PitchDown( Float radian ) @@ -152,6 +162,12 @@ const Float3 & Camera_FPSV2::GetPosition() const Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetViewMatrix( targetMem ); } @@ -162,11 +178,23 @@ const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetViewsProjMatrix( targetMem ); } Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetNormalOf( axis ); } @@ -182,6 +210,12 @@ Float3 Camera_FPSV2::GetUp() const Float3 Camera_FPSV2::GetLook() const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetNormalOf( -Float3::standard_unit_z ); } diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h index 7f66b185..210c9707 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h @@ -50,7 +50,7 @@ public: ::Oyster::Math::Float3 GetForward() const; private: - Camera_BasicV2 head; + mutable Camera_BasicV2 head; ::Oyster::Math::Float pitchUp; ::Oyster::Math::Float3 headOffset; struct @@ -58,6 +58,7 @@ private: ::Oyster::Math::Float3 translation; ::Oyster::Math::Quaternion rotation; } body; + mutable bool pitchHaveChanged; }; #endif \ No newline at end of file