From 7c567ec3601438e7882bbcf10c9a34a3ca3688e3 Mon Sep 17 00:00:00 2001 From: lanariel Date: Wed, 8 Jan 2014 07:01:59 +0100 Subject: [PATCH 01/42] SSAO and frame counter --- Code/OysterGraphics/Core/Core.h | 1 + Code/OysterGraphics/Core/PipelineManager.cpp | 74 ++++++++-- .../Definitions/GraphicalDefinition.h | 9 +- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 23 ++- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 19 ++- .../OysterGraphics/FileLoader/ModelLoader.cpp | 5 +- Code/OysterGraphics/FileLoader/ObjReader.cpp | 24 +-- Code/OysterGraphics/FileLoader/ObjReader.h | 2 +- .../Render/Rendering/BasicRender.cpp | 14 +- Code/OysterGraphics/Render/Rendering/Render.h | 2 +- .../Render/Resources/Deffered.cpp | 137 +++++++++++++++--- .../Render/Resources/Deffered.h | 12 ++ .../HLSL/Deffered Shaders/Defines.hlsli | 19 ++- .../HLSL/Deffered Shaders/GBufferHeader.hlsli | 3 +- .../HLSL/Deffered Shaders/LightCalc.hlsli | 3 +- .../HLSL/Deffered Shaders/LightPass.hlsl | 35 +++-- .../Deffered Shaders/PosManipulation.hlsli | 13 +- .../HLSL/Deffered Shaders/PostPass.hlsl | 12 ++ .../Shader/HLSL/Deffered Shaders/SSAO.hlsli | 49 +++++++ .../Deffered Shaders/VertexGatherData.hlsl | 11 +- Code/Tester/MainTest.cpp | 60 +++----- 21 files changed, 374 insertions(+), 153 deletions(-) create mode 100644 Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl create mode 100644 Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli diff --git a/Code/OysterGraphics/Core/Core.h b/Code/OysterGraphics/Core/Core.h index 7d886dc6..126323eb 100644 --- a/Code/OysterGraphics/Core/Core.h +++ b/Code/OysterGraphics/Core/Core.h @@ -7,6 +7,7 @@ #include "Dx11Includes.h" #include #include "OysterMath.h" +#include namespace Oyster { diff --git a/Code/OysterGraphics/Core/PipelineManager.cpp b/Code/OysterGraphics/Core/PipelineManager.cpp index b9a4df14..ae9e4088 100644 --- a/Code/OysterGraphics/Core/PipelineManager.cpp +++ b/Code/OysterGraphics/Core/PipelineManager.cpp @@ -52,8 +52,15 @@ namespace Oyster data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload); if(data) { - VSMap[name] = VS.size(); - VS.push_back((ID3D11VertexShader*)data); + if(ForceReload && VSMap.count(name)) + { + VS[VSMap[name]] = (ID3D11VertexShader*)data; + } + else + { + VSMap[name] = VS.size(); + VS.push_back((ID3D11VertexShader*)data); + } } } break; @@ -63,8 +70,16 @@ namespace Oyster { if(data!=0) { - HSMap[name] = HS.size(); - HS.push_back((ID3D11HullShader*)data); + if(ForceReload && HSMap.count(name)) + { + HS[HSMap[name]] = (ID3D11HullShader*)data; + } + else + { + HSMap[name] = HS.size(); + HS.push_back((ID3D11HullShader*)data); + } + } } break; @@ -74,8 +89,15 @@ namespace Oyster { if(data!=0) { - DSMap[name] = DS.size(); - DS.push_back((ID3D11DomainShader*)data); + if(ForceReload && DSMap.count(name)) + { + DS[DSMap[name]] = (ID3D11DomainShader*)data; + } + else + { + DSMap[name] = DS.size(); + DS.push_back((ID3D11DomainShader*)data); + } } } break; @@ -85,8 +107,15 @@ namespace Oyster { if(data!=0) { - GSMap[name] = GS.size(); - GS.push_back((ID3D11GeometryShader*)data); + if(ForceReload && GSMap.count(name)) + { + GS[GSMap[name]] = (ID3D11GeometryShader*)data; + } + else + { + GSMap[name] = GS.size(); + GS.push_back((ID3D11GeometryShader*)data); + } } } break; @@ -96,8 +125,15 @@ namespace Oyster { if(data!=0) { - PSMap[name] = PS.size(); - PS.push_back((ID3D11PixelShader*)data); + if(ForceReload && PSMap.count(name)) + { + PS[PSMap[name]] = (ID3D11PixelShader*)data; + } + else + { + PSMap[name] = PS.size(); + PS.push_back((ID3D11PixelShader*)data); + } } } break; @@ -107,8 +143,16 @@ namespace Oyster { if(data!=0) { - CSMap[name] = CS.size(); - CS.push_back((ID3D11ComputeShader*)data); + if(ForceReload && CSMap.count(name)) + { + CS[CSMap[name]] = (ID3D11ComputeShader*)data; + } + else + { + CSMap[name] = CS.size(); + CS.push_back((ID3D11ComputeShader*)data); + } + } } break; @@ -375,9 +419,9 @@ namespace Oyster void Core::PipelineManager::CleanPipeline() { - deviceContext->VSSetShaderResources(0,16,Core::srvNULL); - deviceContext->GSSetShaderResources(0,16,Core::srvNULL); - deviceContext->PSSetShaderResources(0,16,Core::srvNULL); + //deviceContext->VSSetShaderResources(0,16,Core::srvNULL); + //deviceContext->GSSetShaderResources(0,16,Core::srvNULL); + //deviceContext->PSSetShaderResources(0,16,Core::srvNULL); deviceContext->CSSetShaderResources(0,16,Core::srvNULL); deviceContext->CSSetUnorderedAccessViews(0,8,Core::uavNULL,NULL); deviceContext->OMSetRenderTargets(8,Core::rtvNULL, NULL); diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index e81d787b..d6529c48 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -20,6 +20,12 @@ namespace Oyster Oyster::Math::Matrix P; }; + struct PerModel + { + Math::Matrix WV; + Math::Matrix WVP; + }; + struct FinalVertex { Oyster::Math::Float3 pos; @@ -34,9 +40,10 @@ namespace Oyster struct LightConstants { Math::Float4x4 InvProj; + Math::Float4x4 Proj; Math::Float2 Pixels; int Lights; - float Pad; + float SSAORadius; Oyster::Math::Float4x4 View; }; diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index f02d36a2..4d612513 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -6,6 +6,7 @@ #include "../FileLoader/ObjReader.h" #include "../../Misc/Resource/OysterResource.h" #include "../FileLoader/GeneralLoader.h" +#include namespace Oyster { @@ -26,12 +27,6 @@ namespace Oyster { return API::Fail; } -#ifdef _DEBUG - if(Render::Resources::Debug::Init() == Core::Init::Fail) - { - return API::Fail; - } -#endif Render::Resources::Deffered::Init(); Render::Preparations::Basic::SetViewPort(); @@ -62,12 +57,12 @@ namespace Oyster void API::RenderScene(Model::Model models[], int count) { - Render::Rendering::Basic::RenderScene(models,count); + Render::Rendering::Basic::RenderScene(models,count, View, Projection); } void API::RenderModel(Model::Model& m) { - Render::Rendering::Basic::RenderScene(&m,1); + Render::Rendering::Basic::RenderScene(&m,1, View, Projection); } void API::EndFrame() @@ -103,10 +98,6 @@ namespace Oyster SAFE_DELETE(Core::viewPort); Oyster::Resource::OysterResource::Clean(); Oyster::Graphics::Core::PipelineManager::Clean(); - -#ifdef _DEBUG - Oyster::Graphics::Render::Resources::Debug::Clean(); -#endif Oyster::Graphics::Render::Resources::Deffered::Clean(); SAFE_RELEASE(Core::depthStencil); @@ -128,5 +119,13 @@ namespace Oyster { Lights.clear(); } + +#ifdef _DEBUG + API::State API::ReloadShaders() + { + Render::Resources::Deffered::InitShaders(); + return State::Sucsess; + } +#endif } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index e218fb7c..65bffe5a 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -4,7 +4,7 @@ #include "..\Model\Model.h" #include "OysterMath.h" #include -//#include +#include #ifdef GFX_DLL_EXPORT #define GFX_DLL_USAGE __declspec(dllexport) @@ -29,23 +29,40 @@ namespace Oyster }; static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion); +#ifdef _DEBUG + static State ReloadShaders(); +#endif + + //! @todo Memory Leaks + + //! @brief Clean Resources and release all memory static void Clean(); + //! @brief Sets the view matrix to use next frame static void SetView(Oyster::Math::Float4x4& View); + //! @brief Sets the projection matrix to use next frame static void SetProjection(Oyster::Math::Float4x4& Projection); //! @brief will internally use last values from SetView and SetProjection static void NewFrame(); + //! @brief Renders a list of models static void RenderScene(Oyster::Graphics::Model::Model models[], int count); + //! @brief Renders a single model static void RenderModel(Oyster::Graphics::Model::Model& model); + //! @brief Performs light calculations, post effects and presents the scene static void EndFrame(); + //! @brief Creates a model from the supplied file, note: do not include .obj static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename); + //! @brief deletes a model and relases the models resources static void DeleteModel(Oyster::Graphics::Model::Model* model); + //! @brief adds a light to the scene static void AddLight(Definitions::Pointlight light); + //! @brief removes all lights from the scene static void ClearLights(); + //! @brief Sets Options to the graphics, note: currently unused static State SetOptions(Option); }; } diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index 8a2d52b8..cfd61e0d 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -39,11 +39,12 @@ void Oyster::Graphics::Loading::UnloadTexture(void* data) void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out) { - FileLoaders::ObjReader* obj = FileLoaders::ObjReader::LoadFile(filename); + FileLoaders::ObjReader obj; + obj.LoadFile(filename); Model::ModelInfo* info = new Model::ModelInfo(); Oyster::FileLoaders::ObjReader::Vertex* vdata; int count; - obj->GetVertexData(&vdata, count); + obj.GetVertexData(&vdata, count); info->Vertices = new Core::Buffer(); Core::Buffer::BUFFER_INIT_DESC desc; desc.ElementSize = sizeof(FileLoaders::ObjReader::Vertex); diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index e34ca8fd..ccc32fea 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -3,31 +3,16 @@ #include "..\Core\Core.h" #include #include +#include using namespace std; using namespace Oyster::FileLoaders; using namespace Oyster; using namespace Oyster::Math; -ObjReader *ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform) +void ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform) { - static std::map cache; - - ObjReader *reader = NULL; - - if (cache.count(fileName)) - { - reader = cache[fileName]; - } - else - { - reader = new ObjReader(); - reader->ParseFile(fileName + L".obj", transform); - - cache[fileName] = reader; - } - - return reader; + this->ParseFile(fileName + L".obj", transform); } ObjReader::ObjReader(void) @@ -37,6 +22,7 @@ ObjReader::ObjReader(void) ObjReader::~ObjReader(void) { + SAFE_DELETE_ARRAY(this->vertices); } void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform) @@ -50,7 +36,6 @@ void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform) } wstring path; - //Utility::String::ExtractDirPath(path,fileName,'\\'); std::vector VertexList; std::vector vList; @@ -74,6 +59,7 @@ void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform) if(c==L"v") { position = readVertex(offset,s); + //position *= 0.001f; vList.push_back(position); } else if(c==L"vt") diff --git a/Code/OysterGraphics/FileLoader/ObjReader.h b/Code/OysterGraphics/FileLoader/ObjReader.h index bb361b07..4ae2bffd 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.h +++ b/Code/OysterGraphics/FileLoader/ObjReader.h @@ -16,7 +16,7 @@ namespace Oyster Oyster::Math::Float3 Normal; }; - static ObjReader *LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity); + void LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity); ObjReader(void); ~ObjReader(void); diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index e61bd656..9950ce76 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -34,6 +34,8 @@ namespace Oyster lc.Pixels = Core::resolution; lc.Lights = numLights; lc.View = View; + lc.Proj = Projection; + lc.SSAORadius = 3; data = Resources::Deffered::LightConstantsData.Map(); memcpy(data, &lc, sizeof(Definitions::LightConstants)); @@ -44,14 +46,18 @@ namespace Oyster Resources::Deffered::PointLightsData.Unmap(); } - void Basic::RenderScene(Model::Model* models, int count) + void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection) { for(int i = 0; i < count; ++i) { if(models[i].Visible) { + Definitions::PerModel pm; + pm.WV = View * models[i].WorldMatrix; + pm.WVP = Projection * pm.WV; + void* data = Resources::Deffered::ModelData.Map(); - memcpy(data,&(models[i].WorldMatrix),sizeof(Math::Float4x4)); + memcpy(data,&(pm),sizeof(pm)); Resources::Deffered::ModelData.Unmap(); @@ -82,6 +88,10 @@ namespace Oyster Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1); + Core::PipelineManager::SetRenderPass(Resources::Deffered::PostPass); + + Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1); + Core::swapChain->Present(0,0); } } diff --git a/Code/OysterGraphics/Render/Rendering/Render.h b/Code/OysterGraphics/Render/Rendering/Render.h index 62604d6c..48d153d4 100644 --- a/Code/OysterGraphics/Render/Rendering/Render.h +++ b/Code/OysterGraphics/Render/Rendering/Render.h @@ -17,7 +17,7 @@ namespace Oyster public: static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights); - static void RenderScene(Model::Model* models, int count); + static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection); static void EndFrame(); }; } diff --git a/Code/OysterGraphics/Render/Resources/Deffered.cpp b/Code/OysterGraphics/Render/Resources/Deffered.cpp index e14ac812..77bcad09 100644 --- a/Code/OysterGraphics/Render/Resources/Deffered.cpp +++ b/Code/OysterGraphics/Render/Resources/Deffered.cpp @@ -11,6 +11,9 @@ typedef Oyster::Graphics::Core::Buffer Buffer; const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\Deffered Shaders\\"; const std::wstring PathToCSO = L"..\\Content\\Shaders\\"; +const int KernelSize = 10; +const int SampleSpread = 8; + namespace Oyster { namespace Graphics @@ -20,12 +23,15 @@ namespace Oyster namespace Resources { - ID3D11RenderTargetView* Deffered::GBufferRTV[2] = {0}; - ID3D11ShaderResourceView* Deffered::GBufferSRV[2] = {0}; + ID3D11RenderTargetView* Deffered::GBufferRTV[Deffered::GBufferSize] = {0}; + ID3D11ShaderResourceView* Deffered::GBufferSRV[Deffered::GBufferSize] = {0}; + ID3D11UnorderedAccessView* Deffered::LBufferUAV[Deffered::LBufferSize] = {0}; + ID3D11ShaderResourceView* Deffered::LBufferSRV[Deffered::LBufferSize] = {0}; Shader::RenderPass Deffered::GeometryPass; Shader::RenderPass Deffered::LightPass; + Shader::RenderPass Deffered::PostPass; Buffer Deffered::ModelData = Buffer(); Buffer Deffered::VPData = Buffer(); @@ -34,9 +40,12 @@ namespace Oyster Buffer Deffered::PointLightsData = Buffer(); ID3D11ShaderResourceView* Deffered::PointLightView = NULL; - Core::Init::State Deffered::Init() + ID3D11ShaderResourceView* Deffered::SSAOKernel = NULL; + ID3D11ShaderResourceView* Deffered::SSAORandom = NULL; + + Core::Init::State Deffered::InitShaders() { -#ifdef _DEBUG + #ifdef _DEBUG std::wstring path = PathToHLSL; std::wstring end = L".hlsl"; #else @@ -47,10 +56,17 @@ namespace Oyster Core::PipelineManager::Init(path + L"PixelGatherData" + end, ShaderType::Pixel, L"Geometry"); Core::PipelineManager::Init(path + L"VertexGatherData" + end, ShaderType::Vertex, L"Geometry"); Core::PipelineManager::Init(path + L"LightPass" + end, ShaderType::Compute, L"LightPass"); + Core::PipelineManager::Init(path + L"PostPass" + end, ShaderType::Compute, L"PostPass"); + return Core::Init::State::Success; + } + + Core::Init::State Deffered::Init() + { + InitShaders(); //Create Buffers Buffer::BUFFER_INIT_DESC desc; - desc.ElementSize = sizeof(Oyster::Math::Matrix); + desc.ElementSize = sizeof(Definitions::PerModel); desc.NumElements = 1; desc.InitData = NULL; desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS; @@ -72,7 +88,7 @@ namespace Oyster desc.Type = Buffer::STRUCTURED_BUFFER; PointLightsData.Init(desc); - //Create States + ////Create States D3D11_RASTERIZER_DESC rdesc; rdesc.CullMode = D3D11_CULL_BACK; rdesc.FillMode = D3D11_FILL_SOLID; @@ -131,11 +147,82 @@ namespace Oyster Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL); } + for(int i = 0; i < Resources::Deffered::LBufferSize; ++i) + { + Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]); + } + Buffer* b = &PointLightsData; Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL); + srand(time(0)); + //SSAO + Math::Vector3 kernel[KernelSize]; + Math::Vector3 random[SampleSpread]; + for(int i = 0;i < KernelSize; ++i) + { + kernel[i] = Oyster::Math::Vector3::null; + while( kernel[i] == Oyster::Math::Vector3::null ) + { + kernel[i] = Oyster::Math::Vector3( + (float)rand() / (RAND_MAX + 1) * (1 - -1) + -1, + (float)rand() / (RAND_MAX + 1) * (1 - -1) + -1, + (float)rand() / (RAND_MAX + 1) * (1 - 0) + 0); + } + kernel[i].Normalize(); - //Create ShaderEffects + float scale = float(i) / float(KernelSize); + + scale = (0.1f*(1 - scale * scale) + 1.0f *( scale * scale)); + kernel[i] *= scale; + + + } + + for( int i = 0; i < SampleSpread; ++i) + { + random[i] = Oyster::Math::Vector3::null; + while( random[i] == Oyster::Math::Vector3::null ) + { + random[i] = Oyster::Math::Vector3( + (float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, + (float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, + 0.0f); + } + random[i].Normalize(); + } + //kernel[0] = Math::Vector3(0,1,1); + //kernel[0].Normalize(); + + D3D11_TEXTURE1D_DESC T1desc; + T1desc.Width = KernelSize; + T1desc.MipLevels = T1desc.ArraySize = 1; + T1desc.Format = DXGI_FORMAT_R32G32B32_FLOAT; + T1desc.Usage = D3D11_USAGE_DEFAULT; + T1desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + T1desc.CPUAccessFlags = 0; + T1desc.MiscFlags = 0; + + D3D11_SUBRESOURCE_DATA sphere; + sphere.pSysMem = kernel; + + D3D11_SUBRESOURCE_DATA rnd; + rnd.pSysMem = random; + + ID3D11Texture1D *pTexture1[2]; + + Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1[0] ); + Core::device->CreateShaderResourceView( pTexture1[0], 0, &SSAOKernel ); + pTexture1[0]->Release(); + + T1desc.Width = SampleSpread; + Core::device->CreateTexture1D( &T1desc, &rnd, &pTexture1[1] ); + Core::device->CreateShaderResourceView( (pTexture1[1]), 0, &SSAORandom ); + pTexture1[1]->Release(); + + ////Create ShaderEffects + + ////---------------- Geometry Pass Setup ---------------------------- GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry"); GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry"); @@ -161,8 +248,12 @@ namespace Oyster } GeometryPass.depth = Core::depthStencil; + ////---------------- Light Pass Setup ---------------------------- LightPass.Shaders.Compute = GetShader::Compute(L"LightPass"); - LightPass.UAV.Compute.push_back(Core::backBufferUAV); + for(int i = 0; i Points : register(t3); -StructuredBuffer Points : register(t3); +Texture1D SSAOKernel : register(t4); +Texture1D SSAORand : register(t5); -RWTexture2D Output : register(u0); +RWTexture2D Diffuse : register(u0); +RWTexture2D Specular : register(u1); +RWTexture2D Ambient : register(u2); #endif \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli index 49c42127..2f5a4a01 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli @@ -39,5 +39,6 @@ cbuffer PerFrame : register(b0) cbuffer PerModel : register(b1) { - matrix World; + matrix WV; + matrix WVP; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli index 64c3c98c..bd449209 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli @@ -14,9 +14,8 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w); //Check att later float att = max( 0, 1 - (d / pl.Radius)); - //att = 1; //fix Ilum calcs instead of PhongBlinn - output.Diffuse = pl.Bright * att * diffFactor * pl.Color; + output.Diffuse = pl.Bright * att * diffFactor * pl.Color; output.Specular = pl.Bright * att * specFactor * pl.Color; if(diffFactor == 0) output.Specular * 0; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl index 268c3365..98b2887e 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl @@ -1,31 +1,40 @@ #include "Defines.hlsli" #include "LightCalc.hlsli" #include "PosManipulation.hlsli" +#include "SSAO.hlsli" //todo //LightCulling -//Calc Diff + Spec -//Calc Ambience +//Calc Diff + Spec Done +//Calc Ambience Done //Write Glow [numthreads(16, 16, 1)] -void main( uint3 DTid : SV_DispatchThreadID ) +void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) { - float3 ViewPos = ToVpos(DTid.xy); + float2 UV = DTid / Pixels; + UV.x = UV.x * 2 - 1; + UV.y = 1 - 2 * UV.y; + float3 ViewPos = ToVpos(DTid.xy, UV); DiffSpec Shaded; Shaded.Diffuse = float4(0,0,0,0); Shaded.Specular = float4(0,0,0,0); + for(int i = 0; i < Lights; ++i) { DiffSpec light = LightCalc(Points[i], ViewPos, DTid.xy); - Shaded.Diffuse = light.Diffuse; - Shaded.Specular = light.Specular; + Shaded.Diffuse += light.Diffuse; + Shaded.Specular += light.Specular; } - //Output[DTid.xy] = float4(ViewPos,1); - //Output[DTid.xy] = DepthTexture[DTid.xy].x; - //Output[DTid.xy] = float4(DTid.xy/ Pixels,1,1); - //Output[DTid.xy] = NormalSpec[DTid.xy]; - //Output[DTid.xy] = float4(light.Diffuse, 1); - //Output[DTid.xy] = float4(light.Specular, 1); - Output[DTid.xy] = float4( Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz + Shaded.Specular + DiffuseGlow[DTid.xy].xyz * 0.2f, 1); + + Diffuse[DTid.xy] = float4(Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz,1); + Specular[DTid.xy] = float4(Shaded.Specular, 1); + + + if((DTid.x + DTid.y) %4 == 0 ) + { + float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy); + Ambient[DTid.xy/4] = AmbValue; + } + } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PosManipulation.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PosManipulation.hlsli index 8c4b2e48..5393655e 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PosManipulation.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PosManipulation.hlsli @@ -1,22 +1,23 @@ +#ifndef PosHelper +#define PosHelper #include "Defines.hlsli" //assumes ProperfloatTexCoords -float3 ToVpos(float2 texCoord) +float3 ToVpos(int2 texCoord, float2 UV) { - //Get proper UV - float2 UV = texCoord / Pixels; float4 ViewPos = float4(0,0,0,0); // Get the depth value for this pixel ViewPos.z= DepthTexture[texCoord].x; //Get X/w - ViewPos.x = UV.x * 2 - 1; + ViewPos.x = UV.x; //Get Y/w //ViewPos.y = -(UV.y * 2) + 1; - ViewPos.y = 1 - 2 * UV.y; + ViewPos.y = UV.y; ViewPos.w = 1; //Un project ViewPos = mul(InvProj, ViewPos); return ViewPos.xyz / ViewPos.w; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl new file mode 100644 index 00000000..1c52e5bf --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl @@ -0,0 +1,12 @@ +Texture2D Diffuse : register(t0); +Texture2D Specular : register(t1); +Texture2D Ambient : register(t2); + +RWTexture2D Output; + +[numthreads(16, 16, 1)] +void main( uint3 DTid : SV_DispatchThreadID ) +{ + //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW + Output[DTid.xy] = Diffuse[DTid.xy]; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli new file mode 100644 index 00000000..32f84f90 --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli @@ -0,0 +1,49 @@ +#include "Defines.hlsli" +#include "PosManipulation.hlsli" + +static float Radius =5; + +float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) +{ + + float occlusion = 0.0f; + //create sample coordinate system + float4 rnd = float4( SSAORand[(rndID.x + rndID.y) % SSAORand.Length.x].xyz, 0.0f ); + rnd = normalize(rnd); + float3 normal = NormalSpec[uv].xyz; + float4 tangent = float4( normalize(rnd.xyz - (normal * dot(rnd.xyz, normal))), 0.0f ); + float4 biTangent = float4( cross(tangent.xyz, normal), 0.0f ); + + float4x4 tbn = float4x4(tangent, biTangent, float4(normal,0), float4(pos*Radius,1)); + + for( uint i = 0; i < SSAOKernel.Length.x; ++i ) + { + //take sample from localspace to viewspace + float4 sampled = mul(tbn, float4(SSAOKernel[i].xyz,1)); + //project sample to get uv.xy + float4 ProjOffset = sampled; + ProjOffset = mul(Proj, ProjOffset); + float4 offset = ProjOffset; + float2 UV = offset; + offset /= offset.w; + offset.xyz = offset.xyz * 0.5f + 0.5f; + //extra invert y axis, DX11 + offset.y = 1.0f - offset.y; + + // get depth from that point in screenspace + uint2 texCoord; + texCoord = (uint2)(offset.xy * Pixels); + float3 ViewPos = ToVpos(texCoord, UV); + + float sampleDepth = ViewPos.z; + + //compare to depth from sample + float rangeCheck = (abs(pos.z - sampleDepth) < Radius) ? 1.0f : 0.0f; + occlusion += (sampleDepth >= sampled.z ? 1.0f : 0.0f) * rangeCheck; + } + occlusion /= (float)(SSAOKernel.Length.x); + occlusion = 1.0f - occlusion; + + return occlusion; +} + diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl index d713408f..e0cf21c3 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl @@ -3,15 +3,8 @@ VertexOut main( VertexIn input ) { VertexOut output; - float4 WorldPos = mul(World, float4(input.pos,1)); - float4 ViewPos = mul(View, WorldPos); - output.pos = mul(Projection, ViewPos); - float4 WorldNor = mul(World, float4(input.normal,0)); - float4 ViewNor = mul(View, WorldNor); - output.normal = ViewNor; - //output.normal.z *= -1; - + output.pos = mul(WVP, float4(input.pos,1)); + output.normal = mul(WV, float4(input.normal,0)); output.UV = input.UV; - //output.normal = ViewNor; return output; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 4a684915..cfa3b8b6 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -70,8 +70,11 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL __int64 prevTimeStamp = 0; QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp); + std::string fps = "FPS:"; + char count[100]; // Main message loop MSG msg = {0}; + float fpsCounter = 0; while(WM_QUIT != msg.message) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) ) @@ -88,13 +91,20 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL //render Update(dt); Render(dt); - + fpsCounter += dt; + if(fpsCounter>0.1f) + { + sprintf_s(count, "%f",1/dt); + SetWindowTextA(g_hWnd, (fps + count).c_str()); + fpsCounter = 0; + } prevTimeStamp = currTimeStamp; } } Oyster::Graphics::API::DeleteModel(m); Oyster::Graphics::API::DeleteModel(m2); + Oyster::Graphics::API::DeleteModel(m3); Oyster::Graphics::API::Clean(); return (int) msg.wParam; } @@ -160,57 +170,25 @@ HRESULT InitDirect3D() { return E_FAIL; } - -#pragma region Triangle - //Oyster::Graphics::Definitions::ObjVertex mesh[] = - //{ - // {Oyster::Math::Vector3(-1,1,0),Oyster::Math::Vector2(0,0),Oyster::Math::Vector3(1,1,0)}, - // {Oyster::Math::Vector3(1,-1,0),Oyster::Math::Vector2(0,0),Oyster::Math::Vector3(1,1,0)}, - // {Oyster::Math::Vector3(1,1,0),Oyster::Math::Vector2(0,0),Oyster::Math::Vector3(1,1,0)}, - //}; - - //Oyster::Graphics::Buffer::BUFFER_INIT_DESC desc; - //desc.ElementSize= sizeof(Oyster::Graphics::Definitions::ObjVertex); - //desc.NumElements = 3; - //desc.InitData=mesh; - //desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::VERTEX_BUFFER; - //desc.Usage = Oyster::Graphics::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE; - - //Oyster::Graphics::Buffer *b = new Oyster::Graphics::Buffer();; - //b->Init(desc); - - ////b.Apply(0); - //Oyster::Graphics::Render::ModelInfo* mi = new Oyster::Graphics::Render::ModelInfo(); - //mi->Indexed = false; - //mi->VertexCount = 3; - //mi->Vertices = b; - //m->info = mi; -#pragma endregion - -#pragma region Obj - m = Oyster::Graphics::API::CreateModel(L"orca_dummy"); + m = Oyster::Graphics::API::CreateModel(L"christmastree"); m2 = Oyster::Graphics::API::CreateModel(L"worldDummy"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); m3 = Oyster::Graphics::API::CreateModel(L"worldDummy"); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); -#pragma endregion - P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000); + P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,100); Oyster::Graphics::API::SetProjection(P); - P.Invert(); - V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f)); - //V = Oyster::Math3D::OrientationMatrix_LookAtPos(Oyster::Math::Float3(0,0,0), Oyster::Math::Float3(0,1,0), Oyster::Math::Float3(0,0,-5.4f)); - //V.v[3][2] *= -1; + V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,15.4f)); V = V.GetInverse(); Oyster::Graphics::Definitions::Pointlight pl; pl.Color = Oyster::Math::Float3(1,1,1); pl.Bright = 1; - pl.Pos = Oyster::Math::Float3(0,0,5.4f); + pl.Pos = Oyster::Math::Float3(0,5,5.4f); pl.Radius = 15; Oyster::Graphics::API::AddLight(pl); @@ -222,7 +200,7 @@ float angle = 0; HRESULT Update(float deltaTime) { - angle += Oyster::Math::pi/10000; + angle += Oyster::Math::pi/8 * deltaTime; m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-angle,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null); @@ -269,6 +247,12 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam case VK_ESCAPE: PostQuitMessage(0); break; + //R + case 0x52: +#ifdef _DEBUG + Oyster::Graphics::API::ReloadShaders(); +#endif + break; } break; From 0a3d68a407204856daf9abf44035eb6e6b3be17e Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 9 Jan 2014 01:08:49 +0100 Subject: [PATCH 02/42] Small bug fix and include new SSAO shader --- Code/OysterGraphics/OysterGraphics.vcxproj | 13 +++++++++++-- Code/Tester/MainTest.cpp | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj b/Code/OysterGraphics/OysterGraphics.vcxproj index 659d9087..d2196e4e 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj +++ b/Code/OysterGraphics/OysterGraphics.vcxproj @@ -182,7 +182,6 @@ - @@ -196,7 +195,6 @@ - @@ -219,6 +217,16 @@ Pixel Pixel + + Compute + 5.0 + Compute + 5.0 + Compute + 5.0 + Compute + 5.0 + Vertex Vertex @@ -268,6 +276,7 @@ + diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index cfa3b8b6..e3284c0b 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -171,7 +171,7 @@ HRESULT InitDirect3D() return E_FAIL; } - m = Oyster::Graphics::API::CreateModel(L"christmastree"); + m = Oyster::Graphics::API::CreateModel(L"orca_dummy"); m2 = Oyster::Graphics::API::CreateModel(L"worldDummy"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); m3 = Oyster::Graphics::API::CreateModel(L"worldDummy"); From 4a07586076459bc107ce54b53c8812d9fdd1abf3 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 9 Jan 2014 12:43:32 +0100 Subject: [PATCH 03/42] state --- Code/DanBiasGame/DanBiasGame.vcxproj.user | 22 ++++++++++++++++++++++ Code/Game/GameLogic/Object.h | 1 + Code/Game/GameLogic/Player.cpp | Bin 3037 -> 3103 bytes Code/GameLogic/GameLogic.vcxproj.user | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 Code/DanBiasGame/DanBiasGame.vcxproj.user create mode 100644 Code/GameLogic/GameLogic.vcxproj.user diff --git a/Code/DanBiasGame/DanBiasGame.vcxproj.user b/Code/DanBiasGame/DanBiasGame.vcxproj.user new file mode 100644 index 00000000..1371945a --- /dev/null +++ b/Code/DanBiasGame/DanBiasGame.vcxproj.user @@ -0,0 +1,22 @@ + + + + true + + + $(SolutionDir)..\Bin\Executable\Tester + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index a73dc154..5442424f 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -36,6 +36,7 @@ namespace GameLogic int objectID; protected: Oyster::Physics::ICustomBody *rigidBody; + Oyster::Physics::ICustomBody::State *state; }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ecf60dd310744c606c1634c2f19cc31d79702227..c9c356a152677295faf23f618cf3520f0f99d897 100644 GIT binary patch literal 3103 kcmeIu0Sy2E0K%a6Pwi$7h(KY$fB^#r3>YwAz<_}d3=AIt0RR91 literal 3037 zcmd5;QE%EX5Pl}V!rG+COwdy8jcS!r2rOMF5oJSrLT+NfYltJqfY8+b_MPLzP10=Y zx@ww~huCM|eg5wA`QEZPh;|`GZ~TZHsW{oZvEG`w=`od5Oo-f6=LbBBSju=jAu(Ck zcP%JMc&v60^!S+Pb zA(6!TVYNy_+_qXU(>i2<(MJ^11JWpP`y34LMQlaEa@Omq2}#M;9m2SKriMv&_8STA zVb1sLZ_aFaGq>jsge{Gh?$C1p8Mx#8ZpZ|zE^sTB`u$PFiTr@iI=xO$g}#Ty4-HV+ z3SkWwuxH>~A&n@+*Ru-Mz1j}gSuBx)4|D2QV~2r0A$o6il%b;1nP6=bN|YZ0%+~$( zsECEL8M-r06t(^7?ROeTT+cdildUoH9W=eXat8C|{F@KVl?F=Hp0hC9m-ABqg{79V8GTInp5lPVDM&`=Y%=}oOq}aEdbb7Jmc}x3bb8vz zMz9kCmVBiV512dxK*825yyW4rdoiYRrbZr%DG|jQr7o+L9+(U^_%VjcXFyU~$6>@& z09%fxvxPky_95FXg@44wfrwD6wsk8gxl<9I=j_rRe6D!AB*C3>m%hxO=ZxkCnMYUh zWo~Bf_|u~wU~%(8M^|4aeun32w@s>8;G%#Yp2)$_sdRUGYWr@#?}9)`98laov6Cb^ z!kU2E5}Raq%wLxF0ce5>-0o=MbuWsm|6Uan5WxM@xFzCWBXai-Lg)PIutSal!P68a zf`_V>f>JkVrA3DJaH+XKBo5&!u8CxOiq?YcmH4$yk=A%uRN=$jDp6y-^_q(g2P*vcUl1E zjgy@&g++4o6Vknat@v?8R*x%}YNp=tLyQ|mk(qoBZ&Y4p>-X)3$~=WeIi1obP)32L z@>&;@$)CN_kItU=R@V!Nt}?H3f1BvSy$*Bw?&Xq8$HO3Up{9w9Tjdjmx@*~<||n3=sfE`8+R4$U0set cvV~ULgFX-|XJIzX4r}767PtE`H^Jro31M2q{{R30 diff --git a/Code/GameLogic/GameLogic.vcxproj.user b/Code/GameLogic/GameLogic.vcxproj.user new file mode 100644 index 00000000..75ed2a95 --- /dev/null +++ b/Code/GameLogic/GameLogic.vcxproj.user @@ -0,0 +1,22 @@ + + + + true + + + $(SolutionDir)..\Bin\Executable\Tester + WindowsLocalDebugger + + + $(SolutionDir)..\Bin\Executable\Tester + WindowsLocalDebugger + + + $(SolutionDir)..\Bin\Executable\Tester + WindowsLocalDebugger + + + $(SolutionDir)..\Bin\Executable\Tester + WindowsLocalDebugger + + \ No newline at end of file From 48b9189a03a649b00b1cf6f4f37395e4334db752 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 9 Jan 2014 12:51:17 +0100 Subject: [PATCH 04/42] Revert "state" This reverts commit 4a07586076459bc107ce54b53c8812d9fdd1abf3. --- Code/DanBiasGame/DanBiasGame.vcxproj.user | 22 ---------------------- Code/Game/GameLogic/Object.h | 1 - Code/Game/GameLogic/Player.cpp | Bin 3103 -> 3037 bytes Code/GameLogic/GameLogic.vcxproj.user | 22 ---------------------- 4 files changed, 45 deletions(-) delete mode 100644 Code/DanBiasGame/DanBiasGame.vcxproj.user delete mode 100644 Code/GameLogic/GameLogic.vcxproj.user diff --git a/Code/DanBiasGame/DanBiasGame.vcxproj.user b/Code/DanBiasGame/DanBiasGame.vcxproj.user deleted file mode 100644 index 1371945a..00000000 --- a/Code/DanBiasGame/DanBiasGame.vcxproj.user +++ /dev/null @@ -1,22 +0,0 @@ - - - - true - - - $(SolutionDir)..\Bin\Executable\Tester - WindowsLocalDebugger - - - $(OutDir) - WindowsLocalDebugger - - - $(OutDir) - WindowsLocalDebugger - - - $(OutDir) - WindowsLocalDebugger - - \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 5442424f..a73dc154 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -36,7 +36,6 @@ namespace GameLogic int objectID; protected: Oyster::Physics::ICustomBody *rigidBody; - Oyster::Physics::ICustomBody::State *state; }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index c9c356a152677295faf23f618cf3520f0f99d897..ecf60dd310744c606c1634c2f19cc31d79702227 100644 GIT binary patch literal 3037 zcmd5;QE%EX5Pl}V!rG+COwdy8jcS!r2rOMF5oJSrLT+NfYltJqfY8+b_MPLzP10=Y zx@ww~huCM|eg5wA`QEZPh;|`GZ~TZHsW{oZvEG`w=`od5Oo-f6=LbBBSju=jAu(Ck zcP%JMc&v60^!S+Pb zA(6!TVYNy_+_qXU(>i2<(MJ^11JWpP`y34LMQlaEa@Omq2}#M;9m2SKriMv&_8STA zVb1sLZ_aFaGq>jsge{Gh?$C1p8Mx#8ZpZ|zE^sTB`u$PFiTr@iI=xO$g}#Ty4-HV+ z3SkWwuxH>~A&n@+*Ru-Mz1j}gSuBx)4|D2QV~2r0A$o6il%b;1nP6=bN|YZ0%+~$( zsECEL8M-r06t(^7?ROeTT+cdildUoH9W=eXat8C|{F@KVl?F=Hp0hC9m-ABqg{79V8GTInp5lPVDM&`=Y%=}oOq}aEdbb7Jmc}x3bb8vz zMz9kCmVBiV512dxK*825yyW4rdoiYRrbZr%DG|jQr7o+L9+(U^_%VjcXFyU~$6>@& z09%fxvxPky_95FXg@44wfrwD6wsk8gxl<9I=j_rRe6D!AB*C3>m%hxO=ZxkCnMYUh zWo~Bf_|u~wU~%(8M^|4aeun32w@s>8;G%#Yp2)$_sdRUGYWr@#?}9)`98laov6Cb^ z!kU2E5}Raq%wLxF0ce5>-0o=MbuWsm|6Uan5WxM@xFzCWBXai-Lg)PIutSal!P68a zf`_V>f>JkVrA3DJaH+XKBo5&!u8CxOiq?YcmH4$yk=A%uRN=$jDp6y-^_q(g2P*vcUl1E zjgy@&g++4o6Vknat@v?8R*x%}YNp=tLyQ|mk(qoBZ&Y4p>-X)3$~=WeIi1obP)32L z@>&;@$)CN_kItU=R@V!Nt}?H3f1BvSy$*Bw?&Xq8$HO3Up{9w9Tjdjmx@*~<||n3=sfE`8+R4$U0set cvV~ULgFX-|XJIzX4r}767PtE`H^Jro31M2q{{R30 literal 3103 kcmeIu0Sy2E0K%a6Pwi$7h(KY$fB^#r3>YwAz<_}d3=AIt0RR91 diff --git a/Code/GameLogic/GameLogic.vcxproj.user b/Code/GameLogic/GameLogic.vcxproj.user deleted file mode 100644 index 75ed2a95..00000000 --- a/Code/GameLogic/GameLogic.vcxproj.user +++ /dev/null @@ -1,22 +0,0 @@ - - - - true - - - $(SolutionDir)..\Bin\Executable\Tester - WindowsLocalDebugger - - - $(SolutionDir)..\Bin\Executable\Tester - WindowsLocalDebugger - - - $(SolutionDir)..\Bin\Executable\Tester - WindowsLocalDebugger - - - $(SolutionDir)..\Bin\Executable\Tester - WindowsLocalDebugger - - \ No newline at end of file From 52ba5602d5c0f281a8f8b66f674f9b0e01ca5e26 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 9 Jan 2014 13:06:18 +0100 Subject: [PATCH 05/42] GameLogic - player now using some of the new phys api --- Code/Game/GameLogic/Object.h | 3 +++ Code/Game/GameLogic/Player.cpp | 20 +++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index a73dc154..c199eb58 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -15,6 +15,7 @@ namespace Oyster namespace Physics { class ICustomBody; + class State; } } namespace GameLogic @@ -36,6 +37,8 @@ namespace GameLogic int objectID; protected: Oyster::Physics::ICustomBody *rigidBody; + Oyster::Physics::ICustomBody::State *state; + }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ecf60dd3..a9e5b1d0 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -16,7 +16,7 @@ struct Player::PrivateData teamID = -1; playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - lookDir = Oyster::Math::Float3(1,0,0); + lookDir = Oyster::Math::Float4(1,0,0); } ~PrivateData() @@ -31,7 +31,7 @@ struct Player::PrivateData int teamID; Weapon *weapon; PLAYER_STATE playerState; - Oyster::Math::Float3 lookDir; + Oyster::Math::Float4 lookDir; }myData; @@ -49,8 +49,6 @@ Player::~Player(void) void Player::Move(const PLAYER_MOVEMENT &movement) { - //Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity(); - switch(movement) { case PLAYER_MOVEMENT::PLAYER_MOVEMENT_FORWARD: @@ -77,23 +75,23 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - //API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100); + state->ApplyLinearImpulse(myData->lookDir * 100); } void Player::MoveBackwards() { - //API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); + state->ApplyLinearImpulse(-myData->lookDir * 100); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector - //Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross(myData->lookDir); - //API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100); + Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir); + state->ApplyLinearImpulse(r * 100); } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector - //Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross(myData->lookDir); - //API::Instance().ApplyForceAt(rigidBody, rigidBody->GetCenter(), r * 100); + Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir); + state->ApplyLinearImpulse(-r * 100); } void Player::UseWeapon(const WEAPON_FIRE &fireInput) @@ -106,7 +104,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) //API::Instance().SetCenter(rigidBody,spawnPoint); myData->life = 100; myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - myData->lookDir = Oyster::Math::Float3(1,0,0); + myData->lookDir = Oyster::Math::Float4(1,0,0); } void Player::Jump() From a02a32c0298d1fe47040846e1c122f3307e2ea91 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Thu, 9 Jan 2014 14:18:01 +0100 Subject: [PATCH 06/42] Network now closes listener gracefully, meaning threads dont crash anymore, also fixed a minor bug in Game folder --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 26 ++-- Code/Game/DanBiasServer/GameServer.cpp | 10 +- .../DanBiasServer/GameSession/GameSession.cpp | 9 +- .../GameSession/GameSessionManager.cpp | 9 +- .../GameSession/GameSessionManager.h | 5 + .../DanBiasServer/LobbySessions/MainLobby.cpp | 5 +- Code/Misc/Thread/OysterThread_Impl.cpp | 114 +++--------------- Code/Network/NetworkAPI/NetworkClient.cpp | 4 +- Code/Network/NetworkDependencies/Listener.cpp | 40 +++++- Code/Network/NetworkDependencies/Listener.h | 5 +- 10 files changed, 101 insertions(+), 126 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 57d47292..0edbce01 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -96,19 +96,29 @@ namespace DanBias break; case protocol_Gameplay_ObjectPosition: { - - Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; - protocolData->object_ID = p[1].value.netInt; + Client::GameClientState::ObjPos protocolData; + protocolData.object_ID = p[1].value.netInt; for(int i = 0; i< 16; i++) { - protocolData->worldPos[i] = p[i+2].value.netFloat; + protocolData.worldPos[i] = p[i+2].value.netFloat; } if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); + ((Client::GameState*)gameClientState)->Protocol(&protocolData); - delete protocolData; - protocolData = NULL; + //Why use dynamicly allocated memory when data dies after block? + //Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; + //protocolData->object_ID = p[1].value.netInt; + //for(int i = 0; i< 16; i++) + //{ + // protocolData->worldPos[i] = p[i+2].value.netFloat; + //} + // + //if(dynamic_cast(gameClientState)) + // ((Client::GameState*)gameClientState)->Protocol(protocolData); + // + //delete protocolData; + //protocolData = NULL; } break; @@ -159,7 +169,7 @@ namespace DanBias m_data->recieverObj = new MyRecieverObject; - // m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object); + m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object); m_data->recieverObj->nwClient->Connect(desc.port, desc.IP); if (!m_data->recieverObj->nwClient->IsConnected()) diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp index 837d52b0..a5210123 100644 --- a/Code/Game/DanBiasServer/GameServer.cpp +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -25,7 +25,8 @@ namespace DanBias void GameServer::NetworkCallback(NetworkClient* client) { - static GameSession *myTest = 0; + static bool myTest = false; + static int sessionId = -1; printf("Client with ID [%i] connected.\n", client->GetID()); if(!myTest) @@ -36,10 +37,9 @@ namespace DanBias desc.mapName = L"test"; desc.clients.Push(c); desc.exitDestionation = this->mainLobby; - int sessionId = 0; if((sessionId = GameSessionManager::AddSession(desc, true)) == 0) printf("Failed to create a game session"); - + myTest = true; //myTest = new GameSession(); // //DanBias::GameSession::GameSessionDescription desc; @@ -52,7 +52,7 @@ namespace DanBias else { Utility::DynamicMemory::SmartPointer c = new LobbyClient(client); - myTest->Join(c); + GameSessionManager::JoinSession(sessionId, c); } @@ -119,6 +119,8 @@ namespace DanBias } DanBiasServerReturn GameServer::Release() { + GameSessionManager::CloseSession(); + this->mainLobby->Release(); delete this->mainLobby; this->server->Shutdown(); delete this->server; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.cpp b/Code/Game/DanBiasServer/GameSession/GameSession.cpp index 866626c4..706a575c 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession.cpp @@ -29,6 +29,7 @@ namespace DanBias return; } } + clients.Push(obj); } void RemoveObject(DynamicArray>& clients, DanBias::GameClient* obj) { @@ -165,10 +166,8 @@ namespace DanBias if(p[6].value.netBool) //bool bStrafeLeft; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - //Oyster::Math::Float4x4 p; - Protocol_ObjectPosition op;//(c.GetPlayer()->GetRigidBody(), c.GetPlayer()->GetID()); - //op.object_ID = c.GetPlayer()->GetID(); - Send(op.GetProtocol()); + //Protocol_ObjectPosition op(c->GetPlayer()->GetOrientation(), c->GetPlayer()->GetID()); + //Send(op.GetProtocol()); } break; case protocol_Gameplay_PlayerMouseMovement: @@ -197,7 +196,7 @@ namespace DanBias break; case GameLogic::Protocol_General_Status::States_disconected: - printf("Client with ID [%i] dissconnected", c->GetClient()->GetID()); + printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); RemoveObject(this->clients, c); break; diff --git a/Code/Game/DanBiasServer/GameSession/GameSessionManager.cpp b/Code/Game/DanBiasServer/GameSession/GameSessionManager.cpp index ee7c191f..23dadb65 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSessionManager.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSessionManager.cpp @@ -78,7 +78,7 @@ bool GameSessionManager::StartSession(int session) bool GameSessionManager::JoinSession(int session, Utility::DynamicMemory::SmartPointer client) { int i = -1; - if((i = gameSessionData.Existst(session)) != -1) return false; + if((i = gameSessionData.Existst(session)) == -1) return false; gameSessionData.sessions[i]->Join(client); @@ -97,6 +97,13 @@ void GameSessionManager::GetSessionInfo(int session, GameSessionInfo& data) //data.numberOfPlayers = gameSessionData.sessions[i]-> } +void GameSessionManager::CloseSession() +{ + for (unsigned int i = 0; i < gameSessionData.sessions.Size(); i++) + { + gameSessionData.sessions[i]->CloseSession(); + } +} void GameSessionManager::CloseSession(int session) { int i = -1; diff --git a/Code/Game/DanBiasServer/GameSession/GameSessionManager.h b/Code/Game/DanBiasServer/GameSession/GameSessionManager.h index 4f93232b..75b0e64d 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSessionManager.h +++ b/Code/Game/DanBiasServer/GameSession/GameSessionManager.h @@ -64,6 +64,11 @@ namespace DanBias */ static void CloseSession(int session); + /** + * Close all sessions. + */ + static void CloseSession(); + /** * Get total sessions running * @return Returns the total sessions curently running. diff --git a/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp b/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp index fd31f445..9b8899ca 100644 --- a/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp +++ b/Code/Game/DanBiasServer/LobbySessions/MainLobby.cpp @@ -19,11 +19,12 @@ namespace DanBias } MainLobby::~MainLobby() { - delete this->box; - this->box = 0; + } void MainLobby::Release() { + delete this->box; + this->box = 0; this->CloseSession(true); } diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index ab7f6ac6..16668c04 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -15,8 +15,6 @@ using namespace Oyster::Thread; using namespace Utility::DynamicMemory; - - #pragma region Declerations enum OYSTER_THREAD_STATE @@ -51,8 +49,8 @@ using namespace Utility::DynamicMemory; OwnerContainer ownerObj; // std::atomic msec; //threadData->state = OYSTER_THREAD_STATE_DEAD; - if(wait) + if(this->workerThread.joinable()) { - if(std::this_thread::get_id() != this->workerThread.get_id()) - if(this->workerThread.joinable()) - { - this->workerThread.join(); - this->isCreated = false; - this->threadData = 0; - } - } - else - { - if(this->workerThread.joinable()) - this->workerThread.detach(); + this->workerThread.join(); + this->isCreated = false; + delete this->threadData; + this->threadData = 0; } + return OYSTER_THREAD_ERROR_SUCCESS; } - //OYSTER_THREAD_ERROR Create(ThreadFunction fnc, IThreadObject* worker, bool start, bool detach) - //{ - // if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated; - // - // threadData = new ThreadData(); - // if(start) - // this->threadData->state = OYSTER_THREAD_STATE_NORMAL; - // else - // this->threadData->state = OYSTER_THREAD_STATE_IDLE; - // threadData->owner = worker; - // threadData->prio = OYSTER_THREAD_PRIORITY_3; - // - // workerThread = std::thread(fnc, this->threadData); - // - // if(detach) - // this->workerThread.detach(); - // - // isCreated = true; - // - // return OYSTER_THREAD_ERROR_SUCCESS; - //} - //OYSTER_THREAD_ERROR Create(ThreadFunction fnc, Oyster::Callback::OysterCallback worker, bool start, bool detach) - //{ - // if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated; - // - // threadData = new ThreadData(); - // if(start) - // this->threadData->state = OYSTER_THREAD_STATE_NORMAL; - // else - // this->threadData->state = OYSTER_THREAD_STATE_IDLE; - // threadData->ownerObj = worker; - // threadData->prio = OYSTER_THREAD_PRIORITY_3; - // - // workerThread = std::thread(fnc, this->threadData); - // - // if(detach) - // this->workerThread.detach(); - // - // isCreated = true; - // - // return OYSTER_THREAD_ERROR_SUCCESS; - //} OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach) { if(this->isCreated ) return OYSTER_THREAD_ERROR_ThreadAlreadyCreated; - + threadData = new ThreadData(); if(start) this->threadData->state = OYSTER_THREAD_STATE_NORMAL; @@ -155,8 +105,8 @@ using namespace Utility::DynamicMemory; workerThread = std::thread(fnc, this->threadData); - if(detach) - this->workerThread.detach(); + //if(detach) + // this->workerThread.detach(); isCreated = true; @@ -171,9 +121,7 @@ using namespace Utility::DynamicMemory; PrivateData(){} ~PrivateData() { - if(data) - if(data->threadData) - memset(&data->threadData->ownerObj, 0, sizeof(OwnerContainer)); + data.Release(); } OYSTER_THREAD_ERROR Create(ThreadFunction fnc, OwnerContainer worker, bool start, bool detach) { @@ -248,7 +196,8 @@ using namespace Utility::DynamicMemory; if(w->ownerObj.value.obj) w->ownerObj.value.obj->ThreadExit(); w->state = OYSTER_THREAD_STATE_DEAD; - delete w; + + //delete w; } }; @@ -295,31 +244,6 @@ OYSTER_THREAD_ERROR OysterThread::Create(ThreadFnc worker, bool start, bool deta return this->privateData->Create(ThreadHelp::ThreadingFunction, c, start, detach); } -/* -OYSTER_THREAD_ERROR OysterThread::Create(Oyster::Callback::CallbackObject* worker, bool start, bool detach) -{ - if(!this->privateData) - this->privateData = new PrivateData(); - - Oyster::Callback::OysterCallback<> temp; - temp.callbackType = Oyster::Callback::CallbackType_Object; - temp.value = worker; - - return this->privateData->Create(ThreadHelp::ThreadingFunction, temp, start, detach); -} -OYSTER_THREAD_ERROR OysterThread::Create(Oyster::Callback::CallbackFunction::FNC worker, bool start, bool detach) -{ - if(!this->privateData) - this->privateData = new PrivateData(); - - Oyster::Callback::OysterCallback<> temp; - temp.callbackType = Oyster::Callback::CallbackType_Function; - temp.value = worker; - - return this->privateData->Create(ThreadHelp::ThreadingFunction, temp, start, detach); -} -*/ - OYSTER_THREAD_ERROR OysterThread::Start() { if(!this->privateData->data->threadData->ownerObj) @@ -384,9 +308,6 @@ OYSTER_THREAD_ERROR OysterThread::Wait() if( this->privateData->data->workerThread.get_id() == std::this_thread::get_id()) return OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe; - - //this->privateData->data->threadData->threadFunctionLock.lock(); - //this->privateData->data->threadData->threadFunctionLock.unlock(); return OYSTER_THREAD_ERROR_SUCCESS; } @@ -394,9 +315,6 @@ OYSTER_THREAD_ERROR OysterThread::Wait(int msec) { if(this->privateData->data->workerThread.get_id() == std::this_thread::get_id()) return OYSTER_THREAD_ERROR_ThreadCannotWaintOnItselfe; - - //if(this->privateData->data->threadData->threadFunctionLock.try_lock_for(std::chrono::milliseconds(msec))) - // this->privateData->data->threadData->threadFunctionLock.unlock(); return OYSTER_THREAD_ERROR_SUCCESS; } diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index f8c55476..2a0c4dc0 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -63,9 +63,8 @@ struct ClientDataContainer } ~ClientDataContainer() { - thread.Stop(); - thread.Wait(); connection.Disconnect(); + thread.Stop(); callbackType = NetworkProtocolCallbackType_Unknown; ShutdownWinSock(); @@ -244,6 +243,7 @@ bool NetworkClient::Connect(unsigned short port, const char serverIP[]) void NetworkClient::Disconnect() { privateData->data->connection.Disconnect(); + privateData->data->thread.Terminate(); } bool NetworkClient::IsConnected() diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index 6f3aaa37..deb0d992 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -6,11 +6,14 @@ using namespace Oyster::Thread; Listener::Listener() { + this->port = -1; + this->isListening = false; connection = NULL; } Listener::Listener(Oyster::Network::IPostBox* postBox) { + this->isListening = false; connection = NULL; this->postBox = postBox; } @@ -19,9 +22,11 @@ Listener::~Listener() { if(connection) { - this->thread.Terminate(false); + this->isListening = false; + this->thread.Terminate(); delete connection; connection = 0; + this->port = -1; } } @@ -36,6 +41,8 @@ bool Listener::Init(unsigned int port) return false; } + this->port = port; + this->isListening = true; return true; } @@ -52,6 +59,11 @@ bool Listener::Init(unsigned int port, bool start) return false; } + if(start) + { + this->isListening = true; + } + this->port = port; return true; } @@ -62,17 +74,18 @@ bool Listener::Start() return false; } + this->isListening = true; return true; } void Listener::Stop() { - thread.Stop(); + StopListen(); } void Listener::Shutdown() { - thread.Stop(false); + StopListen(); } void Listener::SetPostBox(Oyster::Network::IPostBox* postBox) @@ -87,6 +100,10 @@ int Listener::Accept() int clientSocket = -1; clientSocket = connection->Listen(); + if(!this->isListening.load()) + { + return -1; + } if(clientSocket != -1) { stdMutex.lock(); @@ -96,13 +113,26 @@ int Listener::Accept() return clientSocket; } - +void Listener::StopListen() +{ + if(this->connection && this->connection->IsConnected()) + { + this->isListening = false; + Connection c; + c.InitiateClient(); + c.Connect(this->port, "127.0.0.1"); + } +} bool Listener::DoWork() { if(!this->connection) return false; int result = Accept(); - if(result == -1) + if(!this->isListening.load()) + { + return false; + } + else if(result == -1) { //Do something? } diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index b45dc1f4..422592e7 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -11,6 +11,7 @@ #include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterMutex.h" #include "../../Misc/Utilities.h" +#include namespace Oyster { @@ -41,6 +42,7 @@ namespace Oyster //Function that runs in the thread. int Accept(); + void StopListen(); private: ::Oyster::Network::Connection* connection; @@ -50,7 +52,8 @@ namespace Oyster std::mutex stdMutex; IPostBox* postBox; - + std::atomic isListening; + int port; }; } } From 72625354549c251660a897b8ed8e92004fc7731c Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Thu, 9 Jan 2014 14:19:12 +0100 Subject: [PATCH 07/42] Added some more UML-stuff --- Code/Dokumentation/Danbias Structure.uxf | 244 ++++++----- Code/Dokumentation/GameClient.uxf | 4 + Code/Dokumentation/GameLogic.uxf | 4 + ...GameServerStructure.uxf => GameServer.uxf} | 0 Code/Dokumentation/Protocols.uxf | 402 ++++++++++++++++++ 5 files changed, 538 insertions(+), 116 deletions(-) create mode 100644 Code/Dokumentation/GameClient.uxf create mode 100644 Code/Dokumentation/GameLogic.uxf rename Code/Dokumentation/{GameServerStructure.uxf => GameServer.uxf} (100%) create mode 100644 Code/Dokumentation/Protocols.uxf diff --git a/Code/Dokumentation/Danbias Structure.uxf b/Code/Dokumentation/Danbias Structure.uxf index 3380c3ff..c24380c9 100644 --- a/Code/Dokumentation/Danbias Structure.uxf +++ b/Code/Dokumentation/Danbias Structure.uxf @@ -1,10 +1,10 @@ - + 11 com.umlet.element.Class - 726 + 847 363 132 33 @@ -15,7 +15,7 @@ com.umlet.element.Class - 440 + 561 363 132 33 @@ -26,19 +26,19 @@ com.umlet.element.Class - 550 - 286 + 671 + 209 132 33 - Physics / Math + Physics com.umlet.element.Class - 737 - 176 + 858 + 132 121 33 @@ -48,8 +48,8 @@ com.umlet.element.Class - 363 - 286 + 484 + 209 154 33 @@ -59,8 +59,8 @@ com.umlet.element.Class - 385 - 176 + 506 + 132 121 33 @@ -70,8 +70,8 @@ com.umlet.element.Class - 550 - 154 + 671 + 132 132 33 @@ -81,7 +81,7 @@ com.umlet.element.Class - 583 + 704 363 132 33 @@ -92,86 +92,64 @@ com.umlet.element.Class - 550 - 198 - 132 - 33 - - Threading - - - - com.umlet.element.Class - - 550 + 495 55 - 132 + 176 44 - DanBias + DanBiasClientLauncher bg=green com.umlet.element.Relation - 759 - 176 + 880 + 132 54 - 208 + 252 lt=<- - 33;187;33;165;33;33 + 33;231;33;209;33;33 com.umlet.element.Relation - 462 - 176 + 583 + 132 351 - 208 + 252 lt=<- - 33;187;33;165;330;165;330;33 + 33;231;33;209;330;209;330;33 com.umlet.element.Relation - 407 - 176 + 528 + 132 54 - 131 + 98 lt=<- - 33;110;33;33 + 33;77;33;33 com.umlet.element.Relation - 649 - 176 - 153 - 142 - - lt=<- - 33;121;132;121;132;33 - - - com.umlet.element.Relation - - 473 - 143 + 594 + 110 98 - 65 + 54 lt=<- - 77;33;44;33;44;44;33;44 + 77;33;33;33 com.umlet.element.Relation - 484 - 264 + 605 + 187 87 54 @@ -181,76 +159,54 @@ bg=green com.umlet.element.Relation - 616 - 176 + 737 + 132 197 - 208 + 252 lt=<- - 33;187;33;165;176;165;176;33 + 33;231;33;209;176;209;176;33 com.umlet.element.Relation - 473 - 165 - 98 - 65 - - lt=<- - 77;44;44;44;44;33;33;33 - - - com.umlet.element.Relation - - 649 - 165 + 770 + 110 109 - 65 + 54 lt=<- - 33;44;66;44;66;33;88;33 + 33;33;88;33 com.umlet.element.Relation - 649 - 143 - 109 - 65 - - lt=<- - 33;33;66;33;66;44;88;44 - - - com.umlet.element.Relation - - 649 - 33 - 164 - 164 + 880 + 66 + 54 + 87 lt=>- - 33;33;143;33;143;143 + 33;33;33;66 com.umlet.element.Relation - 407 - 33 - 164 - 164 + 528 + 66 + 54 + 87 lt=>- - 143;33;33;33;33;143 + 33;33;33;66 com.umlet.element.Package - 319 + 440 22 550 - 385 + 396 GameEngine @@ -258,7 +214,7 @@ bg=green com.umlet.element.Relation - 759 + 880 363 54 164 @@ -269,7 +225,7 @@ bg=green com.umlet.element.Package - 770 + 891 506 319 220 @@ -280,7 +236,7 @@ bg=green com.umlet.element.Class - 781 + 902 539 297 176 @@ -300,7 +256,7 @@ Release(resource :Model*) :void com.umlet.element.Package - 440 + 561 506 308 242 @@ -311,7 +267,7 @@ Release(resource :Model*) :void com.umlet.element.Relation - 528 + 649 363 142 175 @@ -322,7 +278,7 @@ Release(resource :Model*) :void com.umlet.element.Class - 451 + 572 539 286 198 @@ -343,7 +299,7 @@ Enable(Enable :bool) :void com.umlet.element.Class - 330 + 451 363 99 33 @@ -354,18 +310,18 @@ Enable(Enable :bool) :void com.umlet.element.Relation - 341 - 176 + 462 + 132 472 - 208 + 252 lt=<- - 33;187;33;165;451;165;451;33 + 33;231;33;209;451;209;451;33 com.umlet.element.Package - 55 + 176 506 374 242 @@ -376,7 +332,7 @@ Enable(Enable :bool) :void com.umlet.element.Class - 66 + 187 539 352 121 @@ -393,7 +349,7 @@ Release(Resource :ResourceHandle*) :void com.umlet.element.Class - 66 + 187 693 352 44 @@ -406,7 +362,7 @@ FMOD com.umlet.element.Relation - 209 + 330 627 54 87 @@ -417,7 +373,7 @@ FMOD com.umlet.element.Relation - 165 + 286 363 362 175 @@ -425,4 +381,60 @@ FMOD lt=<<. 341;33;341;88;253;88;253;154;33;154 + + com.umlet.element.Class + + 781 + 55 + 198 + 44 + + DanBiasServerLauncher +bg=green + + + + com.umlet.element.Class + + 671 + 253 + 132 + 33 + + Math + + + + com.umlet.element.Relation + + 770 + 132 + 153 + 164 + + lt=<- + 33;143;132;143;132;33 + + + com.umlet.element.Class + + 682 + 297 + 99 + 33 + + Misc + + + + com.umlet.element.Relation + + 605 + 198 + 87 + 98 + + lt=<- + 66;77;44;77;44;33;33;33 + diff --git a/Code/Dokumentation/GameClient.uxf b/Code/Dokumentation/GameClient.uxf new file mode 100644 index 00000000..294b3dba --- /dev/null +++ b/Code/Dokumentation/GameClient.uxf @@ -0,0 +1,4 @@ + + + 10 + diff --git a/Code/Dokumentation/GameLogic.uxf b/Code/Dokumentation/GameLogic.uxf new file mode 100644 index 00000000..294b3dba --- /dev/null +++ b/Code/Dokumentation/GameLogic.uxf @@ -0,0 +1,4 @@ + + + 10 + diff --git a/Code/Dokumentation/GameServerStructure.uxf b/Code/Dokumentation/GameServer.uxf similarity index 100% rename from Code/Dokumentation/GameServerStructure.uxf rename to Code/Dokumentation/GameServer.uxf diff --git a/Code/Dokumentation/Protocols.uxf b/Code/Dokumentation/Protocols.uxf new file mode 100644 index 00000000..f1b5f84f --- /dev/null +++ b/Code/Dokumentation/Protocols.uxf @@ -0,0 +1,402 @@ + + + 8 + + UMLClass + + 680 + 592 + 136 + 40 + + CustomNetworkProtocol +-- + + + + UMLClass + + 560 + 688 + 152 + 40 + + NetworkServer +-- +elementstyle=wordwrap + + + + UMLClass + + 776 + 688 + 152 + 40 + + NetworkClient +-- +elementstyle=wordwrap + + + + com.umlet.element.Relation + + 720 + 448 + 40 + 160 + + lt=> +fg=red + 24;24;24;144 + + + UMLClass + + 664 + 432 + 152 + 40 + + GameProtocols +-- +elementstyle=wordwrap +bg=green + + + + com.umlet.element.Relation + + 592 + 424 + 88 + 48 + + lt=> + 24;32;72;24 + + + UMLClass + + 464 + 440 + 152 + 40 + + DanBiasServer +-- +elementstyle=wordwrap +bg=green + + + + UMLClass + + 880 + 440 + 152 + 40 + + DanBiasGame +-- +elementstyle=wordwrap +bg=green + + + + com.umlet.element.Relation + + 792 + 424 + 104 + 48 + + lt=> + 88;32;24;24 + + + com.umlet.element.Relation + + 608 + 608 + 152 + 96 + + lt=> +fg=blue + 24;80;24;56;136;56;136;24 + + + com.umlet.element.Relation + + 736 + 608 + 136 + 96 + + lt=> +fg=blue + 120;80;120;56;24;56;24;24 + + + com.umlet.element.Relation + + 688 + 680 + 104 + 40 + + lt=< +fg=blue + 88;24;24;24 + + + com.umlet.element.Relation + + 512 + 456 + 64 + 264 + + lt=> +fg=red + 24;24;24;248;48;248 + + + com.umlet.element.Relation + + 904 + 456 + 64 + 272 + + lt=> +fg=red + 48;24;48;256;24;256 + + + com.umlet.element.Relation + + 504 + 456 + 288 + 304 + + lt=> +fg=red + 24;24;24;288;248;288;248;256;272;256 + + + com.umlet.element.Package + + 544 + 568 + 400 + 168 + + bg=orange +NetworkAPI + + + + com.umlet.element.Relation + + 720 + 240 + 40 + 208 + + lt=. +fg=red + 24;24;24;192 + + + UMLClass + + 520 + 168 + 120 + 56 + + ProtocolIdentificationID +-- +/Collection of uniuqe/ +/protocol identifications/ + + + + + UMLClass + + 824 + 176 + 120 + 48 + + GameProtocols +-- +/Collects protocols/ + + + + + UMLClass + + 696 + 136 + 88 + 24 + + ControlProtocols + + + + + UMLClass + + 696 + 168 + 88 + 24 + + LobbyProtocols + + + + + UMLClass + + 696 + 200 + 88 + 24 + + ObjectProtocols + + + + UMLClass + + 696 + 232 + 88 + 24 + + PlayerProtocols + + + + + com.umlet.element.Relation + + 760 + 184 + 80 + 72 + + lt=> + 64;24;48;24;48;56;24;56 + + + com.umlet.element.Relation + + 760 + 176 + 80 + 48 + + lt=> + 64;24;40;24;40;32;24;32 + + + com.umlet.element.Relation + + 760 + 160 + 80 + 48 + + lt=> + 64;32;40;32;40;24;24;24 + + + com.umlet.element.Relation + + 760 + 128 + 80 + 72 + + lt=> + 64;56;48;56;48;24;24;24 + + + com.umlet.element.Relation + + 616 + 184 + 96 + 72 + + lt=> + 80;56;56;56;56;24;24;24 + + + com.umlet.element.Relation + + 616 + 176 + 96 + 48 + + lt=> + 80;32;64;32;64;24;24;24 + + + com.umlet.element.Relation + + 616 + 160 + 96 + 48 + + lt=> + 80;24;64;24;64;32;24;32 + + + com.umlet.element.Relation + + 616 + 128 + 96 + 72 + + lt=> + 80;24;56;24;56;56;24;56 + + + com.umlet.element.Package + + 512 + 112 + 440 + 152 + + bg=orange +GameProtocols + + + + UMLClass + + 744 + 312 + 184 + 72 + + Protocols is created in a seperate module because both server and client needs to share the same protocols and the same protocol identifications. +elementstyle=wordwrap + + + From e575fff610a3e1e5f39f15aa0c9fcf885e656b74 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 10 Jan 2014 08:53:20 +0100 Subject: [PATCH 08/42] Physics proj .. show all files should be set to false That is how we in Physics rolls --- Code/OysterPhysics3D/OysterPhysics3D.vcxproj.user | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.user b/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.user index 9a0b0ae0..3f030911 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.user +++ b/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.user @@ -1,6 +1,6 @@  - true + false \ No newline at end of file From 586031aa948fdf7199d91873d7d4a991f118f6bd Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 10 Jan 2014 10:08:42 +0100 Subject: [PATCH 09/42] GameLogic - making sure GameLogic uses the new physics api --- Code/Game/GameLogic/Level.cpp | 2 +- Code/Game/GameLogic/Object.cpp | 4 ++++ Code/Game/GameLogic/Object.h | 11 ++--------- Code/Game/GameLogic/Player.cpp | 17 ++++++++--------- Code/Game/GameLogic/Weapon.h | 2 -- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index f0d1b935..9f4416aa 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -10,7 +10,7 @@ using namespace GameLogic; struct Level::PrivateData { - PrivateData() + PrivateData() { } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 9e516907..e824c1d5 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -23,6 +23,8 @@ Object::Object() this->objectID = GID(); this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; + + rigidBody->GetState(state); } Object::Object(void* collisionFunc, OBJECT_TYPE type) @@ -40,6 +42,8 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) this->objectID = GID(); this->type = type; + + rigidBody->GetState(state); } diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index c199eb58..6d6437f1 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -9,15 +9,8 @@ #include "GameLogicStates.h" #include "GameLogicDef.h" +#include -namespace Oyster -{ - namespace Physics - { - class ICustomBody; - class State; - } -} namespace GameLogic { class DANBIAS_GAMELOGIC_DLL Object @@ -37,7 +30,7 @@ namespace GameLogic int objectID; protected: Oyster::Physics::ICustomBody *rigidBody; - Oyster::Physics::ICustomBody::State *state; + Oyster::Physics::ICustomBody::State state; }; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index a9e5b1d0..626e565f 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -16,7 +16,7 @@ struct Player::PrivateData teamID = -1; playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - lookDir = Oyster::Math::Float4(1,0,0); + lookDir = Oyster::Math::Float4(1,0,0,0); } ~PrivateData() @@ -75,23 +75,23 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - state->ApplyLinearImpulse(myData->lookDir * 100); + state.ApplyLinearImpulse(myData->lookDir * 100); } void Player::MoveBackwards() { - state->ApplyLinearImpulse(-myData->lookDir * 100); + state.ApplyLinearImpulse(-myData->lookDir * 100); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir); - state->ApplyLinearImpulse(r * 100); + state.ApplyLinearImpulse(r * 100); } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir); - state->ApplyLinearImpulse(-r * 100); + state.ApplyLinearImpulse(-r * 100); } void Player::UseWeapon(const WEAPON_FIRE &fireInput) @@ -101,7 +101,7 @@ void Player::UseWeapon(const WEAPON_FIRE &fireInput) void Player::Respawn(Oyster::Math::Float3 spawnPoint) { - //API::Instance().SetCenter(rigidBody,spawnPoint); + myData->life = 100; myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; myData->lookDir = Oyster::Math::Float4(1,0,0); @@ -109,7 +109,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Jump() { - //API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100); + } bool Player::IsWalking() @@ -127,8 +127,7 @@ bool Player::IsIdle() Oyster::Math::Float3 Player::GetPos() { - //return rigidBody->GetCenter(); - return Oyster::Math::Float3(0,0,0); + return (Oyster::Math::Float3)state.GetCenterPosition(); } Oyster::Math::Float3 Player::GetLookDir() diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index cdd1a3b7..719a853c 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -34,8 +34,6 @@ namespace GameLogic bool IsValidSocket(int socketID); int GetCurrentSocketID(); - - private: struct PrivateData; From c541d032e79ebdb2499db8cafe3be37ac4cc51f4 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 10 Jan 2014 10:47:54 +0100 Subject: [PATCH 10/42] GL - can move a obj on the client via the server --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 5 ++-- .../GameClientState/C_obj/C_DynamicObj.cpp | 1 + .../GameClientState/C_obj/C_Player.cpp | 2 +- .../GameClientState/C_obj/C_StaticObj.cpp | 1 + .../GameClientState/C_obj/C_UIobject.cpp | 1 + .../DanBiasGame/GameClientState/GameState.cpp | 13 +++++++++- .../DanBiasServer/GameSession/GameSession.cpp | 24 ++++++++++++------- Code/Game/GameLogic/Object.h | 9 +------ 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 57d47292..b71f6dcd 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -23,7 +23,8 @@ namespace DanBias { Oyster::Network::NetworkClient* nwClient; Client::GameClientState* gameClientState; - + + void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override { int pType = p[0].value.netInt; @@ -159,7 +160,7 @@ namespace DanBias m_data->recieverObj = new MyRecieverObject; - // m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object); + m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object); m_data->recieverObj->nwClient->Connect(desc.port, desc.IP); if (!m_data->recieverObj->nwClient->IsConnected()) diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp index f47fc9fe..3df74e40 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp @@ -26,6 +26,7 @@ void C_DynamicObj::Init(ModelInitData modelInit) privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->ID = modelInit.id; } void C_DynamicObj::setPos(Oyster::Math::Float4x4 world) { diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp index 86acaf4b..4cd6fbd3 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp @@ -28,7 +28,7 @@ void C_Player::Init(ModelInitData modelInit) privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; - + privData->ID = modelInit.id; } void C_Player::setPos(Oyster::Math::Float4x4 world) diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp index c5f2e119..177b032b 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp @@ -28,6 +28,7 @@ void C_StaticObj::Init(ModelInitData modelInit) privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->ID = modelInit.id; } void C_StaticObj::setPos(Oyster::Math::Float4x4 world) diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp index 226d8ca7..fa5dff04 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp @@ -24,6 +24,7 @@ void C_UIobject::Init(ModelInitData modelInit) privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->ID = modelInit.id; } void C_UIobject::setPos(Oyster::Math::Float4x4 world) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index bf156d3e..cc4bbe53 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -40,6 +40,12 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient) } GameState::gameStateState GameState::LoadGame() { + Oyster::Graphics::Definitions::Pointlight plight; + plight.Pos = Oyster::Math::Float3(0,3,0); + plight.Color = Oyster::Math::Float3(0,1,0); + plight.Radius = 5; + plight.Bright = 2; + Oyster::Graphics::API::AddLight(plight); LoadModels(L"map"); InitCamera(Oyster::Math::Float3(0,0,5.4f)); return gameStateState_playing; @@ -56,18 +62,22 @@ bool GameState::LoadModels(std::wstring mapFile) modelData.world = Oyster::Math3D::Float4x4::identity; modelData.visible = true; modelData.modelPath = L"..\\Content\\worldDummy"; + modelData.id = 0; // load models C_Object* obj = new C_Player(); privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); + Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2)); modelData.world = modelData.world * translate; modelData.modelPath = L"..\\Content\\worldDummy"; + modelData.id ++; obj = new C_DynamicObj(); privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); + + return true; } bool GameState::InitCamera(Oyster::Math::Float3 startPos) @@ -209,6 +219,7 @@ void GameState::Protocol( ObjPos* pos ) { world[i] = pos->worldPos[i]; } + for (int i = 0; i < privData->object.size(); i++) { if(privData->object[i]->GetId() == pos->object_ID) diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.cpp b/Code/Game/DanBiasServer/GameSession/GameSession.cpp index 866626c4..e5238620 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession.cpp @@ -156,19 +156,25 @@ namespace DanBias { case protocol_Gameplay_PlayerNavigation: { + + Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; if(p[1].value.netBool) //bool bForward; - c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); + world.v[3].x = 2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); if(p[2].value.netBool) //bool bBackward; - c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); + world.v[3].x = -2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); if(p[5].value.netBool) //bool bStrafeRight; - c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); + world.v[3].y = 2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); if(p[6].value.netBool) //bool bStrafeLeft; - c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - - //Oyster::Math::Float4x4 p; - Protocol_ObjectPosition op;//(c.GetPlayer()->GetRigidBody(), c.GetPlayer()->GetID()); - //op.object_ID = c.GetPlayer()->GetID(); - Send(op.GetProtocol()); + world.v[3].y = -2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); + + Protocol_ObjectPosition res(world, 0); + Send(res.GetProtocol()); + + } break; case protocol_Gameplay_PlayerMouseMovement: diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index c199eb58..c880e90d 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -9,15 +9,8 @@ #include "GameLogicStates.h" #include "GameLogicDef.h" +#include -namespace Oyster -{ - namespace Physics - { - class ICustomBody; - class State; - } -} namespace GameLogic { class DANBIAS_GAMELOGIC_DLL Object From 059b3dd5e46e18b9c4e6611598dafd35f5fd00e0 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 10 Jan 2014 12:33:04 +0100 Subject: [PATCH 11/42] GameLogic - Basic game interface made (functions not yet implemented) --- Code/Game/GameLogic/Game.cpp | 71 +++++++++++++++++++++ Code/Game/GameLogic/Game.h | 88 +++++++++++++++++++++++++++ Code/Game/GameLogic/GameLogic.vcxproj | 2 + Code/Game/GameLogic/Object.cpp | 1 - Code/Game/GameLogic/Player.cpp | 4 +- Code/Game/GameLogic/Player.h | 2 +- 6 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 Code/Game/GameLogic/Game.cpp create mode 100644 Code/Game/GameLogic/Game.h diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp new file mode 100644 index 00000000..806ac6d2 --- /dev/null +++ b/Code/Game/GameLogic/Game.cpp @@ -0,0 +1,71 @@ +#include "Game.h" +#include "Player.h" +#include "Level.h" + +using namespace GameLogic; + +struct Game::PrivateData +{ + PrivateData() + { + + } + + ~PrivateData() + { + + } + + Player **players; + Level *level; + +}myData; + + +Game::Game(void) +{ + myData = new PrivateData(); +} + +Game::~Game(void) +{ + if(myData) + { + delete myData; + } +} + +void Game::MovePlayer(int playerID, const PLAYER_MOVEMENT &movement) +{ + +} + +void Game::PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage) +{ + +} + +void Game::GetPlayerPos(int playerID) +{ + +} + +void Game::GetAllPlayerPos() +{ + +} + +Game::PlayerData Game::CreatePlayer() +{ + +} + +void Game::CreateTeam() +{ + +} + +void Game::NewFrame() +{ + +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h new file mode 100644 index 00000000..a70dc842 --- /dev/null +++ b/Code/Game/GameLogic/Game.h @@ -0,0 +1,88 @@ +#ifndef GAME_H +#define GAME_H + +#include "GameLogicStates.h" +namespace GameLogic +{ + class Game + { + + public: + struct PlayerData + { + int playerID; + int teamID; + + PlayerData() + { + playerID = 0; + teamID = 0; + } + + PlayerData(int playerID,int teamID) + { + this->playerID = playerID; + this->teamID = teamID; + + } + + ~PlayerData() + { + + } + }; + + public: + Game(void); + ~Game(void); + + /******************************************************** + * Moves the chosen player based on input + * @param playerID: ID of the player you want to recieve the message + * @param movement: enum value on what kind of action is to be taken + ********************************************************/ + void MovePlayer(int playerID, const PLAYER_MOVEMENT &movement); + + /******************************************************** + * Uses the chosen players weapon based on input + * @param playerID: ID of the player you want to recieve the message + * @param Usage: enum value on what kind of action is to be taken + ********************************************************/ + void PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage); + + /******************************************************** + * Gets a specific players position + * @param playerID: ID of the player whos position you want + ********************************************************/ + void GetPlayerPos(int playerID); + + /******************************************************** + * Gets the position of all players currently in the game + ********************************************************/ + void GetAllPlayerPos(); + + /******************************************************** + * Creates a player and returns PlayerData containing ID of the player + ********************************************************/ + PlayerData CreatePlayer(); + + /******************************************************** + * Creates a team + ********************************************************/ + void CreateTeam(); + + /******************************************************** + * Runs a update of the gamelogic and physics + ********************************************************/ + void NewFrame(); + + + private: + struct PrivateData; + PrivateData *myData; + + }; +} + + +#endif diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 500f8bbc..c67ef3d9 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -173,6 +173,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index e824c1d5..49ff7780 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -50,7 +50,6 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) Object::~Object(void) { - } OBJECT_TYPE Object::GetType() diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 626e565f..a3702a53 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -94,9 +94,9 @@ void Player::MoveLeft() state.ApplyLinearImpulse(-r * 100); } -void Player::UseWeapon(const WEAPON_FIRE &fireInput) +void Player::UseWeapon(const WEAPON_FIRE &Usage) { - myData->weapon->Use(fireInput); + myData->weapon->Use(Usage); } void Player::Respawn(Oyster::Math::Float3 spawnPoint) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 2cc703ac..e9ad03da 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -33,7 +33,7 @@ namespace GameLogic * Uses the weapon based on input * @param fireInput: enum value on what kind of action is to be taken ********************************************************/ - void UseWeapon(const WEAPON_FIRE &fireInput); + void UseWeapon(const WEAPON_FIRE &Usage); /******************************************************** * Respawns the player, this resets several stats and settings on the player From 8ecd2633180d909b47a149e591a8ffa9bc835a49 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 13 Jan 2014 10:25:20 +0100 Subject: [PATCH 12/42] Work asssignment split line --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index f917407b..0d0d31b2 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -73,6 +73,9 @@ namespace } protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis ); + + /////// Dan below / Robin Above + protoState.ApplyImpulse( bounce, worldPointOfContact, normal ); proto->SetState( protoState ); } From 792f78c34a9c66a4422104b481bf66107a20dd45 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Mon, 13 Jan 2014 12:11:45 +0100 Subject: [PATCH 13/42] GL- adding client UML, trying AddObj protocol with down-button. Problem with sending char* --- Code/Dokumentation/GameClient.uxf | 334 ++++++++++++++++++ Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 16 +- .../DanBiasGame/GameClientState/GameState.cpp | 51 ++- .../DanBiasGame/GameClientState/GameState.h | 7 +- Code/Game/DanBiasGame/Include/DanBiasGame.h | 2 + .../DanBiasServer/GameSession/GameSession.cpp | 16 +- Code/Game/GameLogic/Game.cpp | 2 +- Code/Game/GameProtocols/ObjectProtocols.h | 51 ++- 8 files changed, 445 insertions(+), 34 deletions(-) create mode 100644 Code/Dokumentation/GameClient.uxf diff --git a/Code/Dokumentation/GameClient.uxf b/Code/Dokumentation/GameClient.uxf new file mode 100644 index 00000000..154f0791 --- /dev/null +++ b/Code/Dokumentation/GameClient.uxf @@ -0,0 +1,334 @@ + + + 10 + + com.umlet.element.Class + + 390 + 120 + 100 + 30 + + /C_Object/ + + + + + com.umlet.element.Class + + 320 + 0 + 100 + 30 + + C_Player + + + + com.umlet.element.Class + + 440 + 0 + 100 + 30 + + C_StaticObj + + + + com.umlet.element.Class + + 200 + 0 + 100 + 30 + + C_DynamicObj + + + + com.umlet.element.Relation + + 240 + 0 + 200 + 140 + + lt=<<- + 30;30;30;120;180;120 + + + com.umlet.element.Relation + + 370 + 0 + 50 + 140 + + lt=<<- + 30;30;30;120 + + + com.umlet.element.Relation + + 450 + 0 + 50 + 140 + + lt=<<- + 30;30;30;120 + + + com.umlet.element.Class + + 210 + 220 + 100 + 100 + + GameState +-- +C_Object* +GameState +Camera +Client* + + + + com.umlet.element.Class + + 360 + 330 + 160 + 50 + + /GameClientState/ +Is eighter game or lobby + + + + com.umlet.element.Class + + 570 + 220 + 100 + 100 + + LobbyState +-- +C_Object* +Camera +Client* + + + + com.umlet.element.Class + + 380 + 440 + 120 + 120 + + DanBiasGame +-- +Client +Input +GameClientState +Window + + + + com.umlet.element.Relation + + 400 + 350 + 50 + 110 + + lt=<<<<- + 30;90;30;30 + + + com.umlet.element.Relation + + 230 + 290 + 150 + 80 + + lt=<<- + 30;30;30;60;130;60 + + + com.umlet.element.Relation + + 490 + 290 + 150 + 80 + + lt=<<- + 130;30;130;60;30;60 + + + com.umlet.element.Class + + 560 + 0 + 100 + 30 + + C_UiObject + + + + com.umlet.element.Relation + + 410 + 0 + 210 + 140 + + lt=<<- + 190;30;190;120;30;120 + + + com.umlet.element.Relation + + 410 + 120 + 180 + 120 + + lt=<<<- + 160;100;30;100;30;30 + + + com.umlet.element.Relation + + 280 + 120 + 170 + 120 + + lt=<<<- + 30;100;150;100;150;30 + + + com.umlet.element.Class + + 620 + 120 + 100 + 30 + + Light + + + + com.umlet.element.Class + + 340 + 640 + 100 + 40 + + NetworkAPI +-- + + + + com.umlet.element.Class + + 230 + 640 + 100 + 40 + + GraphicsAPI +-- + + + + + com.umlet.element.Relation + + 230 + 530 + 170 + 130 + + lt=<<. + 30;110;30;30;150;30 + + + com.umlet.element.Relation + + 360 + 530 + 50 + 130 + + lt=<<. + 30;110;30;30 + + + com.umlet.element.Class + + 460 + 640 + 100 + 40 + + Input +-- + + + + com.umlet.element.Relation + + 460 + 530 + 50 + 130 + + lt=<<. + 30;110;30;30 + + + com.umlet.element.Class + + 120 + 520 + 110 + 40 + + DanBiasLancher +-- + + + + com.umlet.element.Class + + 580 + 640 + 110 + 40 + + WindowManager +-- + + + + com.umlet.element.Relation + + 470 + 530 + 190 + 130 + + lt=<<. + 170;110;170;30;30;30 + + diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index b71f6dcd..2a5daa3f 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -70,6 +70,7 @@ namespace DanBias Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; protocolData->object_ID = p[1].value.netInt; + char k = p[2].value.netChar; protocolData->path = p[2].value.netCharPtr; for(int i = 0; i< 16; i++) { @@ -142,6 +143,7 @@ namespace DanBias DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData(); + float DanBiasGame::capFrame = 0; //-------------------------------------------------------------------------------------- // Interface API functions @@ -186,10 +188,16 @@ namespace DanBias float dt = (float)m_data->timer->getElapsedSeconds(); m_data->timer->reset(); - if(Update(dt) != S_OK) - return DanBiasClientReturn_Error; - if(Render(dt) != S_OK) - return DanBiasClientReturn_Error; + capFrame += dt; + if(capFrame > 0.03) + { + if(Update(dt) != S_OK) + return DanBiasClientReturn_Error; + if(Render(dt) != S_OK) + return DanBiasClientReturn_Error; + capFrame = 0; + } + } return DanBiasClientReturn_Sucess; } diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index cc4bbe53..a93a8e91 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -18,10 +18,16 @@ struct GameState::myData Oyster::Network::NetworkClient* nwClient; gameStateState state; + + }privData; GameState::GameState(void) { + key_forward = false; + key_backward = false; + key_strafeRight = false; + key_strafeLeft = false; } @@ -121,24 +127,53 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI if(KeyInput->IsKeyPressed(DIK_W)) { - movePlayer.bForward = true; - send = true; + + if(!key_forward) + { + movePlayer.bForward = true; + send = true; + key_forward = true; + } } + else + key_forward = false; + if(KeyInput->IsKeyPressed(DIK_S)) { - movePlayer.bBackward = true; - send = true; + if(!key_backward) + { + movePlayer.bBackward = true; + send = true; + key_backward = true; + } } + else + key_backward = false; + if(KeyInput->IsKeyPressed(DIK_A)) { - movePlayer.bStrafeLeft = true; - send = true; + if(!key_strafeLeft) + { + movePlayer.bStrafeLeft = true; + send = true; + key_strafeLeft = true; + } } + else + key_strafeLeft = false; + if(KeyInput->IsKeyPressed(DIK_D)) { - movePlayer.bStrafeRight = true; - send = true; + if(!key_strafeRight) + { + movePlayer.bStrafeRight = true; + send = true; + key_strafeRight = true; + } } + else + key_strafeRight = false; + if (privData->nwClient->IsConnected() && send) { diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 4de73a39..3942afba 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -16,7 +16,12 @@ class GameState : public GameClientState gameStateState_end, }; private: - + + bool key_forward; + bool key_backward; + bool key_strafeRight; + bool key_strafeLeft; + struct myData; myData* privData; public: diff --git a/Code/Game/DanBiasGame/Include/DanBiasGame.h b/Code/Game/DanBiasGame/Include/DanBiasGame.h index 2041e6fe..70bbcb18 100644 --- a/Code/Game/DanBiasGame/Include/DanBiasGame.h +++ b/Code/Game/DanBiasGame/Include/DanBiasGame.h @@ -54,6 +54,8 @@ namespace DanBias static HRESULT Render(float deltaTime); static HRESULT CleanUp(); + static float capFrame; + private: static DanBiasGamePrivateData* m_data; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.cpp b/Code/Game/DanBiasServer/GameSession/GameSession.cpp index e5238620..ed47f53c 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession.cpp @@ -133,6 +133,14 @@ namespace DanBias Send(p.GetProtocol()); Sleep(100); } + if(GetAsyncKeyState(VK_DOWN)) + { + Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; + Protocol_CreateObject p(world, 2, "grdg"); + //p.path = "../Content/crate"; + Send(p.GetProtocol()); + Sleep(100); + } } void GameSession::ParseEvents() { @@ -159,16 +167,16 @@ namespace DanBias Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; if(p[1].value.netBool) //bool bForward; - world.v[3].x = 2; + world.v[3].y = 2; //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); if(p[2].value.netBool) //bool bBackward; - world.v[3].x = -2; + world.v[3].y = -2; //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); if(p[5].value.netBool) //bool bStrafeRight; - world.v[3].y = 2; + world.v[3].x = -2; //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); if(p[6].value.netBool) //bool bStrafeLeft; - world.v[3].y = -2; + world.v[3].x = 2; //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); Protocol_ObjectPosition res(world, 0); diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 806ac6d2..8c23763c 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -57,7 +57,7 @@ void Game::GetAllPlayerPos() Game::PlayerData Game::CreatePlayer() { - + return PlayerData(); } void Game::CreateTeam() diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 6a1cde90..880b645d 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -28,27 +28,46 @@ namespace GameLogic this->protocol[i].type = Oyster::Network::NetAttributeType_Float; } } + Protocol_CreateObject(float m[16], int id, char *path) + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_CreateObject; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + for (int i = 2; i <= 17; i++) + { + this->protocol[i].type = Oyster::Network::NetAttributeType_Float; + } + + object_ID = id; + this->path = path; + memcpy(&worldMatrix[0], &m[0], sizeof(float)*16); + } Oyster::Network::CustomNetProtocol* GetProtocol() override { this->protocol[1].value = object_ID; this->protocol[2].value = path; - this->protocol[3].value = worldMatrix[1]; - this->protocol[4].value = worldMatrix[2]; - this->protocol[5].value = worldMatrix[3]; - this->protocol[6].value = worldMatrix[4]; - this->protocol[7].value = worldMatrix[5]; - this->protocol[8].value = worldMatrix[6]; - this->protocol[9].value = worldMatrix[7]; - this->protocol[10].value = worldMatrix[8]; - this->protocol[11].value = worldMatrix[9]; - this->protocol[12].value = worldMatrix[10]; - this->protocol[13].value = worldMatrix[11]; - this->protocol[14].value = worldMatrix[12]; - this->protocol[15].value = worldMatrix[13]; - this->protocol[16].value = worldMatrix[14]; - this->protocol[17].value = worldMatrix[15]; - this->protocol[18].value = worldMatrix[16]; + this->protocol[3].value = worldMatrix[0]; + this->protocol[4].value = worldMatrix[1]; + this->protocol[5].value = worldMatrix[2]; + this->protocol[6].value = worldMatrix[3]; + this->protocol[7].value = worldMatrix[4]; + this->protocol[8].value = worldMatrix[5]; + this->protocol[9].value = worldMatrix[6]; + this->protocol[10].value = worldMatrix[7]; + this->protocol[11].value = worldMatrix[8]; + this->protocol[12].value = worldMatrix[9]; + this->protocol[13].value = worldMatrix[10]; + this->protocol[14].value = worldMatrix[11]; + this->protocol[15].value = worldMatrix[12]; + this->protocol[16].value = worldMatrix[13]; + this->protocol[17].value = worldMatrix[14]; + this->protocol[18].value = worldMatrix[15]; + + + return &protocol; } From ce89e6bc980709a82d98d44bbfcfd09181ef0463 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Mon, 13 Jan 2014 12:44:33 +0100 Subject: [PATCH 14/42] GameServer - Fixed some minor bugs, one that made server crash on exit. Also integrated some of GameLogics new API functions --- Code/Dokumentation/GameServer.uxf | 10 +- Code/Dokumentation/Threading.uxf | 58 +--- Code/Game/DanBiasGame/DLLMain.cpp | 1 - Code/Game/DanBiasGame/Include/DanBiasGame.h | 3 + .../AdminInterface/AdminInterface.h | 3 + Code/Game/DanBiasServer/DanBiasServer.vcxproj | 5 +- Code/Game/DanBiasServer/DanBiasServerAPI.h | 6 +- Code/Game/DanBiasServer/GameServer.cpp | 14 +- Code/Game/DanBiasServer/GameServer.h | 3 + .../DanBiasServer/GameSession/GameClient.cpp | 45 ++- .../DanBiasServer/GameSession/GameClient.h | 20 +- .../DanBiasServer/GameSession/GameSession.cpp | 326 ------------------ .../DanBiasServer/GameSession/GameSession.h | 38 +- .../GameSession/GameSession_Events.cpp | 114 ++++++ .../GameSession/GameSession_General.cpp | 167 +++++++++ .../GameSession/GameSession_Logic.cpp | 37 ++ .../GameSession/GameSession_Network.cpp | 29 ++ Code/Game/DanBiasServer/Helpers/MapManager.h | 3 + .../LobbySessions/INetworkSession.h | 3 + .../DanBiasServer/LobbySessions/LobbyClient.h | 3 + .../DanBiasServerLauncher/ServerLauncher.cpp | 2 +- Code/Game/GameLogic/Game.cpp | 8 +- Code/Game/GameLogic/Game.h | 8 +- Code/Game/GameLogic/Player.cpp | 2 +- Code/Game/GameLogic/Player.h | 3 +- Code/Misc/Thread/OysterThread.h | 4 +- Code/Misc/Thread/OysterThread_Impl.cpp | 16 +- Code/Misc/Utilities-Impl.h | 3 +- Code/Network/NetworkAPI/NetworkServer.cpp | 2 +- Code/OysterGraphics/Model/Model.h | 2 + 30 files changed, 508 insertions(+), 430 deletions(-) delete mode 100644 Code/Game/DanBiasServer/GameSession/GameSession.cpp create mode 100644 Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp create mode 100644 Code/Game/DanBiasServer/GameSession/GameSession_General.cpp create mode 100644 Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp create mode 100644 Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp diff --git a/Code/Dokumentation/GameServer.uxf b/Code/Dokumentation/GameServer.uxf index 0b15fff4..9b416e02 100644 --- a/Code/Dokumentation/GameServer.uxf +++ b/Code/Dokumentation/GameServer.uxf @@ -423,14 +423,14 @@ INetworkSession UMLClass - 170 - 400 - 130 - 90 + 150 + 420 + 160 + 50 MapManager -- -Manages and makes sure maps are avalible to all clinents. +Manages all map stuff. elementstyle=wordwrap diff --git a/Code/Dokumentation/Threading.uxf b/Code/Dokumentation/Threading.uxf index 9628a18c..30499d26 100644 --- a/Code/Dokumentation/Threading.uxf +++ b/Code/Dokumentation/Threading.uxf @@ -1,12 +1,12 @@ - + 12 com.umlet.element.Class 540 - 456 - 132 + 468 + 336 36 OysterThread @@ -16,9 +16,9 @@ com.umlet.element.Class 372 - 408 + 396 120 - 36 + 48 /Some class/ @@ -29,11 +29,11 @@ 336 300 228 - 132 + 120 lt=>>>>>- <<implements>> - 96;108;96;60;204;60 + 96;96;96;60;204;60 com.umlet.element.Relation @@ -41,52 +41,30 @@ 396 408 168 - 96 + 108 lt=<<<<- Creates>> - 36;36;36;72;132;72;144;72 + 36;36;36;84;132;84;144;84 com.umlet.element.Relation - 564 - 372 + 660 + 384 60 108 lt=<<<- 36;84;36;36 - - com.umlet.element.Class - - 540 - 540 - 132 - 36 - - OysterMutex - - - - com.umlet.element.Relation - - 564 - 456 - 60 - 108 - - lt=<<<<- - 36;36;36;84 - UMLClass 540 312 336 - 96 + 108 /<<interface>>/ IThreadObject @@ -123,16 +101,4 @@ bg=red lt=- 36;36;36;108 - - com.umlet.element.Relation - - 336 - 408 - 228 - 168 - - lt=>>. -uses - 60;36;60;144;204;144 - diff --git a/Code/Game/DanBiasGame/DLLMain.cpp b/Code/Game/DanBiasGame/DLLMain.cpp index e2d438ba..dfd6ca1a 100644 --- a/Code/Game/DanBiasGame/DLLMain.cpp +++ b/Code/Game/DanBiasGame/DLLMain.cpp @@ -3,6 +3,5 @@ BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ) { - //MessageBox(0, L"DanBiasGame Loaded", 0, 0); return TRUE; } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/Include/DanBiasGame.h b/Code/Game/DanBiasGame/Include/DanBiasGame.h index 2041e6fe..184960e3 100644 --- a/Code/Game/DanBiasGame/Include/DanBiasGame.h +++ b/Code/Game/DanBiasGame/Include/DanBiasGame.h @@ -1,3 +1,6 @@ +///////////////////////////////////////// +// Created by [Dennis Andersen] [2013] // +///////////////////////////////////////// #ifndef DANBIASGAME_DANBIASGAME_H #define DANBIASGAME_DANBIASGAME_H diff --git a/Code/Game/DanBiasServer/AdminInterface/AdminInterface.h b/Code/Game/DanBiasServer/AdminInterface/AdminInterface.h index afb00973..4acc20a2 100644 --- a/Code/Game/DanBiasServer/AdminInterface/AdminInterface.h +++ b/Code/Game/DanBiasServer/AdminInterface/AdminInterface.h @@ -1,3 +1,6 @@ +///////////////////////////////////////// +// Created by [Dennis Andersen] [2013] // +///////////////////////////////////////// #ifndef DANBIASSERVER_ADMIN_INTERFACE_H #define DANBIASSERVER_ADMIN_INTERFACE_H diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj index 529ebdc0..82b62bee 100644 --- a/Code/Game/DanBiasServer/DanBiasServer.vcxproj +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -179,10 +179,13 @@ + + + - + diff --git a/Code/Game/DanBiasServer/DanBiasServerAPI.h b/Code/Game/DanBiasServer/DanBiasServerAPI.h index 1165ba48..1d514053 100644 --- a/Code/Game/DanBiasServer/DanBiasServerAPI.h +++ b/Code/Game/DanBiasServer/DanBiasServerAPI.h @@ -1,6 +1,6 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////// +// Created by [Dennis Andersen] [2013] // +///////////////////////////////////////// #ifndef DANBIAS_SERVER_DANBIAS_SERVER_H #define DANBIAS_SERVER_DANBIAS_SERVER_H diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp index a5210123..1da2b5ba 100644 --- a/Code/Game/DanBiasServer/GameServer.cpp +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -22,6 +22,7 @@ namespace DanBias { using namespace Oyster::Network; + GameServer* GameServer::instance = 0; void GameServer::NetworkCallback(NetworkClient* client) { @@ -38,7 +39,7 @@ namespace DanBias desc.clients.Push(c); desc.exitDestionation = this->mainLobby; if((sessionId = GameSessionManager::AddSession(desc, true)) == 0) - printf("Failed to create a game session"); + printf("Failed to create a game session\n"); myTest = true; //myTest = new GameSession(); // @@ -68,7 +69,7 @@ namespace DanBias , maxClients(0) , mainLobby(0) , server(0) - { } + { this->instance = this; } GameServer::~GameServer() { @@ -89,7 +90,6 @@ namespace DanBias if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error; if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error; - //if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error; this->initiated = true; return DanBiasServerReturn_Sucess; @@ -108,10 +108,9 @@ namespace DanBias { if(!WindowShell::Frame()) break; - this->mainLobby->Frame(); - if(GetAsyncKeyState(0x51)) + if(GetAsyncKeyState(0x51)) //Q for exit break; } @@ -128,6 +127,11 @@ namespace DanBias return DanBiasServerReturn_Sucess; } + NetworkSession* GameServer::MainLobbyInstance() + { + return GameServer::instance->mainLobby; + } + bool GameServer::LoadIniFile(InitData& ini) { std::ifstream in; diff --git a/Code/Game/DanBiasServer/GameServer.h b/Code/Game/DanBiasServer/GameServer.h index 2461ee9a..ccdb6e05 100644 --- a/Code/Game/DanBiasServer/GameServer.h +++ b/Code/Game/DanBiasServer/GameServer.h @@ -21,6 +21,8 @@ namespace DanBias DanBiasServerReturn Run(); DanBiasServerReturn Release(); + static NetworkSession* MainLobbyInstance(); + private: //static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient); void NetworkCallback(Oyster::Network::NetworkClient* client) override; @@ -31,6 +33,7 @@ namespace DanBias int maxClients; MainLobby *mainLobby; Oyster::Network::NetworkServer *server; + static GameServer* instance; private: struct InitData diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.cpp b/Code/Game/DanBiasServer/GameSession/GameClient.cpp index 5e086e91..a856a751 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameClient.cpp @@ -4,16 +4,22 @@ #include "GameClient.h" #include "..\LobbySessions\NetworkSession.h" +#include #include using namespace Utility::DynamicMemory; using namespace DanBias; +using namespace GameLogic; -GameClient::GameClient(SmartPointer client, Oyster::Callback::OysterCallback value) +static int gameClientIDCount = 1; + +GameClient::GameClient(SmartPointer client, Game::PlayerData player, Oyster::Callback::OysterCallback value) { this->callbackValue = value; this->client = client; - this->player = new GameLogic::Player(); + //this->player = new GameLogic::Player(); + this->id = gameClientIDCount++; + this->player = player; Oyster::Callback::OysterCallback c; c.callbackType = Oyster::Callback::CallbackType_Object; c.value = this; @@ -22,8 +28,11 @@ GameClient::GameClient(SmartPointer client, Oyster::Callback::Oyste } GameClient::~GameClient() { - this->client->Disconnect(); - this->player.Release(); + if(this->client) this->client->Disconnect(); + this->player.playerID = 0; + this->player.teamID = 0; + this->id = -1; + //this->player.Release(); } void GameClient::SetCallback(Oyster::Callback::OysterCallback value) @@ -31,15 +40,35 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallbackcallbackValue = value; } -GameLogic::Player* GameClient::GetPlayer() +//GameLogic::Player* GameClient::GetPlayer() +//{ +// return this->player.Get(); +//} +GameLogic::Game::PlayerData* GameClient::GetPlayer() { - return this->player.Get(); + return &this->player; } -LobbyClient* GameClient::GetClient() +GameLogic::Game::PlayerData GameClient::ReleasePlayer() +{ + GameLogic::Game::PlayerData temp = this->player; + this->player.playerID = 0; + this->player.teamID = 0; + return temp; +} +LobbyClient* GameClient::GetClient() const { return this->client; } - +Utility::DynamicMemory::SmartPointer GameClient::ReleaseClient() +{ + SmartPointer temp = this->client; + this->client = 0; + return temp; +} +int GameClient::GetID() const +{ + return this->id; +} void GameClient::ObjectCallback(NetworkSession::NetEvent e) { e.gameClient = this; diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.h b/Code/Game/DanBiasServer/GameSession/GameClient.h index a79c3707..f3d10a77 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.h +++ b/Code/Game/DanBiasServer/GameSession/GameClient.h @@ -6,28 +6,34 @@ #include "..\LobbySessions\LobbyClient.h" #include -#include +#include namespace DanBias { class GameClient: Oyster::Callback::CallbackObject { public: - GameClient(Utility::DynamicMemory::SmartPointer client, Oyster::Callback::OysterCallback value); + GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::Game::PlayerData player, Oyster::Callback::OysterCallback value); virtual~GameClient(); void SetCallback(Oyster::Callback::OysterCallback value); - GameLogic::Player* GetPlayer(); - LobbyClient* GetClient(); + //GameLogic::Player* GetPlayer(); + GameLogic::Game::PlayerData* GetPlayer(); + GameLogic::Game::PlayerData ReleasePlayer(); + + LobbyClient* GetClient() const; + Utility::DynamicMemory::SmartPointer ReleaseClient(); + int GetID() const; private: - Utility::DynamicMemory::SmartPointer player; + //Utility::DynamicMemory::SmartPointer player; + GameLogic::Game::PlayerData player; Utility::DynamicMemory::SmartPointer client; Oyster::Callback::OysterCallback callbackValue; - + int id; void ObjectCallback(NetworkSession::NetEvent) override; - + private: friend class AdminInterface; }; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.cpp b/Code/Game/DanBiasServer/GameSession/GameSession.cpp deleted file mode 100644 index 745e1369..00000000 --- a/Code/Game/DanBiasServer/GameSession/GameSession.cpp +++ /dev/null @@ -1,326 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// -#include "GameSession.h" -#include "GameClient.h" - -#include -#include -#include - -#include - - -using namespace Utility::DynamicMemory; -using namespace Oyster; -using namespace Oyster::Network; -using namespace Oyster::Thread; -using namespace GameLogic; - -namespace DanBias -{ - void InsertObject(DynamicArray>& clients, SmartPointer obj) - { - for (unsigned int i = 0; i < clients.Size(); i++) - { - if(!clients[i]) - { - clients[i] = obj; - return; - } - } - clients.Push(obj); - } - void RemoveObject(DynamicArray>& clients, DanBias::GameClient* obj) - { - for (unsigned int i = 0; i < clients.Size(); i++) - { - if(clients[i] && clients[i]->GetClient()->GetID() == obj->GetClient()->GetID()) - { - clients[i] = 0; - return; - } - } - } - - GameSession::GameSession() - { - this->owner = 0; - this->box = 0; - this->isCreated = false; - this->isRunning = false; - } - GameSession::~GameSession() - { - delete this->box; - this->box = 0; - this->owner = 0; - } - - bool GameSession::Create(GameDescription& desc) - { - if(desc.clients.Size() == 0) return false; - if(!desc.owner) return false; - if(!desc.mapName.size()) return false; - if(this->isCreated) return false; - - this->clients.Resize(desc.clients.Size()); - - this->box = new PostBox(); - this->owner = desc.owner; - - Oyster::Callback::OysterCallback c; - c.value.callbackPostBox = this->box; - c.callbackType = Oyster::Callback::CallbackType_PostBox; - - for (unsigned int i = 0; i < desc.clients.Size(); i++) - { - this->clients[i] = new GameClient(desc.clients[i], c); - } - - this->isCreated = true; - return true; - } - - void GameSession::Run() - { - if(this->isRunning) return; - if(this->clients.Size() > 0) - { - if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return; - this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2); - this->isRunning = true; - } - } - - bool GameSession::Join(Utility::DynamicMemory::SmartPointer client) - { - if(!this->isCreated) return false; - - Oyster::Callback::OysterCallback c; - c.value.callbackPostBox = this->box; - c.callbackType = Oyster::Callback::CallbackType_PostBox; - - SmartPointer obj = new GameClient(client, c); - InsertObject(this->clients, obj); - - return true; - } - void GameSession::CloseSession(bool dissconnectClients) - { - this->worker.Stop(false); - //NetworkSession::CloseSession(dissconnectClients); - this->isCreated = false; - this->isRunning = false; - } - -////private: //overriden Threading functions - bool GameSession::DoWork ( ) - { - this->Frame(); - - return true; - } - -#ifndef ERIK -////private: - void GameSession::Frame() - { - this->ParseEvents(); - - if(GetAsyncKeyState(VK_UP)) - { - Protocol_General_Status p(Protocol_General_Status::States_ready); - Send(p.GetProtocol()); - Sleep(100); - } - } - void GameSession::ParseEvents() - { - if( !this->box->IsEmpty() ) - { - NetworkSession::NetEvent &e = this->box->Fetch(); - - if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return; - - if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) ) - ParseGameplayEvent(e.protocol, e.gameClient); - - if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) ) - ParseGeneralEvent(e.protocol, e.gameClient); - } - } - - void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) - { - switch (p[protocol_INDEX_ID].value.netShort) - { - case protocol_Gameplay_PlayerNavigation: - { - - Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; - if(p[1].value.netBool) //bool bForward; - world.v[3].x = 2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); - if(p[2].value.netBool) //bool bBackward; - world.v[3].x = -2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); - if(p[5].value.netBool) //bool bStrafeRight; - world.v[3].y = 2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); - if(p[6].value.netBool) //bool bStrafeLeft; - world.v[3].y = -2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - - Protocol_ObjectPosition res(world, 0); - Send(res.GetProtocol()); - - - } - break; - case protocol_Gameplay_PlayerMouseMovement: - - break; - case protocol_Gameplay_PlayerPosition: - - break; - case protocol_Gameplay_CreateObject: - - break; - case protocol_Gameplay_ObjectPosition: - - break; - } - } - void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) - { - switch (p[protocol_INDEX_ID].value.netShort) - { - case protocol_General_Status: - switch (p[1].value.netInt) - { - case GameLogic::Protocol_General_Status::States_bussy: - - break; - - case GameLogic::Protocol_General_Status::States_disconected: - printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); - RemoveObject(this->clients, c); - break; - - case GameLogic::Protocol_General_Status::States_idle: - break; - - case GameLogic::Protocol_General_Status::States_ready: - - break; - } - break; - - case protocol_General_Text: - - break; - } - } - void GameSession::Send(Oyster::Network::CustomNetProtocol* p) - { - for (unsigned int i = 0; i < this->clients.Size(); i++) - { - if(this->clients[i] && this->clients[i]->GetClient()) - this->clients[i]->GetClient()->Send(p); - } - } - -#else -#include "DynamicObject.h" -//#include "CollisionManager.h" -//#include "GameLogicStates.h" -//#include - - /* - using namespace GameLogic; - //VARIABLES GOES HERE - DynamicObject* objectBox; - - bool GameSession::Init(GameSessionDescription& desc) - { - if(desc.clients.Size() == 0) return false; - this->box = new PostBox(); - this->owner = desc.owner; - for (unsigned int i = 0; i < desc.clients.Size(); i++) - { - desc.clients[i]->SetPostbox(this->box); - this->clients.Push(desc.clients[i]); - } - - CollisionManager::BoxCollision(0,0); - - objectBox = new DynamicObject(CollisionManager::BoxCollision, OBJECT_TYPE::OBJECT_TYPE_BOX); - - Protocol_CreateObject objectCreation; - objectCreation.object_ID = objectBox->GetID(); - objectCreation.path = "crate"; - Oyster::Math::Float4x4 worldMat = objectBox->GetRigidBody()->GetOrientation(); - - for (int i = 0; i < 16; i++) - { - objectCreation.worldMatrix[i] = worldMat[i]; - } - - for (int i = 0; i < clients.Size(); i++) - { - clients[i]->NetClient_Object()->Send(objectCreation); - } - - return true; - } - void GameSession::Frame() - { - } - void GameSession::ParseEvents() - { - if(this->box && !this->box->IsEmpty()) - { - NetEvent &e = this->box->Fetch(); - - if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return; - - ParseProtocol(e.protocol, *e.reciever); - } - } - void GameSession::ParseProtocol(Oyster::Network::CustomNetProtocol& p, DanBias::ClientObject& c) - { - switch (p[0].value.netShort) - { - case protocol_Gamplay_PlayerNavigation: - { - if(p[1].value.netBool) //bool bForward; - c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); - if(p[2].value.netBool) //bool bBackward; - c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); - if(p[5].value.netBool) //bool bStrafeRight; - c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); - if(p[6].value.netBool) //bool bStrafeLeft; - c.Logic_Object()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - } - break; - case protocol_Gamplay_PlayerMouseMovement: - - break; - case protocol_Gamplay_PlayerPosition: - - break; - case protocol_Gamplay_CreateObject: - - break; - case protocol_Gamplay_ObjectPosition: - - break; - } - } - */ - -#endif - -}//End namespace DanBias - diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.h b/Code/Game/DanBiasServer/GameSession/GameSession.h index a128cc74..c4318db4 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.h +++ b/Code/Game/DanBiasServer/GameSession/GameSession.h @@ -4,12 +4,14 @@ #ifndef DANBIASSERVER_GAME_SESSION_H #define DANBIASSERVER_GAME_SESSION_H -//warning C4150: deletion of pointer to incomplete type, no destructor called +//warning C4150: deletion of pointer to incomplete type, no destructor called, because of forward decleration and the use of smartpointer. #pragma warning(disable: 4150) #include "..\LobbySessions\NetworkSession.h" +#include #include #include +#include namespace DanBias { @@ -18,6 +20,9 @@ namespace DanBias class GameSession : public Oyster::Thread::IThreadObject, public INetworkSession { public: + /** + * A container to use when initiating a new session + */ struct GameDescription { std::wstring mapName; @@ -41,31 +46,44 @@ namespace DanBias bool Join(Utility::DynamicMemory::SmartPointer client); /** - * + * Closes the game session + * @param disconnectClients If set to true clients is dissconnected from the server, if false the clients is sent to the given owner of the session. */ - void CloseSession(bool dissconnectClients = false); - + void CloseSession(bool disconnectClients = false); inline bool IsCreated() const { return this->isCreated; } inline bool IsRunning() const { return this->isRunning; } - + //Private member functions private: - void Frame(); + //Handles all events recieved void ParseEvents(); + //Handles all gameplay events void ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); + //Handles all general events void ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c); - + //Adds a client to the client list + void AddClient(Utility::DynamicMemory::SmartPointer obj); + //Removes a client from the client list + void RemoveClient(DanBias::GameClient* obj); + //Sends a protocol ta all clients in session void Send(Oyster::Network::CustomNetProtocol* p); - - private: //overriden Threading functions + //Frame function, derived from IThreadObject bool DoWork ( ) override; + //Sends a client to the owner, if obj is NULL then all clients is sent + void SendToOwner(DanBias::GameClient* obj); + //Do a cleanup on all the private data + void Clean(); + //Private member variables private: + Utility::DynamicMemory::DynamicArray> clients; - NetworkSession* owner; Oyster::IPostBox *box; Oyster::Thread::OysterThread worker; + GameLogic::Game gameInstance; + NetworkSession* owner; + Utility::WinTimer timer; bool isCreated; bool isRunning; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp new file mode 100644 index 00000000..b8906867 --- /dev/null +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -0,0 +1,114 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "GameSession.h" +#include "GameClient.h" + +#include +#include +#include +#include + +#include + + +using namespace Utility::DynamicMemory; +using namespace Oyster; +using namespace Oyster::Network; +using namespace Oyster::Thread; +using namespace GameLogic; + +namespace DanBias +{ + void GameSession::ParseEvents() + { + if( !this->box->IsEmpty() ) + { + NetworkSession::NetEvent &e = this->box->Fetch(); + + if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return; + + if( ProtocolIsGameplay(e.protocol[protocol_INDEX_ID].value.netShort) ) + ParseGameplayEvent(e.protocol, e.gameClient); + + if( ProtocolIsGeneral(e.protocol[protocol_INDEX_ID].value.netShort) ) + ParseGeneralEvent(e.protocol, e.gameClient); + } + } + + void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) + { + switch (p[protocol_INDEX_ID].value.netShort) + { + case protocol_Gameplay_PlayerNavigation: + { + + Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; + if(p[1].value.netBool) //bool bForward; + world.v[3].x = 2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); + if(p[2].value.netBool) //bool bBackward; + world.v[3].x = -2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); + if(p[5].value.netBool) //bool bStrafeRight; + world.v[3].y = 2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); + if(p[6].value.netBool) //bool bStrafeLeft; + world.v[3].y = -2; + //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); + + Protocol_ObjectPosition res(world, 0); + Send(res.GetProtocol()); + + + } + break; + case protocol_Gameplay_PlayerMouseMovement: + + break; + case protocol_Gameplay_PlayerPosition: + + break; + case protocol_Gameplay_CreateObject: + + break; + case protocol_Gameplay_ObjectPosition: + + break; + } + } + + void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) + { + switch (p[protocol_INDEX_ID].value.netShort) + { + case protocol_General_Status: + switch (p[1].value.netInt) + { + case GameLogic::Protocol_General_Status::States_bussy: + + break; + + case GameLogic::Protocol_General_Status::States_disconected: + printf("Client with ID [%i] dissconnected\n", c->GetClient()->GetID()); + this->RemoveClient(c); + break; + + case GameLogic::Protocol_General_Status::States_idle: + + break; + + case GameLogic::Protocol_General_Status::States_ready: + + break; + } + break; + + case protocol_General_Text: + + break; + } + } + +}//End namespace DanBias + diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp new file mode 100644 index 00000000..e0ba12ee --- /dev/null +++ b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp @@ -0,0 +1,167 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "GameSession.h" +#include "GameClient.h" +#include "..\GameServer.h" +#include +#include +#include + +#include + + +using namespace Utility::DynamicMemory; +using namespace Oyster; +using namespace Oyster::Network; +using namespace Oyster::Thread; +using namespace GameLogic; + +namespace DanBias +{ + GameSession::GameSession() + { + this->owner = 0; + this->box = 0; + this->isCreated = false; + this->isRunning = false; + } + + GameSession::~GameSession() + { + delete this->box; + this->box = 0; + this->owner = 0; + } + + bool GameSession::Create(GameDescription& desc) + { + if(desc.clients.Size() == 0) return false; + if(!desc.owner) return false; + if(!desc.mapName.size()) return false; + if(this->isCreated) return false; + + this->clients.Resize(desc.clients.Size()); + + this->box = new PostBox(); + this->owner = desc.owner; + + Oyster::Callback::OysterCallback c; + c.value.callbackPostBox = this->box; + c.callbackType = Oyster::Callback::CallbackType_PostBox; + + for (unsigned int i = 0; i < desc.clients.Size(); i++) + { + this->clients[i] = new GameClient(desc.clients[i], gameInstance.CreatePlayer(), c); + } + + if(this->worker.Create(this, true, true) != OYSTER_THREAD_ERROR_SUCCESS) return false; + + this->isCreated = true; + + return true; + } + + void GameSession::Run() + { + + if(this->isRunning) return; + + if(this->clients.Size() > 0) + { + + this->worker.SetPriority(OYSTER_THREAD_PRIORITY_2); + this->isRunning = true; + } + } + + bool GameSession::Join(Utility::DynamicMemory::SmartPointer client) + { + if(!this->isCreated) return false; + + Oyster::Callback::OysterCallback c; + c.value.callbackPostBox = this->box; + c.callbackType = Oyster::Callback::CallbackType_PostBox; + + SmartPointer obj = new GameClient(client, this->gameInstance.CreatePlayer(), c); + AddClient(obj); + + return true; + } + + void GameSession::CloseSession(bool dissconnectClients) + { + if(dissconnectClients) + { + for (int i = 0; i < this->clients.Size(); i++) + { + this->clients[i]->GetClient()->Disconnect(); + } + } + else + { + this->SendToOwner(0); //Send all clients to the current owner + } + this->Clean(); + } + + void GameSession::AddClient(SmartPointer obj) + { + for (unsigned int i = 0; i < clients.Size(); i++) + { + if(!clients[i]) + { + clients[i] = obj; + return; + } + } + clients.Push(obj); + } + + void GameSession::RemoveClient(DanBias::GameClient* obj) + { + for (unsigned int i = 0; i < clients.Size(); i++) + { + if(clients[i] && clients[i]->GetID() == obj->GetID()) + { + clients[i] = 0; + return; + } + } + } + + void GameSession::SendToOwner(DanBias::GameClient* obj) + { + DanBias::NetworkSession *s = GameServer::MainLobbyInstance(); + + if(this->owner) s = this->owner; + + if(obj) + { + s->Attach(obj->ReleaseClient()); + RemoveClient(obj); + } + else + { + for (int i = 0; i < this->clients.Size(); i++) + { + s->Attach(this->clients[i]->ReleaseClient()); + RemoveClient(this->clients[i]); + } + } + } + + void GameSession::Clean() + { + this->worker.Terminate(); + this->clients.Clear(); + delete this->box; + this->box = 0; + this->gameInstance; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; + } + +}//End namespace DanBias + diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp new file mode 100644 index 00000000..ab1bcdf5 --- /dev/null +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "GameSession.h" +#include "GameClient.h" + +#include +#include +#include +#include + +using namespace Utility::DynamicMemory; +using namespace Oyster; +using namespace Oyster::Network; +using namespace Oyster::Thread; +using namespace GameLogic; + +namespace DanBias +{ + bool GameSession::DoWork( ) + { + this->gameInstance.NewFrame(); + + this->ParseEvents(); + + if(GetAsyncKeyState(VK_UP)) + { + Protocol_General_Status p(Protocol_General_Status::States_ready); + Send(p.GetProtocol()); + Sleep(100); + } + + return this->isRunning; + } + +}//End namespace DanBias + diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp new file mode 100644 index 00000000..f23ab118 --- /dev/null +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp @@ -0,0 +1,29 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "GameSession.h" +#include "GameClient.h" + +#include +#include +#include +#include + +using namespace Utility::DynamicMemory; +using namespace Oyster; +using namespace Oyster::Network; +using namespace Oyster::Thread; +using namespace GameLogic; + +namespace DanBias +{ + void GameSession::Send(Oyster::Network::CustomNetProtocol* p) + { + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i] && this->clients[i]->GetClient()) + this->clients[i]->GetClient()->Send(p); + } + } +}//End namespace DanBias + diff --git a/Code/Game/DanBiasServer/Helpers/MapManager.h b/Code/Game/DanBiasServer/Helpers/MapManager.h index 34999014..49342a56 100644 --- a/Code/Game/DanBiasServer/Helpers/MapManager.h +++ b/Code/Game/DanBiasServer/Helpers/MapManager.h @@ -1,3 +1,6 @@ +///////////////////////////////////////// +// Created by [Dennis Andersen] [2013] // +///////////////////////////////////////// #ifndef DANBIASSERVER_LEVELMANAGER_H #define DANBIASSERVER_LEVELMANAGER_H diff --git a/Code/Game/DanBiasServer/LobbySessions/INetworkSession.h b/Code/Game/DanBiasServer/LobbySessions/INetworkSession.h index 4495739f..dfad66ae 100644 --- a/Code/Game/DanBiasServer/LobbySessions/INetworkSession.h +++ b/Code/Game/DanBiasServer/LobbySessions/INetworkSession.h @@ -1,3 +1,6 @@ +///////////////////////////////////////// +// Created by [Dennis Andersen] [2013] // +///////////////////////////////////////// #ifndef DANBIASSERVER_INETWORKSESSION_H #define DANBIASSERVER_INETWORKSESSION_H diff --git a/Code/Game/DanBiasServer/LobbySessions/LobbyClient.h b/Code/Game/DanBiasServer/LobbySessions/LobbyClient.h index b827ca7e..33b99d78 100644 --- a/Code/Game/DanBiasServer/LobbySessions/LobbyClient.h +++ b/Code/Game/DanBiasServer/LobbySessions/LobbyClient.h @@ -1,3 +1,6 @@ +///////////////////////////////////////// +// Created by [Dennis Andersen] [2013] // +///////////////////////////////////////// #ifndef DANBIASSERVER_LOBBYCLIENT_H #define DANBIASSERVER_LOBBYCLIENT_H diff --git a/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp b/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp index 0d26c37d..17d1a045 100644 --- a/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp +++ b/Code/Game/DanBiasServerLauncher/ServerLauncher.cpp @@ -1,5 +1,5 @@ ////////////////////////////////////////////////// -// Launcher to launch Danbias server or client // +// Launcher to launch Danbias server // // Created by [Dennis Andersen] [2013] // ////////////////////////////////////////////////// #define NOMINMAX //Blame it on windows diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 806ac6d2..3e985cb8 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -1,6 +1,7 @@ #include "Game.h" #include "Player.h" #include "Level.h" +#include using namespace GameLogic; @@ -57,7 +58,12 @@ void Game::GetAllPlayerPos() Game::PlayerData Game::CreatePlayer() { - + PlayerData data; + //Yo mammma + data.playerID = GID(); + data.teamID = -1; + + return data; } void Game::CreateTeam() diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index a70dc842..3948f266 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -1,10 +1,16 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Erik Persson] [2013] +///////////////////////////////////////////////////////////////////// + #ifndef GAME_H #define GAME_H +#include "GameLogicDef.h" #include "GameLogicStates.h" + namespace GameLogic { - class Game + class DANBIAS_GAMELOGIC_DLL Game { public: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index a3702a53..08af0b9e 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -132,7 +132,7 @@ Oyster::Math::Float3 Player::GetPos() Oyster::Math::Float3 Player::GetLookDir() { - return myData->lookDir; + return myData->lookDir.xyz; } int Player::GetTeamID() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index e9ad03da..0743dc00 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -4,14 +4,13 @@ #ifndef PLAYER_H #define PLAYER_H #include "GameLogicStates.h" -#include "GameLogicDef.h" #include "OysterMath.h" #include "Object.h" namespace GameLogic { - class DANBIAS_GAMELOGIC_DLL Player : public Object + class Player : public Object { public: diff --git a/Code/Misc/Thread/OysterThread.h b/Code/Misc/Thread/OysterThread.h index 84c32144..cd4bfd3f 100644 --- a/Code/Misc/Thread/OysterThread.h +++ b/Code/Misc/Thread/OysterThread.h @@ -71,13 +71,13 @@ namespace Oyster //OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackObject* worker, bool start, bool detach = false); //OYSTER_THREAD_ERROR Create(Oyster::Callback::CallbackFunction::FNC worker, bool start, bool detach = false); OYSTER_THREAD_ERROR Start(); - OYSTER_THREAD_ERROR Stop(bool wait = false); + OYSTER_THREAD_ERROR Stop(); OYSTER_THREAD_ERROR Pause(); OYSTER_THREAD_ERROR Pause(int mSec); OYSTER_THREAD_ERROR Resume(); OYSTER_THREAD_ERROR SetWorker(IThreadObject* worker = 0); OYSTER_THREAD_ERROR SetWorker(ThreadFnc worker = 0); - OYSTER_THREAD_ERROR Terminate(bool wait = true); + OYSTER_THREAD_ERROR Terminate(); OYSTER_THREAD_ERROR Wait(); OYSTER_THREAD_ERROR Wait(int mSec); OYSTER_THREAD_ERROR Swap(const OysterThread* other); diff --git a/Code/Misc/Thread/OysterThread_Impl.cpp b/Code/Misc/Thread/OysterThread_Impl.cpp index 16668c04..534c992f 100644 --- a/Code/Misc/Thread/OysterThread_Impl.cpp +++ b/Code/Misc/Thread/OysterThread_Impl.cpp @@ -72,10 +72,10 @@ using namespace Utility::DynamicMemory; ~RefData() { //threadWaitFunctionLock.lock(); - Terminate(true); + Terminate(); //threadWaitFunctionLock.unlock(); } - OYSTER_THREAD_ERROR Terminate(bool wait) + OYSTER_THREAD_ERROR Terminate() { if(!threadData) return OYSTER_THREAD_ERROR_SUCCESS; @@ -129,12 +129,12 @@ using namespace Utility::DynamicMemory; data = new RefData(); return data->Create(fnc, worker, start, detach); } - OYSTER_THREAD_ERROR Terminate(bool wait) + OYSTER_THREAD_ERROR Terminate() { if(!data) return OYSTER_THREAD_ERROR_FAILED; - return data->Terminate(wait); + return data->Terminate(); } }; @@ -256,9 +256,9 @@ OYSTER_THREAD_ERROR OysterThread::Start() return OYSTER_THREAD_ERROR_SUCCESS; } -OYSTER_THREAD_ERROR OysterThread::Stop(bool wait) +OYSTER_THREAD_ERROR OysterThread::Stop() { - return this->Terminate(wait); + return this->Terminate(); } OYSTER_THREAD_ERROR OysterThread::Pause() { @@ -297,9 +297,9 @@ OYSTER_THREAD_ERROR OysterThread::SetWorker(ThreadFnc worker) return OYSTER_THREAD_ERROR_SUCCESS;; } -OYSTER_THREAD_ERROR OysterThread::Terminate(bool wait) +OYSTER_THREAD_ERROR OysterThread::Terminate() { - return this->privateData->Terminate(wait); + return this->privateData->Terminate(); } OYSTER_THREAD_ERROR OysterThread::Wait() { diff --git a/Code/Misc/Utilities-Impl.h b/Code/Misc/Utilities-Impl.h index 6ede28d0..476861f6 100644 --- a/Code/Misc/Utilities-Impl.h +++ b/Code/Misc/Utilities-Impl.h @@ -292,7 +292,8 @@ namespace Utility this->_ptr = p; - if(p) this->_rc->Incref(); + if(p) this->_rc->Incref(); + else this->_rc = 0; } return *this; } diff --git a/Code/Network/NetworkAPI/NetworkServer.cpp b/Code/Network/NetworkAPI/NetworkServer.cpp index e47195bf..ec4da231 100644 --- a/Code/Network/NetworkAPI/NetworkServer.cpp +++ b/Code/Network/NetworkAPI/NetworkServer.cpp @@ -115,7 +115,7 @@ void NetworkServer::PrivateData::Stop() started = false; - thread.Stop(true); + thread.Stop(); } void NetworkServer::PrivateData::Shutdown() diff --git a/Code/OysterGraphics/Model/Model.h b/Code/OysterGraphics/Model/Model.h index 0103b143..9fa5fb66 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -9,9 +9,11 @@ namespace Oyster { namespace Model { + //struct ModelInfo; struct Model { //! do not Edit, linked to render data + //ModelInfo* info; void* info; Oyster::Math::Float4x4 WorldMatrix; bool Visible; From c1c3b5e6af5ad5008a51bedfb6655a870f8e5bec Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 09:02:46 +0100 Subject: [PATCH 15/42] angular collision response fix Incorrect formula found and corrected --- Code/GamePhysics/PhysicsStructs-Impl.h | 4 +++- Code/OysterPhysics3D/OysterPhysics3D.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 1bdf07b6..9b13cacf 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -147,7 +147,9 @@ namespace Oyster inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const { //return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos ); // C3083 error? - return this->linearMomentum + ::Oyster::Math::Float4( this->angularMomentum.xyz.Cross((at - this->centerPos).xyz), 0.0f ); + + ::Oyster::Math::Float4 offset = at - this->centerPos; + return this->linearMomentum + ( ::Oyster::Math::Float4(this->angularMomentum.xyz.Cross(offset.xyz), 0.0f) /= offset.Dot(offset) ); } inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularMomentum() const diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index f70d228f..84058387 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -63,7 +63,7 @@ namespace Oyster { namespace Physics3D ******************************************************************/ inline ::Oyster::Math::Float4 TangentialLinearMomentum( const ::Oyster::Math::Float4 &angularMomentum, const ::Oyster::Math::Float4 &worldOffset ) { - return ::Oyster::Math::Float4( angularMomentum.xyz.Cross(worldOffset.xyz), 0.0f ); + return ::Oyster::Math::Float4( angularMomentum.xyz.Cross(worldOffset.xyz), 0.0f ) /= worldOffset.Dot( worldOffset ); } /****************************************************************** From 50b5b2dbf938c7778b617947d028acc1a2736a0e Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 09:12:37 +0100 Subject: [PATCH 16/42] linear collision response fix moved improved version of Robin's implementation --- .../Implementation/PhysicsAPI_Impl.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 0d0d31b2..c61f9ce9 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -38,6 +38,23 @@ namespace Float protoG_Magnitude = protoG.Dot( normal ), deuterG_Magnitude = deuterG.Dot( normal ); + // if they are not relatively moving towards eachother, there is no collision + Float deltaPos = normal.Dot( deuterState.GetCenterPosition() - protoState.GetCenterPosition() ); + if( deltaPos < 0.0f ) + { + if( protoG_Magnitude >= deuterG_Magnitude ) + { + break; + } + } + else if( deltaPos > 0.0f ) + { + if( protoG_Magnitude <= deuterG_Magnitude ) + { + break; + } + } + // bounce Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), deuterState.GetMass(), deuterG_Magnitude, From cc68088298d30f81036871c53698b36c9e8a5fbb Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 09:14:17 +0100 Subject: [PATCH 17/42] linear coll. resp. fix add fix didn't cover all cases. Now it do --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index c61f9ce9..0d1eaf5d 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -54,6 +54,10 @@ namespace break; } } + else + { + break; + } // bounce Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), From 8aa5ad772315525b36f3024868fdd00e70a1f227 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 09:16:54 +0100 Subject: [PATCH 18/42] Revert "Work asssignment split line" This reverts commit 8ecd2633180d909b47a149e591a8ffa9bc835a49. --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 0d1eaf5d..1115e7e9 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -94,9 +94,6 @@ namespace } protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis ); - - /////// Dan below / Robin Above - protoState.ApplyImpulse( bounce, worldPointOfContact, normal ); proto->SetState( protoState ); } From 04c5898f4e720f03a53b48759cddd84792b2f6e4 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 14 Jan 2014 09:24:55 +0100 Subject: [PATCH 19/42] GL - sending string and createOBJ working --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 1 - Code/Game/DanBiasGame/GameClientState/GameState.cpp | 12 +++++++----- Code/Game/DanBiasServer/GameSession/GameSession.cpp | 3 +-- Code/Game/GameProtocols/ObjectProtocols.h | 3 ++- Code/Network/NetworkAPI/CustomNetProtocol.cpp | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 2a5daa3f..cd3783ff 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -70,7 +70,6 @@ namespace DanBias Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; protocolData->object_ID = p[1].value.netInt; - char k = p[2].value.netChar; protocolData->path = p[2].value.netCharPtr; for(int i = 0; i< 16; i++) { diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index a93a8e91..d488808f 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -66,6 +66,8 @@ bool GameState::LoadModels(std::wstring mapFile) ModelInitData modelData; modelData.world = Oyster::Math3D::Float4x4::identity; + Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); + modelData.world = modelData.world * translate; modelData.visible = true; modelData.modelPath = L"..\\Content\\worldDummy"; modelData.id = 0; @@ -74,7 +76,7 @@ bool GameState::LoadModels(std::wstring mapFile) privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2)); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2)); modelData.world = modelData.world * translate; modelData.modelPath = L"..\\Content\\worldDummy"; modelData.id ++; @@ -262,21 +264,21 @@ void GameState::Protocol( ObjPos* pos ) } } -void GameState::Protocol( NewObj* pos ) +void GameState::Protocol( NewObj* newObj ) { Oyster::Math::Float4x4 world; for(int i = 0; i<16; i++) { - world[i] = pos->worldPos[i]; + world[i] = newObj->worldPos[i]; } ModelInitData modelData; modelData.world = world; modelData.visible = true; - modelData.id = pos->object_ID; + modelData.id = newObj->object_ID; //not sure if this is good parsing rom char* to wstring - const char* path = pos->path; + const char* path = newObj->path; modelData.modelPath = std::wstring(path, path + strlen(path)); // load models C_Object* player = new C_Player(); diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.cpp b/Code/Game/DanBiasServer/GameSession/GameSession.cpp index ed47f53c..853c13c7 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession.cpp @@ -136,8 +136,7 @@ namespace DanBias if(GetAsyncKeyState(VK_DOWN)) { Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; - Protocol_CreateObject p(world, 2, "grdg"); - //p.path = "../Content/crate"; + Protocol_CreateObject p(world, 2, "../Content/crate"); Send(p.GetProtocol()); Sleep(100); } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 880b645d..2a538714 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -34,8 +34,9 @@ namespace GameLogic this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; - for (int i = 2; i <= 17; i++) + for (int i = 3; i <= 18; i++) { this->protocol[i].type = Oyster::Network::NetAttributeType_Float; } diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index 91fb7267..d34832d7 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -22,10 +22,10 @@ struct CustomNetProtocol::PrivateData size_t size = strlen(i->second.value.netCharPtr); if(size == 0) continue; - attributes[i->first]; attributes[i->first].value.netCharPtr = new char[size + 1]; //strcpy_s(attributes[i->first].value.netCharPtr, size + 1, i->second.value.netCharPtr); memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1); + attributes[i->first].type = NetAttributeType_CharArray; } else { From 97cba4248debff4b7b7a33d30a11988faf2ce5da Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 14 Jan 2014 09:25:22 +0100 Subject: [PATCH 20/42] GameServer - Added more protocols. Divided the code in gamesession into several .cpp files --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 2 +- .../DanBiasGame/GameClientState/GameState.cpp | 2 +- .../DanBiasServer/GameSession/GameClient.cpp | 2 +- .../GameSession/GameSession_Events.cpp | 10 +-- .../GameSession/GameSession_General.cpp | 2 +- .../GameSession/GameSession_Logic.cpp | 2 +- .../GameSession/GameSession_Network.cpp | 2 +- .../LobbySessions/LobbyClient.cpp | 2 +- .../DanBiasServer/LobbySessions/MainLobby.h | 2 +- Code/Game/GameLogic/DynamicObject.h | 4 +- Code/Game/GameLogic/Object.h | 3 +- Code/Game/GameProtocols/ControlProtocols.h | 1 + Code/Game/GameProtocols/GameProtocols.vcxproj | 3 +- Code/Game/GameProtocols/GameplayProtocols.h | 63 +++++++++++++++++++ .../GameProtocols/ProtocolIdentificationID.h | 10 +-- .../{GameProtocols.h => Protocols.h} | 1 + 16 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 Code/Game/GameProtocols/GameplayProtocols.h rename Code/Game/GameProtocols/{GameProtocols.h => Protocols.h} (88%) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 4c0cc060..0a16e8f4 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -5,7 +5,7 @@ #include "GameClientState/GameClientState.h" #include "GameClientState\GameState.h" #include "GameClientState\LobbyState.h" -#include +#include #include "NetworkClient.h" #include "../WindowManager/WindowShell.h" diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index a93a8e91..3426bce8 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -2,7 +2,7 @@ #include "DllInterfaces/GFXAPI.h" #include "C_obj/C_Player.h" #include "C_obj/C_DynamicObj.h" -#include +#include #include "NetworkClient.h" diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.cpp b/Code/Game/DanBiasServer/GameSession/GameClient.cpp index a856a751..dd62c44a 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameClient.cpp @@ -5,7 +5,7 @@ #include "GameClient.h" #include "..\LobbySessions\NetworkSession.h" #include -#include +#include using namespace Utility::DynamicMemory; using namespace DanBias; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index b8906867..0016de8a 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -4,7 +4,7 @@ #include "GameSession.h" #include "GameClient.h" -#include +#include #include #include #include @@ -64,16 +64,16 @@ namespace DanBias } break; case protocol_Gameplay_PlayerMouseMovement: - + break; case protocol_Gameplay_PlayerPosition: - + break; case protocol_Gameplay_CreateObject: - + break; case protocol_Gameplay_ObjectPosition: - + break; } } diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp index e0ba12ee..07f97cff 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp @@ -4,7 +4,7 @@ #include "GameSession.h" #include "GameClient.h" #include "..\GameServer.h" -#include +#include #include #include diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp index ab1bcdf5..eb1cf0ca 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp @@ -4,7 +4,7 @@ #include "GameSession.h" #include "GameClient.h" -#include +#include #include #include #include diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp index f23ab118..729ef417 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Network.cpp @@ -4,7 +4,7 @@ #include "GameSession.h" #include "GameClient.h" -#include +#include #include #include #include diff --git a/Code/Game/DanBiasServer/LobbySessions/LobbyClient.cpp b/Code/Game/DanBiasServer/LobbySessions/LobbyClient.cpp index af29410d..95f18e68 100644 --- a/Code/Game/DanBiasServer/LobbySessions/LobbyClient.cpp +++ b/Code/Game/DanBiasServer/LobbySessions/LobbyClient.cpp @@ -1,5 +1,5 @@ #include "LobbyClient.h" -#include +#include using namespace Utility::DynamicMemory; using namespace Oyster::Network; diff --git a/Code/Game/DanBiasServer/LobbySessions/MainLobby.h b/Code/Game/DanBiasServer/LobbySessions/MainLobby.h index 88ae4067..a28d90e9 100644 --- a/Code/Game/DanBiasServer/LobbySessions/MainLobby.h +++ b/Code/Game/DanBiasServer/LobbySessions/MainLobby.h @@ -6,7 +6,7 @@ #include "NetworkSession.h" #include "GameLobby.h" -#include +#include #include namespace DanBias diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 6a2263c9..70b5efe7 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -9,9 +9,7 @@ namespace GameLogic { - - - class DANBIAS_GAMELOGIC_DLL DynamicObject : public Object + class DynamicObject : public Object { public: diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 6d6437f1..c3519f73 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -8,12 +8,11 @@ #include "GameLogicStates.h" -#include "GameLogicDef.h" #include namespace GameLogic { - class DANBIAS_GAMELOGIC_DLL Object + class Object { public: Object(); diff --git a/Code/Game/GameProtocols/ControlProtocols.h b/Code/Game/GameProtocols/ControlProtocols.h index cdb30df9..46268b75 100644 --- a/Code/Game/GameProtocols/ControlProtocols.h +++ b/Code/Game/GameProtocols/ControlProtocols.h @@ -13,6 +13,7 @@ namespace GameLogic States_ready, States_idle, States_bussy, + State_waiting, States_disconected, }; States status; diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index d4d5fb7a..e01959b8 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -155,7 +155,8 @@ - + + diff --git a/Code/Game/GameProtocols/GameplayProtocols.h b/Code/Game/GameProtocols/GameplayProtocols.h new file mode 100644 index 00000000..b595ce36 --- /dev/null +++ b/Code/Game/GameProtocols/GameplayProtocols.h @@ -0,0 +1,63 @@ +#ifndef GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H +#define GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H + +#include +#include +#include "ProtocolIdentificationID.h" + +namespace GameLogic +{ + struct Protocol_GameplayInitiateSession :public Oyster::Network::CustomProtocolObject + { + struct SessionInitData + { + int id; + int type; + //std::string text; + }; + std::vector element; + + Protocol_GameplayInitiateSession() + { + this->protocol[protocol_INDEX_ID].value = protocol_Gameplay_Initiate; + this->protocol[protocol_INDEX_ID].type = Oyster::Network::NetAttributeType_Short; + } + Protocol_GameplayInitiateSession(Oyster::Network::CustomNetProtocol& p) + { + int size = p[1].value.netInt; + for (int i = 0; i < size; i++) + { + SessionInitData d = { p[i+2].value.netInt, p[i+3].value.netInt /*, p[i+4].value.netCharPtr */ }; + element.push_back(d); + } + } + void Add(int id, int type, std::string text) + { + SessionInitData d = { id, type /*, text*/ }; + element.push_back(d); + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + //Store the elements count + this->protocol[1].value = element.size(); + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + + for (unsigned int i = 0; i < element.size(); i+=3) + { + this->protocol[i+2].value = element[i].id; + this->protocol[i+3].value = element[i].type; + //element[i].text.copy(this->protocol[i+4].value.netCharPtr, element[i].text.size()); + + this->protocol[i+2].type = Oyster::Network::NetAttributeType_Int; + this->protocol[i+3].type = Oyster::Network::NetAttributeType_Int; + //this->protocol[i+4].type = Oyster::Network::NetAttributeType_CharArray; + } + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; +} + +#endif // !GAMEPROTOCOLS_GAMEPLAYPROTOCOLS_H diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index d99b7e65..fb54e403 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -22,7 +22,7 @@ /***********************************/ /********* GENERAL PROTOCOLS ***************************************************************************************************/ /***********[ 100 - 200 ]***********/ -#define protocol_GeneralMIN 100 /* This defines lower bounds of general protocols (okay to have same value on first element). */ +#define protocol_GeneralMIN 100 #define protocol_General_Status 100 #define protocol_General_Text 101 #define protocol_GeneralMAX 199 @@ -51,6 +51,7 @@ #define protocol_Gameplay_CreateObject 303 #define protocol_Gameplay_RemoveObject 304 #define protocol_Gameplay_ObjectPosition 305 +#define protocol_Gameplay_Initiate 306 #define protocol_GameplayMAX 399 @@ -61,11 +62,4 @@ inline bool ProtocolIsLobby(short ID) { return (ID >= protocol_LobbyMIN && ID <= inline bool ProtocolIsGeneral(short ID) { return (ID >= protocol_GeneralMIN && ID <= protocol_GeneralMAX); } inline bool ProtocolIsGameplay(short ID) { return (ID >= protocol_GameplayMIN && ID <= protocol_GameplayMAX); } - - -/***********************************/ -/*********** TEST PROTOCOLS *******************************************************************************************************/ -/***********[ x - x ]************/ - - #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H diff --git a/Code/Game/GameProtocols/GameProtocols.h b/Code/Game/GameProtocols/Protocols.h similarity index 88% rename from Code/Game/GameProtocols/GameProtocols.h rename to Code/Game/GameProtocols/Protocols.h index 4c52e716..6e084b75 100644 --- a/Code/Game/GameProtocols/GameProtocols.h +++ b/Code/Game/GameProtocols/Protocols.h @@ -5,5 +5,6 @@ #include "PlayerProtocols.h" #include "LobbyProtocols.h" #include "ControlProtocols.h" +#include "GameplayProtocols.h" #endif // !GAMEPROTOCOLS_GAMEPROTOCOLS_H From 82de85d1accaa147ee2550c7f5c9388f949d4e5a Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 14 Jan 2014 10:15:50 +0100 Subject: [PATCH 21/42] Fixed minor server network bug, modified shader to get visual --- Code/Game/DanBiasServer/GameSession/GameClient.cpp | 6 ------ .../Game/DanBiasServer/GameSession/GameSession_General.cpp | 7 +++++-- Code/Network/NetworkDependencies/Connection.cpp | 6 ++++++ .../Shader/HLSL/Deffered Shaders/PostPass.hlsl | 4 ++-- Code/WindowManager/WindowShell.h | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.cpp b/Code/Game/DanBiasServer/GameSession/GameClient.cpp index dd62c44a..da666881 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameClient.cpp @@ -17,7 +17,6 @@ GameClient::GameClient(SmartPointer client, Game::PlayerData player { this->callbackValue = value; this->client = client; - //this->player = new GameLogic::Player(); this->id = gameClientIDCount++; this->player = player; Oyster::Callback::OysterCallback c; @@ -32,7 +31,6 @@ GameClient::~GameClient() this->player.playerID = 0; this->player.teamID = 0; this->id = -1; - //this->player.Release(); } void GameClient::SetCallback(Oyster::Callback::OysterCallback value) @@ -40,10 +38,6 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallbackcallbackValue = value; } -//GameLogic::Player* GameClient::GetPlayer() -//{ -// return this->player.Get(); -//} GameLogic::Game::PlayerData* GameClient::GetPlayer() { return &this->player; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp index 07f97cff..d6db176e 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp @@ -145,8 +145,11 @@ namespace DanBias { for (int i = 0; i < this->clients.Size(); i++) { - s->Attach(this->clients[i]->ReleaseClient()); - RemoveClient(this->clients[i]); + if(this->clients[i]) + { + s->Attach(this->clients[i]->ReleaseClient()); + RemoveClient(this->clients[i]); + } } } } diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 7d6daca6..bd289c63 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -108,6 +108,7 @@ int Connection::InitiateClient() int Connection::Disconnect() { + if(this->closed) return -1; int val = CloseSocket(this->socket); this->socket = -1; this->closed = true; @@ -117,6 +118,8 @@ int Connection::Disconnect() int Connection::Send(OysterByte &bytes) { + if(this->closed) return -1; + int nBytes; nBytes = send(this->socket, bytes, bytes.GetSize(), 0); @@ -130,6 +133,7 @@ int Connection::Send(OysterByte &bytes) int Connection::Recieve(OysterByte &bytes) { + if(this->closed) return -1; int nBytes; bytes.Resize(1000); @@ -150,6 +154,8 @@ int Connection::Recieve(OysterByte &bytes) //Listen will only return the correct socket or -1 for failure. int Connection::Listen() { + if(this->closed) return -1; + int clientSocket; if((clientSocket = (int)accept(this->socket, NULL, NULL)) == INVALID_SOCKET) { diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl index 1c52e5bf..2aaf2051 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl @@ -7,6 +7,6 @@ RWTexture2D Output; [numthreads(16, 16, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { - //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW - Output[DTid.xy] = Diffuse[DTid.xy]; + Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW + //Output[DTid.xy] = Diffuse[DTid.xy]; } \ No newline at end of file diff --git a/Code/WindowManager/WindowShell.h b/Code/WindowManager/WindowShell.h index d4004be2..86726ccf 100644 --- a/Code/WindowManager/WindowShell.h +++ b/Code/WindowManager/WindowShell.h @@ -32,7 +32,7 @@ public: { parent = 0; hInstance = NULL; - windowName = L"おはよう"; + windowName = L"Window"; windowSize.x = 800; windowSize.y = 600; windowPosition.x = 0; From 32e64c0dbbeae9717d4a1538da19cd9d3438c9a3 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 14 Jan 2014 10:25:49 +0100 Subject: [PATCH 22/42] GL - moved reciever struct to a separate file --- Code/Game/DanBiasGame/DanBiasGame.vcxproj | 1 + Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 105 +--------------- .../Game/DanBiasGame/GameClientRecieverFunc.h | 113 ++++++++++++++++++ .../HLSL/Deffered Shaders/PostPass.hlsl | 4 +- 4 files changed, 119 insertions(+), 104 deletions(-) create mode 100644 Code/Game/DanBiasGame/GameClientRecieverFunc.h diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 740f9a51..0e856428 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -204,6 +204,7 @@ + diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index cd3783ff..6bd3f865 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -12,112 +12,13 @@ #include "L_inputClass.h" #include "WinTimer.h" #include "vld.h" +#include "GameClientRecieverFunc.h" namespace DanBias { #pragma region Game Data - - struct MyRecieverObject :public Oyster::Network::ProtocolRecieverObject - { - Oyster::Network::NetworkClient* nwClient; - Client::GameClientState* gameClientState; - - - void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override - { - int pType = p[0].value.netInt; - switch (pType) - { - case protocol_General_Status: - { - GameLogic::Protocol_General_Status::States state; - state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort; - - } - break; - case protocol_Gameplay_PlayerNavigation: - { - Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; - for(int i = 0; i< 6; i++) - { - protocolData->key[i] = p[i+1].value.netBool; - } - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - delete protocolData; - protocolData = NULL; - } - break; - case protocol_Gameplay_PlayerPosition: - { - Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; - for(int i = 0; i< 3; i++) - { - protocolData->playerPos[i] = p[i].value.netFloat; - } - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - delete protocolData; - protocolData = NULL; - } - break; - - case protocol_Gameplay_CreateObject: - { - - Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; - protocolData->object_ID = p[1].value.netInt; - protocolData->path = p[2].value.netCharPtr; - for(int i = 0; i< 16; i++) - { - protocolData->worldPos[i] = p[i+3].value.netFloat; - } - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - - delete protocolData; - protocolData = NULL; - } - break; - case protocol_Gameplay_RemoveObject: - { - Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj; - protocolData->object_ID = p[1].value.netInt; - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - - delete protocolData; - protocolData = NULL; - } - break; - case protocol_Gameplay_ObjectPosition: - { - - Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; - protocolData->object_ID = p[1].value.netInt; - for(int i = 0; i< 16; i++) - { - protocolData->worldPos[i] = p[i+2].value.netFloat; - } - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - - delete protocolData; - protocolData = NULL; - } - break; - - default: - break; - } - } - }; class DanBiasGamePrivateData { @@ -135,7 +36,7 @@ namespace DanBias WindowShell* window; InputClass* inputObj; Utility::WinTimer* timer; - MyRecieverObject* recieverObj; + GameRecieverObject* recieverObj; } data; #pragma endregion @@ -159,7 +60,7 @@ namespace DanBias if( FAILED( InitInput() ) ) return DanBiasClientReturn_Error; - m_data->recieverObj = new MyRecieverObject; + m_data->recieverObj = new GameRecieverObject; m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient(m_data->recieverObj, Oyster::Network::NetworkProtocolCallbackType_Object); m_data->recieverObj->nwClient->Connect(desc.port, desc.IP); diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h new file mode 100644 index 00000000..0a42d33a --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -0,0 +1,113 @@ +#ifndef DANBIAS_CLIENTRECIEVEROBJECT_H +#define DANBIAS_CLIENTRECIEVEROBJECT_H + +namespace DanBias +{ +struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject +{ + Oyster::Network::NetworkClient* nwClient; + Client::GameClientState* gameClientState; + + // receiver function for server messages + // parsing protocols and sending it to the gameState + void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override + { + int pType = p[0].value.netInt; + switch (pType) + { + case protocol_General_Status: + { + GameLogic::Protocol_General_Status::States state; + state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort; + if( state == GameLogic::Protocol_General_Status::States_disconected) + { + // server disconnected + DanBiasGame::Release(); + } + } + break; + case protocol_Gameplay_PlayerNavigation: + { + Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; + for(int i = 0; i< 6; i++) + { + protocolData->key[i] = p[i+1].value.netBool; + } + + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + delete protocolData; + protocolData = NULL; + } + break; + case protocol_Gameplay_PlayerPosition: + { + Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; + for(int i = 0; i< 3; i++) + { + protocolData->playerPos[i] = p[i].value.netFloat; + } + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + delete protocolData; + protocolData = NULL; + } + break; + + case protocol_Gameplay_CreateObject: + { + + Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; + protocolData->object_ID = p[1].value.netInt; + protocolData->path = p[2].value.netCharPtr; + for(int i = 0; i< 16; i++) + { + protocolData->worldPos[i] = p[i+3].value.netFloat; + } + + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + + delete p[2].value.netCharPtr; //delete char array + delete protocolData; + protocolData = NULL; + } + break; + case protocol_Gameplay_RemoveObject: + { + Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj; + protocolData->object_ID = p[1].value.netInt; + + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + + delete protocolData; + protocolData = NULL; + } + break; + case protocol_Gameplay_ObjectPosition: + { + + Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; + protocolData->object_ID = p[1].value.netInt; + for(int i = 0; i< 16; i++) + { + protocolData->worldPos[i] = p[i+2].value.netFloat; + } + + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + + delete protocolData; + protocolData = NULL; + } + break; + + default: + break; + } + + } +}; +} +#endif \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl index 1c52e5bf..2aaf2051 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl @@ -7,6 +7,6 @@ RWTexture2D Output; [numthreads(16, 16, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { - //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW - Output[DTid.xy] = Diffuse[DTid.xy]; + Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW + //Output[DTid.xy] = Diffuse[DTid.xy]; } \ No newline at end of file From 54240b217c4807d8fec10c2a64d7676d9eb87fe2 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 14 Jan 2014 10:28:12 +0100 Subject: [PATCH 23/42] GameLogic - game interface updated(not finnished) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit förlåt dennis --- Code/Game/GameLogic/AttatchmentSocket.cpp | 22 +++++-------- Code/Game/GameLogic/Game.cpp | 18 +++++----- Code/Game/GameLogic/Game.h | 40 +++++++++++++---------- Code/Game/GameLogic/Game_PlayerData.cpp | 14 ++++++++ Code/Game/GameLogic/Level.cpp | 17 +++++----- Code/Game/GameLogic/Weapon.cpp | 26 ++++----------- 6 files changed, 70 insertions(+), 67 deletions(-) create mode 100644 Code/Game/GameLogic/Game_PlayerData.cpp diff --git a/Code/Game/GameLogic/AttatchmentSocket.cpp b/Code/Game/GameLogic/AttatchmentSocket.cpp index 5d997a45..a3d9097c 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.cpp +++ b/Code/Game/GameLogic/AttatchmentSocket.cpp @@ -1,6 +1,9 @@ #include "AttatchmentSocket.h" #include "IAttatchment.h" +#include "DynamicArray.h" + using namespace GameLogic; +using namespace Utility::DynamicMemory; struct AttatchmentSocket::PrivateData { @@ -14,7 +17,7 @@ struct AttatchmentSocket::PrivateData } - IAttatchment *attatchment; + SmartPointer attatchment; }myData; @@ -26,10 +29,7 @@ AttatchmentSocket::AttatchmentSocket(void) AttatchmentSocket::~AttatchmentSocket(void) { - if (myData->attatchment) - { - delete myData->attatchment; - } + } IAttatchment* AttatchmentSocket::GetAttatchment() @@ -39,18 +39,12 @@ IAttatchment* AttatchmentSocket::GetAttatchment() void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment) { - if (myData->attatchment) - { - delete myData->attatchment; - } - myData->attatchment = attatchment; } void AttatchmentSocket::RemoveAttatchment() { - if (myData->attatchment) - { - delete myData->attatchment; - } + + myData->attatchment = 0; + } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 806ac6d2..e2879e10 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -1,8 +1,10 @@ #include "Game.h" #include "Player.h" #include "Level.h" +#include using namespace GameLogic; +using namespace Utility::DynamicMemory; struct Game::PrivateData { @@ -15,9 +17,9 @@ struct Game::PrivateData { } - - Player **players; - Level *level; + //DynamicArray> players; + DynamicArray> players; + SmartPointer level; }myData; @@ -35,14 +37,10 @@ Game::~Game(void) } } -void Game::MovePlayer(int playerID, const PLAYER_MOVEMENT &movement) -{ - -} void Game::PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage) { - + } void Game::GetPlayerPos(int playerID) @@ -57,7 +55,9 @@ void Game::GetAllPlayerPos() Game::PlayerData Game::CreatePlayer() { - + SmartPointer newPlayer = new Player(); + + myData->players.Push(newPlayer); } void Game::CreateTeam() diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index a70dc842..dc3c898f 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -4,44 +4,50 @@ #include "GameLogicStates.h" namespace GameLogic { + class Player; class Game { public: struct PlayerData { + private: + friend class Game; + Player *player; + + + public: + int playerID; int teamID; - PlayerData() - { - playerID = 0; - teamID = 0; - } - PlayerData(int playerID,int teamID) - { - this->playerID = playerID; - this->teamID = teamID; - - } + PlayerData(); + + PlayerData(int playerID,int teamID); + ~PlayerData() { } + + /******************************************************** + * Moves the chosen player based on input + * @param playerID: ID of the player you want to recieve the message + * @param movement: enum value on what kind of action is to be taken + ********************************************************/ + void MovePlayer(const PLAYER_MOVEMENT &movement); + + }; public: Game(void); ~Game(void); - /******************************************************** - * Moves the chosen player based on input - * @param playerID: ID of the player you want to recieve the message - * @param movement: enum value on what kind of action is to be taken - ********************************************************/ - void MovePlayer(int playerID, const PLAYER_MOVEMENT &movement); + + /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp new file mode 100644 index 00000000..258c164c --- /dev/null +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -0,0 +1,14 @@ +#include "Game.h" +#include "Player.h" + +using namespace GameLogic; + +Game::PlayerData::PlayerData() +{ + +} + +void Game::PlayerData::MovePlayer(const PLAYER_MOVEMENT &movement) +{ + +} diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 9f4416aa..9b3c90ff 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -5,8 +5,11 @@ #include "Player.h" #include "PhysicsAPI.h" #include "TeamManager.h" +#include "DynamicArray.h" using namespace GameLogic; +using namespace Utility::DynamicMemory; + struct Level::PrivateData { @@ -18,17 +21,15 @@ struct Level::PrivateData { } - TeamManager *teamManager; + SmartPointer teamManager; - StaticObject** staticObjects; - int nrOfStaticObjects; + DynamicArray> staticObjects; + + DynamicArray> dynamicObjects; - DynamicObject** dynamicObjects; - int nrOfDynamicObjects; + SmartPointer gameMode; - GameMode* gameMode; - - Oyster::Physics::ICustomBody *rigidBodyLevel; + SmartPointer rigidBodyLevel; }myData; diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 7f4b3308..6ac989c5 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -1,8 +1,10 @@ #include "Weapon.h" #include "AttatchmentSocket.h" #include "AttatchmentMassDriver.h" +#include "DynamicArray.h" using namespace GameLogic; +using namespace Utility::DynamicMemory; struct Weapon::PrivateData { @@ -12,7 +14,6 @@ struct Weapon::PrivateData selectedAttatchment = 0; currentNrOfAttatchments = 0; selectedSocketID = 0; - maxNrOfSockets = 0; attatchmentSockets = 0; } @@ -22,11 +23,9 @@ struct Weapon::PrivateData WEAPON_STATE weaponState; - AttatchmentSocket **attatchmentSockets; - int maxNrOfSockets; + DynamicArray> attatchmentSockets; int currentNrOfAttatchments; - - IAttatchment *selectedAttatchment; + SmartPointer selectedAttatchment; int selectedSocketID; }myData; @@ -39,23 +38,12 @@ Weapon::Weapon() Weapon::Weapon(int MaxNrOfSockets) { myData = new PrivateData(); - myData->maxNrOfSockets = MaxNrOfSockets; - myData->attatchmentSockets = new AttatchmentSocket*[MaxNrOfSockets]; - for (int i = 0; i < MaxNrOfSockets; i++) - { - myData->attatchmentSockets[i] = new AttatchmentSocket(); - } + myData->attatchmentSockets.Resize(MaxNrOfSockets); } Weapon::~Weapon(void) { - for (int i = 0; i < myData->currentNrOfAttatchments; i++) - { - delete myData->attatchmentSockets[i]; - } - delete[] myData->attatchmentSockets; - delete myData; } @@ -95,7 +83,7 @@ bool Weapon::IsReloading() bool Weapon::IsValidSocket(int socketID) { - if(socketID < myData->maxNrOfSockets && socketID >= 0) + if(socketID < myData->attatchmentSockets.Size() && socketID >= 0) { if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) { @@ -114,7 +102,7 @@ int Weapon::GetCurrentSocketID() void Weapon::AddNewAttatchment(IAttatchment *attatchment, Player *owner) { - if(myData->currentNrOfAttatchments < myData->maxNrOfSockets) + if(myData->currentNrOfAttatchments < myData->attatchmentSockets.Size()) { myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); myData->currentNrOfAttatchments++; From 01e7614a5cd04153b0a737d49065b736ac9a772b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 10:34:22 +0100 Subject: [PATCH 24/42] Tangiential formula fixes --- Code/GamePhysics/PhysicsStructs-Impl.h | 20 ++++++++------------ Code/OysterPhysics3D/OysterPhysics3D.h | 8 ++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 9b13cacf..c74c6537 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -2,6 +2,7 @@ #define PHYSICS_STRUCTS_IMPL_H #include "PhysicsStructs.h" +#include "OysterPhysics3D.h" namespace Oyster { @@ -146,10 +147,7 @@ namespace Oyster inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const { - //return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos ); // C3083 error? - - ::Oyster::Math::Float4 offset = at - this->centerPos; - return this->linearMomentum + ( ::Oyster::Math::Float4(this->angularMomentum.xyz.Cross(offset.xyz), 0.0f) /= offset.Dot(offset) ); + return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos ); } inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularMomentum() const @@ -214,11 +212,9 @@ namespace Oyster if( tensor.GetDeterminant() != 0.0f ) { // sanity block! ::Oyster::Math::Float4x4 rotation = ::Oyster::Math3D::RotationMatrix(this->angularAxis.xyz); - //::Oyster::Math::Float4 w = ::Oyster::Physics3D::Formula::AngularVelocity( (rotation * this->inertiaTensor).GetInverse(), this->angularMomentum ); // C3083 error? - ::Oyster::Math::Float4 w = (rotation * this->inertiaTensor).GetInverse() * this->angularMomentum; + ::Oyster::Math::Float4 w = ::Oyster::Physics3D::Formula::AngularVelocity( (rotation * this->inertiaTensor).GetInverse(), this->angularMomentum ); this->inertiaTensor = tensor; - //this->angularMomentum = ::Oyster::Physics3D::Formula::AngularMomentum( rotation * tensor, w ); // C3083 error? - this->angularMomentum = rotation * tensor * w; + this->angularMomentum = ::Oyster::Physics3D::Formula::AngularMomentum( rotation * tensor, w ); } } @@ -307,10 +303,10 @@ namespace Oyster inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal ) { - //::Oyster::Math::Float4 tangentialImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, at - this->centerPos ); // C3083 error? - ::Oyster::Math::Float4 tangentialImpulse = ::Oyster::Math::Float4( (at - this->centerPos).xyz.Cross(j.xyz), 0.0f ); - this->linearImpulse += j - tangentialImpulse; - this->angularImpulse += tangentialImpulse; + ::Oyster::Math::Float4 offset = at - this->centerPos; + ::Oyster::Math::Float4 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset ); + this->linearImpulse += j - ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset ); + this->angularImpulse += deltaAngularImpulse; this->isDisturbed = true; } diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index 84058387..970d739e 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -126,7 +126,7 @@ namespace Oyster { namespace Physics3D ******************************************************************/ inline ::Oyster::Math::Float3 TangentialLinearMomentum( const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &worldOffset ) { - return angularMomentum.Cross( worldOffset ); + return angularMomentum.Cross( worldOffset ) /= worldOffset.Dot( worldOffset ); } /****************************************************************** @@ -135,7 +135,7 @@ namespace Oyster { namespace Physics3D ******************************************************************/ inline ::Oyster::Math::Float3 TangentialLinearMomentum( const ::Oyster::Math::Float4x4 &momentOfInertia, const ::Oyster::Math::Float3 &angularVelocity, const ::Oyster::Math::Float3 &worldOffset ) { - return TangentialLinearMomentum( AngularMomentum(momentOfInertia, angularVelocity), worldOffset ); + return TangentialLinearMomentum( AngularMomentum(momentOfInertia, angularVelocity), worldOffset ) /= worldOffset.Dot( worldOffset ); } /****************************************************************** @@ -144,7 +144,7 @@ namespace Oyster { namespace Physics3D ******************************************************************/ inline ::Oyster::Math::Float3 TangentialImpulseForce( const ::Oyster::Math::Float3 &impulseTorque, const ::Oyster::Math::Float3 &worldOffset ) { - return impulseTorque.Cross( worldOffset ); + return impulseTorque.Cross( worldOffset ) /= worldOffset.Dot( worldOffset ); } /****************************************************************** @@ -207,7 +207,7 @@ namespace Oyster { namespace Physics3D ******************************************************************/ inline ::Oyster::Math::Float3 TangentialLinearVelocity( const ::Oyster::Math::Float3 &angularVelocity, const ::Oyster::Math::Float3 &worldOffset ) { - return angularVelocity.Cross( worldOffset ); + return angularVelocity.Cross( worldOffset ) /= worldOffset.Dot( worldOffset ); } /****************************************************************** From 23dab9dea6627e11aca6e96c73f65569e92ecb83 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 11:32:02 +0100 Subject: [PATCH 25/42] Inertia tensor fix should produce radian anglevelocities --- Code/OysterPhysics3D/OysterPhysics3D.h | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index 970d739e..16d0e158 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -278,7 +278,7 @@ namespace Oyster { namespace Physics3D /** @todo TODO: add MomentOfInertia tensor formulas */ inline ::Oyster::Math::Float CalculateSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) { - return (2.0f/5.0f)*mass*radius*radius; + return ::Utility::Value::Radian( 2.0f / 5.0f ) * mass * radius * radius; } inline ::Oyster::Math::Float4x4 Sphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) @@ -293,7 +293,7 @@ namespace Oyster { namespace Physics3D inline ::Oyster::Math::Float CalculateHollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) { - return (2.0f/3.0f)*mass*radius*radius; + return ::Utility::Value::Radian( 2.0f / 3.0f ) * mass * radius * radius; } inline ::Oyster::Math::Float4x4 HollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) @@ -308,38 +308,38 @@ namespace Oyster { namespace Physics3D inline ::Oyster::Math::Float CalculateCuboidX( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float depth ) { - return (1.0f/12.0f)*mass*(height*height + depth*depth); + return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * (height * height + depth * depth); } inline ::Oyster::Math::Float CalculateCuboidY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth ) { - return (1.0f/12.0f)*mass*(width*width + depth*depth); + return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * (width * width + depth * depth ); } inline ::Oyster::Math::Float CalculateCuboidZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float height ) { - return (1.0f/12.0f)*mass*(height*height + width*width); + return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * (height * height + width * width ); } inline ::Oyster::Math::Float4x4 Cuboid( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth ) { ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity; - inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidX( mass , height, depth ); - inertia.m[1][1] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidY( mass , width, depth ); - inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidZ( mass , height, width ); + inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidX( mass, height, depth ); + inertia.m[1][1] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidY( mass, width, depth ); + inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidZ( mass, height, width ); return inertia; } inline ::Oyster::Math::Float CalculateRodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length ) { - return (1.0f/12.0f)*mass*(length*length); + return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * length * length; } inline ::Oyster::Math::Float4x4 RodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length ) { ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity; - inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateRodCenter( mass , length ); + inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateRodCenter( mass, length ); inertia.m[1][1] = inertia.m[0][0]; inertia.m[2][2] = inertia.m[0][0]; @@ -348,20 +348,20 @@ namespace Oyster { namespace Physics3D inline ::Oyster::Math::Float CalculateCylinderXY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius ) { - return (1.0f/12.0f)*mass*(3.0f*radius*radius + height*height); + return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * ( 3.0f * radius * radius + height * height ); } inline ::Oyster::Math::Float CalculateCylinderZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) { - return 0.5f*mass*(radius*radius); + return ::Utility::Value::Radian( 0.5f ) * mass * ( radius * radius ); } inline ::Oyster::Math::Float4x4 Cylinder( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius ) { ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity; - inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderXY( mass , height, radius ); + inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderXY( mass, height, radius ); inertia.m[1][1] = inertia.m[0][0]; - inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderZ( mass , radius ); + inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderZ( mass, radius ); return inertia; } From 89ef3b830a2b7f0851e52d540c3993137990fb6d Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 11:40:47 +0100 Subject: [PATCH 26/42] Revert "Inertia tensor fix" This reverts commit 23dab9dea6627e11aca6e96c73f65569e92ecb83. --- Code/OysterPhysics3D/OysterPhysics3D.h | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index 16d0e158..970d739e 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -278,7 +278,7 @@ namespace Oyster { namespace Physics3D /** @todo TODO: add MomentOfInertia tensor formulas */ inline ::Oyster::Math::Float CalculateSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) { - return ::Utility::Value::Radian( 2.0f / 5.0f ) * mass * radius * radius; + return (2.0f/5.0f)*mass*radius*radius; } inline ::Oyster::Math::Float4x4 Sphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) @@ -293,7 +293,7 @@ namespace Oyster { namespace Physics3D inline ::Oyster::Math::Float CalculateHollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) { - return ::Utility::Value::Radian( 2.0f / 3.0f ) * mass * radius * radius; + return (2.0f/3.0f)*mass*radius*radius; } inline ::Oyster::Math::Float4x4 HollowSphere( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) @@ -308,38 +308,38 @@ namespace Oyster { namespace Physics3D inline ::Oyster::Math::Float CalculateCuboidX( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float depth ) { - return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * (height * height + depth * depth); + return (1.0f/12.0f)*mass*(height*height + depth*depth); } inline ::Oyster::Math::Float CalculateCuboidY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth ) { - return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * (width * width + depth * depth ); + return (1.0f/12.0f)*mass*(width*width + depth*depth); } inline ::Oyster::Math::Float CalculateCuboidZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float width, const ::Oyster::Math::Float height ) { - return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * (height * height + width * width ); + return (1.0f/12.0f)*mass*(height*height + width*width); } inline ::Oyster::Math::Float4x4 Cuboid( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth ) { ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity; - inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidX( mass, height, depth ); - inertia.m[1][1] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidY( mass, width, depth ); - inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidZ( mass, height, width ); + inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidX( mass , height, depth ); + inertia.m[1][1] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidY( mass , width, depth ); + inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCuboidZ( mass , height, width ); return inertia; } inline ::Oyster::Math::Float CalculateRodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length ) { - return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * length * length; + return (1.0f/12.0f)*mass*(length*length); } inline ::Oyster::Math::Float4x4 RodCenter( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length ) { ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity; - inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateRodCenter( mass, length ); + inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateRodCenter( mass , length ); inertia.m[1][1] = inertia.m[0][0]; inertia.m[2][2] = inertia.m[0][0]; @@ -348,20 +348,20 @@ namespace Oyster { namespace Physics3D inline ::Oyster::Math::Float CalculateCylinderXY( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius ) { - return ::Utility::Value::Radian( 1.0f / 12.0f ) * mass * ( 3.0f * radius * radius + height * height ); + return (1.0f/12.0f)*mass*(3.0f*radius*radius + height*height); } inline ::Oyster::Math::Float CalculateCylinderZ( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius ) { - return ::Utility::Value::Radian( 0.5f ) * mass * ( radius * radius ); + return 0.5f*mass*(radius*radius); } inline ::Oyster::Math::Float4x4 Cylinder( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius ) { ::Oyster::Math::Float4x4 inertia = ::Oyster::Math::Float4x4::identity; - inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderXY( mass, height, radius ); + inertia.m[0][0] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderXY( mass , height, radius ); inertia.m[1][1] = inertia.m[0][0]; - inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderZ( mass, radius ); + inertia.m[2][2] = ::Oyster::Physics3D::Formula::MomentOfInertia::CalculateCylinderZ( mass , radius ); return inertia; } From 8f630125b4ba318699fac37346382478a8b1a295 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 14 Jan 2014 11:42:54 +0100 Subject: [PATCH 27/42] AngularVelocity fix --- Code/OysterPhysics3D/RigidBody.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 3ae48511..6fef6311 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -58,7 +58,7 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) Float4x4 wMomentOfInertiaTensor = TransformMatrix( rotationMatrix, this->momentOfInertiaTensor ); // RI // dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H - this->axis += Formula::AngularVelocity( wMomentOfInertiaTensor.GetInverse(), AverageWithDelta(this->momentum_Angular, this->impulse_Angular) ); + this->axis += Radian( Formula::AngularVelocity(wMomentOfInertiaTensor.GetInverse(), AverageWithDelta(this->momentum_Angular, this->impulse_Angular)) ); this->rotation = Rotation( this->axis ); // update momentums and clear impulse_Linear and impulse_Angular From 8c7a17ff8f8189a03d0282e00f82eaadc4e7800d Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 14 Jan 2014 11:58:53 +0100 Subject: [PATCH 28/42] Added missing mass and inertia --- Code/GamePhysics/Implementation/SimpleRigidBody.cpp | 2 ++ Code/GamePhysics/Implementation/SphericalRigidBody.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 09855984..49fa292f 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -113,6 +113,8 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) this->rigid.restitutionCoeff = state.GetRestitutionCoeff(); this->rigid.frictionCoeff_Static = state.GetFrictionCoeff_Static(); this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic(); + this->rigid.SetMass_KeepMomentum( state.GetMass() ); + this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() ); if( state.IsForwarded() ) { diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 95901763..2d96412c 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -83,6 +83,8 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) this->rigid.restitutionCoeff = state.GetRestitutionCoeff(); this->rigid.frictionCoeff_Static = state.GetFrictionCoeff_Static(); this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic(); + this->rigid.SetMass_KeepMomentum( state.GetMass() ); + this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() ); if( state.IsForwarded() ) { From e9ad87507f9405dfc56b07d9c44a37bdce7fdd81 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 15 Jan 2014 09:06:57 +0100 Subject: [PATCH 29/42] Obsolete code removed More commentated out than deleted actually --- .../GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 1115e7e9..b3abf32c 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -86,14 +86,14 @@ namespace //sumJ += ( 1 / deuterState.GetMass() )*frictionImpulse; // FRICTION END - Float4 forwardedDeltaPos, forwardedDeltaAxis; - { // @todo TODO: is this right? - Float4 bounceAngularImpulse = ::Oyster::Math::Float4( (worldPointOfContact - protoState.GetCenterPosition()).xyz.Cross(bounce.xyz), 0.0f ), - bounceLinearImpulse = bounce - bounceAngularImpulse; - proto->Predict( forwardedDeltaPos, forwardedDeltaAxis, bounceLinearImpulse, bounceAngularImpulse, API_instance.GetFrameTimeLength() ); - } +// Float4 forwardedDeltaPos, forwardedDeltaAxis; +// { // @todo TODO: is this right? +// Float4 bounceAngularImpulse = ::Oyster::Math::Float4( (worldPointOfContact - protoState.GetCenterPosition()).xyz.Cross(bounce.xyz), 0.0f ), +// bounceLinearImpulse = bounce - bounceAngularImpulse; +// proto->Predict( forwardedDeltaPos, forwardedDeltaAxis, bounceLinearImpulse, bounceAngularImpulse, API_instance.GetFrameTimeLength() ); +// } - protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis ); +// protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis ); protoState.ApplyImpulse( bounce, worldPointOfContact, normal ); proto->SetState( protoState ); } From 7a48e058dae48abe5a2f780ad10941c00ffd3293 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 15 Jan 2014 10:44:20 +0100 Subject: [PATCH 30/42] Added Equal operators to Gravity struct == & != --- Code/GamePhysics/PhysicsStructs-Impl.h | 82 ++++++++++++++++++++++++++ Code/GamePhysics/PhysicsStructs.h | 16 ++++- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index c74c6537..17c18ba2 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -353,6 +353,26 @@ namespace Oyster return *this; } + inline bool GravityWell::operator == ( const GravityWell &gravity ) const + { + if( this->position == gravity.position ) + if( this->mass == gravity.mass ) + { + return true; + } + return false; + } + + inline bool GravityWell::operator != ( const GravityWell &gravity ) const + { + if( this->position == gravity.position ) + if( this->mass == gravity.mass ) + { + return false; + } + return true; + } + inline GravityDirected::GravityDirected( ) { this->impulse = ::Oyster::Math::Float3::null; @@ -370,6 +390,16 @@ namespace Oyster return *this; } + inline bool GravityDirected::operator == ( const GravityDirected &gravity ) const + { + return this->impulse == gravity.impulse; + } + + inline bool GravityDirected::operator != ( const GravityDirected &gravity ) const + { + return this->impulse != gravity.impulse; + } + inline GravityDirectedField::GravityDirectedField( ) { this->normalizedDirection = ::Oyster::Math::Float3::null; @@ -393,6 +423,28 @@ namespace Oyster return *this; } + inline bool GravityDirectedField::operator == ( const GravityDirectedField &gravity ) const + { + if( this->normalizedDirection == gravity.normalizedDirection ) + if( this->mass == gravity.mass ) + if( this->magnitude == gravity.magnitude ) + { + return true; + } + return false; + } + + inline bool GravityDirectedField::operator != ( const GravityDirectedField &gravity ) const + { + if( this->normalizedDirection == gravity.normalizedDirection ) + if( this->mass == gravity.mass ) + if( this->magnitude == gravity.magnitude ) + { + return false; + } + return true; + } + inline Gravity::Gravity() { this->gravityType = GravityType_Undefined; @@ -437,6 +489,36 @@ namespace Oyster return *this; } + + inline bool Gravity::operator == ( const Gravity &gravity ) const + { + if( this->gravityType == gravity.gravityType ) + { + switch( this->gravityType ) + { + case GravityType_Well: return this->well == gravity.well; + case GravityType_Directed: return this->directed == gravity.directed; + case GravityType_DirectedField: return this->directedField == gravity.directedField; + default: return true; + } + } + return false; + } + + inline bool Gravity::operator != ( const Gravity &gravity ) const + { + if( this->gravityType == gravity.gravityType ) + { + switch( this->gravityType ) + { + case GravityType_Well: return this->well != gravity.well; + case GravityType_Directed: return this->directed != gravity.directed; + case GravityType_DirectedField: return this->directedField != gravity.directedField; + default: return false; + } + } + return true; + } } } } diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index bf6c0618..7ed37c59 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -123,7 +123,10 @@ namespace Oyster { namespace Physics GravityWell( ); GravityWell( const GravityWell &gravityWell ); - GravityWell& operator=( const GravityWell &gravityWell ); + GravityWell & operator = ( const GravityWell &gravityWell ); + + bool operator == ( const GravityWell &gravity ) const; + bool operator != ( const GravityWell &gravity ) const; }; struct GravityDirected @@ -133,6 +136,9 @@ namespace Oyster { namespace Physics GravityDirected( ); GravityDirected( const GravityDirected &gravityDirected ); GravityDirected & operator = ( const GravityDirected &gravityDirected ); + + bool operator == ( const GravityDirected &gravity ) const; + bool operator != ( const GravityDirected &gravity ) const; }; struct GravityDirectedField @@ -143,7 +149,10 @@ namespace Oyster { namespace Physics GravityDirectedField( ); GravityDirectedField( const GravityDirectedField &gravityDirectedField ); - GravityDirectedField & operator=( const GravityDirectedField &gravityDirectedField ); + GravityDirectedField & operator = ( const GravityDirectedField &gravityDirectedField ); + + bool operator == ( const GravityDirectedField &gravity ) const; + bool operator != ( const GravityDirectedField &gravity ) const; }; struct Gravity @@ -177,6 +186,9 @@ namespace Oyster { namespace Physics Gravity( ); Gravity( const Gravity &gravity ); Gravity & operator = ( const Gravity &gravity ); + + bool operator == ( const Gravity &gravity ) const; + bool operator != ( const Gravity &gravity ) const; }; } } } From 44e071fba953c74c5cbfb82b192bdc201780e958 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 15 Jan 2014 10:44:31 +0100 Subject: [PATCH 31/42] Gravity implemented --- .../Implementation/PhysicsAPI_Impl.cpp | 55 +++++++++++++++++-- .../Implementation/PhysicsAPI_Impl.h | 4 ++ Code/GamePhysics/PhysicsAPI.h | 12 ++++ Code/OysterPhysics3D/OysterPhysics3D.h | 16 ++++++ 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 1115e7e9..94c908b9 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -3,6 +3,7 @@ #include "SimpleRigidBody.h" #include "SphericalRigidBody.h" +using namespace ::Oyster; using namespace ::Oyster::Physics; using namespace ::Oyster::Math; using namespace ::Oyster::Collision3D; @@ -113,6 +114,7 @@ API_Impl::API_Impl() this->gravityConstant = Constant::gravity_constant; this->updateFrameLength = 1.0f / 120.0f; this->destructionAction = Default::EventAction_Destruction; + this->gravity = ::std::vector(); this->worldScene = Octree(); } @@ -121,6 +123,8 @@ API_Impl::~API_Impl() {} void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize ) { unsigned char numLayers = 4; //!< @todo TODO: calc numLayers from worldSize + this->gravity.resize( 0 ); + this->gravity.reserve( numGravityWells ); this->worldScene = Octree( numObjects, numLayers, worldSize ); } @@ -153,14 +157,39 @@ float API_Impl::GetFrameTimeLength() const void API_Impl::Update() { /** @todo TODO: Update is a temporary solution .*/ - - - ::std::vector updateList; + ICustomBody::State state; auto proto = this->worldScene.Sample( Universe(), updateList ).begin(); for( ; proto != updateList.end(); ++proto ) { - // Step 1: @todo TODO: Apply Gravity + // Step 1: Apply Gravity + (*proto)->GetState( state ); + for( ::std::vector::size_type i = 0; i < this->gravity.size(); ++i ) + { + switch( this->gravity[i].gravityType ) + { + case Gravity::GravityType_Well: + { + Float4 d = state.GetCenterPosition() - Float4( this->gravity[i].well.position, 1.0f ); + Float rSquared = d.Dot( d ); + if( rSquared != 0.0 ) + { + Float force = Physics3D::Formula::ForceField( this->gravityConstant, state.GetMass(), this->gravity[i].well.mass, rSquared ); + state.ApplyLinearImpulse( (this->updateFrameLength * force / ::std::sqrt(rSquared)) * d ); + } + break; + } + case Gravity::GravityType_Directed: + state.ApplyLinearImpulse( Float4(this->gravity[i].directed.impulse, 0.0f) ); + break; +// case Gravity::GravityType_DirectedField: +// //this->gravity[i].directedField. +// //! TODO: @todo rethink +// break; + default: break; + } + } + (*proto)->SetState( state ); // Step 2: Apply Collision Response this->worldScene.Visit( *proto, OnPossibleCollision ); @@ -213,6 +242,24 @@ void API_Impl::DestroyObject( const ICustomBody* objRef ) } } +void API_Impl::AddGravity( const API::Gravity &g ) +{ + this->gravity.push_back( g ); +} + +void API_Impl::RemoveGravity( const API::Gravity &g ) +{ + for( ::std::vector::size_type i = this->gravity.size() - 1; i >= 0; --i ) + { + if( g == this->gravity[i] ) + { + int end = this->gravity.size() - 1; + this->gravity[i] = this->gravity[end]; + this->gravity.resize( end ); + } + } +} + //void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF ) //{ // unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 0c08bf11..314e0657 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -32,6 +32,9 @@ namespace Oyster ::Utility::DynamicMemory::UniquePointer ExtractObject( const ICustomBody* objRef ); void DestroyObject( const ICustomBody* objRef ); + void AddGravity( const Gravity &g ); + void RemoveGravity( const Gravity &g ); + //void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ); //void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ); @@ -49,6 +52,7 @@ namespace Oyster private: ::Oyster::Math::Float gravityConstant, updateFrameLength; EventAction_Destruction destructionAction; + ::std::vector gravity; Octree worldScene; }; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 0904551d..019a4af7 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -22,6 +22,7 @@ namespace Oyster struct SimpleBodyDescription; struct SphericalBodyDescription; struct CustomBodyState; + struct Gravity; } enum UpdateState @@ -40,6 +41,7 @@ namespace Oyster public: typedef Struct::SimpleBodyDescription SimpleBodyDescription; typedef Struct::SphericalBodyDescription SphericalBodyDescription; + typedef Struct::Gravity Gravity; typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer proto ); @@ -124,6 +126,16 @@ namespace Oyster ********************************************************/ virtual void DestroyObject( const ICustomBody* objRef ) = 0; + /******************************************************** + * TODO: @todo doc + ********************************************************/ + virtual void AddGravity( const Gravity &g ) = 0; + + /******************************************************** + * TODO: @todo doc + ********************************************************/ + virtual void RemoveGravity( const Gravity &g ) = 0; + ///******************************************************** // * Apply force on an object. // * @param objRef: A pointer to the ICustomBody representing a physical object. diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index 970d739e..f814ff46 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -273,6 +273,22 @@ namespace Oyster { namespace Physics3D return momentOfInertia * angularImpulseAcceleration; } + /****************************************************************** + * @todo TODO: doc + ******************************************************************/ + inline ::Oyster::Math::Float ForceField( ::Oyster::Math::Float g, ::Oyster::Math::Float massA, ::Oyster::Math::Float massB, ::Oyster::Math::Float radiusSquared ) + { + return g * massA * massB / radiusSquared; + } + + /****************************************************************** + * @todo TODO: doc + ******************************************************************/ + inline ::Oyster::Math::Float ForceField( ::Oyster::Math::Float g, ::Oyster::Math::Float massA, ::Oyster::Math::Float massB, const ::Oyster::Math::Float4 &deltaPos ) + { + return g * massA * massB / deltaPos.Dot( deltaPos ); + } + namespace MomentOfInertia { /// Library of Formulas to calculate moment of inerta for simple shapes /** @todo TODO: add MomentOfInertia tensor formulas */ From ceac5ce31d064379d4c795e9a7f0f2681601a506 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Wed, 15 Jan 2014 11:03:25 +0100 Subject: [PATCH 32/42] Modified namespace around Threadsafe queue and IQueue. Added TCP_NODELAY to sockets. Implemented some functionality to gamelogic --- .../DanBiasServer/GameSession/GameClient.cpp | 14 +- .../DanBiasServer/GameSession/GameClient.h | 9 +- .../DanBiasServer/GameSession/GameSession.h | 18 +- .../GameSession/GameSession_Events.cpp | 27 +-- .../GameSession/GameSession_General.cpp | 4 +- .../GameSession/GameSession_Logic.cpp | 26 ++- Code/Game/GameLogic/Game.cpp | 92 ++++++--- Code/Game/GameLogic/Game.h | 74 +++---- Code/Game/GameLogic/GameLogic.vcxproj | 1 + Code/Game/GameLogic/GameLogicStates.h | 4 +- Code/Game/GameLogic/Game_PlayerData.cpp | 38 +++- Code/Game/GameLogic/Object.cpp | 10 +- Code/Game/GameLogic/Object.h | 7 +- Code/Game/GameLogic/Player.cpp | 102 +++++----- Code/Game/GameLogic/Player.h | 29 ++- Code/Game/GameLogic/TeamManager.cpp | 2 +- Code/Game/GameLogic/Weapon.cpp | 2 +- Code/Misc/IQueue.h | 25 ++- Code/Misc/Misc.vcxproj | 1 + Code/Misc/Misc.vcxproj.filters | 3 + Code/Misc/PostBox/PostBox.h | 3 +- Code/Misc/Queue.h | 181 ++++++++++++++++++ Code/Misc/ThreadSafeQueue.h | 5 +- .../NetworkDependencies/Connection.cpp | 9 + Code/Network/NetworkDependencies/PostBox.h | 2 +- .../NetworkDependencies/ThreadedClient.cpp | 1 + 26 files changed, 500 insertions(+), 189 deletions(-) create mode 100644 Code/Misc/Queue.h diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.cpp b/Code/Game/DanBiasServer/GameSession/GameClient.cpp index da666881..479aedfd 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameClient.cpp @@ -13,7 +13,7 @@ using namespace GameLogic; static int gameClientIDCount = 1; -GameClient::GameClient(SmartPointer client, Game::PlayerData player, Oyster::Callback::OysterCallback value) +GameClient::GameClient(SmartPointer client, Game::PlayerData* player, Oyster::Callback::OysterCallback value) { this->callbackValue = value; this->client = client; @@ -28,8 +28,7 @@ GameClient::GameClient(SmartPointer client, Game::PlayerData player GameClient::~GameClient() { if(this->client) this->client->Disconnect(); - this->player.playerID = 0; - this->player.teamID = 0; + this->player = 0; this->id = -1; } @@ -40,13 +39,12 @@ void GameClient::SetCallback(Oyster::Callback::OysterCallbackplayer; + return this->player; } -GameLogic::Game::PlayerData GameClient::ReleasePlayer() +GameLogic::Game::PlayerData* GameClient::ReleasePlayer() { - GameLogic::Game::PlayerData temp = this->player; - this->player.playerID = 0; - this->player.teamID = 0; + GameLogic::Game::PlayerData *temp = this->player; + this->player = 0; return temp; } LobbyClient* GameClient::GetClient() const diff --git a/Code/Game/DanBiasServer/GameSession/GameClient.h b/Code/Game/DanBiasServer/GameSession/GameClient.h index f3d10a77..3a714bd6 100644 --- a/Code/Game/DanBiasServer/GameSession/GameClient.h +++ b/Code/Game/DanBiasServer/GameSession/GameClient.h @@ -13,14 +13,15 @@ namespace DanBias class GameClient: Oyster::Callback::CallbackObject { public: - GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::Game::PlayerData player, Oyster::Callback::OysterCallback value); + GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::Game::PlayerData* player, Oyster::Callback::OysterCallback value); virtual~GameClient(); void SetCallback(Oyster::Callback::OysterCallback value); - //GameLogic::Player* GetPlayer(); + /* */ GameLogic::Game::PlayerData* GetPlayer(); - GameLogic::Game::PlayerData ReleasePlayer(); + + GameLogic::Game::PlayerData* ReleasePlayer(); LobbyClient* GetClient() const; Utility::DynamicMemory::SmartPointer ReleaseClient(); @@ -28,7 +29,7 @@ namespace DanBias private: //Utility::DynamicMemory::SmartPointer player; - GameLogic::Game::PlayerData player; + GameLogic::Game::PlayerData* player; Utility::DynamicMemory::SmartPointer client; Oyster::Callback::OysterCallback callbackValue; int id; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession.h b/Code/Game/DanBiasServer/GameSession/GameSession.h index c4318db4..95514ba2 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession.h +++ b/Code/Game/DanBiasServer/GameSession/GameSession.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace DanBias { @@ -29,6 +30,19 @@ namespace DanBias NetworkSession* owner; Utility::DynamicMemory::DynamicArray> clients; }; + + struct GameSessionEvent + { + union EventData + { + GameLogic::Game::PlayerData* player; + } data; + enum EventType + { + EventType_Player, + EventType_DynamicObject, + } value; + }; public: GameSession(); @@ -74,6 +88,8 @@ namespace DanBias void SendToOwner(DanBias::GameClient* obj); //Do a cleanup on all the private data void Clean(); + //Update game objects if needed + void UpdateGameObjects(); //Private member variables private: @@ -83,9 +99,9 @@ namespace DanBias Oyster::Thread::OysterThread worker; GameLogic::Game gameInstance; NetworkSession* owner; - Utility::WinTimer timer; bool isCreated; bool isRunning; + Utility::Container::Queue modifiedClient; private: friend class AdminInterface; diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index 0016de8a..fb897211 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -38,6 +38,10 @@ namespace DanBias void GameSession::ParseGameplayEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) { + GameSessionEvent e; + e.data.player = c->GetPlayer(); + e.value = GameSessionEvent::EventType_Player; + switch (p[protocol_INDEX_ID].value.netShort) { case protocol_Gameplay_PlayerNavigation: @@ -45,22 +49,17 @@ namespace DanBias Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; if(p[1].value.netBool) //bool bForward; - world.v[3].x = 2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); + //world.v[3].x = 2; + c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); if(p[2].value.netBool) //bool bBackward; - world.v[3].x = -2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); + //world.v[3].x = -2; + c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_BACKWARD); if(p[5].value.netBool) //bool bStrafeRight; - world.v[3].y = 2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); + //world.v[3].y = 2; + c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_RIGHT); if(p[6].value.netBool) //bool bStrafeLeft; - world.v[3].y = -2; - //c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - - Protocol_ObjectPosition res(world, 0); - Send(res.GetProtocol()); - - + //world.v[3].y = -2; + c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); } break; case protocol_Gameplay_PlayerMouseMovement: @@ -76,6 +75,8 @@ namespace DanBias break; } + + this->modifiedClient.Push(e); } void GameSession::ParseGeneralEvent(Oyster::Network::CustomNetProtocol& p, DanBias::GameClient* c) diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp index d6db176e..7a3b87b4 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_General.cpp @@ -93,7 +93,7 @@ namespace DanBias { if(dissconnectClients) { - for (int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { this->clients[i]->GetClient()->Disconnect(); } @@ -143,7 +143,7 @@ namespace DanBias } else { - for (int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->clients.Size(); i++) { if(this->clients[i]) { diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp index eb1cf0ca..2cf5a61e 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp @@ -19,10 +19,6 @@ namespace DanBias { bool GameSession::DoWork( ) { - this->gameInstance.NewFrame(); - - this->ParseEvents(); - if(GetAsyncKeyState(VK_UP)) { Protocol_General_Status p(Protocol_General_Status::States_ready); @@ -30,8 +26,30 @@ namespace DanBias Sleep(100); } + this->ParseEvents(); + + this->gameInstance.NewFrame(); + + this->UpdateGameObjects(); + return this->isRunning; } + void GameSession::UpdateGameObjects() + { + while(!this->modifiedClient.IsEmpty()) + { + //There is something that needs update + GameSessionEvent e = this->modifiedClient.Pop(); + + switch (e.value) + { + case GameSessionEvent::EventType_Player: + //e.data.player->GetOrientation(); + break; + } + } + } + }//End namespace DanBias diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 08d081a2..f462bf89 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -3,24 +3,60 @@ #include "Level.h" #include #include +#include +#include using namespace GameLogic; using namespace Utility::DynamicMemory; +using namespace Oyster::Physics; + +#define DELTA_TIME 0.01666666666666666666666666666667f + +template +int InsertObject(DynamicArray& list, T* obj) +{ + for (unsigned int i = 0; i < list.Size(); i++) + { + if(!list[i]) + { + list[i] = obj; + return i; + } + } + list.Push(obj); + return list.Size() - 1; +} +template +int RemoveObject(DynamicArray& list, T* obj) +{ + for (unsigned int i = 0; i < list.Size(); i++) + { + if(!list[i]) + { + list[i] = obj; + return i; + } + } + list.Push(obj); + return list.Size() - 1; +} struct Game::PrivateData { PrivateData() - { - - } + { } ~PrivateData() { - + for (unsigned int i = 0; i < players.Size(); i++) + { + this->players[i]->player = 0; + } } - //DynamicArray> players; - DynamicArray> players; + + DynamicArray players; SmartPointer level; + Utility::WinTimer timer; }myData; @@ -38,27 +74,18 @@ Game::~Game(void) } } - -void Game::PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage) -{ - -} - -void Game::GetPlayerPos(int playerID) +void Game::GetAllPlayerPositions() const { } -void Game::GetAllPlayerPos() +Game::PlayerData* Game::CreatePlayer() { - -} - -Game::PlayerData Game::CreatePlayer() -{ - SmartPointer newPlayer = new Player(); - - myData->players.Push(newPlayer); + Player *newPlayer = new Player(); + PlayerData *newPdata = new PlayerData(); + newPdata->player = newPlayer; + int id = InsertObject(this->myData->players, newPdata); + return this->myData->players[id]; } void Game::CreateTeam() @@ -68,5 +95,24 @@ void Game::CreateTeam() void Game::NewFrame() { - + double dt = this->myData->timer.getElapsedSeconds(); + + //60 fps sec is currently staticly + + if(dt >= DELTA_TIME) + { + for (int i = 0; i < this->myData->players.Size(); i++) + { + if(this->myData->players[i]->player) + this->myData->players[i]->player->BeginFrame(); + } + API::Instance().Update(); + + for (int i = 0; i < this->myData->players.Size(); i++) + { + if(this->myData->players[i]->player) + this->myData->players[i]->player->EndFrame(); + } + this->myData->timer.reset(); + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index af35ee4d..28d4c7fc 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -7,76 +7,77 @@ #include "GameLogicDef.h" #include "GameLogicStates.h" +#include namespace GameLogic { class Player; - class Game + class DANBIAS_GAMELOGIC_DLL Game { public: - struct PlayerData + struct DANBIAS_GAMELOGIC_DLL PlayerData { private: friend class Game; Player *player; - - - public: - - int playerID; - int teamID; - - PlayerData(); - PlayerData(int playerID,int teamID); - - - ~PlayerData() - { + ~PlayerData(); - } - + public: /******************************************************** * Moves the chosen player based on input * @param playerID: ID of the player you want to recieve the message * @param movement: enum value on what kind of action is to be taken ********************************************************/ - void MovePlayer(const PLAYER_MOVEMENT &movement); + void Move(const PLAYER_MOVEMENT &movement); + /******************************************************** + * Uses the chosen players weapon based on input + * @param playerID: ID of the player you want to recieve the message + * @param Usage: enum value on what kind of action is to be taken + ********************************************************/ + void UseWeapon(int playerID, const WEAPON_FIRE &Usage); + /******************************************************** + * Gets players position + * @param playerID: ID of the player whos position you want + ********************************************************/ + Oyster::Math::Float3 GetPosition(); + + /******************************************************** + * Gets players current orientation + * @param playerID: ID of the player whos position you want + ********************************************************/ + Oyster::Math::Float4x4 GetOrientation(); + + /******************************************************** + * Check player state + * @return The current player state + ********************************************************/ + PLAYER_STATE GetState() const; + + /***/ + int GetID() const; + + /***/ + int GetTeamID() const; }; public: Game(void); ~Game(void); - - - - /******************************************************** - * Uses the chosen players weapon based on input - * @param playerID: ID of the player you want to recieve the message - * @param Usage: enum value on what kind of action is to be taken - ********************************************************/ - void PlayerUseWeapon(int playerID, const WEAPON_FIRE &Usage); - - /******************************************************** - * Gets a specific players position - * @param playerID: ID of the player whos position you want - ********************************************************/ - void GetPlayerPos(int playerID); - /******************************************************** * Gets the position of all players currently in the game ********************************************************/ - void GetAllPlayerPos(); + void GetAllPlayerPositions() const; /******************************************************** * Creates a player and returns PlayerData containing ID of the player ********************************************************/ - PlayerData CreatePlayer(); + PlayerData* CreatePlayer(); /******************************************************** * Creates a team @@ -88,7 +89,6 @@ namespace GameLogic ********************************************************/ void NewFrame(); - private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index c67ef3d9..f4e65b40 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -193,6 +193,7 @@ + diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 452f03ee..2a4f6b41 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -16,6 +16,8 @@ namespace GameLogic PLAYER_STATE_JUMPING = 0, PLAYER_STATE_WALKING = 1, PLAYER_STATE_IDLE = 2, + PLAYER_STATE_DEAD = 4, + PLAYER_STATE_INVALID = 8, }; enum OBJECT_TYPE @@ -37,7 +39,7 @@ namespace GameLogic enum WEAPON_STATE { - WEAPON_STATE_FIREING = 0, + WEAPON_STATE_FIRING = 0, WEAPON_STATE_IDLE = 1, WEAPON_STATE_RELOADING = 2, }; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 258c164c..881cdb58 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -5,10 +5,42 @@ using namespace GameLogic; Game::PlayerData::PlayerData() { - -} -void Game::PlayerData::MovePlayer(const PLAYER_MOVEMENT &movement) +} +Game::PlayerData::PlayerData(int playerID,int teamID) { } +Game::PlayerData::~PlayerData() +{ + +} + +void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement) +{ + this->player->Move(movement); +} +void Game::PlayerData::UseWeapon(int playerID, const WEAPON_FIRE &Usage) +{ + +} +Oyster::Math::Float3 Game::PlayerData::GetPosition() +{ + return this->player->GetPosition(); +} +Oyster::Math::Float4x4 Game::PlayerData::GetOrientation() +{ + return this->player->GetOrientation(); +} +PLAYER_STATE Game::PlayerData::GetState() const +{ + return this->player->GetState(); +} +int Game::PlayerData::GetID() const +{ + return this->player->GetID(); +} +int Game::PlayerData::GetTeamID() const +{ + return this->player->GetTeamID(); +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 49ff7780..3997246f 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -16,15 +16,13 @@ Object::Object() //sbDesc.centerPosition = //poi - ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); //rigidBody->gameObjectRef = this; this->objectID = GID(); this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; - - rigidBody->GetState(state); } Object::Object(void* collisionFunc, OBJECT_TYPE type) @@ -42,8 +40,6 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) this->objectID = GID(); this->type = type; - - rigidBody->GetState(state); } @@ -52,11 +48,11 @@ Object::~Object(void) } -OBJECT_TYPE Object::GetType() +OBJECT_TYPE Object::GetType() const { return this->type; } -int Object::GetID() +int Object::GetID() const { return this->objectID; } diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index c3519f73..d7fd02d9 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -19,8 +19,8 @@ namespace GameLogic Object(void* collisionFunc, OBJECT_TYPE type); ~Object(void); - OBJECT_TYPE GetType(); - int GetID(); + OBJECT_TYPE GetType() const; + int GetID() const; Oyster::Physics::ICustomBody* GetRigidBody(); @@ -29,7 +29,8 @@ namespace GameLogic int objectID; protected: Oyster::Physics::ICustomBody *rigidBody; - Oyster::Physics::ICustomBody::State state; + Oyster::Physics::ICustomBody::State setState; + Oyster::Physics::ICustomBody::State getState; }; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 08af0b9e..b5fb6189 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -1,49 +1,26 @@ + #include "Player.h" -#include "OysterMath.h" -#include "CollisionManager.h" #include "Weapon.h" using namespace GameLogic; using namespace Oyster::Physics; -struct Player::PrivateData -{ - PrivateData() - { - weapon = new Weapon(); - - life = 100; - teamID = -1; - playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - - lookDir = Oyster::Math::Float4(1,0,0,0); - } - - ~PrivateData() - { - if (weapon) - { - delete weapon; - } - } - - int life; - int teamID; - Weapon *weapon; - PLAYER_STATE playerState; - Oyster::Math::Float4 lookDir; - -}myData; - Player::Player() :Object(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) { - myData = new PrivateData(); + weapon = new Weapon(); + + life = 100; + teamID = -1; + playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + lookDir = Oyster::Math::Float4(1,0,0,0); } Player::~Player(void) { - delete myData; + delete weapon; + + weapon = NULL; } @@ -75,36 +52,36 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - state.ApplyLinearImpulse(myData->lookDir * 100); + setState.ApplyLinearImpulse(this->lookDir * 100); } void Player::MoveBackwards() { - state.ApplyLinearImpulse(-myData->lookDir * 100); + setState.ApplyLinearImpulse(-this->lookDir * 100); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir); - state.ApplyLinearImpulse(r * 100); + Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); + setState.ApplyLinearImpulse(r * 100); } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)myData->lookDir); - state.ApplyLinearImpulse(-r * 100); + Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); + setState.ApplyLinearImpulse(-r * 100); } void Player::UseWeapon(const WEAPON_FIRE &Usage) { - myData->weapon->Use(Usage); + this->weapon->Use(Usage); } void Player::Respawn(Oyster::Math::Float3 spawnPoint) { - myData->life = 100; - myData->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - myData->lookDir = Oyster::Math::Float4(1,0,0); + this->life = 100; + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + this->lookDir = Oyster::Math::Float4(1,0,0); } void Player::Jump() @@ -114,33 +91,48 @@ void Player::Jump() bool Player::IsWalking() { - return (myData->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); + return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); } bool Player::IsJumping() { - return (myData->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); + return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); } bool Player::IsIdle() { - return (myData->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); + return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); } -Oyster::Math::Float3 Player::GetPos() +Oyster::Math::Float3 Player::GetPosition() const { - return (Oyster::Math::Float3)state.GetCenterPosition(); + return (Oyster::Math::Float3)getState.GetCenterPosition(); } - -Oyster::Math::Float3 Player::GetLookDir() +Oyster::Math::Float4x4 Player::GetOrientation() const { - return myData->lookDir.xyz; + return this->getState.GetOrientation(); } - -int Player::GetTeamID() +Oyster::Math::Float3 Player::GetLookDir() const { - return myData->teamID; + return this->lookDir.xyz; +} +int Player::GetTeamID() const +{ + return this->teamID; +} +PLAYER_STATE Player::GetState() const +{ + return this->playerState; } void Player::DamageLife(int damage) { - myData->life -= damage; + this->life -= damage; +} + +void Player::BeginFrame() +{ + this->rigidBody->SetState(this->setState); +} +void Player::EndFrame() +{ + this->rigidBody->GetState(this->getState); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 0743dc00..9f190faf 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -3,13 +3,18 @@ ////////////////////////////////////////////////// #ifndef PLAYER_H #define PLAYER_H + #include "GameLogicStates.h" #include "OysterMath.h" #include "Object.h" +#include "OysterMath.h" +#include "CollisionManager.h" + namespace GameLogic { + class Weapon; class Player : public Object { @@ -45,18 +50,28 @@ namespace GameLogic bool IsJumping(); bool IsIdle(); - Oyster::Math::Float3 GetPos(); - Oyster::Math::Float3 GetLookDir(); - int GetTeamID(); + Oyster::Math::Float3 GetPosition() const; + Oyster::Math::Float3 GetLookDir() const; + Oyster::Math::Float4x4 GetOrientation() const; + int GetTeamID() const; + PLAYER_STATE GetState() const; void DamageLife(int damage); - private: + //Do frame calculations + void BeginFrame(); + void EndFrame(); - void Jump(); private: - struct PrivateData; - PrivateData *myData; + void Jump(); + + private: + int life; + int teamID; + Weapon *weapon; + PLAYER_STATE playerState; + Oyster::Math::Float4 lookDir; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/TeamManager.cpp b/Code/Game/GameLogic/TeamManager.cpp index 477697d1..6110707d 100644 --- a/Code/Game/GameLogic/TeamManager.cpp +++ b/Code/Game/GameLogic/TeamManager.cpp @@ -54,7 +54,7 @@ void TeamManager::RespawnPlayerRandom(Player *player) Player *respawnOnThis = myData->teams[teamID]->GetPlayer(0); - player->Respawn(respawnOnThis->GetPos()); + player->Respawn(respawnOnThis->GetPosition()); } void TeamManager::CreateTeam(int teamSize) diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 6ac989c5..f9c4a4b6 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -68,7 +68,7 @@ void Weapon::Use(const WEAPON_FIRE &fireInput) ********************************************************/ bool Weapon::IsFireing() { - return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIREING); + return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_FIRING); } bool Weapon::IsIdle() diff --git a/Code/Misc/IQueue.h b/Code/Misc/IQueue.h index fc85800e..00f8f135 100644 --- a/Code/Misc/IQueue.h +++ b/Code/Misc/IQueue.h @@ -1,13 +1,13 @@ -#ifndef I_QUEUE_H -#define I_QUEUE_H +#ifndef MISC_I_QUEUE_H +#define MISC_I_QUEUE_H ///////////////////////////////// // Created by Sam Svensson 2013// ///////////////////////////////// -namespace Oyster +namespace Utility { - namespace Queue + namespace Container { template class IQueue @@ -18,16 +18,13 @@ namespace Oyster //standard operations of the std::queue //--------------------------------------------- virtual ~IQueue() {}; - virtual void Push( Type item ) = 0; - virtual Type Pop() = 0; - - virtual Type Front() = 0; - virtual Type Back() = 0; - - virtual int Size() = 0; - virtual bool IsEmpty() = 0; - - virtual void Swap( IQueue &queue ) = 0; + virtual void Push( Type item ) = 0; + virtual Type Pop() = 0; + virtual Type Front() = 0; + virtual Type Back() = 0; + virtual int Size() = 0; + virtual bool IsEmpty() = 0; + virtual void Swap( IQueue &queue ) = 0; }; } } diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index c0ff5de7..744d1ed2 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -162,6 +162,7 @@ + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index 7f094027..97d25b7d 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -101,5 +101,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Code/Misc/PostBox/PostBox.h b/Code/Misc/PostBox/PostBox.h index 1e8dfb74..b79e07a5 100644 --- a/Code/Misc/PostBox/PostBox.h +++ b/Code/Misc/PostBox/PostBox.h @@ -24,7 +24,8 @@ namespace Oyster virtual bool IsEmpty(); private: - Oyster::Queue::ThreadSafeQueue messages; + Utility::Container::ThreadSafeQueue messages; + //Utility::Container::ThreadSafeQueue messages; }; diff --git a/Code/Misc/Queue.h b/Code/Misc/Queue.h new file mode 100644 index 00000000..67776e5a --- /dev/null +++ b/Code/Misc/Queue.h @@ -0,0 +1,181 @@ +#ifndef MISC_QUEUE_H +#define MISC_QUEUE_H + +//////////////////////////////////////////// +// Created by Sam Svensson 2013 +///////////////////////////////////////////// + +#include "IQueue.h" + +namespace Utility +{ + namespace Container + { + template + class Queue : public IQueue + { + public: + Queue(); + virtual ~Queue(); + + virtual void Push( Type item ); + virtual Type Pop(); + + virtual Type Front(); + virtual Type Back(); + + virtual int Size(); + virtual bool IsEmpty(); + virtual void Swap( IQueue &queue ); + + private: + class Node + { + public: + Type item; + Node *next; + Node(Type item){ this->item = item; this->next = NULL; }; + ~Node() {}; + }; + + Node *front; + Node *back; + int nrOfNodes; + }; + + + + + //---------------------------------------------- + //implemented template functions + //---------------------------------------------- + + template < typename Type > + Queue::Queue() + { + this->front = NULL; + this->back = NULL; + this->nrOfNodes = 0; + + } + + template < typename Type > + Queue::~Queue() + { + if(!nrOfNodes) return; + + if(this->front != NULL) + { + Node *destroyer; + Node *walker = this->front; + + for(int i = 0; i < this->nrOfNodes; i++) + { + destroyer = walker; + walker = walker->next; + + delete destroyer; + } + + this->front = NULL; + this->back = NULL; + } + } + + + template < typename Type > + void Queue::Push(Type item) + { + Node *e = new Node(item); + + if(this->front != NULL) + { + this->back->next = e; + this->back = e; + } + + else + { + this->front = e; + this->back = e; + } + + this->nrOfNodes++; + } + + template < typename Type > + Type Queue::Pop() + { + Type item = this->front->item; + Node *destroyer = this->front; + this->front = front->next; + + delete destroyer; + this->nrOfNodes--; + + if(nrOfNodes == 0) + { + this->front = NULL; + this->back = NULL; + } + + return item; + } + + template < typename Type > + Type Queue::Front() + { + Type temp = this->front->item; + + return temp; + + } + + template < typename Type > + Type Queue::Back() + { + Type temp = this->back->item; + return temp; + } + + template < typename Type > + int Queue::Size() + { + int size = this->nrOfNodes; + return size; + + } + + template < typename Type > + bool Queue::IsEmpty() + { + if(nrOfNodes == 0 || this->front == NULL) + { + return true; + } + + return false; + } + + template < typename Type > + void Queue::Swap(IQueue &queue ) + { + int prevNrOfNodes = this->nrOfNodes; + int size = queue.Size(); + + for(int i = 0; i < size; i++) + { + this->Push(queue.Pop()); + } + + for(int i = 0; i < prevNrOfNodes; i++) + { + queue.Push(this->Pop()); + } + } + + + } +} +#endif + diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index 7c3e3f02..3fab7c70 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -10,11 +10,10 @@ ///////////////////////////////////////////// #include "IQueue.h" -#include "Thread/OysterMutex.h" -namespace Oyster +namespace Utility { - namespace Queue + namespace Container { template class ThreadSafeQueue : public IQueue diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index bd289c63..5ff4eeda 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -211,5 +211,14 @@ int Connection::InitiateSocket() return WSAGetLastError(); } + int flag = 1; + int result = setsockopt(this->socket, /* socket affected */ + IPPROTO_TCP, /* set option at TCP level */ + TCP_NODELAY, /* name of option */ + (char *) &flag, /* the cast is historical cruft */ + sizeof(int)); /* length of option value */ + if (result < 0) + return -1; + return 0; } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/PostBox.h b/Code/Network/NetworkDependencies/PostBox.h index baaa8cc5..86375ce0 100644 --- a/Code/Network/NetworkDependencies/PostBox.h +++ b/Code/Network/NetworkDependencies/PostBox.h @@ -27,7 +27,7 @@ namespace Oyster virtual bool IsFull(); private: - Oyster::Queue::ThreadSafeQueue messages; + Utility::Container::ThreadSafeQueue messages; }; diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index fc652f7f..7b71b8dd 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -4,6 +4,7 @@ #include using namespace Oyster::Network; using namespace Oyster::Thread; +using namespace Utility::Container; using namespace Utility::DynamicMemory; ThreadedClient::ThreadedClient() From 208482b0ce0982ff85ac92f0973d76b2660ccc91 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 15 Jan 2014 11:25:59 +0100 Subject: [PATCH 33/42] GL merge error --- Code/Game/GameLogic/Game.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 0c70ad3b..20d13b18 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -55,13 +55,11 @@ void Game::GetAllPlayerPos() Game::PlayerData Game::CreatePlayer() { -<<<<<<< HEAD - SmartPointer newPlayer = new Player(); + SmartPointer newPlayer = new PlayerData(); myData->players.Push(newPlayer); -======= - return PlayerData(); ->>>>>>> eb6ed13cceff0ce4380699391759883acf487107 + + return newPlayer; } void Game::CreateTeam() From 8557559b9bceb48cf0e8e8a94af42331b4b7a4f1 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 15 Jan 2014 11:57:36 +0100 Subject: [PATCH 34/42] GL - going to merge --- Code/Game/DanBiasGame/GameClientState/LobbyState.cpp | 6 ++++++ Code/Game/GameLogic/Game.cpp | 12 +++++++----- Code/Game/GameLogic/GameLogic.vcxproj | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index d5005078..142fda1b 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -39,6 +39,12 @@ bool LobbyState::Init(Oyster::Network::NetworkClient* nwClient) } bool LobbyState::LoadModels(std::wstring file) { + Oyster::Graphics::Definitions::Pointlight plight; + plight.Pos = Oyster::Math::Float3(-2,3,0); + plight.Color = Oyster::Math::Float3(0,1,0); + plight.Radius = 10; + plight.Bright = 3; + Oyster::Graphics::API::AddLight(plight); // open file // read file // init models diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 0c70ad3b..752f534f 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -55,13 +55,15 @@ void Game::GetAllPlayerPos() Game::PlayerData Game::CreatePlayer() { -<<<<<<< HEAD - SmartPointer newPlayer = new Player(); - myData->players.Push(newPlayer); -======= + //SmartPointer newPlayer = new Player(); + + + + //myData->players.Push(newPlayer); + return PlayerData(); ->>>>>>> eb6ed13cceff0ce4380699391759883acf487107 + } void Game::CreateTeam() diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index c67ef3d9..f4e65b40 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -193,6 +193,7 @@ + From aac92bc20ed8210fd9cda828af207a7fa6859dcd Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Thu, 16 Jan 2014 09:30:16 +0100 Subject: [PATCH 35/42] GL- send new player pos to client --- Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index fb897211..7819187a 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -47,7 +47,7 @@ namespace DanBias case protocol_Gameplay_PlayerNavigation: { - Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; + //Oyster::Math::Float4x4 world = Oyster::Math::Matrix::identity; if(p[1].value.netBool) //bool bForward; //world.v[3].x = 2; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_FORWARD); @@ -60,6 +60,10 @@ namespace DanBias if(p[6].value.netBool) //bool bStrafeLeft; //world.v[3].y = -2; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); + + Oyster::Math::Float4x4 world = c->GetPlayer()->GetOrientation(); + Protocol_ObjectPosition p(world, 1); + Send(p.GetProtocol()); } break; case protocol_Gameplay_PlayerMouseMovement: From 0080a9f6f28c7e47babce3ee1c32d94979390bcd Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 16 Jan 2014 11:17:19 +0100 Subject: [PATCH 36/42] small name changes --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 12 ++++++------ Code/Game/GameLogic/AttatchmentMassDriver.h | 8 ++++---- Code/Game/GameLogic/Game.h | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 2 +- Code/Game/GameLogic/IAttatchment.h | 2 +- Code/Game/GameLogic/Player.cpp | 4 ++-- Code/Game/GameLogic/Player.h | 2 +- Code/Game/GameLogic/Weapon.cpp | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 409fa683..6ec70e1b 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -39,16 +39,16 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void) /******************************************************** * Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used ********************************************************/ -void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput) +void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage) { //switch case to determin what functionallity to use in the attatchment - switch (fireInput) + switch (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - ForcePush(fireInput); + ForcePush(usage); break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - ForcePull(fireInput); + ForcePull(usage); break; } @@ -57,7 +57,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInp /******************************************************** * Pushes objects in a cone in front of the weapon when fired ********************************************************/ -void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) +void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage) { //create coneRigidBody that will then collide with object and push them in the aimed direction } @@ -65,7 +65,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) /******************************************************** * Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) ********************************************************/ -void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput) +void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage) { //Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index 4c4fc124..a1ededd0 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -15,26 +15,26 @@ namespace GameLogic ~AttatchmentMassDriver(void); - void UseAttatchment(const WEAPON_FIRE &fireInput); + void UseAttatchment(const WEAPON_FIRE &usage); private: /******************************************************** * Pushes objects and players in a cone in front of the player * @param fireInput: allows switching on different functionality in this specific function ********************************************************/ - void ForcePush(const WEAPON_FIRE &fireInput); + void ForcePush(const WEAPON_FIRE &usage); /******************************************************** * Pulls the player forward, this is a movement tool * @param fireInput: allows switching on different functionality in this specific function ********************************************************/ - void ForcePull(const WEAPON_FIRE &fireInput); + void ForcePull(const WEAPON_FIRE &usage); /******************************************************** * Sucks objects towards the player, the player can then pick up an object and throw it as a projectile * @param fireInput: allows switching on different functionality in this specific function ********************************************************/ - void ForceSuck(const WEAPON_FIRE &fireInput); + void ForceSuck(const WEAPON_FIRE &usage); private: struct PrivateData; diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 28d4c7fc..3a860653 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -38,7 +38,7 @@ namespace GameLogic * @param playerID: ID of the player you want to recieve the message * @param Usage: enum value on what kind of action is to be taken ********************************************************/ - void UseWeapon(int playerID, const WEAPON_FIRE &Usage); + void UseWeapon(int playerID, const WEAPON_FIRE &usage); /******************************************************** * Gets players position diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 881cdb58..c393a18d 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -20,7 +20,7 @@ void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement) { this->player->Move(movement); } -void Game::PlayerData::UseWeapon(int playerID, const WEAPON_FIRE &Usage) +void Game::PlayerData::UseWeapon(int playerID, const WEAPON_FIRE &usage) { } diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h index 2192ffcf..5bc400e6 100644 --- a/Code/Game/GameLogic/IAttatchment.h +++ b/Code/Game/GameLogic/IAttatchment.h @@ -19,7 +19,7 @@ namespace GameLogic IAttatchment(void); ~IAttatchment(void); - virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; + virtual void UseAttatchment(const WEAPON_FIRE &usage) = 0; private: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index b5fb6189..ffeb3f9e 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -71,9 +71,9 @@ void Player::MoveLeft() setState.ApplyLinearImpulse(-r * 100); } -void Player::UseWeapon(const WEAPON_FIRE &Usage) +void Player::UseWeapon(const WEAPON_FIRE &usage) { - this->weapon->Use(Usage); + this->weapon->Use(usage); } void Player::Respawn(Oyster::Math::Float3 spawnPoint) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 9f190faf..0f080b3b 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -37,7 +37,7 @@ namespace GameLogic * Uses the weapon based on input * @param fireInput: enum value on what kind of action is to be taken ********************************************************/ - void UseWeapon(const WEAPON_FIRE &Usage); + void UseWeapon(const WEAPON_FIRE &usage); /******************************************************** * Respawns the player, this resets several stats and settings on the player diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index f9c4a4b6..9e6b6bd2 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -50,11 +50,11 @@ Weapon::~Weapon(void) /******************************************************** * Uses the weapon based on the input given and the current chosen attatchment ********************************************************/ -void Weapon::Use(const WEAPON_FIRE &fireInput) +void Weapon::Use(const WEAPON_FIRE &usage) { if (myData->selectedAttatchment) { - myData->selectedAttatchment->UseAttatchment(fireInput); + myData->selectedAttatchment->UseAttatchment(usage); } } From 27b6affd6ab51a67d552c7f7fbbc545a7a8d68cb Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 16 Jan 2014 11:28:07 +0100 Subject: [PATCH 37/42] BoxVsBox pointOfContact fix it was not translated --- Code/OysterPhysics3D/OysterCollision3D.cpp | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 3ef44974..169b5add 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -204,7 +204,7 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } - bool SeperatingAxisTest_AxisAlignedVsTransformedBox( const Float4 &boundingOffsetA, const Float4 &boundingOffsetB, const Float4x4 &rotationB, const Float4 &worldOffset, Float4 &worldPointOfContact ) + bool SeperatingAxisTest_AxisAlignedVsTransformedBox( const Float4 &boundingOffsetA, const Float4 &boundingOffsetB, const Float4x4 &rotationB, const Float4 &worldOffset, Float4 &localPointOfContact ) { // by Dan Andersson /***************************************************************** @@ -241,7 +241,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact = s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact = s * ( centerSeperation * eA / edgeSeperation ); s = Float4::standard_unit_y; centerSeperation = t.Dot(s); @@ -251,7 +251,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = Float4::standard_unit_z; centerSeperation = t.Dot(s); @@ -261,7 +261,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = rotationB.v[0]; centerSeperation = t.Dot(s); @@ -271,7 +271,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = rotationB.v[1]; centerSeperation = t.Dot(s); @@ -281,7 +281,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = rotationB.v[2]; centerSeperation = t.Dot(s); @@ -291,7 +291,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); // enough point of contact data gathered for approximative result. + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); // enough point of contact data gathered for approximative result. s = Float4( Float3::standard_unit_x.Cross(rotationB.v[0].xyz), 0.0f ); centerSeperation = t.Dot(s); @@ -374,7 +374,7 @@ namespace Oyster { namespace Collision3D { namespace Utility return false; } - worldPointOfContact *= 0.5f; + localPointOfContact *= 0.5f; return true; } } @@ -821,10 +821,11 @@ namespace Oyster { namespace Collision3D { namespace Utility Float4 alignedOffsetBoundaries = (boxB.maxVertex - boxB.minVertex) * 0.5f, offset = boxA.center - Average( boxB.maxVertex, boxB.minVertex ); - Float4 pointOfContact; - if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries, boxA.boundingOffset, boxA.rotation, offset, pointOfContact ) ) + Float4 localPointOfContact; + if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries, boxA.boundingOffset, boxA.rotation, offset, localPointOfContact ) ) { - worldPointOfContact = pointOfContact.xyz; + worldPointOfContact = localPointOfContact + boxA.center; + worldPointOfContact.w = 1.0f; return true; } else return false; @@ -843,10 +844,12 @@ namespace Oyster { namespace Collision3D { namespace Utility Float4x4 rotationB = TransformMatrix( InverseRotationMatrix(boxA.rotation), boxB.rotation ); Float4 posB = boxB.center - boxA.center; - Float4 pointOfContact; - if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( boxA.boundingOffset, boxB.boundingOffset, rotationB, posB, pointOfContact ) ) + Float4 localPointOfContact; + if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( boxA.boundingOffset, boxB.boundingOffset, rotationB, posB, localPointOfContact ) ) { - worldPointOfContact = TransformVector( boxA.rotation, pointOfContact, pointOfContact ).xyz; + worldPointOfContact = TransformVector( boxA.rotation, localPointOfContact, localPointOfContact ); + worldPointOfContact += boxA.center; + worldPointOfContact.w = 1.0f; return true; } else return false; From 225d8912dac5b5b06691461a97e3c068edb4056b Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 16 Jan 2014 11:40:29 +0100 Subject: [PATCH 38/42] GL - make rigidbody level --- Code/Game/GameLogic/CollisionManager.cpp | 5 +++++ Code/Game/GameLogic/CollisionManager.h | 2 +- Code/Game/GameLogic/Level.cpp | 17 +++++++++++++++-- Code/Game/GameLogic/Level.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 698fb88f..a16d63fe 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -55,3 +55,8 @@ using namespace GameLogic; return Physics::ICustomBody::SubscriptMessage_none; } + + Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj) + { + return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; + } diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index 18d482b4..21723885 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -14,7 +14,7 @@ namespace GameLogic //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); - + static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj); //these are the specific collision case functions //void PlayerVBox(Player &player, DynamicObject &box); //void BoxVBox(DynamicObject &box1, DynamicObject &box2); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 9b3c90ff..81cad9e9 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -9,7 +9,7 @@ using namespace GameLogic; using namespace Utility::DynamicMemory; - +using namespace Oyster::Physics; struct Level::PrivateData { @@ -29,7 +29,7 @@ struct Level::PrivateData SmartPointer gameMode; - SmartPointer rigidBodyLevel; + SmartPointer rigidBodyLevel; }myData; @@ -47,6 +47,19 @@ Level::~Level(void) void Level::InitiateLevel(std::string levelPath) { +} +void Level::InitiateLevel(float radius) +{ + API::SphericalBodyDescription sbDesc; + sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,0); + sbDesc.ignoreGravity = true; + sbDesc.radius = radius; + sbDesc.mass = 1e16; //10^20 + sbDesc.subscription = CollisionManager::LevelCollision; + + ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + + } void Level::AddPlayerToTeam(Player *player, int teamID) diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index fa450dc4..68dfca0f 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -21,6 +21,7 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ void InitiateLevel(std::string levelPath); + void Level::InitiateLevel(float radius); /******************************************************** * Creates a team in the level From d08e999f0702d6ddbc28acf7145648a978ae0380 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 16 Jan 2014 12:08:24 +0100 Subject: [PATCH 39/42] Create level and initiate it with a rigidbody etc --- Code/Game/GameLogic/Game.cpp | 12 +++++++++++- Code/Game/GameLogic/Game.h | 20 +++++++++++++++++++- Code/Game/GameLogic/Game_LevelData.cpp | 14 ++++++++++++++ Code/Game/GameLogic/Level.cpp | 12 ++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 Code/Game/GameLogic/Game_LevelData.cpp diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 64ab7c57..d102aa16 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -55,7 +55,7 @@ struct Game::PrivateData } DynamicArray players; - SmartPointer level; + SmartPointer level; Utility::WinTimer timer; }myData; @@ -88,6 +88,16 @@ Game::PlayerData* Game::CreatePlayer() return this->myData->players[id]; } +Game::LevelData* Game::CreateLevel() +{ + Level *newLevel = new Level(); + newLevel->InitiateLevel(1000); + LevelData *newLdata = new LevelData(); + newLdata->level = newLevel; + myData->level = newLdata; + return myData->level; +} + void Game::CreateTeam() { diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 3a860653..0cd9b2a8 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -65,6 +65,19 @@ namespace GameLogic int GetTeamID() const; }; + struct DANBIAS_GAMELOGIC_DLL LevelData + { + private: + friend class Game; + Level *level; + LevelData(); + ~LevelData(); + + public: + + + }; + public: Game(void); ~Game(void); @@ -75,10 +88,15 @@ namespace GameLogic void GetAllPlayerPositions() const; /******************************************************** - * Creates a player and returns PlayerData containing ID of the player + * Creates a player and returns PlayerData ********************************************************/ PlayerData* CreatePlayer(); + /******************************************************** + * Creates a level and returns LevelData + ********************************************************/ + LevelData* CreateLevel(); + /******************************************************** * Creates a team ********************************************************/ diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp new file mode 100644 index 00000000..a9a5394e --- /dev/null +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -0,0 +1,14 @@ +#include "Game.h" +#include "Level.h" + +using namespace GameLogic; + +Game::LevelData::LevelData() +{ + +} + +Game::LevelData::~LevelData() +{ + +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 81cad9e9..4ce96dee 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -51,14 +51,22 @@ void Level::InitiateLevel(std::string levelPath) void Level::InitiateLevel(float radius) { API::SphericalBodyDescription sbDesc; - sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,0); + sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1); sbDesc.ignoreGravity = true; sbDesc.radius = radius; - sbDesc.mass = 1e16; //10^20 + sbDesc.mass = 1e16; //10^16 sbDesc.subscription = CollisionManager::LevelCollision; ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + API::Instance().AddObject(rigidBody); + API::Gravity gravityWell; + + gravityWell.gravityType = API::Gravity::GravityType_Well; + gravityWell.well.mass = (float)1e16; + gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); + + API::Instance().AddGravity(gravityWell); } From a168328a447e4a4edb7080fd2baaa47d3b4db48e Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Thu, 16 Jan 2014 12:26:14 +0100 Subject: [PATCH 40/42] GL - movement with physics working!! --- .../DanBiasGame/GameClientState/GameState.cpp | 15 +++++++++++++++ .../GameSession/GameSession_Events.cpp | 7 ++++--- .../GameSession/GameSession_Logic.cpp | 11 +++++++++++ Code/Game/GameLogic/Object.cpp | 5 +++++ Code/Game/GameLogic/Player.cpp | 17 +++++++++++++---- Code/Game/GameProtocols/PlayerProtocols.h | 4 ++-- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 1d1e45a9..af6ec035 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -85,6 +85,15 @@ bool GameState::LoadModels(std::wstring mapFile) privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); + modelData.world = modelData.world * translate; + modelData.modelPath = L"..\\Content\\worldDummy"; + modelData.id ++; + + obj = new C_DynamicObj(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); + return true; } @@ -260,7 +269,13 @@ void GameState::Protocol( ObjPos* pos ) for (int i = 0; i < privData->object.size(); i++) { if(privData->object[i]->GetId() == pos->object_ID) + { privData->object[i]->setPos(world); + + //privData->view = world; + //privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); + + } } } diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp index 7819187a..51d052ba 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Events.cpp @@ -61,9 +61,8 @@ namespace DanBias //world.v[3].y = -2; c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); - Oyster::Math::Float4x4 world = c->GetPlayer()->GetOrientation(); - Protocol_ObjectPosition p(world, 1); - Send(p.GetProtocol()); + + } break; case protocol_Gameplay_PlayerMouseMovement: @@ -78,6 +77,8 @@ namespace DanBias case protocol_Gameplay_ObjectPosition: break; + + } this->modifiedClient.Push(e); diff --git a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp index 68d3c968..50979092 100644 --- a/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp +++ b/Code/Game/DanBiasServer/GameSession/GameSession_Logic.cpp @@ -34,6 +34,8 @@ namespace DanBias Sleep(100); } + + this->ParseEvents(); this->gameInstance.NewFrame(); @@ -56,6 +58,15 @@ namespace DanBias //e.data.player->GetOrientation(); break; } + + } + + if(clients.Size() == 1) + { + Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation(); + Protocol_ObjectPosition p(world, 1); + Send(p.GetProtocol()); + Sleep(100); } } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 3997246f..cf8c8d9e 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -18,6 +18,9 @@ Object::Object() //poi ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + + Oyster::Physics::API::Instance().AddObject(rigidBody); + //rigidBody->gameObjectRef = this; this->objectID = GID(); @@ -32,6 +35,8 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) //poi ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + + Oyster::Physics::API::Instance().AddObject(rigidBody); rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index b5fb6189..85cd8db7 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -13,7 +13,12 @@ Player::Player() life = 100; teamID = -1; playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - lookDir = Oyster::Math::Float4(1,0,0,0); + lookDir = Oyster::Math::Float4(0,0,-1,0); + Oyster::Physics::ICustomBody::State state; + this->rigidBody->GetState( this->setState ); + setState.SetLinearMomentum( Oyster::Math::Float4(20, 0, 0, 0) ); + this->rigidBody->SetState( setState ); + } Player::~Player(void) @@ -61,13 +66,16 @@ void Player::MoveBackwards() void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); + Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); + //Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); setState.ApplyLinearImpulse(r * 100); + } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); + Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); + //Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); setState.ApplyLinearImpulse(-r * 100); } @@ -106,7 +114,7 @@ Oyster::Math::Float3 Player::GetPosition() const { return (Oyster::Math::Float3)getState.GetCenterPosition(); } -Oyster::Math::Float4x4 Player::GetOrientation() const +Oyster::Math::Float4x4 Player::GetOrientation() const { return this->getState.GetOrientation(); } @@ -135,4 +143,5 @@ void Player::BeginFrame() void Player::EndFrame() { this->rigidBody->GetState(this->getState); + this->setState = this->getState; } \ No newline at end of file diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 68065071..96686807 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -42,7 +42,7 @@ namespace GameLogic bTurnLeft = val[3].value.netBool; bTurnRight = val[4].value.netBool; bStrafeRight = val[5].value.netBool; - bStrafeRight = val[6].value.netBool; + bStrafeLeft = val[6].value.netBool; return *this; } @@ -53,7 +53,7 @@ namespace GameLogic this->protocol[3].value = bTurnLeft; this->protocol[4].value = bTurnRight; this->protocol[5].value = bStrafeRight; - this->protocol[6].value = bStrafeRight; + this->protocol[6].value = bStrafeLeft; return &protocol; } From eaf0ae1479dd34edbdab1c9724ca39224fc465c7 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 17 Jan 2014 08:52:34 +0100 Subject: [PATCH 41/42] GL - can now compile --- Code/Game/GameLogic/CollisionManager.cpp | 2 +- Code/Game/GameLogic/Game.cpp | 2 +- Code/Game/GameLogic/Game.h | 1 + Code/Game/GameLogic/GameLogic.vcxproj | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index a16d63fe..4cdb3689 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -56,7 +56,7 @@ using namespace GameLogic; return Physics::ICustomBody::SubscriptMessage_none; } - Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj) + Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj) { return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index d102aa16..af1e9d8c 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -55,7 +55,7 @@ struct Game::PrivateData } DynamicArray players; - SmartPointer level; + LevelData* level; Utility::WinTimer timer; }myData; diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 0cd9b2a8..1550001d 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -12,6 +12,7 @@ namespace GameLogic { class Player; + class Level; class DANBIAS_GAMELOGIC_DLL Game { diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index f4e65b40..3c5ae258 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -193,6 +193,7 @@ + From ce4c57bab3d71df5bdde198b3a831f2d6be05786 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 20 Jan 2014 08:40:41 +0100 Subject: [PATCH 42/42] GL - player inherits dynamicobject instead of object --- Code/Game/GameLogic/Level.cpp | 14 +++++++------- Code/Game/GameLogic/Player.cpp | 2 +- Code/Game/GameLogic/Player.h | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 4ce96dee..50862c9e 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -21,13 +21,13 @@ struct Level::PrivateData { } - SmartPointer teamManager; + //SmartPointer teamManager; - DynamicArray> staticObjects; + //DynamicArray> staticObjects; - DynamicArray> dynamicObjects; + //DynamicArray> dynamicObjects; - SmartPointer gameMode; + //SmartPointer gameMode; SmartPointer rigidBodyLevel; @@ -72,17 +72,17 @@ void Level::InitiateLevel(float radius) void Level::AddPlayerToTeam(Player *player, int teamID) { - myData->teamManager->AddPlayerToTeam(player,teamID); + //myData->teamManager->AddPlayerToTeam(player,teamID); } void Level::CreateTeam(int teamSize) { - myData->teamManager->CreateTeam(teamSize); + //myData->teamManager->CreateTeam(teamSize); } void Level::RespawnPlayer(Player *player) { - myData->teamManager->RespawnPlayerRandom(player); + //myData->teamManager->RespawnPlayerRandom(player); } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 05a20503..ea66ac3d 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -6,7 +6,7 @@ using namespace GameLogic; using namespace Oyster::Physics; Player::Player() - :Object(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) + :DynamicObject(CollisionManager::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER) { weapon = new Weapon(); diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 0f080b3b..0211136a 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -6,7 +6,7 @@ #include "GameLogicStates.h" #include "OysterMath.h" -#include "Object.h" +#include "DynamicObject.h" #include "OysterMath.h" #include "CollisionManager.h" @@ -15,9 +15,8 @@ namespace GameLogic { class Weapon; - class Player : public Object + class Player : public DynamicObject { - public: Player(void); ~Player(void);