Skip to content

Commit

Permalink
Ref issue #11, 9 Renamed ParticleModule->ParticleSystem and particles…
Browse files Browse the repository at this point in the history
…ystem->particlesystemComponent. Replaced the map<string,system> by vector<pair<particlecomponent,renderer> > 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<t update the renderer according to those changes yet. Draft of the rendering process in the stub_renderer class.
  • Loading branch information
frtru committed Dec 10, 2016
1 parent 8e0669d commit 92047ee
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 212 deletions.
8 changes: 4 additions & 4 deletions ParticleSystem.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
<ClCompile Include="src\graphic_context.cc" />
<ClCompile Include="src\main.cc" />
<ClCompile Include="src\opengl_context.cc" />
<ClCompile Include="src\particle_module.cc" />
<ClCompile Include="src\particle_system.cc" />
<ClCompile Include="src\renderer.cc" />
<ClCompile Include="src\shader.cc" />
<ClCompile Include="src\source.cc" />
<ClCompile Include="src\particle_pool.cc" />
<ClCompile Include="src\particle_system.cc" />
<ClCompile Include="src\particle_system_component.cc" />
<ClCompile Include="src\stub_renderer.cc" />
</ItemGroup>
<ItemGroup>
Expand All @@ -44,13 +44,13 @@
<ClInclude Include="src\global_acceleration.hh" />
<ClInclude Include="src\graphic_context.hh" />
<ClInclude Include="src\opengl_context.hh" />
<ClInclude Include="src\particle_module.hh" />
<ClInclude Include="src\particle_system.hh" />
<ClInclude Include="src\renderer.hh" />
<ClInclude Include="src\shader.hh" />
<ClInclude Include="src\source.hh" />
<ClInclude Include="src\particle.hh" />
<ClInclude Include="src\particle_pool.hh" />
<ClInclude Include="src\particle_system.hh" />
<ClInclude Include="src\particle_system_component.hh" />
<ClInclude Include="src\stub_renderer.hh" />
<ClInclude Include="src\timer.hh" />
</ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions ParticleSystem.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
<ClCompile Include="src\particle_pool.cc">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="src\particle_system.cc">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="src\default_dynamic.cc">
<Filter>Fichiers sources</Filter>
</ClCompile>
Expand Down Expand Up @@ -57,7 +54,10 @@
<ClCompile Include="src\renderer.cc">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="src\particle_module.cc">
<ClCompile Include="src\particle_system_component.cc">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="src\particle_system.cc">
<Filter>Fichiers sources</Filter>
</ClCompile>
</ItemGroup>
Expand All @@ -68,9 +68,6 @@
<ClInclude Include="src\particle_pool.hh">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="src\particle_system.hh">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="src\timer.hh">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
Expand Down Expand Up @@ -110,7 +107,10 @@
<ClInclude Include="src\stub_renderer.hh">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="src\particle_module.hh">
<ClInclude Include="src\particle_system_component.hh">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="src\particle_system.hh">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
Expand Down
19 changes: 10 additions & 9 deletions src/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -50,17 +51,17 @@ void Init() {
ShaderManager::Bind();

// Particle module initialization
System wTempSystem(100000);
ParticleSystemComponent wTempSystem(
std::make_unique<StubRenderer>(),
100000);
wTempSystem.AddSource(
std::make_unique<Gem::Particle::FountainSource>(
Gem::Particle::FountainSource({ 0.0f, 0.0f, 0.0f })
)
);
std::make_unique<FountainSource>(
FountainSource({ 0.0f, 0.0f, 0.0f })));
wTempSystem.AddDynamic(
std::make_unique<Gem::Particle::GlobalAcceleration>()
std::make_unique<GlobalAcceleration>()
);

ParticleModule::AddSystem("OBVIOUSLY_TEMPORARY", std::move(wTempSystem));
ParticleSystem::AddSystem("OBVIOUSLY_TEMPORARY", std::move(wTempSystem));
}

void Run() {
Expand All @@ -71,7 +72,7 @@ void Run() {
double dt = timer::chrono::GetTimeElapsed<std::chrono::nanoseconds>()
/ timer::NANO_PER_SEC;

ParticleModule::Update(dt);
ParticleSystem::Update(dt);

//TODO: Render here
//m_particleSystem.Render()
Expand All @@ -81,7 +82,7 @@ void Run() {
}

// App destruction
ParticleModule::Terminate();
ParticleSystem::Terminate();
ShaderManager::Terminate();
graphic_context->Terminate();
}
Expand Down
6 changes: 2 additions & 4 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
56 changes: 0 additions & 56 deletions src/particle_module.cc

This file was deleted.

33 changes: 0 additions & 33 deletions src/particle_module.hh

This file was deleted.

98 changes: 71 additions & 27 deletions src/particle_system.cc
Original file line number Diff line number Diff line change
@@ -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 <vector>
#include <map>
#include <string>

namespace Gem {
namespace Particle {
System::System(std::size_t a_unMaxParticleCount)
: m_pParticlePool(new Pool(a_unMaxParticleCount)) {
m_vDynamics.push_back(std::make_unique<DefaultDynamic>());
namespace ParticleSystem {
namespace {
//TODO : Use pointers instead of raw entities!!

// See if map is better here
using ComponentsList = std::vector<std::pair<ParticleSystemComponent, Renderer> >;
using Components = std::pair<ParticleSystemComponent, Renderer>;

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<ParticleSystemComponent,Renderer*>(
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 */
Loading

0 comments on commit 92047ee

Please sign in to comment.