Skip to content
Snippets Groups Projects
Commit 9c36372b authored by Baton Théau's avatar Baton Théau
Browse files

Add getter for Engine and Layer

parent 195b2e99
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -23,6 +23,36 @@ namespace megu { ...@@ -23,6 +23,36 @@ namespace megu {
this->_layers[layer_priority]->push(draw_priority, group); this->_layers[layer_priority]->push(draw_priority, group);
} }
void GraphicEngine::remove(Priority priority) {
auto it = this->_layers.find(priority);
if(it != this->_layers.end()) {
this->_layers.erase(it);
}
}
void GraphicEngine::remove(Priority layer_priority, Priority draw_priority) {
auto it = this->_layers.find(layer_priority);
if(it != this->_layers.end()) {
it->second->remove(draw_priority);
}
}
std::optional<std::reference_wrapper<const Layer>> GraphicEngine::get(Priority priority) const {
const auto it = this->_layers.find(priority);
if(it != this->_layers.end()) {
return *it->second;
}
return {};
}
std::optional<std::reference_wrapper<const DrawGroup>> GraphicEngine::get(Priority layer_priority, Priority draw_priority) const {
const auto it = this->_layers.find(layer_priority);
if(it != this->_layers.end()) {
return it->second->get(draw_priority);
}
return {};
}
void GraphicEngine::step() { void GraphicEngine::step() {
if(this->_window.isOpen()) { if(this->_window.isOpen()) {
// Draw Layers // Draw Layers
......
#pragma once #pragma once
#include <map> #include <map>
#include <optional>
#include <engine/graphics/front/group/DrawGroup.hpp> #include <engine/graphics/front/group/DrawGroup.hpp>
#include <engine/graphics/front/group/FrameBufferGroup.hpp> #include <engine/graphics/front/group/FrameBufferGroup.hpp>
...@@ -18,6 +19,16 @@ namespace megu { ...@@ -18,6 +19,16 @@ namespace megu {
void push(Priority, const Renderer &); void push(Priority, const Renderer &);
void push(Priority, Priority, const DrawGroup &); void push(Priority, Priority, const DrawGroup &);
void remove(Priority);
void remove(Priority, Priority);
std::optional<std::reference_wrapper<const Layer>> get(Priority) const;
std::optional<std::reference_wrapper<const DrawGroup>> get(Priority, Priority) const;
inline bool empty() const {return this->_layers.empty();}
inline const Renderer & renderer() const {return this->_renderer;}
inline const std::map<Priority, std::unique_ptr<Layer>> & layers() const {return this->_layers;}
void step(); void step();
private: private:
......
...@@ -11,6 +11,21 @@ namespace megu { ...@@ -11,6 +11,21 @@ namespace megu {
this->_objects[priority] = &group; this->_objects[priority] = &group;
} }
void Layer::remove(Priority priority) {
auto it = this->_objects.find(priority);
if(it != this->_objects.end()) {
this->_objects.erase(it);
}
}
std::optional<std::reference_wrapper<const DrawGroup>> Layer::get(Priority priority) const {
const auto it = this->_objects.find(priority);
if(it != this->_objects.end()) {
return *it->second;
}
return {};
}
const Texture & Layer::draw(const Window & window, const TextureArray & textures) const { const Texture & Layer::draw(const Window & window, const TextureArray & textures) const {
this->_frameBuffer.bind(); this->_frameBuffer.bind();
......
#pragma once #pragma once
#include <map> #include <map>
#include <optional>
#include <engine/graphics/back/buffers/FrameBuffer.hpp> #include <engine/graphics/back/buffers/FrameBuffer.hpp>
#include <engine/graphics/front/group/DrawGroup.hpp> #include <engine/graphics/front/group/DrawGroup.hpp>
...@@ -15,8 +16,12 @@ namespace megu { ...@@ -15,8 +16,12 @@ namespace megu {
~Layer() = default; ~Layer() = default;
void push(Priority, const DrawGroup &); void push(Priority, const DrawGroup &);
void remove(Priority);
std::optional<std::reference_wrapper<const DrawGroup>> get(Priority) const;
inline bool empty() const {return this->_objects.empty();} inline bool empty() const {return this->_objects.empty();}
inline const Renderer & renderer() const {return this->_renderer;}
inline const std::map<Priority, DrawGroup const *> & groups() const {return this->_objects;}
virtual const Texture & draw(const Window &, const TextureArray &) const; virtual const Texture & draw(const Window &, const TextureArray &) const;
......
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include <map>
namespace megu { namespace megu {
using Priority = size_t; using Priority = size_t;
......
...@@ -7,9 +7,11 @@ namespace megu { ...@@ -7,9 +7,11 @@ namespace megu {
reference_sorter() = default; reference_sorter() = default;
~reference_sorter() = default; ~reference_sorter() = default;
friend bool operator<(const T &, const T &);
bool operator()(const T &, const T &) const; bool operator()(const T &, const T &) const;
bool operator()(const T *, const T *) const; bool operator()(const T *, const T *) const;
template <class U>
friend bool operator<(const U &, const U &);
}; };
} }
......
#include "reference_sorter.hpp" #include "reference_sorter.hpp"
namespace megu { namespace megu {
template <class T>
bool operator<(const T & obj_1, const T & obj_2) {
return &obj_1 < &obj_2;
}
template <class T> template <class T>
bool reference_sorter<T>::operator()(const T & obj_1, const T & obj_2) const { bool reference_sorter<T>::operator()(const T & obj_1, const T & obj_2) const {
return &obj_1 < &obj_2; return &obj_1 < &obj_2;
...@@ -15,4 +10,9 @@ namespace megu { ...@@ -15,4 +10,9 @@ namespace megu {
bool reference_sorter<T>::operator()(const T * obj_1, const T * obj_2) const { bool reference_sorter<T>::operator()(const T * obj_1, const T * obj_2) const {
return obj_1 < obj_2; return obj_1 < obj_2;
} }
template <class T>
bool operator<(const T & obj_1, const T & obj_2) {
return &obj_1 < &obj_2;
}
} }
\ No newline at end of file
...@@ -186,7 +186,7 @@ int main(int argc, const char * argv[]) { ...@@ -186,7 +186,7 @@ int main(int argc, const char * argv[]) {
frameCount++; frameCount++;
if(currentTime - previousTime >= 1.0) { if(currentTime - previousTime >= 1.0) {
//window.setTitle(std::to_string(frameCount)); window.setTitle(std::to_string(frameCount));
frameCount = 0; frameCount = 0;
previousTime = currentTime; previousTime = currentTime;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment