From 6b9be0ee8e7827c3479d63d3eb3995d3d978bf8a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 25 Feb 2014 17:05:25 +0100 Subject: [PATCH 01/46] Multi bone animation support internal legwork done --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 23 +- Code/OysterGraphics/DllInterfaces/GFXAPI.h | 2 +- Code/OysterGraphics/Model/Model.h | 4 +- Code/OysterGraphics/Model/ModelInfo.h | 3 + .../OysterGraphics/Render/DefaultRenderer.cpp | 653 +++++++++++------- 5 files changed, 422 insertions(+), 263 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index ee3d9f8a..0369a3eb 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -171,7 +171,8 @@ namespace Oyster Model::Model* m = new Model::Model(); m->WorldMatrix = Oyster::Math::Float4x4::identity; m->Visible = true; - m->Animation.AnimationPlaying = NULL; + m->Animation[0].AnimationPlaying = nullptr; + m->Animation[1].AnimationPlaying = nullptr; m->Tint = Math::Float3(1); m->GlowTint = Math::Float3(1); m->Instanced = true; @@ -327,14 +328,20 @@ namespace Oyster Core::loader.ReleaseResource(tex); } - float API::PlayAnimation(Model::Model* m, std::wstring name,bool looping) + float API::PlayAnimation( Model::Model* m, const std::wstring &name, bool looping ) { - if(m==NULL) - return 0; - m->Animation.AnimationPlaying = &(*m->info->Animations.find(name)).second; - m->Animation.AnimationTime=0; - m->Animation.LoopAnimation = looping; - return (float)m->Animation.AnimationPlaying->duration; + if( m ) + { // nasty temp solution by Dan + static int fairSlotLooper = 0; + fairSlotLooper = (fairSlotLooper + 1) & 3; // same as n % 2 + + m->Animation[fairSlotLooper].AnimationPlaying = &(*m->info->Animations.find(name)).second; + m->Animation[fairSlotLooper].AnimationTime=0; + m->Animation[fairSlotLooper].LoopAnimation = looping; + + return (float)m->Animation[fairSlotLooper].AnimationPlaying->duration; + } + return 0; } void API::Update(float dt) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 7f338cce..9a99bbf5 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -111,7 +111,7 @@ namespace Oyster static Option GetOption(); //! @brief Starts an animation and returns the time of the animation - static float PlayAnimation(Model::Model* model, std::wstring name, bool looping = false); + static float PlayAnimation(Model::Model* model, const std::wstring &name, bool looping = false); //! @brief Moves all animating models forward the specified time; static void Update(float deltaTime); diff --git a/Code/OysterGraphics/Model/Model.h b/Code/OysterGraphics/Model/Model.h index 6d4e96f2..5fb2aa18 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -19,6 +19,7 @@ namespace Oyster float AnimationTime; bool LoopAnimation; }; + struct Model { ModelInfo* info; @@ -27,10 +28,9 @@ namespace Oyster Oyster::Math::Float3 GlowTint; bool Visible; bool Instanced; - AnimationData Animation; + AnimationData Animation[2]; }; } - }; }; diff --git a/Code/OysterGraphics/Model/ModelInfo.h b/Code/OysterGraphics/Model/ModelInfo.h index a53bcb23..7e737dbc 100644 --- a/Code/OysterGraphics/Model/ModelInfo.h +++ b/Code/OysterGraphics/Model/ModelInfo.h @@ -17,11 +17,13 @@ namespace Oyster Math::Matrix Absolute; int Parent; }; + struct Frame { Bone bone; double time; }; + struct Animation { int Bones; @@ -29,6 +31,7 @@ namespace Oyster Frame** Keyframes; //! @brief [Bone][Frame] double duration; }; + struct ModelInfo { std::vector Material; diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 4b979be8..3a94c20e 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -12,278 +12,427 @@ namespace Oyster { namespace Render { - Definitions::Pointlight pl; + Definitions::Pointlight pl; - void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights) + /******************************************************** + * Private Prototype Methods + ********************************************************/ + void AnimateRelativeBones( const Model::ModelInfo &info, Model::AnimationData &anim, Math::Matrix relativeBuffer[] ); + void MergeAnimatedBones + ( + const Model::Bone raw[], int numBones, Math::Float interpolation, // comparable raw bone data and interpolation value + const Math::Matrix animatedBoneSourceA[], // relative bone animations + Math::Matrix animatedBoneSourceB_Target[] // relative bone animations and targetbuffer + ); + int AnimateAbsoluteBones + ( + const Model::ModelInfo &info, Math::Float deltaTime, + Model::AnimationData &anim, + Math::Matrix SkinTransformBuffer[], + Math::Matrix BoneAnimationBuffer_Relative[], + Math::Matrix BoneAnimationBuffer_Absolute[] + ); + int AnimateAbsoluteBones + ( + const Model::ModelInfo &info, Math::Float deltaTime, + Model::AnimationData anim[], int numAnimations, + Math::Matrix SkinTransformBuffer[], + Math::Matrix BoneAnimationBuffer_Relative[], + Math::Matrix BoneAnimationBuffer_Absolute[] + ); + + /******************************************************** + * Public Method Implementations + ********************************************************/ + + void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights) + { + Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); + Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); + Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); + Lights[1]; + + void* data; + + Definitions::LightConstants lc; + lc.InvProj = Projection.GetInverse(); + lc.Pixels = Core::resolution; + lc.Lights = numLights; + lc.View = View; + lc.Proj = Projection; + lc.SSAORadius = 3; + + data = Resources::Light::LightConstantsData.Map(); + memcpy(data, &lc, sizeof(Definitions::LightConstants)); + Resources::Light::LightConstantsData.Unmap(); + + data = Resources::Light::PointLightsData.Map(); + memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); + Resources::Light::PointLightsData.Unmap(); + + for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) { - Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); - Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); - Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); - Lights[1]; - - void* data; - - Definitions::LightConstants lc; - lc.InvProj = Projection.GetInverse(); - lc.Pixels = Core::resolution; - lc.Lights = numLights; - lc.View = View; - lc.Proj = Projection; - lc.SSAORadius = 3; - - data = Resources::Light::LightConstantsData.Map(); - memcpy(data, &lc, sizeof(Definitions::LightConstants)); - Resources::Light::LightConstantsData.Unmap(); - - data = Resources::Light::PointLightsData.Map(); - memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); - Resources::Light::PointLightsData.Unmap(); - - for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) - { - (*i).second->Models=0; - } - - Core::PipelineManager::SetRenderPass(Resources::Gather::AnimatedPass); + (*i).second->Models=0; } - void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime) + Core::PipelineManager::SetRenderPass(Resources::Gather::AnimatedPass); + } + + void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime) + { + for(int i = 0; i < count; ++i) { - for(int i = 0; i < count; ++i) + if(&models[i] == NULL || !models[i].Visible) + continue; + + Model::ModelInfo* info = models[i].info; + if(!info->Animated && models[i].Instanced) { - if(&models[i] == NULL || !models[i].Visible) - continue; + Definitions::RenderInstanceData rid; + Math::Float3x3 normalTransform; + normalTransform = Math::Float3x3(models[i].WorldMatrix.v[0].xyz, models[i].WorldMatrix.v[1].xyz, models[i].WorldMatrix.v[2].xyz); + normalTransform.Transpose().Invert(); + Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f)); + rid.WV = View * m; + rid.WVP = Projection * View * models[i].WorldMatrix; - Model::ModelInfo* info = models[i].info; - if(!info->Animated && models[i].Instanced) - { - Definitions::RenderInstanceData rid; - Math::Float3x3 normalTransform; - normalTransform = Math::Float3x3(models[i].WorldMatrix.v[0].xyz, models[i].WorldMatrix.v[1].xyz, models[i].WorldMatrix.v[2].xyz); - normalTransform.Transpose().Invert(); - Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f)); - rid.WV = View * m; - rid.WVP = Projection * View * models[i].WorldMatrix; + rid.Tint = models[i].Tint; + rid.GTint = models[i].GlowTint; - rid.Tint = models[i].Tint; - rid.GTint = models[i].GlowTint; - - Resources::RenderData[info]->rid[Resources::RenderData[info]->Models++] = rid; - } - else - { - Definitions::PerModel pm; - Math::Float3x3 normalTransform; - normalTransform = Math::Float3x3(models[i].WorldMatrix.v[0].xyz, models[i].WorldMatrix.v[1].xyz, models[i].WorldMatrix.v[2].xyz); - normalTransform.Transpose().Invert(); - Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f)); - pm.WV = View * m; - pm.WVP = Projection * View * models[i].WorldMatrix; - - Model::ModelInfo* info = models[i].info; - - Definitions::AnimationData am; //final - if(info->Animated && models[i].Animation.AnimationPlaying != NULL) - { - models[i].Animation.AnimationTime += deltaTime; - ////store inverse absolut transform - Math::Matrix SkinTransform[100]; - Math::Matrix BoneAnimated[100]; - Math::Matrix BoneAbsAnimated[100]; - - - - for(int b = 0; b BoneCount; ++b) - { - Model::Bone Bone = info->bones[b]; - SkinTransform[b] = Bone.Absolute.GetInverse(); - BoneAnimated[b] = Bone.Relative; - BoneAbsAnimated[b] = Bone.Absolute; - } - int b = 0; - Model::Animation A = *models[i].Animation.AnimationPlaying; - while(models[i].Animation.AnimationTime>A.duration && models[i].Animation.LoopAnimation) - models[i].Animation.AnimationTime -= (float)A.duration; - - float position = models[i].Animation.AnimationTime; - for(int b = 0; b < A.Bones;++b) - { - //find current frame - int nrOfFrames = A.Frames[b]; - Model::Frame PFrame = A.Keyframes[b][nrOfFrames-1]; - Model::Frame NFrame = A.Keyframes[b][nrOfFrames-1]; - bool FrameFound = false; - for (int i = 0; i < nrOfFrames; i++) - { - if(position < A.Keyframes[b][i].time) - { - PFrame = A.Keyframes[b][i-1]; - NFrame = A.Keyframes[b][i]; - break; - } - } - float denominator = (float)(NFrame.time - PFrame.time); - if(denominator == 0) - { - BoneAnimated[PFrame.bone.Parent] = PFrame.bone.Relative; - continue; - } - float inter = (float)((position - PFrame.time) / denominator); - Math3D::InterpolateOrientation_UsingNonRigidNlerp(PFrame.bone.Relative,NFrame.bone.Relative,inter, BoneAnimated[PFrame.bone.Parent]); - } - - ////calculate Absolute Animation Transform - for(int b = 0; b < info->BoneCount; ++b) - { - BoneAbsAnimated[b] = BoneAbsAnimated[info->bones[b].Parent] * BoneAnimated[b]; - } - - //write data to am - for(int b = 0; b < info->BoneCount; ++b) - { - am.AnimatedData[b] = (BoneAbsAnimated[b] * SkinTransform[b]); - } - - - void *data = Resources::Gather::AnimationData.Map(); - memcpy(data,&am,sizeof(Definitions::AnimationData)); - Resources::Gather::AnimationData.Unmap(); - - pm.Animated = 1; - } - else - pm.Animated = 0; - - void* data = Resources::Gather::ModelData.Map(); - memcpy(data,&(pm),sizeof(pm)); - Resources::Gather::ModelData.Unmap(); - - Definitions::TintData td; - td.GlowTint = models[i].GlowTint; - td.Tint = models[i].Tint; - td.PAD = 0; - td.PAD2 = 0; - int s = sizeof(Definitions::TintData); - - data = Render::Resources::Color.Map(); - memcpy(data,&td,sizeof(Definitions::TintData)); - Render::Resources::Color.Unmap(); - - if(info->Material.size()) - { - Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); - } - - - info->Vertices->Apply(); - if(info->Indexed) - { - info->Indecies->Apply(); - Oyster::Graphics::Core::deviceContext->DrawIndexed(info->IndexCount,0,0); - } - else - { - Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0); - } - } - } - } - - void BlurGlow() - { - Definitions::BlurrData bd; - bd.BlurMask = Math::Float4(1,1,1,1); - bd.StopX = (UINT)Core::resolution.x/2; - bd.StopY = (UINT)Core::resolution.y; - bd.StartX = 0; - bd.StartY = (UINT)Core::resolution.y/2; - - void* data = Resources::Blur::Data.Map(); - memcpy(data,&bd,sizeof(Definitions::BlurrData)); - Resources::Blur::Data.Unmap(); - - Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); - Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); - - Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); - Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); - } - - void BlurSSAO() - { - Definitions::BlurrData bd; - bd.BlurMask = Math::Float4(0,0,0,1); - bd.StopX = (UINT)Core::resolution.x/2; - bd.StopY = (UINT)Core::resolution.y/2; - bd.StartX = 0; - bd.StartY = 0; - - void* data = Resources::Blur::Data.Map(); - memcpy(data,&bd,sizeof(Definitions::BlurrData)); - Resources::Blur::Data.Unmap(); - - Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); - Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); - - Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); - Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); - } - - void RenderModel(Model::ModelInfo* info, Definitions::RenderInstanceData* rid , int count) - { - if(count < 1) - return; - if(info->Material.size()) - { - Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); - } - info->Vertices->Apply(); - if(info->Indexed) - { - info->Indecies->Apply(); - } - - void* data = Resources::Gather::InstancedData.Map(); - memcpy(data, rid, sizeof(Definitions::RenderInstanceData)*count); - Resources::Gather::InstancedData.Unmap(); - - if(info->Indexed) - { - Core::deviceContext->DrawIndexedInstanced(info->IndexCount,count,0,0,0); - //Core::deviceContext->DrawIndexed(info->IndexCount,0,0); + Resources::RenderData[info]->rid[Resources::RenderData[info]->Models++] = rid; } else { - Core::deviceContext->DrawInstanced(info->VertexCount,count,0,0); - //Core::deviceContext->Draw(info->VertexCount,0); + Definitions::PerModel pm; + Math::Float3x3 normalTransform; + normalTransform = Math::Float3x3(models[i].WorldMatrix.v[0].xyz, models[i].WorldMatrix.v[1].xyz, models[i].WorldMatrix.v[2].xyz); + normalTransform.Transpose().Invert(); + Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f)); + pm.WV = View * m; + pm.WVP = Projection * View * models[i].WorldMatrix; + + Model::ModelInfo* info = models[i].info; + + // Bone animation buffers + Math::Matrix SkinTransform[100]; + Math::Matrix BoneAnimated[100]; + Math::Matrix BoneAbsAnimated[100]; + + pm.Animated = AnimateAbsoluteBones + ( + *info, deltaTime, + models[i].Animation, + ::Utility::StaticArray::NumElementsOf( models[i].Animation ), + SkinTransform, BoneAnimated, BoneAbsAnimated + ); + + void* data = Resources::Gather::ModelData.Map(); + memcpy(data,&(pm),sizeof(pm)); + Resources::Gather::ModelData.Unmap(); + + Definitions::TintData td; + td.GlowTint = models[i].GlowTint; + td.Tint = models[i].Tint; + td.PAD = 0; + td.PAD2 = 0; + int s = sizeof(Definitions::TintData); + + data = Render::Resources::Color.Map(); + memcpy(data,&td,sizeof(Definitions::TintData)); + Render::Resources::Color.Unmap(); + + if(info->Material.size()) + { + Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); + } + + + info->Vertices->Apply(); + if(info->Indexed) + { + info->Indecies->Apply(); + Oyster::Graphics::Core::deviceContext->DrawIndexed(info->IndexCount,0,0); + } + else + { + Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0); + } } - } + } + } + void BlurGlow() + { + Definitions::BlurrData bd; + bd.BlurMask = Math::Float4(1,1,1,1); + bd.StopX = (UINT)Core::resolution.x/2; + bd.StopY = (UINT)Core::resolution.y; + bd.StartX = 0; + bd.StartY = (UINT)Core::resolution.y/2; + + void* data = Resources::Blur::Data.Map(); + memcpy(data,&bd,sizeof(Definitions::BlurrData)); + Resources::Blur::Data.Unmap(); - void DefaultRenderer::EndFrame() + Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); + + Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); + Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); + } + + void BlurSSAO() + { + Definitions::BlurrData bd; + bd.BlurMask = Math::Float4(0,0,0,1); + bd.StopX = (UINT)Core::resolution.x/2; + bd.StopY = (UINT)Core::resolution.y/2; + bd.StartX = 0; + bd.StartY = 0; + + void* data = Resources::Blur::Data.Map(); + memcpy(data,&bd,sizeof(Definitions::BlurrData)); + Resources::Blur::Data.Unmap(); + + Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass); + Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1); + + Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass); + Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1); + } + + void RenderModel(Model::ModelInfo* info, Definitions::RenderInstanceData* rid , int count) + { + if(count < 1) + return; + if(info->Material.size()) { - Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::InstancedPass); - Resources::Gather::InstancedData.Apply(1); + Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0])); + } + info->Vertices->Apply(); + if(info->Indexed) + { + info->Indecies->Apply(); + } - for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) + void* data = Resources::Gather::InstancedData.Map(); + memcpy(data, rid, sizeof(Definitions::RenderInstanceData)*count); + Resources::Gather::InstancedData.Unmap(); + + if(info->Indexed) + { + Core::deviceContext->DrawIndexedInstanced(info->IndexCount,count,0,0,0); + //Core::deviceContext->DrawIndexed(info->IndexCount,0,0); + } + else + { + Core::deviceContext->DrawInstanced(info->VertexCount,count,0,0); + //Core::deviceContext->Draw(info->VertexCount,0); + } + } + + + void DefaultRenderer::EndFrame() + { + Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::InstancedPass); + Resources::Gather::InstancedData.Apply(1); + + for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) + { + RenderModel((*i).first,(*i).second->rid, (*i).second->Models); + } + + Core::PipelineManager::SetRenderPass(Resources::Light::Pass); + + Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); + + BlurGlow(); + + BlurSSAO(); + + Core::PipelineManager::SetRenderPass(Resources::Post::Pass); + + Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); + + Core::swapChain->Present(0,0); + } + + /******************************************************** + * Private Prototype Method Implementations + ********************************************************/ + + void AnimateRelativeBones( const Model::ModelInfo &info, Model::AnimationData &anim, Math::Matrix relativeBuffer[] ) + { + for( int i = 0; i < info.BoneCount; ++i ) + { + Model::Bone Bone = info.bones[i]; + relativeBuffer[i] = Bone.Relative; + } + + const Model::Animation &A = *anim.AnimationPlaying; + + while( anim.AnimationTime > A.duration && anim.LoopAnimation ) + anim.AnimationTime -= (float)A.duration; + + float position = anim.AnimationTime; + for( int i = 0; i < A.Bones; ++i ) + { + //find current frame + int nrOfFrames = A.Frames[i]; + Model::Frame PFrame = A.Keyframes[i][nrOfFrames-1]; + Model::Frame NFrame = A.Keyframes[i][nrOfFrames-1]; + bool FrameFound = false; + + for (int j = 0; j < nrOfFrames; j++) { - RenderModel((*i).first,(*i).second->rid, (*i).second->Models); + if(position < A.Keyframes[i][j].time) + { + PFrame = A.Keyframes[i][j-1]; + NFrame = A.Keyframes[i][j]; + break; + } } - Core::PipelineManager::SetRenderPass(Resources::Light::Pass); - - Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); - - BlurGlow(); - - BlurSSAO(); - - Core::PipelineManager::SetRenderPass(Resources::Post::Pass); - - Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); - - Core::swapChain->Present(0,0); + float denominator = (float)(NFrame.time - PFrame.time); + + if( denominator != 0.0f ) + { + float inter = (float)((position - PFrame.time) / denominator); + Math3D::InterpolateOrientation_UsingNonRigidNlerp( PFrame.bone.Relative,NFrame.bone.Relative, inter, relativeBuffer[PFrame.bone.Parent] ); + } + else + { + relativeBuffer[PFrame.bone.Parent] = PFrame.bone.Relative; + } } + } + + enum Conflict + { + Conflict_detected, + Conflict_useA, + Conflict_useB + }; + + Conflict DetectBoneAnimationConflict( const Model::Bone &raw, const Math::Matrix &animBoneA, const Math::Matrix &animBoneB ); + + void MergeAnimatedBones( const Model::Bone raw[], int numBones, Math::Float interpolation, const Math::Matrix *animatedBoneSourceA, Math::Matrix animatedBoneSourceB_Target[] ) + { + for( int i = 0; i < numBones; ++i ) + { + switch( DetectBoneAnimationConflict(raw[i], animatedBoneSourceA[i], animatedBoneSourceB_Target[i]) ) + { + case Conflict_detected: + Math3D::InterpolateOrientation_UsingNonRigidNlerp( animatedBoneSourceA[i], animatedBoneSourceB_Target[i], interpolation, animatedBoneSourceB_Target[i] ); + break; + case Conflict_useA: + animatedBoneSourceB_Target[i] = animatedBoneSourceA[i]; + break; + default: case Conflict_useB: break; + } + } + } + + Conflict DetectBoneAnimationConflict( const Model::Bone &raw, const Math::Matrix &animBoneA, const Math::Matrix &animBoneB ) + { + if( animBoneA == raw.Relative ) + return Conflict_useB; + + if( animBoneB == raw.Relative ) + return Conflict_useA; + + return Conflict_detected; + } + + int AnimateAbsoluteBones( const Model::ModelInfo &info, Math::Float deltaTime, Model::AnimationData &anim, Math::Matrix SkinTransformBuffer[], Math::Matrix BoneAnimationBuffer_Relative[], Math::Matrix BoneAnimationBuffer_Absolute[] ) + { + if( !info.Animated || (anim.AnimationPlaying == nullptr) ) + { // no animation + return 0; + } + + anim.AnimationTime += deltaTime; + AnimateRelativeBones( info, anim, BoneAnimationBuffer_Relative ); + + for( int i = 0; i < info.BoneCount; ++i ) + { + Model::Bone Bone = info.bones[i]; + SkinTransformBuffer[i] = Bone.Absolute.GetInverse(); + BoneAnimationBuffer_Absolute[i] = Bone.Absolute; + } + + Definitions::AnimationData am; + + for( int i = 0; i < info.BoneCount; ++i ) + { + //calculate Absolute Animation Transform + BoneAnimationBuffer_Absolute[i] = BoneAnimationBuffer_Absolute[info.bones[i].Parent] * BoneAnimationBuffer_Relative[i]; + + //write data to am + am.AnimatedData[i] = (BoneAnimationBuffer_Absolute[i] * SkinTransformBuffer[i]); + } + + void *data = Resources::Gather::AnimationData.Map(); + memcpy( data, &am, sizeof(Definitions::AnimationData) ); + Resources::Gather::AnimationData.Unmap(); + + return 1; + } + + int AnimateAbsoluteBones( const Model::ModelInfo &info, Math::Float deltaTime, Model::AnimationData anim[], int numAnimations, Math::Matrix SkinTransformBuffer[], Math::Matrix BoneAnimationBuffer_Relative[], Math::Matrix BoneAnimationBuffer_Absolute[] ) + { + if( !info.Animated || (numAnimations < 1) ) + { // no animation + return 0; + } + int isAnimated = 0; + + // for each animation + for( int i = 0; i < numAnimations; ++i ) + { + if( anim[i].AnimationPlaying != nullptr ) + { + anim[i].AnimationTime += deltaTime; + if( isAnimated ) + { + AnimateRelativeBones( info, anim[i], BoneAnimationBuffer_Absolute ); // Borrowing BoneAnimationBuffer_Absolute as interim buffer + MergeAnimatedBones( info.bones, info.BoneCount, 0.5f, BoneAnimationBuffer_Absolute, BoneAnimationBuffer_Relative ); + } + else + { + isAnimated = 1; + AnimateRelativeBones( info, anim[i], BoneAnimationBuffer_Relative ); + } + } + } + + if( isAnimated ) + { + for( int i = 0; i < info.BoneCount; ++i ) + { + Model::Bone Bone = info.bones[i]; + SkinTransformBuffer[i] = Bone.Absolute.GetInverse(); + BoneAnimationBuffer_Absolute[i] = Bone.Absolute; + } + + Definitions::AnimationData am; + + for( int i = 0; i < info.BoneCount; ++i ) + { + //calculate Absolute Animation Transform + BoneAnimationBuffer_Absolute[i] = BoneAnimationBuffer_Absolute[info.bones[i].Parent] * BoneAnimationBuffer_Relative[i]; + + //write data to am + am.AnimatedData[i] = (BoneAnimationBuffer_Absolute[i] * SkinTransformBuffer[i]); + } + + void *data = Resources::Gather::AnimationData.Map(); + memcpy( data, &am, sizeof(Definitions::AnimationData) ); + Resources::Gather::AnimationData.Unmap(); + } + + return isAnimated; + } } } } \ No newline at end of file From 3e72421cb5d6773360eb63656f8b6534a38a9f39 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 27 Feb 2014 09:04:12 +0100 Subject: [PATCH 02/46] half baked tiles --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 2 +- .../GameClient/GameClientState/GameState.cpp | 10 +- .../GameServerDebugEnvironment/Source.cpp | 2 +- Code/Misc/OysterMath/LinearMath.h | 2 +- .../Definitions/GraphicalDefinition.h | 3 +- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 6 +- .../OysterGraphics/Render/DefaultRenderer.cpp | 14 +- Code/OysterGraphics/Render/DefaultRenderer.h | 2 +- Code/OysterGraphics/Render/Resources.h | 2 +- .../Shader/Passes/Light/Defines.hlsli | 18 ++- .../Shader/Passes/Light/LightCalc.hlsli | 26 ++-- .../Shader/Passes/Light/LightPass.hlsl | 124 +++++++++++------- .../Shader/Passes/Light/SSAO.hlsli | 5 +- .../Shader/Passes/Post/PostPass.hlsl | 5 +- 14 files changed, 139 insertions(+), 82 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index b461f908..535357e7 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -118,7 +118,7 @@ namespace DanBias Graphics::API::Update( data.capFrame ); if(Render() != S_OK) return DanBiasClientReturn_Error; - data.capFrame -= 0.03f; + data.capFrame = 0.0f; } if(data.networkClient.IsConnected()) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index b608a4f3..92b3c7e8 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -73,9 +73,15 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 1.0f, 100.0f ); + + // HACK: debug test + Matrix debug_p = this->privData->camera.GetProjectionMatrix(); + Float debug_n = - debug_p.m34 / debug_p.m33; + Float debug_f = debug_p.m34 / (1.0f - debug_p.m33); + Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); - gfxOp.AmbientValue = 0.5f; + gfxOp.AmbientValue = 0.3f; gfxOp.GlobalGlowTint = Math::Float3(1,1,1); gfxOp.GlobalTint = Math::Float3(1,1,1); Graphics::API::SetOptions(gfxOp); diff --git a/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp b/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp index 3357f52c..8ec4c9aa 100644 --- a/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp +++ b/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp @@ -32,7 +32,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh GameServerAPI::GameSetGameMode(L"free-for-all"); GameServerAPI::GameSetGameName(L"DebugServer"); GameServerAPI::GameSetGameTime(15); - GameServerAPI::GameSetMapName(L"erik_250.bias"); + GameServerAPI::GameSetMapName(L"manyLights.bias"); GameServerAPI::GameSetMaxClients(10); if(GameServerAPI::GameStart(true)) diff --git a/Code/Misc/OysterMath/LinearMath.h b/Code/Misc/OysterMath/LinearMath.h index 5b87d83d..c4158035 100644 --- a/Code/Misc/OysterMath/LinearMath.h +++ b/Code/Misc/OysterMath/LinearMath.h @@ -78,7 +78,7 @@ inline ::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra:: { return ::LinearAlgebra::Vector4( (matrix.m11 * vector.x) + (matrix.m12 * vector.y) + (matrix.m13 * vector.z) + (matrix.m14 * vector.w), (matrix.m21 * vector.x) + (matrix.m22 * vector.y) + (matrix.m23 * vector.z) + (matrix.m24 * vector.w), - (matrix.m23 * vector.x) + (matrix.m32 * vector.y) + (matrix.m33 * vector.z) + (matrix.m34 * vector.w), + (matrix.m31 * vector.x) + (matrix.m32 * vector.y) + (matrix.m33 * vector.z) + (matrix.m34 * vector.w), (matrix.m41 * vector.x) + (matrix.m42 * vector.y) + (matrix.m43 * vector.z) + (matrix.m44 * vector.w) ); } diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index 77aecdc8..5572be72 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -35,9 +35,10 @@ namespace Oyster { Math::Float4x4 InvProj; Math::Float4x4 Proj; - Math::Float2 Pixels; + float FoV; int Lights; float SSAORadius; + float pad; Oyster::Math::Float4x4 View; }; diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index ee3d9f8a..46145430 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -20,6 +20,7 @@ namespace Oyster std::vector Lights; float deltaTime; int MostModel; + float FoV; #ifdef _DEBUG Model::Model* cube; Model::Model* sphere; @@ -85,6 +86,7 @@ namespace Oyster void API::SetProjection(const Math::Float4x4& projection) { Projection = projection; + FoV = 2 * std::atanf(1/projection.m[1][1]); } void API::SetView(const Math::Float4x4& view) @@ -96,11 +98,11 @@ namespace Oyster { if(Lights.size()) { - Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size()); + Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size(), FoV); } else { - Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0); + Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0, FoV); } } diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 4b979be8..4e9d197d 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -14,7 +14,7 @@ namespace Oyster { Definitions::Pointlight pl; - void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights) + void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights, float Fov) { Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); @@ -25,7 +25,7 @@ namespace Oyster Definitions::LightConstants lc; lc.InvProj = Projection.GetInverse(); - lc.Pixels = Core::resolution; + lc.FoV = Fov; lc.Lights = numLights; lc.View = View; lc.Proj = Projection; @@ -36,7 +36,15 @@ namespace Oyster Resources::Light::LightConstantsData.Unmap(); data = Resources::Light::PointLightsData.Map(); - memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); + Definitions::Pointlight* plData = (Definitions::Pointlight*)data; + for(int i=0; i < numLights; ++i) + { + plData[i].Pos = (View * Math::Float4(Lights[i].Pos,1)).xyz; + plData[i].Radius = Lights[i].Radius; + plData[i].Color = Lights[i].Color; + plData[i].Bright = Lights[i].Bright; + } + //memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); Resources::Light::PointLightsData.Unmap(); for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ ) diff --git a/Code/OysterGraphics/Render/DefaultRenderer.h b/Code/OysterGraphics/Render/DefaultRenderer.h index 1a5cdcc0..74a1e4ff 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.h +++ b/Code/OysterGraphics/Render/DefaultRenderer.h @@ -13,7 +13,7 @@ namespace Oyster class DefaultRenderer { public: - static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights); + static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights, float Fov); static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float DeltaTime = 0); static void EndFrame(); }; diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index fe1393b9..d7f66199 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -24,7 +24,7 @@ namespace Oyster static const int GBufferSize = 3; static const int LBufferSize = 3; - static const int MaxLightSize = 100; + static const int MaxLightSize = 1024; //! GBuffers //! 0 = Diffuse + Glow diff --git a/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli b/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli index fb125b12..0db1b98f 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli @@ -19,20 +19,24 @@ cbuffer LightConstants : register(b0) { float4x4 InvProj; float4x4 Proj; - float2 Pixels; + float FoV; int Lights; float SSAORadius; + float pad; float4x4 View; } struct FrustrumPoints { - float3 v0; - float3 v1; - float3 v2; - float3 v3; - float3 v4; - float3 v5; + float3 NUL; + float3 NUR; + float3 NDL; + float3 NDR; + + float3 FUL; + float3 FUR; + float3 FDL; + float3 FDR; }; Texture2D DiffuseGlow : register(t0); diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli index 81fa2fa1..36606f01 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli @@ -4,10 +4,18 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) { DiffSpec output; float4 normalSpec = NormalSpec[texCoord]; - float4 LPos = mul(View, float4(pl.Pos, 1)); - float3 lightVec = LPos.xyz - pos.xyz; + float4 LPos = float4(pl.Pos, 1); + float3 lightVec = LPos.xyz - pos; float d = length(lightVec); + lightVec = lightVec/d; + + if(d > pl.Radius) + { + output.Diffuse = float3(0,0,0); + output.Specular = float3(0,0,0); + return output; + } float diffFactor = max(dot(lightVec, normalSpec.xyz), 0.0f); float3 v = reflect(-lightVec, normalSpec.xyz); @@ -15,21 +23,13 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord) //Check att later float att = max( 0, 1 - (d / pl.Radius)); //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; - if(d > pl.Radius) - { - output.Diffuse = float3(0,0,0); - output.Specular = float3(0,0,0); - } + float SpecCo = normalSpec.w < 1 ? 0.0f : 1.0f; + output.Specular = output.Specular * SpecCo; return output; -} - -bool intersects(FrustrumPoints box, int Index) -{ - return true; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl index ddaed99e..78d7975b 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl @@ -8,20 +8,18 @@ //Calc Ambience Done //Write Glow -#define EXPAND 1024.0f -#define SHRINK 1.0f/EXPAND #define UINT_MAX 0xFFFFFFFF #define FLOAT_MAX 3.402823466e+38 #define BLOCKSIZE 16 #define NUMTHREADS BLOCKSIZE * BLOCKSIZE -#define MAXLIGHTS 100 +#define MAXLIGHTS 1024 +#define TEXTURESPREAD 1/255 // -- Shared Memory ------------------------------------------------- // -groupshared uint iMinDepth = UINT_MAX, - iMaxDepth = 0; -groupshared uint numVisiblePointLights = 0, +groupshared uint iMinDepth, iMaxDepth; +groupshared uint numVisiblePointLights, visiblePointlightIndex[MAXLIGHTS]; // ------------------------------------------------------------------ // @@ -29,77 +27,110 @@ groupshared uint numVisiblePointLights = 0, [numthreads(BLOCKSIZE, BLOCKSIZE, 1)] void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex ) { - float2 UV = DTid.xy / Pixels; + float2 UV = DTid.xy / (float2)Diffuse.Length.xy; UV.x = UV.x * 2 - 1; UV.y = 1 - 2 * UV.y; float3 posN = float3(UV, DepthTexture[DTid.xy].x); + + float3 ViewPos = ToVpos(DTid.xy, UV); + + if(GI==0) + { + numVisiblePointLights = 0; + iMinDepth = 0x7F7FFFFF; + iMaxDepth = 0; + } + GroupMemoryBarrierWithGroupSync(); // store and load shared minDepth and maxDepth - float minDepth = 0.0f, maxDepth = 0.0f, - depth = posN.z; + float minDepth = 0.0f, maxDepth = 0.0f; { - uint uidepth = (uint)( depth * EXPAND); - InterlockedMin( iMinDepth, uidepth ); - InterlockedMax( iMaxDepth, uidepth ); + InterlockedMin( iMinDepth, asuint(ViewPos.z) ); + InterlockedMax( iMaxDepth, asuint(ViewPos.z) ); GroupMemoryBarrierWithGroupSync(); - minDepth = (float)( iMinDepth ) * SHRINK; - maxDepth = (float)( iMaxDepth ) * SHRINK; + minDepth = asfloat(iMinDepth); + maxDepth = asfloat(iMaxDepth); } // -- Switching to LightCulling ------------------------------------- // //define collision volume - float2 size = BLOCKSIZE / Pixels; - FrustrumPoints tile; - tile.v0 = float3(size * Gid,minDepth); - tile.v1 = float3(tile.v0.xy+size,maxDepth); - tile.v2 = float3(tile.v1.xy, minDepth); - tile.v3 = float3(tile.v0.x,tile.v1.y,minDepth); - tile.v4 = float3(tile.v1.x, tile.v0.y, minDepth); - tile.v5 = float3(tile.v0.xy, maxDepth); + float2 tilescale = float2(Diffuse.Length.xy) * rcp(float(2 * BLOCKSIZE)); + float2 tilebias = tilescale - float2(Gid.xy); + // Now work out composite projection matrix + // Relevant matrix columns for this tile frusta + float4 c1 = float4(Proj._11 * tilescale.x, 0.0f, tilebias.x, 0.0f); + float4 c2 = float4(0.0f, -Proj._22 * tilescale.y, tilebias.y, 0.0f); + float4 c4 = float4(0.0f, 0.0f, 1.0f, 1.0f); + // Derive frustum planes + float4 frustumPlanes[6]; + // Sides + frustumPlanes[0] = c4 - c1; + frustumPlanes[1] = c4 + c1; + frustumPlanes[2] = c4 - c2; + frustumPlanes[3] = c4 + c2; + // Near/far + frustumPlanes[4] = float4(0.0f, 0.0f, 1.0f, -minDepth); + frustumPlanes[5] = float4(0.0f, 0.0f, -1.0f, maxDepth); + + // Normalize frustum planes (near/far already normalized) + [unroll] + for (uint i = 0; i < 4; ++i) + { + frustumPlanes[i] *= rcp(length(frustumPlanes[i].xyz)); + } // culling the tile's near and far to minDepth & maxDepth ( with tolerance ) - uint numPass = (Lights + NUMTHREADS - 1) / NUMTHREADS; - numPass = min( numPass, MAXLIGHTS / NUMTHREADS ); + for(uint lightIndex = GI; lightIndex < Lights; lightIndex += NUMTHREADS) + { + PointLight pl = Points[lightIndex]; + + bool inFrustrum = true; + float d = dot(frustumPlanes[0], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); + d = dot(frustumPlanes[1], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); + d = dot(frustumPlanes[2], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); + d = dot(frustumPlanes[3], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); + d = dot(frustumPlanes[4], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); + d = dot(frustumPlanes[5], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); - for( uint passI = 0; passI < numPass; ++passI ) + [branch] + if(inFrustrum) { - uint lightIndex = (passI * NUMTHREADS) + GI; - lightIndex = min( lightIndex, Lights ); - - if( lightIndex < Lights ) - if( intersects(tile, lightIndex) ) - { - uint offset; - InterlockedAdd( numVisiblePointLights, 1, offset ); - visiblePointlightIndex[offset] = lightIndex; - } + uint offset; + InterlockedAdd( numVisiblePointLights, 1, offset ); + visiblePointlightIndex[offset] = lightIndex; } + } GroupMemoryBarrierWithGroupSync(); - float3 ViewPos = ToVpos(DTid.xy, UV); DiffSpec Shaded; Shaded.Diffuse = float3(0,0,0); Shaded.Specular = float3(0,0,0); - for(int i = 0; i < Lights; ++i) + for(int i = 0; i < numVisiblePointLights; ++i) { - DiffSpec light = LightCalc(Points[i], ViewPos, DTid.xy); + DiffSpec light = LightCalc(Points[visiblePointlightIndex[i]], ViewPos, DTid.xy); Shaded.Diffuse += light.Diffuse; Shaded.Specular += light.Specular; } - Diffuse[DTid.xy] = float4(Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz,0); + Diffuse[DTid.xy] = float4(Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz,1); Specular[DTid.xy] = float4(Shaded.Specular, 0); @@ -113,14 +144,15 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uin DiffBase = DiffBase / 4; float4 DepthBase = DepthTexture[DTid.xy]; - DepthBase = DepthTexture[DTid.xy + uint2(1,0)]; - DepthBase = DepthTexture[DTid.xy + uint2(0,1)]; - DepthBase = DepthTexture[DTid.xy + uint2(1,1)]; + DepthBase += DepthTexture[DTid.xy + uint2(1,0)]; + DepthBase += DepthTexture[DTid.xy + uint2(0,1)]; + DepthBase += DepthTexture[DTid.xy + uint2(1,1)]; DepthBase = DepthBase /4; - Ambient[DTid.xy/2] = float4(DiffBase.xyz, AmbValue); - Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy]; - Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffBase.xyz * DiffBase.w ,DiffBase.w); - Ambient[DTid.xy/2 + Pixels/2] = float4(NormalSpec[DTid.xy].xyz * float3(1,1,-1),1); + Ambient[DTid.xy/2] = float4(DiffBase.xyz , AmbValue); + //Ambient[DTid.xy/2] = float4(DiffBase.xyz, 1); + Ambient[DTid.xy/2 + float2(Diffuse.Length.x/2, 0)] = GUI[DTid.xy]; + Ambient[DTid.xy/2 + float2(0, Diffuse.Length.y/2)] = float4(DiffBase.xyz * DiffBase.w ,DiffBase.w); + Ambient[DTid.xy/2 + Diffuse.Length.xy/2] = float4(numVisiblePointLights * (1.0f/Lights), 0, 0 ,1); } } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli b/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli index c71cb4d5..10cb00f6 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli @@ -23,6 +23,7 @@ float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) float3 sampled = mul(tbn, SSAOKernel[i].xyz); sampled = sampled * Radius + pos; + //project sample to get uv.xy float4 ProjOffset = float4(sampled,1); ProjOffset = mul(Proj, ProjOffset); @@ -35,7 +36,7 @@ float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) // get depth from that point in screenspace uint2 texCoord; - texCoord = (uint2)(offset.xy * Pixels); + texCoord = (uint2)(offset.xy * Diffuse.Length.xy); float3 ViewPos = ToVpos(texCoord, UV); float sampleDepth = ViewPos.z; @@ -43,6 +44,8 @@ float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID) //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 += rangeCheck; + } occlusion /= (float)(SSAOKernel.Length.x); occlusion = 1.0f - occlusion; diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index c3f7e69e..87c7c95a 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -27,7 +27,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) SSAO = SSAO / 16; - float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); + float4 Light = Diffuse[DTid.xy];// + saturate(Specular[DTid.xy]); float3 Amb = Ambient[DTid.xy/2].xyz * SSAO * Color; float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; @@ -43,5 +43,6 @@ void main( uint3 DTid : SV_DispatchThreadID ) //Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(Output.Length*0.5f)].xyz,1); //Output[DTid.xy] = SSAO * float4(1,1,1,1); - //Output[DTid.xy] = Ambient[DTid.xy]; + Output[DTid.xy] = Ambient[DTid.xy]; + //Output[DTid.xy] = Diffuse[DTid.xy]; } \ No newline at end of file From 5c023acc5b2e301189fd6a50185d2872c6bdcceb Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 25 Feb 2014 10:37:33 +0100 Subject: [PATCH 03/46] merge --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 2 + Code/Game/GameLogic/CollisionManager.cpp | 67 ++++++++++++++++++- Code/Game/GameLogic/DynamicObject.cpp | 26 +++++++ Code/Game/GameLogic/DynamicObject.h | 9 +++ Code/Game/GameLogic/GameLogicStates.h | 3 + Code/Game/GameLogic/Level.cpp | 10 +-- Code/Game/GameLogic/Player.cpp | 47 ++++++++++--- Code/Game/GameLogic/Player.h | 7 ++ 8 files changed, 156 insertions(+), 15 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index b988451f..c6b0df0a 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -99,6 +99,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float forcePushData args; args.pushForce = pushForce; + args.p = this->owner; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); @@ -136,6 +137,7 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); forcePushData args; args.pushForce = -pushForce; + args.p = this->owner; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 90a2aefe..8a360059 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -113,7 +113,7 @@ using namespace GameLogic; Object *realObjA = ((Object*)(objA->GetCustomTag())); - Object *realObjB = (Object*)objB->GetCustomTag(); //needs to be changed? + Object *realObjB = (Object*)objB->GetCustomTag(); ExplosiveCrate* crate; if(!realObjA) @@ -166,9 +166,13 @@ using namespace GameLogic; Player *hitPlayer = (Player*)realObj; hitPlayer->DamageLife(ExplosionSource->extraDamageOnCollision); //hitPlayer->GetRigidBody()->ApplyImpulse(force); + + //hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision()); + realObj->GetRigidBody()->ApplyImpulse(force * 5); //do shredding damage } + } @@ -226,6 +230,58 @@ using namespace GameLogic; { return Physics::ICustomBody::SubscriptMessage_none; } + + void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *objA, Oyster::Physics::ICustomBody *objB, Oyster::Math::Float kineticEnergyLoss) + { + + DynamicObject *realObjA = dynamic_cast((Object*)objA->GetCustomTag()); + + DynamicObject *realObjB = dynamic_cast((Object*)objB->GetCustomTag()); + + if(!realObjA || !realObjB) // one of the objects cannot be cast into a dynamicObject and so we leave the function + { + return; + } + + //check which obj is the one that is already affected, if both are then use the special case of changing ownership. + if(realObjA->getAffectingPlayer() == NULL && realObjB->getAffectingPlayer() == NULL) //None of the objects have a player affecting them + { + return;//leave function as the are not to transfer any ownership + } + + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() == NULL) + { + //realobjA is the affectedObject, transfer this to realobjB + realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + + } + if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) + { + //realobjB is the affectedObject, transfer this to realobjA + realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + + } + + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL) + { + //Both objects have a player affecting them, now use the special case + if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) + { + //realObjA is the winner and will change Bs ownership to A + realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + } + else + { + realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + //realObjB is the winner and will change As ownership to B + } + } + + + + + } + Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; @@ -250,7 +306,16 @@ using namespace GameLogic; if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World) return; + + obj->ApplyImpulse(((forcePushData*)(args))->pushForce); + + DynamicObject *dynamicObj = dynamic_cast(realObj); + + if(dynamicObj) + { + dynamicObj->SetAffectedBy(*((forcePushData*)(args))->p); + } } void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index e6d9ff49..961d29fc 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -1,5 +1,6 @@ #include "DynamicObject.h" #include "CollisionManager.h" +#include "Player.h" using namespace GameLogic; using namespace Oyster::Math; @@ -10,6 +11,7 @@ DynamicObject::DynamicObject() { this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) @@ -17,12 +19,14 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev { this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) { this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -31,6 +35,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev this->extraDamageOnCollision = extraDamageOnCollision; this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -39,6 +44,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P this->extraDamageOnCollision = extraDamageOnCollision; this->isReleased = false; this->isActive = true; + this->affectedBy = NULL; } DynamicObject::~DynamicObject(void) { @@ -74,4 +80,24 @@ void DynamicObject::Activate() { this->isActive = true; this->isReleased = false; +} + +void DynamicObject::SetAffectedBy(Player &player) +{ + this->affectedBy = &player; + if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player + { + player.AddAffectedObject(*this); + } + +} + +Player* DynamicObject::getAffectingPlayer() +{ + return this->affectedBy; +} + +void DynamicObject::RemoveAffectedBy() +{ + this->affectedBy = NULL; } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 8a32e849..d1bb63bc 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -9,6 +9,7 @@ namespace GameLogic { + class Player; class DynamicObject : public Object { @@ -28,9 +29,17 @@ namespace GameLogic void Inactivate(); void Activate(); + void SetAffectedBy(GameLogic::Player &player); + void RemoveAffectedBy(); + GameLogic::Player* getAffectingPlayer(); + + static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + private: bool isActive; bool isReleased; + protected: + GameLogic::Player *affectedBy; }; diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 9ae0d482..ae4e192f 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -2,8 +2,10 @@ #define GAMELOGICSTATES_H #include "OysterMath.h" + namespace GameLogic { + class Player; enum PLAYER_MOVEMENT { PLAYER_MOVEMENT_FORWARD = 0, @@ -41,6 +43,7 @@ namespace GameLogic struct forcePushData { Oyster::Math::Float3 pushForce; + Player *p; }; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 922d2a8f..a4252bc4 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -59,12 +59,12 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_RedExplosiveBox: @@ -81,12 +81,12 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_CrystalFormation: @@ -98,7 +98,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_JumpPad: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 69569d44..4dcdacaa 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -18,6 +18,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { weapon = new Weapon(2,this); + AffectedObjects.Reserve(15); + this->life = 100; this->teamID = teamID; @@ -46,6 +48,9 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { weapon = new Weapon(2,this); + AffectedObjects.Reserve(15); + + this->life = 100; this->teamID = teamID; this->playerState = PLAYER_STATE_IDLE; @@ -213,6 +218,16 @@ void Player::BeginFrame() void Player::EndFrame() { + //check if there are any objects that can be removed from the AffectedObjects list + for(int i = 0; i < this->AffectedObjects.Size(); i++) + { + if((this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) + { + this->AffectedObjects[i]->RemoveAffectedBy(); + this->AffectedObjects.Remove(i); + } + + } } @@ -334,17 +349,31 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - if( this->playerState != PLAYER_STATE_DEAD) - { - this->life -= damage; - this->gameInstance->onDamageTakenFnc( this, this->life); - if(this->life <= 0) + this->life -= damage; + this->gameInstance->onDamageTakenFnc( this, this->life); + + if(this->life <= 0) + { + this->life = 0; + playerState = PLAYER_STATE_DEAD; + this->deathTimeLeft = this->deathTime; + this->gameInstance->onDeadFnc(this, this->deathTimeLeft); + } + +} + +void Player::AddAffectedObject(DynamicObject &AffectedObject) +{ + //check if object already exists in the list, if so then do not add + for(int i = 0; i < AffectedObjects.Size(); i++) + { + if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) { - this->life = 0; - playerState = PLAYER_STATE_DEAD; - this->deathTimeLeft = this->deathTime; - this->gameInstance->onDeadFnc(this, this->deathTimeLeft); + //object already exists, exit function + return; } } + //else you add the object to the stack + AffectedObjects.Push(&AffectedObject); } diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 001c9141..99af52c5 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -7,6 +7,7 @@ #include "GameLogicStates.h" #include "OysterMath.h" #include "DynamicObject.h" +#include "DynamicArray.h" namespace GameLogic @@ -49,6 +50,8 @@ namespace GameLogic void SetLookDir(const Oyster::Math3D::Float3& lookDir); void TurnLeft(Oyster::Math3D::Float deltaRadians); + + void AddAffectedObject(DynamicObject &AffectedObject); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -77,10 +80,14 @@ namespace GameLogic void EndFrame(); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + + private: void Jump(); private: + Utility::DynamicMemory::DynamicArray AffectedObjects; + Oyster::Math::Float life; int teamID; Weapon *weapon; From ba618387036debf2fd722acb8cb18139a7fc40f3 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 25 Feb 2014 11:20:46 +0100 Subject: [PATCH 04/46] GL - only 1 player can manipulate a object at a time --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 2 +- Code/Game/GameLogic/CollisionManager.cpp | 14 +++++++++++-- Code/Game/GameLogic/DynamicObject.cpp | 20 +++++++++++++++++++ Code/Game/GameLogic/DynamicObject.h | 5 +++++ Code/Game/GameLogic/Player.cpp | 2 +- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index c6b0df0a..1f86bf60 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -80,7 +80,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float { pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); - + ((DynamicObject*)(heldObject->GetCustomTag()))->RemoveManipulation(); hasObject = false; heldObject = NULL; return; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 8a360059..d60d16ce 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -309,6 +309,7 @@ using namespace GameLogic; obj->ApplyImpulse(((forcePushData*)(args))->pushForce); + DynamicObject *dynamicObj = dynamic_cast(realObj); @@ -333,12 +334,21 @@ using namespace GameLogic; Object* realObj = (Object*)(obj->GetCustomTag()); //check so that it is an object that you can pickup - switch(realObj->GetObjectType()) + DynamicObject *dynamicObj = dynamic_cast(realObj); + + if(!dynamicObj) return; + + if(dynamicObj->getManipulatingPlayer() != NULL) + { + return; + } + + switch(dynamicObj->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_StandardBox: weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; - + dynamicObj->SetManipulatingPlayer(*weapon->owner); //TODO: add if this is to be a struggle of who has the most power in its weapon, the player that is already manipulating the object or you. if you then you take the object from the other player, if not then you do not take the object break; } diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 961d29fc..844deaf2 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -12,6 +12,7 @@ DynamicObject::DynamicObject() this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) @@ -20,6 +21,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) @@ -27,6 +29,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -36,6 +39,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void (*Ev this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) @@ -45,6 +49,7 @@ DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::P this->isReleased = false; this->isActive = true; this->affectedBy = NULL; + this->manipulatedBy = NULL; } DynamicObject::~DynamicObject(void) { @@ -100,4 +105,19 @@ Player* DynamicObject::getAffectingPlayer() void DynamicObject::RemoveAffectedBy() { this->affectedBy = NULL; +} + +GameLogic::Player* DynamicObject::getManipulatingPlayer() +{ + return this->manipulatedBy; +} + +void DynamicObject::SetManipulatingPlayer(GameLogic::Player &player) +{ + this->manipulatedBy = &player; +} + +void DynamicObject::RemoveManipulation() +{ + this->manipulatedBy = NULL; } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index d1bb63bc..03a03ad6 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -30,8 +30,11 @@ namespace GameLogic void Activate(); void SetAffectedBy(GameLogic::Player &player); + void SetManipulatingPlayer(GameLogic::Player &player); void RemoveAffectedBy(); + void RemoveManipulation(); GameLogic::Player* getAffectingPlayer(); + GameLogic::Player* getManipulatingPlayer(); static void DynamicObject::DynamicDefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); @@ -40,6 +43,8 @@ namespace GameLogic bool isReleased; protected: GameLogic::Player *affectedBy; + GameLogic::Player *manipulatedBy; + }; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 4dcdacaa..d8ba38ba 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -221,7 +221,7 @@ void Player::EndFrame() //check if there are any objects that can be removed from the AffectedObjects list for(int i = 0; i < this->AffectedObjects.Size(); i++) { - if((this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) + if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) { this->AffectedObjects[i]->RemoveAffectedBy(); this->AffectedObjects.Remove(i); From 4d967b995deb5e8e422890ef0787417411c3475c Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Tue, 25 Feb 2014 11:46:05 +0100 Subject: [PATCH 05/46] Added player stats. Added players to level. Respawn logic in level. --- Code/Game/GameLogic/Game.cpp | 5 +- Code/Game/GameLogic/Game.h | 13 +- Code/Game/GameLogic/GameAPI.h | 2 + Code/Game/GameLogic/GameLogicStates.h | 3 +- Code/Game/GameLogic/Game_LevelData.cpp | 14 +- Code/Game/GameLogic/Game_PlayerData.cpp | 4 + Code/Game/GameLogic/Level.cpp | 56 ++++++- Code/Game/GameLogic/Level.h | 14 +- Code/Game/GameLogic/Player.cpp | 141 ++++++------------ Code/Game/GameLogic/Player.h | 35 +++-- .../Implementation/GameSession_Gameplay.cpp | 5 - 11 files changed, 167 insertions(+), 125 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 0e1ab178..a33ce03c 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -108,6 +108,7 @@ Game::PlayerData* Game::CreatePlayer() this->players[insert] = new PlayerData(freeID, 0); // user constructor with objectID and teamID this->players[insert]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + this->level->AddPlayerToGame(this->players[insert]); return this->players[insert]; } @@ -128,6 +129,9 @@ void Game::CreateTeam() bool Game::NewFrame() { + // HACK need dynamic delta time + this->level->Update(this->frameTime); + for (unsigned int i = 0; i < this->players.Size(); i++) { if(this->players[i] && this->players[i]->player) this->players[i]->player->BeginFrame(); @@ -202,4 +206,3 @@ void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer { if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0, 0); } - diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 37abe97f..c03de2ed 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -45,7 +45,7 @@ namespace GameLogic ObjectSpecialType GetObjectType() const override; void Inactivate() override; void Release() override; - + Player* GetPlayer(); Player *player; }; @@ -63,7 +63,8 @@ namespace GameLogic int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const override; - + void Update(float deltaTime); + void AddPlayerToGame(IPlayerData *player); Level *level; }; @@ -80,16 +81,16 @@ namespace GameLogic void SetFrameTimeLength( float seconds ) override; void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) override; void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) override; - void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override; - void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override; - void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; - + void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override; + void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override; + void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; static void PhysicsOnMove(const Oyster::Physics::ICustomBody *object); static void PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto); + static void PhysicsOnDead(const Oyster::Physics::ICustomBody *object); Utility::DynamicMemory::DynamicArray players; LevelData* level; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 0c79f33d..627ea547 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -117,8 +117,10 @@ namespace GameLogic class ILevelData :public IObjectData { public: + virtual void Update(float deltaTime) = 0; virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; + virtual void AddPlayerToGame(IPlayerData *player) = 0; virtual void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& destMem) const = 0; }; diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index ae4e192f..f006ad27 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -20,7 +20,8 @@ namespace GameLogic PLAYER_STATE_WALKING = 1, PLAYER_STATE_IDLE = 2, PLAYER_STATE_DEAD = 4, - PLAYER_STATE_INVALID = 8, + PLAYER_STATE_DIED = 8, + PLAYER_STATE_INVALID = 16, }; enum WEAPON_FIRE diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 903cb959..f16f4072 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -54,9 +54,17 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const { - mem.Resize(level->dynamicObjects.Size()); - for(int i = 0; i < (int)level->dynamicObjects.Size(); i++) + mem.Resize(level->GetDynamicObject().Size()); + for(int i = 0; i < (int)level->GetDynamicObject().Size(); i++) { - mem[i] = level->dynamicObjects[i]; + mem[i] = level->GetDynamicObject()[i]; } +} +void Game::LevelData::Update(float deltaTime) +{ + this->level->Update(deltaTime); +} +void Game::LevelData::AddPlayerToGame(IPlayerData *player) +{ + this->level->AddPlayerToGame(((PlayerData*)player)->GetPlayer()); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index ad409e3b..88b4bbbe 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -101,4 +101,8 @@ void Game::PlayerData::Inactivate() void Game::PlayerData::Release() { this->player->ReleaseDynamicObject(); +} +Player* Game::PlayerData::GetPlayer() +{ + return this->player; } \ No newline at end of file diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index a4252bc4..f3a763d0 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -12,7 +12,7 @@ using namespace GameLogic; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; - +using namespace Oyster::Math; Level::Level(void) { @@ -69,7 +69,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_RedExplosiveBox: { - Oyster::Math::Float dmg = 90; + Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); @@ -393,7 +393,20 @@ void Level::AddPlayerToTeam(Player *player, int teamID) { this->teamManager.AddPlayerToTeam(player,teamID); } - +void Level::AddPlayerToGame(Player *player) +{ + this->playerObjects.Push(player); +} +void Level::RemovePlayerFromGame(Player *player) +{ + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if ((Player*)this->playerObjects[i] == player) + { + //this->playerObjects[i]. + } + } +} void Level::CreateTeam(int teamSize) { this->teamManager.CreateTeam(teamSize); @@ -401,9 +414,29 @@ void Level::CreateTeam(int teamSize) void Level::RespawnPlayer(Player *player) { - this->teamManager.RespawnPlayerRandom(player); -} + //this->teamManager.RespawnPlayerRandom(player); + Float3 spawnPoint = spawnPoints[0]; + player->Respawn(spawnPoint); +} +void Level::Update(float deltaTime) +{ + // update lvl-things + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], DEATH_TIMER); // add killer ID + } + } +} int Level::getNrOfDynamicObj() { return this->dynamicObjects.Size(); @@ -417,10 +450,23 @@ Object* Level::GetObj( int ID) const } return NULL; } + void Level::PhysicsOnMoveLevel(const ICustomBody *object) { // function call from physics update when object was moved Object* temp = (Object*)object->GetCustomTag(); ((Game*)&Game::Instance())->onMoveFnc(temp); } +Utility::DynamicMemory::DynamicArray> Level::GetPlayers() +{ + return this->playerObjects; +} +Utility::DynamicMemory::DynamicArray> Level::GetStaticObjects() +{ + return this->staticObjects; +} +Utility::DynamicMemory::DynamicArray> Level::GetDynamicObject() +{ + return this->dynamicObjects; +} diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 27f0bab6..9fb3dbad 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -16,6 +16,7 @@ #include "DynamicArray.h" #include "LevelLoader.h" +const int DEATH_TIMER = 5; namespace GameLogic { @@ -48,7 +49,8 @@ namespace GameLogic * @param teamID: ArrayPos of the team you want to add the player to ********************************************************/ void AddPlayerToTeam(Player *player, int teamID); - + void AddPlayerToGame(Player *player); + void RemovePlayerFromGame(Player *player); /******************************************************** * Respawns a player on a random teammate @@ -64,13 +66,21 @@ namespace GameLogic ********************************************************/ static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + void Update(float deltaTime); + int getNrOfDynamicObj(); Object* GetObj( int ID ) const; + static void PlayerDied( Player* player ); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); + Utility::DynamicMemory::DynamicArray> GetPlayers(); + Utility::DynamicMemory::DynamicArray> GetStaticObjects(); + Utility::DynamicMemory::DynamicArray> GetDynamicObject(); - //private: + private: + Utility::DynamicMemory::DynamicArray> playerObjects; + Utility::DynamicMemory::DynamicArray> deadPlayerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index d8ba38ba..91f09c56 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -11,36 +11,17 @@ const float KEY_TIMER = 0.03f; Player::Player() :DynamicObject() { - + Player::initPlayerData(); + this->teamID = -1; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { weapon = new Weapon(2,this); - AffectedObjects.Reserve(15); - - this->life = 100; + Player::initPlayerData(); this->teamID = teamID; - this->playerState = PLAYER_STATE_IDLE; - this->lookDir = Oyster::Math::Float3(0,0,-1); - key_forward = 0; - key_backward = 0; - key_strafeRight = 0; - key_strafeLeft = 0; - key_jump = 0; - invincibleCooldown = 0; - this->deathTimeLeft = 0; - this->deathTime = 5; - - this->previousPosition = Oyster::Math::Float3(0,0,0); - - this->moveDir = Oyster::Math::Float3(0,0,0); - this->moveSpeed = 100; - this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); - - this->rotationUp = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -48,27 +29,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { weapon = new Weapon(2,this); - AffectedObjects.Reserve(15); - - - this->life = 100; + Player::initPlayerData(); this->teamID = teamID; - this->playerState = PLAYER_STATE_IDLE; - this->lookDir = Oyster::Math::Float3(0,0,-1); - key_forward = 0; - key_backward = 0; - key_strafeRight = 0; - key_strafeLeft = 0; - key_jump = 0; - invincibleCooldown = 0; - this->deathTimeLeft = 0; - this->deathTime = 5; - this->previousPosition = Oyster::Math::Float3(0,0,0); - this->moveDir = Oyster::Math::Float3(0,0,0); - this->moveSpeed = 20; - this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); - - this->rotationUp = 0; } Player::~Player(void) @@ -79,10 +41,29 @@ Player::~Player(void) weapon = NULL; } } +void Player::initPlayerData() +{ + this->playerStats.hp = MAX_HP; + this->playerStats.movementSpeed = BASIC_SPEED; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; + this->playerState = PLAYER_STATE_IDLE; + this->lookDir = Oyster::Math::Float3(0,0,-1); + + this->key_forward = 0; + this->key_backward = 0; + this->key_strafeRight = 0; + this->key_strafeLeft = 0; + this->key_jump = 0; + this->invincibleCooldown = 0; + this->deathTimer = 0; + + this->rotationUp = 0; +} void Player::BeginFrame() { - if( this->playerState != PLAYER_STATE_DEAD) + if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) { weapon->Update(0.002f); @@ -117,7 +98,7 @@ void Player::BeginFrame() // Walking data Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); - Oyster::Math::Float walkSpeed = this->moveSpeed*0.2f; + Oyster::Math::Float walkSpeed = this->playerStats.movementSpeed*0.2f; // Check for input if(key_forward > 0.001) @@ -199,36 +180,15 @@ void Player::BeginFrame() if(this->rigidBody->GetLambda() < 0.9f) { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); - this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass*20); + this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } } - else - { - // player is dead - // TODO move this logic to lvl - this->deathTimeLeft -= gameInstance->GetFrameTime(); - if( this->deathTimeLeft <= 0) - { - Respawn( Oyster::Math::Float3( -50, 180, 0)); - } - } } void Player::EndFrame() { - //check if there are any objects that can be removed from the AffectedObjects list - for(int i = 0; i < this->AffectedObjects.Size(); i++) - { - if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) - { - this->AffectedObjects[i]->RemoveAffectedBy(); - this->AffectedObjects.Remove(i); - } - - } - } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -283,12 +243,10 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) { if( this->playerState == PLAYER_STATE_DEAD) { - this->life = 100; - this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - //this->lookDir = Oyster::Math::Float4(1,0,0); + Player::initPlayerData(); this->rigidBody->SetPosition(spawnPoint); this->gameInstance->onRespawnFnc( this, spawnPoint); - this->gameInstance->onDamageTakenFnc( this, this->life); + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); } } @@ -349,31 +307,30 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - - this->life -= damage; - this->gameInstance->onDamageTakenFnc( this, this->life); - - if(this->life <= 0) + if( this->playerState != PLAYER_STATE_DEAD) { - this->life = 0; - playerState = PLAYER_STATE_DEAD; - this->deathTimeLeft = this->deathTime; - this->gameInstance->onDeadFnc(this, this->deathTimeLeft); - } + this->playerStats.hp -= damage; + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); -} - -void Player::AddAffectedObject(DynamicObject &AffectedObject) -{ - //check if object already exists in the list, if so then do not add - for(int i = 0; i < AffectedObjects.Size(); i++) - { - if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) + if(this->playerStats.hp <= 0) { - //object already exists, exit function - return; + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; } } - //else you add the object to the stack - AffectedObjects.Push(&AffectedObject); } +bool Player::deathTimerTick(float dt) +{ + this->deathTimer -= dt; + if( this->deathTimer <= 0) + { + return true; + } + return false; +} +void Player::setDeathTimer(float deathTimer) +{ + this->deathTimer = deathTimer; + this->playerState = PLAYER_STATE_DEAD; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 99af52c5..2d6f0a35 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -9,6 +9,8 @@ #include "DynamicObject.h" #include "DynamicArray.h" +const float MAX_HP = 100.0f; +const float BASIC_SPEED = 30.0f; namespace GameLogic { @@ -16,6 +18,21 @@ namespace GameLogic class Player : public DynamicObject { public: + struct PlayerStats + { + Oyster::Math::Float hp; + Oyster::Math::Float movementSpeed; + //Oyster::Math::Float resistance; + }; + + struct PlayerScore + { + int killScore; + int deathScore; + // int assistScore; + // int suicideScore; + }; + Player(void); Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID); @@ -75,20 +92,21 @@ namespace GameLogic PLAYER_STATE GetState() const; void DamageLife(int damage); + void setDeathTimer(float deathTimer); + bool deathTimerTick(float dt); void BeginFrame(); void EndFrame(); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - private: void Jump(); + void initPlayerData(); private: - Utility::DynamicMemory::DynamicArray AffectedObjects; + - Oyster::Math::Float life; int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -100,18 +118,15 @@ namespace GameLogic float key_jump; - Oyster::Math::Float3 previousPosition; - Oyster::Math::Float3 moveDir; - Oyster::Math::Float moveSpeed; - Oyster::Math::Float3 previousMoveSpeed; - Oyster::Math::Float rotationUp; - float deathTime; - float deathTimeLeft; + float deathTimer; bool hasTakenDamage; float invincibleCooldown; + PlayerStats playerStats; + PlayerScore playerScore; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 8cc47dcc..5d3f2a71 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -188,7 +188,6 @@ using namespace DanBias; break; case protocol_Gameplay_PlayerShot: this->Gameplay_PlayerShot ( Protocol_PlayerShot (p), c ); break; - case protocol_Gameplay_ObjectPickup: this->Gameplay_ObjectPickup ( Protocol_ObjectPickup (p), c ); break; case protocol_Gameplay_ObjectDamage: this->Gameplay_ObjectDamage ( Protocol_ObjectDamage (p), c ); @@ -201,7 +200,6 @@ using namespace DanBias; break; case protocol_Gameplay_ObjectCreate: this->Gameplay_ObjectCreate ( Protocol_ObjectCreate (p), c ); break; - case protocol_General_Status: this->General_Status ( Protocol_General_Status (p), c ); break; case protocol_General_Text: this->General_Text ( Protocol_General_Text (p), c ); @@ -242,11 +240,8 @@ using namespace DanBias; { if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); - if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); } - - void GameSession::Gameplay_ObjectPickup ( Protocol_ObjectPickup& p, DanBias::GameClient* c ) { From f2b63b7ad4704a083e07ad3deafe9dc21f90ec59 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 25 Feb 2014 13:56:35 +0100 Subject: [PATCH 06/46] GL - weapon energy, force etc inside weapon --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 45 ++++++++++++++----- Code/Game/GameLogic/AttatchmentMassDriver.h | 19 ++++++++ 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 1f86bf60..62f3599e 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -11,10 +11,18 @@ AttatchmentMassDriver::AttatchmentMassDriver(void) this->owner = 0; this->heldObject = NULL; this->hasObject = false; + this->currentEnergy = StandardMaxEnergy; + this->maxEnergy = StandardMaxEnergy; + this->rechargeRate = StandardrechargeRate; + this->force = Standardforce; } AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) { + this->currentEnergy = StandardMaxEnergy; + this->maxEnergy = StandardMaxEnergy; + this->rechargeRate = StandardrechargeRate; + this->force = Standardforce; this->owner = &owner; this->heldObject = NULL; @@ -36,15 +44,27 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, switch (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - ForcePush(usage,dt); + if(currentEnergy >= 90.0f) + { + currentEnergy -= 90.0f; + ForcePush(usage,dt); + } break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - ForcePull(usage,dt); + if(currentEnergy >= 1.0f) + { + currentEnergy -= 1.0f; + ForcePull(usage,dt); + } break; case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: - ForceZip(usage,dt); + if(currentEnergy >= 90.0f) + { + currentEnergy -= 90.0f; + ForceZip(usage,dt); + } break; } @@ -64,7 +84,14 @@ void AttatchmentMassDriver::Update(float dt) heldObject->SetPosition(pos); heldObject->SetLinearVelocity(Oyster::Math::Float3::null); + currentEnergy += rechargeRate * 0.5f; //rechargeRate is halfed if you are holding an object } + else + { + currentEnergy += rechargeRate; + } + + } /******************************************************** @@ -78,7 +105,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float if(hasObject) { - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); ((DynamicObject*)(heldObject->GetCustomTag()))->RemoveManipulation(); hasObject = false; @@ -91,12 +118,10 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float Oyster::Math::Float lenght = 10; Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos; - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force * 0.6f); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); - - forcePushData args; args.pushForce = pushForce; args.p = this->owner; @@ -111,7 +136,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float ********************************************************/ void AttatchmentMassDriver::ForceZip(const WEAPON_FIRE &usage, float dt) { - Oyster::Math::Float3 force = Oyster::Math::Float4(this->owner->GetLookDir()) * (1000); + Oyster::Math::Float3 force = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force); this->owner->GetRigidBody()->ApplyImpulse(force); } @@ -132,11 +157,11 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) Oyster::Math::Float lenght = 10; Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos; - Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100); + Oyster::Math::Float4 pullForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force * 0.2); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); forcePushData args; - args.pushForce = -pushForce; + args.pushForce = -pullForce; args.p = this->owner; Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index 51368e91..385fcca3 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -4,8 +4,14 @@ #ifndef ATTATCHMENTMASSDRIVER_H #define ATTATCHMENTMASSDRIVER_H #include "IAttatchment.h" + + + namespace GameLogic { + const Oyster::Math::Float StandardMaxEnergy = 100.0f; + const Oyster::Math::Float StandardrechargeRate = 0.5f; + const Oyster::Math::Float Standardforce = 1000.0f; class AttatchmentMassDriver : public IAttatchment { @@ -53,6 +59,19 @@ namespace GameLogic Oyster::Physics::ICustomBody *heldObject; bool hasObject; + Oyster::Math::Float force; + + Oyster::Math::Float maxEnergy; + Oyster::Math::Float currentEnergy; + + Oyster::Math::Float rechargeRate; + + struct Aim + { + + }; + + }; } #endif From 5620a3c5175341bec46642711f95e8fb53060e8a Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Tue, 25 Feb 2014 14:35:27 +0100 Subject: [PATCH 07/46] Added eventfunctions for PlayerAction and PickupEvent --- Code/Game/GameLogic/Game.cpp | 19 +++++++++++++++---- Code/Game/GameLogic/Game.h | 19 +++++++++++++------ Code/Game/GameLogic/GameAPI.h | 16 +++++++++------- Code/Game/GameLogic/Level.cpp | 3 +++ Code/Game/GameServer/GameSession.h | 6 ++++-- .../Implementation/GameSession_Gameplay.cpp | 18 ++++++++++++++++-- .../Implementation/GameSession_General.cpp | 7 +++++-- Code/Game/LevelLoader/ObjectDefines.h | 12 ++++++++++++ 8 files changed, 77 insertions(+), 23 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index a33ce03c..e4782582 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -156,14 +156,18 @@ void Game::SetFrameTimeLength( float seconds ) this->frameTime = seconds; } -void Game::SetSubscription(GameEvent::ObjectMovedFunction functionPointer) +void Game::SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) { this->onMoveFnc = functionPointer; } -void Game::SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) +void Game::SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) { this->onDisableFnc = functionPointer; } +void Game::SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) +{ + this->onEnableFnc = functionPointer; +} void Game::SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) { this->onDamageTakenFnc = functionPointer; @@ -176,7 +180,14 @@ void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) { this->onDeadFnc = functionPointer; } - +void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) +{ + this->onPlayerActionEventFnc = functionPointer; +} +void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) +{ + this->onPickupEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); @@ -204,5 +215,5 @@ void Game::PhysicsOnMove(const ICustomBody *object) } void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto) { - if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0, 0); + if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0); } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index c03de2ed..22b9fbda 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -79,11 +79,14 @@ namespace GameLogic bool NewFrame() override; void SetFPS( int FPS ) override; void SetFrameTimeLength( float seconds ) override; - void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) override; - void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) override; - void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override; - void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override; - void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; + void SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) override; + void SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) override; + void SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) override; + void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) override; + void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) override; + void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; + void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; + void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -96,11 +99,15 @@ namespace GameLogic LevelData* level; float frameTime; bool initiated; - GameEvent::ObjectDisabledFunction onDisableFnc; + GameEvent::ObjectMovedFunction onMoveFnc; + GameEvent::ObjectDisabledFunction onDisableFnc; + GameEvent::ObjectEnabledFunction onEnableFnc; GameEvent::ObjectHpFunction onDamageTakenFnc; GameEvent::ObjectRespawnedFunction onRespawnFnc; GameEvent::ObjectDeadFunction onDeadFnc; + GameEvent::AnimationEventFunction onPlayerActionEventFnc; + GameEvent::PickupEventFunction onPickupEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 627ea547..1bf39816 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -26,10 +26,13 @@ namespace GameLogic namespace GameEvent { typedef void(*ObjectMovedFunction)(IObjectData* object); // Callback method that recieves and object - typedef void(*ObjectDisabledFunction)(IObjectData* object, float seconds); // Callback method that recieves and object + typedef void(*ObjectDisabledFunction)(IObjectData* object); // Callback method that recieves and object + typedef void(*ObjectEnabledFunction)(IObjectData* object); // Callback method that recieves and object typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos typedef void(*ObjectDeadFunction)(IObjectData* object, float seconds); // Callback method that sends death timer + typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer + typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer //etc... }; @@ -177,15 +180,14 @@ namespace GameLogic /** Set a specific object event subscription callback * @param */ - virtual void SetSubscription(GameEvent::ObjectMovedFunction functionPointer) = 0; - - /** Set a specific object event subscription callback - * @param - */ - virtual void SetSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0; + virtual void SetMoveSubscription(GameEvent::ObjectMovedFunction functionPointer) = 0; + virtual void SetDisableSubscription(GameEvent::ObjectDisabledFunction functionPointer) = 0; + virtual void SetEnableSubscription(GameEvent::ObjectEnabledFunction functionPointer) = 0; virtual void SetHpSubscription(GameEvent::ObjectHpFunction functionPointer) = 0; virtual void SetRespawnSubscription(GameEvent::ObjectRespawnedFunction functionPointer) = 0; virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; + virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; + virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index f3a763d0..dc51cb00 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -434,8 +434,11 @@ void Level::Update(float deltaTime) { this->playerObjects[i]->setDeathTimer(DEATH_TIMER); ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], DEATH_TIMER); // add killer ID + Player* killer = this->playerObjects[i]->getAffectingPlayer(); } } + + } int Level::getNrOfDynamicObj() { diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 12067c2b..6ab0c42b 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -98,11 +98,13 @@ namespace DanBias //Callback method recieving from gamelogic static void ObjectMove ( GameLogic::IObjectData* movedObject ); - static void ObjectDisabled ( GameLogic::IObjectData* movedObject, float seconds ); + static void ObjectDisabled ( GameLogic::IObjectData* movedObject ); + static void ObjectEnabled ( GameLogic::IObjectData* movedObject ); static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp ); static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos ); static void ObjectDead ( GameLogic::IObjectData* movedObject, float seconds ); - + static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); + static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 5d3f2a71..b9a17a5e 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -146,9 +146,13 @@ using namespace DanBias; GameSession::gameSession->Send(p.GetProtocol()); //} } - void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject, float seconds ) + void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID(), seconds).GetProtocol()); + //GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + } + void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) + { + //GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { @@ -162,6 +166,16 @@ using namespace DanBias; { GameSession::gameSession->Send(Protocol_ObjectDie(movedObject->GetID(), seconds).GetProtocol()); } + void GameSession::PickupEvent( GameLogic::IObjectData* movedObject, int pickupEffectID ) + { + // send pickup protocol + GameSession::gameSession->Send(Protocol_ObjectPickup(movedObject->GetID(), pickupEffectID).GetProtocol()); + } + void GameSession::ActionEvent( GameLogic::IObjectData* movedObject , int actionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 0ad12987..ca869fb7 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -106,11 +106,14 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) } /* Set some game instance data options */ - this->gameInstance.SetSubscription(GameSession::ObjectMove); - this->gameInstance.SetSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetMoveSubscription(GameSession::ObjectMove); + this->gameInstance.SetDisableSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetEnableSubscription(GameSession::ObjectEnabled); this->gameInstance.SetHpSubscription(GameSession::ObjectDamaged); this->gameInstance.SetRespawnSubscription(GameSession::ObjectRespawned); this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); + this->gameInstance.SetActionSubscription(GameSession::ActionEvent); + this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 52f0e088..8ff3a0af 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -92,6 +92,18 @@ namespace GameLogic WorldSize_Unknown = -1 }; + enum PlayerAction + { + PlayerAction_Jump, + PlayerAction_Walk, + PlayerAction_Idle, + }; + + enum PickupType + { + PickupType_Health, + PickupType_SpeedBoost + }; /************************************ Structs From 4f2738e921da80800207ae9909296c6d3a956edb Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 25 Feb 2014 14:36:54 +0100 Subject: [PATCH 08/46] Not finished Pickup system. --- Code/Game/GameLogic/CollisionManager.cpp | 29 +++++++++++++++ Code/Game/GameLogic/GameLogic.vcxproj | 6 ++++ Code/Game/GameLogic/PickupSystem/Pickup.cpp | 29 +++++++++++++++ Code/Game/GameLogic/PickupSystem/Pickup.h | 35 +++++++++++++++++++ .../GameLogic/PickupSystem/PickupHealth.cpp | 18 ++++++++++ .../GameLogic/PickupSystem/PickupHealth.h | 27 ++++++++++++++ .../GameLogic/PickupSystem/PickupSystem.cpp | 22 ++++++++++++ .../GameLogic/PickupSystem/PickupSystem.h | 30 ++++++++++++++++ Code/Game/LevelLoader/ObjectDefines.h | 1 + 9 files changed, 197 insertions(+) create mode 100644 Code/Game/GameLogic/PickupSystem/Pickup.cpp create mode 100644 Code/Game/GameLogic/PickupSystem/Pickup.h create mode 100644 Code/Game/GameLogic/PickupSystem/PickupHealth.cpp create mode 100644 Code/Game/GameLogic/PickupSystem/PickupHealth.h create mode 100644 Code/Game/GameLogic/PickupSystem/PickupSystem.cpp create mode 100644 Code/Game/GameLogic/PickupSystem/PickupSystem.h diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index d60d16ce..3e931f8e 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -10,6 +10,8 @@ #include "Portal.h" #include "ExplosiveCrate.h" +#include "PickupSystem/PickupHealth.h" + using namespace Oyster; using namespace GameLogic; @@ -356,4 +358,31 @@ using namespace GameLogic; } + } + + //General collision collision for pickups + //It calls the collision function defined in each pickup. + void Pickup::PickupCollision(Oyster::Physics::ICustomBody* objA, Oyster::Physics::ICustomBody* objB, Oyster::Math::Float kineticEnergyLoss) + { + //Check if player is a player. + Object* a = (Object*)objA->GetCustomTag(); + Object* b = (Object*)objB->GetCustomTag(); + + if(!a) + return; + if(!b) + return; + + if(b->GetObjectType() == ObjectSpecialType_Player) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + else if(a->GetObjectType() != ObjectSpecialType_Player) + { + //One of the objects are not a player. + //Do nothing. + return; + } + + ((Pickup*)b)->OnCollision((Player*)a); } \ No newline at end of file diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 52b7722b..08a932d2 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -173,6 +173,9 @@ + + + @@ -194,6 +197,9 @@ + + + diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp new file mode 100644 index 00000000..84b95e87 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -0,0 +1,29 @@ +#include "Pickup.h" + +using namespace GameLogic; + +Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisionFunc, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime) + : StaticObject(rigidBody, collisionFunc, type, objectID) +{ + this->active = true; + this->spawnTime = spawnTime; +} + +Pickup::~Pickup() +{} + +void Pickup::Update() +{ + if(!active) + { + if(timer.getElapsedSeconds() >= spawnTime) + { + active = true; + } + } +} + +bool Pickup::IsActive() +{ + return active; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.h b/Code/Game/GameLogic/PickupSystem/Pickup.h new file mode 100644 index 00000000..e48017fc --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/Pickup.h @@ -0,0 +1,35 @@ +#ifndef PICKUP_H +#define PICKUP_H + +#include "../StaticObject.h" +#include "../Player.h" +#include "WinTimer.h" + +typedef void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss); + +namespace GameLogic +{ + class Pickup : public StaticObject + { + public: + Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisionFunc, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime); + virtual ~Pickup(); + + virtual void Update(); + + bool IsActive(); + + virtual void OnCollision(Player *player) = 0; + + static void PickupCollision(Oyster::Physics::ICustomBody *rigidBodyCrate, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + + protected: + bool active; + + Utility::WinTimer timer; + double spawnTime; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp new file mode 100644 index 00000000..56cbef1e --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -0,0 +1,18 @@ +#include "PickupHealth.h" + +using namespace GameLogic; + +PickupHealth::PickupHealth(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime, Oyster::Math::Float healthValue) + : Pickup(rigidBody, Pickup::PickupCollision, type, objectID, spawnTime) +{ + this->hpValue = healthValue; +} + +PickupHealth::~PickupHealth() +{} + +void PickupHealth::OnCollision(Player *player) +{ + timer.reset(); + player->DamageLife(-hpValue); +} \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.h b/Code/Game/GameLogic/PickupSystem/PickupHealth.h new file mode 100644 index 00000000..5d5db809 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.h @@ -0,0 +1,27 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef PICKUP_HEALTH_H +#define PICKUP_HEALTH_H + +#include "Pickup.h" + +namespace GameLogic +{ + class PickupHealth : public Pickup + { + public: + PickupHealth(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type, int objectID, Oyster::Math::Float spawnTime, Oyster::Math::Float HealthValue); + virtual ~PickupHealth(); + + + void OnCollision(Player *player); + + protected: + int hpValue; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp b/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp new file mode 100644 index 00000000..0f60ddc9 --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupSystem.cpp @@ -0,0 +1,22 @@ +#include "PickupSystem.h" + +using namespace GameLogic; + +PickupSystem::PickupSystem() +{} + +PickupSystem::~PickupSystem() +{} + +void PickupSystem::CreatePickup(Pickup* pickup) +{ + pickups.push_back(pickup); +} + +void PickupSystem::Update() +{ + for(int i = 0; i < pickups.size(); i++) + { + pickups.at(i)->Update(); + } +} \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/PickupSystem.h b/Code/Game/GameLogic/PickupSystem/PickupSystem.h new file mode 100644 index 00000000..4bd1e69e --- /dev/null +++ b/Code/Game/GameLogic/PickupSystem/PickupSystem.h @@ -0,0 +1,30 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef PICKUP_SYSTEM_H +#define PICKUP_SYSTEM_H + +#include + +#include "Pickup.h" + +namespace GameLogic +{ + class PickupSystem + { + public: + PickupSystem(); + ~PickupSystem(); + + void CreatePickup(Pickup* pickup); + + void Update(); + + private: + std::vector> pickups; + + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 8ff3a0af..9ce7d86a 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -42,6 +42,7 @@ namespace GameLogic ObjectSpecialType_Player, ObjectSpecialType_Generic, + ObjectSpecialType_PickupHealth, ObjectSpecialType_Count, ObjectSpecialType_Unknown = -1 From 9a449253c26c909197ff2eb6adb85a6a4f2abf81 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 25 Feb 2014 16:07:50 +0100 Subject: [PATCH 09/46] Fixed error with reading lights from level format. --- Code/Game/LevelLoader/ParseFunctions.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp index ac361c46..060180a2 100644 --- a/Code/Game/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -23,9 +23,9 @@ namespace GameLogic void ParseLight(char* buffer, BasicLight& header, int& size) { int start = 0; - memcpy(&header.typeID, &buffer[start], 40); - start += 40; - /* + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + memcpy(&header.lightType, &buffer[start], 4); start += 4; @@ -39,7 +39,7 @@ namespace GameLogic start += 4; memcpy(&header.intensity, &buffer[start], 4); - start += 4;*/ + start += 4; size += start; From d91fa3073f097c98321a87d99d011da78e4f3a57 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Tue, 25 Feb 2014 16:08:45 +0100 Subject: [PATCH 10/46] Play action animation --- .../GameClient/GameClientState/C_Object.cpp | 5 +- .../GameClient/GameClientState/C_Object.h | 2 +- .../GameClient/GameClientState/GameState.cpp | 198 +++++++++++++++--- Code/Game/GameLogic/Level.h | 1 - Code/Game/GameLogic/Player.cpp | 28 ++- Code/Game/GameProtocols/ObjectProtocols.h | 12 +- 6 files changed, 208 insertions(+), 38 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index 67146770..b168b92c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -123,7 +123,10 @@ void C_Object::SetGlowTint(Oyster::Math::Float3 tint) model->GlowTint = tint; } - +void C_Object::SetVisible(bool visible) +{ + model->Visible = visible; +} //////////////////////////////////////////////// // RB DEBUG diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index fd118068..1a8f7517 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -72,7 +72,7 @@ namespace DanBias void SetTint(Oyster::Math::Float3); void SetGlowTint(Oyster::Math::Float3); - + void SetVisible(bool visible); // RB DEBUG void updateRBWorld(); diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 123b3fb2..d9c6fa30 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -12,6 +12,7 @@ #include "GamingUI.h" #include "RespawnUI.h" #include "StatsUI.h" +#include using namespace ::DanBias::Client; using namespace ::Oyster; @@ -135,7 +136,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa p->InitRB( RBData ); // !RB DEBUG // start with runing animation - p->playAnimation( L"run_forwards", true ); + p->playAnimation( L"idle", true ); (this->privData->players)[id] = p; @@ -425,15 +426,59 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState switch(ID) { - case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectPickup: + { + Protocol_ObjectPickup decoded(data); + decoded.object_ID; + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + // I picked up the pickUp! + } + + if (decoded.pickup_ID == GameLogic::PickupType::PickupType_Health) + { + // object->PickupHealth(); + } + else if (decoded.pickup_ID == GameLogic::PickupType::PickupType_SpeedBoost) + { + // object->PickupSpeed(); + } + } + decoded.pickup_ID; + + + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDamage: { Protocol_ObjectDamage decoded(data); - if( this->privData->myId == decoded.object_ID ) + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) { - if(currGameUI == gameUI) + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + if( this->privData->myId == decoded.object_ID ) { - ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + if(currGameUI == gameUI) + { + // set my HP + ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); + } } } } @@ -446,38 +491,72 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { Protocol_ObjectPosition decoded(data); - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetPosition( decoded.position ); + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } - (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); - // !RB DEBUG + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + this->privData->camera.SetPosition( decoded.position ); + } + + object->setPos( decoded.position ); + // RB DEBUG + object->setRBPos ( decoded.position ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); - (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); - // !RB DEBUG + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } + + if( object ) + { + object->setScale( decoded.scale ); + // RB DEBUG + object->setRBScale ( decoded.scale ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: { Protocol_ObjectRotation decoded(data); Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); + C_Object *object; + object = (this->privData->players)[decoded.object_ID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.object_ID]; + } - // if is this player. Remember to change camera - if( this->privData->myId == decoded.object_ID ) - this->privData->camera.SetRotation( rotation ); + if( object ) + { + if( this->privData->myId == decoded.object_ID ) + { + this->privData->camera.SetRotation( rotation ); + } - (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); - // RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); - // !RB DEBUG + object->setRot( rotation ); + // RB DEBUG + object->setRBRot( rotation ); + // !RB DEBUG + } } return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: @@ -511,17 +590,46 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; - case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectEnabled: + { + Protocol_ObjectEnable decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + + if( object ) + { + object->SetVisible(true); + } + } + return GameClientState::event_processed; case protocol_Gameplay_ObjectDisabled: { Protocol_ObjectDisable decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } - auto object = this->privData->dynamicObjects->find( decoded.objectID ); + if( object ) + { + object->SetVisible(false); + } + + /*auto object = this->privData->dynamicObjects->find( decoded.objectID ); if( object != this->privData->dynamicObjects->end() ) { - object->second = nullptr; - this->privData->dynamicObjects->erase( object ); - } + object->second = nullptr; + this->privData->dynamicObjects->erase( object ); + }*/ + } return GameClientState::event_processed; case protocol_Gameplay_ObjectCreate: @@ -616,6 +724,40 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectAction: + { + Protocol_ObjectAction decoded(data); + + C_Player *player; + player = (this->privData->players)[decoded.objectID]; + + if( player ) + { + if( this->privData->myId == decoded.objectID ) + { + // my player animation + //} + //else + //{ + // HACK for now animate my char + switch (decoded.animationID) + { + case GameLogic::PlayerAction::PlayerAction_Walk: + player->playAnimation(L"run_forwards", true); + break; + case GameLogic::PlayerAction::PlayerAction_Jump: + player->playAnimation(L"movement", true); + break; + case GameLogic::PlayerAction::PlayerAction_Idle: + player->playAnimation(L"idle", true); + break; + default: + break; + } + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 9fb3dbad..f8d41ba9 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -80,7 +80,6 @@ namespace GameLogic private: Utility::DynamicMemory::DynamicArray> playerObjects; - Utility::DynamicMemory::DynamicArray> deadPlayerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 91f09c56..52ac9b0c 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -134,7 +134,16 @@ void Player::BeginFrame() rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); } } - + + if(walkDirection == Oyster::Math::Float3::null) + { + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + { + if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + } + } // Walk if walkdirection is something if(walkDirection != Oyster::Math::Float3::null) { @@ -164,6 +173,12 @@ void Player::BeginFrame() rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; } } + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + { + if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk); + this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; + } } // Adjust velocities so no squaring occurs @@ -181,9 +196,20 @@ void Player::BeginFrame() { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); + + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Jump); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } + else + { + if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING) + { + this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; + } + } } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 234a5301..f6170d66 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -941,29 +941,29 @@ namespace GameLogic struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; - float animationID; + int animationID; Protocol_ObjectAction() { this->protocol[0].value = protocol_Gameplay_ObjectAction; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; - objectID = 0; + objectID = -1; animationID = -1; } Protocol_ObjectAction(Oyster::Network::CustomNetProtocol& p) { objectID = p[1].value.netShort; - animationID = p[2].value.netFloat; + animationID = p[2].value.netInt; } - Protocol_ObjectAction(float animID, int id) + Protocol_ObjectAction( int id, float animID) { this->protocol[0].value = protocol_Gameplay_ObjectAction; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Short; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; objectID = id; animationID = animID; From a8d4ff2c891a7cee57bff454e6acb12667650b6b Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 25 Feb 2014 16:10:02 +0100 Subject: [PATCH 11/46] Reading hp pickups from levelformat. Updating pickups. --- Code/Game/GameLogic/Level.cpp | 16 +++++++++++++--- Code/Game/GameLogic/Level.h | 4 ++++ Code/Game/GameLogic/PickupSystem/Pickup.cpp | 3 +++ Code/Game/LevelLoader/LevelParser.cpp | 15 +++++++++++++++ Code/Game/LevelLoader/ObjectDefines.h | 6 +++++- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index dc51cb00..f7c48f8b 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -131,6 +131,11 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; + case ObjectSpecialType_PickupHealth: + { + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + } + break; default: { gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); @@ -216,7 +221,6 @@ bool Level::InitiateLevel(std::wstring levelPath) std::string convertedLevelPath = converterX.to_bytes(levelPath); objects = ll.LoadLevel(convertedLevelPath); - if(objects.size() == 0) return false; @@ -264,7 +268,12 @@ bool Level::InitiateLevel(std::wstring levelPath) { // create game object Object* staticGameObj = CreateGameObj(staticObjData, rigidBody_Static); - if(staticGameObj != NULL) + + if(staticObjData->specialTypeID == ObjectSpecialType_PickupHealth) + { + this->pickupSystem.CreatePickup((PickupHealth*)staticGameObj); + } + else if(staticGameObj != NULL) { this->staticObjects.Push((StaticObject*)staticGameObj); } @@ -321,6 +330,7 @@ bool Level::InitiateLevel(std::wstring levelPath) break; } } + return true; } bool Level::InitiateLevel(float radius) @@ -438,7 +448,7 @@ void Level::Update(float deltaTime) } } - + this->pickupSystem.Update(); } int Level::getNrOfDynamicObj() { diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index f8d41ba9..7d6c25c9 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -16,6 +16,9 @@ #include "DynamicArray.h" #include "LevelLoader.h" +#include "PickupSystem\PickupSystem.h" +#include "PickupSystem\PickupHealth.h" + const int DEATH_TIMER = 5; namespace GameLogic { @@ -88,6 +91,7 @@ namespace GameLogic StaticObject *levelObj; int objID; Utility::DynamicMemory::DynamicArray spawnPoints; + PickupSystem pickupSystem; }; diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 84b95e87..73a319f8 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -1,4 +1,5 @@ #include "Pickup.h" +#include "../Game.h" using namespace GameLogic; @@ -7,6 +8,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi { this->active = true; this->spawnTime = spawnTime; + timer.reset(); } Pickup::~Pickup() @@ -19,6 +21,7 @@ void Pickup::Update() if(timer.getElapsedSeconds() >= spawnTime) { active = true; + ((Game*)&Game::Instance())->onEnableFnc(this); } } } diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index fe349988..680b0358 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -156,6 +156,21 @@ std::vector> LevelParser::Parse(std::string filen objects.push_back(header); break; } + + case ObjectSpecialType_PickupHealth: + { + PickupHealthAttributes* header = new PickupHealthAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->spawnTime, 4); + counter += 4; + + ParseObject(&buffer[counter], &header->healthValue, 4); + counter += 4; + + objects.push_back(header); + break; + } //this is a hotfix, fix so you only load the relevant data when the file is updated default: //Couldn't find specialType diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 9ce7d86a..aadc3382 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -259,7 +259,11 @@ namespace GameLogic float skySize; }; - + struct PickupHealthAttributes : public ObjectHeader + { + float spawnTime; + float healthValue; + }; From 6bd8c94d790a301e042a44dcc8cb6968a28ae5dd Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Tue, 25 Feb 2014 16:26:37 +0100 Subject: [PATCH 12/46] Addded objectDelete protocol. Enable/ disable will be used for visibility on client --- .../GameClient/GameClientState/GameState.cpp | 40 ++--- Code/Game/GameProtocols/ObjectProtocols.h | 141 +++++++++++------- .../GameProtocols/ProtocolIdentificationID.h | 19 +-- .../Implementation/GameSession_Gameplay.cpp | 4 +- 4 files changed, 116 insertions(+), 88 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index d9c6fa30..6e35202a 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -463,20 +463,21 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { Protocol_ObjectDamage decoded(data); C_Object *object; - object = (this->privData->players)[decoded.object_ID]; + object = (this->privData->players)[decoded.objectID]; if( !object) { // if it is not a player - object = (*this->privData->dynamicObjects)[decoded.object_ID]; + object = (*this->privData->dynamicObjects)[decoded.objectID]; } if( object ) { - if( this->privData->myId == decoded.object_ID ) + if( this->privData->myId == decoded.objectID ) { + // show that you took dmg if(currGameUI == gameUI) { - // set my HP + // set given players HP ((GamingUI*)currGameUI)->SetHPtext(std::to_wstring(decoded.healthLost)); } } @@ -484,7 +485,8 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } return GameClientState::event_processed; case protocol_Gameplay_ObjectHealthStatus: - { + { + // don't know if needed } return GameClientState::event_processed; case protocol_Gameplay_ObjectPosition: @@ -492,16 +494,16 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState Protocol_ObjectPosition decoded(data); C_Object *object; - object = (this->privData->players)[decoded.object_ID]; + object = (this->privData->players)[decoded.objectID]; if( !object) { // if it is not a player - object = (*this->privData->dynamicObjects)[decoded.object_ID]; + object = (*this->privData->dynamicObjects)[decoded.objectID]; } if( object ) { - if( this->privData->myId == decoded.object_ID ) + if( this->privData->myId == decoded.objectID ) { this->privData->camera.SetPosition( decoded.position ); } @@ -517,11 +519,11 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { Protocol_ObjectScale decoded(data); C_Object *object; - object = (this->privData->players)[decoded.object_ID]; + object = (this->privData->players)[decoded.objectID]; if( !object) { // if it is not a player - object = (*this->privData->dynamicObjects)[decoded.object_ID]; + object = (*this->privData->dynamicObjects)[decoded.objectID]; } if( object ) @@ -538,16 +540,16 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState Protocol_ObjectRotation decoded(data); Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); C_Object *object; - object = (this->privData->players)[decoded.object_ID]; + object = (this->privData->players)[decoded.objectID]; if( !object) { // if it is not a player - object = (*this->privData->dynamicObjects)[decoded.object_ID]; + object = (*this->privData->dynamicObjects)[decoded.objectID]; } if( object ) { - if( this->privData->myId == decoded.object_ID ) + if( this->privData->myId == decoded.objectID ) { this->privData->camera.SetRotation( rotation ); } @@ -565,16 +567,16 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState Float3 position = decoded.position; Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); C_Object *object; - object = (this->privData->players)[decoded.object_ID]; + object = (this->privData->players)[decoded.objectID]; if( !object) { // if it is not a player - object = (*this->privData->dynamicObjects)[decoded.object_ID]; + object = (*this->privData->dynamicObjects)[decoded.objectID]; } if( object ) { - if( this->privData->myId == decoded.object_ID ) + if( this->privData->myId == decoded.objectID ) { this->privData->camera.SetPosition( position ); this->privData->camera.SetRotation( rotation ); @@ -643,7 +645,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState modelData.rotation = Quaternion( Float3(decoded.position), decoded.rotationQ[3] ); modelData.scale = Float3( decoded.scale ); modelData.visible = true; - modelData.id = decoded.object_ID; + modelData.id = decoded.objectID; ::Utility::String::StringToWstring( decoded.name, modelData.modelPath ); } @@ -658,14 +660,14 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState object->InitRB( RBData ); // !RB DEBUG - (*this->privData->dynamicObjects)[decoded.object_ID] = object; + (*this->privData->dynamicObjects)[decoded.objectID] = object; } return GameClientState::event_processed; case protocol_Gameplay_ObjectCreatePlayer: { Protocol_ObjectCreatePlayer decoded(data); - this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); + this->InitiatePlayer( decoded.objectID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); } return GameClientState::event_processed; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index f6170d66..5ce8bd9e 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -59,7 +59,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectDamage 351 struct Protocol_ObjectDamage :public Oyster::Network::CustomProtocolObject { - int object_ID; + int objectID; float healthLost; //Precentage% Protocol_ObjectDamage() @@ -70,12 +70,12 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - object_ID = -1; + objectID = -1; healthLost = 0.0f; } Protocol_ObjectDamage(Oyster::Network::CustomNetProtocol& p) { - this->object_ID = p[1].value.netInt; + this->objectID = p[1].value.netInt; this->healthLost = p[2].value.netFloat; } Protocol_ObjectDamage(int id, float hp) @@ -86,12 +86,12 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; healthLost = hp; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = healthLost; return protocol; } @@ -103,8 +103,8 @@ namespace GameLogic //#define protocol_Gameplay_ObjectHealthStatus 352 struct Protocol_ObjectHealthStatus :public Oyster::Network::CustomProtocolObject { + int objectID; float currentHealth; - int id; Protocol_ObjectHealthStatus() { @@ -112,7 +112,7 @@ namespace GameLogic this->protocol[0].value.netShort = protocol_Gameplay_ObjectHealthStatus; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->id = 0; + this->objectID = -1; this->currentHealth = 0.0f; } Protocol_ObjectHealthStatus(int id, float health) @@ -121,16 +121,16 @@ namespace GameLogic this->protocol[0].value.netShort = protocol_Gameplay_ObjectHealthStatus; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->id = id; this->currentHealth = health; + this->objectID = id; this->currentHealth = health; } Protocol_ObjectHealthStatus(Oyster::Network::CustomNetProtocol& p) { - this->id = p[1].value.netInt; + this->objectID = p[1].value.netInt; this->currentHealth = p[2].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->id; + this->protocol[1].value = this->objectID; this->protocol[2].value = this->currentHealth; return protocol; @@ -143,7 +143,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectPosition 353 struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float position[3]; Protocol_ObjectPosition() @@ -155,12 +155,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = 0; + objectID = -1; memset(&position[0], 0, sizeof(float) * 3); } Protocol_ObjectPosition(Oyster::Network::CustomNetProtocol& p) { - object_ID = p[1].value.netShort; + objectID = p[1].value.netShort; position[0] = p[2].value.netFloat; position[1] = p[3].value.netFloat; position[2] = p[4].value.netFloat; @@ -174,12 +174,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&position[0], &v[0], sizeof(float) * 3); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = position[0]; this->protocol[3].value = position[1]; this->protocol[4].value = position[2]; @@ -193,7 +193,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectScale 354 struct Protocol_ObjectScale :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float scale[3]; Protocol_ObjectScale() @@ -205,12 +205,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = 0; + objectID = -1; memset(&scale[0], 0, sizeof(float) * 3); } Protocol_ObjectScale(Oyster::Network::CustomNetProtocol& p) { - object_ID = p[1].value.netShort; + objectID = p[1].value.netShort; scale[0] = p[2].value.netFloat; scale[1] = p[3].value.netFloat; scale[2] = p[4].value.netFloat; @@ -224,12 +224,12 @@ namespace GameLogic this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&scale[0], &v[0], sizeof(float) * 3); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = scale[0]; this->protocol[3].value = scale[1]; this->protocol[4].value = scale[2]; @@ -243,7 +243,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectRotation 355 struct Protocol_ObjectRotation :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float rotationQ[4]; Protocol_ObjectRotation() @@ -256,12 +256,12 @@ namespace GameLogic this->protocol[4].type = Oyster::Network::NetAttributeType_Float; this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - object_ID = 0; + objectID = -1; memset(&rotationQ[0], 0, sizeof(float) * 4); } Protocol_ObjectRotation(Oyster::Network::CustomNetProtocol& p) { - object_ID = p[1].value.netShort; + objectID = p[1].value.netShort; rotationQ[0] = p[2].value.netFloat; rotationQ[1] = p[3].value.netFloat; rotationQ[2] = p[4].value.netFloat; @@ -277,12 +277,12 @@ namespace GameLogic this->protocol[4].type = Oyster::Network::NetAttributeType_Float; this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&rotationQ[0], &v[0], sizeof(float) * 4); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol[2].value = rotationQ[0]; this->protocol[3].value = rotationQ[1]; this->protocol[4].value = rotationQ[2]; @@ -297,7 +297,7 @@ namespace GameLogic //#define protocol_Gameplay_ObjectEnabled 356 struct Protocol_ObjectPositionRotation :public Oyster::Network::CustomProtocolObject { - short object_ID; + short objectID; float position[3]; float rotationQ[4]; @@ -316,13 +316,13 @@ namespace GameLogic this->protocol[7].type = Oyster::Network::NetAttributeType_Float; this->protocol[8].type = Oyster::Network::NetAttributeType_Float; - this->object_ID = 0; + this->objectID = -1; memset(&this->position[0], 0, sizeof(float) * 3); memset(&this->rotationQ[0], 0, sizeof(float) * 4); } Protocol_ObjectPositionRotation(Oyster::Network::CustomNetProtocol& p) { - this->object_ID = p[1].value.netShort; + this->objectID = p[1].value.netShort; //POSITION this->position[0] = p[2].value.netFloat; this->position[1] = p[3].value.netFloat; @@ -348,13 +348,13 @@ namespace GameLogic this->protocol[7].type = Oyster::Network::NetAttributeType_Float; this->protocol[8].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; memcpy(&this->position[0], &p[0], sizeof(float) * 3); memcpy(&this->rotationQ[0], &r[0], sizeof(float) * 4); } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->object_ID; + this->protocol[1].value = this->objectID; this->protocol[2].value = this->position[0]; this->protocol[3].value = this->position[1]; this->protocol[4].value = this->position[2]; @@ -406,35 +406,28 @@ namespace GameLogic struct Protocol_ObjectDisable :public Oyster::Network::CustomProtocolObject { int objectID; - float seconds; Protocol_ObjectDisable() { this->protocol[0].value = protocol_Gameplay_ObjectDisabled; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->objectID = 0; - this->seconds = 0.0f; + this->objectID = -1; } - Protocol_ObjectDisable(int objctID, float seconds) + Protocol_ObjectDisable(int objctID) { this->protocol[0].value = protocol_Gameplay_ObjectDisabled; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->objectID = objctID; - this->seconds = seconds; } Protocol_ObjectDisable(Oyster::Network::CustomNetProtocol& p) { this->objectID = p[1].value.netInt; - this->seconds = p[2].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = this->objectID; - this->protocol[2].value = this->seconds; return protocol; } @@ -446,7 +439,7 @@ namespace GameLogic struct Protocol_ObjectCreate :public Oyster::Network::CustomProtocolObject { //ObjectType type; //ie player, box or whatever - int object_ID; + int objectID; std::string name; float position[3]; float rotationQ[4]; @@ -473,13 +466,13 @@ namespace GameLogic this->protocol[11].type = Oyster::Network::NetAttributeType_Float; this->protocol[12].type = Oyster::Network::NetAttributeType_Float; - this->object_ID = 0; + this->objectID = -1; memset(this->position, 0, sizeof(float) * 3); memset(this->rotationQ, 0, sizeof(float) * 4); } Protocol_ObjectCreate( Oyster::Network::CustomNetProtocol& p ) { - this->object_ID = p[1].value.netInt; + this->objectID = p[1].value.netInt; this->name.assign(p[2].value.netCharPtr); this->position[0] = p[3].value.netFloat; @@ -516,7 +509,7 @@ namespace GameLogic this->protocol[11].type = Oyster::Network::NetAttributeType_Float; this->protocol[12].type = Oyster::Network::NetAttributeType_Float; - object_ID = id; + objectID = id; this->name = path; memcpy(this->position, p, sizeof(float) * 3); @@ -526,7 +519,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = object_ID; + this->protocol[1].value = objectID; this->protocol.Set(2, name); this->protocol[3].value = this->position[0]; this->protocol[4].value = this->position[1]; @@ -546,10 +539,42 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectCreatePlayer 360 + //#define protocol_Gameplay_ObjectDelete 360 + struct Protocol_ObjectDelete :public Oyster::Network::CustomProtocolObject + { + int objectID; + + Protocol_ObjectDelete() + { + this->protocol[0].value = protocol_Gameplay_ObjectDelete; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = -1; + } + Protocol_ObjectDelete(int objctID) + { + this->protocol[0].value = protocol_Gameplay_ObjectDelete; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = objctID; + } + Protocol_ObjectDelete(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netInt; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = this->objectID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; + //#define protocol_Gameplay_ObjectCreatePlayer 361 struct Protocol_ObjectCreatePlayer :public Oyster::Network::CustomProtocolObject { - /*1*/ int object_ID; + /*1*/ int objectID; /*2*/ int teamId; /*3*/ bool owner; /*4*/ std::string name; @@ -589,7 +614,7 @@ namespace GameLogic Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { this->owner = p[1].value.netBool; - this->object_ID = p[2].value.netInt; + this->objectID = p[2].value.netInt; this->teamId = p[3].value.netInt; this->name.assign(p[4].value.netCharPtr); @@ -637,7 +662,7 @@ namespace GameLogic this->protocol[14].type = Oyster::Network::NetAttributeType_Float; this->protocol[15].type = Oyster::Network::NetAttributeType_Float; - this->object_ID = ObjectID; + this->objectID = ObjectID; this->teamId = teamID; this->owner = owner; this->name = name; @@ -649,7 +674,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol GetProtocol() override { this->protocol[1].value = this->owner; - this->protocol[2].value = this->object_ID; + this->protocol[2].value = this->objectID; this->protocol[3].value = this->teamId; this->protocol.Set(4, this->name); @@ -676,7 +701,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectJoinTeam 361 + //#define protocol_Gameplay_ObjectJoinTeam 362 struct Protocol_ObjectJoinTeam :public Oyster::Network::CustomProtocolObject { int objectID; @@ -716,7 +741,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectLeaveTeam 362 + //#define protocol_Gameplay_ObjectLeaveTeam 363 struct Protocol_ObjectLeaveTeam :public Oyster::Network::CustomProtocolObject { int objectID; @@ -748,7 +773,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectWeaponCooldown 363 + //#define protocol_Gameplay_ObjectWeaponCooldown 364 struct Protocol_ObjectWeaponCooldown :public Oyster::Network::CustomProtocolObject { float seconds; @@ -780,7 +805,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectWeaponEnergy 364 + //#define protocol_Gameplay_ObjectWeaponEnergy 365 struct Protocol_ObjectWeaponEnergy :public Oyster::Network::CustomProtocolObject { float energy; @@ -812,7 +837,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectRespawn 365 + //#define protocol_Gameplay_ObjectRespawn 366 struct Protocol_ObjectRespawn :public Oyster::Network::CustomProtocolObject { int objectID; @@ -864,7 +889,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectDie 366 + //#define protocol_Gameplay_ObjectDie 367 struct Protocol_ObjectDie :public Oyster::Network::CustomProtocolObject { int objectID; @@ -904,7 +929,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - //#define protocol_Gameplay_ObjectDisconnectPlayer 367 + //#define protocol_Gameplay_ObjectDisconnectPlayer 368 struct Protocol_ObjectDisconnectPlayer :public Oyster::Network::CustomProtocolObject { int objectID; @@ -937,7 +962,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } -//#define protocol_Gameplay_ObjectAction 368 +//#define protocol_Gameplay_ObjectAction 369 struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; @@ -958,7 +983,7 @@ namespace GameLogic objectID = p[1].value.netShort; animationID = p[2].value.netInt; } - Protocol_ObjectAction( int id, float animID) + Protocol_ObjectAction( int id, int animID) { this->protocol[0].value = protocol_Gameplay_ObjectAction; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 4828e7ed..02b1084a 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -63,15 +63,16 @@ #define protocol_Gameplay_ObjectEnabled 357 #define protocol_Gameplay_ObjectDisabled 358 #define protocol_Gameplay_ObjectCreate 359 -#define protocol_Gameplay_ObjectCreatePlayer 360 -#define protocol_Gameplay_ObjectJoinTeam 361 -#define protocol_Gameplay_ObjectLeaveTeam 362 -#define protocol_Gameplay_ObjectWeaponCooldown 363 -#define protocol_Gameplay_ObjectWeaponEnergy 364 -#define protocol_Gameplay_ObjectRespawn 365 -#define protocol_Gameplay_ObjectDie 366 -#define protocol_Gameplay_ObjectDisconnectPlayer 367 -#define protocol_Gameplay_ObjectAction 368 +#define protocol_Gameplay_ObjectDelete 360 +#define protocol_Gameplay_ObjectCreatePlayer 361 +#define protocol_Gameplay_ObjectJoinTeam 362 +#define protocol_Gameplay_ObjectLeaveTeam 363 +#define protocol_Gameplay_ObjectWeaponCooldown 364 +#define protocol_Gameplay_ObjectWeaponEnergy 365 +#define protocol_Gameplay_ObjectRespawn 366 +#define protocol_Gameplay_ObjectDie 367 +#define protocol_Gameplay_ObjectDisconnectPlayer 368 +#define protocol_Gameplay_ObjectAction 369 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index b9a17a5e..93d6fa56 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -148,11 +148,11 @@ using namespace DanBias; } void GameSession::ObjectDisabled( GameLogic::IObjectData* movedObject ) { - //GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) { - //GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { From 800f514028ed945ca39a5b1472909364d8659ae2 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 25 Feb 2014 18:25:51 +0100 Subject: [PATCH 13/46] Fixed player going bonkers on lower hemisphere --- Code/Game/GameLogic/Player.cpp | 27 +++---- .../Implementation/SimpleRigidBody.cpp | 70 +++++++++++-------- .../Implementation/SimpleRigidBody.h | 2 +- Code/Physics/GamePhysics/PhysicsAPI.h | 2 +- 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 52ac9b0c..735f7338 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -70,13 +70,9 @@ void Player::BeginFrame() Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly + this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - Oyster::Math::Quaternion firstUp = this->rigidBody->GetState().quaternion; - this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); - Oyster::Math::Quaternion secondTurn = this->rigidBody->GetState().quaternion; - this->rigidBody->SetRotation(secondTurn*firstUp); - // Direction data Oyster::Math::Float4x4 xform; xform = this->rigidBody->GetState().GetOrientation(); @@ -284,7 +280,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir) } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - this->rotationUp += deltaRadians; + this->rotationUp = deltaRadians; } void Player::Jump() @@ -333,17 +329,14 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - if( this->playerState != PLAYER_STATE_DEAD) - { - this->playerStats.hp -= damage; - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + this->life -= damage; + this->life = 0; - if(this->playerStats.hp <= 0) - { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; - } + if(this->life <= 0) + { + this->life = 0; + playerState = PLAYER_STATE_DEAD; + this->gameInstance->onDisableFnc(this, 0.0f); } } bool Player::deathTimerTick(float dt) @@ -359,4 +352,4 @@ void Player::setDeathTimer(float deathTimer) { this->deathTimer = deathTimer; this->playerState = PLAYER_STATE_DEAD; -} \ No newline at end of file +} diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 25c57e3b..9b9c7739 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -163,25 +163,15 @@ void SimpleRigidBody::SetRotation(::Oyster::Math::Float4x4 rotation) this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); } -void SimpleRigidBody::SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis) +void SimpleRigidBody::AddRotationAroundY(::Oyster::Math::Float angle) { - if(angularAxis.xyz.GetMagnitude() == 0) - { - return; - } - - float s = sin(angularAxis.w/2); - float x = angularAxis.x * s; - float y = angularAxis.y * s; - float z = angularAxis.z * s; - float w = cos(angularAxis.w/2); - btTransform trans; - btVector3 vector(angularAxis.x, angularAxis.y, angularAxis.z); - btQuaternion quaternion(x,y,z,w); + btQuaternion quaternion; trans = this->rigidBody->getWorldTransform(); - trans.setRotation(quaternion); + + quaternion = btQuaternion(trans.getBasis().getColumn(1), angle); + trans.setRotation(quaternion*trans.getRotation()); this->rigidBody->setWorldTransform(trans); this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); @@ -245,23 +235,45 @@ void SimpleRigidBody::SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math: void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up) { - Float3 vector = Float3(0, 1, 0).Cross(up); - - if(vector == Float3::null) - { - return; - } - - Float sine = vector.GetLength(); - Float cosine = acos(Float3(0, 1, 0).Dot(up)); - - btQuaternion quaternion(btVector3(vector.x, vector.y, vector.z),cosine); - + btQuaternion newRotation; btTransform trans; trans = this->rigidBody->getWorldTransform(); - trans.setRotation(quaternion); + + btVector3 v1 = trans.getBasis().getColumn(1); + btVector3 v2(up.x, up.y, up.z); + + btQuaternion q; + btVector3 a = v1.cross(v2); + + if (v1.dot(v2) < -0.999999) + { + btVector3 xCrossPre = btVector3(1, 0 ,0).cross(v1); + if(xCrossPre.length() < 0.000001) + xCrossPre = btVector3(0, 1 ,0).cross(v1); + xCrossPre.normalize(); + q.setRotation(xCrossPre, 3.1415); + } + else if (v1.dot(v2) > 0.999999) + { + q = btQuaternion(0, 0, 0, 1); + } + else + { + q.setX(a.x()); + q.setY(a.y()); + q.setZ(a.z()); + + q.setW(1 + v1.dot(v2)); + + q.normalize(); + } + + newRotation = q*trans.getRotation(); + + trans.setRotation(newRotation); this->rigidBody->setWorldTransform(trans); - this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); + + this->state.quaternion = Quaternion(Float3(newRotation.x(), newRotation.y(), newRotation.z()), newRotation.w()); } Float4x4 SimpleRigidBody::GetRotation() const diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index f3e7e0c6..65c59820 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -29,7 +29,7 @@ namespace Oyster void SetRotation(Math::Quaternion quaternion); void SetRotation(Math::Float3 eulerAngles); void SetRotation(::Oyster::Math::Float4x4 rotation); - void SetRotationAsAngularAxis(Math::Float4 angularAxis); + void AddRotationAroundY(Math::Float angle); void SetAngularFactor(Math::Float factor); void SetMass(Math::Float mass); diff --git a/Code/Physics/GamePhysics/PhysicsAPI.h b/Code/Physics/GamePhysics/PhysicsAPI.h index 33dc24a8..a536bdce 100644 --- a/Code/Physics/GamePhysics/PhysicsAPI.h +++ b/Code/Physics/GamePhysics/PhysicsAPI.h @@ -147,7 +147,7 @@ namespace Oyster virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0; virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0; virtual void SetRotation(::Oyster::Math::Float4x4 rotation) = 0; - virtual void SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis) = 0; + virtual void AddRotationAroundY(::Oyster::Math::Float angle) = 0; virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0; virtual void SetMass(::Oyster::Math::Float mass) = 0; From 4b4255cfcce313c3a0cb9f692bafdd1144b2dad4 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 26 Feb 2014 08:51:18 +0100 Subject: [PATCH 14/46] Player air check function --- Code/Game/GameLogic/Player.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 735f7338..ebc38d26 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -119,7 +119,7 @@ void Player::BeginFrame() } // Dampen velocity if certain keys are not pressed - if(key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.9f) + if(key_jump <= 0.001 && IsWalking()) { if(key_forward <= 0.001 && key_backward <= 0.001) { @@ -146,7 +146,7 @@ void Player::BeginFrame() walkDirection.Normalize(); // If on the ground, accelerate normally - if(this->rigidBody->GetLambda() < 0.9f) + if(IsWalking()) { if(forwardSpeed < maxSpeed) { @@ -158,7 +158,7 @@ void Player::BeginFrame() } } // If in the air, accelerate slower - if(this->rigidBody->GetLambda() >= 0.9f) + if(IsJumping()) { if(forwardSpeed < maxSpeed) { @@ -188,7 +188,7 @@ void Player::BeginFrame() if(key_jump > 0.001) { this->key_jump -= this->gameInstance->GetFrameTime(); - if(this->rigidBody->GetLambda() < 0.9f) + if(IsWalking()) { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); @@ -290,15 +290,15 @@ void Player::Jump() bool Player::IsWalking() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); + return (this->rigidBody->GetLambda() < 0.99f); } bool Player::IsJumping() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); + return (this->rigidBody->GetLambda() < 1.0f); } bool Player::IsIdle() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); + return (this->rigidBody->GetLambda() < 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); } void Player::Inactivate() From b39d52e5362ac5116929ebb3b6f45f874e878990 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 08:51:56 +0100 Subject: [PATCH 15/46] Weapon action enum added --- Code/Game/LevelLoader/ObjectDefines.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index aadc3382..3eae71a5 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -99,6 +99,11 @@ namespace GameLogic PlayerAction_Walk, PlayerAction_Idle, }; + enum WeaponAction + { + WeaponAtcion_PrimaryShoot, + WeaponAction_SecondaryShoot + }; enum PickupType { From 5a74f5368fff534b47a907946a2d9ce84e2b90c5 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 10:05:07 +0100 Subject: [PATCH 16/46] Added collision and weapon events and send them to client --- .../GameClient/GameClientState/GameState.cpp | 31 +++++++++++++ Code/Game/GameLogic/AttatchmentMassDriver.cpp | 10 ++++- Code/Game/GameLogic/CollisionManager.cpp | 3 +- Code/Game/GameLogic/Game.cpp | 4 ++ Code/Game/GameLogic/Game.h | 2 + Code/Game/GameLogic/GameAPI.h | 3 +- Code/Game/GameLogic/Level.cpp | 40 ++++++++++++----- Code/Game/GameProtocols/ObjectProtocols.h | 44 ++++++++++++++++++- .../GameProtocols/ProtocolIdentificationID.h | 1 + Code/Game/GameServer/GameSession.h | 1 + .../Implementation/GameSession_Gameplay.cpp | 5 +++ .../Implementation/GameSession_General.cpp | 1 + Code/Game/LevelLoader/ObjectDefines.h | 20 ++++++--- 13 files changed, 143 insertions(+), 22 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 6e35202a..fa4ab0f0 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -753,6 +753,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case GameLogic::PlayerAction::PlayerAction_Idle: player->playAnimation(L"idle", true); break; + + case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_Reload: + break; + + default: break; } @@ -760,6 +769,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectCollision: + { + Protocol_ObjectCollision decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + if( object ) + { + switch (decoded.collisionID) + { + case GameLogic::CollisionEvent::CollisionEvent_BasicCollision: + break; + default: + break; + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 62f3599e..13ef8fef 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,7 +1,7 @@ #include "AttatchmentMassDriver.h" #include "PhysicsAPI.h" #include "GameLogicStates.h" - +#include "Game.h" using namespace GameLogic; @@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForcePush(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); } break; @@ -55,7 +57,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(currentEnergy >= 1.0f) { currentEnergy -= 1.0f; - ForcePull(usage,dt); + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); } break; @@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForceZip(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate); } break; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..72057e2b 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -69,7 +69,8 @@ using namespace GameLogic; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } - + // send collision event message + ((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision); //return Physics::ICustomBody::SubscriptMessage_none; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index e4782582..d4abb9e1 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -188,6 +188,10 @@ void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) { this->onPickupEventFnc = functionPointer; } +void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) +{ + this->onCollisionEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 22b9fbda..f6e852a9 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -87,6 +87,7 @@ namespace GameLogic void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; + void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -108,6 +109,7 @@ namespace GameLogic GameEvent::ObjectDeadFunction onDeadFnc; GameEvent::AnimationEventFunction onPlayerActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; + GameEvent::CollisionEventFunction onCollisionEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 1bf39816..7bf01d60 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -33,6 +33,7 @@ namespace GameLogic typedef void(*ObjectDeadFunction)(IObjectData* object, float seconds); // Callback method that sends death timer typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer + typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); //etc... }; @@ -188,7 +189,7 @@ namespace GameLogic virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; - + virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index f7c48f8b..40a2b55a 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -16,6 +16,7 @@ using namespace Oyster::Math; Level::Level(void) { + srand (time(NULL)); objID = 100; } Level::~Level(void) @@ -405,6 +406,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (!this->playerObjects[i]) + { + this->playerObjects[i] = player; + return; + } + } + // if no free space, allocate a new spot this->playerObjects.Push(player); } void Level::RemovePlayerFromGame(Player *player) @@ -413,7 +423,7 @@ void Level::RemovePlayerFromGame(Player *player) { if ((Player*)this->playerObjects[i] == player) { - //this->playerObjects[i]. + this->playerObjects[i] = nullptr; } } } @@ -426,7 +436,8 @@ void Level::RespawnPlayer(Player *player) { //this->teamManager.RespawnPlayerRandom(player); - Float3 spawnPoint = spawnPoints[0]; + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; player->Respawn(spawnPoint); } void Level::Update(float deltaTime) @@ -434,17 +445,22 @@ void Level::Update(float deltaTime) // update lvl-things for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + if(this->playerObjects[i]) { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); - } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) - { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], DEATH_TIMER); // add killer ID - Player* killer = this->playerObjects[i]->getAffectingPlayer(); + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + } } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 5ce8bd9e..c37c0faf 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -962,7 +962,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } -//#define protocol_Gameplay_ObjectAction 369 + //#define protocol_Gameplay_ObjectAction 369 struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; @@ -1003,4 +1003,46 @@ namespace GameLogic private: Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectCollision 370 + struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject + { + short objectID; + int collisionID; + // TODO: maybe position, impact, and velocity + + Protocol_ObjectCollision() + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = -1; + this->collisionID = -1; + } + Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netShort; + this->collisionID = p[2].value.netInt; + } + Protocol_ObjectCollision( int id, int collisionID) + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = id; + this->collisionID = collisionID; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = objectID; + this->protocol[2].value = collisionID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 02b1084a..eea1e945 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -73,6 +73,7 @@ #define protocol_Gameplay_ObjectDie 367 #define protocol_Gameplay_ObjectDisconnectPlayer 368 #define protocol_Gameplay_ObjectAction 369 +#define protocol_Gameplay_ObjectCollision 370 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 6ab0c42b..38a8e119 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -105,6 +105,7 @@ namespace DanBias static void ObjectDead ( GameLogic::IObjectData* movedObject, float seconds ); static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); + static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 93d6fa56..b0703983 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -176,6 +176,11 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); } + void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index ca869fb7..d19fcecf 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); + this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 3eae71a5..e77174f7 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -95,16 +95,26 @@ namespace GameLogic enum PlayerAction { - PlayerAction_Jump, - PlayerAction_Walk, - PlayerAction_Idle, + PlayerAction_Jump = 0, + PlayerAction_Walk = 1, + PlayerAction_Idle = 2, }; + // continue ID counting from playerAction enum WeaponAction { - WeaponAtcion_PrimaryShoot, - WeaponAction_SecondaryShoot + WeaponAction_PrimaryShoot = 3, + WeaponAction_SecondaryShoot = 4, + WeaponAction_UtilityActivate = 5, + WeaponAction_Reload = 6, + WeaponAction_EnergyDepleted = 7, + }; + // TODO: add more collision Events + enum CollisionEvent + { + CollisionEvent_BasicCollision, + }; enum PickupType { PickupType_Health, From 5675155be44b0243fa8c6e53605d0b069464f79c Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 26 Feb 2014 10:05:18 +0100 Subject: [PATCH 17/46] Fixed player jump --- Code/Game/GameLogic/Player.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ebc38d26..9625822e 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -70,7 +70,7 @@ void Player::BeginFrame() Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly - this->rigidBody->AddRotationAroundY(this->rotationUp); + this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); // Direction data @@ -119,7 +119,7 @@ void Player::BeginFrame() } // Dampen velocity if certain keys are not pressed - if(key_jump <= 0.001 && IsWalking()) + if(key_jump <= 0.001 && IsWalking()) { if(key_forward <= 0.001 && key_backward <= 0.001) { @@ -146,7 +146,7 @@ void Player::BeginFrame() walkDirection.Normalize(); // If on the ground, accelerate normally - if(IsWalking()) + if(IsWalking()) { if(forwardSpeed < maxSpeed) { @@ -158,7 +158,7 @@ void Player::BeginFrame() } } // If in the air, accelerate slower - if(IsJumping()) + if(IsJumping()) { if(forwardSpeed < maxSpeed) { @@ -294,11 +294,11 @@ bool Player::IsWalking() } bool Player::IsJumping() { - return (this->rigidBody->GetLambda() < 1.0f); + return (this->rigidBody->GetLambda() == 1.0f); } bool Player::IsIdle() { - return (this->rigidBody->GetLambda() < 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); + return (this->rigidBody->GetLambda() == 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); } void Player::Inactivate() From 762aea73a0e29e82e01bd1850f7da5e57805b9b4 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:08 +0100 Subject: [PATCH 18/46] Fixed static id not matching on client/server. --- Code/Game/GameLogic/Level.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 40a2b55a..d785a082 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -239,7 +239,11 @@ bool Level::InitiateLevel(std::wstring levelPath) { LevelMetaData* LevelObjData = ((LevelMetaData*)obj); std::string levelName = LevelObjData->levelName; + // LevelObjData->worldSize; + + //LevelMetaData is not an object. + --this->objID; } break; case ObjectType::ObjectType_Static: From 8a6590762529c50ed62d752bfb27cdd967fc98cb Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:43 +0100 Subject: [PATCH 19/46] Does not render non visible models anymore. --- Code/Game/GameClient/GameClientState/C_Object.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index b168b92c..8e84da8e 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -91,7 +91,10 @@ void C_Object::Render() { if( this->model ) { - Oyster::Graphics::API::RenderModel(model); + if(this->model->Visible) + { + Oyster::Graphics::API::RenderModel(model); + } } } void C_Object::Release() From 28e84854d14f8b15b8bda40bc61b408c8b3ce431 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:23:38 +0100 Subject: [PATCH 20/46] Health pickups is now working! --- .../GameClient/GameClientState/GameState.cpp | 18 ++++- Code/Game/GameLogic/CollisionManager.cpp | 20 +++-- Code/Game/GameLogic/PickupSystem/Pickup.cpp | 1 + .../GameLogic/PickupSystem/PickupHealth.cpp | 4 + Code/Game/GameLogic/Player.cpp | 78 ++++++++++++++----- .../Implementation/GameSession_Gameplay.cpp | 2 +- Code/Game/LevelLoader/LevelParser.cpp | 8 ++ 7 files changed, 101 insertions(+), 30 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index fa4ab0f0..f90bc0c7 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -146,8 +146,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.SetPosition( p->getPos() ); Float3 offset = Float3( 0.0f ); // DEBUG position of camera so we can see the player model - offset.y = p->getScale().y * 5.0f; - offset.z = p->getScale().z * -5.0f; + //offset.y = p->getScale().y * 5.0f; + //offset.z = p->getScale().z * -5.0f; // !DEBUG this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); @@ -191,7 +191,7 @@ bool GameState::Render() { if(playerObject->second) { - //if( this->privData->myId != playerObject->second->GetId() ) + if( this->privData->myId != playerObject->second->GetId() ) { playerObject->second->Render(); } @@ -601,6 +601,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) @@ -618,6 +624,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 72057e2b..32f5bdc5 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -44,7 +44,6 @@ using namespace GameLogic; realObjB = realObjA; } - switch (realObjB->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_Generic: @@ -369,14 +368,19 @@ using namespace GameLogic; Object* a = (Object*)objA->GetCustomTag(); Object* b = (Object*)objB->GetCustomTag(); - if(!a) + if(!a) return; - if(!b) + if(!b) return; if(b->GetObjectType() == ObjectSpecialType_Player) { - ((Pickup*)a)->OnCollision((Player*)(b)); + //Only update if it is active. And if the player is alive + if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + return; } else if(a->GetObjectType() != ObjectSpecialType_Player) { @@ -384,6 +388,10 @@ using namespace GameLogic; //Do nothing. return; } - - ((Pickup*)b)->OnCollision((Player*)a); + + //Only update if it is active. And if the player is alive + if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)b)->OnCollision((Player*)a); + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 73a319f8..a7bcaf14 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi this->active = true; this->spawnTime = spawnTime; timer.reset(); + this->GetRigidBody()->MoveToLimbo(); } Pickup::~Pickup() diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp index 56cbef1e..5473c44c 100644 --- a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -1,4 +1,5 @@ #include "PickupHealth.h" +#include "../Game.h" using namespace GameLogic; @@ -14,5 +15,8 @@ PickupHealth::~PickupHealth() void PickupHealth::OnCollision(Player *player) { timer.reset(); + ((Game*)&Game::Instance())->onDisableFnc(this); + + this->active = false; player->DamageLife(-hpValue); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 9625822e..9a440b2d 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -12,24 +12,26 @@ Player::Player() :DynamicObject() { Player::initPlayerData(); + AffectedObjects.Reserve(15); + this->weapon = NULL; this->teamID = -1; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { - weapon = new Weapon(2,this); - + this->weapon = new Weapon(2,this); Player::initPlayerData(); + AffectedObjects.Reserve(15); this->teamID = teamID; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { - weapon = new Weapon(2,this); - + this->weapon = new Weapon(2,this); Player::initPlayerData(); + AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -70,9 +72,13 @@ void Player::BeginFrame() Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly - this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); + Oyster::Math::Quaternion firstUp = this->rigidBody->GetState().quaternion; + this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); + Oyster::Math::Quaternion secondTurn = this->rigidBody->GetState().quaternion; + this->rigidBody->SetRotation(secondTurn*firstUp); + // Direction data Oyster::Math::Float4x4 xform; xform = this->rigidBody->GetState().GetOrientation(); @@ -119,7 +125,7 @@ void Player::BeginFrame() } // Dampen velocity if certain keys are not pressed - if(key_jump <= 0.001 && IsWalking()) + if(key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.9f) { if(key_forward <= 0.001 && key_backward <= 0.001) { @@ -146,7 +152,7 @@ void Player::BeginFrame() walkDirection.Normalize(); // If on the ground, accelerate normally - if(IsWalking()) + if(this->rigidBody->GetLambda() < 0.9f) { if(forwardSpeed < maxSpeed) { @@ -158,7 +164,7 @@ void Player::BeginFrame() } } // If in the air, accelerate slower - if(IsJumping()) + if(this->rigidBody->GetLambda() >= 0.9f) { if(forwardSpeed < maxSpeed) { @@ -188,7 +194,7 @@ void Player::BeginFrame() if(key_jump > 0.001) { this->key_jump -= this->gameInstance->GetFrameTime(); - if(IsWalking()) + if(this->rigidBody->GetLambda() < 0.9f) { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); @@ -211,6 +217,16 @@ void Player::BeginFrame() void Player::EndFrame() { + //check if there are any objects that can be removed from the AffectedObjects list + for(int i = 0; i < this->AffectedObjects.Size(); i++) + { + if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) + { + this->AffectedObjects[i]->RemoveAffectedBy(); + this->AffectedObjects.Remove(i); + } + + } } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -280,7 +296,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir) } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - this->rotationUp = deltaRadians; + this->rotationUp += deltaRadians; } void Player::Jump() @@ -290,15 +306,15 @@ void Player::Jump() bool Player::IsWalking() { - return (this->rigidBody->GetLambda() < 0.99f); + return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); } bool Player::IsJumping() { - return (this->rigidBody->GetLambda() == 1.0f); + return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); } bool Player::IsIdle() { - return (this->rigidBody->GetLambda() == 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); + return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); } void Player::Inactivate() @@ -329,16 +345,38 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - this->life -= damage; - this->life = 0; - - if(this->life <= 0) + if(damage != 0) { - this->life = 0; - playerState = PLAYER_STATE_DEAD; - this->gameInstance->onDisableFnc(this, 0.0f); + this->playerStats.hp -= damage; + + if(this->playerStats.hp > 100) + this->playerStats.hp = 100; + + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + + if(this->playerStats.hp <= 0) + { + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; + } } } + +void Player::AddAffectedObject(DynamicObject &AffectedObject) +{ + //check if object already exists in the list, if so then do not add + for(int i = 0; i < AffectedObjects.Size(); i++) + { + if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) + { + //object already exists, exit function + return; + } + } + //else you add the object to the stack + AffectedObjects.Push(&AffectedObject); +} bool Player::deathTimerTick(float dt) { this->deathTimer -= dt; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index b0703983..d1e32b55 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -152,7 +152,7 @@ using namespace DanBias; } void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 680b0358..f94513b0 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -167,6 +167,14 @@ std::vector> LevelParser::Parse(std::string filen ParseObject(&buffer[counter], &header->healthValue, 4); counter += 4; + + // DEBUG + header->position[1] = 150; + header->spawnTime = 5; + header->boundingVolume.box.mass = 0; + header->typeID = ObjectType_Static; + header->healthValue = 50; + // !DEBUG objects.push_back(header); break; From d4e80733d29baac76b1b1e2c44eeb303ebcf0abb Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 11:09:24 +0100 Subject: [PATCH 21/46] Fixed deleting problems when shuting down --- Code/Game/GameLogic/Level.cpp | 116 +++--------------- Code/Game/GameLogic/Level.h | 11 +- Code/Game/GameLogic/Player.cpp | 6 +- .../GameServer/Implementation/GameClient.cpp | 3 - 4 files changed, 27 insertions(+), 109 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index d785a082..233e73da 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -17,12 +17,10 @@ using namespace Oyster::Math; Level::Level(void) { srand (time(NULL)); - objID = 100; + objIDCounter = 100; } Level::~Level(void) { - delete this->levelObj; - this->levelObj = NULL; } Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { @@ -32,7 +30,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; @@ -50,22 +48,22 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_RedExplosiveBox: @@ -73,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -82,24 +80,24 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_JumpPad: @@ -107,39 +105,28 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = 500; //((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 pushForce = dir * power; - gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce); + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination); - } - break; - //case ObjectSpecialType_SpawnPoint: - //{ - // save - - //} - break; - case ObjectSpecialType_Player: - { - // should not be read from the lvl format + gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, destination); } break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_PickupHealth: { - gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objIDCounter, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; } @@ -231,7 +218,7 @@ bool Level::InitiateLevel(std::wstring levelPath) for (int i = 0; i < objCount; i++) { - ++this->objID; + ++this->objIDCounter; ObjectTypeHeader* obj = objects.at(i); switch (obj->typeID) { @@ -243,7 +230,7 @@ bool Level::InitiateLevel(std::wstring levelPath) // LevelObjData->worldSize; //LevelMetaData is not an object. - --this->objID; + --this->objIDCounter; } break; case ObjectType::ObjectType_Static: @@ -338,71 +325,6 @@ bool Level::InitiateLevel(std::wstring levelPath) return true; } -bool Level::InitiateLevel(float radius) -{ - API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); - API::Instance().SetGravity(200); - int idCount = 100; - // add level sphere - ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World, idCount++); - - //this->levelObj->objectID = idCount++; - rigidBody->SetCustomTag(levelObj); - - - ICustomBody* rigidBody_TestBox; - - int nrOfBoxex = 5; - int offset = 0; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - } - /*offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0,5, -605 -( i*5)), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - - } - offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(200, 620 + ( i*7), 0), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - } - offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(5, 605 + i*5, 0), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); - - }*/ - - // add crystal - ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - - // add house - ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++)); - - // add jumppad - - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); - return true; -} void Level::AddPlayerToTeam(Player *player, int teamID) { @@ -490,7 +412,7 @@ void Level::PhysicsOnMoveLevel(const ICustomBody *object) Object* temp = (Object*)object->GetCustomTag(); ((Game*)&Game::Instance())->onMoveFnc(temp); } -Utility::DynamicMemory::DynamicArray> Level::GetPlayers() +Utility::DynamicMemory::DynamicArray Level::GetPlayers() { return this->playerObjects; } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 7d6c25c9..876fd034 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -35,7 +35,6 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ bool InitiateLevel(std::wstring levelPath); - bool InitiateLevel(float radius); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); @@ -77,19 +76,19 @@ namespace GameLogic static void PlayerDied( Player* player ); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); - Utility::DynamicMemory::DynamicArray> GetPlayers(); + Utility::DynamicMemory::DynamicArray GetPlayers(); Utility::DynamicMemory::DynamicArray> GetStaticObjects(); Utility::DynamicMemory::DynamicArray> GetDynamicObject(); private: - Utility::DynamicMemory::DynamicArray> playerObjects; + Utility::DynamicMemory::DynamicArray playerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; GameModeType gameMode; - Utility::DynamicMemory::SmartPointer rigidBodyLevel; - StaticObject *levelObj; - int objID; + //Utility::DynamicMemory::SmartPointer rigidBodyLevel; +// //StaticObject *levelObj; + int objIDCounter; Utility::DynamicMemory::DynamicArray spawnPoints; PickupSystem pickupSystem; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 9a440b2d..6682237f 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -37,10 +37,10 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom Player::~Player(void) { - if(weapon) + if(this->weapon) { - delete weapon; - weapon = NULL; + delete this->weapon; + this->weapon = NULL; } } void Player::initPlayerData() diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 90b412ef..74795ce6 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,9 +25,6 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerplayer) - this->player->Inactivate(); - this->isReady = false; this->character = L"char_orca.dan"; this->alias = L"Unknown"; From 7d7d4754996ef34da5795d24220596634c2333d4 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 11:53:33 +0100 Subject: [PATCH 22/46] InGame keys: Go to mainMenu with M. Exit client with ESC. Fix drop in drop out correctly. --- .../GameClient/GameClientState/GameState.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index f90bc0c7..4b3e7cb8 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -157,19 +157,28 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { - GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime ); + GameStateUI::UIState UIstate = this->gameUI->Update( deltaTime ); switch (UIstate) { + case DanBias::Client::GameStateUI::UIState_shut_down: + { + this->privData->nextState = ClientState_Quit; + // disconnect + } + + break; case DanBias::Client::GameStateUI::UIState_same: break; case DanBias::Client::GameStateUI::UIState_gaming: break; case DanBias::Client::GameStateUI::UIState_main_menu: - //this->privData->nextState = - break; - case DanBias::Client::GameStateUI::UIState_shut_down: - this->privData->nextState = ClientState_Quit; + { + this->privData->nextState = ClientState_Main; + // disconnect + } + break; + default: break; } From 977920b3607498f925dfc1feb4bdc1c31a6a4e77 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 26 Feb 2014 12:00:30 +0100 Subject: [PATCH 23/46] GL - merge stuff --- Code/Game/GameLogic/CollisionManager.cpp | 4 +- Code/Game/GameLogic/DynamicObject.cpp | 5 -- Code/Game/GameLogic/Level.cpp | 58 +++++++++++++++++++----- Code/Game/GameLogic/Player.cpp | 35 +++----------- Code/Game/GameLogic/Player.h | 8 +--- 5 files changed, 58 insertions(+), 52 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 32f5bdc5..c355fd04 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -255,16 +255,18 @@ using namespace GameLogic; { //realobjA is the affectedObject, transfer this to realobjB realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + return; } if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) { //realobjB is the affectedObject, transfer this to realobjA realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + return; } - if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL) + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL && ( realObjA->getAffectingPlayer()->GetID() != realObjB->getAffectingPlayer()->GetID())) { //Both objects have a player affecting them, now use the special case if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 844deaf2..d785b4d4 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -90,11 +90,6 @@ void DynamicObject::Activate() void DynamicObject::SetAffectedBy(Player &player) { this->affectedBy = &player; - if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player - { - player.AddAffectedObject(*this); - } - } Player* DynamicObject::getAffectingPlayer() diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 233e73da..56c0e21c 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -369,23 +369,59 @@ void Level::RespawnPlayer(Player *player) void Level::Update(float deltaTime) { // update lvl-things + + for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if(this->playerObjects[i]) + if(this->playerObjects[i]->getAffectingPlayer() != NULL) { - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + + } + + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + if(!killer) //if there is no killer then you commited suicide { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); + killer = this->playerObjects[i]; } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID + } + } + + for(int i = 0; i < dynamicObjects.Size(); i++) + { + if(dynamicObjects[i]->getAffectingPlayer() != NULL) + { + Oyster::Math::Float vel = dynamicObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude(); + + if(vel <= 0.1f) // is bearly moving { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + //set the tag AffectedBy to NULL + dynamicObjects[i]->RemoveAffectedBy(); + } + } + } + + for(int i = 0; i < playerObjects.Size(); i++) + { + if(playerObjects[i]->getAffectingPlayer() != NULL) + { + Oyster::Math::Float vel = playerObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude(); + + if(vel <= 0.1f) // is bearly moving + { + //set the tag AffectedBy to NULL + playerObjects[i]->RemoveAffectedBy(); } } } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 6682237f..1d95a83b 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -8,11 +8,11 @@ using namespace GameLogic; using namespace Oyster::Physics; const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; +const float AFFECTED_TIMER = 1.0f; Player::Player() :DynamicObject() { Player::initPlayerData(); - AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; } @@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -31,7 +30,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -57,7 +55,7 @@ void Player::initPlayerData() this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; - this->invincibleCooldown = 0; + this->RecentlyAffected = 0; this->deathTimer = 0; this->rotationUp = 0; @@ -67,7 +65,10 @@ void Player::BeginFrame() { if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) { - weapon->Update(0.002f); + weapon->Update(0.002f); + + + Oyster::Math::Float maxSpeed = 30; @@ -217,16 +218,6 @@ void Player::BeginFrame() void Player::EndFrame() { - //check if there are any objects that can be removed from the AffectedObjects list - for(int i = 0; i < this->AffectedObjects.Size(); i++) - { - if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) - { - this->AffectedObjects[i]->RemoveAffectedBy(); - this->AffectedObjects.Remove(i); - } - - } } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -363,20 +354,6 @@ void Player::DamageLife(int damage) } } -void Player::AddAffectedObject(DynamicObject &AffectedObject) -{ - //check if object already exists in the list, if so then do not add - for(int i = 0; i < AffectedObjects.Size(); i++) - { - if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) - { - //object already exists, exit function - return; - } - } - //else you add the object to the stack - AffectedObjects.Push(&AffectedObject); -} bool Player::deathTimerTick(float dt) { this->deathTimer -= dt; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 2d6f0a35..edb4cc79 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -67,8 +67,6 @@ namespace GameLogic void SetLookDir(const Oyster::Math3D::Float3& lookDir); void TurnLeft(Oyster::Math3D::Float deltaRadians); - - void AddAffectedObject(DynamicObject &AffectedObject); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -90,6 +88,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() const; int GetTeamID() const; PLAYER_STATE GetState() const; + Oyster::Math::Float GetRecentlyAffected(); void DamageLife(int damage); void setDeathTimer(float deathTimer); @@ -99,14 +98,11 @@ namespace GameLogic void EndFrame(); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - private: void Jump(); void initPlayerData(); private: - - int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -123,7 +119,7 @@ namespace GameLogic float deathTimer; bool hasTakenDamage; - float invincibleCooldown; + Oyster::Math::Float RecentlyAffected; PlayerStats playerStats; PlayerScore playerScore; From c32871687e7e0f0177c4be9672b38c152f6ce845 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 13:59:06 +0100 Subject: [PATCH 24/46] Found bug. Explosive box was increasing the ID. --- Code/Game/GameLogic/Level.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 56c0e21c..3fa39829 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -71,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -228,9 +228,6 @@ bool Level::InitiateLevel(std::wstring levelPath) std::string levelName = LevelObjData->levelName; // LevelObjData->worldSize; - - //LevelMetaData is not an object. - --this->objIDCounter; } break; case ObjectType::ObjectType_Static: From d81a1c204cfcf0897b7659d9cc50a7389bec72d9 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 26 Feb 2014 14:06:02 +0100 Subject: [PATCH 25/46] Added early triangle collisions --- Code/Game/GameLogic/Level.cpp | 37 ++++++++ Code/Game/GameLogic/Level.h | 2 + Code/Game/GameLogic/Player.cpp | 85 +++++++++++-------- .../Implementation/PhysicsAPI_Impl.cpp | 25 ++---- .../Implementation/SimpleRigidBody.cpp | 39 +++++---- .../Implementation/SimpleRigidBody.h | 3 +- Code/Physics/GamePhysics/PhysicsAPI.h | 3 +- 7 files changed, 122 insertions(+), 72 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 3fa39829..546562f9 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -196,6 +196,38 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic); return rigidBody; } +ICustomBody* Level::InitRigidBodyMesh( const ObjectHeader* obj) +{ + ICustomBody* rigidBody = NULL; + Oyster::Math::Float3 rigidWorldPos; + Oyster::Math::Float4 rigidWorldRotation; + float rigidBodyMass; + float rigidBodyRadius; + + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)obj->position + (Oyster::Math::Float3)obj->boundingVolume.cgMesh.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * obj->scale; + + //offset the rigidRotation from modelspace to worldspace; + Oyster::Math::Quaternion worldPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->rotation[0],obj->rotation[1],obj->rotation[2]), obj->rotation[3]); + Oyster::Math::Quaternion physicsPosQuaternion = Oyster::Math::Quaternion(Oyster::Math::Float3(obj->boundingVolume.cgMesh.rotation[0],obj->boundingVolume.cgMesh.rotation[1],obj->boundingVolume.cgMesh.rotation[2]), obj->boundingVolume.cgMesh.rotation[3]); + Oyster::Math::Quaternion rigidWorldQuaternion = worldPosQuaternion * physicsPosQuaternion; + + rigidWorldRotation = Oyster::Math::Float4(rigidWorldQuaternion); + + + //mass scaled + rigidBodyMass = obj->scale[0] * obj->scale[1] * obj->scale[2] * obj->boundingVolume.cgMesh.mass; + + //Radius scaled + //rigidBodyRadius = (obj->scale[0]) * obj->boundingVolume.sphere.radius; + //rigidBodyRadius = (obj->scale[0] * obj->scale[1] * obj->scale[2]) * obj->boundingVolume.sphere.radius; + + //create the rigid body + rigidBody = API::Instance().AddTriangleMesh(obj->boundingVolume.cgMesh.filename, rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.cgMesh.restitutionCoeff , obj->boundingVolume.cgMesh.frictionCoeffStatic , obj->boundingVolume.cgMesh.frictionCoeffDynamic); + return rigidBody; +} bool Level::InitiateLevel(std::wstring levelPath) { LevelLoader ll; @@ -253,6 +285,11 @@ bool Level::InitiateLevel(std::wstring levelPath) //rigidBody_Static = InitRigidBodyCylinder(staticObjData); } + else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_CG_MESH) + { + rigidBody_Static = InitRigidBodyMesh(staticObjData); + } + if(rigidBody_Static != NULL) { // create game object diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 876fd034..1811c9af 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -37,6 +37,8 @@ namespace GameLogic bool InitiateLevel(std::wstring levelPath); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); + Oyster::Physics::ICustomBody* InitRigidBodyMesh( const ObjectHeader* obj); + Object* CreateGameObj(ObjectHeader* obj, Oyster::Physics::ICustomBody* rigidBody); /******************************************************** diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 1d95a83b..49babcc3 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -8,11 +8,11 @@ using namespace GameLogic; using namespace Oyster::Physics; const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; -const float AFFECTED_TIMER = 1.0f; Player::Player() :DynamicObject() { Player::initPlayerData(); + AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; } @@ -22,6 +22,7 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) { this->weapon = new Weapon(2,this); Player::initPlayerData(); + AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -30,15 +31,16 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { this->weapon = new Weapon(2,this); Player::initPlayerData(); + AffectedObjects.Reserve(15); this->teamID = teamID; } Player::~Player(void) { - if(this->weapon) + if(weapon) { - delete this->weapon; - this->weapon = NULL; + delete weapon; + weapon = NULL; } } void Player::initPlayerData() @@ -55,7 +57,7 @@ void Player::initPlayerData() this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; - this->RecentlyAffected = 0; + this->invincibleCooldown = 0; this->deathTimer = 0; this->rotationUp = 0; @@ -65,21 +67,14 @@ void Player::BeginFrame() { if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) { - weapon->Update(0.002f); - - - + weapon->Update(0.002f); Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly + this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - Oyster::Math::Quaternion firstUp = this->rigidBody->GetState().quaternion; - this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); - Oyster::Math::Quaternion secondTurn = this->rigidBody->GetState().quaternion; - this->rigidBody->SetRotation(secondTurn*firstUp); - // Direction data Oyster::Math::Float4x4 xform; xform = this->rigidBody->GetState().GetOrientation(); @@ -126,7 +121,7 @@ void Player::BeginFrame() } // Dampen velocity if certain keys are not pressed - if(key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.9f) + if(key_jump <= 0.001 && IsWalking()) { if(key_forward <= 0.001 && key_backward <= 0.001) { @@ -153,7 +148,7 @@ void Player::BeginFrame() walkDirection.Normalize(); // If on the ground, accelerate normally - if(this->rigidBody->GetLambda() < 0.9f) + if(IsWalking()) { if(forwardSpeed < maxSpeed) { @@ -165,7 +160,7 @@ void Player::BeginFrame() } } // If in the air, accelerate slower - if(this->rigidBody->GetLambda() >= 0.9f) + if(IsJumping()) { if(forwardSpeed < maxSpeed) { @@ -195,7 +190,7 @@ void Player::BeginFrame() if(key_jump > 0.001) { this->key_jump -= this->gameInstance->GetFrameTime(); - if(this->rigidBody->GetLambda() < 0.9f) + if(IsWalking()) { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); @@ -218,6 +213,16 @@ void Player::BeginFrame() void Player::EndFrame() { + //check if there are any objects that can be removed from the AffectedObjects list + for(int i = 0; i < this->AffectedObjects.Size(); i++) + { + if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) + { + this->AffectedObjects[i]->RemoveAffectedBy(); + this->AffectedObjects.Remove(i); + } + + } } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -287,7 +292,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir) } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - this->rotationUp += deltaRadians; + this->rotationUp = deltaRadians; } void Player::Jump() @@ -297,15 +302,15 @@ void Player::Jump() bool Player::IsWalking() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING); + return (this->rigidBody->GetLambdaUp() < 0.99f); } bool Player::IsJumping() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING); + return (this->rigidBody->GetLambdaUp() == 1.0f); } bool Player::IsIdle() { - return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE); + return (this->rigidBody->GetLambdaUp() == 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); } void Player::Inactivate() @@ -336,24 +341,32 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - if(damage != 0) + this->playerStats.hp -= damage; + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + + if(this->playerStats.hp <= 0) { - this->playerStats.hp -= damage; - - if(this->playerStats.hp > 100) - this->playerStats.hp = 100; - - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - - if(this->playerStats.hp <= 0) - { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; - } + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; } + } +void Player::AddAffectedObject(DynamicObject &AffectedObject) +{ + //check if object already exists in the list, if so then do not add + for(int i = 0; i < AffectedObjects.Size(); i++) + { + if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) + { + //object already exists, exit function + return; + } + } + //else you add the object to the stack + AffectedObjects.Push(&AffectedObject); +} bool Player::deathTimerTick(float dt) { this->deathTimer -= dt; diff --git a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index b86f3821..27cd8ba5 100644 --- a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -229,15 +229,15 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma SimpleRigidBody* body = new SimpleRigidBody; SimpleRigidBody::State state; - btBulletWorldImporter bulletFile; + btBulletWorldImporter bulletFile(0); typedef std::codecvt_utf8 convert_typeX; std::wstring_convert converterX; - std::string bulletPath = converterX.to_bytes(fileName); + //std::string bulletPath = converterX.to_bytes(); // Add collision shape - bulletFile.loadFile(bulletPath.c_str()); + bulletFile.loadFile("C:\\DV1477\\Git Repository\\Danbias\\Bin\\Content\\Worlds\\cgf\\structure_corporation.bullet"); btCollisionShape* collisionShape = bulletFile.getCollisionShapeByIndex(0); body->SetCollisionShape(collisionShape); @@ -247,8 +247,8 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma // Add rigid body btVector3 fallInertia(0, 0, 0); - collisionShape->calculateLocalInertia(mass, fallInertia); - btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, collisionShape, fallInertia); + //collisionShape->calculateLocalInertia(mass, fallInertia); + btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, motionState, collisionShape, fallInertia); btRigidBody* rigidBody = new btRigidBody(rigidBodyCI); rigidBody->setFriction(staticFriction); rigidBody->setRestitution(restitution); @@ -264,7 +264,7 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma state.dynamicFrictionCoeff = dynamicFriction; state.staticFrictionCoeff = staticFriction; state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); - state.mass = mass; + state.mass = 0; body->SetState(state); @@ -291,7 +291,7 @@ void API_Impl::UpdateWorld() simpleBody->SetPreviousVelocity(simpleBody->GetLinearVelocity()); } - this->dynamicsWorld->stepSimulation(this->timeStep, 10, this->timeStep); + this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep); ICustomBody::State state; @@ -314,23 +314,12 @@ void API_Impl::UpdateWorld() ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer(); ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer(); - - int numContacts = contactManifold->getNumContacts(); for (int j=0;jgetContactPoint(j); if (pt.getDistance()<0.f) { - if(bodyA->GetState().mass == 40 && bodyB->GetState().centerPos == Float3::null) - { - const char* breakPoint = "STOP"; - } - if(bodyB->GetState().mass == 40 && bodyA->GetState().centerPos == Float3::null) - { - const char* breakPoint = "STOP"; - } - const btVector3& ptA = pt.getPositionWorldOnA(); const btVector3& ptB = pt.getPositionWorldOnB(); const btVector3& normalOnB = pt.m_normalWorldOnB; diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 9b9c7739..7fbd44e8 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -63,7 +63,8 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) this->rigidBody->setFriction(state.staticFrictionCoeff); this->rigidBody->setRestitution(state.restitutionCoeff); btVector3 fallInertia(0, 0, 0); - collisionShape->calculateLocalInertia(state.mass, fallInertia); + if(state.mass != 0) + collisionShape->calculateLocalInertia(state.mass, fallInertia); this->rigidBody->setMassProps(state.mass, fallInertia); this->state = state; @@ -185,7 +186,8 @@ void SimpleRigidBody::SetAngularFactor(Float factor) void SimpleRigidBody::SetMass(Float mass) { btVector3 fallInertia(0, 0, 0); - collisionShape->calculateLocalInertia(mass, fallInertia); + if(mass != 0) + collisionShape->calculateLocalInertia(mass, fallInertia); this->rigidBody->setMassProps(mass, fallInertia); this->state.mass = mass; } @@ -362,29 +364,25 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) { btTransform xform; xform = this->rigidBody->getWorldTransform (); - Float3 normalDown = -this->state.centerPos.GetNormalized(); - btVector3 down(normalDown.x, normalDown.y, normalDown.z); - btVector3 forward = xform.getBasis()[2]; - down.normalize (); + //Float3 normalDown = -xform.getBasis().getColumn(1); + btVector3 down(-xform.getBasis().getColumn(1)); + btVector3 forward(xform.getBasis().getColumn(2)); + down.normalize(); forward.normalize(); this->raySource[0] = xform.getOrigin(); this->raySource[1] = xform.getOrigin(); - if(this->state.reach.y < 1.0f) - - - Float angle = acos(Float3(0, 1, 0).Dot(this->state.centerPos.GetNormalized())); - //down.setZ(-down.z()); - btVector3 targetPlus = down * this->state.reach.y * btScalar(1.1); - if(this->state.mass == 40) { - const char* breakpoint = "STOP"; + const char* breakPoint = "STOP!"; } + btVector3 targetPlus = down*this->state.reach.y*btScalar(1.1); + this->rayTarget[0] = this->raySource[0] + targetPlus; - this->rayTarget[1] = this->raySource[1] + forward * this->state.reach.y * btScalar(1.1); + targetPlus = this->raySource[1] + forward*this->state.reach.z*btScalar(1.1); + this->rayTarget[1] = btVector3(targetPlus.x(), targetPlus.y(), targetPlus.z()); class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback { @@ -415,6 +413,10 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) if (rayCallback.hasHit()) { this->rayLambda[i] = rayCallback.m_closestHitFraction; + if(i == 1 && this->state.mass == 40) + { + btVector3 hitNormal = rayCallback.m_hitNormalWorld; + } } else { @@ -423,11 +425,16 @@ void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) } } -float SimpleRigidBody::GetLambda() const +float SimpleRigidBody::GetLambdaUp() const { return this->rayLambda[0]; } +float SimpleRigidBody::GetLambdaForward() const +{ + return this->rayLambda[1]; +} + void SimpleRigidBody::MoveToLimbo() { this->rigidBody->setCollisionFlags(this->rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index 65c59820..dc1158d7 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -68,7 +68,8 @@ namespace Oyster void PreStep(const btCollisionWorld* collisionWorld); - float GetLambda() const; + float GetLambdaUp() const; + float GetLambdaForward() const; void MoveToLimbo(); void ReleaseFromLimbo(); diff --git a/Code/Physics/GamePhysics/PhysicsAPI.h b/Code/Physics/GamePhysics/PhysicsAPI.h index a536bdce..3c2ef879 100644 --- a/Code/Physics/GamePhysics/PhysicsAPI.h +++ b/Code/Physics/GamePhysics/PhysicsAPI.h @@ -185,7 +185,8 @@ namespace Oyster ********************************************************/ virtual void SetCustomTag( void *ref ) = 0; - virtual float GetLambda() const = 0; + virtual float GetLambdaUp() const = 0; + virtual float GetLambdaForward() const = 0; }; } } From 30c425f8fab651a94a1b9de9889ac48cfabad4c5 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 26 Feb 2014 14:08:49 +0100 Subject: [PATCH 26/46] Fixed the damn path --- Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 27cd8ba5..772bf32e 100644 --- a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -234,10 +234,10 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma typedef std::codecvt_utf8 convert_typeX; std::wstring_convert converterX; - //std::string bulletPath = converterX.to_bytes(); + std::string bulletPath = converterX.to_bytes(fileName); // Add collision shape - bulletFile.loadFile("C:\\DV1477\\Git Repository\\Danbias\\Bin\\Content\\Worlds\\cgf\\structure_corporation.bullet"); + bulletFile.loadFile(bulletPath.c_str()); btCollisionShape* collisionShape = bulletFile.getCollisionShapeByIndex(0); body->SetCollisionShape(collisionShape); From 2da9ef4506720f2a2c76b93daf0bedc158e2f284 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 26 Feb 2014 14:33:08 +0100 Subject: [PATCH 27/46] Merged with physics and added filepath --- Code/Game/GameLogic/Level.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 546562f9..be970c04 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -225,7 +225,9 @@ ICustomBody* Level::InitRigidBodyMesh( const ObjectHeader* obj) //rigidBodyRadius = (obj->scale[0] * obj->scale[1] * obj->scale[2]) * obj->boundingVolume.sphere.radius; //create the rigid body - rigidBody = API::Instance().AddTriangleMesh(obj->boundingVolume.cgMesh.filename, rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.cgMesh.restitutionCoeff , obj->boundingVolume.cgMesh.frictionCoeffStatic , obj->boundingVolume.cgMesh.frictionCoeffDynamic); + std::wstring fname = L"..\\Content\\Worlds\\cgf\\"; + fname.append(obj->boundingVolume.cgMesh.filename); + rigidBody = API::Instance().AddTriangleMesh( fname , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.cgMesh.restitutionCoeff , obj->boundingVolume.cgMesh.frictionCoeffStatic , obj->boundingVolume.cgMesh.frictionCoeffDynamic); return rigidBody; } bool Level::InitiateLevel(std::wstring levelPath) From 9731cd9c5effd95393ad336eadb6c97fe602bd3a Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 14:55:29 +0100 Subject: [PATCH 28/46] Spawning players on rand spawnpoint when they connect --- .../GameClient/GameClientState/GameState.cpp | 22 ++++++++-- Code/Game/GameLogic/Level.cpp | 44 +++++++++++-------- Code/Game/GameLogic/Player.cpp | 16 +++++-- Code/Game/GameLogic/Player.h | 1 + .../GameServer/Implementation/GameClient.cpp | 4 ++ 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 4b3e7cb8..d8e0c0e9 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -153,6 +153,11 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.UpdateOrientation(); } } + else + { + int i = 0; + // some error loading model + } } GameClientState::ClientState GameState::Update( float deltaTime ) @@ -739,11 +744,20 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { //Remove the disconnected player Protocol_ObjectDisconnectPlayer decoded(data); - auto object = this->privData->dynamicObjects->find( decoded.objectID ); - if( object != this->privData->dynamicObjects->end() ) + C_Player *player; + player = (this->privData->players)[decoded.objectID]; + + if( player ) { - object->second = nullptr; - this->privData->dynamicObjects->erase( object ); + if( this->privData->myId == decoded.objectID ) + { + // dont delete my player + } + if( player ) + { + player->SetVisible(false); + (this->privData->players)[decoded.objectID].Release(); + } } } return GameClientState::event_processed; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index be970c04..385571af 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -368,6 +368,9 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; + player->ResetPlayer(spawnPoint); for(int i = 0; i < (int)this->playerObjects.Size(); i++) { if (!this->playerObjects[i]) @@ -409,28 +412,31 @@ void Level::Update(float deltaTime) for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if(this->playerObjects[i]->getAffectingPlayer() != NULL) + if(this->playerObjects[i]) { - - } - - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) - { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); - } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) - { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - if(!killer) //if there is no killer then you commited suicide + if(this->playerObjects[i]->getAffectingPlayer() != NULL) { - killer = this->playerObjects[i]; + + } + + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + if(!killer) //if there is no killer then you commited suicide + { + killer = this->playerObjects[i]; + } + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID } - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID } } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 49babcc3..85477fc9 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -15,6 +15,8 @@ Player::Player() AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -24,6 +26,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) Player::initPlayerData(); AffectedObjects.Reserve(15); this->teamID = teamID; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -33,6 +37,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom Player::initPlayerData(); AffectedObjects.Reserve(15); this->teamID = teamID; + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; } Player::~Player(void) @@ -47,8 +53,6 @@ void Player::initPlayerData() { this->playerStats.hp = MAX_HP; this->playerStats.movementSpeed = BASIC_SPEED; - this->playerScore.killScore = 0; - this->playerScore.deathScore = 0; this->playerState = PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float3(0,0,-1); @@ -317,7 +321,13 @@ void Player::Inactivate() { //this-> } - +void Player::ResetPlayer( Oyster::Math::Float3 spawnPos) +{ + Player::initPlayerData(); + this->rigidBody->SetPosition(spawnPos); + this->playerScore.killScore = 0; + this->playerScore.deathScore = 0; +} Oyster::Math::Float3 Player::GetPosition() const { return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index edb4cc79..965abfd9 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -82,6 +82,7 @@ namespace GameLogic bool IsIdle(); void Inactivate(); + void ResetPlayer( Oyster::Math::Float3 spawnPos); Oyster::Math::Float3 GetPosition() const; Oyster::Math::Float3 GetLookDir() const; diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 74795ce6..0c33ba89 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,6 +25,10 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerplayer) + { + this->player->Inactivate(); + } this->isReady = false; this->character = L"char_orca.dan"; this->alias = L"Unknown"; From 4e502b298b9bfa2b74262ecc115403fb0ee1ea08 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 26 Feb 2014 16:10:04 +0100 Subject: [PATCH 29/46] GameServer - minor --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 8eabffb3..2088427d 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -80,8 +80,8 @@ namespace DanBias //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) WindowShell::WINDOW_INIT_DESC winDesc; - winDesc.windowSize.x = 1920; - winDesc.windowSize.y = 1080; + winDesc.windowSize.x = 1280; + winDesc.windowSize.y = 720; winDesc.windowProcCallback = WindowCallBack; if(! data.window->CreateWin(winDesc) ) @@ -155,7 +155,7 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - p.Resolution = Oyster::Math::Float2( 1920.0f, 1080.0f ); + p.Resolution = Oyster::Math::Float2( 1280.0f, 720.0f ); //! @todo fix proper amb value p.AmbientValue = 1.3f; From 50acc12951ef39b137e110717c5f9613f0a3b4b1 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 26 Feb 2014 16:57:32 +0100 Subject: [PATCH 30/46] Broken shit, dont take --- .../GameClient/GameClientState/GamingUI.cpp | 51 ++++++++++++++++++- .../GameClient/GameClientState/GamingUI.h | 4 +- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 42 +++++++++++---- 3 files changed, 82 insertions(+), 15 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index ce08fa16..63366a2a 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -146,7 +146,7 @@ void GamingUI::ReadKeyInput() this->key_Shoot = true; } } - else + else this->key_Shoot = false; if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) ) @@ -170,7 +170,54 @@ void GamingUI::ReadKeyInput() } } - +void GamingUI::OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender ) +{ + switch ( key ) + { + case ::Input::Enum::SAMI_MouseLeftBtn: // shoot + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = true; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + this->sharedData->network->Send( playerShot ); + } + break; + case ::Input::Enum::SAMI_MouseRightBtn: + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = true; + playerShot.utilityPressed = false; + this->sharedData->network->Send( playerShot ); + } + break; + case ::Input::Enum::SAMI_MouseMiddleBtn: + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = true; + this->sharedData->network->Send( playerShot ); + } + break; + } +} +void GamingUI::OnMouseRelease ( Input::Enum::SAMI key, Input::Mouse* sender ) +{ + switch ( key ) + { + case ::Input::Enum::SAMI_MouseRightBtn: + { + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + this->sharedData->network->Send( playerShot ); + } + break; + } +} void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender ) { //send delta mouse movement diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index c4e34441..d21ae0bd 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -28,9 +28,9 @@ namespace DanBias { namespace Client private: /* Overidden mouse methods */ void OnMouse ( const Input::Struct::MouseEventData& eventData ) override { } - void OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender ) override { } + void OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender ) override; void OnMouseDown ( Input::Enum::SAMI key, Input::Mouse* sender ) override { } - void OnMouseRelease ( Input::Enum::SAMI key, Input::Mouse* sender ) override { } + void OnMouseRelease ( Input::Enum::SAMI key, Input::Mouse* sender ) override; void OnMouseMovePixelPos ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender ) override { } void OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender ) override; void OnMouseScroll ( int delta, Input::Mouse* sender ) override { } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 13ef8fef..dd20e8f3 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -44,9 +44,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, switch (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - if(currentEnergy >= 90.0f) + if(currentEnergy >= 9.0f) { - currentEnergy -= 90.0f; + currentEnergy -= 9.0f; ForcePush(usage,dt); // add CD ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); @@ -54,13 +54,33 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - if(currentEnergy >= 1.0f) + if( currentEnergy >= 1.0f ) { currentEnergy -= 1.0f; - ForcePull(usage,dt); - // add CD - ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); + if(!this->hasObject) + { + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); + } } + else //Energy drained, release object + { + ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + this->hasObject = false; + this->heldObject = NULL; + } + break; + + case WEAPON_USE_SECONDARY_RELEASE: + { + if (this->hasObject) //Dummy check + { + ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + this->hasObject = false; + this->heldObject = NULL; + } + } break; case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: @@ -112,11 +132,11 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float if(hasObject) { pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force); - heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); - ((DynamicObject*)(heldObject->GetCustomTag()))->RemoveManipulation(); - hasObject = false; - heldObject = NULL; - return; + this->heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); + ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + this->hasObject = false; + this->heldObject = NULL; + return ; } Oyster::Math::Float radius = 4; From 22bc079ed7f6958d27ba67bccbf02212d4ea9669 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Thu, 27 Feb 2014 08:19:50 +0100 Subject: [PATCH 31/46] GameLogic - Fixed drop on secondary, Modified how keys are sent --- .../GameClient/GameClientState/GamingUI.cpp | 130 ++++++++---------- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 35 +++-- Code/Game/GameLogic/CollisionManager.cpp | 2 +- Code/Game/GameProtocols/PlayerProtocols.h | 52 +++++-- .../Implementation/GameSession_Gameplay.cpp | 18 ++- Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 4 +- 6 files changed, 135 insertions(+), 106 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 63366a2a..1b5c2648 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -119,50 +119,50 @@ void GamingUI::ReadKeyInput() this->key_Jump = false; // shoot - if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) ) - { - if( !this->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = true; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = false; - this->sharedData->network->Send( playerShot ); - this->key_Shoot = true; - } - } - else - this->key_Shoot = false; - - if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseRightBtn) ) - { - if( !this->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = true; - playerShot.utilityPressed = false; - this->sharedData->network->Send( playerShot ); - this->key_Shoot = true; - } - } - else - this->key_Shoot = false; - - if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) ) - { - if( !this->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = true; - this->sharedData->network->Send( playerShot ); - this->key_Shoot = true; - } - } - else - this->key_Shoot = false; + //if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = true; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = false; + // this->sharedData->network->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + // + //if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseRightBtn) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = true; + // playerShot.utilityPressed = false; + // this->sharedData->network->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + // + //if( this->sharedData->mouseDevice->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = true; + // this->sharedData->network->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; if( this->sharedData->keyboardDevice->IsKeyDown(::Input::Enum::SAKI_Escape) ) { @@ -175,31 +175,13 @@ void GamingUI::OnMousePress ( Input::Enum::SAMI key, Input::Mouse* sender ) switch ( key ) { case ::Input::Enum::SAMI_MouseLeftBtn: // shoot - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = true; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = false; - this->sharedData->network->Send( playerShot ); - } + this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_PrimaryPress) ); break; case ::Input::Enum::SAMI_MouseRightBtn: - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = true; - playerShot.utilityPressed = false; - this->sharedData->network->Send( playerShot ); - } + this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_SecondaryPress) ); break; - case ::Input::Enum::SAMI_MouseMiddleBtn: - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = true; - this->sharedData->network->Send( playerShot ); - } + case ::Input::Enum::SAMI_MouseMiddleBtn: + this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_UtilityPress) ); break; } } @@ -207,14 +189,14 @@ void GamingUI::OnMouseRelease ( Input::Enum::SAMI key, Input::Mouse* sender ) { switch ( key ) { + case ::Input::Enum::SAMI_MouseLeftBtn: // shoot + this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_PrimaryRelease) ); + break; case ::Input::Enum::SAMI_MouseRightBtn: - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = false; - this->sharedData->network->Send( playerShot ); - } + this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_SecondaryRelease) ); + break; + case ::Input::Enum::SAMI_MouseMiddleBtn: + this->sharedData->network->Send( Protocol_PlayerShot(Protocol_PlayerShot::ShootValue_UtilityRelease) ); break; } } @@ -228,4 +210,4 @@ void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, In this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) ); } } -} \ No newline at end of file +} diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index dd20e8f3..f4b5e2ec 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -54,7 +54,13 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - if( currentEnergy >= 1.0f ) + if(this->hasObject) + { + ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + this->hasObject = false; + this->heldObject = NULL; + } + else if( currentEnergy >= 1.0f ) { currentEnergy -= 1.0f; if(!this->hasObject) @@ -76,9 +82,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { if (this->hasObject) //Dummy check { - ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); - this->hasObject = false; - this->heldObject = NULL; + //((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + //this->hasObject = false; + //this->heldObject = NULL; } } break; @@ -185,22 +191,27 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) Oyster::Math::Float4 pullForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (this->force * 0.2); - Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); + Oyster::Collision3D::Cone hitCone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); forcePushData args; args.pushForce = -pullForce; args.p = this->owner; - Oyster::Physics::API::Instance().ApplyEffect(hitCone,&args,ForcePushAction); - - if(hitCone) delete hitCone; + Oyster::Physics::API::Instance().ApplyEffect(&hitCone,&args,ForcePushAction); } void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) { - Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*2; - Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,10); + //DEBUG: + MessageBeep(MB_ICONINFORMATION); + Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized() * 2; - Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); + //Do ray test first! + //Oyster::Collision3D::Ray r(pos, owner->GetLookDir()); + //Oyster::Physics::API::Instance().ApplyEffect(&r, this, AttemptPickUp); - if(hitSphere) delete hitSphere; + if(this->hasObject) return; + + Oyster::Collision3D::Sphere hitSphere = Oyster::Collision3D::Sphere(pos , 1); + Oyster::Physics::API::Instance().ApplyEffect(&hitSphere,this,AttemptPickUp); + return; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index c355fd04..acad935a 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -326,6 +326,7 @@ using namespace GameLogic; void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args) { if(obj->GetState().mass == 0) return; + if(!args) return; AttatchmentMassDriver *weapon = ((AttatchmentMassDriver*)args); @@ -339,7 +340,6 @@ using namespace GameLogic; //check so that it is an object that you can pickup DynamicObject *dynamicObj = dynamic_cast(realObj); - if(!dynamicObj) return; if(dynamicObj->getManipulatingPlayer() != NULL) diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index eb34c07c..e3cea80c 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -157,37 +157,59 @@ namespace GameLogic struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject { - bool primaryPressed; - bool secondaryPressed; - bool utilityPressed; + enum ShootValue + { + ShootValue_PrimaryPress, + ShootValue_PrimaryRelease, + ShootValue_SecondaryPress, + ShootValue_SecondaryRelease, + ShootValue_UtilityPress, + ShootValue_UtilityRelease, + } value; + //bool primaryPressed; + //bool secondaryPressed; + //bool utilityPressed; Protocol_PlayerShot() { this->protocol[0].value = protocol_Gameplay_PlayerShot; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; - this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; - this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + + //this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; + //this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; + //this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + } + Protocol_PlayerShot(ShootValue val) + { + this->protocol[0].value = protocol_Gameplay_PlayerShot; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + this->value = val; } Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p) { - primaryPressed = p[1].value.netBool; - secondaryPressed = p[2].value.netBool; - utilityPressed = p[3].value.netBool; + value = (ShootValue)p[1].value.netChar; + //primaryPressed = p[1].value.netBool; + //secondaryPressed = p[2].value.netBool; + //utilityPressed = p[3].value.netBool; } const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val) { - primaryPressed = val[1].value.netBool; - secondaryPressed = val[2].value.netBool; - utilityPressed = val[3].value.netBool; + value = (ShootValue)val[1].value.netChar; + //primaryPressed = val[1].value.netBool; + //secondaryPressed = val[2].value.netBool; + //utilityPressed = val[3].value.netBool; return *this; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = primaryPressed; - this->protocol[2].value = secondaryPressed; - this->protocol[3].value = utilityPressed; + this->protocol[1].value = value; + //this->protocol[1].value = primaryPressed; + //this->protocol[2].value = secondaryPressed; + //this->protocol[3].value = utilityPressed; return protocol; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index d1e32b55..f18f5c07 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -257,9 +257,21 @@ using namespace DanBias; } void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c ) { - if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); - if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); - if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); + switch (p.value) + { + case Protocol_PlayerShot::ShootValue_PrimaryPress: c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + break; + case Protocol_PlayerShot::ShootValue_PrimaryRelease: c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_RELEASE); + break; + case Protocol_PlayerShot::ShootValue_SecondaryPress: c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); + break; + case Protocol_PlayerShot::ShootValue_SecondaryRelease: c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_RELEASE); + break; + case Protocol_PlayerShot::ShootValue_UtilityPress: c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); + break; + case Protocol_PlayerShot::ShootValue_UtilityRelease: c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_RELEASE); + break; + } } void GameSession::Gameplay_ObjectPickup ( Protocol_ObjectPickup& p, DanBias::GameClient* c ) { diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index 6defebcc..35e63980 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -200,12 +200,12 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) if(btn == SAMI_Unknown) return; - this->buttons[btn].isDown = !isUp; this->buttons[btn].makeCode = makeCode; //The btn is released. if(isUp) { + this->buttons[btn].isDown = false; InternalOnBtnRelease(btn); GetNormalizedPosition( mouseEventData.normalizedPos ); @@ -222,6 +222,7 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) //The btn is down since last frame if(this->buttons[btn].isDown) { + this->buttons[btn].isDown = true; InternalOnBtnDown(btn); GetNormalizedPosition( mouseEventData.normalizedPos ); @@ -234,6 +235,7 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) } else { + this->buttons[btn].isDown = true; InternalOnBtnPress(btn); GetNormalizedPosition( mouseEventData.normalizedPos ); From e43996bdc88784d8316fb17e7e6c1449c6330230 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 27 Feb 2014 09:11:13 +0100 Subject: [PATCH 32/46] =?UTF-8?q?Se=20till=20s=C3=A5=20att=20man=20inte=20?= =?UTF-8?q?g=C3=A5r=20=C3=B6ver=20maxenergy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index f4b5e2ec..401c40f8 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -105,6 +105,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, void AttatchmentMassDriver::Update(float dt) { + //update position of heldObject if there is an object being held if(hasObject) { @@ -116,12 +117,26 @@ void AttatchmentMassDriver::Update(float dt) heldObject->SetPosition(pos); heldObject->SetLinearVelocity(Oyster::Math::Float3::null); - currentEnergy += rechargeRate * 0.5f; //rechargeRate is halfed if you are holding an object + if(currentEnergy < maxEnergy) + { + currentEnergy += rechargeRate * 0.5f; //rechargeRate is halfed if you are holding an object + } + } else { - currentEnergy += rechargeRate; + if(currentEnergy < maxEnergy) + { + currentEnergy += rechargeRate; + + if(currentEnergy == maxEnergy) + { + int trap = 0; + } + } } + + if(currentEnergy > maxEnergy) currentEnergy = maxEnergy; } From f1e6a1c8974d27c68cd292d80af6087c5c180369 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 10:46:30 +0100 Subject: [PATCH 33/46] Merge fixes Warning! Possibility that code were lost during this merge. Please oh please do check what branch you are in before you edit files. --- Code/Game/GameLogic/Game.cpp | 2 +- Code/Game/GameLogic/Game.h | 2 +- Code/Game/GameLogic/GameAPI.h | 2 +- Code/Game/GameLogic/Player.cpp | 40 +++---------------- Code/Game/GameServer/GameSession.h | 2 +- .../Implementation/GameSession_Gameplay.cpp | 2 +- 6 files changed, 10 insertions(+), 40 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index d4abb9e1..87216b3b 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -182,7 +182,7 @@ void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) } void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) { - this->onPlayerActionEventFnc = functionPointer; + this->onActionEventFnc = functionPointer; } void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) { diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index f6e852a9..28ad9772 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -107,7 +107,7 @@ namespace GameLogic GameEvent::ObjectHpFunction onDamageTakenFnc; GameEvent::ObjectRespawnedFunction onRespawnFnc; GameEvent::ObjectDeadFunction onDeadFnc; - GameEvent::AnimationEventFunction onPlayerActionEventFnc; + GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; GameEvent::CollisionEventFunction onCollisionEventFnc; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 7bf01d60..bda2312d 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -30,7 +30,7 @@ namespace GameLogic typedef void(*ObjectEnabledFunction)(IObjectData* object); // Callback method that recieves and object typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos - typedef void(*ObjectDeadFunction)(IObjectData* object, float seconds); // Callback method that sends death timer + typedef void(*ObjectDeadFunction)(IObjectData* object, IObjectData* killer, float seconds); // Callback method that sends death timer typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 85477fc9..17bbcca2 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -12,7 +12,6 @@ Player::Player() :DynamicObject() { Player::initPlayerData(); - AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; this->playerScore.killScore = 0; @@ -24,7 +23,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; this->playerScore.killScore = 0; this->playerScore.deathScore = 0; @@ -35,7 +33,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; this->playerScore.killScore = 0; this->playerScore.deathScore = 0; @@ -61,7 +58,6 @@ void Player::initPlayerData() this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; - this->invincibleCooldown = 0; this->deathTimer = 0; this->rotationUp = 0; @@ -142,7 +138,7 @@ void Player::BeginFrame() if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } } @@ -178,7 +174,7 @@ void Player::BeginFrame() if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Walk); this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; } } @@ -200,7 +196,7 @@ void Player::BeginFrame() this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Jump); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Jump); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } @@ -208,26 +204,14 @@ void Player::BeginFrame() { if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING) { - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } } } } -void Player::EndFrame() -{ - //check if there are any objects that can be removed from the AffectedObjects list - for(int i = 0; i < this->AffectedObjects.Size(); i++) - { - if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) - { - this->AffectedObjects[i]->RemoveAffectedBy(); - this->AffectedObjects.Remove(i); - } - - } -} +void Player::EndFrame() { /* do nothing .. for now */ } void Player::Move(const PLAYER_MOVEMENT &movement) { @@ -363,20 +347,6 @@ void Player::DamageLife(int damage) } -void Player::AddAffectedObject(DynamicObject &AffectedObject) -{ - //check if object already exists in the list, if so then do not add - for(int i = 0; i < AffectedObjects.Size(); i++) - { - if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) - { - //object already exists, exit function - return; - } - } - //else you add the object to the stack - AffectedObjects.Push(&AffectedObject); -} bool Player::deathTimerTick(float dt) { this->deathTimer -= dt; diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 38a8e119..0f8ffc97 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -102,7 +102,7 @@ namespace DanBias static void ObjectEnabled ( GameLogic::IObjectData* movedObject ); static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp ); static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos ); - static void ObjectDead ( GameLogic::IObjectData* movedObject, float seconds ); + static void ObjectDead ( GameLogic::IObjectData* movedObject, GameLogic::IObjectData* killer, float seconds ); static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index f18f5c07..6fea69c1 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -162,7 +162,7 @@ using namespace DanBias; { GameSession::gameSession->Send(Protocol_ObjectRespawn(movedObject->GetID(), spawnPos).GetProtocol()); } - void GameSession::ObjectDead( GameLogic::IObjectData* movedObject, float seconds ) + void GameSession::ObjectDead( GameLogic::IObjectData* movedObject, GameLogic::IObjectData* killer, float seconds ) { GameSession::gameSession->Send(Protocol_ObjectDie(movedObject->GetID(), seconds).GetProtocol()); } From 1b7cebc2e9fdbfbc64f6641c02ccea77de699346 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 27 Feb 2014 10:49:22 +0100 Subject: [PATCH 34/46] Resize --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 11 ++++--- .../GameClient/GameClientState/GameState.cpp | 13 ++------ Code/Game/GameClient/Include/DanBiasGame.h | 2 +- Code/OysterGraphics/Core/Core.cpp | 4 +++ Code/OysterGraphics/Core/Core.h | 8 +++-- Code/OysterGraphics/Core/Init.cpp | 14 +++++---- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 30 +++++++++++++------ Code/OysterGraphics/DllInterfaces/GFXAPI.h | 14 +++++---- .../Shader/Passes/Light/LightPass.hlsl | 21 +++++-------- .../Shader/Passes/Post/PostPass.hlsl | 4 +-- 10 files changed, 68 insertions(+), 53 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index edf6e7af..1b2e099a 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -40,7 +40,7 @@ namespace DanBias { public: WindowShell* window; - Utility::WinTimer timer; + Utility::WinTimer timer, graphicalTimer; UniquePointer state; NetworkClient networkClient; @@ -155,11 +155,14 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - p.Resolution = Oyster::Math::Float2( 1920.0f, 1080.0f ); + p.resolution = Oyster::Math::Float2( 1920.0f, 1080.0f ); //! @todo fix proper amb value - p.AmbientValue = 1.3f; + p.ambientValue = 0.3f; + p.globalGlowTint = Math::Float3(1); + p.globalTint = Math::Float3(1); + p.fullscreen = false; - if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, p) != Oyster::Graphics::API::Sucsess) + if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, p) != Oyster::Graphics::API::Sucsess) return E_FAIL; return S_OK; } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 0824d8bc..d6ebeafc 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -74,19 +74,10 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->lights = &shared.lights; Graphics::API::Option gfxOp = Graphics::API::GetOption(); - Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 1.0f, 100.0f ); - - // HACK: debug test - Matrix debug_p = this->privData->camera.GetProjectionMatrix(); - Float debug_n = - debug_p.m34 / debug_p.m33; - Float debug_f = debug_p.m34 / (1.0f - debug_p.m33); + Float aspectRatio = gfxOp.resolution.x / gfxOp.resolution.y; + this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.5f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); - gfxOp.AmbientValue = 0.3f; - gfxOp.GlobalGlowTint = Math::Float3(1,1,1); - gfxOp.GlobalTint = Math::Float3(1,1,1); - Graphics::API::SetOptions(gfxOp); // DEGUG KEYS this->key_Reload_Shaders = false; diff --git a/Code/Game/GameClient/Include/DanBiasGame.h b/Code/Game/GameClient/Include/DanBiasGame.h index f6f0cdee..8213f879 100644 --- a/Code/Game/GameClient/Include/DanBiasGame.h +++ b/Code/Game/GameClient/Include/DanBiasGame.h @@ -45,6 +45,7 @@ namespace DanBias static DanBiasClientReturn Initiate(DanBiasGameDesc& desc); static DanBiasClientReturn Run(); static void Release(); + static HRESULT Render(); private: enum Result @@ -58,7 +59,6 @@ namespace DanBias static HRESULT InitInput( HWND handle ); static Result Update(float deltaTime); - static HRESULT Render(); static HRESULT CleanUp(); }; diff --git a/Code/OysterGraphics/Core/Core.cpp b/Code/OysterGraphics/Core/Core.cpp index 8cb4c5e0..0874e2cc 100644 --- a/Code/OysterGraphics/Core/Core.cpp +++ b/Code/OysterGraphics/Core/Core.cpp @@ -36,3 +36,7 @@ ID3D11RenderTargetView* Core::rtvNULL[8] = {0}; ID3D11UnorderedAccessView* Core::uavNULL[8] = {0}; int Core::UsedMem = 0; + +HWND Core::window = 0; + +bool Core::fullscreen = false; \ No newline at end of file diff --git a/Code/OysterGraphics/Core/Core.h b/Code/OysterGraphics/Core/Core.h index ae234ee4..79f63227 100644 --- a/Code/OysterGraphics/Core/Core.h +++ b/Code/OysterGraphics/Core/Core.h @@ -40,7 +40,8 @@ namespace Oyster //ViewPort static D3D11_VIEWPORT* viewPort; - static Oyster::Math::Float2 resolution; + static Oyster::Math::Float2 resolution; + static bool fullscreen; static ID3D11ShaderResourceView* srvNULL[16]; static ID3D11RenderTargetView* rtvNULL[8]; @@ -48,6 +49,8 @@ namespace Oyster static int UsedMem; + static HWND window; + class Buffer { public: @@ -250,11 +253,12 @@ namespace Oyster static State FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen); - static State ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen); + static State ReInitialize(bool MSAA_Quality, bool Fullscreen, Math::Float2 Size); static State CreateLinkedShaderResourceFromTexture(ID3D11RenderTargetView** rtv, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav); static State CreateLinkedShaderResourceFromStructuredBuffer(Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav); + static State CreateLinkedShaderResourceFromStructuredBuffer(void* InitData, int numElem, int ElemSize, Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav); }; diff --git a/Code/OysterGraphics/Core/Init.cpp b/Code/OysterGraphics/Core/Init.cpp index 47731dbf..c9e2e07c 100644 --- a/Code/OysterGraphics/Core/Init.cpp +++ b/Code/OysterGraphics/Core/Init.cpp @@ -110,7 +110,7 @@ namespace Oyster if(Core::swapChain) { Core::swapChain->Release(); - Core::UsedMem -= desc.BufferDesc.Height * desc.BufferDesc.Width * 16; + Core::UsedMem -= Core::resolution.x * Core::resolution.y * 4; delete Core::swapChain; } @@ -168,7 +168,7 @@ namespace Oyster } dxgiFactory->Release(); - Core::UsedMem += desc.BufferDesc.Height * desc.BufferDesc.Width * 16; + Core::UsedMem += desc.BufferDesc.Height * desc.BufferDesc.Width * 4; return Init::Success; } @@ -188,7 +188,7 @@ namespace Oyster if(Core::depthStencil) { Core::depthStencil->Release(); - Core::UsedMem -= desc.Height * desc.Width * 4; + Core::UsedMem -= Core::resolution.x * Core::resolution.y * 4; delete Core::depthStencil; } @@ -327,12 +327,16 @@ namespace Oyster return Init::Fail; } + + Core::window = Window; + Core::fullscreen = Fullscreen; + return Init::Success; } - Core::Init::State Core::Init::ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen) + Core::Init::State Core::Init::ReInitialize(bool MSAA_Quality, bool Fullscreen, Math::Float2 Size) { - if(Init::CreateSwapChain(Window, 1, MSAA_Quality, Fullscreen, Core::resolution) == Init::Fail) + if(Init::CreateSwapChain(Core::window, 1, MSAA_Quality, Fullscreen, Size) == Init::Fail) { return Init::Fail; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 46145430..5efde879 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -31,13 +31,14 @@ namespace Oyster #endif } - API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, API::Option o) + API::State API::Init(HWND Window, bool MSAA_Quality, API::Option o) { - Core::resolution = o.Resolution; + Core::resolution = o.resolution; Core::modelPath = o.modelPath; Core::texturePath = o.texturePath; + Core::fullscreen = o.fullscreen; - if(Core::Init::FullInit(Window, MSAA_Quality, Fullscreen) == Core::Init::Fail) + if(Core::Init::FullInit(Window, MSAA_Quality, o.fullscreen) == Core::Init::Fail) { return API::Fail; } @@ -45,7 +46,9 @@ namespace Oyster Render::Resources::Init(); Definitions::PostData pd; - pd.Amb = o.AmbientValue; + pd.Amb = o.ambientValue; + pd.GlowTint = o.globalGlowTint; + pd.Tint = o.globalTint; void* data = Render::Resources::Post::Data.Map(); memcpy(data,&pd,sizeof(Definitions::PostData)); @@ -127,14 +130,22 @@ namespace Oyster Core::texturePath = option.texturePath; Definitions::PostData pd; - pd.Amb = option.AmbientValue; - pd.Tint = option.GlobalTint; - pd.GlowTint = option.GlobalGlowTint; + pd.Amb = option.ambientValue; + pd.Tint = option.globalTint; + pd.GlowTint = option.globalGlowTint; void* data = Render::Resources::Post::Data.Map(); memcpy(data,&pd,sizeof(Definitions::PostData)); Render::Resources::Post::Data.Unmap(); + if(option.resolution != Core::resolution || option.fullscreen != Core::fullscreen) + { + //RESIZE + Core::Init::ReInitialize(false,option.fullscreen,option.resolution); + Core::fullscreen = option.fullscreen; + Core::resolution = option.resolution; + } + return API::Sucsess; } @@ -302,10 +313,11 @@ namespace Oyster API::Option API::GetOption() { Option o; - o.BytesUsed = Core::UsedMem; + o.bytesUsed = Core::UsedMem; o.modelPath = Core::modelPath; o.texturePath = Core::texturePath; - o.Resolution = Core::resolution; + o.resolution = Core::resolution; + o.fullscreen = Core::fullscreen; return o; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.h b/Code/OysterGraphics/DllInterfaces/GFXAPI.h index 7f338cce..4fe0c281 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.h +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.h @@ -28,19 +28,21 @@ namespace Oyster { std::wstring modelPath, texturePath; //between 0-1 - float AmbientValue; + float ambientValue; - Math::Float3 GlobalTint; - Math::Float3 GlobalGlowTint; + Math::Float3 globalTint; + Math::Float3 globalGlowTint; - Math::Float2 Resolution; + Math::Float2 resolution; //Bytes on the GPU - int BytesUsed; + int bytesUsed; + + bool fullscreen; }; typedef void* Texture; - static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Option options); + static State Init(HWND Window, bool MSAA_Quality, Option options); static void BeginLoadingModels(); diff --git a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl index 78d7975b..adec6575 100644 --- a/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl @@ -93,18 +93,12 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uin PointLight pl = Points[lightIndex]; bool inFrustrum = true; - float d = dot(frustumPlanes[0], float4(pl.Pos, 1.0f)); - inFrustrum = inFrustrum && (d >= -pl.Radius); - d = dot(frustumPlanes[1], float4(pl.Pos, 1.0f)); - inFrustrum = inFrustrum && (d >= -pl.Radius); - d = dot(frustumPlanes[2], float4(pl.Pos, 1.0f)); - inFrustrum = inFrustrum && (d >= -pl.Radius); - d = dot(frustumPlanes[3], float4(pl.Pos, 1.0f)); - inFrustrum = inFrustrum && (d >= -pl.Radius); - d = dot(frustumPlanes[4], float4(pl.Pos, 1.0f)); - inFrustrum = inFrustrum && (d >= -pl.Radius); - d = dot(frustumPlanes[5], float4(pl.Pos, 1.0f)); - inFrustrum = inFrustrum && (d >= -pl.Radius); + [unroll] + for(int i = 0; i < 6; ++i) + { + float d = dot(frustumPlanes[i], float4(pl.Pos, 1.0f)); + inFrustrum = inFrustrum && (d >= -pl.Radius); + } [branch] if(inFrustrum) @@ -152,7 +146,8 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uin //Ambient[DTid.xy/2] = float4(DiffBase.xyz, 1); Ambient[DTid.xy/2 + float2(Diffuse.Length.x/2, 0)] = GUI[DTid.xy]; Ambient[DTid.xy/2 + float2(0, Diffuse.Length.y/2)] = float4(DiffBase.xyz * DiffBase.w ,DiffBase.w); - Ambient[DTid.xy/2 + Diffuse.Length.xy/2] = float4(numVisiblePointLights * (1.0f/Lights), 0, 0 ,1); + //Ambient[DTid.xy/2 + Diffuse.Length.xy/2] = float4(numVisiblePointLights * (1.0f/Lights), 0, 0 ,1); + Ambient[DTid.xy/2 + Diffuse.Length.xy/2] = float4(NormalSpec[DTid.xy/2].xyz ,1); } } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl index 87c7c95a..2a498804 100644 --- a/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl @@ -27,7 +27,7 @@ void main( uint3 DTid : SV_DispatchThreadID ) SSAO = SSAO / 16; - float4 Light = Diffuse[DTid.xy];// + saturate(Specular[DTid.xy]); + float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]); float3 Amb = Ambient[DTid.xy/2].xyz * SSAO * Color; float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)]; @@ -43,6 +43,6 @@ void main( uint3 DTid : SV_DispatchThreadID ) //Output[DTid.xy] = float4(Ambient[DTid.xy/2 + uint2(Output.Length*0.5f)].xyz,1); //Output[DTid.xy] = SSAO * float4(1,1,1,1); - Output[DTid.xy] = Ambient[DTid.xy]; + //Output[DTid.xy] = Ambient[DTid.xy]; //Output[DTid.xy] = Diffuse[DTid.xy]; } \ No newline at end of file From 2089b7f01fe984cc875ff70c32252ff21f2bf015 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 11:17:13 +0100 Subject: [PATCH 35/46] permanent disable of player friction --- Code/Game/GameLogic/Player.cpp | 75 ++++++++++++++++++---------------- Code/Game/GameLogic/Player.h | 2 +- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index bea0f896..34c46461 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -6,6 +6,8 @@ using namespace GameLogic; using namespace Oyster::Physics; +using namespace Oyster::Math; + const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; const float AFFECTED_TIMER = 1.0f; @@ -52,7 +54,7 @@ void Player::initPlayerData() this->playerStats.hp = MAX_HP; this->playerStats.movementSpeed = BASIC_SPEED; this->playerState = PLAYER_STATE_IDLE; - this->lookDir = Oyster::Math::Float3(0,0,-1); + this->lookDir = Float3( 0.0f, 0.0f, -1.0f ); this->key_forward = 0; this->key_backward = 0; @@ -63,82 +65,84 @@ void Player::initPlayerData() this->deathTimer = 0; this->rotationUp = 0; + + ICustomBody::State state = this->rigidBody->GetState(); + state.staticFrictionCoeff = 0.0f; + state.dynamicFrictionCoeff = 0.0f; + this->rigidBody->SetState( state ); } void Player::BeginFrame() { - if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED) + if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED ) { - weapon->Update(0.002f); + static const Float maxSpeed = 30.0f; - - - - Oyster::Math::Float maxSpeed = 30; + weapon->Update( 0.002f ); // Rotate player accordingly this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); this->rotationUp = 0; + // Direction data - Oyster::Math::Float4x4 xform; - xform = this->rigidBody->GetState().GetOrientation(); + Oyster::Math::Float4x4 orientation; + orientation = this->rigidBody->GetState().GetOrientation(); - Oyster::Math::Float3 forwardDir = xform.v[2]; - Oyster::Math::Float3 upDir = xform.v[1]; - Oyster::Math::Float3 rightDir = xform.v[0]; - forwardDir.Normalize(); - upDir.Normalize(); - rightDir.Normalize(); + Float3 &forwardDir = orientation.v[2].xyz; + Float3 &upDir = orientation.v[1].xyz; + Float3 &rightDir = orientation.v[0].xyz; - // Previous velocities data - Oyster::Math::Float3 linearVelocity = this->rigidBody->GetLinearVelocity(); - Oyster::Math::Float3 forwardVelocity = linearVelocity*Oyster::Math::Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z)); - Oyster::Math::Float forwardSpeed = (linearVelocity*forwardDir).GetLength(); - Oyster::Math::Float3 rightVelocity = linearVelocity*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)); - Oyster::Math::Float rightSpeed = (linearVelocity*rightDir).GetLength(); - Oyster::Math::Float3 upVelocity = linearVelocity*Oyster::Math::Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z)); + // Pre-update velocities data + Float3 linearVelocity = this->rigidBody->GetLinearVelocity(); + Float3 forwardVelocity = linearVelocity * Float3(fabs(forwardDir.x), fabs(forwardDir.y), fabs(forwardDir.z) ); + Float forwardSpeed = (linearVelocity * forwardDir).GetLength(); + Float3 rightVelocity = linearVelocity * Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z) ); + Float rightSpeed = (linearVelocity * rightDir).GetLength(); + Float3 upVelocity = linearVelocity * Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z) ); // Walking data - Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); - Oyster::Math::Float walkSpeed = this->playerStats.movementSpeed*0.2f; + Float3 walkDirection = Float3( 0.0f ); + Float &walkSpeed = this->playerStats.movementSpeed; + + Float frameTime = gameInstance->GetFrameTime(); // Check for input if(key_forward > 0.001) { - key_forward -= gameInstance->GetFrameTime(); + key_forward -= frameTime; walkDirection += forwardDir; } if(key_backward > 0.001) { - key_backward -= gameInstance->GetFrameTime(); + key_backward -= frameTime; walkDirection -= forwardDir; } if(key_strafeRight > 0.001) { - key_strafeRight -= gameInstance->GetFrameTime(); + key_strafeRight -= frameTime; walkDirection += rightDir; } if(key_strafeLeft > 0.001) { - key_strafeLeft -= gameInstance->GetFrameTime(); + key_strafeLeft -= frameTime; walkDirection -= rightDir; } // Dampen velocity if certain keys are not pressed - if(key_jump <= 0.001 && IsWalking()) + if( key_jump <= 0.001 && IsWalking() ) { if(key_forward <= 0.001 && key_backward <= 0.001) { - forwardVelocity *= Oyster::Math::Float3(0.2f*fabs(forwardDir.x), 0.2f*fabs(forwardDir.y), 0.2f*fabs(forwardDir.z)); + forwardVelocity *= Float3(0.2f*fabs(forwardDir.x), 0.2f*fabs(forwardDir.y), 0.2f*fabs(forwardDir.z)); } if(key_strafeRight <= 0.001 && key_strafeLeft <= 0.001) { - rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); + rightVelocity *= Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); } } - if(walkDirection == Oyster::Math::Float3::null) + if( walkDirection == Float3::null ) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { @@ -147,9 +151,8 @@ void Player::BeginFrame() this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } } - // Walk if walkdirection is something - if(walkDirection != Oyster::Math::Float3::null) - { + else + { // Walk if walkdirection is something walkDirection.Normalize(); // If on the ground, accelerate normally @@ -164,6 +167,7 @@ void Player::BeginFrame() rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), abs(rightDir.y), fabs(rightDir.z)) * walkSpeed; } } + // If in the air, accelerate slower if(IsJumping()) { @@ -176,6 +180,7 @@ void Player::BeginFrame() rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; } } + if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 965abfd9..e6e755c6 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -10,7 +10,7 @@ #include "DynamicArray.h" const float MAX_HP = 100.0f; -const float BASIC_SPEED = 30.0f; +const float BASIC_SPEED = 30.0f;// * 0.2f; namespace GameLogic { From b1cf134bea2d20c1acb7d321dbd9b4b48d130478 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 27 Feb 2014 11:40:58 +0100 Subject: [PATCH 36/46] added support to resize --- Code/OysterGraphics/Render/Resources.cpp | 43 ++++++++++++++++++++++-- Code/OysterGraphics/Render/Resources.h | 1 + 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index cced13e9..2290c427 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -154,6 +154,11 @@ namespace Oyster desc.Type = Buffer::STRUCTURED_BUFFER; Light::PointLightsData.Init(desc); + + Buffer* b = &Light::PointLightsData; + + Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&Light::PointLightView,NULL); + desc.Type = Buffer::BUFFER_TYPE::VERTEX_BUFFER; desc.ElementSize = sizeof(Definitions::Text2D); desc.NumElements = MAX_LETTER_COUNT; @@ -237,6 +242,41 @@ namespace Oyster return Core::Init::Success; } + Core::Init::State Resources::ReInitViews(Math::Float2 size) + { + //Release Views + for(int i = 0; i < GBufferSize; ++i) + { + SAFE_RELEASE(GBufferRTV[i]); + SAFE_RELEASE(GBufferSRV[i]); + Core::UsedMem -= Core::resolution.x * Core::resolution.y * 16; + } + + //Release Views + for(int i = 0; i < GBufferSize; ++i) + { + SAFE_RELEASE(LBufferUAV[i]); + SAFE_RELEASE(LBufferSRV[i]); + Core::UsedMem -= Core::resolution.x * Core::resolution.y * 16; + } + + Core::resolution = size; + + //Create Views + for(int i = 0; i< GBufferSize; ++i) + { + Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL); + } + + for(int i = 0; i < LBufferSize; ++i) + { + Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]); + } + + //Blur + Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&Blur::BufferSRV,&Blur::BufferUAV); + } + Core::Init::State Resources::InitViews() { //Create Views @@ -253,9 +293,6 @@ namespace Oyster //Blur Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&Blur::BufferSRV,&Blur::BufferUAV); - Buffer* b = &Light::PointLightsData; - - Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&Light::PointLightView,NULL); srand((unsigned int)time(0)); //SSAO diff --git a/Code/OysterGraphics/Render/Resources.h b/Code/OysterGraphics/Render/Resources.h index fe1393b9..769bc2c2 100644 --- a/Code/OysterGraphics/Render/Resources.h +++ b/Code/OysterGraphics/Render/Resources.h @@ -108,6 +108,7 @@ namespace Oyster static Core::Init::State Init(); static Core::Init::State InitShaders(); + static Core::Init::State ReInitViews(Math::Float2); static Core::Init::State InitRenderStates(); static Core::Init::State InitBuffers(); static Core::Init::State InitViews(); From 779b2ee00c28886ab5e33f6a7914638893c711e9 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 11:46:58 +0100 Subject: [PATCH 37/46] More merge conflicts untanglement --- .../GameClient/GameClientState/GameState.cpp | 74 --------------- .../GameClient/GameClientState/GamingUI.cpp | 7 +- Code/Game/GameLogic/GameAPI.h | 4 - Code/Game/GameLogic/Player.cpp | 89 +------------------ Code/Game/GameLogic/Player.h | 6 +- Code/Game/GameServer/GameSession.h | 4 - .../Implementation/GameSession_Gameplay.cpp | 20 +---- .../Implementation/PhysicsAPI_Impl.cpp | 2 +- .../Implementation/SimpleRigidBody.cpp | 19 ---- .../Implementation/SimpleRigidBody.h | 7 +- 10 files changed, 8 insertions(+), 224 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1833b436..3a8a004b 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -752,7 +752,6 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState player = (this->privData->players)[decoded.objectID]; if( player ) -<<<<<<< HEAD { if( this->privData->myId == decoded.objectID ) { @@ -793,15 +792,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case GameLogic::PlayerAction::PlayerAction_Idle: player->playAnimation(L"idle", true); break; - case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: break; case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: break; case GameLogic::WeaponAction::WeaponAction_Reload: break; - - default: break; } @@ -821,76 +817,6 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } if( object ) { -======= - { - if( this->privData->myId == decoded.objectID ) - { - // dont delete my player - } - if( player ) - { - player->SetVisible(false); - (this->privData->players)[decoded.objectID].Release(); - } - } - } - return GameClientState::event_processed; - case protocol_Gameplay_ObjectAction: - { - Protocol_ObjectAction decoded(data); - - C_Player *player; - player = (this->privData->players)[decoded.objectID]; - - if( player ) - { - if( this->privData->myId == decoded.objectID ) - { - // my player animation - //} - //else - //{ - // HACK for now animate my char - switch (decoded.animationID) - { - case GameLogic::PlayerAction::PlayerAction_Walk: - player->playAnimation(L"run_forwards", true); - break; - case GameLogic::PlayerAction::PlayerAction_Jump: - player->playAnimation(L"movement", true); - break; - case GameLogic::PlayerAction::PlayerAction_Idle: - player->playAnimation(L"idle", true); - break; - - case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: - break; - case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: - break; - case GameLogic::WeaponAction::WeaponAction_Reload: - break; - - - default: - break; - } - } - } - } - return GameClientState::event_processed; - case protocol_Gameplay_ObjectCollision: - { - Protocol_ObjectCollision decoded(data); - C_Object *object; - object = (this->privData->players)[decoded.objectID]; - if( !object) - { - // if it is not a player - object = (*this->privData->dynamicObjects)[decoded.objectID]; - } - if( object ) - { ->>>>>>> origin/New-inputsystem switch (decoded.collisionID) { case GameLogic::CollisionEvent::CollisionEvent_BasicCollision: diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 74f50c22..3db2ade1 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -217,9 +217,4 @@ void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, In this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) ); } } -} -<<<<<<< HEAD - - -======= ->>>>>>> origin/New-inputsystem +} \ No newline at end of file diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 503b40ba..80b255bd 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -30,11 +30,7 @@ namespace GameLogic typedef void(*ObjectEnabledFunction)(IObjectData* object); // Callback method that recieves and object typedef void(*ObjectHpFunction)(IObjectData* object, float hp); // Callback method that sends obj HP typedef void(*ObjectRespawnedFunction)(IObjectData* object, Oyster::Math::Float3 spawnPos ); // Callback method that sends spawnPos -<<<<<<< HEAD typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer -======= - typedef void(*ObjectDeadFunction)(IObjectData* object, IObjectData* killer, float seconds); // Callback method that sends death timer ->>>>>>> origin/New-inputsystem typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index a6fc12f7..47552d27 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -54,18 +54,13 @@ void Player::initPlayerData() this->playerStats.hp = MAX_HP; this->playerStats.movementSpeed = BASIC_SPEED; this->playerState = PLAYER_STATE_IDLE; -<<<<<<< HEAD this->lookDir = Float3( 0.0f, 0.0f, -1.0f ); -======= - this->lookDir = Oyster::Math::Float3(0,0,-1); ->>>>>>> origin/New-inputsystem this->key_forward = 0; this->key_backward = 0; this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; -<<<<<<< HEAD this->RecentlyAffected = 0; this->deathTimer = 0; @@ -75,20 +70,11 @@ void Player::initPlayerData() state.staticFrictionCoeff = 0.0f; state.dynamicFrictionCoeff = 0.0f; this->rigidBody->SetState( state ); -======= - this->deathTimer = 0; - - this->rotationUp = 0; ->>>>>>> origin/New-inputsystem } void Player::BeginFrame() { -<<<<<<< HEAD - if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED ) -======= - if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) ->>>>>>> origin/New-inputsystem + if( this->playerState & (PLAYER_STATE_DEAD | PLAYER_STATE_DIED) ) { static const Float maxSpeed = 30.0f; @@ -96,11 +82,7 @@ void Player::BeginFrame() // Rotate player accordingly this->rigidBody->AddRotationAroundY(this->rotationUp); - this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); -<<<<<<< HEAD - this->rotationUp = 0; -======= ->>>>>>> origin/New-inputsystem + this->rigidBody->SetUp( this->rigidBody->GetState().centerPos.GetNormalized() ); // Direction data Oyster::Math::Float4x4 orientation; @@ -119,15 +101,10 @@ void Player::BeginFrame() Float3 upVelocity = linearVelocity * Float3(fabs(upDir.x), fabs(upDir.y), fabs(upDir.z) ); // Walking data -<<<<<<< HEAD Float3 walkDirection = Float3( 0.0f ); Float &walkSpeed = this->playerStats.movementSpeed; Float frameTime = gameInstance->GetFrameTime(); -======= - Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); - Oyster::Math::Float walkSpeed = this->playerStats.movementSpeed*0.2f; ->>>>>>> origin/New-inputsystem // Check for input if(key_forward > 0.001) @@ -152,11 +129,7 @@ void Player::BeginFrame() } // Dampen velocity if certain keys are not pressed -<<<<<<< HEAD if( key_jump <= 0.001 && IsWalking() ) -======= - if(key_jump <= 0.001 && IsWalking()) ->>>>>>> origin/New-inputsystem { if(key_forward <= 0.001 && key_backward <= 0.001) { @@ -168,21 +141,7 @@ void Player::BeginFrame() } } -<<<<<<< HEAD if( walkDirection == Float3::null ) -======= - if(walkDirection == Oyster::Math::Float3::null) - { - if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) - { - if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) - this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); - this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - } - } - // Walk if walkdirection is something - if(walkDirection != Oyster::Math::Float3::null) ->>>>>>> origin/New-inputsystem { if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { @@ -209,7 +168,7 @@ void Player::BeginFrame() } // If in the air, accelerate slower - if(IsJumping()) + if( IsJumping() ) { if(forwardSpeed < maxSpeed) { @@ -220,10 +179,6 @@ void Player::BeginFrame() rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; } } -<<<<<<< HEAD - -======= ->>>>>>> origin/New-inputsystem if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) @@ -242,13 +197,8 @@ void Player::BeginFrame() //Jump if(key_jump > 0.001) { -<<<<<<< HEAD this->key_jump -= this->gameInstance->GetFrameTime(); if(IsWalking()) -======= - this->key_jump -= this->gameInstance->GetFrameTime(); - if(IsWalking()) ->>>>>>> origin/New-inputsystem { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); @@ -269,13 +219,7 @@ void Player::BeginFrame() } } -<<<<<<< HEAD -void Player::EndFrame() -{ -} -======= void Player::EndFrame() { /* do nothing .. for now */ } ->>>>>>> origin/New-inputsystem void Player::Move(const PLAYER_MOVEMENT &movement) { @@ -399,7 +343,6 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { -<<<<<<< HEAD if(damage != 0) { this->playerStats.hp -= damage; @@ -415,33 +358,7 @@ void Player::DamageLife(int damage) this->playerStats.hp = 0; this->playerState = PLAYER_STATE_DIED; } -======= - this->playerStats.hp -= damage; - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - - if(this->playerStats.hp <= 0) - { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; } - -} - -bool Player::deathTimerTick(float dt) -{ - this->deathTimer -= dt; - if( this->deathTimer <= 0) - { - return true; ->>>>>>> origin/New-inputsystem - } - return false; -} -void Player::setDeathTimer(float deathTimer) -{ - this->deathTimer = deathTimer; - this->playerState = PLAYER_STATE_DEAD; } bool Player::deathTimerTick(float dt) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 0b96166f..8952c5b0 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -10,11 +10,7 @@ #include "DynamicArray.h" const float MAX_HP = 100.0f; -<<<<<<< HEAD -const float BASIC_SPEED = 30.0f;// * 0.2f; -======= -const float BASIC_SPEED = 30.0f; ->>>>>>> origin/New-inputsystem +const float BASIC_SPEED = 30.0f * 0.2f; namespace GameLogic { diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 583e92b3..d449ff2d 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -102,11 +102,7 @@ namespace DanBias static void ObjectEnabled ( GameLogic::IObjectData* movedObject ); static void ObjectDamaged ( GameLogic::IObjectData* movedObject, float hp ); static void ObjectRespawned ( GameLogic::IObjectData* movedObject, Oyster::Math::Float3 spawnPos ); -<<<<<<< HEAD static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); -======= - static void ObjectDead ( GameLogic::IObjectData* movedObject, GameLogic::IObjectData* killer, float seconds ); ->>>>>>> origin/New-inputsystem static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 7ac4f157..28f0f993 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -162,11 +162,7 @@ using namespace DanBias; { GameSession::gameSession->Send(Protocol_ObjectRespawn(movedObject->GetID(), spawnPos).GetProtocol()); } -<<<<<<< HEAD void GameSession::ObjectDead( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ) -======= - void GameSession::ObjectDead( GameLogic::IObjectData* movedObject, GameLogic::IObjectData* killer, float seconds ) ->>>>>>> origin/New-inputsystem { GameSession::gameSession->Send(Protocol_ObjectDie(victim->GetID(), killer->GetID(), seconds).GetProtocol()); } @@ -185,21 +181,7 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); } - void GameSession::PickupEvent( GameLogic::IObjectData* movedObject, int pickupEffectID ) - { - // send pickup protocol - GameSession::gameSession->Send(Protocol_ObjectPickup(movedObject->GetID(), pickupEffectID).GetProtocol()); - } - void GameSession::ActionEvent( GameLogic::IObjectData* movedObject , int actionID ) - { - // send action protocol - GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); - } - void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID ) - { - // send action protocol - GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); - } + //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 772bf32e..d46f7b0a 100644 --- a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -68,7 +68,7 @@ void API_Impl::SetGravity(float gravity) // Bullet physics ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) { - SimpleRigidBody* body = new SimpleRigidBody; + SimpleRigidBody* body = new SimpleRigidBody(); SimpleRigidBody::State state; // Add collision shape diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 4587d36d..ed36dcec 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -239,16 +239,6 @@ void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up) btQuaternion newRotation; btTransform trans; trans = this->rigidBody->getWorldTransform(); -<<<<<<< HEAD - - btVector3 v1 = trans.getBasis().getColumn(1); - btVector3 v2(up.x, up.y, up.z); - - btQuaternion q; - btVector3 a = v1.cross(v2); - - if (v1.dot(v2) < -0.999999) -======= btVector3 v1 = trans.getBasis().getColumn(1); btVector3 v2(up.x, up.y, up.z); @@ -257,26 +247,17 @@ void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up) btVector3 a = v1.cross(v2); if (v1.dot(v2) < -0.999999) ->>>>>>> origin/New-inputsystem { btVector3 xCrossPre = btVector3(1, 0 ,0).cross(v1); if(xCrossPre.length() < 0.000001) xCrossPre = btVector3(0, 1 ,0).cross(v1); xCrossPre.normalize(); q.setRotation(xCrossPre, 3.1415); -<<<<<<< HEAD - } - else if (v1.dot(v2) > 0.999999) - { - q = btQuaternion(0, 0, 0, 1); - } -======= } else if (v1.dot(v2) > 0.999999) { q = btQuaternion(0, 0, 0, 1); } ->>>>>>> origin/New-inputsystem else { q.setX(a.x()); diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index b8157be6..1609f607 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -29,11 +29,8 @@ namespace Oyster void SetRotation(Math::Quaternion quaternion); void SetRotation(Math::Float3 eulerAngles); void SetRotation(::Oyster::Math::Float4x4 rotation); -<<<<<<< HEAD - void AddRotationAroundY(::Oyster::Math::Float angle); -======= + void AddRotationAroundY(Math::Float angle); ->>>>>>> origin/New-inputsystem void SetAngularFactor(Math::Float factor); void SetMass(Math::Float mass); @@ -62,8 +59,6 @@ namespace Oyster void SetCustomTag( void *ref ); void* GetCustomTag() const; - - // Class specific void SetCollisionShape(btCollisionShape* shape); void SetMotionState(btDefaultMotionState* motionState); From cf8a83e1e39856af8f1d3d605541f7bc6bb70303 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 12:55:34 +0100 Subject: [PATCH 38/46] Merge fixes --- Code/Game/GameLogic/Player.h | 2 +- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 6 ++---- Code/OysterGraphics/Render/DefaultRenderer.cpp | 1 - Code/OysterGraphics/Render/DefaultRenderer.h | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 8952c5b0..2f029ae4 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -10,7 +10,7 @@ #include "DynamicArray.h" const float MAX_HP = 100.0f; -const float BASIC_SPEED = 30.0f * 0.2f; +const float BASIC_SPEED = 10.0f; namespace GameLogic { diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 1a35d408..9bed5560 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -20,7 +20,6 @@ namespace Oyster std::vector Lights; float deltaTime; int MostModel; - float FoV; #ifdef _DEBUG Model::Model* cube; Model::Model* sphere; @@ -89,7 +88,6 @@ namespace Oyster void API::SetProjection(const Math::Float4x4& projection) { Projection = projection; - FoV = 2 * std::atanf(1/projection.m[1][1]); } void API::SetView(const Math::Float4x4& view) @@ -101,11 +99,11 @@ namespace Oyster { if(Lights.size()) { - Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size(), FoV); + Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size()); } else { - Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0, FoV); + Render::DefaultRenderer::NewFrame(View, Projection, NULL, 0); } } diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp index 2ecbbeeb..1066db54 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.cpp +++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp @@ -56,7 +56,6 @@ namespace Oyster Definitions::LightConstants lc; lc.InvProj = Projection.GetInverse(); - lc.Pixels = Core::resolution; lc.Lights = numLights; lc.View = View; lc.Proj = Projection; diff --git a/Code/OysterGraphics/Render/DefaultRenderer.h b/Code/OysterGraphics/Render/DefaultRenderer.h index 74a1e4ff..1a5cdcc0 100644 --- a/Code/OysterGraphics/Render/DefaultRenderer.h +++ b/Code/OysterGraphics/Render/DefaultRenderer.h @@ -13,7 +13,7 @@ namespace Oyster class DefaultRenderer { public: - static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights, float Fov); + static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights); static void RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float DeltaTime = 0); static void EndFrame(); }; From 74a833baf8e5613cffa6e654b507231abb3a83a9 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 12:58:51 +0100 Subject: [PATCH 39/46] changed arena to sumLights.bias --- Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp b/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp index 8ec4c9aa..08afcf67 100644 --- a/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp +++ b/Code/Game/LanServer/GameServerDebugEnvironment/Source.cpp @@ -32,7 +32,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh GameServerAPI::GameSetGameMode(L"free-for-all"); GameServerAPI::GameSetGameName(L"DebugServer"); GameServerAPI::GameSetGameTime(15); - GameServerAPI::GameSetMapName(L"manyLights.bias"); + GameServerAPI::GameSetMapName(L"sumLights.bias"); GameServerAPI::GameSetMaxClients(10); if(GameServerAPI::GameStart(true)) From 5970b23d3c044e4ae504a1afc8712251cdf5782f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 13:07:31 +0100 Subject: [PATCH 40/46] lost code fix --- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- Code/Game/GameClient/GameClientState/GamingUI.cpp | 1 - Code/Game/GameLogic/Player.cpp | 3 ++- Code/Game/GameLogic/Player.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 3db2ade1..20c409ee 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -211,7 +211,6 @@ void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, In //send delta mouse movement { this->camera->PitchDown( (-coordinate.y) * this->sharedData->mouseSensitivity ); - //this->camera->YawLeft( (-coordinate.x) * this->sharedData->mouseSensitivity ); //if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why? { this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) ); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 090656d7..2364acdb 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -83,9 +83,10 @@ void Player::BeginFrame() // Rotate player accordingly this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp( this->rigidBody->GetState().centerPos.GetNormalized() ); + this->rotationUp = 0.0f; // Direction data - Oyster::Math::Float4x4 orientation; + Float4x4 orientation; orientation = this->rigidBody->GetState().GetOrientation(); Float3 &forwardDir = orientation.v[2].xyz; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 2f029ae4..29ab1016 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -10,7 +10,7 @@ #include "DynamicArray.h" const float MAX_HP = 100.0f; -const float BASIC_SPEED = 10.0f; +const float BASIC_SPEED = 20.0f; namespace GameLogic { From edd6169c447ec07c43348504f7e2e6de6583d866 Mon Sep 17 00:00:00 2001 From: lanariel Date: Thu, 27 Feb 2014 13:12:18 +0100 Subject: [PATCH 41/46] quick fix --- Code/OysterGraphics/Render/Resources.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 2290c427..590983bc 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -275,6 +275,8 @@ namespace Oyster //Blur Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&Blur::BufferSRV,&Blur::BufferUAV); + + return Core::Init::Success; } Core::Init::State Resources::InitViews() From 84a462de6c1905121a99aacd210bdd68aedb5c19 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 27 Feb 2014 13:40:51 +0100 Subject: [PATCH 42/46] GL - Player pushed by weapon --- Code/Game/GameLogic/CollisionManager.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 928ddaac..acdf030c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -304,13 +304,19 @@ using namespace GameLogic; Object *realObj = (Object*)obj->GetCustomTag(); - if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World) + if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_World) return; - + if(realObj->GetObjectType() == ObjectSpecialType::ObjectSpecialType_Player) + { + obj->ApplyImpulse(((forcePushData*)(args))->pushForce* 0.5); + ((Player*)obj->GetCustomTag())->DamageLife(10); + } + else + { + obj->ApplyImpulse(((forcePushData*)(args))->pushForce); + } - obj->ApplyImpulse(((forcePushData*)(args))->pushForce); - DynamicObject *dynamicObj = dynamic_cast(realObj); From 97ea35e91e33084b4ad3a19ab4df26961cd7edf5 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Thu, 27 Feb 2014 14:11:03 +0100 Subject: [PATCH 43/46] Fixing player animation updates --- Code/Game/GameLogic/Player.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 209287a8..9cd4635e 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -71,9 +71,6 @@ void Player::BeginFrame() { weapon->Update(0.002f); - - - Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly @@ -137,15 +134,11 @@ void Player::BeginFrame() rightVelocity *= Oyster::Math::Float3(0.2f*fabs(rightDir.x), 0.2f*fabs(rightDir.y), 0.2f*fabs(rightDir.z)); } } - - if(walkDirection == Oyster::Math::Float3::null) + if(IsIdle()) { - if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) - { - if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) - this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); - this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - } + if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } // Walk if walkdirection is something if(walkDirection != Oyster::Math::Float3::null) @@ -176,12 +169,13 @@ void Player::BeginFrame() rightVelocity += walkDirection*Oyster::Math::Float3(fabs(rightDir.x), fabs(rightDir.y), fabs(rightDir.z)) * walkSpeed*0.2f; } } - if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) - { + // TODO not suer if we want to keep jump animation while jumping + //if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) + //{ if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Walk); this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; - } + //} } // Adjust velocities so no squaring occurs @@ -205,14 +199,6 @@ void Player::BeginFrame() this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } - else - { - if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING) - { - this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); - this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; - } - } } } @@ -305,7 +291,7 @@ bool Player::IsJumping() } bool Player::IsIdle() { - return (this->rigidBody->GetLambdaUp() == 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f); + return (this->rigidBody->GetLambdaUp() < 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.1f); } void Player::Inactivate() From 2592e4d3e3d28e50858165028aa64d06a2d9f1d3 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 14:36:15 +0100 Subject: [PATCH 44/46] Picked box should be dropped when impacted by any dynamic object --- Code/Game/GameLogic/CollisionManager.cpp | 13 ++++++++++++- Code/Game/GameLogic/GameLogicStates.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index fd5f372a..f8669591 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -242,6 +242,18 @@ using namespace GameLogic; return; } + Player *player = realObjA->getManipulatingPlayer(); + if( player != nullptr ) + { + player->UseWeapon( WEAPON_INTERRUPT ); + } + + player = realObjB->getManipulatingPlayer(); + if( player != nullptr ) + { + player->UseWeapon( WEAPON_INTERRUPT ); + } + //check which obj is the one that is already affected, if both are then use the special case of changing ownership. if(realObjA->getAffectingPlayer() == NULL && realObjB->getAffectingPlayer() == NULL) //None of the objects have a player affecting them { @@ -350,7 +362,6 @@ using namespace GameLogic; weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; dynamicObj->SetManipulatingPlayer(*weapon->owner); //TODO: add if this is to be a struggle of who has the most power in its weapon, the player that is already manipulating the object or you. if you then you take the object from the other player, if not then you do not take the object - break; } diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index f006ad27..5f3952fd 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -32,6 +32,7 @@ namespace GameLogic WEAPON_USE_SECONDARY_RELEASE = 4, WEAPON_USE_UTILLITY_PRESS = 8, WEAPON_USE_UTILLITY_RELEASE = 16, + WEAPON_INTERRUPT = 32 }; enum WEAPON_STATE From 36761a83142f4a9d603e58b75d503bf97428dc25 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 27 Feb 2014 14:37:15 +0100 Subject: [PATCH 45/46] OnDynamicCollision drop box .. missed a file in commit --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 6abe81b6..4e584a44 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -43,7 +43,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, //switch case to determin what functionallity to use in the attatchment switch (usage) { - case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: + case WEAPON_USE_PRIMARY_PRESS: //if(currentEnergy >= 9.0f) { currentEnergy -= 9.0f; @@ -51,23 +51,24 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, // add CD ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); } - break; + break; - case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: + case WEAPON_USE_SECONDARY_PRESS: if(this->hasObject) { - ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); - this->hasObject = false; - this->heldObject = NULL; + goto CASE_WEAPON_INTERRUPT; } else if( currentEnergy >= 1.0f ) { - currentEnergy -= 1.0f; - if(!this->hasObject) + if(this->hasObject) { - ForcePull(usage,dt); - // add CD - ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); + currentEnergy -= 1.0f; + if(!this->hasObject) + { + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); + } } } else //Energy drained, release object @@ -76,20 +77,27 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, this->hasObject = false; this->heldObject = NULL; } - break; + break; + + case WEAPON_INTERRUPT: + CASE_WEAPON_INTERRUPT: + ((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + this->hasObject = false; + this->heldObject = NULL; + break; case WEAPON_USE_SECONDARY_RELEASE: - { - if (this->hasObject) //Dummy check { - //((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); - //this->hasObject = false; - //this->heldObject = NULL; + if (this->hasObject) //Dummy check + { + //((DynamicObject*)(this->heldObject->GetCustomTag()))->RemoveManipulation(); + //this->hasObject = false; + //this->heldObject = NULL; + } } - } - break; + break; - case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: + case WEAPON_USE_UTILLITY_PRESS: if(currentEnergy >= 90.0f) { currentEnergy -= 90.0f; @@ -97,9 +105,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, // add CD ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate); } - break; + break; } - } void AttatchmentMassDriver::Update(float dt) From 09d8825c662b84a3e5a2d4ef9d2e3f77c6bdeab8 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 27 Feb 2014 14:41:31 +0100 Subject: [PATCH 46/46] sada --- Code/Game/GameLogic/GameLogic.vcxproj | 2 ++ Code/Game/GameLogic/GameLogicStates.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 26c98891..4f1cb1fa 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -159,6 +159,7 @@ + @@ -185,6 +186,7 @@ + diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index f006ad27..6b101f5f 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -46,6 +46,10 @@ namespace GameLogic Oyster::Math::Float3 pushForce; Player *p; }; + struct firedBullet + { + Oyster::Math::Float hitDamage; + };