diff --git a/Main b/Main index 7276334660cba1c76f07a9bc517346b257a3e2fb..ab6ab60176414d4f8d52338fc36679d0d9183470 100755 Binary files a/Main and b/Main differ diff --git a/source/engine/graphics/front/engine/Engine.cpp b/source/engine/graphics/front/engine/Engine.cpp index fd7282a893c9cb64991b81330ee2b07eea0646ee..f5e4b127a70c0cc5b46954e7919742152cacdb88 100644 --- a/source/engine/graphics/front/engine/Engine.cpp +++ b/source/engine/graphics/front/engine/Engine.cpp @@ -23,6 +23,36 @@ namespace megu { 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() { if(this->_window.isOpen()) { // Draw Layers diff --git a/source/engine/graphics/front/engine/Engine.hpp b/source/engine/graphics/front/engine/Engine.hpp index 6442d3f8e6998f0a1ac0dc438bdabfdf68bd9e61..b9a88bc84659a6a157a72b53ee07dc4d1cdc1828 100644 --- a/source/engine/graphics/front/engine/Engine.hpp +++ b/source/engine/graphics/front/engine/Engine.hpp @@ -1,6 +1,7 @@ #pragma once #include <map> +#include <optional> #include <engine/graphics/front/group/DrawGroup.hpp> #include <engine/graphics/front/group/FrameBufferGroup.hpp> @@ -17,6 +18,16 @@ namespace megu { void push(Priority, const Renderer &); 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(); diff --git a/source/engine/graphics/front/engine/Layer.cpp b/source/engine/graphics/front/engine/Layer.cpp index 63a0e4d474c7ee148101d5b5e808f7c8cb65fea7..22a78dc175bd00f6b0af360519e1fa1413eaffa6 100644 --- a/source/engine/graphics/front/engine/Layer.cpp +++ b/source/engine/graphics/front/engine/Layer.cpp @@ -11,6 +11,21 @@ namespace megu { 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 { this->_frameBuffer.bind(); diff --git a/source/engine/graphics/front/engine/Layer.hpp b/source/engine/graphics/front/engine/Layer.hpp index 5ba2a668b72e645b4ecbf08ad92a4b6b68eb40ef..ee585b73528ea6039528ba75e8da5f28f8048419 100644 --- a/source/engine/graphics/front/engine/Layer.hpp +++ b/source/engine/graphics/front/engine/Layer.hpp @@ -1,6 +1,7 @@ #pragma once #include <map> +#include <optional> #include <engine/graphics/back/buffers/FrameBuffer.hpp> #include <engine/graphics/front/group/DrawGroup.hpp> @@ -15,8 +16,12 @@ namespace megu { ~Layer() = default; 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 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; diff --git a/source/engine/graphics/front/engine/Priority.hpp b/source/engine/graphics/front/engine/Priority.hpp index e3318408204c286f7c07e2839f8f6bef40a58090..1b628a4f2d219fe993ddeee3f30d789383ecae55 100644 --- a/source/engine/graphics/front/engine/Priority.hpp +++ b/source/engine/graphics/front/engine/Priority.hpp @@ -1,6 +1,7 @@ #pragma once #include <stddef.h> +#include <map> namespace megu { using Priority = size_t; diff --git a/source/engine/graphics/utility/reference_sorter.hpp b/source/engine/graphics/utility/reference_sorter.hpp index 54353b6e9beb6d079c5f7eb16f9384937c884298..7abf0577bbda7fb5d0992f596151a38e64ce4ea1 100644 --- a/source/engine/graphics/utility/reference_sorter.hpp +++ b/source/engine/graphics/utility/reference_sorter.hpp @@ -7,9 +7,11 @@ namespace megu { 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; + + template <class U> + friend bool operator<(const U &, const U &); }; } diff --git a/source/engine/graphics/utility/reference_sorter.tpp b/source/engine/graphics/utility/reference_sorter.tpp index c1226ad6e56d719f5592ee07ef9d18b352635a67..e8d0c3258de8e7c92396f4ddef11d38585e96595 100644 --- a/source/engine/graphics/utility/reference_sorter.tpp +++ b/source/engine/graphics/utility/reference_sorter.tpp @@ -1,18 +1,18 @@ #include "reference_sorter.hpp" namespace megu { - template <class T> - bool operator<(const T & obj_1, const T & obj_2) { - return &obj_1 < &obj_2; - } - template <class T> bool reference_sorter<T>::operator()(const T & obj_1, const T & obj_2) const { 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 { 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 diff --git a/source/main.cpp b/source/main.cpp index dd11de7f3c0414ab6e496ccd4a91c91391846d22..cc854ff9fa54e1fd7040536f22e2a5be82628810 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -186,7 +186,7 @@ int main(int argc, const char * argv[]) { frameCount++; if(currentTime - previousTime >= 1.0) { - //window.setTitle(std::to_string(frameCount)); + window.setTitle(std::to_string(frameCount)); frameCount = 0; previousTime = currentTime;