Daniele Bartolini 8 yıl önce
ebeveyn
işleme
bc25b19600

+ 31 - 31
src/device/device.cpp

@@ -319,22 +319,6 @@ void Device::run()
 
 	_console_server->listen(_device_options._console_port, _device_options._wait_console);
 
-	namespace cor = config_resource_internal;
-	namespace ftr = font_resource_internal;
-	namespace lur = lua_resource_internal;
-	namespace lvr = level_resource_internal;
-	namespace mhr = mesh_resource_internal;
-	namespace mtr = material_resource_internal;
-	namespace pcr = physics_config_resource_internal;
-	namespace phr = physics_resource_internal;
-	namespace pkr = package_resource_internal;
-	namespace sar = sprite_animation_resource_internal;
-	namespace sdr = sound_resource_internal;
-	namespace shr = shader_resource_internal;
-	namespace spr = sprite_resource_internal;
-	namespace txr = texture_resource_internal;
-	namespace utr = unit_resource_internal;
-
 #if CROWN_PLATFORM_ANDROID
 	_data_filesystem = CE_NEW(_allocator, FilesystemApk)(default_allocator(), const_cast<AAssetManager*>((AAssetManager*)_device_options._asset_manager));
 #else
@@ -356,23 +340,39 @@ void Device::run()
 
 	profiler_globals::init();
 
+	namespace cor = config_resource_internal;
+	namespace ftr = font_resource_internal;
+	namespace lur = lua_resource_internal;
+	namespace lvr = level_resource_internal;
+	namespace mhr = mesh_resource_internal;
+	namespace mtr = material_resource_internal;
+	namespace pcr = physics_config_resource_internal;
+	namespace phr = physics_resource_internal;
+	namespace pkr = package_resource_internal;
+	namespace sar = sprite_animation_resource_internal;
+	namespace sdr = sound_resource_internal;
+	namespace shr = shader_resource_internal;
+	namespace spr = sprite_resource_internal;
+	namespace txr = texture_resource_internal;
+	namespace utr = unit_resource_internal;
+
 	_resource_loader  = CE_NEW(_allocator, ResourceLoader)(*_data_filesystem);
 	_resource_manager = CE_NEW(_allocator, ResourceManager)(*_resource_loader);
-	_resource_manager->register_type(RESOURCE_TYPE_CONFIG,           cor::load, cor::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_FONT,             ftr::load, ftr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_LEVEL,            lvr::load, lvr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_MATERIAL,         mtr::load, mtr::unload, mtr::online, mtr::offline);
-	_resource_manager->register_type(RESOURCE_TYPE_MESH,             mhr::load, mhr::unload, mhr::online, mhr::offline);
-	_resource_manager->register_type(RESOURCE_TYPE_PACKAGE,          pkr::load, pkr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_PHYSICS,          phr::load, phr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_PHYSICS_CONFIG,   pcr::load, pcr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_SCRIPT,           lur::load, lur::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_SHADER,           shr::load, shr::unload, shr::online, shr::offline);
-	_resource_manager->register_type(RESOURCE_TYPE_SOUND,            sdr::load, sdr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_SPRITE,           spr::load, spr::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_SPRITE_ANIMATION, sar::load, sar::unload, NULL,        NULL        );
-	_resource_manager->register_type(RESOURCE_TYPE_TEXTURE,          txr::load, txr::unload, txr::online, txr::offline);
-	_resource_manager->register_type(RESOURCE_TYPE_UNIT,             utr::load, utr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_CONFIG,           RESOURCE_VERSION_CONFIG,           cor::load, cor::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_FONT,             RESOURCE_VERSION_FONT,             ftr::load, ftr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_LEVEL,            RESOURCE_VERSION_LEVEL,            lvr::load, lvr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_MATERIAL,         RESOURCE_VERSION_MATERIAL,         mtr::load, mtr::unload, mtr::online, mtr::offline);
+	_resource_manager->register_type(RESOURCE_TYPE_MESH,             RESOURCE_VERSION_MESH,             mhr::load, mhr::unload, mhr::online, mhr::offline);
+	_resource_manager->register_type(RESOURCE_TYPE_PACKAGE,          RESOURCE_VERSION_PACKAGE,          pkr::load, pkr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_PHYSICS,          RESOURCE_VERSION_PHYSICS,          phr::load, phr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_PHYSICS_CONFIG,   RESOURCE_VERSION_PHYSICS_CONFIG,   pcr::load, pcr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_SCRIPT,           RESOURCE_VERSION_SCRIPT,           lur::load, lur::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_SHADER,           RESOURCE_VERSION_SHADER,           shr::load, shr::unload, shr::online, shr::offline);
+	_resource_manager->register_type(RESOURCE_TYPE_SOUND,            RESOURCE_VERSION_SOUND,            sdr::load, sdr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_SPRITE,           RESOURCE_VERSION_SPRITE,           spr::load, spr::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_SPRITE_ANIMATION, RESOURCE_VERSION_SPRITE_ANIMATION, sar::load, sar::unload, NULL,        NULL        );
+	_resource_manager->register_type(RESOURCE_TYPE_TEXTURE,          RESOURCE_VERSION_TEXTURE,          txr::load, txr::unload, txr::online, txr::offline);
+	_resource_manager->register_type(RESOURCE_TYPE_UNIT,             RESOURCE_VERSION_UNIT,             utr::load, utr::unload, NULL,        NULL        );
 
 	// Read config
 	{

+ 5 - 5
src/resource/resource_loader.cpp

@@ -15,8 +15,8 @@
 
 namespace crown
 {
-ResourceLoader::ResourceLoader(Filesystem& fs)
-	: _fs(fs)
+ResourceLoader::ResourceLoader(Filesystem& data_filesystem)
+	: _data_filesystem(data_filesystem)
 	, _requests(default_allocator())
 	, _loaded(default_allocator())
 	, _exit(false)
@@ -46,7 +46,7 @@ bool ResourceLoader::can_load(StringId64 type, StringId64 name)
 	DynamicString path(ta);
 	path::join(path, CROWN_DATA_DIRECTORY, res_path.c_str());
 
-	return _fs.exists(path.c_str());
+	return _data_filesystem.exists(path.c_str());
 }
 
 void ResourceLoader::add_request(const ResourceRequest& rr)
@@ -115,9 +115,9 @@ s32 ResourceLoader::run()
 		DynamicString path(ta);
 		path::join(path, CROWN_DATA_DIRECTORY, res_path.c_str());
 
-		File* file = _fs.open(path.c_str(), FileOpenMode::READ);
+		File* file = _data_filesystem.open(path.c_str(), FileOpenMode::READ);
 		rr.data = rr.load_function(*file, *rr.allocator);
-		_fs.close(*file);
+		_data_filesystem.close(*file);
 
 		add_loaded(rr);
 		_mutex.lock();

+ 4 - 3
src/resource/resource_loader.h

@@ -20,6 +20,7 @@ struct ResourceRequest
 
 	StringId64 type;
 	StringId64 name;
+	u32 version;
 	LoadFunction load_function;
 	Allocator* allocator;
 	void* data;
@@ -30,7 +31,7 @@ struct ResourceRequest
 /// @ingroup Resource
 class ResourceLoader
 {
-	Filesystem& _fs;
+	Filesystem& _data_filesystem;
 
 	Queue<ResourceRequest> _requests;
 	Queue<ResourceRequest> _loaded;
@@ -47,8 +48,8 @@ class ResourceLoader
 
 public:
 
-	/// Read resources from @a fs.
-	ResourceLoader(Filesystem& fs);
+	/// Read resources from @a data_filesystem.
+	ResourceLoader(Filesystem& data_filesystem);
 	~ResourceLoader();
 
 	/// Returns whether the resource (type, name) can be loaded.

+ 18 - 8
src/resource/resource_manager.cpp

@@ -57,10 +57,19 @@ void ResourceManager::load(StringId64 type, StringId64 name)
 		CE_UNUSED(type_str);
 		CE_UNUSED(name_str);
 
+		ResourceTypeData rtd;
+		rtd.version = UINT32_MAX;
+		rtd.load = NULL;
+		rtd.online = NULL;
+		rtd.offline = NULL;
+		rtd.unload = NULL;
+		rtd = sort_map::get(_type_data, type, rtd);
+
 		ResourceRequest rr;
 		rr.type = type;
 		rr.name = name;
-		rr.load_function = sort_map::get(_type_data, type, ResourceTypeData()).load;
+		rr.version = rtd.version;
+		rr.load_function = rtd.load;
 		rr.allocator = &_resource_heap;
 		rr.data = NULL;
 
@@ -170,18 +179,19 @@ void ResourceManager::complete_request(StringId64 type, StringId64 name, void* d
 	on_online(type, name);
 }
 
-void ResourceManager::register_type(StringId64 type, LoadFunction load, UnloadFunction unload, OnlineFunction online, OfflineFunction offline)
+void ResourceManager::register_type(StringId64 type, u32 version, LoadFunction load, UnloadFunction unload, OnlineFunction online, OfflineFunction offline)
 {
 	CE_ENSURE(NULL != load);
 	CE_ENSURE(NULL != unload);
 
-	ResourceTypeData data;
-	data.load = load;
-	data.online = online;
-	data.offline = offline;
-	data.unload = unload;
+	ResourceTypeData rtd;
+	rtd.version = version;
+	rtd.load = load;
+	rtd.online = online;
+	rtd.offline = offline;
+	rtd.unload = unload;
 
-	sort_map::set(_type_data, type, data);
+	sort_map::set(_type_data, type, rtd);
 	sort_map::sort(_type_data);
 }
 

+ 2 - 1
src/resource/resource_manager.h

@@ -50,6 +50,7 @@ class ResourceManager
 
 	struct ResourceTypeData
 	{
+		u32 version;
 		LoadFunction load;
 		OnlineFunction online;
 		OfflineFunction offline;
@@ -103,7 +104,7 @@ public:
 	void complete_requests();
 
 	/// Registers a new resource @a type into the resource manager.
-	void register_type(StringId64 type, LoadFunction load, UnloadFunction unload, OnlineFunction online, OfflineFunction offline);
+	void register_type(StringId64 type, u32 version, LoadFunction load, UnloadFunction unload, OnlineFunction online, OfflineFunction offline);
 };
 
 } // namespace crown