Unravel Engine C++ Reference
Loading...
Searching...
No Matches
thumbnail_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include <base/basetypes.hpp>
4#include <context/context.hpp>
5#include <graphics/shader.h>
6#include <graphics/texture.h>
7
9#include <engine/ecs/scene.h>
10
11#include <chrono>
12
13
14namespace gfx
15{
16struct texture;
17struct shader;
18} // namespace gfx
19
20namespace unravel
21{
22class mesh;
23class material;
24struct prefab;
25struct scene_prefab;
26struct animation_clip;
27struct physics_material;
28struct audio_clip;
29struct script;
30struct font;
31struct ui_tree;
32struct style_sheet;
33class rendering_system;
34} // namespace unravel
35
36
37namespace unravel
38{
39
40
42{
43 using clock = std::chrono::steady_clock;
44
46 {
47 auto get() -> gfx::texture::ptr;
48 void set(gfx::texture::ptr tex);
49
55
56 bool is_cached_on_disk{false};
57 fs::path cache_path{};
58
59 clock::time_point last_access_time{clock::now()};
60 };
61
62 struct generator
63 {
64 std::map<hpp::uuid, generated_thumbnail> thumbnails;
65
66 auto get_scene() -> scene&;
67
68 void reset(rendering_system& rpath);
69
70 void reset_wait();
71
72 int remaining{0};
73
74 std::array<scene, 3> scenes{scene{"thumbnail"}, scene{"thumbnail"}, scene{"thumbnail"}};
75
77 };
78
79 auto init(rtti::context& ctx) -> bool;
80 auto deinit(rtti::context& ctx) -> bool;
83
84 template<typename T>
86 {
87 return thumbnails_.file.get();
88 }
89
90
91
92 auto get_thumbnail(const fs::path& path) -> gfx::texture::ptr;
93
94 auto get_gizmo_icon(entt::handle e) -> gfx::texture::ptr;
95
96
97 void regenerate_thumbnail(const hpp::uuid& uid);
98 void remove_thumbnail(const hpp::uuid& uid);
99 void clear_thumbnails();
100
102 void set_cache_directory(const fs::path& cache_dir);
103
105 auto get_cache_path(const hpp::uuid& uid) const -> fs::path;
106
108 auto load_cached_thumbnail(const hpp::uuid& uid) -> gfx::texture::ptr;
109
111 void save_thumbnail_to_cache(const hpp::uuid& uid, gfx::texture::ptr tex);
112
114 void invalidate_cache_entry(const hpp::uuid& uid);
115
116private:
117 struct thumbnail_cache
118 {
119 asset_handle<gfx::texture> transparent;
121 asset_handle<gfx::texture> folder_empty;
136
137 } thumbnails_;
138
139
140 struct gizmo_cache
141 {
144 asset_handle<gfx::texture> directional_light;
145 asset_handle<gfx::texture> point_light;
147 asset_handle<gfx::texture> audio_source;
148 asset_handle<gfx::texture> reflection_probe;
149 asset_handle<gfx::texture> particle_emitter;
150
151 } gimzmo_icons_;
152
153
154 generator gen_;
155
156 std::map<std::string, asset_handle<gfx::texture>> icons_;
157 std::map<std::string, asset_handle<gfx::texture>> gizmo_icons_;
158
160 void commit_pending_snapshots();
161
163 void evict_unused_thumbnails(std::chrono::seconds scan_interval, std::chrono::seconds idle_timeout);
164
166 fs::path cache_directory_{};
167
169 clock::time_point last_eviction_scan_{clock::now()};
170
171 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
172};
173
174
175#define DECLARE_THUMBNAIL_SPEC(T) template<>\
176auto thumbnail_manager::get_thumbnail<T>(const asset_handle<T>& asset) -> gfx::texture::ptr;
177
191} // namespace unravel
Base class for materials used in rendering.
Definition material.h:44
Main class representing a 3D mesh with support for different LODs, submeshes, and skinning.
Definition mesh.h:323
Base class for different rendering paths in the ACE framework.
std::chrono::duration< float > delta_t
ImGui::Font::Enum font
Definition hub.cpp:30
Thread-safe handle to an asset.
auto get(bool wait=true) const -> std::shared_ptr< T >
Gets the shared pointer to the asset.
Struct representing an animation.
Definition animation.h:99
Struct representing an audio clip.
Definition audio_clip.h:16
Represents the physical properties of a material.
Represents a generic prefab with a buffer for serialized data.
Definition prefab.h:18
Represents a scene-specific prefab. Inherits from the generic prefab structure.
Definition prefab.h:31
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:70
Represents a UI style sheet asset (CSS/RCSS document).
Definition style_sheet.h:26
gfx::texture::ptr snapshot
Owned snapshot copied from the preview OBUFFER (not a live render target).
gfx::texture::ptr pending_snapshot
Queued during capture; committed after gfx::frame() so the GPU blit has finished.
std::map< hpp::uuid, generated_thumbnail > thumbnails
void reset(rendering_system &rpath)
void invalidate_cache_entry(const hpp::uuid &uid)
Invalidates a cached thumbnail on disk.
auto load_cached_thumbnail(const hpp::uuid &uid) -> gfx::texture::ptr
Loads a cached thumbnail from disk (stub – returns nullptr for now).
auto init(rtti::context &ctx) -> bool
auto get_thumbnail(const asset_handle< T > &asset) -> gfx::texture::ptr
std::chrono::steady_clock clock
auto deinit(rtti::context &ctx) -> bool
void set_cache_directory(const fs::path &cache_dir)
Sets the directory for persistent thumbnail caching.
void save_thumbnail_to_cache(const hpp::uuid &uid, gfx::texture::ptr tex)
Saves a generated thumbnail to disk (stub – no-op for now).
auto get_gizmo_icon(entt::handle e) -> gfx::texture::ptr
void on_frame_update(rtti::context &ctx, delta_t)
void on_frame_end(rtti::context &ctx, delta_t)
void remove_thumbnail(const hpp::uuid &uid)
void regenerate_thumbnail(const hpp::uuid &uid)
auto get_cache_path(const hpp::uuid &uid) const -> fs::path
Gets the disk cache path for a given asset uid.
Represents a UI visual tree asset (HTML/RML document).
Definition ui_tree.h:25
#define DECLARE_THUMBNAIL_SPEC(T)