From 8034b42c870aa109efaa3362f2c67565b4e260fe Mon Sep 17 00:00:00 2001 From: viktorljung Date: Fri, 5 Feb 2016 16:43:57 +0100 Subject: [PATCH 1/8] spriteComponent WIP --- include/Engine/Rendering/Camera.h | 2 + include/Engine/Rendering/DrawFinalPass.h | 2 + include/Engine/Rendering/RenderQueue.h | 4 ++ include/Engine/Rendering/RenderSystem.h | 1 + include/Engine/Rendering/SpriteJob.h | 75 ++++++++++++++++++++ resources/Schema/Components.xsd | 1 + resources/Schema/Components/Sprite.xml | 7 ++ resources/Schema/Components/Sprite.xsd | 27 +++++++ resources/Schema/Entities/RenderingWorld.xml | 16 ++++- resources/Shaders/Sprite.frag.glsl | 41 +++++++++++ resources/Shaders/Sprite.vert.glsl | 24 +++++++ src/Engine/Rendering/Camera.cpp | 7 ++ src/Engine/Rendering/DrawFinalPass.cpp | 56 ++++++++++++++- src/Engine/Rendering/RenderSystem.cpp | 53 +++++++++++++- src/Engine/Rendering/Texture.cpp | 7 +- src/Game/Game.cpp | 3 +- 16 files changed, 318 insertions(+), 8 deletions(-) create mode 100644 include/Engine/Rendering/SpriteJob.h create mode 100644 resources/Schema/Components/Sprite.xml create mode 100644 resources/Schema/Components/Sprite.xsd create mode 100644 resources/Shaders/Sprite.frag.glsl create mode 100644 resources/Shaders/Sprite.vert.glsl diff --git a/include/Engine/Rendering/Camera.h b/include/Engine/Rendering/Camera.h index 29dd4626..6130fd01 100644 --- a/include/Engine/Rendering/Camera.h +++ b/include/Engine/Rendering/Camera.h @@ -33,6 +33,8 @@ public: glm::mat4 ViewMatrix() const { return m_ViewMatrix; } void SetViewMatrix(glm::mat4 val); + glm::mat4 BillboardMatrix(); + float AspectRatio() const { return m_AspectRatio; } void SetAspectRatio(float val); diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 74f505fe..867ec844 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -31,6 +31,7 @@ private: void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const; void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps) const; void DrawModelRenderQueues(std::list>& job, RenderScene& scene); + void DrawSprites(std::list>&jobs, RenderScene& scene); void BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); void BindModelUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene); @@ -53,6 +54,7 @@ private: ShaderProgram* m_ForwardPlusProgram; ShaderProgram* m_ExplosionEffectProgram; + ShaderProgram* m_SpriteProgram; }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index af9d928e..47b15b63 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -15,6 +15,7 @@ #include "PointLightJob.h" #include "DirectionalLightJob.h" #include "ExplosionEffectJob.h" +#include "SpriteJob.h" struct RenderScene { @@ -24,6 +25,8 @@ struct RenderScene std::list> PointLightJobs; std::list> TextJobs; std::list> DirectionalLightJobs; + std::list> SpriteJobs; + Rectangle Viewport; bool ClearDepth = false; glm::vec4 AmbientColor; @@ -35,6 +38,7 @@ struct RenderScene PointLightJobs.clear(); TextJobs.clear(); DirectionalLightJobs.clear(); + SpriteJobs.clear(); } }; diff --git a/include/Engine/Rendering/RenderSystem.h b/include/Engine/Rendering/RenderSystem.h index d64147b9..6ab4b98b 100644 --- a/include/Engine/Rendering/RenderSystem.h +++ b/include/Engine/Rendering/RenderSystem.h @@ -45,6 +45,7 @@ private: void fillPointLights(std::list>& jobs, World* world); void fillDirectionalLights(std::list>& jobs, World* world); void fillLight(std::list>& jobs); + void fillSprites(std::list>& jobs, World* world); bool isChildOfACamera(EntityWrapper entity); bool isChildOfCurrentCamera(EntityWrapper entity); diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h new file mode 100644 index 00000000..a20d0395 --- /dev/null +++ b/include/Engine/Rendering/SpriteJob.h @@ -0,0 +1,75 @@ +#ifndef SpriteJob_h__ +#define SpriteJob_h__ + +#include + +#include "../Common.h" +#include "../GLM.h" +#include "../Core/ComponentWrapper.h" +#include "Texture.h" +#include "Model.h" +#include "RenderJob.h" +#include "../Core/ResourceManager.h" +#include "Camera.h" +#include "../Core/World.h" +#include "../Core/Transform.h" +#include "Skeleton.h" + +struct SpriteJob : RenderJob +{ + SpriteJob(ComponentWrapper cSprite, Camera* camera, glm::mat4 matrix, World* world, glm::vec4 fillColor, float fillPercentage) + : RenderJob() + { + Model = ResourceManager::Load<::Model>("Models/Core/UnitQuad.mesh"); + ::RawModel::MaterialGroup matGroup = Model->MaterialGroups().front(); + TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0; + + if (cSprite["DiffuseTexture"]) { + DiffuseTexture = ResourceManager::Load(cSprite["DiffuseTexture"]); + } else { + DiffuseTexture = nullptr; + } + if (cSprite["GlowMap"]) { + IncandescenceTexture = ResourceManager::Load(cSprite["GlowMap"]); + } else { + IncandescenceTexture = nullptr; + } + StartIndex = matGroup.StartIndex; + EndIndex = matGroup.EndIndex; + Matrix = matrix; + Color = cSprite["Color"]; + Entity = cSprite.EntityID; + glm::vec3 abspos = Transform::AbsolutePosition(world, cSprite.EntityID); + glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1)); + Depth = viewpos.z; + World = world; + + FillColor = fillColor; + FillPercentage = fillPercentage; + }; + + unsigned int TextureID; + + EntityID Entity; + glm::mat4 Matrix; + const Texture* DiffuseTexture; + const Texture* NormalTexture; + const Texture* SpecularTexture; + const Texture* IncandescenceTexture; + float Shininess = 0.f; + glm::vec4 Color; + const ::Model* Model = nullptr; + unsigned int StartIndex = 0; + unsigned int EndIndex = 0; + World* World; + + glm::vec4 FillColor = glm::vec4(0); + float FillPercentage = 0.0; + + void CalculateHash() override + { + Hash = TextureID; + } +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 265a3cc5..3163c787 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -31,4 +31,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/Sprite.xml b/resources/Schema/Components/Sprite.xml new file mode 100644 index 00000000..c2a2057f --- /dev/null +++ b/resources/Schema/Components/Sprite.xml @@ -0,0 +1,7 @@ + + + + + + true + diff --git a/resources/Schema/Components/Sprite.xsd b/resources/Schema/Components/Sprite.xsd new file mode 100644 index 00000000..c8f0c187 --- /dev/null +++ b/resources/Schema/Components/Sprite.xsd @@ -0,0 +1,27 @@ + + + + + + + + A sprite that will be facing the camera + + + + + Diffuse Texture file + + + GlowMap file + + + Color tint + + + Whether the model is visible or not + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/RenderingWorld.xml b/resources/Schema/Entities/RenderingWorld.xml index 20301d5f..d9f7c62d 100644 --- a/resources/Schema/Entities/RenderingWorld.xml +++ b/resources/Schema/Entities/RenderingWorld.xml @@ -52,11 +52,11 @@ - 0.65990006923675537 + Models/Core/UnitHexagon.mesh @@ -161,7 +161,7 @@ - + @@ -346,6 +346,18 @@ + + + + Textures/HexmapDiff.png + Textures/GlowFrame.png + + + + + + + diff --git a/resources/Shaders/Sprite.frag.glsl b/resources/Shaders/Sprite.frag.glsl new file mode 100644 index 00000000..c391322d --- /dev/null +++ b/resources/Shaders/Sprite.frag.glsl @@ -0,0 +1,41 @@ +#version 430 + +uniform vec4 Color; +uniform vec4 FillColor; +uniform float FillPercentage; +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; + +layout (binding = 0) uniform sampler2D DiffuseTexture; +layout (binding = 1) uniform sampler2D GlowMapTexture; + + +in VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; +}Input; + + +out vec4 sceneColor; +out vec4 bloomColor; + +void main() +{ + vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); + vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate); + + vec4 color_result = Color * diffuseTexel; + + float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; + if(pos <= FillPercentage) { + color_result += FillColor; + } + sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); + color_result += glowTexel*3; + + bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0); +} + + diff --git a/resources/Shaders/Sprite.vert.glsl b/resources/Shaders/Sprite.vert.glsl new file mode 100644 index 00000000..e910a26a --- /dev/null +++ b/resources/Shaders/Sprite.vert.glsl @@ -0,0 +1,24 @@ +#version 430 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 4) in vec2 TextureCoords; + +out VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; +}Output; + +void main() +{ + gl_Position = P * M * vec4(Position, 1.0); + + Output.Position = Position; + Output.TextureCoordinate = TextureCoords; + Output.Normal = Normal; +} \ No newline at end of file diff --git a/src/Engine/Rendering/Camera.cpp b/src/Engine/Rendering/Camera.cpp index f6b2e5ef..c1246c6a 100644 --- a/src/Engine/Rendering/Camera.cpp +++ b/src/Engine/Rendering/Camera.cpp @@ -62,6 +62,13 @@ void Camera::SetViewMatrix(glm::mat4 val) m_ViewMatrix = val; } + +glm::mat4 Camera::BillboardMatrix() +{ + glm::mat4 matrix = glm::toMat4(m_Orientation); + return matrix; +} + //void Camera::Pitch(float val) //{ // m_Pitch = val; diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 8247797e..e5919fbe 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -55,6 +55,15 @@ void DrawFinalPass::InitializeShaderPrograms() m_ExplosionEffectProgram->BindFragDataLocation(1, "bloomColor"); m_ExplosionEffectProgram->Link(); GLERROR("Creating explosion program"); + + m_SpriteProgram = ResourceManager::Load("#m_SpriteProgram"); + m_SpriteProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Sprite.vert.glsl"))); + m_SpriteProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/Sprite.frag.glsl"))); + m_SpriteProgram->Compile(); + m_SpriteProgram->BindFragDataLocation(0, "sceneColor"); + m_SpriteProgram->BindFragDataLocation(1, "bloomColor"); + m_SpriteProgram->Link(); + GLERROR("Creating sprite program"); } void DrawFinalPass::Draw(RenderScene& scene) @@ -70,6 +79,8 @@ void DrawFinalPass::Draw(RenderScene& scene) GLERROR("OpaqueObjects"); DrawModelRenderQueues(scene.TransparentObjects, scene); GLERROR("TransparentObjects"); + DrawSprites(scene.SpriteJobs, scene); + GLERROR("SpriteJobs"); delete state; GLERROR("END"); @@ -201,6 +212,50 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& } + +void DrawFinalPass::DrawSprites(std::list>&jobs, RenderScene& scene) +{ + m_SpriteProgram->Bind(); + + GLuint shaderHandle = m_SpriteProgram->GetHandle(); + + for(auto& job : jobs) { + auto spriteJob = std::dynamic_pointer_cast(job); + + if(spriteJob) { + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); + glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor)); + glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage); + + glActiveTexture(GL_TEXTURE0); + if (spriteJob->DiffuseTexture != nullptr) { + glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture); + } else { + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } + + glActiveTexture(GL_TEXTURE1); + if (spriteJob->IncandescenceTexture != nullptr) { + glBindTexture(GL_TEXTURE_2D, spriteJob->IncandescenceTexture->m_Texture); + } else { + glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); + } + + + glBindVertexArray(spriteJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer); + glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int))); + } + } + + + + // m_SpriteProgram->Unbind(); +} + void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) { glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix)); @@ -245,7 +300,6 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr& job) { glActiveTexture(GL_TEXTURE0); diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index eaecf99e..3a1729fc 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -31,6 +31,56 @@ bool RenderSystem::OnSetCamera(Events::SetCamera& e) return true; } + +void RenderSystem::fillSprites(std::list>& jobs, World* world) +{ + auto sprites = world->GetComponents("Sprite"); + if (sprites == nullptr) { + return; + } + + for (auto& cSprite : *sprites) { + bool visible = cSprite["Visible"]; + if (!visible) { + continue; + } + + + EntityWrapper entity(world, cSprite.EntityID); + + // Only render children of a camera if that camera is currently active + if (isChildOfACamera(entity) && !isChildOfCurrentCamera(entity)) { + continue; + } + + // Hide things parented to local player if they have the HiddenFromLocalPlayer component + if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) { + continue; + } + + std::string diffuseResource = cSprite["DiffuseTexture"]; + std::string glowResource = cSprite["GlowMap"]; + if (diffuseResource.empty() && glowResource.empty()) { + continue; + } + + float fillPercentage = 0.f; + glm::vec4 fillColor = glm::vec4(0); + if (world->HasComponent(entity.ID, "Fill")) { + auto fillComponent = world->GetComponent(entity.ID, "Fill"); + fillPercentage = (float)(double)fillComponent["Percentage"]; + fillColor = (glm::vec4)fillComponent["Color"]; + } + + glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, world); + //modelMatrix *= m_Camera->BillboardMatrix(); + + std::shared_ptr spriteJob = std::shared_ptr(new SpriteJob(cSprite, m_Camera, modelMatrix, world, fillColor, fillPercentage)); + + jobs.push_back(spriteJob); + } +} + bool RenderSystem::isChildOfACamera(EntityWrapper entity) { return entity.FirstParentWithComponent("Camera").Valid(); @@ -167,7 +217,6 @@ void RenderSystem::fillPointLights(std::list>& jobs, } } - void RenderSystem::fillDirectionalLights(std::list>& jobs, World* world) { auto directionalLights = world->GetComponents("DirectionalLight"); @@ -189,7 +238,6 @@ void RenderSystem::fillDirectionalLights(std::list>& } } - void RenderSystem::fillText(std::list>& jobs, World* world) { auto texts = world->GetComponents("Text"); @@ -255,6 +303,7 @@ void RenderSystem::Update(double dt) fillPointLights(scene.PointLightJobs, m_World); fillDirectionalLights(scene.DirectionalLightJobs, m_World); fillText(scene.TextJobs, m_World); + fillSprites(scene.SpriteJobs, m_World); m_RenderFrame->Add(scene); } \ No newline at end of file diff --git a/src/Engine/Rendering/Texture.cpp b/src/Engine/Rendering/Texture.cpp index 57f3ca36..492b35be 100644 --- a/src/Engine/Rendering/Texture.cpp +++ b/src/Engine/Rendering/Texture.cpp @@ -2,14 +2,17 @@ Texture::Texture(std::string path) { + PNG image(path); if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) { - image = PNG("Textures/Core/ErrorTexture.png"); + //image = PNG("Textures/Core/ErrorTexture.png"); + return; // Temporary fix to remove crash + /* if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) { LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed."); return; - } + }*/ } this->Width = image.Width; diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index f5afcaeb..d7806ba5 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -14,6 +14,7 @@ #include "Game/Systems/PlayerHUD.h" #include "Game/Systems/LifetimeSystem.h" #include "../Engine/Rendering/AnimationSystem.h" +#include "../Engine/Core/UniformScaleSystem.h" Game::Game(int argc, char* argv[]) { @@ -97,7 +98,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeTrigger, "Player"); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); - + m_SystemPipeline->AddSystem(updateOrderLevel); // Collision and TriggerSystem should update after player. ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision); From 53265bbc90c4c2e647be75ddbfe739e34eb9e5c2 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 10 Feb 2016 17:50:17 +0100 Subject: [PATCH 2/8] PNG is now a resource. You can now load textures threaded. PNG will now throw exceptions when errors happend SpriteComponent is now working without billboarding. --- include/Engine/GUI/TextureFrame.h | 5 +- include/Engine/Rendering/DrawFinalPass.h | 2 + include/Engine/Rendering/Model.h | 1 + include/Engine/Rendering/PNG.h | 3 +- include/Engine/Rendering/Renderer.h | 1 + include/Engine/Rendering/SpriteJob.h | 19 ++--- .../Engine/Rendering/Util/CommonFunctions.h | 11 +-- .../Schema/Entities/QualityAssurance.xml | 74 +++++++++++++++---- resources/Shaders/Sprite.vert.glsl | 3 +- src/Engine/Rendering/DrawBloomPass.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 17 +++-- src/Engine/Rendering/Model.cpp | 8 +- src/Engine/Rendering/PNG.cpp | 22 ++---- src/Engine/Rendering/Renderer.cpp | 17 +++-- src/Engine/Rendering/Texture.cpp | 29 ++++---- src/Engine/Rendering/Util/CommonFunctions.cpp | 17 +++++ src/Game/Game.cpp | 1 + 17 files changed, 149 insertions(+), 83 deletions(-) diff --git a/include/Engine/GUI/TextureFrame.h b/include/Engine/GUI/TextureFrame.h index 2c6d34dd..77967b4d 100644 --- a/include/Engine/GUI/TextureFrame.h +++ b/include/Engine/GUI/TextureFrame.h @@ -3,6 +3,7 @@ #include "Frame.h" #include "../Rendering/Texture.h" +#include "../Rendering/Util/CommonFunctions.h" namespace GUI { @@ -55,10 +56,10 @@ public: return; } - m_Texture = ResourceManager::Load(resourceName); + m_Texture = CommonFunctions::LoadTexture(resourceName, false); m_TextureName = resourceName; if (m_Texture == nullptr) { - m_Texture = ResourceManager::Load("Textures/Core/ErrorTexture.png"); + m_Texture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false); } SizeToTexture(); diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 867ec844..98f986b4 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -7,6 +7,7 @@ #include "FrameBuffer.h" #include "ShaderProgram.h" #include "Util/UnorderedMapVec2.h" +#include "Util/CommonFunctions.h" #include "Texture.h" class DrawFinalPass @@ -43,6 +44,7 @@ private: Texture* m_BlackTexture; Texture* m_NeutralNormalTexture; Texture* m_GreyTexture; + Texture* m_ErrorTexture; FrameBuffer m_FinalPassFrameBuffer; GLuint m_BloomTexture; diff --git a/include/Engine/Rendering/Model.h b/include/Engine/Rendering/Model.h index f751a8cc..6812494c 100644 --- a/include/Engine/Rendering/Model.h +++ b/include/Engine/Rendering/Model.h @@ -2,6 +2,7 @@ #define Model_h__ #include "Rendering/RawModelCustom.h" +#include "Util/CommonFunctions.h" //#include "Rendering/RawModelAssimp.h" #include "../OpenGL.h" diff --git a/include/Engine/Rendering/PNG.h b/include/Engine/Rendering/PNG.h index f2cbf157..a45e9e7c 100644 --- a/include/Engine/Rendering/PNG.h +++ b/include/Engine/Rendering/PNG.h @@ -6,9 +6,10 @@ #include #include "../Common.h" +#include "../Core/ResourceManager.h" #include "Image.h" -class PNG : public Image +class PNG : public Image, public Resource { public: PNG(std::string path); diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 33a61edf..04754514 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -22,6 +22,7 @@ #include "../Core/Transform.h" #include "imgui/imgui.h" #include "TextPass.h" +#include "Util/CommonFunctions.h" class Renderer : public IRenderer { diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index a20d0395..23bf6360 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -24,23 +24,17 @@ struct SpriteJob : RenderJob ::RawModel::MaterialGroup matGroup = Model->MaterialGroups().front(); TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0; - if (cSprite["DiffuseTexture"]) { - DiffuseTexture = ResourceManager::Load(cSprite["DiffuseTexture"]); - } else { - DiffuseTexture = nullptr; - } - if (cSprite["GlowMap"]) { - IncandescenceTexture = ResourceManager::Load(cSprite["GlowMap"]); - } else { - IncandescenceTexture = nullptr; - } + DiffuseTexture = CommonFunctions::LoadTexture(cSprite["DiffuseTexture"], true); + + IncandescenceTexture = CommonFunctions::LoadTexture(cSprite["GlowMap"], true); + StartIndex = matGroup.StartIndex; EndIndex = matGroup.EndIndex; Matrix = matrix; Color = cSprite["Color"]; Entity = cSprite.EntityID; - glm::vec3 abspos = Transform::AbsolutePosition(world, cSprite.EntityID); - glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1)); + Position = Transform::AbsolutePosition(world, cSprite.EntityID); + glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1)); Depth = viewpos.z; World = world; @@ -58,6 +52,7 @@ struct SpriteJob : RenderJob const Texture* IncandescenceTexture; float Shininess = 0.f; glm::vec4 Color; + glm::vec3 Position; const ::Model* Model = nullptr; unsigned int StartIndex = 0; unsigned int EndIndex = 0; diff --git a/include/Engine/Rendering/Util/CommonFunctions.h b/include/Engine/Rendering/Util/CommonFunctions.h index b262568c..e178f52d 100644 --- a/include/Engine/Rendering/Util/CommonFunctions.h +++ b/include/Engine/Rendering/Util/CommonFunctions.h @@ -4,14 +4,11 @@ #include "../../Common.h" #include "../../OpenGL.h" #include "../../GLM.h" +#include "../Texture.h" -class CommonFuntions -{ -public: - CommonFuntions() = delete; - -private: - +namespace CommonFunctions +{ +Texture* LoadTexture(std::string path, bool threaded); }; #endif \ No newline at end of file diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index e057cf38..23ebb4a5 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -40,7 +40,7 @@ - + @@ -188,7 +188,7 @@ - + @@ -683,7 +683,7 @@ - + @@ -730,7 +730,7 @@ - + @@ -790,7 +790,7 @@ - + @@ -837,7 +837,7 @@ - + @@ -883,7 +883,7 @@ - + @@ -930,7 +930,7 @@ - + @@ -977,7 +977,7 @@ - + @@ -1374,7 +1374,7 @@ - + @@ -1383,7 +1383,7 @@ true - 0.75008034908941568 + 0.75102457088592522 3.7999999523162842 true @@ -1430,7 +1430,7 @@ - + @@ -1439,7 +1439,7 @@ - 1.1999860997035228 + 1.2009303215000324 Models/Assault.mesh @@ -1482,7 +1482,7 @@ - + @@ -1497,7 +1497,7 @@ true - 0.68343188336345406 + 0.68437610515996361 true @@ -1553,6 +1553,50 @@ + + + + + + + + + + + + Textures/FoliageDiff.png + Textures/DefenderGunBlueIncd.png + + + + + + + + + Textures/FoliageDiff.png + Textures/AssaultWeaponBlueGlowMap.png + + + + + + + + + + + Textures/FoliageDiff.png + Textures/GlowTest.png + + + + + + + + + diff --git a/resources/Shaders/Sprite.vert.glsl b/resources/Shaders/Sprite.vert.glsl index e910a26a..c09d745b 100644 --- a/resources/Shaders/Sprite.vert.glsl +++ b/resources/Shaders/Sprite.vert.glsl @@ -16,7 +16,8 @@ out VertexData{ void main() { - gl_Position = P * M * vec4(Position, 1.0); + + gl_Position = P * V * M * vec4(Position, 1.0); Output.Position = Position; Output.TextureCoordinate = TextureCoords; diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 5d8b2359..2c9e47b4 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -13,7 +13,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer) void DrawBloomPass::InitializeTextures() { - m_WhiteTexture = ResourceManager::Load("Textures/Core/White.png"); + m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false); } void DrawBloomPass::InitializeShaderPrograms() diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index e5919fbe..98f17835 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -11,10 +11,11 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling void DrawFinalPass::InitializeTextures() { - m_WhiteTexture = ResourceManager::Load("Textures/Core/White.png"); - m_BlackTexture = ResourceManager::Load("Textures/Core/Black.png"); - m_NeutralNormalTexture = ResourceManager::Load("Textures/Core/NeutralNormalMap.png"); - m_GreyTexture = ResourceManager::Load("Textures/Core/Grey.png"); + m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false); + m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false); + m_NeutralNormalTexture = CommonFunctions::LoadTexture("Textures/Core/NeutralNormalMap.png", false); + m_GreyTexture = CommonFunctions::LoadTexture("Textures/Core/Grey.png", false); + m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false); } void DrawFinalPass::InitializeFrameBuffers() @@ -56,7 +57,7 @@ void DrawFinalPass::InitializeShaderPrograms() m_ExplosionEffectProgram->Link(); GLERROR("Creating explosion program"); - m_SpriteProgram = ResourceManager::Load("#m_SpriteProgram"); + m_SpriteProgram = ResourceManager::Load("#SpriteProgram"); m_SpriteProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/Sprite.vert.glsl"))); m_SpriteProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/Sprite.frag.glsl"))); m_SpriteProgram->Compile(); @@ -222,10 +223,12 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend for(auto& job : jobs) { auto spriteJob = std::dynamic_pointer_cast(job); - if(spriteJob) { + if (spriteJob) { + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix)); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position())); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor)); glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage); @@ -234,7 +237,7 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend if (spriteJob->DiffuseTexture != nullptr) { glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture); } else { - glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture); } glActiveTexture(GL_TEXTURE1); diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index cf4923a3..82dd71af 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -7,16 +7,16 @@ Model::Model(std::string fileName) for (auto& group : m_RawModel->MaterialGroups) { if (!group.TexturePath.empty()) { - group.Texture = std::shared_ptr(ResourceManager::Load(group.TexturePath)); + group.Texture = std::shared_ptr(CommonFunctions::LoadTexture(group.TexturePath, false)); } if (!group.NormalMapPath.empty()) { - group.NormalMap = std::shared_ptr(ResourceManager::Load(group.NormalMapPath)); + group.NormalMap = std::shared_ptr(CommonFunctions::LoadTexture(group.NormalMapPath, false)); } if (!group.SpecularMapPath.empty()) { - group.SpecularMap = std::shared_ptr(ResourceManager::Load(group.SpecularMapPath)); + group.SpecularMap = std::shared_ptr(CommonFunctions::LoadTexture(group.SpecularMapPath, false)); } if (!group.IncandescenceMapPath.empty()) { - group.IncandescenceMap = std::shared_ptr(ResourceManager::Load(group.IncandescenceMapPath)); + group.IncandescenceMap = std::shared_ptr(CommonFunctions::LoadTexture(group.IncandescenceMapPath, false)); } } diff --git a/src/Engine/Rendering/PNG.cpp b/src/Engine/Rendering/PNG.cpp index 7ffd5c20..409da9b1 100644 --- a/src/Engine/Rendering/PNG.cpp +++ b/src/Engine/Rendering/PNG.cpp @@ -4,40 +4,35 @@ PNG::PNG(std::string path) { FILE* file = fopen(path.c_str(), "rb"); if (!file) { - LOG_ERROR("Failed to open texture file \"%s\": %s", path.c_str(), const_cast(strerror(errno))); - return; + throw Resource::FailedLoadingException("Failed to open texture file."); } png_byte header[8]; fread(header, 1, 8, file); bool isPNG = !png_sig_cmp(header, 0, 8); if (!isPNG) { - LOG_ERROR("Failed to load texture file \"%s\": File isn't PNG", path.c_str()); fclose(file); - return; + throw Resource::FailedLoadingException("File is not PNG."); } // Initialize libpng png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, (png_error_ptr)&PNG::pngErrorFunction, (png_error_ptr)&PNG::pngErrorFunction); if (!png_ptr) { - LOG_ERROR("libpng: Failed to initialze png_struct"); png_destroy_read_struct(&png_ptr, nullptr, nullptr); fclose(file); - return; + throw Resource::FailedLoadingException("Failed to initialze png_struct."); } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { - LOG_ERROR("libpng: Failed to initialze png_info"); png_destroy_read_struct(&png_ptr, nullptr, nullptr); fclose(file); - return; + throw Resource::FailedLoadingException("Failed to initialze png_info."); } png_infop info_end_ptr = png_create_info_struct(png_ptr); if (!info_end_ptr) { - LOG_ERROR("libpng: Failed to initialze second png_info"); png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); fclose(file); - return; + throw Resource::FailedLoadingException("Failed to initialze second png_info."); } png_init_io(png_ptr, file); @@ -51,8 +46,8 @@ PNG::PNG(std::string path) unsigned int width, height; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL); if (bit_depth != 8) { - LOG_ERROR("libpng: Unsupported bit depth \"%i\" of image \"%s\", must be 8", bit_depth, path.c_str()); - return; + throw Resource::FailedLoadingException("Unsupported bit depth. Must be 8"); + } switch (color_type) { case PNG_COLOR_TYPE_RGB: @@ -60,8 +55,7 @@ PNG::PNG(std::string path) Format = Image::ImageFormat::RGBA; break; default: - LOG_ERROR("libpng: Unsupported color format \"%i\" of image \"%s\"", color_type, path.c_str()); - return; + throw Resource::FailedLoadingException("Unsupported color format."); } // Convert RGB to RGBA, since DirectX rather treat them all the same way diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index a63e02a0..c0e4d07c 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -106,16 +106,21 @@ void Renderer::Draw(RenderFrame& frame) for (auto scene : frame.RenderScenes){ SortRenderJobsByDepth(*scene); + GLERROR("SortByDepth"); m_PickingPass->Draw(*scene); + GLERROR("Drawing pickingpass"); m_LightCullingPass->GenerateNewFrustum(*scene); + GLERROR("Generate frustums"); m_LightCullingPass->FillLightList(*scene); + GLERROR("Filling light list"); m_LightCullingPass->CullLights(*scene); + GLERROR("LightCulling"); m_DrawFinalPass->Draw(*scene); + GLERROR("Draw Geometry+Light"); //m_DrawScenePass->Draw(*scene); - GLERROR("Renderer::Draw m_DrawScenePass->Draw"); - m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer()); + GLERROR("Draw Text"); } m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture()); @@ -136,7 +141,8 @@ void Renderer::Draw(RenderFrame& frame) } m_ImGuiRenderPass->Draw(); - glfwSwapBuffers(m_Window); + GLERROR("Imgui draw"); + glfwSwapBuffers(m_Window); } PickData Renderer::Pick(glm::vec2 screenCoord) @@ -146,8 +152,8 @@ PickData Renderer::Pick(glm::vec2 screenCoord) void Renderer::InitializeTextures() { - m_ErrorTexture = ResourceManager::Load("Textures/Core/ErrorTexture.png"); - m_WhiteTexture = ResourceManager::Load("Textures/Core/White.png"); + m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false); + m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false); } @@ -155,6 +161,7 @@ void Renderer::SortRenderJobsByDepth(RenderScene &scene) { //Sort all forward jobs so transparency is good. scene.TransparentObjects.sort(Renderer::DepthSort); + scene.SpriteJobs.sort(Renderer::DepthSort); } void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) diff --git a/src/Engine/Rendering/Texture.cpp b/src/Engine/Rendering/Texture.cpp index 492b35be..a4b2d4c9 100644 --- a/src/Engine/Rendering/Texture.cpp +++ b/src/Engine/Rendering/Texture.cpp @@ -2,24 +2,25 @@ Texture::Texture(std::string path) { + PNG* img = ResourceManager::Load(path); //TODO: Make this threaded. Catch exeptions in all other load places. - PNG image(path); + //PNG image(path); - if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) { - //image = PNG("Textures/Core/ErrorTexture.png"); - return; // Temporary fix to remove crash - /* - if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) { - LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed."); - return; - }*/ - } + //if (img->Width == 0 && img->Height == 0 || img->Format == Image::ImageFormat::Unknown) { + // //image = PNG("Textures/Core/ErrorTexture.png"); + // //return; // Temporary fix to remove crash - this->Width = image.Width; - this->Height = image.Height; + // if (img->Width == 0 && img->Height == 0 || img->Format == Image::ImageFormat::Unknown) { + // LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed."); + // return; + // } + //} + + this->Width = img->Width; + this->Height = img->Height; GLint format; - switch (image.Format) { + switch (img->Format) { case Image::ImageFormat::RGB: format = GL_RGB; break; @@ -32,7 +33,7 @@ Texture::Texture(std::string path) glGenTextures(1, &m_Texture); glBindTexture(GL_TEXTURE_2D, m_Texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, format, image.Width, image.Height, 0, format, GL_UNSIGNED_BYTE, image.Data); + glTexImage2D(GL_TEXTURE_2D, 0, format, img->Width, img->Height, 0, format, GL_UNSIGNED_BYTE, img->Data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); diff --git a/src/Engine/Rendering/Util/CommonFunctions.cpp b/src/Engine/Rendering/Util/CommonFunctions.cpp index 3c81de66..382cb790 100644 --- a/src/Engine/Rendering/Util/CommonFunctions.cpp +++ b/src/Engine/Rendering/Util/CommonFunctions.cpp @@ -1,2 +1,19 @@ #include "Rendering/Util/CommonFunctions.h" +Texture* CommonFunctions::LoadTexture(std::string path, bool threaded) +{ + Texture* img; + try { + if(threaded) { + img = ResourceManager::Load(path); + } else { + img = ResourceManager::Load(path); + } + } catch (const Resource::StillLoadingException&) { + img = ResourceManager::Load("Textures/Core/ErrorTexture.png"); + } catch (const std::exception&) { + img = nullptr; + } + + return img; +} diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 0cc41a73..780842a6 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -25,6 +25,7 @@ Game::Game(int argc, char* argv[]) ResourceManager::RegisterType("Model"); ResourceManager::RegisterType("RawModel"); ResourceManager::RegisterType("Texture"); + ResourceManager::RegisterType("Png"); ResourceManager::RegisterType("ShaderProgram"); ResourceManager::RegisterType("EntityFile"); ResourceManager::RegisterType("FontFile"); From f5de267f2552d3bc6ae8211fd2c77b6fe3862867 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 10 Feb 2016 20:58:10 +0100 Subject: [PATCH 3/8] Merge fixes and CapturePointHUD component skeleton added. --- include/Engine/Rendering/RawModelCustom.h | 2 +- include/Engine/Rendering/RenderQueue.h | 5 +- include/Engine/Rendering/SpriteJob.h | 8 +- resources/Schema/Components.xsd | 1 + .../Schema/Components/CapturePointHUD.xml | 2 + .../Schema/Components/CapturePointHUD.xsd | 6 + .../Schema/Entities/QualityAssurance.xml | 104 ++++++++++-------- resources/Schema/Types/Entity.xsd | 1 + src/Engine/Rendering/DrawFinalPass.cpp | 2 +- src/Engine/Rendering/Model.cpp | 47 ++------ src/Engine/Rendering/RenderSystem.cpp | 2 +- src/Engine/Rendering/Renderer.cpp | 2 +- 12 files changed, 87 insertions(+), 95 deletions(-) create mode 100644 resources/Schema/Components/CapturePointHUD.xml create mode 100644 resources/Schema/Components/CapturePointHUD.xsd diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index cf21fb6d..ebf8da2b 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -50,7 +50,7 @@ public: struct TextureProperties { std::string TexturePath; glm::vec2 UVRepeat; - std::shared_ptr<::Texture> Texture; + Texture* Texture; }; struct MaterialBasic diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 21802e05..647adab8 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -26,8 +26,7 @@ struct RenderScene std::list> OpaqueShieldedObjects; std::list> TransparentShieldedObjects; std::list> ShieldObjects; - std::list> SpriteJobs; - + std::list> SpriteJob; std::list> PointLight; std::list> Text; std::list> DirectionalLight; @@ -44,7 +43,7 @@ struct RenderScene Jobs.OpaqueShieldedObjects.clear(); Jobs.TransparentShieldedObjects.clear(); Jobs.ShieldObjects.clear(); - SpriteJobs.clear(); + Jobs.SpriteJob.clear(); Jobs.DirectionalLight.clear(); } }; diff --git a/include/Engine/Rendering/SpriteJob.h b/include/Engine/Rendering/SpriteJob.h index 23bf6360..2708ab0e 100644 --- a/include/Engine/Rendering/SpriteJob.h +++ b/include/Engine/Rendering/SpriteJob.h @@ -21,15 +21,15 @@ struct SpriteJob : RenderJob : RenderJob() { Model = ResourceManager::Load<::Model>("Models/Core/UnitQuad.mesh"); - ::RawModel::MaterialGroup matGroup = Model->MaterialGroups().front(); - TextureID = (matGroup.Texture) ? matGroup.Texture->ResourceID : 0; + ::RawModel::MaterialProperties matProp = Model->MaterialGroups().front(); + TextureID = 0; DiffuseTexture = CommonFunctions::LoadTexture(cSprite["DiffuseTexture"], true); IncandescenceTexture = CommonFunctions::LoadTexture(cSprite["GlowMap"], true); - StartIndex = matGroup.StartIndex; - EndIndex = matGroup.EndIndex; + StartIndex = matProp.material->StartIndex; + EndIndex = matProp.material->EndIndex; Matrix = matrix; Color = cSprite["Color"]; Entity = cSprite.EntityID; diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 9487a7ad..bcc3fbdf 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -37,4 +37,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointHUD.xml b/resources/Schema/Components/CapturePointHUD.xml new file mode 100644 index 00000000..c024411c --- /dev/null +++ b/resources/Schema/Components/CapturePointHUD.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointHUD.xsd b/resources/Schema/Components/CapturePointHUD.xsd new file mode 100644 index 00000000..dfdef822 --- /dev/null +++ b/resources/Schema/Components/CapturePointHUD.xsd @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index 7a69ed32..c234f93a 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -40,7 +40,7 @@ - + @@ -120,11 +120,7 @@ - - Run - - 1 - + Models/Characters/Assault/AssaultAnimated.mesh @@ -136,11 +132,7 @@ - - Walk - - 1 - + Models/Characters/Assault/AssaultAnimated.mesh @@ -188,17 +180,13 @@ - + - - Run - - 1 - + Models/Characters/Assault/AssaultAnimated.mesh @@ -683,7 +671,7 @@ - + @@ -730,7 +718,7 @@ - + @@ -790,7 +778,7 @@ - + @@ -837,7 +825,7 @@ - + @@ -883,7 +871,7 @@ - + @@ -930,7 +918,7 @@ - + @@ -977,7 +965,7 @@ - + @@ -1390,7 +1378,7 @@ - + @@ -1399,7 +1387,7 @@ true - 0.75102457088592522 + 0.75134174339666815 3.7999999523162842 true @@ -1446,7 +1434,7 @@ - + @@ -1455,7 +1443,7 @@ - 1.2009303215000324 + 1.2012474940107754 Models/Characters/Assault/AssaultTPose.mesh @@ -1498,22 +1486,18 @@ - + - - Walk - - 1 - + true - 0.68437610515996361 + 0.68469327767070653 true @@ -1558,7 +1542,7 @@ - + @@ -1568,7 +1552,7 @@ true - 0.95047462600732735 + 0.95079179851807027 10 3 @@ -1616,7 +1600,7 @@ - + @@ -1626,7 +1610,7 @@ true - 1.350502887383392 + 1.3508200598941349 true 5 true @@ -1807,7 +1791,7 @@ true - 1.3671759474185377 + 1.3674931199292806 3.7999999523162842 true @@ -1850,11 +1834,7 @@ - - Hold Pos - - 1 - + Models/AssaultAnimated.mesh @@ -1916,7 +1896,8 @@ - Models/BushAlive.mesh + Models/Props/Flora/AliveBush.mesh + true @@ -1943,6 +1924,37 @@ + + + + + + + + + + + + Textures/Props/FoliageDiff.png + + + + + + + + + + Textures/Props/FoliageDiff.png + + + + + + + + + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 16366a67..8c9f6bcc 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -41,6 +41,7 @@ + diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 2e1e717e..e5e046dc 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -193,7 +193,7 @@ void DrawFinalPass::Draw(RenderScene& scene) GLERROR("OpaqueObjects"); DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene); GLERROR("TransparentObjects"); - DrawSprites(scene.SpriteJobs, scene); + DrawSprites(scene.Jobs.SpriteJob, scene); GLERROR("SpriteJobs"); //DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle()); diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index 009e4abe..ce6eab8c 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -10,60 +10,31 @@ Model::Model(std::string fileName) case RawModel::MaterialType::SingleTextures: { RawModel::MaterialSingleTextures* materialSingleTexture = static_cast(materialProperty.material); - if (!materialSingleTexture->ColorMap.TexturePath.empty()) { - materialSingleTexture->ColorMap.Texture = std::shared_ptr(ResourceManager::LoadfixTexture>(materialSingleTexture->ColorMap.TexturePath)); - } - if (!materialSingleTexture->NormalMap.TexturePath.empty()) { - materialSingleTexture->NormalMap.Texture = std::shared_ptr(ResourceManager::LoadfixTexture>(materialSingleTexture->NormalMap.TexturePath)); - } - if (!materialSingleTexture->SpecularMap.TexturePath.empty()) { - materialSingleTexture->SpecularMap.Texture = std::shared_ptr(ResourceManager::LoadfixTexture>(materialSingleTexture->SpecularMap.TexturePath)); - } - if (!materialSingleTexture->IncandescenceMap.TexturePath.empty()) { - materialSingleTexture->IncandescenceMap.Texture = std::shared_ptr(ResourceManager::LoadfixTexture>(materialSingleTexture->IncandescenceMap.TexturePath)); - } + materialSingleTexture->ColorMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->ColorMap.TexturePath, false); + materialSingleTexture->NormalMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->NormalMap.TexturePath, false); + materialSingleTexture->SpecularMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->SpecularMap.TexturePath, false); + materialSingleTexture->IncandescenceMap.Texture = CommonFunctions::LoadTexture(materialSingleTexture->IncandescenceMap.TexturePath, false); } break; case RawModel::MaterialType::SplatMapping: { RawModel::MaterialSplatMapping* materialSplatMapping = static_cast(materialProperty.material); - if (!materialSplatMapping->SplatMap.TexturePath.empty()) { - materialSplatMapping->SplatMap.Texture = std::shared_ptr(ResourceManager::Load(materialSplatMapping->SplatMap.TexturePath)); - } + materialSplatMapping->SplatMap.Texture = CommonFunctions::LoadTexture(materialSplatMapping->SplatMap.TexturePath, false); for (auto& texture : materialSplatMapping->ColorMaps) { - if (!texture.TexturePath.empty()) { - texture.Texture = std::shared_ptr(ResourceManager::Load(texture.TexturePath)); - } - else { - texture.Texture = nullptr; - } + texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false); } for (auto& texture : materialSplatMapping->NormalMaps) { - if (!texture.TexturePath.empty()) { - texture.Texture = std::shared_ptr(ResourceManager::Load(texture.TexturePath)); - } else { - texture.Texture = nullptr; - } + texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false); } for (auto& texture : materialSplatMapping->SpecularMaps) { - if (!texture.TexturePath.empty()) { - texture.Texture = std::shared_ptr(ResourceManager::Load(texture.TexturePath)); - } - else { - texture.Texture = nullptr; - } + texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false); } for (auto& texture : materialSplatMapping->IncandescenceMaps) { - if (!texture.TexturePath.empty()) { - texture.Texture = std::shared_ptr(ResourceManager::Load(texture.TexturePath)); - } - else { - texture.Texture = nullptr; - } + texture.Texture = CommonFunctions::LoadTexture(texture.TexturePath, false); } } break; diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index eb81818e..173afc95 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -346,7 +346,7 @@ void RenderSystem::Update(double dt) fillPointLights(scene.Jobs.PointLight, m_World); //TODO: Make sure all objects needed are also sorted. scene.Jobs.OpaqueObjects.sort(); - fillSprites(scene.SpriteJobs, m_World); + fillSprites(scene.Jobs.SpriteJob, m_World); fillDirectionalLights(scene.Jobs.DirectionalLight, m_World); fillText(scene.Jobs.Text, m_World); m_RenderFrame->Add(scene); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index f02ca4d5..6f53eeda 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -167,7 +167,7 @@ void Renderer::SortRenderJobsByDepth(RenderScene &scene) { //Sort all forward jobs so transparency is good. scene.Jobs.TransparentObjects.sort(Renderer::DepthSort); - scene.SpriteJobs.sort(Renderer::DepthSort); + scene.Jobs.SpriteJob.sort(Renderer::DepthSort); } void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) From 64a2354b24ee1e0304d00831e967ca12b4ad944c Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 10 Feb 2016 22:22:09 +0100 Subject: [PATCH 4/8] WIP with CapturePointHUDSystem --- include/Game/Systems/CapturePointHUDSystem.h | 55 ++++ resources/Schema/Components.xsd | 2 +- .../Schema/Components/CapturePointHUD.xml | 5 +- .../Schema/Components/CapturePointHUD.xsd | 18 ++ .../Entities/CapturePointHUDHexagon.xml | 34 +++ .../Schema/Entities/QualityAssurance.xml | 208 +++++++++++++-- src/Game/Systems/CapturePointHUDSystem.cpp | 243 ++++++++++++++++++ 7 files changed, 542 insertions(+), 23 deletions(-) create mode 100644 include/Game/Systems/CapturePointHUDSystem.h create mode 100644 resources/Schema/Entities/CapturePointHUDHexagon.xml create mode 100644 src/Game/Systems/CapturePointHUDSystem.cpp diff --git a/include/Game/Systems/CapturePointHUDSystem.h b/include/Game/Systems/CapturePointHUDSystem.h new file mode 100644 index 00000000..18c32c76 --- /dev/null +++ b/include/Game/Systems/CapturePointHUDSystem.h @@ -0,0 +1,55 @@ +#ifndef CapturePointSystem_h__ +#define CapturePointSystem_h__ + +#include +#include + +#include "Common.h" +#include "Core/System.h" +#include "Engine/Collision/ETrigger.h" +#include "Core/ECaptured.h" +#include "Core/EWin.h" + +#include +#include + +class CapturePointSystem : public PureSystem +{ +public: + //WARNING: on new map, destroy all info in the vectors, as well as reset all variables (just make new?) + CapturePointSystem(World* world, EventBroker* eventBroker); + + //updatecomponent + virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; + +private: + //methods which will take care of specific events + EventRelay m_ETriggerTouch; + bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e); + EventRelay m_ETriggerLeave; + bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); + EventRelay m_ECaptured; + bool CapturePointSystem::OnCaptured(const Events::Captured& e); + + bool m_WinnerWasFound = false; + //need to track these variables for the captureSystem to work as per design! + const int m_NotACapturePoint = 999; + int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint; + int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint; + int m_RedTeamHomeCapturePoint = m_NotACapturePoint; + int m_BlueTeamHomeCapturePoint = m_NotACapturePoint; + + int m_NumberOfCapturePoints = 0; + std::map m_CapturePointNumberToEntityMap; + + //std::vector + + const double m_CaptureTimeToTakeOver = 15.0; + bool m_ResetTimers = false; + + //vectors which will keep track of enter/leave changes + std::vector> m_ETriggerTouchVector; + std::vector> m_ETriggerLeaveVector; +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index bcc3fbdf..bf452eba 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -37,5 +37,5 @@ - + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointHUD.xml b/resources/Schema/Components/CapturePointHUD.xml index c024411c..2943d57b 100644 --- a/resources/Schema/Components/CapturePointHUD.xml +++ b/resources/Schema/Components/CapturePointHUD.xml @@ -1,2 +1,5 @@ - \ No newline at end of file + + 0 + + \ No newline at end of file diff --git a/resources/Schema/Components/CapturePointHUD.xsd b/resources/Schema/Components/CapturePointHUD.xsd index dfdef822..7984fc50 100644 --- a/resources/Schema/Components/CapturePointHUD.xsd +++ b/resources/Schema/Components/CapturePointHUD.xsd @@ -1,6 +1,24 @@ + + + Hud element for tracking capture points. + + + + + + Corresponds to the number on the capture point it should track. + + + + + Specify the team that own this capturePoint. + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/CapturePointHUDHexagon.xml b/resources/Schema/Entities/CapturePointHUDHexagon.xml new file mode 100644 index 00000000..68cf42a7 --- /dev/null +++ b/resources/Schema/Entities/CapturePointHUDHexagon.xml @@ -0,0 +1,34 @@ + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + 0.5 + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index c234f93a..ce6a650e 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -40,7 +40,7 @@ - + @@ -180,7 +180,7 @@ - + @@ -671,7 +671,7 @@ - + @@ -718,7 +718,7 @@ - + @@ -778,7 +778,7 @@ - + @@ -825,7 +825,7 @@ - + @@ -871,7 +871,7 @@ - + @@ -918,7 +918,7 @@ - + @@ -965,7 +965,7 @@ - + @@ -1378,7 +1378,7 @@ - + @@ -1387,7 +1387,7 @@ true - 0.75134174339666815 + 0.75158864645285173 3.7999999523162842 true @@ -1434,7 +1434,7 @@ - + @@ -1443,7 +1443,7 @@ - 1.2012474940107754 + 1.2014943970669589 Models/Characters/Assault/AssaultTPose.mesh @@ -1486,7 +1486,7 @@ - + @@ -1497,7 +1497,7 @@ true - 0.68469327767070653 + 0.68494018072689011 true @@ -1542,7 +1542,7 @@ - + @@ -1552,7 +1552,7 @@ true - 0.95079179851807027 + 0.95103870157425385 10 3 @@ -1600,7 +1600,7 @@ - + @@ -1610,7 +1610,7 @@ true - 1.3508200598941349 + 1.3510669629503185 true 5 true @@ -1791,7 +1791,7 @@ true - 1.3674931199292806 + 1.3677400229854642 3.7999999523162842 true @@ -1936,7 +1936,6 @@ Textures/Props/FoliageDiff.png - @@ -1955,6 +1954,173 @@ + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 2 + + + 0.5 + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 3 + + + 0.5 + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 4 + + + 0.5 + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 1 + + + 0.5 + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + 0.5 + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + diff --git a/src/Game/Systems/CapturePointHUDSystem.cpp b/src/Game/Systems/CapturePointHUDSystem.cpp new file mode 100644 index 00000000..a943e234 --- /dev/null +++ b/src/Game/Systems/CapturePointHUDSystem.cpp @@ -0,0 +1,243 @@ +#include "Systems/CapturePointSystem.h" +#include + +CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker) + : System(world, eventBroker) + , PureSystem("CapturePoint") +{ + //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) + EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); + EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); + EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); +} + +//here all capturepoints will update their component +//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt +void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt) +{ + if (m_WinnerWasFound) { + return; + } + const int capturePointNumber = cCapturePoint["CapturePointNumber"]; + const bool hasTeamComponent = capturePointEntity.HasComponent("Team"); + + //if point doesnt have a teamComponent yet, add one. since: + //what if capture point has no team -> we cant get/use the team enum from it... + if (!hasTeamComponent) { + m_World->AttachComponent(cCapturePoint.EntityID, "Team"); + ComponentWrapper& teamComponent = capturePointEntity["Team"]; + teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator"); + } + ComponentWrapper& teamComponent = capturePointEntity["Team"]; + const int redTeam = (int)teamComponent["Team"].Enum("Red"); + const int blueTeam = (int)teamComponent["Team"].Enum("Blue"); + const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); + + int homePointForTeam = (int)cCapturePoint["HomePointForTeam"]; + if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) { + m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3 + if (homePointForTeam == redTeam) { + m_RedTeamHomeCapturePoint = capturePointNumber; + m_BlueTeamHomeCapturePoint = 0; + } else { + m_BlueTeamHomeCapturePoint = capturePointNumber; + m_RedTeamHomeCapturePoint = 0; + } + } + + //if we havent received all capturepoints yet, just return + if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { + m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); + return; + } + + //we have all capturepoints now - process stuff + int ownedBy = teamComponent["Team"]; + int redTeamPlayersStandingInside = 0; + int blueTeamPlayersStandingInside = 0; + if (capturePointEntity.HasComponent("Model")) { + //Now sets team color to the capturepoint, or white if it is uncaptured. + capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3); + } + + //calculate next possible capturePoint for both teams + std::map nextPossibleCapturePoint; + nextPossibleCapturePoint["Red"] = -1; + nextPossibleCapturePoint["Blue"] = -1; + for (int i = 0; i < m_NumberOfCapturePoints; i++) + { + if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { + continue; + } + ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; + if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) { + nextPossibleCapturePoint["Red"] = i + 1; + } + if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) { + nextPossibleCapturePoint["Blue"] = i + 1; + } + } + for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--) + { + if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { + continue; + } + ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; + if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) { + nextPossibleCapturePoint["Red"] = i - 1; + } + if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) { + nextPossibleCapturePoint["Blue"] = i - 1; + } + } + + //reset timers and reset the bool that triggers this + if (m_ResetTimers) { + for (int i = 0; i < m_NumberOfCapturePoints; i++) + { + ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; + if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] && + (int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) { + capturePoint["CaptureTimer"] = 0.0; + } + } + m_ResetTimers = false; + } + + //colorize next possible capturepoint + if (nextPossibleCapturePoint["Red"] == capturePointNumber) { + capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 0.3); + } + if (nextPossibleCapturePoint["Blue"] == capturePointNumber) { + capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 0.3); + } + + //check how many players are standing inside and are healthy + for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--) + { + auto triggerTouched = m_ETriggerTouchVector[i - 1]; + if (std::get<1>(triggerTouched) == capturePointEntity) { + //some player has touched this - lets figure out: what team, health + EntityWrapper player = std::get<0>(triggerTouched); + //check if its really a player that has triggered the touch + if (!player.HasComponent("Player")) { + //if a non-player has entered the capturePoint, just erase that event and continue + m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1); + continue; + } + bool hasHealthComponent = player.HasComponent("Health"); + if (hasHealthComponent) { + double currentHealth = player["Health"]["Health"]; + //check if player is dead + if ((int)currentHealth == 0) { + continue; + } + } + //check team - spectatorNumber = "no team" + int teamNumber = player["Team"]["Team"]; + if (teamNumber == redTeam) { + redTeamPlayersStandingInside++; + } else if (teamNumber == blueTeam) { + blueTeamPlayersStandingInside++; + } + continue; + } + } + + //create data to be used in option B + //check so this is the next possible capture point for the take-over team and see if only one team is standing inside it + double timerDeltaChange = 0.0; + int currentTeam = 0; + bool canCapture = false; + if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) { + timerDeltaChange = redTeamPlayersStandingInside*dt; + currentTeam = redTeam; + canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber; + } + if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) { + timerDeltaChange = -blueTeamPlayersStandingInside*dt; + currentTeam = blueTeam; + canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber; + } + + if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) { + //A.nobodys standing inside + //do nothing (?) + } else if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside > 0) { + //C.both teams have players inside + //do nothing (?) + } else { + //B. at most one of the teams have players inside + //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly + if (ownedBy != currentTeam && canCapture) { + if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) { + LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently. + } + cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; + } + //if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0 + if ((ownedBy == currentTeam && currentTeam == redTeam && (double)cCapturePoint["CaptureTimer"] < 0.0) || + (ownedBy == currentTeam && currentTeam == blueTeam && (double)cCapturePoint["CaptureTimer"] > 0.0)) { + cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; + } + //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event + if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) { + teamComponent["Team"] = currentTeam; + cCapturePoint["CaptureTimer"] = 0.0; + //publish Captured event + LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently. + Events::Captured e; + e.CapturePointID = cCapturePoint.EntityID; + e.TeamNumberThatCapturedCapturePoint = currentTeam; + m_EventBroker->Publish(e); + //NextPossibleCapturePoint will be calculated in the next update... + } + } + + //check for possible winCondition = check if the homebase is owned by the other team + bool checkForWinner = false; + if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam) + { + checkForWinner = true; + } + if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam) + { + checkForWinner = true; + } + + if (checkForWinner && !m_WinnerWasFound) + { + //publish Win event + Events::Win e; + e.TeamThatWon = ownedBy; + m_EventBroker->Publish(e); + m_WinnerWasFound = true; + } + +} + +bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) +{ + //personEntered = e.Entity, thingEntered = e.Trigger + m_ETriggerTouchVector.push_back(std::make_tuple(e.Entity, e.Trigger)); + return true; +} + +bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e) +{ + for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++) + { + auto triggerTouched = m_ETriggerTouchVector[i]; + if (std::get<0>(triggerTouched) == e.Entity && std::get<1>(triggerTouched) == e.Trigger) { + m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i); + break; + } + } + return true; +} +bool CapturePointSystem::OnCaptured(const Events::Captured& e) +{ + //reset the timers in the next update since a capture has changed the "nextCapturePoint" for 1-2 teams + m_ResetTimers = true; + return true; +} From 447f41dbff935c9521a2e74c594d85b1490b6cd9 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 10 Feb 2016 23:59:13 +0100 Subject: [PATCH 5/8] HUD for capture points now update with Capture point data. --- include/Game/Systems/CapturePointHUDSystem.h | 52 +- resources/Shaders/Sprite.frag.glsl | 5 +- src/Game/Game.cpp | 2 + src/Game/Systems/CapturePointHUDSystem.cpp | 482 ++++++++++--------- 4 files changed, 287 insertions(+), 254 deletions(-) diff --git a/include/Game/Systems/CapturePointHUDSystem.h b/include/Game/Systems/CapturePointHUDSystem.h index 18c32c76..102c52ce 100644 --- a/include/Game/Systems/CapturePointHUDSystem.h +++ b/include/Game/Systems/CapturePointHUDSystem.h @@ -1,55 +1,49 @@ -#ifndef CapturePointSystem_h__ -#define CapturePointSystem_h__ +#ifndef CapturePointHUDSystem_h__ +#define CapturePointHUDSystem_h__ #include #include +#include #include "Common.h" #include "Core/System.h" #include "Engine/Collision/ETrigger.h" -#include "Core/ECaptured.h" -#include "Core/EWin.h" -#include -#include - -class CapturePointSystem : public PureSystem +class CapturePointHUDSystem : public ImpureSystem { public: - //WARNING: on new map, destroy all info in the vectors, as well as reset all variables (just make new?) - CapturePointSystem(World* world, EventBroker* eventBroker); + CapturePointHUDSystem(World* world, EventBroker* eventBroker); - //updatecomponent - virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt) override; + virtual void Update(double dt) override; private: //methods which will take care of specific events - EventRelay m_ETriggerTouch; + /* EventRelay m_ETriggerTouch; bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e); EventRelay m_ETriggerLeave; bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e); EventRelay m_ECaptured; - bool CapturePointSystem::OnCaptured(const Events::Captured& e); + bool CapturePointSystem::OnCaptured(const Events::Captured& e);*/ - bool m_WinnerWasFound = false; - //need to track these variables for the captureSystem to work as per design! - const int m_NotACapturePoint = 999; - int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint; - int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint; - int m_RedTeamHomeCapturePoint = m_NotACapturePoint; - int m_BlueTeamHomeCapturePoint = m_NotACapturePoint; + //bool m_WinnerWasFound = false; + ////need to track these variables for the captureSystem to work as per design! + //const int m_NotACapturePoint = 999; + //int m_RedTeamNextPossibleCapturePoint = m_NotACapturePoint; + //int m_BlueTeamNextPossibleCapturePoint = m_NotACapturePoint; + //int m_RedTeamHomeCapturePoint = m_NotACapturePoint; + //int m_BlueTeamHomeCapturePoint = m_NotACapturePoint; - int m_NumberOfCapturePoints = 0; - std::map m_CapturePointNumberToEntityMap; + //int m_NumberOfCapturePoints = 0; + //std::map m_CapturePointNumberToEntityMap; - //std::vector + ////std::vector - const double m_CaptureTimeToTakeOver = 15.0; - bool m_ResetTimers = false; + //const double m_CaptureTimeToTakeOver = 15.0; + //bool m_ResetTimers = false; - //vectors which will keep track of enter/leave changes - std::vector> m_ETriggerTouchVector; - std::vector> m_ETriggerLeaveVector; + ////vectors which will keep track of enter/leave changes + //std::vector> m_ETriggerTouchVector; + //std::vector> m_ETriggerLeaveVector; }; #endif \ No newline at end of file diff --git a/resources/Shaders/Sprite.frag.glsl b/resources/Shaders/Sprite.frag.glsl index c391322d..a1ff3025 100644 --- a/resources/Shaders/Sprite.frag.glsl +++ b/resources/Shaders/Sprite.frag.glsl @@ -30,12 +30,11 @@ void main() float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0; if(pos <= FillPercentage) { - color_result += FillColor; + color_result = FillColor*diffuseTexel.a; } sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); - color_result += glowTexel*3; - bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0); + bloomColor = vec4(clamp((glowTexel.xyz*3) - 1.0, 0, 100), 1.0); } diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 002efe26..b13cbda2 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -12,6 +12,7 @@ #include "Systems/PlayerDeathSystem.h" #include "Core/EntityFileWriter.h" #include "Game/Systems/CapturePointSystem.h" +#include "Game/Systems/CapturePointHUDSystem.h" #include "Game/Systems/PickupSpawnSystem.h" #include "Game/Systems/WeaponSystem.h" #include "Rendering/AnimationSystem.h" @@ -103,6 +104,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); // Populate Octree with collidables ++updateOrderLevel; diff --git a/src/Game/Systems/CapturePointHUDSystem.cpp b/src/Game/Systems/CapturePointHUDSystem.cpp index a943e234..5c4c2b60 100644 --- a/src/Game/Systems/CapturePointHUDSystem.cpp +++ b/src/Game/Systems/CapturePointHUDSystem.cpp @@ -1,243 +1,281 @@ -#include "Systems/CapturePointSystem.h" -#include +#include "Systems/CapturePointHUDSystem.h" -CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker) +CapturePointHUDSystem::CapturePointHUDSystem(World* world, EventBroker* eventBroker) : System(world, eventBroker) - , PureSystem("CapturePoint") + , ImpureSystem() { //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker) - EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); - EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); - EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); + //EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &CapturePointSystem::OnTriggerTouch); + //EVENT_SUBSCRIBE_MEMBER(m_ETriggerLeave, &CapturePointSystem::OnTriggerLeave); + //EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &CapturePointSystem::OnCaptured); } -//here all capturepoints will update their component -//NOTE: needs to run each frame, since we're possibly modifying the captureTimer for the capturePoints by dt -void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt) + +void CapturePointHUDSystem::Update(double dt) { - if (m_WinnerWasFound) { - return; - } - const int capturePointNumber = cCapturePoint["CapturePointNumber"]; - const bool hasTeamComponent = capturePointEntity.HasComponent("Team"); + bool LoadCheck = false; + int redTeam; + int blueTeam; + int spectatorTeam; - //if point doesnt have a teamComponent yet, add one. since: - //what if capture point has no team -> we cant get/use the team enum from it... - if (!hasTeamComponent) { - m_World->AttachComponent(cCapturePoint.EntityID, "Team"); - ComponentWrapper& teamComponent = capturePointEntity["Team"]; - teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator"); - } - ComponentWrapper& teamComponent = capturePointEntity["Team"]; - const int redTeam = (int)teamComponent["Team"].Enum("Red"); - const int blueTeam = (int)teamComponent["Team"].Enum("Blue"); - const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); + auto CapturePointHUDElements = m_World->GetComponents("CapturePointHUD"); + auto CapturePoints = m_World->GetComponents("CapturePoint"); - int homePointForTeam = (int)cCapturePoint["HomePointForTeam"]; - if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) { - m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3 - if (homePointForTeam == redTeam) { - m_RedTeamHomeCapturePoint = capturePointNumber; - m_BlueTeamHomeCapturePoint = 0; - } else { - m_BlueTeamHomeCapturePoint = capturePointNumber; - m_RedTeamHomeCapturePoint = 0; - } - } + for(auto& cCapturePointHUD : *CapturePointHUDElements) { + int HUD_ID = cCapturePointHUD["CapturePointNumber"]; + EntityWrapper entityHUD = EntityWrapper(m_World, cCapturePointHUD.EntityID); + EntityWrapper entityHUDparent = entityHUD.Parent(); - //if we havent received all capturepoints yet, just return - if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { - m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); - return; - } + for(auto& cCapturePoint : *CapturePoints) { + EntityWrapper entityCP = EntityWrapper(m_World, cCapturePoint.EntityID); - //we have all capturepoints now - process stuff - int ownedBy = teamComponent["Team"]; - int redTeamPlayersStandingInside = 0; - int blueTeamPlayersStandingInside = 0; - if (capturePointEntity.HasComponent("Model")) { - //Now sets team color to the capturepoint, or white if it is uncaptured. - capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3); - } - - //calculate next possible capturePoint for both teams - std::map nextPossibleCapturePoint; - nextPossibleCapturePoint["Red"] = -1; - nextPossibleCapturePoint["Blue"] = -1; - for (int i = 0; i < m_NumberOfCapturePoints; i++) - { - if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { - continue; - } - ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; - if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) { - nextPossibleCapturePoint["Red"] = i + 1; - } - if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) { - nextPossibleCapturePoint["Blue"] = i + 1; - } - } - for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--) - { - if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { - continue; - } - ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; - if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) { - nextPossibleCapturePoint["Red"] = i - 1; - } - if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) { - nextPossibleCapturePoint["Blue"] = i - 1; - } - } - - //reset timers and reset the bool that triggers this - if (m_ResetTimers) { - for (int i = 0; i < m_NumberOfCapturePoints; i++) - { - ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; - if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] && - (int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) { - capturePoint["CaptureTimer"] = 0.0; - } - } - m_ResetTimers = false; - } - - //colorize next possible capturepoint - if (nextPossibleCapturePoint["Red"] == capturePointNumber) { - capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 0.3); - } - if (nextPossibleCapturePoint["Blue"] == capturePointNumber) { - capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 0.3); - } - - //check how many players are standing inside and are healthy - for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--) - { - auto triggerTouched = m_ETriggerTouchVector[i - 1]; - if (std::get<1>(triggerTouched) == capturePointEntity) { - //some player has touched this - lets figure out: what team, health - EntityWrapper player = std::get<0>(triggerTouched); - //check if its really a player that has triggered the touch - if (!player.HasComponent("Player")) { - //if a non-player has entered the capturePoint, just erase that event and continue - m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1); - continue; - } - bool hasHealthComponent = player.HasComponent("Health"); - if (hasHealthComponent) { - double currentHealth = player["Health"]["Health"]; - //check if player is dead - if ((int)currentHealth == 0) { - continue; + //Check if the HUD corresponds to the Capture Point Number + if (HUD_ID == (int)entityCP["CapturePoint"]["CapturePointNumber"]) { + ComponentWrapper& teamComponent = entityCP["Team"]; + if (!LoadCheck) { + redTeam = (int)teamComponent["Team"].Enum("Red"); + blueTeam = (int)teamComponent["Team"].Enum("Blue"); + spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); } + //Color hud with team color + auto capturePointTeam = (int)teamComponent["Team"]; + entityHUDparent["Sprite"]["Color"] = capturePointTeam == blueTeam ? glm::vec4(0, 0.2f, 1, 0.7) : capturePointTeam == redTeam ? glm::vec4(1, 0.2f, 0, 0.7) : glm::vec4(1, 1, 1, 0.3); + + //Progress is scaled with time + double currentCaptureTime = (double)entityCP["CapturePoint"]["CaptureTimer"]; + double progress = glm::abs(currentCaptureTime)/15.0; + int currentCapturingTeam = currentCaptureTime > 0 ? redTeam : currentCaptureTime < 0 ? blueTeam : spectatorTeam; + ((glm::vec3&)entityHUD["Transform"]["Orientation"]).z = currentCapturingTeam == redTeam ? glm::half_pi()+glm::pi() : glm::half_pi(); + glm::vec4 fillColor = currentCapturingTeam == redTeam ? glm::vec4(1, 0.2f, 0, 0.7) : glm::vec4(0, 0.2f, 1, 0.7); + entityHUD["Fill"]["Color"] = fillColor; + entityHUD["Fill"]["Percentage"] = progress; } - //check team - spectatorNumber = "no team" - int teamNumber = player["Team"]["Team"]; - if (teamNumber == redTeam) { - redTeamPlayersStandingInside++; - } else if (teamNumber == blueTeam) { - blueTeamPlayersStandingInside++; - } - continue; } } - //create data to be used in option B - //check so this is the next possible capture point for the take-over team and see if only one team is standing inside it - double timerDeltaChange = 0.0; - int currentTeam = 0; - bool canCapture = false; - if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) { - timerDeltaChange = redTeamPlayersStandingInside*dt; - currentTeam = redTeam; - canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber; - } - if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) { - timerDeltaChange = -blueTeamPlayersStandingInside*dt; - currentTeam = blueTeam; - canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber; - } + //if (m_WinnerWasFound) { + // return; + //} + //const int capturePointNumber = cCapturePoint["CapturePointNumber"]; + //const bool hasTeamComponent = capturePointEntity.HasComponent("Team"); - if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) { - //A.nobodys standing inside - //do nothing (?) - } else if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside > 0) { - //C.both teams have players inside - //do nothing (?) - } else { - //B. at most one of the teams have players inside - //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly - if (ownedBy != currentTeam && canCapture) { - if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) { - LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently. - } - cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; - } - //if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0 - if ((ownedBy == currentTeam && currentTeam == redTeam && (double)cCapturePoint["CaptureTimer"] < 0.0) || - (ownedBy == currentTeam && currentTeam == blueTeam && (double)cCapturePoint["CaptureTimer"] > 0.0)) { - cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; - } - //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event - if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) { - teamComponent["Team"] = currentTeam; - cCapturePoint["CaptureTimer"] = 0.0; - //publish Captured event - LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently. - Events::Captured e; - e.CapturePointID = cCapturePoint.EntityID; - e.TeamNumberThatCapturedCapturePoint = currentTeam; - m_EventBroker->Publish(e); - //NextPossibleCapturePoint will be calculated in the next update... - } - } + ////if point doesnt have a teamComponent yet, add one. since: + ////what if capture point has no team -> we cant get/use the team enum from it... + //if (!hasTeamComponent) { + // m_World->AttachComponent(cCapturePoint.EntityID, "Team"); + // ComponentWrapper& teamComponent = capturePointEntity["Team"]; + // teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator"); + //} + //ComponentWrapper& teamComponent = capturePointEntity["Team"]; + //const int redTeam = (int)teamComponent["Team"].Enum("Red"); + //const int blueTeam = (int)teamComponent["Team"].Enum("Blue"); + //const int spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); - //check for possible winCondition = check if the homebase is owned by the other team - bool checkForWinner = false; - if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam) - { - checkForWinner = true; - } - if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam) - { - checkForWinner = true; - } + //int homePointForTeam = (int)cCapturePoint["HomePointForTeam"]; + //if (m_NumberOfCapturePoints == 0 && capturePointNumber != 0 && (homePointForTeam == redTeam || homePointForTeam == blueTeam)) { + // m_NumberOfCapturePoints = capturePointNumber + 1;//ex 2 -> 0,1,2 = 3 + // if (homePointForTeam == redTeam) { + // m_RedTeamHomeCapturePoint = capturePointNumber; + // m_BlueTeamHomeCapturePoint = 0; + // } else { + // m_BlueTeamHomeCapturePoint = capturePointNumber; + // m_RedTeamHomeCapturePoint = 0; + // } + //} - if (checkForWinner && !m_WinnerWasFound) - { - //publish Win event - Events::Win e; - e.TeamThatWon = ownedBy; - m_EventBroker->Publish(e); - m_WinnerWasFound = true; - } + ////if we havent received all capturepoints yet, just return + //if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { + // m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); + // return; + //} + + ////we have all capturepoints now - process stuff + //int ownedBy = teamComponent["Team"]; + //int redTeamPlayersStandingInside = 0; + //int blueTeamPlayersStandingInside = 0; + //if (capturePointEntity.HasComponent("Model")) { + // //Now sets team color to the capturepoint, or white if it is uncaptured. + // capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3); + //} + + ////calculate next possible capturePoint for both teams + //std::map nextPossibleCapturePoint; + //nextPossibleCapturePoint["Red"] = -1; + //nextPossibleCapturePoint["Blue"] = -1; + //for (int i = 0; i < m_NumberOfCapturePoints; i++) + //{ + // if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { + // continue; + // } + // ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; + // if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) { + // nextPossibleCapturePoint["Red"] = i + 1; + // } + // if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint == 0) { + // nextPossibleCapturePoint["Blue"] = i + 1; + // } + //} + //for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--) + //{ + // if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { + // continue; + // } + // ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; + // if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) { + // nextPossibleCapturePoint["Red"] = i - 1; + // } + // if ((int)capturePointOwnedBy["Team"] == blueTeam && m_BlueTeamHomeCapturePoint != 0) { + // nextPossibleCapturePoint["Blue"] = i - 1; + // } + //} + + ////reset timers and reset the bool that triggers this + //if (m_ResetTimers) { + // for (int i = 0; i < m_NumberOfCapturePoints; i++) + // { + // ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; + // if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] && + // (int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) { + // capturePoint["CaptureTimer"] = 0.0; + // } + // } + // m_ResetTimers = false; + //} + + ////colorize next possible capturepoint + //if (nextPossibleCapturePoint["Red"] == capturePointNumber) { + // capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 0.3); + //} + //if (nextPossibleCapturePoint["Blue"] == capturePointNumber) { + // capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 0.3); + //} + + ////check how many players are standing inside and are healthy + //for (size_t i = m_ETriggerTouchVector.size(); i > 0; i--) + //{ + // auto triggerTouched = m_ETriggerTouchVector[i - 1]; + // if (std::get<1>(triggerTouched) == capturePointEntity) { + // //some player has touched this - lets figure out: what team, health + // EntityWrapper player = std::get<0>(triggerTouched); + // //check if its really a player that has triggered the touch + // if (!player.HasComponent("Player")) { + // //if a non-player has entered the capturePoint, just erase that event and continue + // m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i - 1); + // continue; + // } + // bool hasHealthComponent = player.HasComponent("Health"); + // if (hasHealthComponent) { + // double currentHealth = player["Health"]["Health"]; + // //check if player is dead + // if ((int)currentHealth == 0) { + // continue; + // } + // } + // //check team - spectatorNumber = "no team" + // int teamNumber = player["Team"]["Team"]; + // if (teamNumber == redTeam) { + // redTeamPlayersStandingInside++; + // } else if (teamNumber == blueTeam) { + // blueTeamPlayersStandingInside++; + // } + // continue; + // } + //} + + ////create data to be used in option B + ////check so this is the next possible capture point for the take-over team and see if only one team is standing inside it + //double timerDeltaChange = 0.0; + //int currentTeam = 0; + //bool canCapture = false; + //if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside == 0) { + // timerDeltaChange = redTeamPlayersStandingInside*dt; + // currentTeam = redTeam; + // canCapture = nextPossibleCapturePoint["Red"] == capturePointNumber; + //} + //if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside > 0) { + // timerDeltaChange = -blueTeamPlayersStandingInside*dt; + // currentTeam = blueTeam; + // canCapture = nextPossibleCapturePoint["Blue"] == capturePointNumber; + //} + + //if (redTeamPlayersStandingInside == 0 && blueTeamPlayersStandingInside == 0) { + // //A.nobodys standing inside + // //do nothing (?) + //} else if (redTeamPlayersStandingInside > 0 && blueTeamPlayersStandingInside > 0) { + // //C.both teams have players inside + // //do nothing (?) + //} else { + // //B. at most one of the teams have players inside + // //if capturePoint is not owned by the take-over team, just modify the CaptureTimer accordingly + // if (ownedBy != currentTeam && canCapture) { + // if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) { + // LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently. + // } + // cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; + // } + // //if capturePoint is owned by the team, and the other team has been trying to take it, then increase/decrease the timer towards 0.0 + // if ((ownedBy == currentTeam && currentTeam == redTeam && (double)cCapturePoint["CaptureTimer"] < 0.0) || + // (ownedBy == currentTeam && currentTeam == blueTeam && (double)cCapturePoint["CaptureTimer"] > 0.0)) { + // cCapturePoint["CaptureTimer"] = (double)cCapturePoint["CaptureTimer"] + timerDeltaChange; + // } + // //check if captureTimer > m_CaptureTimeToTakeOver and if so change owner and publish the eCaptured event + // if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) { + // teamComponent["Team"] = currentTeam; + // cCapturePoint["CaptureTimer"] = 0.0; + // //publish Captured event + // LOG_DEBUG("Point is captured by team %i!", currentTeam); //Remove when we tested sufficiently. + // Events::Captured e; + // e.CapturePointID = cCapturePoint.EntityID; + // e.TeamNumberThatCapturedCapturePoint = currentTeam; + // m_EventBroker->Publish(e); + // //NextPossibleCapturePoint will be calculated in the next update... + // } + //} + + ////check for possible winCondition = check if the homebase is owned by the other team + //bool checkForWinner = false; + //if (capturePointNumber == m_RedTeamHomeCapturePoint && ownedBy != redTeam) + //{ + // checkForWinner = true; + //} + //if (capturePointNumber == m_BlueTeamHomeCapturePoint && ownedBy != blueTeam) + //{ + // checkForWinner = true; + //} + + //if (checkForWinner && !m_WinnerWasFound) + //{ + // //publish Win event + // Events::Win e; + // e.TeamThatWon = ownedBy; + // m_EventBroker->Publish(e); + // m_WinnerWasFound = true; + //} } - -bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) -{ - //personEntered = e.Entity, thingEntered = e.Trigger - m_ETriggerTouchVector.push_back(std::make_tuple(e.Entity, e.Trigger)); - return true; -} - -bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e) -{ - for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++) - { - auto triggerTouched = m_ETriggerTouchVector[i]; - if (std::get<0>(triggerTouched) == e.Entity && std::get<1>(triggerTouched) == e.Trigger) { - m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i); - break; - } - } - return true; -} -bool CapturePointSystem::OnCaptured(const Events::Captured& e) -{ - //reset the timers in the next update since a capture has changed the "nextCapturePoint" for 1-2 teams - m_ResetTimers = true; - return true; -} +// +//bool CapturePointSystem::OnTriggerTouch(const Events::TriggerTouch& e) +//{ +// //personEntered = e.Entity, thingEntered = e.Trigger +// m_ETriggerTouchVector.push_back(std::make_tuple(e.Entity, e.Trigger)); +// return true; +//} +// +//bool CapturePointSystem::OnTriggerLeave(const Events::TriggerLeave& e) +//{ +// for (size_t i = 0; i < m_ETriggerTouchVector.size(); i++) +// { +// auto triggerTouched = m_ETriggerTouchVector[i]; +// if (std::get<0>(triggerTouched) == e.Entity && std::get<1>(triggerTouched) == e.Trigger) { +// m_ETriggerTouchVector.erase(m_ETriggerTouchVector.begin() + i); +// break; +// } +// } +// return true; +//} +//bool CapturePointSystem::OnCaptured(const Events::Captured& e) +//{ +// //reset the timers in the next update since a capture has changed the "nextCapturePoint" for 1-2 teams +// m_ResetTimers = true; +// return true; +//} From 35e4935497910a37711fc744646d05efced90e3e Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 11 Feb 2016 10:01:11 +0100 Subject: [PATCH 6/8] Some assets and HUD stuff --- assets | 2 +- .../Schema/Entities/CapturePointHUDGroup | 172 ++++++++++++++++++ .../Schema/Entities/QualityAssurance.xml | 75 ++++---- src/Game/Systems/CapturePointHUDSystem.cpp | 5 +- 4 files changed, 215 insertions(+), 39 deletions(-) create mode 100644 resources/Schema/Entities/CapturePointHUDGroup diff --git a/assets b/assets index 7531e441..0580eeae 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 7531e441fea639076d69c6cf05e3ae8ff7170cf9 +Subproject commit 0580eeae80919127622e16f2ec4f4083668d36cd diff --git a/resources/Schema/Entities/CapturePointHUDGroup b/resources/Schema/Entities/CapturePointHUDGroup new file mode 100644 index 00000000..9dce0ffb --- /dev/null +++ b/resources/Schema/Entities/CapturePointHUDGroup @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 2 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 3 + + + 0.80222018197612788 + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 4 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + 1 + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon.png + + + + + + + + + + + + + + + Textures/Core/UnitHexagon_Rotated.png + + + + + + + + + + + + + + diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index ce6a650e..2c77bc30 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -40,7 +40,7 @@ - + @@ -180,7 +180,7 @@ - + @@ -671,7 +671,7 @@ - + @@ -718,7 +718,7 @@ - + @@ -778,7 +778,7 @@ - + @@ -825,7 +825,7 @@ - + @@ -871,7 +871,7 @@ - + @@ -918,7 +918,7 @@ - + @@ -965,7 +965,7 @@ - + @@ -1023,6 +1023,7 @@ + 15 Models/Core/UnitCube.mesh @@ -1162,7 +1163,6 @@ - -12.033302729641917 3 @@ -1212,6 +1212,7 @@ + -15 4 @@ -1378,7 +1379,7 @@ - + @@ -1387,7 +1388,7 @@ true - 0.75158864645285173 + 0.75184169309215043 3.7999999523162842 true @@ -1434,7 +1435,7 @@ - + @@ -1443,7 +1444,7 @@ - 1.2014943970669589 + 1.2017474437062576 Models/Characters/Assault/AssaultTPose.mesh @@ -1486,7 +1487,7 @@ - + @@ -1497,7 +1498,7 @@ true - 0.68494018072689011 + 0.68519322736618882 true @@ -1542,7 +1543,7 @@ - + @@ -1552,7 +1553,7 @@ true - 0.95103870157425385 + 0.95129174821355256 10 3 @@ -1600,7 +1601,7 @@ - + @@ -1610,7 +1611,7 @@ true - 1.3510669629503185 + 1.3513200095896172 true 5 true @@ -1791,7 +1792,7 @@ true - 1.3677400229854642 + 1.3679930696247629 3.7999999523162842 true @@ -1965,7 +1966,7 @@ Textures/Core/UnitHexagon.png - + @@ -1978,7 +1979,7 @@ 2 - 0.5 + Textures/Core/UnitHexagon_Rotated.png @@ -1986,7 +1987,7 @@ - + @@ -1997,7 +1998,7 @@ Textures/Core/UnitHexagon.png - + @@ -2010,7 +2011,7 @@ 3 - 0.5 + Textures/Core/UnitHexagon_Rotated.png @@ -2018,7 +2019,7 @@ - + @@ -2029,7 +2030,7 @@ Textures/Core/UnitHexagon.png - + @@ -2042,7 +2043,8 @@ 4 - 0.5 + 1 + Textures/Core/UnitHexagon_Rotated.png @@ -2050,7 +2052,7 @@ - + @@ -2061,7 +2063,7 @@ Textures/Core/UnitHexagon.png - + @@ -2074,7 +2076,7 @@ 1 - 0.5 + Textures/Core/UnitHexagon_Rotated.png @@ -2082,7 +2084,7 @@ - + @@ -2093,7 +2095,7 @@ Textures/Core/UnitHexagon.png - + @@ -2104,7 +2106,8 @@ - 0.5 + 1 + Textures/Core/UnitHexagon_Rotated.png @@ -2112,7 +2115,7 @@ - + diff --git a/src/Game/Systems/CapturePointHUDSystem.cpp b/src/Game/Systems/CapturePointHUDSystem.cpp index 5c4c2b60..ad8cc63a 100644 --- a/src/Game/Systems/CapturePointHUDSystem.cpp +++ b/src/Game/Systems/CapturePointHUDSystem.cpp @@ -13,7 +13,7 @@ CapturePointHUDSystem::CapturePointHUDSystem(World* world, EventBroker* eventBro void CapturePointHUDSystem::Update(double dt) { - bool LoadCheck = false; + bool LoadCheck = true; int redTeam; int blueTeam; int spectatorTeam; @@ -32,10 +32,11 @@ void CapturePointHUDSystem::Update(double dt) //Check if the HUD corresponds to the Capture Point Number if (HUD_ID == (int)entityCP["CapturePoint"]["CapturePointNumber"]) { ComponentWrapper& teamComponent = entityCP["Team"]; - if (!LoadCheck) { + if (LoadCheck) { redTeam = (int)teamComponent["Team"].Enum("Red"); blueTeam = (int)teamComponent["Team"].Enum("Blue"); spectatorTeam = (int)teamComponent["Team"].Enum("Spectator"); + LoadCheck = false; } //Color hud with team color auto capturePointTeam = (int)teamComponent["Team"]; From 350effd8ebc045f1614e3a1422f99d3d62fe8758 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 11 Feb 2016 11:32:51 +0100 Subject: [PATCH 7/8] New assets and some QA map stuff --- assets | 2 +- .../Schema/Entities/QualityAssurance.xml | 59 +++++++++++++------ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/assets b/assets index 0580eeae..8ffd0a99 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 0580eeae80919127622e16f2ec4f4083668d36cd +Subproject commit 8ffd0a99b9a2e5c140307d382a25c4a470cc8f33 diff --git a/resources/Schema/Entities/QualityAssurance.xml b/resources/Schema/Entities/QualityAssurance.xml index 2c77bc30..40951468 100644 --- a/resources/Schema/Entities/QualityAssurance.xml +++ b/resources/Schema/Entities/QualityAssurance.xml @@ -180,7 +180,7 @@ - + @@ -671,7 +671,7 @@ - + @@ -718,7 +718,7 @@ - + @@ -778,7 +778,7 @@ - + @@ -825,7 +825,7 @@ - + @@ -871,7 +871,7 @@ - + @@ -918,7 +918,7 @@ - + @@ -965,7 +965,7 @@ - + @@ -1379,7 +1379,7 @@ - + @@ -1388,7 +1388,7 @@ true - 0.75184169309215043 + 0.75205058136495551 3.7999999523162842 true @@ -1435,7 +1435,7 @@ - + @@ -1444,7 +1444,7 @@ - 1.2017474437062576 + 1.2019563319790627 Models/Characters/Assault/AssaultTPose.mesh @@ -1487,7 +1487,7 @@ - + @@ -1498,7 +1498,7 @@ true - 0.68519322736618882 + 0.68540211563899389 true @@ -1543,7 +1543,7 @@ - + @@ -1553,7 +1553,7 @@ true - 0.95129174821355256 + 0.95150063648635763 10 3 @@ -1601,7 +1601,7 @@ - + @@ -1611,7 +1611,7 @@ true - 1.3513200095896172 + 1.3515288978624223 true 5 true @@ -1792,7 +1792,7 @@ true - 1.3679930696247629 + 1.3682019578975679 3.7999999523162842 true @@ -2124,6 +2124,27 @@ + + + + + + + + + + + + Models/Widgets/Camera.mesh + + + + + + + + + From 9f657ada4ebd5ed1177b7ca078c5870c8df5f1a4 Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 11 Feb 2016 14:52:52 +0100 Subject: [PATCH 8/8] merge fixes --- include/Game/Systems/CapturePointHUDSystem.h | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 1 - src/Game/Systems/CapturePointHUDSystem.cpp | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/Game/Systems/CapturePointHUDSystem.h b/include/Game/Systems/CapturePointHUDSystem.h index 102c52ce..94be3798 100644 --- a/include/Game/Systems/CapturePointHUDSystem.h +++ b/include/Game/Systems/CapturePointHUDSystem.h @@ -12,7 +12,7 @@ class CapturePointHUDSystem : public ImpureSystem { public: - CapturePointHUDSystem(World* world, EventBroker* eventBroker); + CapturePointHUDSystem(SystemParams params); virtual void Update(double dt) override; diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 42cbd22b..362f2252 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -323,7 +323,6 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO()); - for (auto &job : jobs) { auto explosionEffectJob = std::dynamic_pointer_cast(job); if (explosionEffectJob) { diff --git a/src/Game/Systems/CapturePointHUDSystem.cpp b/src/Game/Systems/CapturePointHUDSystem.cpp index ad8cc63a..c2d62c4b 100644 --- a/src/Game/Systems/CapturePointHUDSystem.cpp +++ b/src/Game/Systems/CapturePointHUDSystem.cpp @@ -1,7 +1,7 @@ #include "Systems/CapturePointHUDSystem.h" -CapturePointHUDSystem::CapturePointHUDSystem(World* world, EventBroker* eventBroker) - : System(world, eventBroker) +CapturePointHUDSystem::CapturePointHUDSystem(SystemParams params) + : System(params) , ImpureSystem() { //subscribe/listenTo playerdamage,healthpickup events (using the eventBroker)