From 5d53472286b3c0e9214dda1cf0f6621e78aaa573 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 27 May 2014 07:08:39 +0200 Subject: [PATCH 01/15] CreateExplosion now Event-based (not tested) --- assets | 2 +- src/Events/CreateExplosion.h | 24 +++++++++++++++++++ vs11/Returngeance/Returngeance.vcxproj | 1 + .../Returngeance/Returngeance.vcxproj.filters | 6 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Events/CreateExplosion.h diff --git a/assets b/assets index 6cc3858..72b93d5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 6cc38589ed77dbb3b9c34c1168d52e0f86e1de46 +Subproject commit 72b93d5750283864f244241e65a38436d05c5f96 diff --git a/src/Events/CreateExplosion.h b/src/Events/CreateExplosion.h new file mode 100644 index 0000000..76f2312 --- /dev/null +++ b/src/Events/CreateExplosion.h @@ -0,0 +1,24 @@ +#ifndef Event_CreateExplosion_h__ +#define Event_CreateExplosion_h__ + +#include "EventBroker.h" +#include +#include + +namespace Events +{ + struct CreateExplosion : Event + { + glm::vec3 Position; + double LifeTime; + int ParticlesToSpawn; + std::string spritePath; + glm::quat RelativeUpOrientation; + float Speed; + float SpreadAngle; + float ParticleScale; + }; + +} + +#endif // Event_CreateExplosion_h__ diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 6a99e47..d0a9467 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -163,6 +163,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 2bf19bf..fccf111 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -158,6 +158,9 @@ {cb06b441-90b8-46ed-b347-4190dac7185b} + + {ddd3c442-7c2f-4690-9308-fcef62deee0b} + @@ -397,6 +400,9 @@ Gameplay\Components + + Particle System\Events + From 571edbc214aa12dd353d23a518ce63944ce9a390 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 27 May 2014 07:09:22 +0200 Subject: [PATCH 02/15] ... even more event-based --- src/Systems/ParticleSystem.cpp | 48 ++++++++++------------------------ src/Systems/ParticleSystem.h | 9 ++++--- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 9b094d3..f16d9ad 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -8,7 +8,7 @@ void Systems::ParticleSystem::Initialize() { m_TransformSystem = m_World->GetSystem(); tempSpawnedExplosions = false; - EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &ParticleSystem::OnKeyUp); + EVENT_SUBSCRIBE_MEMBER(m_EExplosion, &ParticleSystem::CreateExplosion); } void Systems::ParticleSystem::Update(double dt) @@ -225,53 +225,33 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect alpha = spectrum[0] + dAlpha * timeProgress; } -void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale) +bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) { auto explosion = m_World->CreateEntity(); auto emitter = m_World->AddComponent(explosion); - emitter->LifeTime = _lifeTime; - emitter->SpawnCount = _particlesToSpawn; - emitter->Speed = _speed; - emitter->SpreadAngle = _spreadAngle; - emitter->SpawnFrequency = _lifeTime + 20; //temp -// emitter->UseGoalVelocity = true; -// emitter->GoalVelocity = glm::vec3(0,-_speed, 0); + emitter->LifeTime = e.LifeTime; + emitter->SpawnCount = e.ParticlesToSpawn; + emitter->Speed = e.Speed; + emitter->SpreadAngle = e.SpreadAngle; + emitter->SpawnFrequency = e.LifeTime + 20; //temp + // emitter->UseGoalVelocity = true; + // emitter->GoalVelocity = glm::vec3(0,-_speed, 0); m_World->CommitEntity(explosion); auto particleEnt = m_World->CreateEntity(); auto TEMP = m_World->AddComponent(particleEnt); TEMP->Scale = glm::vec3(0); auto spriteComponent = m_World->AddComponent(particleEnt); - spriteComponent->SpriteFile = _spritePath; + spriteComponent->SpriteFile = e.spritePath; m_World->CommitEntity(particleEnt); emitter->ParticleTemplate = particleEnt; - + auto transform = m_World->AddComponent(explosion); - transform->Position = _pos; - transform->Orientation = _relativeUpOri; - + transform->Position = e.Position; + transform->Orientation = e.RelativeUpOrientation; + SpawnParticles(explosion); m_ExplosionEmitters[explosion] = glfwGetTime(); -} -bool Systems::ParticleSystem::OnKeyUp(const Events::KeyUp &e) -{ - if(!tempSpawnedExplosions) - { - if (e.KeyCode == GLFW_KEY_B) - { - tempSpawnedExplosions = true; - CreateExplosion( - glm::vec3(0, 10, 0), - 0.5, - 60, - "Textures/Sprites/NewtonTreeDeleteASAPPlease.png", - glm::angleAxis(glm::pi()/2, glm::vec3(1,0,0)), - 40, - glm::pi(), - 0.5f - ); - } - } return true; } \ No newline at end of file diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index fad8815..f0a10de 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -9,6 +9,7 @@ #include "Components/Sprite.h" #include "EventBroker.h" #include "Events/KeyUp.h" +#include "Events/CreateExplosion.h" #include "Color.h" #include @@ -35,7 +36,7 @@ public: void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void Initialize() override; - void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale); + //void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale); virtual bool OnCommand(const Events::KeyUp &event) { return false; } @@ -54,8 +55,10 @@ private: bool tempSpawnedExplosions; - EventRelay m_EKeyUp; - bool OnKeyUp(const Events::KeyUp &e); +// EventRelay m_EKeyUp; +// bool OnKeyUp(const Events::KeyUp &e); + EventRelay m_EExplosion; + bool CreateExplosion(const Events::CreateExplosion &e); }; From d17450b55499c14b90d3d9a77f550b847afc1b8b Mon Sep 17 00:00:00 2001 From: Stiffly Date: Fri, 30 May 2014 00:12:28 +0200 Subject: [PATCH 03/15] Some Explosion stuff --- src/InputManager.cpp | 14 ++++++++++++++ src/InputManager.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/InputManager.cpp b/src/InputManager.cpp index b20e072..11f21d7 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,6 +85,20 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } + if(m_CurrentKeyState[GLFW_KEY_B]) + { + Events::CreateExplosion e; + e.LifeTime = 1; + e.ParticleScale = 6; + e.ParticlesToSpawn = 50; + e.Position = glm::vec3(0, -20, 40); + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 3; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/SeriousParticle.png"; + EventBroker->Publish(e); + } + // // Lock mouse while holding LMB // if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) // { diff --git a/src/InputManager.h b/src/InputManager.h index 69827ba..94d178d 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -12,6 +12,7 @@ #include "Events/LockMouse.h" #include "Events/GamepadAxis.h" #include "Events/GamepadButton.h" +#include "Events/CreateExplosion.h" class InputManager { From 55db057e5095cd2c29d0e7f4a0d52ca0bff645fe Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 30 May 2014 18:51:11 +0200 Subject: [PATCH 04/15] Texture error checking and removed redundant caching --- src/Texture.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Texture.cpp b/src/Texture.cpp index 373db0d..8d76d39 100755 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -8,13 +8,14 @@ Texture::Texture(std::string path) void Texture::Load(std::string path) { - auto cachedTexture = m_TextureCache.find(path); - if (cachedTexture == m_TextureCache.end()) + m_Texture = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y); + + if (m_Texture == 0) { - m_TextureCache[path] = SOIL_load_OGL_texture(path.c_str(), 0, 0, SOIL_FLAG_INVERT_Y); + LOG_ERROR("SOIL: Failed to load texture \"%s\"", path.c_str()); + return; } - m_Texture = m_TextureCache[path]; glBindTexture(GL_TEXTURE_2D, m_Texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); From 31348e774ecb2ef8f869284334d42c576f8a78c1 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Fri, 30 May 2014 20:00:09 +0200 Subject: [PATCH 05/15] Trying some stuff, this build did not support sprite rendering --- src/GameWorld.cpp | 14 ++++++++++++-- src/InputManager.cpp | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 3eab400..69682b6 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -239,14 +239,24 @@ void GameWorld::Initialize() } { - auto tree = CreateEntity(); + /* auto tree = CreateEntity(); auto transform = AddComponent(tree); transform->Position = glm::vec3(0, -15, 0); auto model = AddComponent(tree); model->ModelFile = "Models/Tree/leafs/Leafs.obj"; model->Transparent = true; - CommitEntity(tree); + CommitEntity(tree);*/ + + + auto thing = CreateEntity(); + auto transform = AddComponent(thing); + transform->Position = glm::vec3(0,15,0); + transform->Scale = glm::vec3(3); +// auto model = AddComponent(thing); +// model->ModelFile = "Models/Barrel/Barrel.obj"; + auto sprite = AddComponent(thing); + sprite->SpriteFile = "Textures/Sprites/SeriousParticle.png"; } EntityID tank1 = CreateTank(1); diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 11f21d7..5e6c942 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,13 +85,13 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } - if(m_CurrentKeyState[GLFW_KEY_B]) + if(m_CurrentKeyState[GLFW_KEY_Z]) { Events::CreateExplosion e; e.LifeTime = 1; e.ParticleScale = 6; - e.ParticlesToSpawn = 50; - e.Position = glm::vec3(0, -20, 40); + e.ParticlesToSpawn = 1; + e.Position = glm::vec3(0, -15, 0); e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); e.Speed = 3; e.SpreadAngle = glm::pi(); From 28c3cf5e1654d9dfb1c2603b36cd75d2e6f27be5 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Fri, 30 May 2014 22:19:03 +0200 Subject: [PATCH 06/15] Optimized ParticleSystem. Still can't see particles though D: --- src/Components/Particle.h | 1 + src/GameWorld.cpp | 92 +++++++++++++-------------- src/Systems/ParticleSystem.cpp | 113 ++++++++++++++++----------------- src/Systems/ParticleSystem.h | 11 +--- 4 files changed, 101 insertions(+), 116 deletions(-) diff --git a/src/Components/Particle.h b/src/Components/Particle.h index d08b1a7..d720dc5 100644 --- a/src/Components/Particle.h +++ b/src/Components/Particle.h @@ -14,6 +14,7 @@ namespace Components std::vector ColorSpectrum; std::vector ScaleSpectrum; double LifeTime; + double SpawnTime; std::vector VelocitySpectrum; std::vector AngularVelocitySpectrum; std::vector OrientationSpectrum; //Keep? diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 93a73ed..95845b9 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -745,29 +745,29 @@ EntityID GameWorld::CreateTank(int playerID) } CommitEntity(wheel); - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); +// auto entity = CreateEntity(tank); +// auto transformComponent = AddComponent(entity); +// transformComponent->Position = glm::vec3(2, -1.7, 2.0); +// transformComponent->Scale = glm::vec3(3, 3, 3); +// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); +// auto emitterComponent = AddComponent(entity); +// emitterComponent->SpawnCount = 2; +// emitterComponent->SpawnFrequency = 0.005; +// emitterComponent->SpreadAngle = glm::pi(); +// emitterComponent->UseGoalVelocity = false; +// emitterComponent->LifeTime = 0.5; +// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); +// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); +// CommitEntity(entity); +// +// auto particleEntity = CreateEntity(entity); +// auto TEMP = AddComponent(particleEntity); +// TEMP->Scale = glm::vec3(0); +// auto spriteComponent = AddComponent(particleEntity); +// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; +// emitterComponent->ParticleTemplate = particleEntity; +// +// CommitEntity(particleEntity); } { @@ -830,29 +830,29 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(wheel); #pragma endregion - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(-2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); +// auto entity = CreateEntity(tank); +// auto transformComponent = AddComponent(entity); +// transformComponent->Position = glm::vec3(-2, -1.7, 2.0); +// transformComponent->Scale = glm::vec3(3, 3, 3); +// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); +// auto emitterComponent = AddComponent(entity); +// emitterComponent->SpawnCount = 2; +// emitterComponent->SpawnFrequency = 0.005; +// emitterComponent->SpreadAngle = glm::pi(); +// emitterComponent->UseGoalVelocity = false; +// emitterComponent->LifeTime = 0.5; +// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); +// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); +// CommitEntity(entity); +// +// auto particleEntity = CreateEntity(entity); +// auto TEMP = AddComponent(particleEntity); +// TEMP->Scale = glm::vec3(0); +// auto spriteComponent = AddComponent(particleEntity); +// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; +// emitterComponent->ParticleTemplate = particleEntity; +// +// CommitEntity(particleEntity); } CommitEntity(tank); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 39ea2fb..a02ea78 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -52,64 +52,59 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID SpawnParticles(entity); emitterComponent->TimeSinceLastSpawn = 0; } + } - std::list::iterator it; - for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();) + auto particleComponent = m_World->GetComponent(entity); + if(particleComponent) + { + EntityID particleID = entity; + auto transformComponent = m_World->GetComponent(particleID); + + double timeLived = glfwGetTime() - particleComponent->SpawnTime; + if(timeLived > particleComponent->LifeTime) { - EntityID particleID = (it)->ParticleID; - auto transformComponent = m_World->GetComponent(particleID); - auto particleComponent = m_World->GetComponent(particleID); + m_World->RemoveEntity(particleID); + } + else + { + // FIX: calculate once + float timeProgress = timeLived / particleComponent->LifeTime; + // ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color); + // Scale interpolation + if(particleComponent->ScaleSpectrum.size() > 1) + VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale); + // Velocity interpolation + if(particleComponent->VelocitySpectrum.size() > 1) + VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity); + - double timeLived = glfwGetTime() - it->SpawnTime; - if(timeLived > particleComponent->LifeTime) + /*// Angular velocity interpolation + if (particleComponent->AngularVelocitySpectrum.size() != 0) { - m_World->RemoveEntity(particleID); - it = m_ParticleEmitter[entity].erase(it); + if(particleComponent->AngularVelocitySpectrum.size() > 1) + { + ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity); + transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); + } + else + { + transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation); + //it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); + } } - else + + //Angular velocity interpolation + if(particleComponent->OrientationSpectrum.size() > 1) { - // FIX: calculate once - float timeProgress = timeLived / particleComponent->LifeTime; - // ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color); - // Scale interpolation - if(particleComponent->ScaleSpectrum.size() > 1) - VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale); - // Velocity interpolation - if(particleComponent->VelocitySpectrum.size() > 1) - VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity); - - // Angular velocity interpolation - if (particleComponent->AngularVelocitySpectrum.size() != 0) - { - if(particleComponent->AngularVelocitySpectrum.size() > 1) - { - ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity); - transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); - } - else - { - transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation); - //it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); - } - } - - //Angular velocity interpolation - if(particleComponent->OrientationSpectrum.size() > 1) - { - VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation); - glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]); - glm::vec3 v2 = (it->Orientation); - glm::vec3 v3 = glm::normalize(glm::cross(v1,v2)); - float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2))); + VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation); + glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]); + glm::vec3 v2 = (it->Orientation); + glm::vec3 v3 = glm::normalize(glm::cross(v1,v2)); + float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2))); - transformComponent->Orientation = glm::angleAxis(angle, v3); - } - - - transformComponent->Position += transformComponent->Velocity * (float)dt; - - it++; - } + transformComponent->Orientation = glm::angleAxis(angle, v3); + }*/ + transformComponent->Position += transformComponent->Velocity * (float)dt; } } } @@ -173,15 +168,13 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) particle->AngularVelocitySpectrum = eComponent->AngularVelocitySpectrum; - ParticleData data; - data.ParticleID = ent; - data.SpawnTime = glfwGetTime(); - if (particle->AngularVelocitySpectrum.size() != 0) - data.AngularVelocity = particle->AngularVelocitySpectrum[0]; - if (particle->OrientationSpectrum.size() != 0) - data.Orientation = particle->OrientationSpectrum[0]; - else data.Orientation = eOrientation * glm::vec3(0,0,-1); - m_ParticleEmitter[emitterID].push_back(data); + particle->SpawnTime = glfwGetTime(); +// if (particle->AngularVelocitySpectrum.size() != 0) +// data.AngularVelocity = particle->AngularVelocitySpectrum[0]; +// if (particle->OrientationSpectrum.size() != 0) +// data.Orientation = particle->OrientationSpectrum[0]; +// else data.Orientation = eOrientation * glm::vec3(0,0,-1); + //m_ParticleEmitter[emitterID].push_back(data); } } diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index 0ecd79c..c7a59f2 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -16,15 +16,6 @@ namespace Systems { - struct ParticleData - { - EntityID ParticleID; - double SpawnTime; - float AngularVelocity; - glm::vec3 Orientation; - Color color; - }; - class ParticleSystem : public System { public: @@ -49,7 +40,7 @@ private: //void ColorInterpolation(double timeProgress, std::vector spectrum, Color &color); void ScalarInterpolation(double timeProgress, std::vector spectrum, float &alpha); void Billboard(); - std::map> m_ParticleEmitter; + //std::map> m_ParticleEmitter; std::map m_TimeSinceLastSpawn; std::map m_ExplosionEmitters; std::shared_ptr m_TransformSystem; From a6906886f590ee0db3009a09e191934da349adcd Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sat, 31 May 2014 03:45:37 +0200 Subject: [PATCH 07/15] Vehicle selection! --- assets | 2 +- src/EventBroker.h | 6 +- src/GUI/Frame.h | 38 +++++-- src/GUI/GameFrame.h | 4 +- src/GUI/PlayerHUD.h | 6 +- src/GUI/TextureFrame.h | 53 ++++++++- src/GUI/VehicleSelection.h | 106 ++++++++++++++++++ src/GUI/Viewport.h | 1 + src/Renderer.cpp | 4 +- src/Renderer.h | 6 + vs11/Returngeance/Returngeance.vcxproj | 1 + .../Returngeance/Returngeance.vcxproj.filters | 3 + 12 files changed, 206 insertions(+), 24 deletions(-) create mode 100644 src/GUI/VehicleSelection.h diff --git a/assets b/assets index fe035e7..d5991da 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit fe035e74bd086cfa924003349711f31133337812 +Subproject commit d5991da346f2ee33353c74c243c2b2d72336c9ed diff --git a/src/EventBroker.h b/src/EventBroker.h index e29437a..5daa273 100644 --- a/src/EventBroker.h +++ b/src/EventBroker.h @@ -139,11 +139,7 @@ template void EventBroker::UnsubscribeAll() { const std::string contextTypeName = typeid(ContextType).name(); - auto contextIt = m_ContextRelays.find(contextTypeName); - if (contextIt != m_ContextRelays.end()) - { - m_ContextRelays.erase(contextIt); - } + m_ContextRelays.erase(contextTypeName); } #endif // MessageRelay_h__ diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index e502fea..2e01b48 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -33,14 +33,14 @@ public: , m_Name("UIParent") , m_Layer(0) , m_Hidden(false) - { } + { Initialize(); } // Create a frame as a child Frame(Frame* parent, std::string name) : m_Name(name) , m_Layer(0) , m_Hidden(false) - { SetParent(std::shared_ptr(parent)); } + { SetParent(std::shared_ptr(parent)); Initialize(); } ::RenderQueue RenderQueue; @@ -89,7 +89,10 @@ public: } int Right() const override { - return Left() + Width; + if (m_Parent) + return std::min(m_Parent->Right(), Left() + Width); + else + return Left() + Width; } int Top() const override { @@ -100,14 +103,26 @@ public: } int Bottom() const override { - return Top() + Height; + if (m_Parent) + return std::min(m_Parent->Bottom(), Top() + Height); + else + return Top() + Height; } Rectangle AbsoluteRectangle() { - return Rectangle(Left(), Top(), Width, Height); + int left = Left(); + int top = Top(); + int width = Right() - left; + int height = Bottom() - top; + return Rectangle(left, top, width, height); } + virtual bool OnKeyDown(const Events::KeyDown &event) { return false; } + virtual bool OnKeyUp(const Events::KeyUp &event) { return false; } + //virtual bool OnMouseDown(const Events::KeyDown &event) { } + //virtual bool OnMouseUp(const Events::KeyDown &event) { } + void UpdateLayered(double dt) { if (this->Hidden()) @@ -137,7 +152,7 @@ public: return; // Draw ourselves - renderer->SetViewport(AbsoluteRectangle()); + renderer->SetScissor(AbsoluteRectangle()); this->Draw(renderer); // Draw children @@ -150,7 +165,7 @@ public: if (child->Hidden()) continue; Rectangle rect = child->AbsoluteRectangle(); - renderer->SetViewport(rect); + renderer->SetScissor(rect); child->Draw(renderer); } } @@ -170,6 +185,15 @@ protected: typedef std::multimap> Children_t; // name -> frame std::map m_Children; // layer -> Children_t +private: + EventRelay m_EKeyDown; + EventRelay m_EKeyUp; + + void Initialize() + { + EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown); + EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp); + } }; } diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 19f66ac..a599fcb 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -6,6 +6,7 @@ #include "GUI/Viewport.h" #include "GUI/TextureFrame.h" #include "GUI/PlayerHUD.h" +#include "VehicleSelection.h" #include "GameWorld.h" @@ -26,7 +27,8 @@ public: vp1 = new Viewport(worldFrame, "Viewport1", m_World); vp1->X = 0; vp1->Width = 640; - new PlayerHUD(vp1, "PlayerHUD", m_World, 1); + //new PlayerHUD(vp1, "PlayerHUD", m_World, 1); + new VehicleSelection(vp1, "VehicleSelection", m_World, 1); vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2->X = vp1->Right(); diff --git a/src/GUI/PlayerHUD.h b/src/GUI/PlayerHUD.h index b094d4c..7ea4dda 100644 --- a/src/GUI/PlayerHUD.h +++ b/src/GUI/PlayerHUD.h @@ -1,9 +1,9 @@ -#include "GUI/Frame.h" -#include "GUI/HealthOverlay.h" - #ifndef GUI_PlayerHUD_h__ #define GUI_PlayerHUD_h__ +#include "GUI/Frame.h" +#include "GUI/HealthOverlay.h" + namespace GUI { diff --git a/src/GUI/TextureFrame.h b/src/GUI/TextureFrame.h index 6018478..f15dfd8 100644 --- a/src/GUI/TextureFrame.h +++ b/src/GUI/TextureFrame.h @@ -13,7 +13,10 @@ public: TextureFrame(Frame* parent, std::string name) : Frame(parent, name) , m_Texture(nullptr) + , m_FadeTexture(nullptr) , m_Color(glm::vec4(1.f, 1.f, 1.f, 1.f)) + , m_FadeDuration(0.f) + , m_CurrentFade(1.f) { } void Draw(std::shared_ptr renderer) override @@ -22,13 +25,28 @@ public: return; RenderQueue.Clear(); - SpriteJob job; - job.TextureID = m_Texture->ResourceID; - job.Texture = *m_Texture; - job.Color = m_Color; - RenderQueue.Add(job); + + // Main texture + { + SpriteJob job; + job.TextureID = m_Texture->ResourceID; + job.Texture = *m_Texture; + job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade); + RenderQueue.Add(job); + } + + // Texture while fading + if (m_FadeTexture && m_CurrentFade < 1) + { + SpriteJob job; + job.TextureID = m_FadeTexture->ResourceID; + job.Texture = *m_FadeTexture; + job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a); + RenderQueue.Add(job); + } renderer->SetCamera(nullptr); + renderer->SetViewport(Rectangle(Left(), Top(), Width, Height)); renderer->DrawFrame(RenderQueue); } @@ -38,12 +56,37 @@ public: m_Texture = ResourceManager->Load<::Texture>("Texture", resourceName); } + void FadeToTexture(std::string resourceName, double duration) + { + m_FadeTexture = m_Texture; + SetTexture(resourceName); + m_FadeDuration = duration; + m_CurrentFade = 0.f; + } + + void Update(double dt) override + { + if (m_CurrentFade < 1) + { + m_CurrentFade += dt / m_FadeDuration; + if (m_CurrentFade > 1) + { + m_FadeTexture = nullptr; + m_CurrentFade = 1; + m_FadeDuration = 0; + } + } + } + glm::vec4 Color() const { return m_Color; } void SetColor(glm::vec4 val) { m_Color = val; } protected: ::Texture* m_Texture; + ::Texture* m_FadeTexture; glm::vec4 m_Color; + float m_FadeDuration; + float m_CurrentFade; }; diff --git a/src/GUI/VehicleSelection.h b/src/GUI/VehicleSelection.h new file mode 100644 index 0000000..bc13c92 --- /dev/null +++ b/src/GUI/VehicleSelection.h @@ -0,0 +1,106 @@ +#ifndef GUI_VehicleSelection_h__ +#define GUI_VehicleSelection_h__ + +#include "GUI/Frame.h" +#include "GUI/HealthOverlay.h" + +namespace GUI +{ + + class VehicleSelection : public Frame + { + public: + VehicleSelection(Frame* parent, std::string name, std::shared_ptr world, int playerID) + : Frame(parent, name) + , m_World(world) + , m_PlayerID(playerID) + { + m_CurrentSelection = 0; + + m_CurrentCoordinate = -m_SelectionCoordinates[0] + glm::vec2(Width / 2.f, Height / 2.f); + m_TargetCoordinate = m_CurrentCoordinate; + m_CurrentSize = m_SelectionSizes[0]; + m_TargetSize = m_CurrentSize; + m_CurrentAlpha = 0.f; + + m_Background = new TextureFrame(this, "VehicleSelectImage1"); + m_Background->X = m_CurrentCoordinate.x; + m_Background->Y = m_CurrentCoordinate.y; + m_Background->Width = m_CurrentSize.x; + m_Background->Height = m_CurrentSize.y; + m_Background->SetTexture("Textures/GUI/VehicleSelection/1.png"); + } + + bool OnKeyUp(const Events::KeyUp &event) override + { + if (event.KeyCode == GLFW_KEY_LEFT) + { + m_CurrentSelection--; + } + else if (event.KeyCode == GLFW_KEY_RIGHT) + { + m_CurrentSelection++; + } + m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 3) ? 3 : m_CurrentSelection); + + std::stringstream ss; + ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png"; + m_Background->FadeToTexture(ss.str(), 1.f); + glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection]; + m_TargetCoordinate = coord + glm::vec2(Width / 2.f, Height / 2.f); + + glm::vec2 size = m_SelectionSizes[m_CurrentSelection]; + m_TargetSize = size; + + return true; + } + + void Update(double dt) override + { + glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate; + m_CurrentCoordinate += posDiff * 2.f * (float)dt; + + glm::vec2 sizeDiff = m_TargetSize - m_CurrentSize; + m_CurrentSize += sizeDiff * 3.f * (float)dt; + + m_CurrentAlpha += (1 - m_CurrentAlpha) * 3.f * (float)dt; + + m_Background->X = m_CurrentCoordinate.x; + m_Background->Y = m_CurrentCoordinate.y; + m_Background->Width = m_CurrentSize.x; + m_Background->Height = m_CurrentSize.y; + } + + protected: + std::shared_ptr m_World; + int m_PlayerID; + int m_CurrentSelection; + static glm::vec2 m_SelectionCoordinates[4]; + static glm::vec2 m_SelectionSizes[4]; + + glm::vec2 m_CurrentCoordinate; + glm::vec2 m_TargetCoordinate; + glm::vec2 m_CurrentSize; + glm::vec2 m_TargetSize; + float m_CurrentAlpha; + + TextureFrame* m_Background; + }; + + glm::vec2 VehicleSelection::m_SelectionCoordinates[4] = { + glm::vec2(339, 506), + glm::vec2(639, 377), + glm::vec2(1249, 399), + glm::vec2(1535, 628) + }; + + glm::vec2 VehicleSelection::m_SelectionSizes[4] = { + glm::vec2(1632, 918), + glm::vec2(1793, 1009), + glm::vec2(1793, 1009), + glm::vec2(1854, 1043) + }; + +} + +#endif // GUI_VehicleSelection_h__ diff --git a/src/GUI/Viewport.h b/src/GUI/Viewport.h index 88af865..44c8e81 100644 --- a/src/GUI/Viewport.h +++ b/src/GUI/Viewport.h @@ -65,6 +65,7 @@ public: return; renderer->SetCamera(m_Camera); + renderer->SetViewport(AbsoluteRectangle()); renderer->DrawWorld(m_Parent->RenderQueue); } diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 4769312..d82d851 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -260,7 +260,7 @@ void Renderer::DrawFrame(RenderQueue &rq) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); - glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClearColor(0.0f, 0.5f, 0.0f, 1.0f); @@ -364,7 +364,7 @@ void Renderer::DrawWorld(RenderQueue &rq) */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); - glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); //glViewport(0, 0, m_Width, m_Height); // Clear G-buffer diff --git a/src/Renderer.h b/src/Renderer.h index ecdecfc..4f76f3a 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -48,6 +48,11 @@ public: m_Viewport = viewport; } + void SetScissor(const Rectangle &scissor) + { + m_Scissor = scissor; + } + void SetCamera(std::shared_ptr camera) { m_Camera = camera; @@ -109,6 +114,7 @@ private: std::unordered_map> m_Cameras; Rectangle m_Viewport; + Rectangle m_Scissor; std::shared_ptr m_Camera; struct Light diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 137e26e..5cf01a5 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -198,6 +198,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 7238a0e..b45e724 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -482,6 +482,9 @@ Physics\Systems + + GUI + From a31e3faa1ff9c90260cee9ca761323a1dfc063de Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sat, 31 May 2014 22:15:00 +0200 Subject: [PATCH 08/15] Linear fade added to particles --- assets | 2 +- src/Components/Particle.h | 1 + src/Components/ParticleEmitter.h | 3 +- src/GameWorld.cpp | 92 ++++++++++++-------------------- src/Systems/ParticleSystem.cpp | 64 +++++++++++++--------- src/Systems/ParticleSystem.h | 8 +-- 6 files changed, 80 insertions(+), 90 deletions(-) diff --git a/assets b/assets index 74035fa..4724dbb 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 74035fae2626e2e62f803cd7d9817d1e47353f69 +Subproject commit 4724dbbd285a35282295661821ef30548ebd550a diff --git a/src/Components/Particle.h b/src/Components/Particle.h index d720dc5..81355db 100644 --- a/src/Components/Particle.h +++ b/src/Components/Particle.h @@ -15,6 +15,7 @@ namespace Components std::vector ScaleSpectrum; double LifeTime; double SpawnTime; + bool Fade; std::vector VelocitySpectrum; std::vector AngularVelocitySpectrum; std::vector OrientationSpectrum; //Keep? diff --git a/src/Components/ParticleEmitter.h b/src/Components/ParticleEmitter.h index 03eaf05..01ed05c 100755 --- a/src/Components/ParticleEmitter.h +++ b/src/Components/ParticleEmitter.h @@ -30,9 +30,10 @@ struct ParticleEmitter : Component float SpreadAngle; double LifeTime; bool UseGoalVelocity; + bool Fade; glm::vec3 GoalVelocity; std::vector AngularVelocitySpectrum; - std::vector OrientationSpectrum; //Keep? + std::vector OrientationSpectrum; //Keep? noo.. private: double TimeSinceLastSpawn; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index ef15a7f..60473be 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -252,14 +252,14 @@ void GameWorld::Initialize() CommitEntity(tree);*/ - auto thing = CreateEntity(); - auto transform = AddComponent(thing); - transform->Position = glm::vec3(0,15,0); - transform->Scale = glm::vec3(3); -// auto model = AddComponent(thing); -// model->ModelFile = "Models/Barrel/Barrel.obj"; - auto sprite = AddComponent(thing); - sprite->SpriteFile = "Textures/Sprites/SeriousParticle.png"; +// auto thing = CreateEntity(); +// auto transform = AddComponent(thing); +// transform->Position = glm::vec3(0,15,0); +// transform->Scale = glm::vec3(3); +// // auto model = AddComponent(thing); +// // model->ModelFile = "Models/Barrel/Barrel.obj"; +// auto sprite = AddComponent(thing); +// sprite->SpriteFile = "Textures/Sprites/SeriousParticle.png"; } EntityID tank1 = CreateTank(1); @@ -745,31 +745,31 @@ EntityID GameWorld::CreateTank(int playerID) } CommitEntity(wheel); - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - { - auto particleEntity = CreateEntity(entity); - auto templateComponent = AddComponent(particleEntity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - CommitEntity(particleEntity); - emitterComponent->ParticleTemplate = particleEntity; - } +// auto entity = CreateEntity(tank); +// auto transformComponent = AddComponent(entity); +// transformComponent->Position = glm::vec3(2, -1.7, 2.0); +// transformComponent->Scale = glm::vec3(3, 3, 3); +// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); +// auto emitterComponent = AddComponent(entity); +// emitterComponent->SpawnCount = 2; +// emitterComponent->SpawnFrequency = 0.005; +// emitterComponent->SpreadAngle = glm::pi(); +// emitterComponent->UseGoalVelocity = false; +// emitterComponent->LifeTime = 0.5; +// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); +// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); +// CommitEntity(entity); +// +// { +// auto particleEntity = CreateEntity(entity); +// auto templateComponent = AddComponent(particleEntity); +// auto TEMP = AddComponent(particleEntity); +// TEMP->Scale = glm::vec3(0); +// auto spriteComponent = AddComponent(particleEntity); +// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; +// CommitEntity(particleEntity); +// emitterComponent->ParticleTemplate = particleEntity; +// } } { @@ -832,31 +832,7 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(wheel); #pragma endregion - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(-2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - { - auto particleEntity = CreateEntity(entity); - auto templateComponent = AddComponent(particleEntity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - CommitEntity(particleEntity); - emitterComponent->ParticleTemplate = particleEntity; - } + } CommitEntity(tank); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index a02ea78..df47cf6 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -22,12 +22,14 @@ void Systems::ParticleSystem::Update(double dt) double timeLived = glfwGetTime() - spawnTime; auto eComp = m_World->GetComponent(explosionID); - if(timeLived > eComp->LifeTime) + if(timeLived > eComp->LifeTime && m_ParticlesToEmitter[explosionID] == NULL) { + auto e = m_World->GetComponent(explosionID); + m_World->RemoveEntity(e->ParticleTemplate); m_World->RemoveEntity(explosionID); it = m_ExplosionEmitters.erase(it); //LOG_INFO("Deleted explosion emitter successfully"); - LOG_INFO("Deleted explosion emitter successfully"); + //LOG_INFO("Deleted explosion emitter successfully. nr of emitters%i", m_ExplosionEmitters.size()); } else { @@ -47,26 +49,34 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID { emitterComponent->TimeSinceLastSpawn += dt; auto emitterTransformComponent = m_World->GetComponent(entity); - if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency) - { - SpawnParticles(entity); - emitterComponent->TimeSinceLastSpawn = 0; - } +// if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency) +// { +// SpawnParticles(entity); +// emitterComponent->TimeSinceLastSpawn = 0; +// } } auto particleComponent = m_World->GetComponent(entity); if(particleComponent) { - EntityID particleID = entity; - auto transformComponent = m_World->GetComponent(particleID); + + EntityID particleID = entity; double timeLived = glfwGetTime() - particleComponent->SpawnTime; + if(timeLived > particleComponent->LifeTime) { m_World->RemoveEntity(particleID); + m_ParticlesToEmitter.erase(particleID); + + LOG_INFO("Removed a particle: %i", particleID); + return; } else { + auto transformComponent = m_World->GetComponent(particleID); + auto eComponent = m_World->GetComponent(m_ParticlesToEmitter[particleID]); + auto sprite = m_World->GetComponent(entity); // FIX: calculate once float timeProgress = timeLived / particleComponent->LifeTime; // ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color); @@ -76,8 +86,16 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID // Velocity interpolation if(particleComponent->VelocitySpectrum.size() > 1) VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity); - - + + if(particleComponent->Fade == true) + { + std::vector spectrum; + spectrum.push_back(1); + spectrum.push_back(0); + float alpha; + ScalarInterpolation(timeProgress, spectrum, alpha); + sprite->Color.w = alpha; + } /*// Angular velocity interpolation if (particleComponent->AngularVelocitySpectrum.size() != 0) { @@ -123,11 +141,11 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) glm::vec3 ePosition = m_TransformSystem->AbsolutePosition(emitterID); glm::quat eOrientation = eTransform->Orientation; glm::vec3 paticleSpeed = glm::vec3(eComponent->Speed); - for(int i = 0; i < eComponent->SpawnCount; i++) { auto ent = m_World->CloneEntity(eComponent->ParticleTemplate); - + LOG_INFO("Spawned a particle: %i", ent); + m_ParticlesToEmitter.insert(std::make_pair(ent, emitterID)); auto particleTransform = m_World->GetComponent(ent); particleTransform->Position = ePosition; @@ -143,6 +161,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) particle->LifeTime = eComponent->LifeTime; particle->ScaleSpectrum = eComponent->ScaleSpectrum; particle->VelocitySpectrum.push_back(particleTransform->Velocity); + particle->Fade = eComponent->Fade; if (eComponent->ScaleSpectrum.size() > 0) { @@ -194,23 +213,13 @@ void Systems::ParticleSystem::VectorInterpolation(double timeProgress, std::vect dAxisValue = glm::abs(spectrum[0].y - spectrum[1].y); if (spectrum[0].y > spectrum[1].y) dAxisValue *= -1; - v.y = spectrum[0].y + dAxisValue * timeProgress; + v.y = spectrum[0].y + dAxisValue * timeProgress; dAxisValue = glm::abs(spectrum[0].z - spectrum[1].z); if(spectrum[0].z > spectrum[1].z) dAxisValue *= -1; v.z = spectrum[0].z + dAxisValue * timeProgress; } -// void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector spectrum, Color &c) -// { -// float dColor = glm::abs(spectrum[0].r - spectrum[1].r); -// c.r = spectrum[0].r + dColor * timeProgress; -// dColor = glm::abs(spectrum[0].g - spectrum[1].g); -// c.g = spectrum[0].g + dColor * timeProgress; -// dColor = glm::abs(spectrum[0].b - spectrum[1].b); -// c.b = spectrum[0].b + dColor * timeProgress; -// } - void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vector spectrum, float &alpha) { float dAlpha = glm::abs(spectrum[0] - spectrum[1]); @@ -221,20 +230,22 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) { + LOG_INFO("Spawning an explosion"); auto explosion = m_World->CreateEntity(); auto emitter = m_World->AddComponent(explosion); emitter->LifeTime = e.LifeTime; emitter->SpawnCount = e.ParticlesToSpawn; emitter->Speed = e.Speed; emitter->SpreadAngle = e.SpreadAngle; + emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale)); emitter->SpawnFrequency = e.LifeTime + 20; //temp - // emitter->UseGoalVelocity = true; + emitter->Fade = true; // emitter->GoalVelocity = glm::vec3(0,-_speed, 0); m_World->CommitEntity(explosion); auto particleEnt = m_World->CreateEntity(); + auto templateComponent = m_World->AddComponent(particleEnt); auto TEMP = m_World->AddComponent(particleEnt); - TEMP->Scale = glm::vec3(0); auto spriteComponent = m_World->AddComponent(particleEnt); spriteComponent->SpriteFile = e.spritePath; m_World->CommitEntity(particleEnt); @@ -244,6 +255,7 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) transform->Position = e.Position; transform->Orientation = e.RelativeUpOrientation; + LOG_INFO("Now we should spawn 1 particle!!!!!! not 2 :("); SpawnParticles(explosion); m_ExplosionEmitters[explosion] = glfwGetTime(); diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index c7a59f2..f70cc9d 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -37,12 +37,10 @@ private: float RandomizeAngle(float spreadAngle); //void ScaleInterpolation(double timeProgress, std::vector spectrum, glm::vec3 &scale); void VectorInterpolation(double timeProgress, std::vector spectrum, glm::vec3 &velocity); - //void ColorInterpolation(double timeProgress, std::vector spectrum, Color &color); void ScalarInterpolation(double timeProgress, std::vector spectrum, float &alpha); void Billboard(); //std::map> m_ParticleEmitter; - std::map m_TimeSinceLastSpawn; - std::map m_ExplosionEmitters; + std::shared_ptr m_TransformSystem; bool tempSpawnedExplosions; @@ -51,7 +49,9 @@ private: // bool OnKeyUp(const Events::KeyUp &e); EventRelay m_EExplosion; bool CreateExplosion(const Events::CreateExplosion &e); - + + std::map m_ExplosionEmitters; + std::map m_ParticlesToEmitter; }; } From d40750243284633e62b9a116cda975cf8dde9fc3 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sat, 31 May 2014 22:15:44 +0200 Subject: [PATCH 09/15] CreateExplosion event published on shell collision now. --- src/InputManager.cpp | 13 ------------- src/InputManager.h | 1 - src/Systems/TankSteeringSystem.cpp | 23 +++++++++++++++++++++++ src/Systems/TankSteeringSystem.h | 1 + 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 5e6c942..01d61ba 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,19 +85,6 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } - if(m_CurrentKeyState[GLFW_KEY_Z]) - { - Events::CreateExplosion e; - e.LifeTime = 1; - e.ParticleScale = 6; - e.ParticlesToSpawn = 1; - e.Position = glm::vec3(0, -15, 0); - e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); - e.Speed = 3; - e.SpreadAngle = glm::pi(); - e.spritePath = "Textures/Sprites/SeriousParticle.png"; - EventBroker->Publish(e); - } // // Lock mouse while holding LMB // if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) diff --git a/src/InputManager.h b/src/InputManager.h index 94d178d..69827ba 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -12,7 +12,6 @@ #include "Events/LockMouse.h" #include "Events/GamepadAxis.h" #include "Events/GamepadButton.h" -#include "Events/CreateExplosion.h" class InputManager { diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 5809fd9..bf72fc7 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -126,6 +126,29 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) auto physicsComponents = m_World->GetComponentsOfType(); auto shellTransform = m_World->GetComponent(shellEntity); //auto otherTransform = m_World->GetComponent(otherEntity); + + { + Events::CreateExplosion e; + e.LifeTime = 2; + e.ParticleScale = 8; + e.ParticlesToSpawn = 10; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 3; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Smoke1.png"; + EventBroker->Publish(e); + e.LifeTime = 1; + e.ParticleScale = 12; + e.ParticlesToSpawn = 10; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 6; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Fire.png"; + EventBroker->Publish(e); + } + for (auto &physComponent : *physicsComponents) { EntityID physicsEntity = std::dynamic_pointer_cast(physComponent)->Entity; diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 9a9c696..f3115a6 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -5,6 +5,7 @@ #include "Events/SetVelocity.h" #include "Events/ApplyForce.h" #include "Events/ApplyPointImpulse.h" +#include "Events/CreateExplosion.h" #include "Events/Collision.h" #include "Components/Transform.h" #include "Components/TankSteering.h" From cea2faaaf86a58a6cea8f54621cc046a5bd58358 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sat, 31 May 2014 23:14:13 +0200 Subject: [PATCH 10/15] Removed unnecessary info messages --- src/Systems/ParticleSystem.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index df47cf6..9b4f682 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -69,7 +69,6 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID m_World->RemoveEntity(particleID); m_ParticlesToEmitter.erase(particleID); - LOG_INFO("Removed a particle: %i", particleID); return; } else @@ -144,7 +143,6 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) for(int i = 0; i < eComponent->SpawnCount; i++) { auto ent = m_World->CloneEntity(eComponent->ParticleTemplate); - LOG_INFO("Spawned a particle: %i", ent); m_ParticlesToEmitter.insert(std::make_pair(ent, emitterID)); auto particleTransform = m_World->GetComponent(ent); particleTransform->Position = ePosition; @@ -255,7 +253,6 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) transform->Position = e.Position; transform->Orientation = e.RelativeUpOrientation; - LOG_INFO("Now we should spawn 1 particle!!!!!! not 2 :("); SpawnParticles(explosion); m_ExplosionEmitters[explosion] = glfwGetTime(); From 756107363e83e2a47587c009a762edae71f8ef92 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sun, 1 Jun 2014 01:15:53 +0200 Subject: [PATCH 11/15] Some pretty darn cool explosions --- assets | 2 +- src/Components/Particle.h | 1 - src/Components/ParticleEmitter.h | 5 +++-- src/Events/CreateExplosion.h | 5 ++++- src/Renderer.cpp | 2 +- src/Renderer.h | 2 +- src/Systems/ParticleSystem.cpp | 15 ++++++++++++++- src/Systems/TankSteeringSystem.cpp | 24 ++++++++++++++++++------ 8 files changed, 42 insertions(+), 14 deletions(-) diff --git a/assets b/assets index 4724dbb..bd74626 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 4724dbbd285a35282295661821ef30548ebd550a +Subproject commit bd746269ffaf3abc61c0c8ed5d116b317a4cdd68 diff --git a/src/Components/Particle.h b/src/Components/Particle.h index 81355db..065ab62 100644 --- a/src/Components/Particle.h +++ b/src/Components/Particle.h @@ -11,7 +11,6 @@ namespace Components struct Particle : Component { - std::vector ColorSpectrum; std::vector ScaleSpectrum; double LifeTime; double SpawnTime; diff --git a/src/Components/ParticleEmitter.h b/src/Components/ParticleEmitter.h index 01ed05c..f7cb678 100755 --- a/src/Components/ParticleEmitter.h +++ b/src/Components/ParticleEmitter.h @@ -19,13 +19,14 @@ struct ParticleEmitter : Component , SpawnCount(0) , SpreadAngle(0) , LifeTime(0) - , TimeSinceLastSpawn(100) { } // TEMP fulhack så att partiklarna spawnar direkt + , TimeSinceLastSpawn(100) + , Color(glm::vec4(0)) { } EntityID ParticleTemplate; float SpawnFrequency; float Speed; int SpawnCount; - std::vector ColorSpectrum; + glm::vec4 Color; std::vector ScaleSpectrum; float SpreadAngle; double LifeTime; diff --git a/src/Events/CreateExplosion.h b/src/Events/CreateExplosion.h index 76f2312..0fb6310 100644 --- a/src/Events/CreateExplosion.h +++ b/src/Events/CreateExplosion.h @@ -9,14 +9,17 @@ namespace Events { struct CreateExplosion : Event { + CreateExplosion() + : Color(glm::vec4(0)) {} glm::vec3 Position; + glm::vec4 Color; double LifeTime; int ParticlesToSpawn; std::string spritePath; glm::quat RelativeUpOrientation; float Speed; float SpreadAngle; - float ParticleScale; + std::vector ParticleScale; }; } diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 142f7ec..64c74e5 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -163,7 +163,7 @@ void Renderer::LoadContent() FrameBufferTextures(); m_sphereModel = ResourceManager->Load("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"); - m_Skybox = std::make_shared("Textures/Skybox/sky36", "jpg"); + m_Skybox = std::make_shared("Textures/Skybox/sunset", "jpg"); } void Renderer::Draw(double dt) diff --git a/src/Renderer.h b/src/Renderer.h index dacc6db..432e21d 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -201,7 +201,7 @@ private: void CreateNormalMapTangent(); void ForwardRendering(RenderQueue &rq); - static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } + static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth > j->Depth); } GLuint CreateQuad(); void DrawDebugShadowMap(); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 9b4f682..45c3646 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -95,6 +95,9 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID ScalarInterpolation(timeProgress, spectrum, alpha); sprite->Color.w = alpha; } + + + /*// Angular velocity interpolation if (particleComponent->AngularVelocitySpectrum.size() != 0) { @@ -161,6 +164,10 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) particle->VelocitySpectrum.push_back(particleTransform->Velocity); particle->Fade = eComponent->Fade; + auto sprite = m_World->GetComponent(ent); + if(eComponent->Color != glm::vec4(0)) + sprite->Color = eComponent->Color; + if (eComponent->ScaleSpectrum.size() > 0) { if (eComponent->ScaleSpectrum.size() > 1) @@ -235,9 +242,15 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) emitter->SpawnCount = e.ParticlesToSpawn; emitter->Speed = e.Speed; emitter->SpreadAngle = e.SpreadAngle; - emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale)); + //emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale)); emitter->SpawnFrequency = e.LifeTime + 20; //temp emitter->Fade = true; + emitter->Color = e.Color; + std::vector scale; + scale.push_back(glm::vec3(e.ParticleScale[0])); + if(e.ParticleScale.size() >= 2) + scale.push_back(glm::vec3(e.ParticleScale[1])); + emitter->ScaleSpectrum = scale; // emitter->GoalVelocity = glm::vec3(0,-_speed, 0); m_World->CommitEntity(explosion); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 94f4f25..55ad7c5 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -130,23 +130,35 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) { Events::CreateExplosion e; - e.LifeTime = 2; - e.ParticleScale = 8; - e.ParticlesToSpawn = 10; + e.LifeTime = 3; + e.ParticleScale.push_back(8); + e.ParticlesToSpawn = 20; e.Position = shellTransform->Position; e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); e.Speed = 3; e.SpreadAngle = glm::pi(); e.spritePath = "Textures/Sprites/Smoke1.png"; + e.Color = glm::vec4(0.6,0.6,0.6,1); EventBroker->Publish(e); - e.LifeTime = 1; - e.ParticleScale = 12; + e.LifeTime = 0.7; + e.ParticleScale.push_back(12); e.ParticlesToSpawn = 10; e.Position = shellTransform->Position; e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 17; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Fire.png"; + EventBroker->Publish(e); + e.LifeTime = 0.2; + e.ParticleScale.push_back(1); + e.ParticleScale.push_back(15); + e.ParticlesToSpawn = 5; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); e.Speed = 6; e.SpreadAngle = glm::pi(); - e.spritePath = "Textures/Sprites/Fire.png"; + e.spritePath = "Textures/Sprites/Blast1.png"; + e.Color = glm::vec4(2, 2, 2, 0.2); EventBroker->Publish(e); } From 72420d42487fe09bf1cf87e63e78cb2efe3d71ab Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sun, 1 Jun 2014 03:05:42 +0200 Subject: [PATCH 12/15] WIP Fullscreen Stuff (UI not scaling properly yet) --- assets | 2 +- src/Engine.h | 10 ++++++---- src/GUI/Frame.h | 4 ++++ src/GUI/GameFrame.h | 4 ++-- src/Renderer.cpp | 14 +++++++++----- src/Renderer.h | 12 ++++++++++++ 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/assets b/assets index d5991da..7cfd17f 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d5991da346f2ee33353c74c243c2b2d72336c9ed +Subproject commit 7cfd17fb7b5c91c3e1f8fad6f3cc737f9483b6e7 diff --git a/src/Engine.h b/src/Engine.h index 22f8451..7094615 100755 --- a/src/Engine.h +++ b/src/Engine.h @@ -25,16 +25,18 @@ public: m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load("OBJ", resourceName)); }); m_ResourceManager->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); }); + m_FrameStack = new GUI::Frame(m_EventBroker, m_ResourceManager); + m_FrameStack->Width = 1920; + m_FrameStack->Height = 1080; + m_Renderer = std::make_shared(m_ResourceManager); + m_Renderer->SetFullscreen(true); + m_Renderer->SetResolution(*static_cast(m_FrameStack)); m_Renderer->Initialize(); m_InputManager = std::make_shared(m_Renderer->GetWindow(), m_EventBroker); - m_FrameStack = new GUI::Frame(m_EventBroker, m_ResourceManager); - m_FrameStack->Width = 1280; - m_FrameStack->Height = 720; new GUI::GameFrame(m_FrameStack, "GameFrame"); - //m_World = std::make_shared(m_EventBroker, m_ResourceManager); //m_World->Initialize(); diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index 2e01b48..e40d73a 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -25,6 +25,9 @@ public: Bottom }; + static const float BaseWidth = 1280.f; + static const float BaseHeight = 720.f; + // Set up a base frame with an event broker Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) : EventBroker(eventBroker) @@ -180,6 +183,7 @@ protected: std::string m_Name; int m_Layer; bool m_Hidden; + glm::vec2 Scale; std::shared_ptr m_Parent; typedef std::multimap> Children_t; // name -> frame diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index a599fcb..6bd5b2f 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -26,13 +26,13 @@ public: { vp1 = new Viewport(worldFrame, "Viewport1", m_World); vp1->X = 0; - vp1->Width = 640; + vp1->Width = this->Width / 2.f; //new PlayerHUD(vp1, "PlayerHUD", m_World, 1); new VehicleSelection(vp1, "VehicleSelection", m_World, 1); vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2->X = vp1->Right(); - vp2->Width = 640; + vp2->Width = this->Width / 2.f; new PlayerHUD(vp2, "PlayerHUD", m_World, 2); m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index d82d851..0c1fd1d 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -5,6 +5,9 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager) : ResourceManager(resourceManager) { m_VSync = false; + m_Fullscreen = false; + m_Width = 1280; + m_Height = 720; #ifdef DEBUG m_DrawNormals = false; m_DrawWireframe = false; @@ -38,11 +41,12 @@ void Renderer::Initialize() } // Create a window - m_Width = 1280; - m_Height = 720; - // Antialiasing - //glfwWindowHint(GLFW_SAMPLES, 16); - m_Window = glfwCreateWindow(m_Width, m_Height, "OpenGL", nullptr, nullptr); + GLFWmonitor* monitor = nullptr; + if (m_Fullscreen) + { + monitor = glfwGetPrimaryMonitor(); + } + m_Window = glfwCreateWindow(m_Width, m_Height, "OpenGL", monitor, nullptr); if (!m_Window) { LOG_ERROR("GLFW: Failed to create window"); diff --git a/src/Renderer.h b/src/Renderer.h index 4f76f3a..9116b67 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -43,6 +43,17 @@ public: void UpdateCamera(int cameraIdentifier, glm::vec3 position, glm::quat orientation, float FOV, float nearClip, float farClip); #pragma region NEWSTUFF + void SetResolution(const Rectangle &resolution) + { + m_Width = resolution.Width; + m_Height = resolution.Height; + } + + void SetFullscreen(bool fullscreen) + { + m_Fullscreen = fullscreen; + } + void SetViewport(const Rectangle &viewport) { m_Viewport = viewport; @@ -99,6 +110,7 @@ public: private: std::shared_ptr<::ResourceManager> ResourceManager; + bool m_Fullscreen; int m_Width, m_Height; struct Viewport From 61fab09ceb832bb689a233ce5000a7759dd422f1 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 2 Jun 2014 16:07:17 +0200 Subject: [PATCH 13/15] UI scaling properly --- src/GUI/Frame.h | 13 ++++++++++--- src/GUI/VehicleSelection.h | 19 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index e40d73a..47d5146 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -25,8 +25,8 @@ public: Bottom }; - static const float BaseWidth = 1280.f; - static const float BaseHeight = 720.f; + static const int BaseWidth = 1280; + static const int BaseHeight = 720; // Set up a base frame with an event broker Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) @@ -112,6 +112,14 @@ public: return Top() + Height; } + glm::vec2 Scale() + { + if (m_Parent) + return m_Parent->Scale(); + else + return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight); + } + Rectangle AbsoluteRectangle() { int left = Left(); @@ -183,7 +191,6 @@ protected: std::string m_Name; int m_Layer; bool m_Hidden; - glm::vec2 Scale; std::shared_ptr m_Parent; typedef std::multimap> Children_t; // name -> frame diff --git a/src/GUI/VehicleSelection.h b/src/GUI/VehicleSelection.h index bc13c92..fa11ceb 100644 --- a/src/GUI/VehicleSelection.h +++ b/src/GUI/VehicleSelection.h @@ -15,11 +15,17 @@ namespace GUI , m_World(world) , m_PlayerID(playerID) { + ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/1.png"); + ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/2.png"); + ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/3.png"); + ResourceManager->Preload("Texture", "Textures/GUI/VehicleSelection/4.png"); + m_CurrentSelection = 0; - m_CurrentCoordinate = -m_SelectionCoordinates[0] + glm::vec2(Width / 2.f, Height / 2.f); + glm::vec2 scale = Scale(); + m_CurrentCoordinate = -m_SelectionCoordinates[0] * scale + glm::vec2(Width / 2.f, Height / 2.f); m_TargetCoordinate = m_CurrentCoordinate; - m_CurrentSize = m_SelectionSizes[0]; + m_CurrentSize = m_SelectionSizes[0] * scale; m_TargetSize = m_CurrentSize; m_CurrentAlpha = 0.f; @@ -46,17 +52,20 @@ namespace GUI std::stringstream ss; ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png"; m_Background->FadeToTexture(ss.str(), 1.f); - glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection]; - m_TargetCoordinate = coord + glm::vec2(Width / 2.f, Height / 2.f); + glm::vec2 scale = Scale(); + glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection]; + m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f); glm::vec2 size = m_SelectionSizes[m_CurrentSelection]; - m_TargetSize = size; + m_TargetSize = size * scale; return true; } void Update(double dt) override { + + glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate; m_CurrentCoordinate += posDiff * 2.f * (float)dt; From 27bfbd2025fdf37ad976da5ea113c71a0f24ef64 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 2 Jun 2014 17:00:45 +0200 Subject: [PATCH 14/15] Fixed free cam viewport toggle bug --- src/GUI/GameFrame.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 6bd5b2f..1100dc9 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -19,8 +19,6 @@ public: GameFrame(Frame* parent, std::string name) : Frame(parent, name) { - EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &GameFrame::OnKeyUp); - m_World = std::make_shared(EventBroker, ResourceManager); auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World); { @@ -36,7 +34,7 @@ public: new PlayerHUD(vp2, "PlayerHUD", m_World, 2); m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World); - m_FreeCamViewport->Show(); + m_FreeCamViewport->Hide(); } m_World->Initialize(); } @@ -49,7 +47,7 @@ private: Viewport* vp2; Viewport* m_FreeCamViewport; - bool OnKeyUp(const Events::KeyUp &event) + bool OnKeyUp(const Events::KeyUp &event) override { if (event.KeyCode == GLFW_KEY_1) { From 94fc516a6914a638d2f9851bcd289e08fc9236fe Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 2 Jun 2014 17:01:07 +0200 Subject: [PATCH 15/15] Cleanup --- src/Engine.h | 2 +- src/GUI/GameFrame.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Engine.h b/src/Engine.h index 7094615..a8e7ef6 100755 --- a/src/Engine.h +++ b/src/Engine.h @@ -30,7 +30,7 @@ public: m_FrameStack->Height = 1080; m_Renderer = std::make_shared(m_ResourceManager); - m_Renderer->SetFullscreen(true); + m_Renderer->SetFullscreen(false); m_Renderer->SetResolution(*static_cast(m_FrameStack)); m_Renderer->Initialize(); diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 1100dc9..f180835 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -25,8 +25,8 @@ public: vp1 = new Viewport(worldFrame, "Viewport1", m_World); vp1->X = 0; vp1->Width = this->Width / 2.f; - //new PlayerHUD(vp1, "PlayerHUD", m_World, 1); - new VehicleSelection(vp1, "VehicleSelection", m_World, 1); + new PlayerHUD(vp1, "PlayerHUD", m_World, 1); + //new VehicleSelection(vp1, "VehicleSelection", m_World, 1); vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2->X = vp1->Right();