From 86f4ff0b3cc74a1ac8ecf874855a0b4bc5ff7463 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 10 Feb 2016 12:38:36 +0100 Subject: [PATCH 1/8] Added an annotation for Trigger and Collideable components. --- resources/Schema/Components/Collidable.xsd | 3 +++ resources/Schema/Components/Trigger.xsd | 3 +++ 2 files changed, 6 insertions(+) diff --git a/resources/Schema/Components/Collidable.xsd b/resources/Schema/Components/Collidable.xsd index 84c66f11..93f7ac24 100644 --- a/resources/Schema/Components/Collidable.xsd +++ b/resources/Schema/Components/Collidable.xsd @@ -4,5 +4,8 @@ + + Needs a Model or AABB component to work, uses AABB if both are attached. + \ No newline at end of file diff --git a/resources/Schema/Components/Trigger.xsd b/resources/Schema/Components/Trigger.xsd index a8bc8865..8119b966 100644 --- a/resources/Schema/Components/Trigger.xsd +++ b/resources/Schema/Components/Trigger.xsd @@ -4,5 +4,8 @@ + + Needs a Model or AABB component to work, uses AABB if both are attached. + \ No newline at end of file From f3a76eb13e2e70d9774a77f95119c0d32df0b4fc Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 10 Feb 2016 15:00:13 +0100 Subject: [PATCH 2/8] Explosion effects should get a proper sized AABB. --- include/Engine/Collision/Collision.h | 1 + src/Engine/Collision/Collision.cpp | 26 +++++++++++++++++++ .../Collision/FillFrustumOctreeSystem.cpp | 16 +++++------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 6e4858b2..8137ceef 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -80,6 +80,7 @@ bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation); // Calculates an absolute AABB from an entity AABB component boost::optional EntityAbsoluteAABB(EntityWrapper& entity); +boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity); } diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index c0c27190..d82ec3fb 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -612,4 +612,30 @@ boost::optional EntityAbsoluteAABB(EntityWrapper& entity) return aabb; } +boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity) +{ + boost::optional modelBox = EntityAbsoluteAABB(entity); + if (!modelBox) { + return boost::none; + } + bool isRandom = (bool)entity["ExplosionEffect"]["Randomness"]; + float random = isRandom ? (float)(double)entity["ExplosionEffect"]["RandomnessScalar"] : 0; + glm::vec3 origin = (glm::vec3)entity["ExplosionEffect"]["ExplosionOrigin"]; + glm::vec3 randomVel = (glm::vec3)entity["ExplosionEffect"]["Velocity"]; + randomVel *= (random + 1); + float endVelocity = randomVel.y; + if ((bool)entity["ExplosionEffect"]["ExponentialAccelaration"]) { + endVelocity *= endVelocity / 2.f; + } + float maxRadius = (float)(double)entity["ExplosionEffect"]["ExplosionDuration"] * endVelocity; + glm::vec3 size; + AABB explosionBox(origin - (size / 2.f), origin + (size / 2.f)); + + glm::vec3 mini = glm::min(explosionBox.MinCorner(), (*modelBox).MinCorner()); + glm::vec3 maxi = glm::max(explosionBox.MaxCorner(), (*modelBox).MaxCorner()); + EntityAABB aabb = AABB(mini, maxi); + aabb.Entity = entity; + return aabb; +} + } diff --git a/src/Engine/Collision/FillFrustumOctreeSystem.cpp b/src/Engine/Collision/FillFrustumOctreeSystem.cpp index f02a30f1..a8835266 100644 --- a/src/Engine/Collision/FillFrustumOctreeSystem.cpp +++ b/src/Engine/Collision/FillFrustumOctreeSystem.cpp @@ -7,15 +7,13 @@ void FillFrustumOctreeSystem::Update(double dt) void FillFrustumOctreeSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) { + boost::optional absoluteAABB; if (entity.HasComponent("ExplosionEffect")) { - //TODO: Fix hack, get real box by using shader equation. - EntityAABB aabb = AABB(glm::vec3(-300), glm::vec3(300)); - aabb.Entity = entity; - m_Octree->AddDynamicObject(aabb); + absoluteAABB = Collision::AbsoluteAABBExplosionEffect(entity); } else { - boost::optional absoluteAABB = Collision::EntityAbsoluteAABB(entity); - if (absoluteAABB) { - m_Octree->AddDynamicObject(*absoluteAABB); - } + absoluteAABB = Collision::EntityAbsoluteAABB(entity); } -} \ No newline at end of file + if (absoluteAABB) { + m_Octree->AddDynamicObject(*absoluteAABB); + } +} From 27cdccac75b2564839609072ec8f02ed8ad9c576 Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 10 Feb 2016 16:10:41 +0100 Subject: [PATCH 3/8] Frustrum octree should only get AABBs derived from Model now. --- include/Engine/Collision/Collision.h | 2 +- src/Engine/Collision/Collision.cpp | 6 +++--- src/Engine/Collision/FillFrustumOctreeSystem.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 86f397f7..c3759393 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -79,7 +79,7 @@ bool AABBVsAABB(const AABB& a, const AABB& b); bool AABBVsAABB(const AABB& a, const AABB& b, glm::vec3& minimumTranslation); // Calculates an absolute AABB from an entity AABB component -boost::optional EntityAbsoluteAABB(EntityWrapper& entity); +boost::optional EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox = false); boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity); } diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp index 07080caf..b7b21969 100644 --- a/src/Engine/Collision/Collision.cpp +++ b/src/Engine/Collision/Collision.cpp @@ -565,10 +565,10 @@ bool AABBvsTriangles(const AABB& box, return hit; } -boost::optional EntityAbsoluteAABB(EntityWrapper& entity) +boost::optional EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox) { AABB modelSpaceBox; - if (entity.HasComponent("AABB")) { + if (entity.HasComponent("AABB") && !takeModelBox) { ComponentWrapper& cAABB = entity["AABB"]; modelSpaceBox = EntityAABB::FromOriginSize((glm::vec3)cAABB["Origin"], (glm::vec3)cAABB["Size"]); } else if (entity.HasComponent("Model")) { @@ -614,7 +614,7 @@ boost::optional EntityAbsoluteAABB(EntityWrapper& entity) boost::optional AbsoluteAABBExplosionEffect(EntityWrapper& entity) { - boost::optional modelBox = EntityAbsoluteAABB(entity); + boost::optional modelBox = EntityAbsoluteAABB(entity, true); if (!modelBox) { return boost::none; } diff --git a/src/Engine/Collision/FillFrustumOctreeSystem.cpp b/src/Engine/Collision/FillFrustumOctreeSystem.cpp index a8835266..2be8bee0 100644 --- a/src/Engine/Collision/FillFrustumOctreeSystem.cpp +++ b/src/Engine/Collision/FillFrustumOctreeSystem.cpp @@ -11,7 +11,7 @@ void FillFrustumOctreeSystem::UpdateComponent(EntityWrapper& entity, ComponentWr if (entity.HasComponent("ExplosionEffect")) { absoluteAABB = Collision::AbsoluteAABBExplosionEffect(entity); } else { - absoluteAABB = Collision::EntityAbsoluteAABB(entity); + absoluteAABB = Collision::EntityAbsoluteAABB(entity, true); } if (absoluteAABB) { m_Octree->AddDynamicObject(*absoluteAABB); From b0bdca5cdd779d4ec16780212e1b394b46ee0763 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Wed, 10 Feb 2016 17:15:08 +0100 Subject: [PATCH 4/8] =?UTF-8?q?SplatMap=20r=C3=A4knas=20r=C3=A4tt=20ny=20o?= =?UTF-8?q?ch=20mitmaps=20i=20Texture.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 2151ad93..b49fe601 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 2151ad934d2ff3f779ae7e4b38c20bbb728cd02d +Subproject commit b49fe60133b1d00a8aa5ada2742484e375337754 From 97780395cfefa0b2913c3dfa294d0cced41dc2f3 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Wed, 10 Feb 2016 17:15:54 +0100 Subject: [PATCH 5/8] ... Now mipmaps and Splatmaps i comming :) --- .../Schema/Entities/SplatMapTesWorld.xml | 8 +++++++- .../Shaders/ForwardPlusSplatMap.frag.glsl | 20 +++++++++---------- src/Engine/Rendering/Texture.cpp | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/resources/Schema/Entities/SplatMapTesWorld.xml b/resources/Schema/Entities/SplatMapTesWorld.xml index 11660a63..fe5718eb 100644 --- a/resources/Schema/Entities/SplatMapTesWorld.xml +++ b/resources/Schema/Entities/SplatMapTesWorld.xml @@ -9,8 +9,14 @@ + + + + + + - Models/Test/SplatMapTest.mesh + Models/Ground.mesh diff --git a/resources/Shaders/ForwardPlusSplatMap.frag.glsl b/resources/Shaders/ForwardPlusSplatMap.frag.glsl index c4908534..239c51b5 100644 --- a/resources/Shaders/ForwardPlusSplatMap.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMap.frag.glsl @@ -151,8 +151,6 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu return vec4(TBN * normalize(NormalMap), 0.0); } -#define TEXTURE_TILE 5.0 - vec4 CalcBlendedTexel(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, sampler2D A, sampler2D D, vec2 R_TileValues, vec2 G_TileValues, vec2 B_TileValues, vec2 A_TileValues, vec2 D_TileValues){ vec4 R_Channel = texture2D(R, Input.TextureCoordinate * R_TileValues); @@ -163,10 +161,11 @@ vec4 CalcBlendedTexel(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, sa float total = blendValue.r + blendValue.g + blendValue.b + blendValue.a; if(total > 1.0f){ - blendValue.r / total; - blendValue.g / total; - blendValue.b / total; - blendValue.a / total; + float totalDiv = 1.0f / total; + blendValue.r = blendValue.r * totalDiv; + blendValue.g = blendValue.g * totalDiv; + blendValue.b = blendValue.b * totalDiv; + blendValue.a = blendValue.a * totalDiv; } float D_percent = clamp( 1.0f - total, 0.0f, 1.0f); @@ -188,10 +187,11 @@ vec4 CalcBlendedNormal(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B, s float total = blendValue.r + blendValue.g + blendValue.b + blendValue.a; if(total > 1.0f){ - blendValue.r / total; - blendValue.g / total; - blendValue.b / total; - blendValue.a / total; + float totalDiv = 1 / total; + blendValue.r = blendValue.r * totalDiv; + blendValue.g = blendValue.g * totalDiv; + blendValue.b = blendValue.b * totalDiv; + blendValue.a = blendValue.a * totalDiv; } float D_percent = clamp( 1.0f - total, 0.0f, 1.0f); diff --git a/src/Engine/Rendering/Texture.cpp b/src/Engine/Rendering/Texture.cpp index 57f3ca36..df197400 100644 --- a/src/Engine/Rendering/Texture.cpp +++ b/src/Engine/Rendering/Texture.cpp @@ -30,9 +30,10 @@ Texture::Texture(std::string path) 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); + glGenerateMipmap(GL_TEXTURE_2D); 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); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); GLERROR("Texture load"); } From 1ba9d97ab7b56a4628dfd7672d1738ddc3ad646d Mon Sep 17 00:00:00 2001 From: stiffly Date: Wed, 10 Feb 2016 17:17:41 +0100 Subject: [PATCH 6/8] Fixed crash when trying to jump, when no player is spawned. --- src/Game/Systems/SoundSystem.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index acb7501c..e3aa49b2 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -25,7 +25,7 @@ void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComp void SoundSystem::Update(double dt) { // Temp for play test. - if(m_DrumsIsPlaying) { + if (m_DrumsIsPlaying) { m_DrumsIsPlaying = !drumTimer(dt); } } @@ -69,6 +69,9 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e) void SoundSystem::playerJumps() { + if (!m_LocalPlayer.Valid()) { + return; + } bool grounded = (bool)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["IsOnGround"]; if (grounded) { Events::PlaySoundOnEntity e; @@ -124,11 +127,11 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) std::vector paths; paths.push_back("Audio/hurt/hurt" + std::to_string(rand) + ".wav"); -// // Breathe -// int ammountOfbreaths = (static_cast(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit -// for (int i = 0; i < ammountOfbreaths; i++) { -// paths.push_back("Audio/exhausted/breath.wav"); -// } + // // Breathe + // int ammountOfbreaths = (static_cast(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit + // for (int i = 0; i < ammountOfbreaths; i++) { + // paths.push_back("Audio/exhausted/breath.wav"); + // } Events::PlayQueueOnEntity ev; ev.Emitter = m_LocalPlayer; ev.FilePaths = paths; @@ -140,7 +143,7 @@ bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) { Events::PlaySoundOnEntity ev; ev.EmitterID = m_LocalPlayer.ID; - ev.FilePath = "Audio/die/die2.wav"; + ev.FilePath = "Audio/die/die2.wav"; m_EventBroker->Publish(ev); return false; } From 67cf0081221fa90b6a259051b1de7156ab27244b Mon Sep 17 00:00:00 2001 From: William Moberg Date: Wed, 10 Feb 2016 18:03:58 +0100 Subject: [PATCH 7/8] Bug fixing. --- include/Engine/Core/Util/IfDebug.h | 2 +- src/Engine/Rendering/Model.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Engine/Core/Util/IfDebug.h b/include/Engine/Core/Util/IfDebug.h index 79cb3a4c..85b64c8d 100644 --- a/include/Engine/Core/Util/IfDebug.h +++ b/include/Engine/Core/Util/IfDebug.h @@ -4,7 +4,7 @@ // } // NOTE: condition statement is not executed at all in release mode. #ifndef DEBUG_IF -#ifndef DEBUG +#ifdef DEBUG #define DEBUG_IF(c) if(c) #else #define DEBUG_IF(c) if(false) diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index 6457c980..0c3d7877 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -135,7 +135,7 @@ Model::Model(std::string fileName) maxi = glm::max(maxi, v.Position); } - m_Box = AABB(maxi, mini); + m_Box = AABB(mini, maxi); } Model::~Model() From f05d0a1b0ce197b6935bcb68bf5c3b5513ab9ec6 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Wed, 10 Feb 2016 22:18:27 +0100 Subject: [PATCH 8/8] assets --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index e0ad8b8d..77bab8c0 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit e0ad8b8d45a79b8f17876f9541cc5e03758ae16c +Subproject commit 77bab8c0f57ef2a5b97a4676c2249979d098f66f