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

Refactoring manager and renderer

parent c8418316
No related branches found
No related tags found
No related merge requests found
Showing
with 35 additions and 28 deletions
...@@ -3,6 +3,6 @@ Pos=60,60 ...@@ -3,6 +3,6 @@ Pos=60,60
Size=400,400 Size=400,400
[Window][Particle Generator] [Window][Particle Generator]
Pos=60,60 Pos=83,81
Size=504,424 Size=864,632
...@@ -32,10 +32,25 @@ namespace pg::interface { ...@@ -32,10 +32,25 @@ namespace pg::interface {
this->_historical.count(current_time); this->_historical.count(current_time);
if(ImGui::Begin(this->_title.c_str())) { if(ImGui::Begin(this->_title.c_str())) {
auto current = this->_manager.current();
if(ImGui::BeginTabBar("")) { if(ImGui::BeginTabBar("")) {
if(ImGui::BeginTabItem("Scene")) { if(ImGui::BeginTabItem("Scene")) {
auto current = this->_manager.current(); if(!this->_manager.getScenes().empty()) {
if(current.has_value()) { std::string name = !current.has_value() ? (*this->_manager.getScenes().begin())->name() : (*current)->name();
if(ImGui::BeginCombo("Current Scene", name.c_str())) {
for(auto & scene : this->_manager.getScenes()) {
bool is_selected = (scene->name() == name);
if(ImGui::Selectable(scene->name().c_str(), is_selected)) {
this->_manager.setCurrent(*scene);
}
}
ImGui::EndCombo();
}
ImGui::Separator();
}
if(current.has_value() && (*current)->interface().has_value()) {
(*(*current)->interface())->render(current_time); (*(*current)->interface())->render(current_time);
} }
......
...@@ -56,6 +56,7 @@ namespace pg { ...@@ -56,6 +56,7 @@ namespace pg {
} }
void Trajectory::draw(const Camera & camera, double current_time) { void Trajectory::draw(const Camera & camera, double current_time) {
glEnable(GL_LINE_SMOOTH);
this->_vao.bind(); this->_vao.bind();
glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_PROGRAM_POINT_SIZE);
......
...@@ -5,35 +5,29 @@ ...@@ -5,35 +5,29 @@
namespace pg { namespace pg {
Manager::Manager(const Window & window) Manager::Manager(const Window & window)
: _current(this->_scenes.begin()), : _current(),
_sceneRenderer(window, *this) {} _sceneRenderer(window, *this) {}
Manager::~Manager() { Manager::~Manager() {
if(this->_current != this->_scenes.end()) { if(this->_current.has_value()) {
(*this->_current)->destroy(); (*this->_current)->destroy();
} }
} }
std::optional<scene::Scene *> Manager::current() const { std::optional<scene::Scene *> Manager::current() const {
return this->_current != this->_scenes.end() ? std::optional<scene::Scene *>((*this->_current).get()) : std::optional<scene::Scene *>(); return this->_current;
} }
void Manager::setCurrent(scene::Scene & scene) { void Manager::setCurrent(scene::Scene & scene) {
if(this->_current != this->_scenes.end()) { if(this->_current.has_value()) {
(*this->_current)->destroy(); (*this->_current)->destroy();
} }
auto ptr = std::shared_ptr<scene::Scene>(&scene); this->_current = std::optional<scene::Scene*>(&scene);
if(!this->_scenes.contains(ptr)) {
this->_scenes.insert(ptr);
}
this->_current = std::find(this->_scenes.begin(), this->_scenes.end(), ptr);
(*this->_current)->initialize(); (*this->_current)->initialize();
} }
void Manager::render(const Camera & camera, double current_time) { void Manager::render(const Camera & camera, double current_time) {
auto current = this->current(); this->_sceneRenderer.render(this->_current, camera, current_time);
this->_sceneRenderer.render(current, camera, current_time);
} }
} }
\ No newline at end of file
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#include "../Renderer/Camera/Camera.hpp" #include "../Renderer/Camera/Camera.hpp"
namespace pg { namespace pg {
using SceneContainer = std::set<std::shared_ptr<scene::Scene>>; using SceneContainer = std::set<scene::Scene *>;
class Manager { class Manager {
private: private:
SceneContainer _scenes; SceneContainer _scenes;
SceneContainer::iterator _current; std::optional<scene::Scene *> _current;
scene::Renderer _sceneRenderer; scene::Renderer _sceneRenderer;
...@@ -26,7 +26,7 @@ namespace pg { ...@@ -26,7 +26,7 @@ namespace pg {
inline const SceneContainer & getScenes() const {return this->_scenes;} inline const SceneContainer & getScenes() const {return this->_scenes;}
inline const scene::Renderer & getSceneRenderer() const {return this->_sceneRenderer;} inline const scene::Renderer & getSceneRenderer() const {return this->_sceneRenderer;}
inline void add(scene::Scene * scene) {this->_scenes.insert(std::shared_ptr<scene::Scene>(scene));} inline void add(scene::Scene * scene) {this->_scenes.insert(scene);}
std::optional<scene::Scene *> current() const; std::optional<scene::Scene *> current() const;
......
...@@ -39,6 +39,7 @@ namespace pg::scene { ...@@ -39,6 +39,7 @@ namespace pg::scene {
this->_grid.render(camera, current_time); this->_grid.render(camera, current_time);
if(scene.has_value()) { if(scene.has_value()) {
(*scene)->update(current_time);
(*scene)->render(camera, current_time); (*scene)->render(camera, current_time);
} }
......
...@@ -25,5 +25,6 @@ namespace pg::scene ...@@ -25,5 +25,6 @@ namespace pg::scene
void destroy() override; void destroy() override;
std::string name() const override; std::string name() const override;
std::optional<interface::Interface *> interface() override {return std::optional<interface::Interface *>();}
}; };
} }
\ No newline at end of file
...@@ -189,10 +189,6 @@ namespace pg::scene ...@@ -189,10 +189,6 @@ namespace pg::scene
return "Mesh Scene"; return "Mesh Scene";
} }
interface::Interface* Mesh::interface() {
return &this->_interface;
}
void Mesh::setMesh(const std::string & path) { void Mesh::setMesh(const std::string & path) {
Model gridModel(path); Model gridModel(path);
this->_mesh.generate(gridModel.getMeshGeometry().vertices, gridModel.getMeshGeometry().indices); this->_mesh.generate(gridModel.getMeshGeometry().vertices, gridModel.getMeshGeometry().indices);
......
...@@ -43,6 +43,7 @@ namespace pg::scene ...@@ -43,6 +43,7 @@ namespace pg::scene
public: public:
Mesh(ct::CurveGenerator *, const ct::Curve &); Mesh(ct::CurveGenerator *, const ct::Curve &);
virtual ~Mesh() = default;
void initialize() override; void initialize() override;
void update(double) override; void update(double) override;
...@@ -50,7 +51,7 @@ namespace pg::scene ...@@ -50,7 +51,7 @@ namespace pg::scene
void destroy() override; void destroy() override;
std::string name() const override; std::string name() const override;
interface::Interface* interface() override; virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>(&this->_interface);}
void setMesh(const std::string &); void setMesh(const std::string &);
void setTexture(const std::string &); void setTexture(const std::string &);
......
...@@ -30,9 +30,7 @@ namespace pg::scene { ...@@ -30,9 +30,7 @@ namespace pg::scene {
public: public:
MeshGenerator(); MeshGenerator();
/*virtual ~MeshGenerator() { virtual ~MeshGenerator() = default;
};*/
virtual void initialize(); virtual void initialize();
virtual void update(double); virtual void update(double);
...@@ -40,7 +38,7 @@ namespace pg::scene { ...@@ -40,7 +38,7 @@ namespace pg::scene {
virtual void destroy(); virtual void destroy();
virtual std::string name() const {return "Mesh Generator Scene";}; virtual std::string name() const {return "Mesh Generator Scene";};
virtual interface::Interface * interface() {return &this->_interface;} virtual std::optional<interface::Interface *> interface() {return std::optional<interface::Interface *>(&this->_interface);}
void changeMesh(const std::string &); void changeMesh(const std::string &);
void changeTexture(const std::string &); void changeTexture(const std::string &);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment