24 #include "generic/object_manager.h"
25 #include "managers/window_holder.h"
26 #include "loaders/heightmap_loader.h"
29 #include "meshes/mesh.h"
30 #include "assets/material.h"
33 #include "assets/particle_script.h"
35 #include "assets/binary_data.h"
41 typedef ObjectManager<MeshID, Mesh, DO_REFCOUNT> MeshManager;
42 typedef ObjectManager<MaterialID, Material, DO_REFCOUNT> MaterialManager;
43 typedef ObjectManager<TextureID, Texture, DO_REFCOUNT> TextureManager;
44 typedef ObjectManager<SoundID, Sound, DO_REFCOUNT> SoundManager;
45 typedef ObjectManager<FontID, Font, DO_REFCOUNT> FontManager;
46 typedef ObjectManager<ParticleScriptID, ParticleScript, DO_REFCOUNT> ParticleScriptManager;
47 typedef ObjectManager<BinaryID, Binary, DO_REFCOUNT> BinaryManager;
51 MipmapGenerate mipmap = MIPMAP_GENERATE_COMPLETE,
52 TextureWrap wrap = TEXTURE_WRAP_REPEAT,
53 TextureFilter filter = TEXTURE_FILTER_POINT):
60 MipmapGenerate mipmap = MIPMAP_GENERATE_COMPLETE;
61 TextureWrap wrap = TEXTURE_WRAP_REPEAT;
62 TextureFilter filter = TEXTURE_FILTER_POINT;
63 TextureFreeData free_data = TEXTURE_FREE_DATA_AFTER_UPLOAD;
64 bool flip_vertically =
false;
65 bool auto_upload =
true;
70 FontWeight weight = FONT_WEIGHT_NORMAL;
71 FontStyle style = FONT_STYLE_NORMAL;
72 CharacterSet charset = CHARACTER_SET_LATIN;
76 std::size_t blur_radius = 0;
80 bool stream_audio =
true;
115 ParticleScriptPtr new_particle_script_from_file(
const Path &filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
119 std::size_t particle_script_count()
const;
121 ParticleScriptPtr find_particle_script(
const std::string& name);
124 TexturePtr new_texture_from_file(
const Path& filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
127 const TexturePtr texture (
TextureID id)
const;
128 std::size_t texture_count()
const;
130 TexturePtr find_texture(
const std::string& alias);
134 void destroy_mesh(
MeshID id);
136 const MeshPtr mesh (
MeshID id)
const;
137 std::size_t mesh_count()
const;
138 bool has_mesh(
MeshID id)
const;
139 MeshPtr find_mesh(
const std::string& name);
143 MaterialPtr new_material_from_file(
const Path &filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
146 const MaterialPtr material (
const MaterialID&
id)
const;
147 std::size_t material_count()
const;
148 bool has_material(
const MaterialID&
id)
const;
149 MaterialPtr find_material(
const std::string& name);
153 SoundPtr new_sound_from_file(
154 const Path& filename,
156 GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC
158 void destroy_sound(
SoundID id);
160 const SoundPtr sound (
SoundID id)
const;
161 std::size_t sound_count()
const;
162 bool has_sound(
SoundID id)
const;
163 SoundPtr find_sound(
const std::string& name);
166 BinaryPtr new_binary_from_file(
const Path& filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
167 BinaryPtr binary(
BinaryID id)
const;
168 std::size_t binary_count()
const;
170 BinaryPtr find_binary(
const std::string& name);
189 FontPtr
new_font_from_family(
const std::string& family,
const FontFlags& flags, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
190 FontPtr new_font_from_file(
const Path &filename,
const FontFlags& flags=
FontFlags(), GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
191 void destroy_font(
FontID id);
193 const FontPtr font (
FontID id)
const;
194 std::size_t font_count()
const;
195 bool has_font(
FontID id)
const;
196 FontPtr find_font(
const std::string& alias);
199 TexturePtr new_texture(uint16_t width, uint16_t height, TextureFormat format=TEXTURE_FORMAT_RGBA_4UB_8888, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
200 TexturePtr new_texture_from_file(
const Path& path,
TextureFlags flags, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
202 MaterialPtr new_material(GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
204 MeshPtr new_mesh(
VertexSpecification vertex_specification, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
205 MeshPtr new_mesh(VertexDataPtr vertex_data, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
211 MeshPtr new_mesh_from_submesh(
SubMesh* submesh, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
214 GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC
217 MeshPtr new_mesh_from_heightmap(
220 GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC
223 MeshPtr new_mesh_from_vertices(
VertexSpecification vertex_specification,
const std::string& submesh_name,
const std::vector<smlt::Vec2>& vertices, MeshArrangement arrangement=MESH_ARRANGEMENT_TRIANGLES, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
224 MeshPtr new_mesh_from_vertices(
VertexSpecification vertex_specification,
const std::string& submesh_name,
const std::vector<smlt::Vec3>& vertices, MeshArrangement arrangement=MESH_ARRANGEMENT_TRIANGLES, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
225 MeshPtr new_mesh_as_cube_with_submesh_per_face(
float width, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
226 MaterialPtr new_material_from_texture(
TextureID texture, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
228 void update(
float dt);
230 virtual MaterialPtr default_material()
const;
232 MaterialPtr clone_material(
const MaterialID& mat_id, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
233 MaterialPtr clone_default_material(GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
238 void run_garbage_collection();
240 bool is_base_manager()
const;
242 std::size_t child_manager_count()
const {
243 return children_.size();
246 const AssetManager* child_manager(std::size_t i)
const {
247 return children_.at(i);
262 std::unordered_map<Path, MaterialID> template_materials_;
263 std::set<MaterialID> materials_loading_;
265 MaterialPtr get_template_material(
const Path &path);
267 std::vector<AssetManager*> children_;
269 children_.push_back(child);
273 children_.erase(std::remove(children_.begin(), children_.end(), child), children_.end());
276 void set_garbage_collection_method(
const Asset* resource, GarbageCollectMethod method) {
280 if(
auto p =
dynamic_cast<const Mesh*
>(resource)) {
281 mesh_manager_.set_garbage_collection_method(p->id(), method);
282 }
else if(
auto p =
dynamic_cast<const Material*
>(resource)) {
283 material_manager_.set_garbage_collection_method(p->id(), method);
284 }
else if(
auto p =
dynamic_cast<const Font*
>(resource)) {
285 font_manager_.set_garbage_collection_method(p->id(), method);
286 }
else if(
auto p =
dynamic_cast<const Sound*
>(resource)) {
287 sound_manager_.set_garbage_collection_method(p->id(), method);
288 }
else if(
auto p =
dynamic_cast<const Texture*
>(resource)) {
289 texture_manager_.set_garbage_collection_method(p->id(), method);
290 }
else if(
auto p =
dynamic_cast<const ParticleScript*
>(resource)) {
291 particle_script_manager_.set_garbage_collection_method(p->id(), method);
292 }
else if(
auto p =
dynamic_cast<const Binary*
>(resource)) {
293 binary_manager_.set_garbage_collection_method(p->id(), method);
295 S_ERROR(
"Unhandled asset type. GC method not set");
310 bool init() {
return true; }
325 virtual MaterialPtr default_material()
const;
327 void set_default_material_filename(
const Path &filename);
328 Path default_material_filename()
const;
331 mutable MaterialPtr default_material_;
332 Path default_material_filename_;
334 mutable FontPtr default_body_font_;
335 Path default_body_font_filename_;
337 mutable FontPtr default_heading_font_;
338 Path default_heading_font_filename_;
344 TexturePtr white_tex_;
345 TexturePtr black_tex_;
350 #undef ASSET_METHOD_DEFINITIONS