Skip to content
Snippets Groups Projects
Commit c8418316 authored by BATON Theau's avatar BATON Theau
Browse files

Refactoring of manager

parent 3d9c7c9d
No related branches found
No related tags found
No related merge requests found
Showing
with 179 additions and 116 deletions
#include "GlobalInterface.hpp" #include "Global.hpp"
#include <imgui.h> #include <imgui.h>
#include <imgui_impl_glfw.h> #include <imgui_impl_glfw.h>
...@@ -6,22 +6,21 @@ ...@@ -6,22 +6,21 @@
#include "../Scene/Manager.hpp" #include "../Scene/Manager.hpp"
namespace pg { namespace pg::interface {
GlobalInterface::GlobalInterface(Window & window, Manager & manager, const std::string & title) Global::Global(Window & window, Manager & manager, const std::string & title)
: _title(title), _manager(manager), _historical() { : _title(title), _manager(manager), _historical() {
if(this->_title.empty()) { if(this->_title.empty()) {
this->_title = window.title(); this->_title = window.title();
} }
ImGui::CreateContext(); ImGui::CreateContext();
ImGui::GetStyle().WindowMenuButtonPosition = ImGuiDir_None;
ImGui::GetIO().IniFilename = "config/imgui.ini"; ImGui::GetIO().IniFilename = "config/imgui.ini";
ImGui_ImplGlfw_InitForOpenGL(window.address(), true); ImGui_ImplGlfw_InitForOpenGL(window.address(), true);
ImGui_ImplOpenGL3_Init("#version 330 core"); ImGui_ImplOpenGL3_Init("#version 330 core");
} }
GlobalInterface::~GlobalInterface() { Global::~Global() {
ImGui::GetIO().IniFilename = ""; ImGui::GetIO().IniFilename = "";
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
...@@ -29,7 +28,7 @@ namespace pg { ...@@ -29,7 +28,7 @@ namespace pg {
ImGui::DestroyContext(); ImGui::DestroyContext();
} }
void GlobalInterface::render(double current_time) { void Global::render(double current_time) {
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
...@@ -39,7 +38,7 @@ namespace pg { ...@@ -39,7 +38,7 @@ namespace pg {
if(ImGui::Begin(this->_title.c_str())) { if(ImGui::Begin(this->_title.c_str())) {
if(ImGui::BeginTabBar("")) { if(ImGui::BeginTabBar("")) {
if(ImGui::BeginTabItem("Scene")) { if(ImGui::BeginTabItem("Scene")) {
this->_manager.interface().render(current_time); //this->_manager.interface().render(current_time);
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "../System/Window.hpp" #include "../System/Window.hpp"
#include "../System/FrameHistorical.hpp" #include "../System/FrameHistorical.hpp"
namespace pg { namespace pg::interface {
class GlobalInterface : public Interface { class Global : public Interface {
private: private:
std::string _title; std::string _title;
...@@ -15,8 +15,8 @@ namespace pg { ...@@ -15,8 +15,8 @@ namespace pg {
FrameHistorical _historical; FrameHistorical _historical;
public: public:
GlobalInterface(Window &, Manager &, const std::string & = ""); Global(Window &, Manager &, const std::string & = "");
~GlobalInterface(); ~Global();
virtual void render(double); virtual void render(double);
inline std::string title() const {return "Global Interface";} inline std::string title() const {return "Global Interface";}
......
#include "SceneManagerInterface.hpp" #include "SceneManager.hpp"
#include <imgui.h> #include <imgui.h>
#include "../Scene/Manager.hpp" #include "../Scene/Manager.hpp"
namespace pg { namespace pg::interface {
SceneManagerInterface::SceneManagerInterface(Manager * manager) SceneManager::SceneManager(Manager * manager)
: _manager(manager) { : _manager(manager) {}
} void SceneManager::render(double current_time) {
void SceneManagerInterface::render(double current_time) {
if(!this->_manager->scenes().empty()) { if(!this->_manager->scenes().empty()) {
std::string name = this->_manager->current() == nullptr ? this->_manager->scenes().front()->name() : this->_manager->current()->name(); std::string name = this->_manager->current() == nullptr ? this->_manager->scenes().front()->name() : this->_manager->current()->name();
if(ImGui::BeginCombo("Current Scene", name.c_str())) { if(ImGui::BeginCombo("Current Scene", name.c_str())) {
for(auto & scene : this->_manager->_scenes) { for(auto & scene : this->_manager->_scenes) {
bool is_selected = (scene == this->_manager->current()); bool is_selected = (scene == this->_manager->current());
if(ImGui::Selectable(scene->name().c_str(), is_selected)) { if(ImGui::Selectable(scene->name().c_str(), is_selected)) {
this->_manager->setScene(scene); this->_manager->changeScene(*scene);
} }
} }
ImGui::EndCombo(); ImGui::EndCombo();
...@@ -25,7 +23,7 @@ namespace pg { ...@@ -25,7 +23,7 @@ namespace pg {
ImGui::Separator(); ImGui::Separator();
} }
Scene * current = this->_manager->current(); scene::Scene * current = this->_manager->current();
if(current != nullptr && current->interface() != nullptr) { if(current != nullptr && current->interface() != nullptr) {
current->interface()->render(current_time); current->interface()->render(current_time);
} }
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
namespace pg { namespace pg {
class Manager; class Manager;
class SceneManagerInterface : public Interface { }
namespace pg::interface {
class SceneManager : public Interface {
private: private:
Manager * _manager; Manager * _manager;
public: public:
SceneManagerInterface(Manager *); SceneManager(Manager *);
virtual void render(double = 0.0); virtual void render(double = 0.0);
inline std::string title() const {return "Scene Manager Interface";} inline std::string title() const {return "Scene Manager Interface";}
......
[Window][Debug##Default] [Window][Debug##Default]
Pos=306,287 Pos=60,60
Size=400,400 Size=400,400
[Window][Particle Debug Menu] [Window][Particle Generator]
Pos=60,60 Pos=60,60
Size=128,100 Size=504,424
[Window][Main window]
Pos=0,0
Size=491,602
[Window][Settings]
Pos=20,23
Size=431,416
[Window][Particles Configuration]
Pos=23,44
Size=729,421
[Window][Particles Settings]
Pos=10,4
Size=674,754
[Window][Particle Generator Settings]
Pos=20,44
Size=523,732
[Window][Dear ImGui Demo]
Pos=650,20
Size=550,680
#pragma once #pragma once
#include "PathGeneratorInterface.hpp" #include "PathGenerator.hpp"
#include <imgui.h> #include <imgui.h>
#include "../../Particle/generator/PathParticleGenerator.hpp" #include "../../Particle/generator/PathParticleGenerator.hpp"
namespace pg { namespace pg::interface {
PathGeneratorInterface::PathGeneratorInterface(PathParticleGenerator * generator, Trajectory * trajectory) PathGenerator::PathGenerator(PathParticleGenerator * generator, Trajectory * trajectory)
: _generator(generator), _trajectory(trajectory), _next(0.f, 0.f, 0.f), _index(0) {} : _generator(generator), _trajectory(trajectory), _next(0.f, 0.f, 0.f), _index(0) {}
void PathGeneratorInterface::render(double) { void PathGenerator::render(double) {
if(ImGui::CollapsingHeader("Generator Information")) { if(ImGui::CollapsingHeader("Generator Information")) {
ImGui::Text("Physic generator at %f / %f / %f (x, y, z) - variation : %f.", this->_generator->m_position.x, this->_generator->m_position.y, this->_generator->m_position.z, this->_generator->m_positionVariation); ImGui::Text("Physic generator at %f / %f / %f (x, y, z) - variation : %f.", this->_generator->m_position.x, this->_generator->m_position.y, this->_generator->m_position.z, this->_generator->m_positionVariation);
ImGui::Separator(); ImGui::Separator();
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
namespace pg { namespace pg {
class PathParticleGenerator; class PathParticleGenerator;
class PathGeneratorInterface : public Interface { }
namespace pg::interface {
class PathGenerator : public Interface {
private: private:
PathParticleGenerator * _generator; PathParticleGenerator * _generator;
Trajectory * _trajectory; Trajectory * _trajectory;
...@@ -15,7 +18,7 @@ namespace pg { ...@@ -15,7 +18,7 @@ namespace pg {
int _index; int _index;
public: public:
PathGeneratorInterface(PathParticleGenerator *, Trajectory * = nullptr); PathGenerator(PathParticleGenerator *, Trajectory * = nullptr);
inline PathParticleGenerator * getGenerator() const {return this->_generator;} inline PathParticleGenerator * getGenerator() const {return this->_generator;}
......
#pragma once #pragma once
#include "PhysicGeneratorInterface.hpp" #include "PhysicGenerator.hpp"
#include <imgui.h> #include <imgui.h>
#include "../../Particle/generator/PhysicsParticleGenerator.hpp" #include "../../Particle/generator/PhysicsParticleGenerator.hpp"
namespace pg { namespace pg::interface {
PhysicGeneratorInterface::PhysicGeneratorInterface(PhysicsParticleGenerator * generator) PhysicGenerator::PhysicGenerator(PhysicsParticleGenerator * generator)
: _generator(generator) {} : _generator(generator) {}
void PhysicGeneratorInterface::render(double) { void PhysicGenerator::render(double) {
if(this->_generator == nullptr) { if(this->_generator == nullptr) {
return; return;
} }
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
namespace pg { namespace pg {
class PhysicsParticleGenerator; class PhysicsParticleGenerator;
class PhysicGeneratorInterface : public Interface { }
namespace pg::interface {
class PhysicGenerator : public Interface {
private: private:
PhysicsParticleGenerator * _generator; PhysicsParticleGenerator * _generator;
public: public:
PhysicGeneratorInterface(PhysicsParticleGenerator *); PhysicGenerator(PhysicsParticleGenerator *);
inline PhysicsParticleGenerator * getGenerator() const {return this->_generator;} inline PhysicsParticleGenerator * getGenerator() const {return this->_generator;}
inline void setGenerator(PhysicsParticleGenerator * generator) {this->_generator = generator;} inline void setGenerator(PhysicsParticleGenerator * generator) {this->_generator = generator;}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <string> #include <string>
namespace pg { namespace pg::interface {
class Interface { class Interface {
public: public:
virtual void render(double = 0.0) = 0; virtual void render(double = 0.0) = 0;
......
#include "Manager.hpp"
#include "../Scene/Manager.hpp"
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
namespace pg::interface {
Manager::Manager(const Window & window, pg::Manager & manager)
: _window(window), _manager(manager), _title(window.title()) {
ImGui::CreateContext();
ImGui::GetIO().IniFilename = "config/imgui.ini";
ImGui_ImplGlfw_InitForOpenGL(window.address(), true);
ImGui_ImplOpenGL3_Init("#version 330 core");
}
Manager::~Manager() {
ImGui::GetIO().IniFilename = "res/config/imgui.ini";
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void Manager::render(double current_time) {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
this->_historical.count(current_time);
if(ImGui::Begin(this->_title.c_str())) {
if(ImGui::BeginTabBar("")) {
if(ImGui::BeginTabItem("Scene")) {
auto current = this->_manager.current();
if(current.has_value()) {
(*(*current)->interface())->render(current_time);
}
ImGui::EndTabItem();
}
if(ImGui::BeginTabItem("Performance")) {
this->_historical.render(current_time);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
}
\ No newline at end of file
#pragma once
#include "Interface.hpp"
#include "../System/FrameHistorical.hpp"
#include "../Scene/Manager.hpp"
#include "../System/Window.hpp"
namespace pg::interface {
class Manager {
private:
const Window & _window;
pg::Manager & _manager;
FrameHistorical _historical;
std::string _title;
public:
Manager(const Window &, pg::Manager &);
~Manager();
void render(double);
};
}
\ No newline at end of file
#include "MeshGeneratorInterface.hpp" #include "MeshGenerator.hpp"
#include <imgui.h> #include <imgui.h>
#include "../../Scene/Scenes/MeshGenerator.hpp" #include "../../Scene/Scenes/MeshGenerator.hpp"
#include "../../tfd/tinyfiledialogs.h" #include "../../tfd/tinyfiledialogs.h"
namespace pg { namespace pg::interface {
MeshGeneratorInterface::MeshGeneratorInterface(scene::MeshGenerator * scene, size_t max) MeshGenerator::MeshGenerator(scene::MeshGenerator * scene, size_t max)
: _scene(scene), : _scene(scene),
_interface(nullptr), _interface(nullptr),
_max(max), _max(max),
...@@ -17,7 +17,7 @@ namespace pg { ...@@ -17,7 +17,7 @@ namespace pg {
} }
void MeshGeneratorInterface::render(double current_time) { void MeshGenerator::render(double current_time) {
ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Spawn")) { if(ImGui::Button("Spawn")) {
......
#pragma once #pragma once
#include "../Interface.hpp" #include "../Interface.hpp"
#include "../Generator/PhysicGeneratorInterface.hpp" #include "../Generator/PhysicGenerator.hpp"
namespace pg { namespace pg::scene {
namespace scene {
class MeshGenerator; class MeshGenerator;
} }
class MeshGeneratorInterface : public Interface { namespace pg::interface {
class MeshGenerator : public Interface {
private: private:
scene::MeshGenerator * _scene; scene::MeshGenerator * _scene;
PhysicGeneratorInterface _interface; PhysicGenerator _interface;
size_t _max; size_t _max;
int _spawnFrequence; int _spawnFrequence;
...@@ -22,7 +22,7 @@ namespace pg { ...@@ -22,7 +22,7 @@ namespace pg {
bool _enableSpawn; bool _enableSpawn;
public: public:
MeshGeneratorInterface(scene::MeshGenerator *, size_t max = 1024); MeshGenerator(scene::MeshGenerator *, size_t max = 1024);
inline size_t getMaxParticle() const {return this->_max;} inline size_t getMaxParticle() const {return this->_max;}
......
#include "MeshSceneInterface.hpp" #include "MeshScene.hpp"
#include <imgui.h> #include <imgui.h>
#include "../../Scene/Scenes/Mesh.hpp" #include "../../Scene/Scenes/Mesh.hpp"
#include "../../tfd/tinyfiledialogs.h" #include "../../tfd/tinyfiledialogs.h"
namespace pg { namespace pg::interface {
MeshSceneInterface::MeshSceneInterface(scene::Mesh * scene, PathParticleGenerator * path, PhysicsParticleGenerator * physic) MeshScene::MeshScene(scene::Mesh * scene, PathParticleGenerator * path, PhysicsParticleGenerator * physic)
: _scene(scene), : _scene(scene),
_currentInterface(nullptr), _current(nullptr),
_pathGenerator(path), _pathGenerator(path),
_physicGenerator(physic), _physicGenerator(physic),
_max(1024), _max(1024),
...@@ -21,7 +21,7 @@ namespace pg { ...@@ -21,7 +21,7 @@ namespace pg {
} }
void MeshSceneInterface::render(double current_time) { void MeshScene::render(double current_time) {
ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max);
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::Button("Clear")) { if(ImGui::Button("Clear")) {
......
#pragma once #pragma once
#include "../Interface.hpp" #include "../Interface.hpp"
#include "../Generator/PathGeneratorInterface.hpp" #include "../Generator/PathGenerator.hpp"
#include "../Generator/PhysicGeneratorInterface.hpp" #include "../Generator/PhysicGenerator.hpp"
#include <glm/vec4.hpp> #include <glm/vec4.hpp>
namespace pg { namespace pg::scene {
namespace scene {
class Mesh; class Mesh;
} }
class MeshSceneInterface : public Interface { namespace pg::interface {
class MeshScene : public Interface {
private: private:
scene::Mesh * _scene; scene::Mesh * _scene;
Interface * _currentInterface; Interface * _current;
PathGeneratorInterface _pathGenerator; PathGenerator _pathGenerator;
PhysicGeneratorInterface _physicGenerator; PhysicGenerator _physicGenerator;
int _max; int _max;
...@@ -30,7 +30,7 @@ namespace pg { ...@@ -30,7 +30,7 @@ namespace pg {
bool _enableRender; bool _enableRender;
public: public:
MeshSceneInterface(scene::Mesh *, PathParticleGenerator *, PhysicsParticleGenerator *); MeshScene(scene::Mesh *, PathParticleGenerator *, PhysicsParticleGenerator *);
inline int getMaxParticle() const {return this->_max;} inline int getMaxParticle() const {return this->_max;}
......
#include "PathSceneInterface.hpp" #include "PathScene.hpp"
#include <imgui.h> #include <imgui.h>
#include "../../Scene/Scenes/Path.hpp" #include "../../Scene/Scenes/Path.hpp"
#include "../../tfd/tinyfiledialogs.h" #include "../../tfd/tinyfiledialogs.h"
namespace pg { namespace pg::interface {
PathSceneInterface::PathSceneInterface(scene::Path * scene) PathScene::PathScene(scene::Path * scene)
: _scene(scene), : _scene(scene),
_interface(&scene->_generator, &scene->_trajectory), _interface(&scene->_generator, &scene->_trajectory),
_max(1024), _max(1024),
...@@ -17,7 +17,7 @@ namespace pg { ...@@ -17,7 +17,7 @@ namespace pg {
_enableRender(true), _enableRender(true),
_enableSpawning(true) {} _enableSpawning(true) {}
void PathSceneInterface::render(double current_time) { void PathScene::render(double current_time) {
ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max);
ImGui::Checkbox("Enable Rendering", &this->_enableRender); ImGui::Checkbox("Enable Rendering", &this->_enableRender);
ImGui::Separator(); ImGui::Separator();
......
#pragma once #pragma once
#include "../Interface.hpp" #include "../Interface.hpp"
#include "../Generator/PathGeneratorInterface.hpp" #include "../Generator/PathGenerator.hpp"
#include <glm/vec4.hpp> #include <glm/vec4.hpp>
namespace pg {
namespace scene { namespace pg::scene {
class Path; class Path;
} }
class PathSceneInterface : public Interface { namespace pg::interface {
class PathScene : public Interface {
private: private:
scene::Path * _scene; scene::Path * _scene;
PathGeneratorInterface _interface; PathGenerator _interface;
int _max; int _max;
int _spawnFrequence; int _spawnFrequence;
...@@ -26,7 +27,7 @@ namespace pg { ...@@ -26,7 +27,7 @@ namespace pg {
bool _enableSpawning; bool _enableSpawning;
public: public:
PathSceneInterface(scene::Path *); PathScene(scene::Path *);
inline int getMaxParticle() const {return this->_max;} inline int getMaxParticle() const {return this->_max;}
inline int getSpawnFrequence() const {return this->_spawnFrequence;} inline int getSpawnFrequence() const {return this->_spawnFrequence;}
...@@ -45,6 +46,6 @@ namespace pg { ...@@ -45,6 +46,6 @@ namespace pg {
inline void setEnableSpawning(bool state) {this->_enableSpawning = state;} inline void setEnableSpawning(bool state) {this->_enableSpawning = state;}
virtual void render(double); virtual void render(double);
inline std::string title() const {return "Path Scene Interface";} inline std::string title() const {return "Path Scene ";}
}; };
} }
\ No newline at end of file
#include "PhysicSceneInterface.hpp" #include "PhysicScene.hpp"
#include <imgui.h> #include <imgui.h>
#include "../../tfd/tinyfiledialogs.h" #include "../../tfd/tinyfiledialogs.h"
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <iostream> #include <iostream>
namespace pg { namespace pg::interface {
PhysicSceneInterface::PhysicSceneInterface(scene::Physic * scene) PhysicScene::PhysicScene(scene::Physic * scene)
: _scene(scene), : _scene(scene),
_generator(&scene->_generator), _generator(&scene->_generator),
_max(1024), _max(1024),
...@@ -19,7 +19,7 @@ namespace pg { ...@@ -19,7 +19,7 @@ namespace pg {
_enableRender(true), _enableRender(true),
_enableSpawning(true) {} _enableSpawning(true) {}
void PhysicSceneInterface::render(double current_time) { void PhysicScene::render(double current_time) {
ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max); ImGui::Text("Particles Number : %i / %i.", this->_scene->_particles.size(), this->_max);
//ImGui::Text("Frame Per Second : %f.", this->_fps); //ImGui::Text("Frame Per Second : %f.", this->_fps);
ImGui::Checkbox("Enable Rendering", &this->_enableRender); ImGui::Checkbox("Enable Rendering", &this->_enableRender);
......
#pragma once #pragma once
#include "../Interface.hpp" #include "../Interface.hpp"
#include "../Generator/PhysicGeneratorInterface.hpp" #include "../Generator/PhysicGenerator.hpp"
#include <glm/vec4.hpp> #include <glm/vec4.hpp>
namespace pg { namespace pg::scene {
namespace scene {
class Physic; class Physic;
} }
class PhysicSceneInterface : public Interface { namespace pg::interface {
class PhysicScene : public Interface {
private: private:
scene::Physic * _scene; scene::Physic * _scene;
PhysicGeneratorInterface _generator; PhysicGenerator _generator;
int _max; int _max;
int _spawnFrequence; int _spawnFrequence;
...@@ -26,7 +26,7 @@ namespace pg { ...@@ -26,7 +26,7 @@ namespace pg {
bool _enableSpawning; bool _enableSpawning;
public: public:
PhysicSceneInterface(scene::Physic *); PhysicScene(scene::Physic *);
inline int getMaxParticle() const {return this->_max;} inline int getMaxParticle() const {return this->_max;}
inline int getSpawnFrequence() const {return this->_spawnFrequence;} inline int getSpawnFrequence() const {return this->_spawnFrequence;}
...@@ -45,6 +45,6 @@ namespace pg { ...@@ -45,6 +45,6 @@ namespace pg {
inline void setEnableSpawning(bool state) {this->_enableSpawning = state;} inline void setEnableSpawning(bool state) {this->_enableSpawning = state;}
virtual void render(double); virtual void render(double);
inline std::string title() const {return "Physic Scene Interface";} inline std::string title() const {return "Physic Scene ";}
}; };
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment