24 #include "assets/binary_data.h"
25 #include "assets/material.h"
26 #include "assets/particle_script.h"
27 #include "assets/texture_flags.h"
29 #include "generic/lru_cache.h"
30 #include "generic/object_manager.h"
32 #include "loaders/heightmap_loader.h"
33 #include "managers/window_holder.h"
34 #include "meshes/mesh.h"
43 typedef ObjectManager<AssetID, Mesh, DO_REFCOUNT> MeshManager;
44 typedef ObjectManager<AssetID, Material, DO_REFCOUNT> MaterialManager;
45 typedef ObjectManager<AssetID, Texture, DO_REFCOUNT> TextureManager;
46 typedef ObjectManager<AssetID, Sound, DO_REFCOUNT> SoundManager;
47 typedef ObjectManager<AssetID, Font, DO_REFCOUNT> FontManager;
48 typedef ObjectManager<AssetID, ParticleScript, DO_REFCOUNT>
49 ParticleScriptManager;
50 typedef ObjectManager<AssetID, Binary, DO_REFCOUNT> BinaryManager;
54 FontWeight weight = FONT_WEIGHT_NORMAL;
55 FontStyle style = FONT_STYLE_NORMAL;
56 CharacterSet charset = CHARACTER_SET_LATIN;
60 std::size_t blur_radius = 0;
64 bool stream_audio =
true;
100 ParticleScriptPtr load_particle_script(
101 const Path& filename,
102 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
103 void destroy_particle_script(AssetID
id);
104 ParticleScriptPtr particle_script(AssetID
id);
105 const ParticleScriptPtr particle_script(AssetID
id)
const;
106 std::size_t particle_script_count()
const;
107 bool has_particle_script(AssetID
id)
const;
108 ParticleScriptPtr find_particle_script(
const std::string& name);
111 TexturePtr load_texture(
112 const Path& filename,
113 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
114 void destroy_texture(AssetID
id);
115 TexturePtr texture(AssetID
id);
116 const TexturePtr texture(AssetID
id)
const;
117 std::size_t texture_count()
const;
118 bool has_texture(AssetID
id)
const;
119 TexturePtr find_texture(
const std::string& alias);
122 void destroy_mesh(AssetID
id);
123 MeshPtr mesh(AssetID
id);
124 const MeshPtr mesh(AssetID
id)
const;
125 std::size_t mesh_count()
const;
126 bool has_mesh(AssetID
id)
const;
127 MeshPtr find_mesh(
const std::string& name);
130 MaterialPtr load_material(
131 const Path& filename,
132 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
133 void destroy_material(
const AssetID&
id);
134 MaterialPtr material(
const AssetID&
id);
135 const MaterialPtr material(
const AssetID&
id)
const;
136 std::size_t material_count()
const;
137 bool has_material(
const AssetID&
id)
const;
138 MaterialPtr find_material(
const std::string& name);
143 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
144 void destroy_sound(AssetID
id);
145 SoundPtr sound(AssetID
id);
146 const SoundPtr sound(AssetID
id)
const;
147 std::size_t sound_count()
const;
148 bool has_sound(AssetID
id)
const;
149 SoundPtr find_sound(
const std::string& name);
152 BinaryPtr load_binary(
153 const Path& filename,
154 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
155 BinaryPtr binary(AssetID
id)
const;
156 std::size_t binary_count()
const;
157 bool has_binary(AssetID
id)
const;
158 BinaryPtr find_binary(
const std::string& name);
159 void destroy_binary(AssetID
id);
179 const uint8_t* data,
const std::size_t size,
const FontFlags& flags,
180 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
181 FontPtr create_font_from_family(
182 const std::string& family,
const FontFlags& flags,
183 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
186 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
187 void destroy_font(AssetID
id);
188 FontPtr font(AssetID
id);
189 const FontPtr font(AssetID
id)
const;
190 std::size_t font_count()
const;
191 bool has_font(AssetID
id)
const;
192 FontPtr find_font(
const std::string& alias);
195 TexturePtr create_texture(
196 uint16_t width, uint16_t height,
197 TextureFormat format = TEXTURE_FORMAT_RGBA_4UB_8888,
198 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
199 TexturePtr load_texture(
201 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
203 MaterialPtr create_material(
204 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
208 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
210 VertexDataPtr vertex_data,
211 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
215 VertexSpecification::DEFAULT,
217 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
222 MeshPtr create_mesh_from_submesh(
224 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
226 MeshPtr create_mesh_from_heightmap(
227 const Path& image_file,
229 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
231 MeshPtr create_mesh_from_heightmap(
232 const TexturePtr& texture,
234 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
236 MeshPtr create_mesh_as_cube_with_submesh_per_face(
238 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
239 MaterialPtr create_material_from_texture(
241 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
243 void update(
float dt);
245 virtual MaterialPtr default_material()
const;
247 MaterialPtr clone_material(
248 const AssetID& mat_id,
249 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
250 MaterialPtr clone_default_material(
251 GarbageCollectMethod garbage_collect = GARBAGE_COLLECT_PERIODIC);
256 void run_garbage_collection();
258 bool is_base_manager()
const;
260 std::size_t child_manager_count()
const {
261 return children_.size();
264 const AssetManager* child_manager(std::size_t i)
const {
265 return children_.at(i);
279 std::vector<AssetManager*> children_;
281 children_.push_back(child);
285 children_.erase(std::remove(children_.begin(), children_.end(), child),
289 void set_garbage_collection_method(
const Asset* resource,
290 GarbageCollectMethod method) {
295 if(
auto p =
dynamic_cast<const Mesh*
>(resource)) {
296 mesh_manager_.set_garbage_collection_method(p->id(), method);
297 }
else if(
auto p =
dynamic_cast<const Material*
>(resource)) {
298 material_manager_.set_garbage_collection_method(p->id(), method);
299 }
else if(
auto p =
dynamic_cast<const Font*
>(resource)) {
300 font_manager_.set_garbage_collection_method(p->id(), method);
301 }
else if(
auto p =
dynamic_cast<const Sound*
>(resource)) {
302 sound_manager_.set_garbage_collection_method(p->id(), method);
303 }
else if(
auto p =
dynamic_cast<const Texture*
>(resource)) {
304 texture_manager_.set_garbage_collection_method(p->id(), method);
305 }
else if(
auto p =
dynamic_cast<const ParticleScript*
>(resource)) {
306 particle_script_manager_.set_garbage_collection_method(p->id(),
308 }
else if(
auto p =
dynamic_cast<const Binary*
>(resource)) {
309 binary_manager_.set_garbage_collection_method(p->id(), method);
311 S_ERROR(
"Unhandled asset type. GC method not set");
338 virtual MaterialPtr default_material()
const override;
340 void set_default_material_filename(
const Path& filename);
341 Path default_material_filename()
const;
344 bool on_init()
override;
346 mutable MaterialPtr default_material_;
347 Path default_material_filename_;
349 mutable FontPtr default_body_font_;
350 Path default_body_font_filename_;
352 mutable FontPtr default_heading_font_;
353 Path default_heading_font_filename_;
359 TexturePtr white_tex_;
360 TexturePtr black_tex_;
364 #undef ASSET_METHOD_DEFINITIONS