2025-09-13 14:49:59 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
2026-02-08 12:09:02 +01:00
|
|
|
#include "ILog.hpp"
|
2026-01-23 23:00:35 +00:00
|
|
|
#include "IPixelariumImageView.hpp"
|
2025-09-13 14:49:59 +02:00
|
|
|
#include "ImageViewFactory.hpp"
|
2026-02-08 12:09:02 +01:00
|
|
|
#include "resource.hpp"
|
2025-09-13 14:49:59 +02:00
|
|
|
|
|
|
|
|
// This is intended as an additional abstraction
|
|
|
|
|
// aggregating views that should be rendered (or not)
|
2026-01-23 23:00:35 +00:00
|
|
|
namespace pixelarium::application
|
2025-09-13 14:49:59 +02:00
|
|
|
{
|
2025-09-23 21:57:08 +02:00
|
|
|
/// @brief Instead of directly using the view, we
|
|
|
|
|
/// proxy it through a wrapper. This allows for arbitrary additional data
|
|
|
|
|
/// to be added in future
|
2025-09-13 14:49:59 +02:00
|
|
|
struct RenderImageStateWrapper
|
|
|
|
|
{
|
2025-09-23 21:57:08 +02:00
|
|
|
std::unique_ptr<IPixelariumImageView> view;
|
2025-09-13 14:49:59 +02:00
|
|
|
const bool* show_state;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-26 21:09:51 +02:00
|
|
|
/// @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()
|
2025-09-13 14:49:59 +02:00
|
|
|
class RenderImageManager
|
|
|
|
|
{
|
|
|
|
|
using Pool = resources::ImageResourcePool;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit RenderImageManager(Pool& pool, const utils::log::ILog& log)
|
2025-09-23 21:57:08 +02:00
|
|
|
: view_factory_(std::make_unique<ImageViewFactory>(pool, log)), log_(log)
|
2025-09-13 14:49:59 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 <typename Callable>
|
|
|
|
|
requires std::invocable<Callable, resources::ResourceKey, RenderImageStateWrapper&>
|
|
|
|
|
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<resources::ResourceKey, RenderImageStateWrapper> render_image_map_;
|
|
|
|
|
std::unique_ptr<ImageViewFactory> view_factory_;
|
|
|
|
|
std::mutex mut_;
|
|
|
|
|
std::unordered_set<resources::ResourceKey> keys_to_delete_;
|
2026-02-08 12:09:02 +01:00
|
|
|
std::unordered_set<resources::ResourceKey> failed_keys_cache_;
|
2025-09-13 14:49:59 +02:00
|
|
|
|
|
|
|
|
const utils::log::ILog& log_;
|
|
|
|
|
};
|
2026-01-23 23:00:35 +00:00
|
|
|
} // namespace pixelarium::application
|