Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_reader.h
Go to the documentation of this file.
1#pragma once
2#include "asset_extensions.h"
4#include "../asset_handle.h"
5#include "../asset_flags.h"
6#include <graphics/shader.h>
7
8namespace gfx
9{
10struct texture;
11struct shader;
12} // namespace gfx
13
14namespace unravel
15{
16class mesh;
17class material;
18struct prefab;
19struct scene_prefab;
20struct animation_clip;
21struct physics_material;
22struct audio_clip;
23struct script;
24struct font;
25struct ui_tree;
26struct style_sheet;
27} // namespace unravel
28
30{
31
32auto resolve_compiled_key(const std::string& key) -> std::string;
33auto resolve_compiled_path(const std::string& key) -> fs::path;
34
35namespace detail
36{
37template<typename T>
38inline auto compiled_extension() -> std::string
39{
40 return {};
41}
42
43template<>
44inline auto compiled_extension<gfx::shader>() -> std::string
45{
47}
48} // namespace detail
49
52template<typename T>
53inline auto resolve_compiled_path(const std::string& key) -> fs::path
54{
55 return fs::path(resolve_compiled_path(key).string() + detail::compiled_extension<T>());
56}
57
61auto resolve_compiled_asset_path(const std::string& key, const std::string& source_extension) -> fs::path;
62
63template<typename T>
64auto load_from_file(tpp::thread_pool& pool, asset_handle<T>& output, const std::string& key,
65 load_mode mode = load_mode::immediate) -> bool;
66
67#define DECLARE_LOADER_SPEC(T)\
68template<>\
69auto load_from_file<T>(tpp::thread_pool& pool, asset_handle<T>& output, const std::string& key, load_mode mode) -> bool
70
84
85template<typename T>
86inline auto get_job_name() -> std::string
87{
88 return fmt::format("Loading {}", ex::get_type<T>());
89}
90
91template<typename T>
92inline auto load_from_instance(tpp::thread_pool& pool, asset_handle<T>& output, std::shared_ptr<T> instance) -> bool
93{
94 auto job = pool.schedule(get_job_name<T>(),
95 [](std::shared_ptr<T> instance)
96 {
97 return instance;
98 },
99 instance)
100 .share();
101
102 output.set_internal_job(job);
103
104 return true;
105}
106} // namespace unravel::asset_reader
#define DECLARE_LOADER_SPEC(T)
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
ImGui::Font::Enum font
Definition hub.cpp:30
auto get_type() -> const std::string &
auto get_current_renderer_filename_extension() -> const std::string &
auto compiled_extension() -> std::string
auto compiled_extension< gfx::shader >() -> std::string
auto load_from_file(tpp::thread_pool &pool, asset_handle< T > &output, const std::string &key, load_mode mode=load_mode::immediate) -> bool
auto resolve_compiled_asset_path(const std::string &key, const std::string &source_extension) -> fs::path
auto resolve_compiled_path(const std::string &key) -> fs::path
auto resolve_compiled_key(const std::string &key) -> std::string
auto load_from_instance(tpp::thread_pool &pool, asset_handle< T > &output, std::shared_ptr< T > instance) -> bool
auto get_job_name() -> std::string
load_mode
Controls whether an asset is loaded immediately or deferred until first access.
Definition asset_flags.h:17
@ immediate
Schedule load on thread pool now (default, backward compatible).
Thread-safe handle to an 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 UI style sheet asset (CSS/RCSS document).
Definition style_sheet.h:26
Represents a UI visual tree asset (HTML/RML document).
Definition ui_tree.h:25