From 92047eee58af09530c0d9647c344bb2da15260eb Mon Sep 17 00:00:00 2001 From: Francois Date: Sat, 10 Dec 2016 17:41:13 -0500 Subject: [PATCH] Ref issue #11, 9 Renamed ParticleModule->ParticleSystem and particlesystem->particlesystemComponent. Replaced the map by vector > in the module/system so that the renderer is bound to the particlecomponent not only by a string. Still have an implementation issue in the new system .cc file and didn - + - + @@ -44,13 +44,13 @@ - + - + diff --git a/ParticleSystem.vcxproj.filters b/ParticleSystem.vcxproj.filters index c638b3f..f2773b1 100644 --- a/ParticleSystem.vcxproj.filters +++ b/ParticleSystem.vcxproj.filters @@ -21,9 +21,6 @@ Fichiers sources - - Fichiers sources - Fichiers sources @@ -57,7 +54,10 @@ Fichiers sources - + + Fichiers sources + + Fichiers sources @@ -68,9 +68,6 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - Fichiers d%27en-tête @@ -110,7 +107,10 @@ Fichiers d%27en-tête - + + Fichiers d%27en-tête + + Fichiers d%27en-tête diff --git a/src/app.cc b/src/app.cc index f62b46b..c25e862 100644 --- a/src/app.cc +++ b/src/app.cc @@ -25,6 +25,7 @@ // TODO: Temporary includes since test suite // is not built yet... +#include "stub_renderer.hh" #include "fountain_source.hh" #include "global_acceleration.hh" @@ -50,17 +51,17 @@ void Init() { ShaderManager::Bind(); // Particle module initialization - System wTempSystem(100000); + ParticleSystemComponent wTempSystem( + std::make_unique(), + 100000); wTempSystem.AddSource( - std::make_unique( - Gem::Particle::FountainSource({ 0.0f, 0.0f, 0.0f }) - ) - ); + std::make_unique( + FountainSource({ 0.0f, 0.0f, 0.0f }))); wTempSystem.AddDynamic( - std::make_unique() + std::make_unique() ); - ParticleModule::AddSystem("OBVIOUSLY_TEMPORARY", std::move(wTempSystem)); + ParticleSystem::AddSystem("OBVIOUSLY_TEMPORARY", std::move(wTempSystem)); } void Run() { @@ -71,7 +72,7 @@ void Run() { double dt = timer::chrono::GetTimeElapsed() / timer::NANO_PER_SEC; - ParticleModule::Update(dt); + ParticleSystem::Update(dt); //TODO: Render here //m_particleSystem.Render() @@ -81,7 +82,7 @@ void Run() { } // App destruction - ParticleModule::Terminate(); + ParticleSystem::Terminate(); ShaderManager::Terminate(); graphic_context->Terminate(); } diff --git a/src/main.cc b/src/main.cc index b2118fc..9415dee 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,13 +17,11 @@ //Your project's .h files #include "app.hh" -using namespace Gem::Particle; - int main(int argc, const char *argv[]) { (void)argc;(void)argv; - App::Init(); + Gem::Particle::App::Init(); - App::Run(); + Gem::Particle::App::Run(); return 0; } diff --git a/src/particle_module.cc b/src/particle_module.cc deleted file mode 100644 index 2a84759..0000000 --- a/src/particle_module.cc +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************* -* Copyright (c) 2016 François Trudel -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -*************************************************************************/ -#include "particle_module.hh" - -#include -#include - -namespace Gem { -namespace Particle { -namespace ParticleModule { -namespace { - std::map particle_systems; -} - -void Init() { -} - -void Terminate() { -} - -void Update(double a_dt) { - // TODO: This update could very well be - // executed in parallel for each systems - - // Update each systems individually - for (auto system : particle_systems) { - system.second.Update(a_dt); - } -} - -void GetSystemByName(const std::string& a_szSystemName) { - particle_systems.at(a_szSystemName); -} - -void AddSystem(const std::string& a_szSystemName, System&& a_system) { - particle_systems.insert({ a_szSystemName, a_system}); -} - -void RemoveSystem(const std::string& a_szSystemName) { - particle_systems.erase(a_szSystemName); -} - -} /* namespace ParticleModule */ -} /* namespace Particle */ -} /* namespace Gem */ \ No newline at end of file diff --git a/src/particle_module.hh b/src/particle_module.hh deleted file mode 100644 index 922a6ad..0000000 --- a/src/particle_module.hh +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************************************* -* Copyright (c) 2016 François Trudel -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -*************************************************************************/ -#ifndef PARTICLE_MODULE_HH -#define PARTICLE_MODULE_HH - -#include "particle_system.hh" - -namespace Gem { -namespace Particle { -namespace ParticleModule { -void Init(); -void Terminate(); - -void Update(double a_dt); -void GetSystemByName(const std::string& a_szSystemName); -void AddSystem(const std::string& a_szSystemName, System&& a_system); -void RemoveSystem(const std::string& a_szSystemName); - -} /* namespace ParticleModule*/ -} /* namespace Particle */ -} /* namespace Gem */ -#endif /* end of include guard: PARTICLE_MODULE_HH */ diff --git a/src/particle_system.cc b/src/particle_system.cc index b216b74..965f3c4 100644 --- a/src/particle_system.cc +++ b/src/particle_system.cc @@ -1,39 +1,83 @@ /************************************************************************* - * Copyright (c) 2016 François Trudel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. +* Copyright (c) 2016 François Trudel +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. *************************************************************************/ #include "particle_system.hh" -#include "default_dynamic.hh" +#include +#include +#include namespace Gem { namespace Particle { -System::System(std::size_t a_unMaxParticleCount) - : m_pParticlePool(new Pool(a_unMaxParticleCount)) { - m_vDynamics.push_back(std::make_unique()); +namespace ParticleSystem { +namespace { + //TODO : Use pointers instead of raw entities!! + +// See if map is better here +using ComponentsList = std::vector >; +using Components = std::pair; + +ComponentsList sub_systems; + +// Some helper accessors for readability +ParticleSystemComponent& GetParticleComponent(Components& rhs) { return rhs.first; } +Renderer& GetRenderingComponent(Components& rhs) { return rhs.second; } + +ParticleSystemComponent& GetParticleComponent(std::size_t rhs) { return sub_systems[rhs].first; } +Renderer& GetRenderingComponent(std::size_t rhs) { return sub_systems[rhs].second; } } -System::System(System&& other) - : m_pParticlePool(std::move(other.m_pParticlePool)), - m_vDynamics(std::move(other.m_vDynamics)), - m_vSources(std::move(other.m_vSources)) { + +void Init() { } -void System::Update(double a_dt){ - for (auto& source : m_vSources) { - source->Emit(a_dt, m_pParticlePool); - } - for (auto& dynamic : m_vDynamics) { - dynamic->Update(a_dt, m_pParticlePool); + +void Terminate() { +} + +void Update(double a_dt) { + // TODO: This update could very well be + // executed in parallel for each systems + + // Update each systems individually + for (std::size_t i = 0; i < sub_systems.size(); ++i) { + // TODO: Change this kind of iteration when the change toward pointers will be done + GetParticleComponent(i).Update(a_dt); } } -} /* namespace Particle */ -} /* namespace Gem */ +void GetSystemByName(const std::string& a_szSystemName) { + /* + TODO: + Add accessors in the particlesystemcompoenent for the name + change the parameeters of this function + Do two function GetParticleComponentByName and GetRenderingComponentByName + and adjust the return type with the corresponding funtion name + */ +} + +void AddComponents(ParticleSystemComponent a_particleComponent, Renderer* a_renderer) { + sub_systems.push_back( + std::make_pair( + a_particleComponent, a_renderer)); +} + +void RemoveSystem(const std::string& a_szSystemName) { + /* + TODO: + This could be necessary, i can see a use case, but this is not priority + RemoveByName maybe + + */ +} +} /* namespace ParticleSystem */ +} /* namespace Particle */ +} /* namespace Gem */ \ No newline at end of file diff --git a/src/particle_system.hh b/src/particle_system.hh index a2ae307..f0b9535 100644 --- a/src/particle_system.hh +++ b/src/particle_system.hh @@ -1,76 +1,37 @@ /************************************************************************* - * Copyright (c) 2016 François Trudel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Inspired by: http://www.bfilipek.com/2014/04/flexible-particle-system-start.html +* Copyright (c) 2016 François Trudel +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. *************************************************************************/ - -/* TODOs - * 1- Why not just a const getter for the particle pool instead of public? - * 2- Since we have the lifetime > 0.0 to see if particles are active, - * an active particle counter and the pool property of having active particles - * at the front, couldn't we just get rid of the activeflags container?? - * Maybe performance wise it is just safer to have one...TBD - * 3- Try AoS vs SoA (in other words move the particle parameters here - * and create an array for each - * 4- See unique_ptr vs vector for pool - */ - #ifndef PARTICLE_SYSTEM_HH #define PARTICLE_SYSTEM_HH -#include -#include - -#include "particle.hh" -#include "particle_pool.hh" -#include "source.hh" -#include "dynamic.hh" +#include "particle_system_component.hh" +#include "renderer.hh" namespace Gem { namespace Particle { -class System { -public: - explicit System(std::size_t a_unMaxParticleCount = 10000); +namespace ParticleSystem { +void Init(); +void Terminate(); - System(System&& other); - System(const System& other) = delete; - System& operator=(System&& other) = delete; - System& operator=(const System& other) = delete; +void Update(double a_dt); +void Render(); - ~System() = default; - - void Update(double a_dt); - const std::unique_ptr& GetParticles() const { - return m_pParticlePool; - } - void AddSource(std::unique_ptr a_pSource) { - m_vSources.push_back(std::move(a_pSource)); - } - void AddDynamic(std::unique_ptr a_pDynamic) { - m_vDynamics.push_back(std::move(a_pDynamic)); - } +void GetSystemByName(const std::string& a_szSystemName); // See .CC file for todo -private: - // TODO: See if raw class (Pool) is faster - std::unique_ptr m_pParticlePool; - // TODO: See if shared_ptr would be better so that - // something else can have a copy of those to change - // some parameters more easily - std::vector > m_vSources; - std::vector > m_vDynamics; -}; /* class System*/ +void AddSystem(const std::string& a_szSystemName, ParticleSystemComponent&& a_system); +void RemoveSystem(const std::string& a_szSystemName); // See .CC file for todo + +} /* namespace ParticleSystem*/ } /* namespace Particle */ } /* namespace Gem */ - - #endif /* end of include guard: PARTICLE_SYSTEM_HH */ diff --git a/src/particle_system_component.cc b/src/particle_system_component.cc new file mode 100644 index 0000000..8490754 --- /dev/null +++ b/src/particle_system_component.cc @@ -0,0 +1,42 @@ +/************************************************************************* + * Copyright (c) 2016 François Trudel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. +*************************************************************************/ +#include "particle_system_component.hh" + +#include "default_dynamic.hh" + +namespace Gem { +namespace Particle { +ParticleSystemComponent::ParticleSystemComponent( + const std::string& a_sSystemName, + std::size_t a_unMaxParticleCount) + : m_pParticlePool(new Pool(a_unMaxParticleCount)), + m_sSystemName(a_sSystemName) { + m_vDynamics.push_back(std::make_unique()); +} +ParticleSystemComponent::ParticleSystemComponent(ParticleSystemComponent&& other) + : m_pParticlePool(std::move(other.m_pParticlePool)), + m_vDynamics(std::move(other.m_vDynamics)), + m_vSources(std::move(other.m_vSources)) { +} +void ParticleSystemComponent::Update(double a_dt){ + for (auto& source : m_vSources) { + source->Emit(a_dt, m_pParticlePool); + } + for (auto& dynamic : m_vDynamics) { + dynamic->Update(a_dt, m_pParticlePool); + } +} +} /* namespace Particle */ +} /* namespace Gem */ + diff --git a/src/particle_system_component.hh b/src/particle_system_component.hh new file mode 100644 index 0000000..527a0d6 --- /dev/null +++ b/src/particle_system_component.hh @@ -0,0 +1,80 @@ +/************************************************************************* + * Copyright (c) 2016 François Trudel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * Inspired by: http://www.bfilipek.com/2014/04/flexible-particle-system-start.html +*************************************************************************/ + +/* TODOs + * 1- Why not just a const getter for the particle pool instead of public? + * 2- Since we have the lifetime > 0.0 to see if particles are active, + * an active particle counter and the pool property of having active particles + * at the front, couldn't we just get rid of the activeflags container?? + * Maybe performance wise it is just safer to have one...TBD + * 3- Try AoS vs SoA (in other words move the particle parameters here + * and create an array for each + * 4- See unique_ptr vs vector for pool + */ + +#ifndef PARTICLE_SYSTEM_COMPONENT_HH +#define PARTICLE_SYSTEM_COMPONENT_HH + +#include +#include + +#include "particle.hh" +#include "particle_pool.hh" +#include "source.hh" +#include "dynamic.hh" +#include "renderer.hh" + +namespace Gem { +namespace Particle { +class ParticleSystemComponent { +public: + explicit ParticleSystemComponent( + const std::string& a_sSystemName = "DEFAULT_SYS_NAME", + std::size_t a_unMaxParticleCount = 10000); + + ParticleSystemComponent(ParticleSystemComponent&& other); + ParticleSystemComponent(const ParticleSystemComponent& other) = delete; + ParticleSystemComponent& operator=(ParticleSystemComponent&& other) = delete; + ParticleSystemComponent& operator=(const ParticleSystemComponent& other) = delete; + + ~ParticleSystemComponent() = default; + + void Update(double a_dt); + const std::unique_ptr& GetParticles() const { + return m_pParticlePool; + } + void AddSource(std::unique_ptr a_pSource) { + m_vSources.push_back(std::move(a_pSource)); + } + void AddDynamic(std::unique_ptr a_pDynamic) { + m_vDynamics.push_back(std::move(a_pDynamic)); + } + +private: + std::string m_sSystemName; + // TODO: See if raw class (Pool) is faster + std::unique_ptr m_pParticlePool; + // TODO: See if shared_ptr would be better so that + // something else can have a copy of those to change + // some parameters more easily + std::vector > m_vSources; + std::vector > m_vDynamics; +}; /* class ParticleSystemComponent */ +} /* namespace Particle */ +} /* namespace Gem */ + + +#endif /* end of include guard: PARTICLE_SYSTEM_COMPONENT_HH */ diff --git a/src/renderer.hh b/src/renderer.hh index 4387cfb..0478932 100644 --- a/src/renderer.hh +++ b/src/renderer.hh @@ -16,7 +16,7 @@ #include -#include "particle_system.hh" +#include "particle_pool.hh" // TODO: Find a way like fenbf did for the billboard, // glpoint, bool useQuads thingy... @@ -28,9 +28,9 @@ public: Renderer() = default; virtual ~Renderer() = default; - // TODO: Copyable and moveable?< - void Init(const System& a_system); - virtual void Render() = 0; + // TODO: Add other methods as the whole process + // becomes clearer + virtual void Render(std::unique_ptr a_pParticlePool) = 0; private: diff --git a/src/stub_renderer.cc b/src/stub_renderer.cc index 0eebcb4..abef32f 100644 --- a/src/stub_renderer.cc +++ b/src/stub_renderer.cc @@ -13,10 +13,33 @@ *************************************************************************/ #include "stub_renderer.hh" +#include +#include + namespace Gem { namespace Particle { -void StubRenderer::Render() { - + +StubRenderer::StubRenderer() { + // VAO initialization + glGenVertexArrays(1, &m_vertexArrayID); + glBindVertexArray(m_vertexArrayID); + + // VBO initialization + glGenBuffers(1, &m_vertexBufferID); + glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferID); + glBufferData(GL_ARRAY_BUFFER, + sizeof(glm::f32vec3), + &(a_pParticlePool->m_position[0]), + GL_STATIC_DRAW); +} + +StubRenderer::~StubRenderer() { + glDeleteBuffers(1, &m_vertexBufferID); +} + +void StubRenderer::Render(std::unique_ptr a_pParticlePool) { + } + } /* namespace Particle */ } /* namespace Gem */ diff --git a/src/stub_renderer.hh b/src/stub_renderer.hh index 5d1c064..1ddb478 100644 --- a/src/stub_renderer.hh +++ b/src/stub_renderer.hh @@ -20,11 +20,17 @@ namespace Gem { namespace Particle { class StubRenderer : public Renderer { public: - StubRenderer() = default; - ~StubRenderer() = default; + StubRenderer(); + ~StubRenderer(); // TODO: Copyable and moveable?< - virtual void Render() override; + virtual void Render(std::unique_ptr a_pParticlePool) override; + +private: + // TODO: See if the following could be refactored in the base class + GLuint m_vertexArrayID; //VAO + GLuint m_vertexBufferID; //VBO + }; /* class StubRenderer*/ } /* namespace Particle */