#pragma once #include #include #include #include #include "ImageViewFactory.hpp" #include "rendering/IPixelariumImageView.hpp" #include "resources/resource.hpp" #include "utilities/ILog.hpp" // This is intended as an additional abstraction // aggregating views that should be rendered (or not) namespace pixelarium::render { /// @brief Instead of directly using the view, we /// proxy it through a wrapper. This allows for arbitrary additional data /// to be added in future struct RenderImageStateWrapper { std::unique_ptr view; const bool* show_state; }; /// @brief Manage instances of IPixelariumImageView. /// /// This class is used to keep track of what must be rendered. /// It manages a set of IPixelariumImageView instances that can be traversed /// via its Enumerate() function. /// Views that shall not be rendered anymore should be marked for deletion /// with MarkForDeletion() class RenderImageManager { using Pool = resources::ImageResourcePool; public: explicit RenderImageManager(Pool& pool, const utils::log::ILog& log) : view_factory_(std::make_unique(pool, log)), log_(log) { } void Clear() noexcept; void Add(resources::ResourceKey key) noexcept; bool Remove(resources::ResourceKey key) noexcept; // can't be const because func mutates the state template requires std::invocable void Enumerate(Callable&& func) { for (auto& [key, val] : this->render_image_map_) { if (val.view != nullptr) { func(key, val); } } } void MarkForDeletion(resources::ResourceKey key); void UpdateCollection(); private: std::unordered_map render_image_map_; std::unique_ptr view_factory_; std::mutex mut_; std::unordered_set keys_to_delete_; const utils::log::ILog& log_; }; } // namespace pixelarium::render