Quellcode durchsuchen

Register resource types from Device

Daniele Bartolini vor 9 Jahren
Ursprung
Commit
a9c1aa0d5e
3 geänderte Dateien mit 48 neuen und 46 gelöschten Zeilen
  1. 44 0
      src/device/device.cpp
  2. 1 45
      src/resource/resource_manager.cpp
  3. 3 1
      src/resource/resource_manager.h

+ 44 - 0
src/device/device.cpp

@@ -8,35 +8,48 @@
 #include "audio.h"
 #include "bundle_compiler.h"
 #include "config.h"
+#include "config_resource.h"
 #include "console_server.h"
 #include "device.h"
 #include "disk_filesystem.h"
 #include "file.h"
 #include "filesystem.h"
+#include "font_resource.h"
 #include "input_device.h"
 #include "input_manager.h"
+#include "level_resource.h"
 #include "log.h"
 #include "lua_environment.h"
+#include "lua_resource.h"
 #include "map.h"
 #include "material_manager.h"
+#include "material_resource.h"
 #include "matrix4x4.h"
 #include "memory.h"
+#include "mesh_resource.h"
 #include "os.h"
 #include "os_event_queue.h"
+#include "package_resource.h"
 #include "path.h"
 #include "physics.h"
+#include "physics_resource.h"
 #include "profiler.h"
 #include "proxy_allocator.h"
 #include "resource_loader.h"
 #include "resource_manager.h"
 #include "resource_package.h"
 #include "shader_manager.h"
+#include "shader_resource.h"
 #include "sjson.h"
+#include "sound_resource.h"
+#include "sprite_resource.h"
 #include "string_stream.h"
 #include "string_utils.h"
 #include "temp_allocator.h"
+#include "texture_resource.h"
 #include "types.h"
 #include "unit_manager.h"
+#include "unit_resource.h"
 #include "vector3.h"
 #include "world.h"
 #include <bgfx/bgfx.h>
@@ -368,6 +381,37 @@ void Device::run()
 		_resource_loader  = CE_NEW(_allocator, ResourceLoader)(*_bundle_filesystem);
 		_resource_manager = CE_NEW(_allocator, ResourceManager)(*_resource_loader);
 
+		namespace pcr = physics_config_resource;
+		namespace phr = physics_resource;
+		namespace pkr = package_resource;
+		namespace sdr = sound_resource;
+		namespace mhr = mesh_resource;
+		namespace utr = unit_resource;
+		namespace txr = texture_resource;
+		namespace mtr = material_resource;
+		namespace lur = lua_resource;
+		namespace ftr = font_resource;
+		namespace lvr = level_resource;
+		namespace spr = sprite_resource;
+		namespace shr = shader_resource;
+		namespace sar = sprite_animation_resource;
+		namespace cor = config_resource;
+		_resource_manager->register_resource_type(RESOURCE_TYPE_SCRIPT,           lur::load, lur::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_TEXTURE,          txr::load, txr::unload, txr::online, txr::offline);
+		_resource_manager->register_resource_type(RESOURCE_TYPE_MESH,             mhr::load, mhr::unload, mhr::online, mhr::offline);
+		_resource_manager->register_resource_type(RESOURCE_TYPE_SOUND,            sdr::load, sdr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_UNIT,             utr::load, utr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_SPRITE,           spr::load, spr::unload, spr::online, spr::offline);
+		_resource_manager->register_resource_type(RESOURCE_TYPE_PACKAGE,          pkr::load, pkr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_PHYSICS,          phr::load, phr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_MATERIAL,         mtr::load, mtr::unload, mtr::online, mtr::offline);
+		_resource_manager->register_resource_type(RESOURCE_TYPE_PHYSICS_CONFIG,   pcr::load, pcr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_FONT,             ftr::load, ftr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_LEVEL,            lvr::load, lvr::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_SHADER,           shr::load, shr::unload, shr::online, shr::offline);
+		_resource_manager->register_resource_type(RESOURCE_TYPE_SPRITE_ANIMATION, sar::load, sar::unload, NULL,        NULL        );
+		_resource_manager->register_resource_type(RESOURCE_TYPE_CONFIG,           cor::load, cor::unload, NULL,        NULL        );
+
 		read_config();
 
 		_bgfx_allocator = CE_NEW(_allocator, BgfxAllocator)(default_allocator());

+ 1 - 45
src/resource/resource_manager.cpp

@@ -4,24 +4,11 @@
  */
 
 #include "array.h"
-#include "config_resource.h"
 #include "dynamic_string.h"
-#include "font_resource.h"
-#include "level_resource.h"
-#include "lua_resource.h"
-#include "material_resource.h"
-#include "mesh_resource.h"
-#include "package_resource.h"
-#include "physics_resource.h"
 #include "resource_loader.h"
 #include "resource_manager.h"
-#include "shader_resource.h"
 #include "sort_map.h"
-#include "sound_resource.h"
-#include "sprite_resource.h"
 #include "temp_allocator.h"
-#include "texture_resource.h"
-#include "unit_resource.h"
 
 namespace crown
 {
@@ -34,37 +21,6 @@ ResourceManager::ResourceManager(ResourceLoader& rl)
 	, _rm(default_allocator())
 	, _autoload(false)
 {
-	namespace pcr = physics_config_resource;
-	namespace phr = physics_resource;
-	namespace pkr = package_resource;
-	namespace sdr = sound_resource;
-	namespace mhr = mesh_resource;
-	namespace utr = unit_resource;
-	namespace txr = texture_resource;
-	namespace mtr = material_resource;
-	namespace lur = lua_resource;
-	namespace ftr = font_resource;
-	namespace lvr = level_resource;
-	namespace spr = sprite_resource;
-	namespace shr = shader_resource;
-	namespace sar = sprite_animation_resource;
-	namespace cor = config_resource;
-
-	register_resource_type(RESOURCE_TYPE_SCRIPT,           lur::load, NULL,        NULL,         lur::unload);
-	register_resource_type(RESOURCE_TYPE_TEXTURE,          txr::load, txr::online, txr::offline, txr::unload);
-	register_resource_type(RESOURCE_TYPE_MESH,             mhr::load, mhr::online, mhr::offline, mhr::unload);
-	register_resource_type(RESOURCE_TYPE_SOUND,            sdr::load, NULL,        NULL,         sdr::unload);
-	register_resource_type(RESOURCE_TYPE_UNIT,             utr::load, NULL,        NULL,         utr::unload);
-	register_resource_type(RESOURCE_TYPE_SPRITE,           spr::load, spr::online, spr::offline, spr::unload);
-	register_resource_type(RESOURCE_TYPE_PACKAGE,          pkr::load, NULL,        NULL,         pkr::unload);
-	register_resource_type(RESOURCE_TYPE_PHYSICS,          phr::load, NULL,        NULL,         phr::unload);
-	register_resource_type(RESOURCE_TYPE_MATERIAL,         mtr::load, mtr::online, mtr::offline, mtr::unload);
-	register_resource_type(RESOURCE_TYPE_PHYSICS_CONFIG,   pcr::load, NULL,        NULL,         pcr::unload);
-	register_resource_type(RESOURCE_TYPE_FONT,             ftr::load, NULL,        NULL,         ftr::unload);
-	register_resource_type(RESOURCE_TYPE_LEVEL,            lvr::load, NULL,        NULL,         lvr::unload);
-	register_resource_type(RESOURCE_TYPE_SHADER,           shr::load, shr::online, shr::offline, shr::unload);
-	register_resource_type(RESOURCE_TYPE_SPRITE_ANIMATION, sar::load, NULL,        NULL,         sar::unload);
-	register_resource_type(RESOURCE_TYPE_CONFIG,           cor::load, NULL,        NULL,         cor::unload);
 }
 
 ResourceManager::~ResourceManager()
@@ -215,7 +171,7 @@ void ResourceManager::complete_request(StringId64 type, StringId64 name, void* d
 	on_online(type, name);
 }
 
-void ResourceManager::register_resource_type(StringId64 type, LoadFunction load, OnlineFunction online, OfflineFunction offline, UnloadFunction unload)
+void ResourceManager::register_resource_type(StringId64 type, LoadFunction load, UnloadFunction unload, OnlineFunction online, OfflineFunction offline)
 {
 	CE_ASSERT_NOT_NULL(load);
 	CE_ASSERT_NOT_NULL(unload);

+ 3 - 1
src/resource/resource_manager.h

@@ -66,7 +66,6 @@ class ResourceManager
 	ResourceMap _rm;
 	bool _autoload;
 
-	void register_resource_type(StringId64 type, LoadFunction load, OnlineFunction online, OfflineFunction offline, UnloadFunction unload);
 	void on_online(StringId64 type, StringId64 name);
 	void on_offline(StringId64 type, StringId64 name);
 	void on_unload(StringId64 type, void* data);
@@ -103,6 +102,9 @@ public:
 
 	/// Completes all load() requests which have been loaded by ResourceLoader.
 	void complete_requests();
+
+	/// Registers a new resource @a type into the resource manager.
+	void register_resource_type(StringId64 type, LoadFunction load, UnloadFunction unload, OnlineFunction online, OfflineFunction offline);
 };
 
 } // namespace crown