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"
40 typedef ObjectManager<MeshID, Mesh, DO_REFCOUNT> MeshManager;
41 typedef ObjectManager<MaterialID, Material, DO_REFCOUNT> MaterialManager;
42 typedef ObjectManager<TextureID, Texture, DO_REFCOUNT> TextureManager;
43 typedef ObjectManager<SoundID, Sound, DO_REFCOUNT> SoundManager;
44 typedef ObjectManager<FontID, Font, DO_REFCOUNT> FontManager;
45 typedef ObjectManager<ParticleScriptID, ParticleScript, DO_REFCOUNT> ParticleScriptManager;
49 MipmapGenerate mipmap = MIPMAP_GENERATE_COMPLETE,
50 TextureWrap wrap = TEXTURE_WRAP_REPEAT,
51 TextureFilter filter = TEXTURE_FILTER_POINT):
58 MipmapGenerate mipmap = MIPMAP_GENERATE_COMPLETE;
59 TextureWrap wrap = TEXTURE_WRAP_REPEAT;
60 TextureFilter filter = TEXTURE_FILTER_POINT;
61 TextureFreeData free_data = TEXTURE_FREE_DATA_AFTER_UPLOAD;
62 bool flip_vertically =
false;
63 bool auto_upload =
true;
68 FontWeight weight = FONT_WEIGHT_NORMAL;
69 CharacterSet charset = CHARACTER_SET_LATIN;
73 bool stream_audio =
true;
108 ParticleScriptPtr new_particle_script_from_file(
const Path &filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
112 std::size_t particle_script_count()
const;
114 ParticleScriptPtr find_particle_script(
const std::string& name);
117 TexturePtr new_texture_from_file(
const Path& filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
120 const TexturePtr texture (
TextureID id)
const;
121 std::size_t texture_count()
const;
123 TexturePtr find_texture(
const std::string& alias);
127 void destroy_mesh(
MeshID id);
129 const MeshPtr mesh (
MeshID id)
const;
130 std::size_t mesh_count()
const;
131 bool has_mesh(
MeshID id)
const;
132 MeshPtr find_mesh(
const std::string& name);
136 MaterialPtr new_material_from_file(
const Path &filename, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
139 const MaterialPtr material (
const MaterialID&
id)
const;
140 std::size_t material_count()
const;
141 bool has_material(
const MaterialID&
id)
const;
142 MaterialPtr find_material(
const std::string& name);
146 SoundPtr new_sound_from_file(
147 const Path& filename,
149 GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC
151 void destroy_sound(
SoundID id);
153 const SoundPtr sound (
SoundID id)
const;
154 std::size_t sound_count()
const;
155 bool has_sound(
SoundID id)
const;
156 SoundPtr find_sound(
const std::string& name);
160 FontPtr new_font_from_file(
const Path &filename,
const FontFlags& flags=
FontFlags(), GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
161 void destroy_font(
FontID id);
163 const FontPtr font (
FontID id)
const;
164 std::size_t font_count()
const;
165 bool has_font(
FontID id)
const;
166 FontPtr find_font(
const std::string& alias);
169 TexturePtr new_texture(uint16_t width, uint16_t height, TextureFormat format=TEXTURE_FORMAT_RGBA_4UB_8888, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
170 TexturePtr new_texture_from_file(
const Path& path,
TextureFlags flags, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
172 MaterialPtr new_material(GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
174 MeshPtr new_mesh(
VertexSpecification vertex_specification, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
175 MeshPtr new_mesh(VertexDataPtr vertex_data, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
181 MeshPtr new_mesh_from_submesh(
SubMesh* submesh, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
184 GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC
187 MeshPtr new_mesh_from_heightmap(
190 GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC
193 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);
194 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);
195 MeshPtr new_mesh_as_cube_with_submesh_per_face(
float width, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
196 MaterialPtr new_material_from_texture(
TextureID texture, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
198 void update(
float dt);
200 virtual MaterialPtr default_material()
const;
202 MaterialPtr clone_material(
const MaterialID& mat_id, GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
203 MaterialPtr clone_default_material(GarbageCollectMethod garbage_collect=GARBAGE_COLLECT_PERIODIC);
207 void run_garbage_collection();
209 bool is_base_manager()
const;
222 std::unordered_map<Path, MaterialID> template_materials_;
223 std::set<MaterialID> materials_loading_;
225 MaterialPtr get_template_material(
const Path &path);
227 std::set<AssetManager*> children_;
229 children_.insert(child);
233 children_.erase(child);
236 void set_garbage_collection_method(
const Asset* resource, GarbageCollectMethod method) {
240 if(
auto p =
dynamic_cast<const Mesh*
>(resource)) {
241 mesh_manager_.set_garbage_collection_method(p->id(), method);
242 }
else if(
auto p =
dynamic_cast<const Material*
>(resource)) {
243 material_manager_.set_garbage_collection_method(p->id(), method);
244 }
else if(
auto p =
dynamic_cast<const Font*
>(resource)) {
245 font_manager_.set_garbage_collection_method(p->id(), method);
246 }
else if(
auto p =
dynamic_cast<const Sound*
>(resource)) {
247 sound_manager_.set_garbage_collection_method(p->id(), method);
248 }
else if(
auto p =
dynamic_cast<const Texture*
>(resource)) {
249 texture_manager_.set_garbage_collection_method(p->id(), method);
250 }
else if(
auto p =
dynamic_cast<const ParticleScript*
>(resource)) {
251 particle_script_manager_.set_garbage_collection_method(p->id(), method);
253 S_ERROR(
"Unhandled asset type. GC method not set");
268 bool init() {
return true; }
283 virtual MaterialPtr default_material()
const;
285 void set_default_material_filename(
const Path &filename);
286 Path default_material_filename()
const;
289 mutable MaterialPtr default_material_;
290 Path default_material_filename_;
292 mutable FontPtr default_body_font_;
293 Path default_body_font_filename_;
295 mutable FontPtr default_heading_font_;
296 Path default_heading_font_filename_;
302 TexturePtr white_tex_;
303 TexturePtr black_tex_;
308 #undef ASSET_METHOD_DEFINITIONS