From 6aeb28124960e9a8d7ad565378f5fd46a25c37ab Mon Sep 17 00:00:00 2001 From: viktorljung Date: Mon, 25 Jan 2016 00:07:17 +0100 Subject: [PATCH 1/7] Resolution fix in render stages //Tobias --- include/Engine/Rendering/IRenderer.h | 4 ++++ resources/Shaders/Gaussian_horiz.frag.glsl | 2 +- resources/Shaders/Gaussian_vert.frag.glsl | 2 +- src/Engine/Rendering/DrawBloomPass.cpp | 5 +++-- src/Engine/Rendering/DrawFinalPass.cpp | 8 ++++---- src/Engine/Rendering/LightCullingPass.cpp | 10 +++++----- src/Engine/Rendering/PickingPass.cpp | 4 ++-- src/Engine/Rendering/Renderer.cpp | 5 +++++ 8 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/Engine/Rendering/IRenderer.h b/include/Engine/Rendering/IRenderer.h index 6ef189f4..54932cfd 100644 --- a/include/Engine/Rendering/IRenderer.h +++ b/include/Engine/Rendering/IRenderer.h @@ -31,15 +31,19 @@ public: void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; } bool VSYNC() const { return m_VSYNC; } void SetVSYNC(bool vsync) { m_VSYNC = vsync; } + Rectangle GetViewPortSize() const { return m_ViewPortWidth; } + void SetViewPortSize(const Rectangle& viewportWidth) { m_ViewPortWidth = viewportWidth; } virtual void Initialize() = 0; virtual void Update(double dt) = 0; virtual void Draw(RenderFrame& rq) = 0; virtual PickData Pick(glm::vec2 screenCord) = 0; + World* m_World; //Temp world, untill viktor merge. protected: Rectangle m_Resolution = Rectangle::Rectangle(1280, 720); + Rectangle m_ViewPortWidth = Rectangle::Rectangle(1280, 720); bool m_Fullscreen = false; bool m_VSYNC = false; int m_GLVersion[2]; diff --git a/resources/Shaders/Gaussian_horiz.frag.glsl b/resources/Shaders/Gaussian_horiz.frag.glsl index bd48d2d5..a5606372 100644 --- a/resources/Shaders/Gaussian_horiz.frag.glsl +++ b/resources/Shaders/Gaussian_horiz.frag.glsl @@ -12,7 +12,7 @@ uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.01 void main() { - vec2 tex_offset = 1.0 / textureSize(Texture, 0); + vec2 tex_offset = 1.0 / textureSize2D(Texture, 0); vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0]; for(int i = 1; i < 5; ++i) { diff --git a/resources/Shaders/Gaussian_vert.frag.glsl b/resources/Shaders/Gaussian_vert.frag.glsl index 25b08f9f..34803b08 100644 --- a/resources/Shaders/Gaussian_vert.frag.glsl +++ b/resources/Shaders/Gaussian_vert.frag.glsl @@ -12,7 +12,7 @@ uniform float weight[5] = float[](0.227027, 0.1945946, 0.1216216, 0.054054, 0.01 void main() { - vec2 tex_offset = 1.0 / textureSize(Texture, 0); + vec2 tex_offset = 1.0 / textureSize2D(Texture, 0); vec3 result = texture(Texture, Input.TextureCoordinate).rgb * weight[0]; for(int i = 1; i < 5; ++i) { diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 8fe1d807..44c88a16 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -34,12 +34,13 @@ void DrawBloomPass::InitializeShaderPrograms() void DrawBloomPass::InitializeBuffers() { - GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + printf("x:%f\ny:%f", m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); + GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0))); m_GaussianFrameBuffer_horiz.Generate(); - GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0))); m_GaussianFrameBuffer_vert.Generate(); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 9abf69d3..994a8bf6 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -19,11 +19,11 @@ void DrawFinalPass::InitializeFrameBuffers() { glGenRenderbuffers(1, &m_DepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); - GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); //GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_FLOAT, 4); m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT))); @@ -63,7 +63,7 @@ void DrawFinalPass::Draw(RenderScene& scene) 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())); - glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); //TODO: Render: Add code for more jobs than modeljobs. diff --git a/src/Engine/Rendering/LightCullingPass.cpp b/src/Engine/Rendering/LightCullingPass.cpp index a68fe4d1..46a17286 100644 --- a/src/Engine/Rendering/LightCullingPass.cpp +++ b/src/Engine/Rendering/LightCullingPass.cpp @@ -25,8 +25,8 @@ void LightCullingPass::GenerateNewFrustum(RenderScene& scene) glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO); glUniformMatrix4fv(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "P"), 1, false, glm::value_ptr(scene.Camera->ProjectionMatrix())); - glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); - glDispatchCompute((int)(m_Renderer->Resolution().Width/(TILE_SIZE*TILE_SIZE) + 1), (int)(m_Renderer->Resolution().Height/(TILE_SIZE*TILE_SIZE) + 1), 1); + glUniform2f(glGetUniformLocation(m_CalculateFrustumProgram->GetHandle(), "ScreenDimensions"), m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); + glDispatchCompute((int)(m_Renderer->GetViewPortSize().Width/(TILE_SIZE*TILE_SIZE) + 1), (int)(m_Renderer->GetViewPortSize().Height/(TILE_SIZE*TILE_SIZE) + 1), 1); GLERROR("CalculateFrustum Error: End"); } @@ -40,7 +40,7 @@ void LightCullingPass::OnResolutionChange() void LightCullingPass::SetSSBOSizes() { - m_NumberOfTiles = (int)(m_Renderer->Resolution().Width/TILE_SIZE) * (int)(m_Renderer->Resolution().Height/TILE_SIZE); + m_NumberOfTiles = (int)(m_Renderer->GetViewPortSize().Width/TILE_SIZE) * (int)(m_Renderer->GetViewPortSize().Height/TILE_SIZE); m_Frustums = new Frustum[m_NumberOfTiles]; m_LightGrid = new LightGrid[m_NumberOfTiles]; @@ -67,14 +67,14 @@ void LightCullingPass::CullLights(RenderScene& scene) glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); m_LightCullProgram->Bind(); - glUniform2f(glGetUniformLocation(m_LightCullProgram->GetHandle(), "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + glUniform2f(glGetUniformLocation(m_LightCullProgram->GetHandle(), "ScreenDimensions"), m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); glUniformMatrix4fv(glGetUniformLocation(m_LightCullProgram->GetHandle(), "V"), 1, false, glm::value_ptr(scene.Camera->ViewMatrix())); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_FrustumSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightGridSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, m_LightOffsetSSBO); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightIndexSSBO); - glDispatchCompute(glm::ceil(m_Renderer->Resolution().Width / TILE_SIZE), glm::ceil(m_Renderer->Resolution().Height / TILE_SIZE), 1); + glDispatchCompute(glm::ceil(m_Renderer->GetViewPortSize().Width/ TILE_SIZE), glm::ceil(m_Renderer->GetViewPortSize().Height / TILE_SIZE), 1); GLERROR("CullLights Error: End"); } diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 0d89f355..2ed6d1a9 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -18,14 +18,14 @@ PickingPass::~PickingPass() void PickingPass::InitializeTextures() { GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR, - glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE); + glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE); } void PickingPass::InitializeFrameBuffers() { glGenRenderbuffers(1, &m_DepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); m_PickingBuffer.AddResource(std::shared_ptr(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT))); m_PickingBuffer.AddResource(std::shared_ptr(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0))); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 4f687a99..f419bcaa 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -58,6 +58,11 @@ void Renderer::InitializeWindow() LOG_ERROR("GLEW: Initialization failed"); exit(EXIT_FAILURE); } + + int res[2]; + glfwGetWindowSize(m_Window, &res[0], &res[1]); + SetViewPortSize(Rectangle::Rectangle(res[0], res[1])); + } void Renderer::InitializeShaders() From d12246833eb851d66e70f5a341979578735a48be Mon Sep 17 00:00:00 2001 From: viktorljung Date: Mon, 25 Jan 2016 01:26:41 +0100 Subject: [PATCH 2/7] Some further small fizes to resolution //Tobias --- include/Engine/Rendering/IRenderer.h | 2 ++ src/Engine/Editor/EditorWidgetSystem.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 4 ++-- src/Game/Systems/WeaponSystem.cpp | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/Engine/Rendering/IRenderer.h b/include/Engine/Rendering/IRenderer.h index 54932cfd..811ecd28 100644 --- a/include/Engine/Rendering/IRenderer.h +++ b/include/Engine/Rendering/IRenderer.h @@ -25,12 +25,14 @@ class IRenderer { public: GLFWwindow* Window() const { return m_Window; } + //Returns screensize including window border and header Rectangle Resolution() const { return m_Resolution; } void SetResolution(const Rectangle& resolution) { m_Resolution = resolution; } bool Fullscreen() { return m_Fullscreen; } void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; } bool VSYNC() const { return m_VSYNC; } void SetVSYNC(bool vsync) { m_VSYNC = vsync; } + //Returns screensize excluding window border and header Rectangle GetViewPortSize() const { return m_ViewPortWidth; } void SetViewPortSize(const Rectangle& viewportWidth) { m_ViewPortWidth = viewportWidth; } virtual void Initialize() = 0; diff --git a/src/Engine/Editor/EditorWidgetSystem.cpp b/src/Engine/Editor/EditorWidgetSystem.cpp index 479671e2..8352c5c1 100644 --- a/src/Engine/Editor/EditorWidgetSystem.cpp +++ b/src/Engine/Editor/EditorWidgetSystem.cpp @@ -30,7 +30,7 @@ void EditorWidgetSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper auto camera = m_PickData.Camera; glm::vec3 axis = cEditorWidget["Axis"]; - glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->Resolution()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->Resolution()); + glm::vec2 axisScreen = camera->WorldToScreen(axis, m_Renderer->GetViewPortSize()) - camera->WorldToScreen(glm::vec3(0, 0, 0), m_Renderer->GetViewPortSize()); float dot = glm::dot(m_MouseDelta, glm::normalize(axisScreen)) / glm::length(axisScreen); glm::vec3 worldMovement = dot * axis; diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 994a8bf6..52c9a4a9 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -22,9 +22,9 @@ void DrawFinalPass::InitializeFrameBuffers() glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - //GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT); + //GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); - //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_FLOAT, 4); + //GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4); m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT))); m_FinalPassFrameBuffer.AddResource(std::shared_ptr(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0))); diff --git a/src/Game/Systems/WeaponSystem.cpp b/src/Game/Systems/WeaponSystem.cpp index f72fd7dd..02d70289 100644 --- a/src/Game/Systems/WeaponSystem.cpp +++ b/src/Game/Systems/WeaponSystem.cpp @@ -47,7 +47,7 @@ bool WeaponSystem::OnInputCommand(const Events::InputCommand& e) bool WeaponSystem::OnShoot(const Events::Shoot& eShoot) { // Screen center, based on current resolution! //TODO: check if player has enough ammo and if weapon has a cooldown or not - Rectangle screenResolution = m_Renderer->Resolution(); + Rectangle screenResolution = m_Renderer->GetViewPortSize(); glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2); // TODO: check if player has enough ammo and if weapon has a cooldown or not From 8bed5194d81827e3d4d292d9da886d0e2148025c Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 27 Jan 2016 11:36:24 +0100 Subject: [PATCH 3/7] "Proper" handling of conditional rendering of entities parented to camera or entities that should be hidden from the active local player perspective --- include/Engine/Rendering/RenderSystem.h | 12 +++--- resources/Schema/Components.xsd | 1 + .../Components/HiddenForLocalPlayer.xml | 2 + .../Components/HiddenForLocalPlayer.xsd | 11 ++++++ resources/Schema/Components/Lifetime.xml | 4 +- resources/Schema/Components/Model.xsd | 2 +- resources/Schema/Entities/Player.xml | 5 ++- resources/Schema/Types/Entity.xsd | 3 ++ src/Engine/Core/EntityFilePreprocessor.cpp | 3 +- src/Engine/Core/World.cpp | 8 +++- src/Engine/Rendering/RenderSystem.cpp | 37 ++++++++++++------- 11 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 resources/Schema/Components/HiddenForLocalPlayer.xml create mode 100644 resources/Schema/Components/HiddenForLocalPlayer.xsd diff --git a/include/Engine/Rendering/RenderSystem.h b/include/Engine/Rendering/RenderSystem.h index 37f99341..d9b0d779 100644 --- a/include/Engine/Rendering/RenderSystem.h +++ b/include/Engine/Rendering/RenderSystem.h @@ -35,17 +35,19 @@ private: EventRelay m_ESetCamera; bool OnSetCamera(Events::SetCamera &event); + EventRelay m_EInputCommand; + bool OnInputCommand(const Events::InputCommand& e); + EventRelay m_EPlayerSpawned; + bool OnPlayerSpawned(Events::PlayerSpawned& e); + void fillText(std::list>& jobs, World* world); void fillPointLights(std::list>& jobs, World* world); void fillDirectionalLights(std::list>& jobs, World* world); - EventRelay m_EInputCommand; - bool OnInputCommand(const Events::InputCommand& e); - void fillModels(std::list>& jobs); void fillLight(std::list>& jobs); + bool isChildOfACamera(EntityWrapper entity); + bool isChildOfCurrentCamera(EntityWrapper entity); - EventRelay m_EPlayerSpawned; - bool OnPlayerSpawned(Events::PlayerSpawned& e); }; #endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 5ce7fa5f..e9c6a813 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -27,4 +27,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/HiddenForLocalPlayer.xml b/resources/Schema/Components/HiddenForLocalPlayer.xml new file mode 100644 index 00000000..5840385c --- /dev/null +++ b/resources/Schema/Components/HiddenForLocalPlayer.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/resources/Schema/Components/HiddenForLocalPlayer.xsd b/resources/Schema/Components/HiddenForLocalPlayer.xsd new file mode 100644 index 00000000..7f47fba5 --- /dev/null +++ b/resources/Schema/Components/HiddenForLocalPlayer.xsd @@ -0,0 +1,11 @@ + + + + + + + + Used to make the entity invisible if it's parented to the current local player entity (for first person player model and such) + + + \ No newline at end of file diff --git a/resources/Schema/Components/Lifetime.xml b/resources/Schema/Components/Lifetime.xml index d7e230d7..302429b1 100644 --- a/resources/Schema/Components/Lifetime.xml +++ b/resources/Schema/Components/Lifetime.xml @@ -1,4 +1,4 @@ - + 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/Model.xsd b/resources/Schema/Components/Model.xsd index fb0774f8..540ab1bf 100644 --- a/resources/Schema/Components/Model.xsd +++ b/resources/Schema/Components/Model.xsd @@ -16,7 +16,7 @@ Color tint - Wether the model is visible or not + Whether the model is visible or not diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 7914f82b..e81ec5aa 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -20,7 +20,7 @@ - + @@ -141,9 +141,10 @@ Hold Pos - + 1 + Models/AssaultAnimated.mesh diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 5d135847..25aad787 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -33,6 +33,9 @@ + + + diff --git a/src/Engine/Core/EntityFilePreprocessor.cpp b/src/Engine/Core/EntityFilePreprocessor.cpp index 7b4b2bb7..2a1d22d6 100644 --- a/src/Engine/Core/EntityFilePreprocessor.cpp +++ b/src/Engine/Core/EntityFilePreprocessor.cpp @@ -65,6 +65,7 @@ void EntityFilePreprocessor::parseComponentInfo() // Name compInfo.Name = XS::ToString(element->getName()); + bool brk = compInfo.Name == "HiddenForLocalPlayer"; // Known allocation compInfo.Meta->Allocation = m_ComponentCounts[compInfo.Name]; // Annotation @@ -90,7 +91,7 @@ void EntityFilePreprocessor::parseComponentInfo() // auto modelGroupParticle = complexTypeDefinition->getParticle(); if (modelGroupParticle == nullptr || modelGroupParticle->getTermType() != XSParticle::TERM_MODELGROUP) { - //LOG_ERROR("Failed to parse component definition for \"%s\": Model group particle was null or wasn't TERM_MODELGROUP!", compInfo.Name.c_str()); + LOG_ERROR("Failed to parse component definition for \"%s\": Model group particle was null or wasn't TERM_MODELGROUP!", compInfo.Name.c_str()); continue; } auto modelGroup = modelGroupParticle->getModelGroupTerm(); diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 0c4c9ce4..8b212d31 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -54,8 +54,12 @@ ComponentWrapper World::AttachComponent(EntityID entity, const std::string& comp bool World::HasComponent(EntityID entity, const std::string& componentType) const { - ComponentPool* pool = m_ComponentPools.at(componentType); - return pool->KnowsEntity(entity); + auto it = m_ComponentPools.find(componentType); + if (it == m_ComponentPools.end()) { + return false; + } else { + return it->second->KnowsEntity(entity); + } } ComponentWrapper World::GetComponent(EntityID entity, const std::string& componentType) diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index a67f2c75..e2aba63e 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -31,6 +31,16 @@ bool RenderSystem::OnSetCamera(Events::SetCamera& e) return true; } +bool RenderSystem::isChildOfACamera(EntityWrapper entity) +{ + return entity.FirstParentWithComponent("Camera").Valid(); +} + +bool RenderSystem::isChildOfCurrentCamera(EntityWrapper entity) +{ + return entity == m_CurrentCamera || entity.IsChildOf(m_CurrentCamera); +} + void RenderSystem::fillModels(std::list>& jobs) { auto models = m_World->GetComponents("Model"); @@ -38,26 +48,25 @@ void RenderSystem::fillModels(std::list>& jobs) return; } - for (auto& modelComponent : *models) { - bool visible = modelComponent["Visible"]; + for (auto& cModel : *models) { + bool visible = cModel["Visible"]; if (!visible) { continue; } - std::string resource = modelComponent["Resource"]; + std::string resource = cModel["Resource"]; if (resource.empty()) { continue; } - EntityWrapper entity(m_World, modelComponent.EntityID); + EntityWrapper entity(m_World, cModel.EntityID); - // Don't render the local player - if (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer)) { - if (!entity.HasComponent("HealthHUD") && entity.Name() != "Crosshair" && entity.Name() != "Weapon") { //Should work but needs to be fixed. Should only render the things "childed" to the local player camera - continue; - } + // Only render children of a camera if that camera is currently active + if (isChildOfACamera(entity) && !isChildOfCurrentCamera(entity)) { + continue; } - if ((entity.Name() == "Weapon" || entity.HasComponent("HealthHUD")) && !entity.IsChildOf(m_LocalPlayer)) { + // Hide things parented to local player if they have the HiddenFromLocalPlayer component + if (entity.HasComponent("HiddenForLocalPlayer") && (entity == m_LocalPlayer || entity.IsChildOf(m_LocalPlayer))) { continue; } @@ -79,17 +88,17 @@ void RenderSystem::fillModels(std::list>& jobs) float fillPercentage = 0.f; glm::vec4 fillColor = glm::vec4(0); - if(m_World->HasComponent(modelComponent.EntityID, "Fill")) { - auto fillComponent = m_World->GetComponent(modelComponent.EntityID, "Fill"); + if(m_World->HasComponent(cModel.EntityID, "Fill")) { + auto fillComponent = m_World->GetComponent(cModel.EntityID, "Fill"); fillPercentage = (float)(double)fillComponent["Percentage"]; fillColor = (glm::vec4)fillComponent["Color"]; } - glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, m_World); + glm::mat4 modelMatrix = Transform::ModelMatrix(cModel.EntityID, m_World); for (auto matGroup : model->MaterialGroups()) { - std::shared_ptr modelJob = std::shared_ptr(new ModelJob(model, m_Camera, modelMatrix, matGroup, modelComponent, m_World, fillColor, fillPercentage)); + std::shared_ptr modelJob = std::shared_ptr(new ModelJob(model, m_Camera, modelMatrix, matGroup, cModel, m_World, fillColor, fillPercentage)); jobs.push_back(modelJob); } } From 5fcd26cd3e4ed2b55f038f56f8245945904d5402 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 27 Jan 2016 13:35:16 +0100 Subject: [PATCH 4/7] Made TriggerSystem make use of Octree --- .../Engine/Collision/CollidableOctreeSystem.h | 5 +- include/Engine/Collision/Collision.h | 3 +- include/Engine/Collision/CollisionSystem.h | 5 +- include/Engine/Collision/ETrigger.h | 14 +-- include/Engine/Collision/EntityAABB.h | 22 +++++ include/Engine/Collision/TriggerSystem.h | 18 ++-- include/Engine/Core/AABB.h | 1 - include/Engine/Core/EntityWrapper.h | 1 - include/Engine/Core/Octree.h | 2 +- include/Game/Game.h | 5 +- include/Game/Systems/CapturePointSystem.h | 6 +- .../Collision/CollidableOctreeSystem.cpp | 2 +- src/Engine/Collision/Collision.cpp | 8 +- src/Engine/Collision/CollisionSystem.cpp | 6 +- src/Engine/Collision/TriggerSystem.cpp | 95 +++++++++---------- src/Engine/Core/AABB.cpp | 4 - src/Engine/Core/EntityWrapper.cpp | 5 - src/Engine/Editor/EditorRenderSystem.cpp | 2 +- src/Game/Game.cpp | 7 +- src/Game/Systems/CapturePointSystem.cpp | 64 ++++++------- 20 files changed, 145 insertions(+), 130 deletions(-) create mode 100644 include/Engine/Collision/EntityAABB.h diff --git a/include/Engine/Collision/CollidableOctreeSystem.h b/include/Engine/Collision/CollidableOctreeSystem.h index 0dcf5829..39aea979 100644 --- a/include/Engine/Collision/CollidableOctreeSystem.h +++ b/include/Engine/Collision/CollidableOctreeSystem.h @@ -4,11 +4,12 @@ #include "../Core/System.h" #include "../Core/Octree.h" #include "Collision.h" +#include "EntityAABB.h" class CollidableOctreeSystem : public ImpureSystem, public PureSystem { public: - CollidableOctreeSystem(World* world, EventBroker* eventBroker, Octree* octree) + CollidableOctreeSystem(World* world, EventBroker* eventBroker, Octree* octree) : System(world, eventBroker) , PureSystem("Collidable") , m_Octree(octree) @@ -18,7 +19,7 @@ public: virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override; private: - Octree* m_Octree; + Octree* m_Octree; }; #endif \ No newline at end of file diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 194a18dc..29a0d2e0 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -15,6 +15,7 @@ #include "../Core/Transform.h" #include "../Core/Entity.h" #include "../Core/EntityWrapper.h" +#include "EntityAABB.h" class World; struct ComponentWrapper; @@ -61,7 +62,7 @@ bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation); bool IsSameBoxProbably(const AABB& first, const AABB& second, const float epsilon = 0.0001f); // Calculates an absolute AABB from an entity AABB component -boost::optional EntityAbsoluteAABB(EntityWrapper& entity); +boost::optional EntityAbsoluteAABB(EntityWrapper& entity); } diff --git a/include/Engine/Collision/CollisionSystem.h b/include/Engine/Collision/CollisionSystem.h index 5f15a3d5..aff5f8ea 100644 --- a/include/Engine/Collision/CollisionSystem.h +++ b/include/Engine/Collision/CollisionSystem.h @@ -9,11 +9,12 @@ #include "../Core/EventBroker.h" #include "../Core/EKeyUp.h" #include "../Core/Octree.h" +#include "EntityAABB.h" class CollisionSystem : public PureSystem { public: - CollisionSystem(World* world, EventBroker* eventBroker, Octree* octree) + CollisionSystem(World* world, EventBroker* eventBroker, Octree* octree) : System(world, eventBroker) , PureSystem("Collidable") , m_Octree(octree) @@ -26,7 +27,7 @@ public: virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override; private: - Octree* m_Octree; + Octree* m_Octree; bool zPress; EventRelay m_EKeyUp; diff --git a/include/Engine/Collision/ETrigger.h b/include/Engine/Collision/ETrigger.h index 687c73fa..0b35ef1b 100644 --- a/include/Engine/Collision/ETrigger.h +++ b/include/Engine/Collision/ETrigger.h @@ -2,7 +2,7 @@ #define Events_TriggerEnter_h__ #include "../Core/EventBroker.h" -#include "../Core/Entity.h" +#include "../Core/EntityWrapper.h" namespace Events { @@ -11,27 +11,27 @@ namespace Events struct TriggerTouch : Event { /** The id of the entity that touches the trigger. */ - EntityID Entity; + EntityWrapper Entity; /** The id of the trigger entity. */ - EntityID Trigger; + EntityWrapper Trigger; }; /** Thrown once, when an entity has completely left a trigger. */ struct TriggerLeave : Event { /** The id of the entity that left the trigger. */ - EntityID Entity; + EntityWrapper Entity; /** The id of the trigger entity. */ - EntityID Trigger; + EntityWrapper Trigger; }; /** Thrown once, when an entity is completely contained inside a trigger. */ struct TriggerEnter : Event { /** The id of the entity that entered the trigger. */ - EntityID Entity; + EntityWrapper Entity; /** The id of the trigger entity. */ - EntityID Trigger; + EntityWrapper Trigger; }; } diff --git a/include/Engine/Collision/EntityAABB.h b/include/Engine/Collision/EntityAABB.h new file mode 100644 index 00000000..79c21271 --- /dev/null +++ b/include/Engine/Collision/EntityAABB.h @@ -0,0 +1,22 @@ +#ifndef EntityAABB_h__ +#define EntityAABB_h__ + +#include "../Core/AABB.h" +#include "../Core/EntityWrapper.h" + +struct EntityAABB : AABB +{ + EntityAABB() = default; + + EntityAABB(const glm::vec3& minPos, const glm::vec3& maxPos) + : AABB(minPos, maxPos) + { } + + EntityAABB(const AABB& aabb) + : AABB(aabb) + { } + + EntityWrapper Entity; +}; + +#endif \ No newline at end of file diff --git a/include/Engine/Collision/TriggerSystem.h b/include/Engine/Collision/TriggerSystem.h index 648c8585..fa322ddd 100644 --- a/include/Engine/Collision/TriggerSystem.h +++ b/include/Engine/Collision/TriggerSystem.h @@ -8,13 +8,14 @@ #include "../Core/EventBroker.h" #include "../Core/Octree.h" #include "ETrigger.h" +#include "EntityAABB.h" class AABB; class TriggerSystem : public PureSystem { public: - TriggerSystem(World* world, EventBroker* eventBroker, Octree* octree) + TriggerSystem(World* world, EventBroker* eventBroker, Octree* octree) : System(world, eventBroker) , PureSystem("Trigger") , m_Octree(octree) @@ -27,9 +28,10 @@ public: virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override; private: - Octree* m_Octree; - std::unordered_map> m_EntitiesTouchingTrigger; - std::unordered_map> m_EntitiesCompletelyInTrigger; + Octree* m_Octree; + std::vector m_OctreeOut; + std::unordered_map> m_EntitiesTouchingTrigger; + std::unordered_map> m_EntitiesCompletelyInTrigger; //TODO: Only exists for debug purposes, remove later. EventRelay m_EEnter; @@ -40,13 +42,13 @@ private: bool OnLeave(const Events::TriggerLeave &event); //True if leave event was thrown. - bool throwLeaveIfWasInTrigger(std::unordered_set& triggerSet, EntityID pId, EntityID tId); + bool throwLeaveIfWasInTrigger(std::unordered_set& triggerSet, EntityWrapper colliderENtity, EntityWrapper triggerEntity); template - void publish(EntityID pId, EntityID tId) + void publish(EntityWrapper collider, EntityWrapper trigger) { Event e; - e.Trigger = tId; - e.Entity = pId; + e.Trigger = trigger; + e.Entity = collider; m_EventBroker->Publish(e); } }; diff --git a/include/Engine/Core/AABB.h b/include/Engine/Core/AABB.h index 5b9c6485..0dea9603 100644 --- a/include/Engine/Core/AABB.h +++ b/include/Engine/Core/AABB.h @@ -9,7 +9,6 @@ public: AABB() = default; //No checks are made. Values in minPos must be less than values in maxPos, i.e. min.x < max.x, etc. AABB(const glm::vec3& minPos, const glm::vec3& maxPos); - AABB(const glm::vec4& minPos, const glm::vec4& maxPos); //No checks are made. Size must consist of non-negative numbers. static AABB FromOriginSize(const glm::vec3& origin, const glm::vec3& size); virtual ~AABB(); diff --git a/include/Engine/Core/EntityWrapper.h b/include/Engine/Core/EntityWrapper.h index b2e0ce4c..bf34b9be 100644 --- a/include/Engine/Core/EntityWrapper.h +++ b/include/Engine/Core/EntityWrapper.h @@ -35,7 +35,6 @@ struct EntityWrapper bool operator==(const EntityWrapper& e) const; bool operator!=(const EntityWrapper& e) const; explicit operator EntityID() const; - operator bool(); private: EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent); diff --git a/include/Engine/Core/Octree.h b/include/Engine/Core/Octree.h index 8bac5503..72825c3c 100644 --- a/include/Engine/Core/Octree.h +++ b/include/Engine/Core/Octree.h @@ -149,7 +149,7 @@ template template void Octree::ObjectsInSameRegion(const Box& box, std::vector& outObjects) { - static_assert(std::is_base_of::value, "template argument type Box in Octree::ObjectsInSameRegion must be a subclass of AABB."); + //static_assert(std::is_base_of::value, "template argument type Box in Octree::ObjectsInSameRegion must be a subclass of AABB."); falsifyObjectChecks(); m_Root->ObjectsInSameRegion(box, outObjects); } diff --git a/include/Game/Game.h b/include/Game/Game.h index fab10a49..1c541055 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -21,6 +21,7 @@ #include "Core/Octree.h" #include "Rendering/Font.h" #include "Systems/InterpolationSystem.h" +#include "Collision/EntityAABB.h" // Network #include #include "Network/Network.h" @@ -48,8 +49,8 @@ private: InputProxy* m_InputProxy; GUI::Frame* m_FrameStack; World* m_World; - Octree* m_OctreeCollision; - Octree* m_OctreeFrustrumCulling; + Octree* m_OctreeCollision; + Octree* m_OctreeFrustrumCulling; SystemPipeline* m_SystemPipeline; RenderFrame* m_RenderFrame; // Network variables diff --git a/include/Game/Systems/CapturePointSystem.h b/include/Game/Systems/CapturePointSystem.h index 3b459c40..18c32c76 100644 --- a/include/Game/Systems/CapturePointSystem.h +++ b/include/Game/Systems/CapturePointSystem.h @@ -40,7 +40,7 @@ private: int m_BlueTeamHomeCapturePoint = m_NotACapturePoint; int m_NumberOfCapturePoints = 0; - std::map m_CapturePointNumberToEntityIDMap; + std::map m_CapturePointNumberToEntityMap; //std::vector @@ -48,8 +48,8 @@ private: bool m_ResetTimers = false; //vectors which will keep track of enter/leave changes - std::vector> m_ETriggerTouchVector; - std::vector> m_ETriggerLeaveVector; + std::vector> m_ETriggerTouchVector; + std::vector> m_ETriggerLeaveVector; }; #endif \ No newline at end of file diff --git a/src/Engine/Collision/CollidableOctreeSystem.cpp b/src/Engine/Collision/CollidableOctreeSystem.cpp index e5da7910..476414dd 100644 --- a/src/Engine/Collision/CollidableOctreeSystem.cpp +++ b/src/Engine/Collision/CollidableOctreeSystem.cpp @@ -8,7 +8,7 @@ void CollidableOctreeSystem::Update(double dt) void CollidableOctreeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) { if (entity.HasComponent("AABB")) { - boost::optional absoluteAABB = Collision::EntityAbsoluteAABB(entity); + boost::optional absoluteAABB = Collision::EntityAbsoluteAABB(entity); if (absoluteAABB) { m_Octree->AddDynamicObject(*absoluteAABB); } diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index b30ae927..aad012da 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -283,7 +283,7 @@ bool attachAABBComponentFromModel(World* world, EntityID id) return true; } -boost::optional EntityAbsoluteAABB(EntityWrapper& entity) +boost::optional EntityAbsoluteAABB(EntityWrapper& entity) { if (!entity.HasComponent("AABB")) { return boost::none; @@ -294,7 +294,11 @@ boost::optional EntityAbsoluteAABB(EntityWrapper& entity) glm::vec3 absScale = Transform::AbsoluteScale(entity.World, entity.ID); glm::vec3 origin = absPosition + (glm::vec3)cAABB["Origin"]; glm::vec3 size = (glm::vec3)cAABB["Size"] * absScale; - return AABB::FromOriginSize(origin, size); + + EntityAABB aabb = EntityAABB::FromOriginSize(origin, size); + aabb.Entity = entity; + + return aabb; } } diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp index ba841e36..3c07db11 100644 --- a/src/Engine/Collision/CollisionSystem.cpp +++ b/src/Engine/Collision/CollisionSystem.cpp @@ -9,12 +9,12 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c } ComponentWrapper& cPhysics = entity["Physics"]; - boost::optional boundingBox = Collision::EntityAbsoluteAABB(entity); + boost::optional boundingBox = Collision::EntityAbsoluteAABB(entity); if (!boundingBox) { return; } ComponentWrapper& cTransform = entity["Transform"]; - AABB& boxA = *boundingBox; + EntityAABB& boxA = *boundingBox; //Press 'Z' to enable/disable collision. if (zPress) { @@ -22,7 +22,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c } // Collide against octree - std::vector octreeResult; + std::vector octreeResult; m_Octree->ObjectsInSameRegion(*boundingBox, octreeResult); for (auto& boxB : octreeResult) { glm::vec3 resolutionVector; diff --git a/src/Engine/Collision/TriggerSystem.cpp b/src/Engine/Collision/TriggerSystem.cpp index ca169e16..dc7c77ff 100644 --- a/src/Engine/Collision/TriggerSystem.cpp +++ b/src/Engine/Collision/TriggerSystem.cpp @@ -3,79 +3,72 @@ #include "Core/AABB.h" #include "Rendering/Model.h" -void TriggerSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) +void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapper& cTrigger, double dt) { - //Currently only players can trigger things. - auto players = m_World->GetComponents("Player"); - if (players == nullptr) { - return; - } - EntityID tId = component.EntityID; - boost::optional triggerBox = Collision::EntityAbsoluteAABB(entity); - //The trigger *should* have a bounding box, or something, to test against so it can be triggered. + // The trigger *should* have a bounding box, or something, to test against so it can be triggered. + boost::optional triggerBox = Collision::EntityAbsoluteAABB(triggerEntity); if (!triggerBox) { return; } - for (auto& pc : *players) { - EntityID pId = pc.EntityID; - boost::optional playerBox = Collision::EntityAbsoluteAABB(EntityWrapper(m_World, pId)); - //The player can't trigger anything without an AABB. - if (!playerBox) { - continue; - } - if (!Collision::AABBVsAABB(*triggerBox, *playerBox)) { - //Entity is not touching the trigger, - //Throw event if it was previously. - if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[tId], pId, tId)) { - continue; - } - //This only occurs if the entity was completely inside the trigger one frame, - //then completely outside the trigger, e.g. when dying and respawning. - throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[tId], pId, tId); - } else { - //Entity is at least touching the trigger. + + m_OctreeOut.clear(); + m_Octree->ObjectsInSameRegion(*triggerBox, m_OctreeOut); + + for (EntityAABB& colliderBox : m_OctreeOut) { + EntityWrapper colliderEntity = colliderBox.Entity; + + if (Collision::AABBVsAABB(*triggerBox, colliderBox)) { AABB completelyInsideBox; - bool playerFitsInTrigger = glm::all(glm::greaterThan((*triggerBox).Size(), (*playerBox).Size())); - if (playerFitsInTrigger) { - completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * (*playerBox).Size()); + bool colliderFitsInTrigger = glm::all(glm::greaterThan((*triggerBox).Size(), colliderBox.Size())); + if (colliderFitsInTrigger) { + completelyInsideBox = AABB::FromOriginSize((*triggerBox).Origin(), (*triggerBox).Size() - 2.0f * colliderBox.Size()); } - if (playerFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, *playerBox)) { - //Entity is completely inside the trigger. - //If it was only touching before, it is erased. - m_EntitiesTouchingTrigger[tId].erase(pId); - std::unordered_set& completeSet = m_EntitiesCompletelyInTrigger[tId]; - if (completeSet.count(pId) == 0) { - //If it wasn't completely in the trigger, throw Enter and add to the set. - completeSet.insert(pId); - publish(pId, tId); + if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox)) { + // Entity is completely inside the trigger. + // If it was only touching before, it is erased. + m_EntitiesTouchingTrigger[triggerEntity].erase(colliderEntity); + auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity]; + if (completeSet.count(colliderEntity) == 0) { + // If it wasn't completely in the trigger, throw Enter and add to the set. + completeSet.insert(colliderEntity); + publish(colliderEntity, triggerEntity); } } else { - //Entity is only touching the trigger. - std::unordered_set& touchSet = m_EntitiesTouchingTrigger[tId]; - std::unordered_set& completeSet = m_EntitiesCompletelyInTrigger[tId]; - const auto& it = completeSet.find(pId); + // Entity is only touching the trigger. + auto& touchSet = m_EntitiesTouchingTrigger[triggerEntity]; + auto& completeSet = m_EntitiesCompletelyInTrigger[triggerEntity]; + const auto& it = completeSet.find(colliderEntity); //If it was completely inside before. if (it != completeSet.end()) { completeSet.erase(it); - touchSet.insert(pId); + touchSet.insert(colliderEntity); //If it was completely outside before. - } else if (touchSet.count(pId) == 0) { - publish(pId, tId); - touchSet.insert(pId); + } else if (touchSet.count(colliderEntity) == 0) { + publish(colliderEntity, triggerEntity); + touchSet.insert(colliderEntity); } - //Else, it was touching the trigger last frame too and nothing is done. + // Else, it was touching the trigger last frame too and nothing is done. } + } else { + // Entity is not touching the trigger, + // Throw event if it was previously. + if (throwLeaveIfWasInTrigger(m_EntitiesTouchingTrigger[triggerEntity], colliderEntity, triggerEntity)) { + continue; + } + // This only occurs if the entity was completely inside the trigger one frame, + // then completely outside the trigger, e.g. when dying and respawning. + throwLeaveIfWasInTrigger(m_EntitiesCompletelyInTrigger[triggerEntity], colliderEntity, triggerEntity); } } } -bool TriggerSystem::throwLeaveIfWasInTrigger(std::unordered_set& triggerSet, EntityID pId, EntityID tId) +bool TriggerSystem::throwLeaveIfWasInTrigger(std::unordered_set& triggerSet, EntityWrapper colliderEntity, EntityWrapper triggerEntity) { - const auto& it = triggerSet.find(pId); + const auto& it = triggerSet.find(colliderEntity); if (it != triggerSet.end()) { //If it was in the trigger, but not anymore, throw leaveEvent and erase from the set. triggerSet.erase(it); - publish(pId, tId); + publish(colliderEntity, triggerEntity); return true; } return false; diff --git a/src/Engine/Core/AABB.cpp b/src/Engine/Core/AABB.cpp index 55b362fe..13e92d9c 100644 --- a/src/Engine/Core/AABB.cpp +++ b/src/Engine/Core/AABB.cpp @@ -20,10 +20,6 @@ AABB::AABB(const glm::vec3& minPos, const glm::vec3& maxPos) } } -AABB::AABB(const glm::vec4& minPos, const glm::vec4& maxPos) - : AABB(glm::vec3(minPos), glm::vec3(maxPos)) -{ } - AABB AABB::FromOriginSize(const glm::vec3& origin, const glm::vec3& size) { return AABB(origin - (size/2.f), origin + (size/2.f)); diff --git a/src/Engine/Core/EntityWrapper.cpp b/src/Engine/Core/EntityWrapper.cpp index 1f3fc1ab..071329a3 100644 --- a/src/Engine/Core/EntityWrapper.cpp +++ b/src/Engine/Core/EntityWrapper.cpp @@ -97,11 +97,6 @@ EntityWrapper::operator EntityID() const return this->ID; } -EntityWrapper::operator bool() -{ - return this->Valid(); -} - EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name, EntityID parent) { if (!this->World->ValidEntity(parent)) { diff --git a/src/Engine/Editor/EditorRenderSystem.cpp b/src/Engine/Editor/EditorRenderSystem.cpp index 2aad1340..7caa4044 100644 --- a/src/Engine/Editor/EditorRenderSystem.cpp +++ b/src/Engine/Editor/EditorRenderSystem.cpp @@ -12,7 +12,7 @@ EditorRenderSystem::EditorRenderSystem(World* m_World, EventBroker* eventBroker, void EditorRenderSystem::Update(double dt) { - if (m_CurrentCamera) { + if (m_CurrentCamera.Valid()) { ComponentWrapper cameraTransform = m_CurrentCamera["Transform"]; m_EditorCamera->SetPosition(cameraTransform["Position"]); m_EditorCamera->SetOrientation(glm::quat((const glm::vec3&)cameraTransform["Orientation"])); diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 903b270f..1f72611b 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -1,5 +1,6 @@ #include "Game.h" #include "Collision/CollidableOctreeSystem.h" +#include "Collision/EntityAABB.h" #include "Collision/TriggerSystem.h" #include "Collision/CollisionSystem.h" #include "Systems/RaptorCopterSystem.h" @@ -42,7 +43,7 @@ Game::Game(int argc, char* argv[]) 0, m_Config->Get("Video.Width", 1280), m_Config->Get("Video.Height", 720) - )); + )); m_Renderer->Initialize(); //m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get("Video.FOV", 90.f))); m_RenderFrame = new RenderFrame(); @@ -72,8 +73,8 @@ Game::Game(int argc, char* argv[]) // Create Octrees - m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); - m_OctreeFrustrumCulling = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); + m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); + m_OctreeFrustrumCulling = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4); // Create system pipeline m_SystemPipeline = new SystemPipeline(m_World, m_EventBroker); diff --git a/src/Game/Systems/CapturePointSystem.cpp b/src/Game/Systems/CapturePointSystem.cpp index fbd20e38..43876822 100644 --- a/src/Game/Systems/CapturePointSystem.cpp +++ b/src/Game/Systems/CapturePointSystem.cpp @@ -13,27 +13,27 @@ CapturePointSystem::CapturePointSystem(World* world, EventBroker* eventBroker) //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& entity, ComponentWrapper& capturePoint, double dt) +void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, ComponentWrapper& cCapturePoint, double dt) { if (m_WinnerWasFound) { return; } - const int capturePointNumber = capturePoint["CapturePointNumber"]; - const bool hasTeamComponent = m_World->HasComponent(capturePoint.EntityID, "Team"); + 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(capturePoint.EntityID, "Team"); - ComponentWrapper& teamComponent = m_World->GetComponent(capturePoint.EntityID, "Team"); + m_World->AttachComponent(cCapturePoint.EntityID, "Team"); + ComponentWrapper& teamComponent = capturePointEntity["Team"]; teamComponent["Team"] = (int)teamComponent["Team"].Enum("Spectator"); } - ComponentWrapper& teamComponent = m_World->GetComponent(capturePoint.EntityID, "Team"); + 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)capturePoint["HomePointForTeam"]; + 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) { @@ -46,8 +46,8 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper } //if we havent received all capturepoints yet, just return - if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityIDMap.size()) { - m_CapturePointNumberToEntityIDMap.insert(std::make_pair(capturePointNumber, capturePoint.EntityID)); + if (m_NumberOfCapturePoints == 0 || m_NumberOfCapturePoints != m_CapturePointNumberToEntityMap.size()) { + m_CapturePointNumberToEntityMap.insert(std::make_pair(capturePointNumber, capturePointEntity)); return; } @@ -55,9 +55,9 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper int ownedBy = teamComponent["Team"]; int redTeamPlayersStandingInside = 0; int blueTeamPlayersStandingInside = 0; - if (entity.HasComponent("Model")) { + if (capturePointEntity.HasComponent("Model")) { //Now sets team color to the capturepoint, or white if it is uncaptured. - entity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 1) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 1) : glm::vec4(1, 1, 1, 1); + capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.2f, 1, 1) : ownedBy == redTeam ? glm::vec4(1, 0.2f, 0, 1) : glm::vec4(1, 1, 1, 1); } //calculate next possible capturePoint for both teams @@ -66,10 +66,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper nextPossibleCapturePoint["Blue"] = -1; for (size_t i = 0; i < m_NumberOfCapturePoints; i++) { - if (!m_World->HasComponent(m_CapturePointNumberToEntityIDMap[i], "Team")) { + if (m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { continue; } - ComponentWrapper& capturePointOwnedBy = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team"); + ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint == 0) { nextPossibleCapturePoint["Red"] = i + 1; } @@ -79,10 +79,10 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper } for (int i = m_NumberOfCapturePoints - 1; i >= 0; i--) { - if (!m_World->HasComponent(m_CapturePointNumberToEntityIDMap[i], "Team")) { + if (!m_CapturePointNumberToEntityMap[i].HasComponent("Team")) { continue; } - ComponentWrapper& capturePointOwnedBy = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "Team"); + ComponentWrapper& capturePointOwnedBy = m_CapturePointNumberToEntityMap[i]["Team"]; if ((int)capturePointOwnedBy["Team"] == redTeam && m_RedTeamHomeCapturePoint != 0) { nextPossibleCapturePoint["Red"] = i - 1; } @@ -95,7 +95,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper if (m_ResetTimers) { for (size_t i = 0; i < m_NumberOfCapturePoints; i++) { - ComponentWrapper& capturePoint = m_World->GetComponent(m_CapturePointNumberToEntityIDMap[i], "CapturePoint"); + ComponentWrapper& capturePoint = m_CapturePointNumberToEntityMap[i]["CapturePoint"]; if ((int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Red"] && (int)capturePoint["CapturePointNumber"] != nextPossibleCapturePoint["Blue"]) { capturePoint["CaptureTimer"] = 0.0; @@ -106,34 +106,34 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper //colorize next possible capturepoint if (nextPossibleCapturePoint["Red"] == capturePointNumber) { - entity["Model"]["Color"] = glm::vec4(1, 1, 0, 1); + capturePointEntity["Model"]["Color"] = glm::vec4(1, 1, 0, 1); } if (nextPossibleCapturePoint["Blue"] == capturePointNumber) { - entity["Model"]["Color"] = glm::vec4(0, 1, 1, 1); + capturePointEntity["Model"]["Color"] = glm::vec4(0, 1, 1, 1); } //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) == capturePoint.EntityID) { + if (std::get<1>(triggerTouched) == capturePointEntity) { //some player has touched this - lets figure out: what team, health - EntityID playerID = std::get<0>(triggerTouched); - if (!m_World->HasComponent(playerID, "Player")) { + EntityWrapper player = std::get<0>(triggerTouched); + 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 = m_World->HasComponent(playerID, "Health"); + bool hasHealthComponent = player.HasComponent("Health"); if (hasHealthComponent) { - double currentHealth = m_World->GetComponent(playerID, "Health")["Health"]; + double currentHealth = player["Health"]["Health"]; //check if player is dead if ((int)currentHealth == 0) { continue; } } //check team - spectatorNumber = "no team" - int teamNumber = m_World->GetComponent(playerID, "Team")["Team"]; + int teamNumber = player["Team"]["Team"]; if (teamNumber == redTeam) { redTeamPlayersStandingInside++; } else if (teamNumber == blueTeam) { @@ -169,24 +169,24 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper //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)capturePoint["CaptureTimer"]) < 0.001f) { + if (abs((double)cCapturePoint["CaptureTimer"]) < 0.001f) { LOG_DEBUG("Point is being captured by team %i", currentTeam); //Remove when we tested sufficiently. } - capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; + 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)capturePoint["CaptureTimer"] < 0.0) || - (ownedBy == currentTeam && currentTeam == blueTeam && (double)capturePoint["CaptureTimer"] > 0.0)) { - capturePoint["CaptureTimer"] = (double)capturePoint["CaptureTimer"] + timerDeltaChange; + 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)capturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) { + if (abs((double)cCapturePoint["CaptureTimer"]) > abs(m_CaptureTimeToTakeOver) && canCapture) { teamComponent["Team"] = currentTeam; - capturePoint["CaptureTimer"] = 0.0; + 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 = capturePoint.EntityID; + e.CapturePointID = cCapturePoint.EntityID; e.TeamNumberThatCapturedCapturePoint = currentTeam; m_EventBroker->Publish(e); //NextPossibleCapturePoint will be calculated in the next update... From 113448dbf035bbd20bacd6324726de0d6a7927c1 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 27 Jan 2016 15:09:23 +0100 Subject: [PATCH 5/7] Added DEBUG preprocessor definition in Debug and RelWithDebInfo mode --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbe8168a..7c98133e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,12 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES) +# DEBUG definition +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS + $<$:DEBUG> + $<$:DEBUG> +) + include(cotire) add_subdirectory(src/Engine) add_subdirectory(src/Game) From 6615fe9438c08e784f56f2893ad961b1ba4654b5 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 27 Jan 2016 15:09:34 +0100 Subject: [PATCH 6/7] Enabled multithreaded build for MSVC --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c98133e..43286658 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ endif() if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +elseif(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") endif() #set(BUILD_SHARED_LIBS FALSE) From 181017313dd1d03f0c4972b6fb927ef3425f3075 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 27 Jan 2016 15:12:34 +0100 Subject: [PATCH 7/7] Made entity parser give more useful errors and fixed the errors that were while I was at it --- include/Engine/Core/Util/Logging.h | 40 +++----------------- resources/Schema/Components/Animation.xml | 1 + resources/Schema/Components/CapturePoint.xsd | 13 +------ resources/Schema/Components/HealthHUD.xml | 2 +- resources/Schema/Components/Team.xsd | 13 +------ resources/Schema/Types/Entity.xsd | 4 +- resources/Schema/Types/TeamEnum.xsd | 17 +++++++++ src/Engine/Core/EntityFile.cpp | 30 ++++++++++----- src/Engine/Core/Util/Logging.cpp | 38 ++++++++++++++++++- src/Engine/Rendering/DrawBloomPass.cpp | 1 - 10 files changed, 86 insertions(+), 73 deletions(-) create mode 100644 resources/Schema/Types/TeamEnum.xsd diff --git a/include/Engine/Core/Util/Logging.h b/include/Engine/Core/Util/Logging.h index 43f2c022..3d027937 100644 --- a/include/Engine/Core/Util/Logging.h +++ b/include/Engine/Core/Util/Logging.h @@ -29,41 +29,9 @@ enum _LOG_LEVEL extern _LOG_LEVEL LOG_LEVEL; -const static char* _LOG_LEVEL_PREFIX[] = -{ - "EE: ", - "", - "WW: ", - "DD: " -}; +extern const char* _LOG_LEVEL_PREFIX[]; -static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...) -{ - if (logLevel > LOG_LEVEL) { - return; - } - - char* message = nullptr; - va_list args; - - va_start(args, format); - size_t size = vsnprintf(message, 0, format, args) + 1; - va_end(args); - - va_start(args, format); - message = new char[size]; - vsnprintf(message, size, format, args); - va_end(args); - - if (logLevel == LOG_LEVEL_ERROR) { - std::cerr << file << ":" << line << " " << func << std::endl; - std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; - } else { - std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; - } - - delete[] message; -} +extern void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...); #define LOG(logLevel, format, ...) \ _LOG(logLevel, __BASE_FILE__, __func__, __LINE__, format, ##__VA_ARGS__) @@ -77,7 +45,11 @@ static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsign #define LOG_INFO(format, ...) \ LOG(LOG_LEVEL_INFO, format, ##__VA_ARGS__) +#ifdef DEBUG #define LOG_DEBUG(format, ...) \ LOG(LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) +#else +#define LOG_DEBUG(format, ...) +#endif #endif // Logging_h__ \ No newline at end of file diff --git a/resources/Schema/Components/Animation.xml b/resources/Schema/Components/Animation.xml index 01af2747..66d2865d 100644 --- a/resources/Schema/Components/Animation.xml +++ b/resources/Schema/Components/Animation.xml @@ -1,5 +1,6 @@ + 0 true diff --git a/resources/Schema/Components/CapturePoint.xsd b/resources/Schema/Components/CapturePoint.xsd index 9e96fca6..91afd366 100644 --- a/resources/Schema/Components/CapturePoint.xsd +++ b/resources/Schema/Components/CapturePoint.xsd @@ -2,18 +2,7 @@ - - - - - - - - - - - - + diff --git a/resources/Schema/Components/HealthHUD.xml b/resources/Schema/Components/HealthHUD.xml index d7e20f92..a48b9606 100644 --- a/resources/Schema/Components/HealthHUD.xml +++ b/resources/Schema/Components/HealthHUD.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/Team.xsd b/resources/Schema/Components/Team.xsd index a81a8978..d6e14684 100755 --- a/resources/Schema/Components/Team.xsd +++ b/resources/Schema/Components/Team.xsd @@ -2,18 +2,7 @@ - - - - - - - - - - - - + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index f105929f..99b90caa 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -47,7 +47,7 @@ - + @@ -55,7 +55,7 @@ - + \ No newline at end of file diff --git a/resources/Schema/Types/TeamEnum.xsd b/resources/Schema/Types/TeamEnum.xsd new file mode 100644 index 00000000..e98e06d3 --- /dev/null +++ b/resources/Schema/Types/TeamEnum.xsd @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Engine/Core/EntityFile.cpp b/src/Engine/Core/EntityFile.cpp index a8e93e49..d5585317 100644 --- a/src/Engine/Core/EntityFile.cpp +++ b/src/Engine/Core/EntityFile.cpp @@ -20,7 +20,7 @@ void EntityFile::Parse(const EntityFileHandler* handler) const { using namespace xercesc; - EntityFileSAXHandler saxHandler(handler, nullptr); + EntityFileSAXHandler saxHandler(handler, m_SAX2XMLReader); setReaderFeatures(m_SAX2XMLReader); m_SAX2XMLReader->setContentHandler(&saxHandler); m_SAX2XMLReader->setErrorHandler(&saxHandler); @@ -37,6 +37,7 @@ void EntityFile::setReaderFeatures(xercesc::SAX2XMLReader* reader) reader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); reader->setFeature(XMLUni::fgXercesSchema, true); reader->setFeature(XMLUni::fgXercesSchemaFullChecking, true); + reader->setFeature(XMLUni::fgXercesCalculateSrcOfs, true); } std::size_t EntityFile::GetTypeStride(std::string typeName) @@ -111,8 +112,9 @@ void EntityFile::WriteValueData(char* outData, const ComponentInfo::Field_t& fie } catch (const boost::bad_lexical_cast&) { } } -EntityFileSAXHandler::EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader) : m_Handler(handler) -, m_Reader(reader) +EntityFileSAXHandler::EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader) + : m_Handler(handler) + , m_Reader(reader) { // 0 is imaginary base parent m_EntityStack.push(0); @@ -188,21 +190,29 @@ void EntityFileSAXHandler::characters(const XMLCh* const chars, const XMLSize_t void EntityFileSAXHandler::fatalError(const xercesc::SAXParseException& e) { - XS::ToString s(e.getMessage()); - LOG_ERROR("SAXParseException: %s", ((std::string)s).c_str()); - //throw e; + std::string message = XS::ToString(e.getMessage()); + std::string systemId = XS::ToString(e.getSystemId()); + XMLFileLoc line = e.getLineNumber(); + XMLFileLoc column = e.getColumnNumber(); + LOG_ERROR("SAXParseException\n\tLocation: %s:%i:%i\n\tFatal Error: %s", systemId.c_str(), line, column, message.c_str()); } void EntityFileSAXHandler::error(const xercesc::SAXParseException& e) { - XS::ToString s(e.getMessage()); - LOG_ERROR("SAXParseException: %s", ((std::string)s).c_str()); + std::string message = XS::ToString(e.getMessage()); + std::string systemId = XS::ToString(e.getSystemId()); + XMLFileLoc line = e.getLineNumber(); + XMLFileLoc column = e.getColumnNumber(); + LOG_ERROR("SAXParseException\n\tLocation: %s:%i:%i\n\tError: %s", systemId.c_str(), line, column, message.c_str()); } void EntityFileSAXHandler::warning(const xercesc::SAXParseException& e) { - XS::ToString s(e.getMessage()); - LOG_ERROR("SAXParseException: %s", ((std::string)s).c_str()); + std::string message = XS::ToString(e.getMessage()); + std::string systemId = XS::ToString(e.getSystemId()); + XMLFileLoc line = e.getLineNumber(); + XMLFileLoc column = e.getColumnNumber(); + LOG_ERROR("SAXParseException\n\tLocation: %s:%i:%i\n\tWarning: %s", systemId.c_str(), line, column, message.c_str()); } void EntityFileSAXHandler::onStartEntity(const xercesc::Attributes& attrs) diff --git a/src/Engine/Core/Util/Logging.cpp b/src/Engine/Core/Util/Logging.cpp index 5c88d98b..63a6f380 100644 --- a/src/Engine/Core/Util/Logging.cpp +++ b/src/Engine/Core/Util/Logging.cpp @@ -4,4 +4,40 @@ _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG; #else _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO; -#endif \ No newline at end of file +#endif + +const char* _LOG_LEVEL_PREFIX[] = +{ + "EE: ", + "", + "WW: ", + "DD: " +}; + +void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...) +{ + if (logLevel > LOG_LEVEL) { + return; + } + + char* message = nullptr; + va_list args; + + va_start(args, format); + size_t size = vsnprintf(message, 0, format, args) + 1; + va_end(args); + + va_start(args, format); + message = new char[size]; + vsnprintf(message, size, format, args); + va_end(args); + + if (logLevel == LOG_LEVEL_ERROR) { + std::cerr << file << ":" << line << " " << func << std::endl; + std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; + } else { + std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl; + } + + delete[] message; +} \ No newline at end of file diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 44c88a16..efd206d3 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -34,7 +34,6 @@ void DrawBloomPass::InitializeShaderPrograms() void DrawBloomPass::InitializeBuffers() { - printf("x:%f\ny:%f", m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height); GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));