Преглед на файлове

Use 64 bit murmur to hash resource type/name

Daniele Bartolini преди 11 години
родител
ревизия
d479ce6137

+ 3 - 1
engine/Device.cpp

@@ -424,8 +424,9 @@ void Device::destroy_resource_package(ResourcePackage* package)
 }
 
 //-----------------------------------------------------------------------------
-void Device::reload(const char* type, const char* name)
+void Device::reload(const char* , const char* )
 {
+/*
 	#if defined(LINUX) || defined(WINDOWS)
 		TempAllocator4096 temp;
 		DynamicString filename(temp);
@@ -478,6 +479,7 @@ void Device::reload(const char* type, const char* name)
 			}
 		}
 	#endif
+*/
 }
 
 static Device* g_device;

+ 8 - 6
engine/compilers/BundleCompiler.cpp

@@ -110,14 +110,16 @@ bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir, con
 
 		const char* filename = files[i].c_str();
 
-		uint64_t filename_hash = string::murmur2_64(filename, string::strlen(filename), 0);
+		char filename_extension[512];
+		char filename_without_extension[512];
+		path::extension(filename, filename_extension, 512);
+		path::filename_without_extension(filename, filename_without_extension, 512);
 
-		char filename_extension[32];
-		path::extension(filename, filename_extension, 32);
-		uint32_t resource_type_hash = string::murmur2_32(filename_extension, string::strlen(filename_extension), 0);
+		ResourceId name(filename_extension, filename_without_extension);
+		char out_name[512];
+		snprintf(out_name, 512, "%.16lx-%.16lx", name.type, name.name);
 
-		char out_name[65];
-		snprintf(out_name, 65, "%.16"PRIx64"", filename_hash);
+		uint64_t resource_type_hash = name.type;
 
 		// Skip crown.config file
 		if (resource_type_hash == CONFIG_TYPE)

+ 1 - 4
engine/core/json/JSONParser.cpp

@@ -237,13 +237,10 @@ StringId32 JSONElement::to_string_id() const
 //--------------------------------------------------------------------------
 ResourceId JSONElement::to_resource_id(const char* type) const
 {
+	CE_ASSERT_NOT_NULL(type);
 	TempAllocator1024 alloc;
 	DynamicString str(alloc);
 	json::parse_string(m_at, str);
-
-	if (type == NULL)
-		return ResourceId(str.c_str());
-
 	return ResourceId(type, str.c_str());
 }
 

+ 27 - 38
engine/core/strings/StringUtils.h

@@ -305,56 +305,45 @@ inline uint32_t murmur2_32(const void* key, size_t len, uint32_t seed = 0)
 	return h;
 }
 
-//-----------------------------------------------------------------------------
-inline uint64_t murmur2_64(const void* key, size_t len, unsigned int seed = 0)
+inline uint64_t murmur2_64(const void* key, int len, uint64_t seed = 0)
 {
-	CE_ASSERT_NOT_NULL(key);
-
-	const unsigned int m = 0x5bd1e995;
-	const int r = 24;
+	const uint64_t m = 0xc6a4a7935bd1e995ull;
+	const int r = 47;
 
-	unsigned int h1 = seed ^ len;
-	unsigned int h2 = 0;
+	uint64_t h = seed ^ (len * m);
 
-	const unsigned int * data = (const unsigned int *)key;
+	const uint64_t * data = (const uint64_t *)key;
+	const uint64_t * end = data + (len/8);
 
-	while(len >= 8)
+	while(data != end)
 	{
-		unsigned int k1 = *data++;
-		k1 *= m; k1 ^= k1 >> r; k1 *= m;
-		h1 *= m; h1 ^= k1;
-		len -= 4;
+		uint64_t k = *data++;
 
-		unsigned int k2 = *data++;
-		k2 *= m; k2 ^= k2 >> r; k2 *= m;
-		h2 *= m; h2 ^= k2;
-		len -= 4;
-	}
+		k *= m; 
+		k ^= k >> r; 
+		k *= m; 
 
-	if(len >= 4)
-	{
-		unsigned int k1 = *data++;
-		k1 *= m; k1 ^= k1 >> r; k1 *= m;
-		h1 *= m; h1 ^= k1;
-		len -= 4;
+		h ^= k;
+		h *= m; 
 	}
 
-	switch(len)
+	const unsigned char * data2 = (const unsigned char*)data;
+
+	switch(len & 7)
 	{
-	case 3: h2 ^= ((unsigned char*)data)[2] << 16;
-	case 2: h2 ^= ((unsigned char*)data)[1] << 8;
-	case 1: h2 ^= ((unsigned char*)data)[0];
-			h2 *= m;
+		case 7: h ^= uint64_t(data2[6]) << 48;
+		case 6: h ^= uint64_t(data2[5]) << 40;
+		case 5: h ^= uint64_t(data2[4]) << 32;
+		case 4: h ^= uint64_t(data2[3]) << 24;
+		case 3: h ^= uint64_t(data2[2]) << 16;
+		case 2: h ^= uint64_t(data2[1]) << 8;
+		case 1: h ^= uint64_t(data2[0]);
+		h *= m;
 	};
 
-	h1 ^= h2 >> 18; h1 *= m;
-	h2 ^= h1 >> 22; h2 *= m;
-	h1 ^= h2 >> 17; h1 *= m;
-	h2 ^= h1 >> 19; h2 *= m;
-
-	uint64_t h = h1;
-
-	h = (h << 32) | h2;
+	h ^= h >> r;
+	h *= m;
+	h ^= h >> r;
 
 	return h;
 }

+ 2 - 1
engine/lua/LuaEnvironment.cpp

@@ -52,7 +52,8 @@ void LuaEnvironment::load_and_execute(const char* res_name)
 	ResourceManager* resman = device()->resource_manager();
 
 	// Load the resource
-	ResourceId res_id = resman->load("lua", res_name);
+	const ResourceId res_id("lua", res_name);
+	resman->load(res_id);
 	resman->flush();
 	LuaResource* lr = (LuaResource*) resman->get(res_id);
 	

+ 2 - 1
engine/lua/LuaSystem.cpp

@@ -125,7 +125,8 @@ namespace lua_system
 
 		const char* filename = stack.get_string(1);
 
-		const ResourceId lua_res = device()->resource_manager()->load("lua", filename);
+		const ResourceId lua_res("lua", filename);
+		device()->resource_manager()->load(lua_res);
 		device()->resource_manager()->flush();
 
 		const LuaResource* lr = (LuaResource*) device()->resource_manager()->get(lua_res);

+ 1 - 1
engine/resource/FileBundle.cpp

@@ -51,7 +51,7 @@ public:
 	{
 		// Convert name/type into strings
 		char resource_name[512];
-		snprintf(resource_name, 512, "%.16"PRIx64"", name.id);
+		snprintf(resource_name, 512, "%.16lx-%.16lx", name.type, name.name);
 
 		// Open the resource and check magic number/version
 		File* file = m_filesystem.open(resource_name, FOM_READ);

+ 1 - 5
engine/resource/FontResource.cpp

@@ -79,10 +79,6 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	JSONElement font_size = root.key("font_size");
 	JSONElement glyphs = root.key("glyphs");
 
-	DynamicString material_name;
-	mat.to_string(material_name);
-	material_name += ".material";
-
 	uint32_t num_glyphs = count.to_int();
 	
 	for (uint32_t i = 0; i < num_glyphs; i++)
@@ -92,7 +88,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 		array::push_back(m_glyphs, data);
 	}
 
-	h.material = ResourceId(material_name.c_str());
+	h.material = mat.to_resource_id("material");
 	h.num_glyphs = array::size(m_glyphs);
 	h.texture_size = size.to_int();
 	h.font_size = font_size.to_int();

+ 2 - 12
engine/resource/LevelResource.cpp

@@ -46,12 +46,7 @@ void parse_units(JSONElement root, Array<LevelUnit>& units)
 		JSONElement e = units_arr[i];
 
 		LevelUnit lu;
-
-		DynamicString name;
-		e.key("name").to_string(name);
-		name += ".unit";
-
-		lu.name = ResourceId(name.c_str());
+		lu.name = e.key("name").to_resource_id("unit");
 		lu.position = e.key("position").to_vector3();
 		lu.rotation = e.key("rotation").to_quaternion();
 
@@ -70,12 +65,7 @@ void parse_sounds(JSONElement root, Array<LevelSound>& sounds)
 		JSONElement e = sounds_arr[i];
 
 		LevelSound ls;
-
-		DynamicString name;
-		e.key("name").to_string(name);
-		name += ".sound";
-
-		ls.name = ResourceId(name.c_str());
+		ls.name = e.key("name").to_resource_id("sound");
 		ls.position = e.key("position").to_vector3();
 		ls.volume = e.key("volume").to_float();
 		ls.range = e.key("range").to_float();

+ 1 - 4
engine/resource/MaterialResource.cpp

@@ -51,10 +51,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	JSONElement tl = root.key("texture_layers");
 	for (uint32_t i = 0; i < tl.size(); i++)
 	{
-		DynamicString tex;
-		tl[i].to_string(tex); tex += ".texture";
-
-		array::push_back(texture_layers, ResourceId(tex.c_str()));
+		array::push_back(texture_layers, tl[i].to_resource_id("texture"));
 	}
 
 	// Write resource

+ 1 - 6
engine/resource/PhysicsResource.cpp

@@ -154,12 +154,7 @@ void parse_shapes(JSONElement e, Array<PhysicsShape>& shapes)
 			}
 			case PhysicsShapeType::CONVEX_MESH:
 			{
-				JSONElement resource = shape.key("mesh");
-				DynamicString mesh_name;
-				resource.to_string(mesh_name);
-				mesh_name += ".mesh";
-
-				ps.resource = ResourceId(mesh_name.c_str());
+				ps.resource = shape.key("mesh").to_resource_id("mesh");
 
 				break;
 			}

+ 26 - 28
engine/resource/Resource.h

@@ -34,45 +34,43 @@ namespace crown
 {
 
 /// Hashed values for supported resource types
-#define TEXTURE_EXTENSION			"texture"
-#define MESH_EXTENSION				"mesh"
+#define CONFIG_EXTENSION			"config"
+#define FONT_EXTENSION				"font"
+#define LEVEL_EXTENSION				"level"
 #define LUA_EXTENSION				"lua"
-#define TEXT_EXTENSION				"text"
 #define MATERIAL_EXTENSION			"material"
+#define MESH_EXTENSION				"mesh"
+#define PACKAGE_EXTENSION			"package"
+#define PHYSICS_CONFIG_EXTENSION	"physics_config"
+#define PHYSICS_EXTENSION			"physics"
 #define SOUND_EXTENSION				"sound"
 #define SPRITE_EXTENSION			"sprite"
-#define CONFIG_EXTENSION			"config"
-#define PACKAGE_EXTENSION			"package"
+#define TEXTURE_EXTENSION			"texture"
 #define UNIT_EXTENSION				"unit"
-#define PHYSICS_EXTENSION			"physics"
-#define PHYSICS_CONFIG_EXTENSION	"physics_config"
-#define FONT_EXTENSION				"font"
-#define LEVEL_EXTENSION				"level"
 
-#define TEXTURE_TYPE				0x0DEED4F7
-#define MESH_TYPE					0x742FBC9A
-#define LUA_TYPE					0xD96E7C37
-#define TEXT_TYPE					0x045CC650
-#define MATERIAL_TYPE				0x46807A92
-#define SOUND_TYPE					0xD196AB6E
-#define SPRITE_TYPE					0x5DD272E5
-#define CONFIG_TYPE					0x17DEA5E1
-#define PACKAGE_TYPE				0xC0A2212C
-#define UNIT_TYPE					0x516224CF
-#define PHYSICS_TYPE				0xFA32C012
-#define PHYSICS_CONFIG_TYPE			0x514F14A1
-#define FONT_TYPE					0x536DC7D4
-#define LEVEL_TYPE					0x349657F7
+#define CONFIG_TYPE					uint64_t(0x82645835e6b73232)
+#define FONT_TYPE					uint64_t(0x9efe0a916aae7880)
+#define LEVEL_TYPE					uint64_t(0x2a690fd348fe9ac5)
+#define LUA_TYPE					uint64_t(0xa14e8dfa2cd117e2)
+#define MATERIAL_TYPE				uint64_t(0xeac0b497876adedf)
+#define MESH_TYPE					uint64_t(0x48ff313713a997a1)
+#define PACKAGE_TYPE				uint64_t(0xad9c6d9ed1e5e77a)
+#define PHYSICS_CONFIG_TYPE			uint64_t(0x72e3cc03787a11a1)
+#define PHYSICS_TYPE				uint64_t(0x5f7203c8f280dab8)
+#define SOUND_TYPE					uint64_t(0x90641b51c98b7aac)
+#define SPRITE_TYPE					uint64_t(0x8d5871f9ebdb651c)
+#define TEXTURE_TYPE				uint64_t(0xcd4238c6a0c69e32)
+#define UNIT_TYPE					uint64_t(0xe0a48d0be9a7453f)
 
 struct ResourceId
 {
-	ResourceId() : id(0) {}
+	ResourceId() : type(0), name(0) {}
 	ResourceId(const char* type, const char* name);
-	ResourceId(const char* name);
 
-	bool operator==(const ResourceId& a) const { return id == a.id; }
+	bool operator==(const ResourceId& a) const { return type == a.type && name == a.name; }
 
-	uint64_t id;
+	uint64_t type;
+	uint64_t name;
 };
 
 class Allocator;
@@ -85,7 +83,7 @@ typedef void	(*ResourceOfflineCallback)(void* resource);
 
 struct ResourceCallback
 {
-	uint32_t					type;
+	uint64_t					type;
 	ResourceLoadCallback		on_load;
 	ResourceUnloadCallback		on_unload;
 	ResourceOnlineCallback		on_online;

+ 3 - 5
engine/resource/ResourceLoader.cpp

@@ -49,16 +49,14 @@ ResourceLoader::ResourceLoader(Bundle& bundle, Allocator& resource_heap) :
 }
 
 //-----------------------------------------------------------------------------
-LoadResourceId ResourceLoader::load_resource(uint32_t type, ResourceId resource)
+LoadResourceId ResourceLoader::load_resource(ResourceId id)
 {
-
 	m_requests_mutex.lock();
 
 	LoadResourceId lr_id = m_num_requests++;
 	LoadResource lr;
 	lr.id = lr_id;
-	lr.type = type;
-	lr.resource = resource;
+	lr.resource = id;
 
 	queue::push_back(m_requests, lr);
 
@@ -113,7 +111,7 @@ int32_t ResourceLoader::run()
 
 			m_results[request.id % MAX_LOAD_REQUESTS].status = LRS_LOADING;
 
-			void* data = resource_on_load(request.type, m_resource_heap, m_bundle, request.resource);
+			void* data = resource_on_load(request.resource.type, m_resource_heap, m_bundle, request.resource);
 
 			m_results[request.id % MAX_LOAD_REQUESTS].data = data;
 			m_results[request.id % MAX_LOAD_REQUESTS].status = LRS_LOADED;

+ 15 - 16
engine/resource/ResourceLoader.h

@@ -54,7 +54,6 @@ enum LoadResourceStatus
 struct LoadResource
 {
 	LoadResourceId id;
-	uint32_t type;
 	ResourceId resource;
 };
 
@@ -71,19 +70,19 @@ public:
 
 	/// Reads the resources data from the given @a bundle using
 	/// @a resource_heap to allocate memory for them.
-							ResourceLoader(Bundle& bundle, Allocator& resource_heap);
+	ResourceLoader(Bundle& bundle, Allocator& resource_heap);
 
 	/// Loads the @a resource in a background thread.
-	LoadResourceId			load_resource(uint32_t type, ResourceId resource);
+	LoadResourceId load_resource(ResourceId id);
 
 	/// Returns the status of the given load request @a id.
-	LoadResourceStatus		load_resource_status(LoadResourceId id) const;
+	LoadResourceStatus load_resource_status(LoadResourceId id) const;
 
 	/// Returns the data which has been loaded for the given request @a id.
-	void*					load_resource_data(LoadResourceId id) const;
+	void* load_resource_data(LoadResourceId id) const;
 
 	// Loads resources in the loading queue.
-	int32_t					run();
+	int32_t run();
 
 	void start()
 	{
@@ -107,22 +106,22 @@ private:
 
 private:
 
-	OsThread				m_thread;
-	bool					m_should_run;
+	OsThread m_thread;
+	bool m_should_run;
 
 	// Whether to look for resources
-	Bundle&					m_bundle;
+	Bundle& m_bundle;
 
 	// Used to strore resource memory
-	Allocator&				m_resource_heap;
+	Allocator& m_resource_heap;
 
-	uint32_t				m_num_requests;
-	Queue<LoadResource>		m_requests;
-	LoadResourceData		m_results[MAX_LOAD_REQUESTS];
+	uint32_t m_num_requests;
+	Queue<LoadResource> m_requests;
+	LoadResourceData m_results[MAX_LOAD_REQUESTS];
 
-	Mutex					m_requests_mutex;
-	Mutex					m_results_mutex;
-	Cond					m_full;
+	Mutex m_requests_mutex;
+	Mutex m_results_mutex;
+	Cond m_full;
 };
 
 } // namespace crown

+ 48 - 67
engine/resource/ResourceManager.cpp

@@ -39,19 +39,9 @@ namespace crown
 {
 
 ResourceId::ResourceId(const char* type, const char* name)
+	: type(string::murmur2_64(type, string::strlen(type), 0))
+	, name(string::murmur2_64(name, string::strlen(name), 0))
 {
-	TempAllocator256 alloc;
-	DynamicString res_name(alloc);
-	res_name += name;
-	res_name += '.';
-	res_name += type;
-
-	id = string::murmur2_64(res_name.c_str(), res_name.length(), 0);
-}
-
-ResourceId::ResourceId(const char* name)
-{
-	id = string::murmur2_64(name, string::strlen(name), 0);
 }
 
 //-----------------------------------------------------------------------------
@@ -71,24 +61,49 @@ ResourceManager::~ResourceManager()
 }
 
 //-----------------------------------------------------------------------------
-ResourceId ResourceManager::load(const char* type, const char* name)
+void ResourceManager::load(ResourceId id)
 {
-	return load(string::murmur2_32(type, string::strlen(type), 0), ResourceId(type, name));
+	// Search for an already existent resource
+	ResourceEntry* entry = find(id);
+
+	// If resource not found, create a new one
+	if (entry == NULL)
+	{
+		ResourceEntry entry;
+
+		entry.id = id;
+		entry.references = 1;
+		entry.resource = NULL;
+
+		array::push_back(m_resources, entry);
+
+		// Issue request to resource loader
+		PendingRequest pr;
+		pr.resource = id;
+		pr.id = m_loader.load_resource(id);
+
+		queue::push_back(m_pendings, pr);
+
+		return;
+	}
+
+	// Else, increment its reference count
+	entry->references++;
 }
 
 //-----------------------------------------------------------------------------
-void ResourceManager::unload(ResourceId name, bool force)
+void ResourceManager::unload(ResourceId id, bool force)
 {
-	CE_ASSERT(has(name), "Resource not loaded: " "%.16"PRIx64"", name.id);
+	CE_ASSERT(has(id), "Resource not loaded: %.16lx-%16lx", id.type, id.name);
 
-	ResourceEntry* entry = find(name);
+	ResourceEntry* entry = find(id);
 
 	entry->references--;
 
 	if (entry->references == 0 || force)
 	{
-		resource_on_offline(entry->type, entry->resource);
-		resource_on_unload(entry->type, m_resource_heap, entry->resource);
+		resource_on_offline(id.type, entry->resource);
+		resource_on_unload(id.type, m_resource_heap, entry->resource);
 
 		// Swap with last
 		ResourceEntry temp = m_resources[array::size(m_resources) - 1];
@@ -98,9 +113,9 @@ void ResourceManager::unload(ResourceId name, bool force)
 }
 
 //-----------------------------------------------------------------------------
-bool ResourceManager::has(ResourceId name) const
+bool ResourceManager::has(ResourceId id) const
 {
-	ResourceEntry* entry = find(name);
+	ResourceEntry* entry = find(id);
 
 	return entry != NULL;
 }
@@ -117,27 +132,27 @@ const void* ResourceManager::get(const char* type, const char* name) const
 }
 
 //-----------------------------------------------------------------------------
-const void* ResourceManager::get(ResourceId name) const
+const void* ResourceManager::get(ResourceId id) const
 {
-	CE_ASSERT(has(name), "Resource not loaded: " "%.16"PRIx64"", name.id);
+	CE_ASSERT(has(id), "Resource not loaded: %.16lx-%16lx", id.type, id.name);
 
-	return find(name)->resource;
+	return find(id)->resource;
 }
 
 //-----------------------------------------------------------------------------
-bool ResourceManager::is_loaded(ResourceId name) const
+bool ResourceManager::is_loaded(ResourceId id) const
 {
-	CE_ASSERT(has(name), "Resource not loaded: " "%.16"PRIx64"", name.id);
+	CE_ASSERT(has(id), "Resource not loaded: %.16lx-%16lx", id.type, id.name);
 
-	return find(name)->resource != NULL;
+	return find(id)->resource != NULL;
 }
 
 //-----------------------------------------------------------------------------
-uint32_t ResourceManager::references(ResourceId name) const
+uint32_t ResourceManager::references(ResourceId id) const
 {
-	CE_ASSERT(has(name), "Resource not loaded: " "%.16"PRIx64"", name.id);
+	CE_ASSERT(has(id), "Resource not loaded: %.16lx-%16lx", id.type, id.name);
 
-	return find(name)->references;
+	return find(id)->references;
 }
 
 //-----------------------------------------------------------------------------
@@ -175,44 +190,10 @@ void ResourceManager::poll_resource_loader()
 }
 
 //-----------------------------------------------------------------------------
-ResourceId ResourceManager::load(uint32_t type, ResourceId name)
-{
-	// Search for an already existent resource
-	ResourceEntry* entry = find(name);
-
-	// If resource not found, create a new one
-	if (entry == NULL)
-	{
-		ResourceEntry entry;
-
-		entry.id = name;
-		entry.type = type;
-		entry.references = 1;
-		entry.resource = NULL;
-
-		array::push_back(m_resources, entry);
-
-		// Issue request to resource loader
-		PendingRequest pr;
-		pr.resource = name;
-		pr.id = m_loader.load_resource(type, name);
-
-		queue::push_back(m_pendings, pr);
-
-		return name;
-	}
-
-	// Else, increment its reference count
-	entry->references++;
-
-	return entry->id;
-}
-
-//-----------------------------------------------------------------------------
-void ResourceManager::online(ResourceId name, void* resource)
+void ResourceManager::online(ResourceId id, void* resource)
 {
-	ResourceEntry* entry = find(name);
-	resource_on_online(entry->type, resource);
+	ResourceEntry* entry = find(id);
+	resource_on_online(id.type, resource);
 
 	entry->resource = resource;
 }

+ 11 - 16
engine/resource/ResourceManager.h

@@ -37,20 +37,18 @@ namespace crown
 
 struct ResourceEntry
 {
-	bool operator==(const ResourceId& resource) const { return id == resource; }
+	bool operator==(const ResourceId& res) const { return id == res; }
 	bool operator==(const ResourceEntry& b) const { return id == b.id; }
 
-	ResourceId		id;
-	uint32_t		type;
-	uint32_t		references;
-	void*			resource;
+	ResourceId id;
+	uint32_t references;
+	void* resource;
 };
 
 struct PendingRequest
 {
 	LoadResourceId id;
 	ResourceId resource;
-	uint32_t type;
 };
 
 class Bundle;
@@ -67,7 +65,7 @@ public:
 	/// Loads the resource by @a type and @a name and returns its ResourceId.
 	/// @note
 	/// You have to call is_loaded() to check if the loading process is actually completed.
-	ResourceId load(const char* type, const char* name);
+	void load(ResourceId id);
 
 	/// Unloads the resource @a name, freeing up all the memory associated by it
 	/// and eventually any global object associated with it.
@@ -75,28 +73,28 @@ public:
 	/// is greater than 1.
 	/// @warning
 	/// Use @a force option only if you know - exactly - what you are doing.
-	void unload(ResourceId name, bool force = false);
+	void unload(ResourceId id, bool force = false);
 
 	/// Returns whether the manager has the @a name resource into
 	/// its list of resources.
 	/// @warning
 	/// Having a resource does not mean that the resource is
 	/// ready to be used; See is_loaded().
-	bool has(ResourceId name) const;
+	bool has(ResourceId id) const;
 
 	/// Returns the resource instance associated to the given @a type and @a name.
 	const void* get(const char* type, const char* name) const;
 
 	/// Returns the data associated with the @a name resource.
 	/// You will have to cast the returned pointer accordingly.
-	const void* get(ResourceId name) const;
+	const void* get(ResourceId id) const;
 
 	/// Returns whether the @a name resource is loaded (i.e. whether
 	/// you can use the data associated with it).
-	bool is_loaded(ResourceId name) const;
+	bool is_loaded(ResourceId id) const;
 
 	/// Returns the number of references to the resource @a name;
-	uint32_t references(ResourceId name) const;
+	uint32_t references(ResourceId id) const;
 
 	/// Forces all of the loading requests to complete before preceeding.
 	void flush();
@@ -110,15 +108,12 @@ private:
 	// Polls the resource loader for loaded resources.
 	void poll_resource_loader();
 
-	// Loads the resource by name and type and returns its ResourceId.
-	ResourceId load(uint32_t type, ResourceId name);
-	void online(ResourceId name, void* resource);
+	void online(ResourceId id, void* resource);
 
 private:
 
 	ProxyAllocator m_resource_heap;
 	ResourceLoader m_loader;
-	uint32_t m_seed;
 
 	Queue<PendingRequest> m_pendings;
 	Array<ResourceEntry> m_resources;

+ 12 - 12
engine/resource/ResourcePackage.h

@@ -47,7 +47,7 @@ public:
 		, m_package(NULL)
 		, m_has_loaded(false)
 	{
-		resman.load("package", name);
+		resman.load(m_id);
 		resman.flush();
 		m_package = (const PackageResource*) resman.get(m_id);
 	}
@@ -65,57 +65,57 @@ public:
 	{
 		for (uint32_t i = 0; i < m_package->num_textures(); i++)
 		{
-			m_resource_manager->load(TEXTURE_TYPE, m_package->get_texture_id(i));
+			m_resource_manager->load(m_package->get_texture_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_scripts(); i++)
 		{
-			m_resource_manager->load(LUA_TYPE, m_package->get_script_id(i));
+			m_resource_manager->load(m_package->get_script_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_sounds(); i++)
 		{
-			m_resource_manager->load(SOUND_TYPE, m_package->get_sound_id(i));
+			m_resource_manager->load(m_package->get_sound_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_meshes(); i++)
 		{
-			m_resource_manager->load(MESH_TYPE, m_package->get_mesh_id(i));
+			m_resource_manager->load(m_package->get_mesh_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_units(); i++)
 		{
-			m_resource_manager->load(UNIT_TYPE, m_package->get_unit_id(i));
+			m_resource_manager->load(m_package->get_unit_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_sprites(); i++)
 		{
-			m_resource_manager->load(SPRITE_TYPE, m_package->get_sprite_id(i));
+			m_resource_manager->load(m_package->get_sprite_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_physics(); i++)
 		{
-			m_resource_manager->load(PHYSICS_TYPE, m_package->get_physics_id(i));
+			m_resource_manager->load(m_package->get_physics_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_materials(); i++)
 		{
-			m_resource_manager->load(MATERIAL_TYPE, m_package->get_material_id(i));
+			m_resource_manager->load(m_package->get_material_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_fonts(); i++)
 		{
-			m_resource_manager->load(FONT_TYPE, m_package->get_font_id(i));
+			m_resource_manager->load(m_package->get_font_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_levels(); i++)
 		{
-			m_resource_manager->load(LEVEL_TYPE, m_package->get_level_id(i));
+			m_resource_manager->load(m_package->get_level_id(i));
 		}
 
 		for (uint32_t i = 0; i < m_package->num_physics_configs(); i++)
 		{
-			m_resource_manager->load(PHYSICS_CONFIG_TYPE, m_package->get_physics_config_id(i));
+			m_resource_manager->load(m_package->get_physics_config_id(i));
 		}
 	}
 

+ 5 - 5
engine/resource/ResourceRegistry.cpp

@@ -58,7 +58,7 @@ static const ResourceCallback RESOURCE_CALLBACK_REGISTRY[] =
 };
 
 //-----------------------------------------------------------------------------
-static const ResourceCallback* find_callback(uint32_t type)
+static const ResourceCallback* find_callback(uint64_t type)
 {
 	const ResourceCallback* c = RESOURCE_CALLBACK_REGISTRY;
 
@@ -76,7 +76,7 @@ static const ResourceCallback* find_callback(uint32_t type)
 }
 
 //-----------------------------------------------------------------------------
-void* resource_on_load(uint32_t type, Allocator& allocator, Bundle& bundle, ResourceId id)
+void* resource_on_load(uint64_t type, Allocator& allocator, Bundle& bundle, ResourceId id)
 {
 	const ResourceCallback* c = find_callback(type);
 
@@ -86,7 +86,7 @@ void* resource_on_load(uint32_t type, Allocator& allocator, Bundle& bundle, Reso
 }
 
 //-----------------------------------------------------------------------------
-void resource_on_unload(uint32_t type, Allocator& allocator, void* resource)
+void resource_on_unload(uint64_t type, Allocator& allocator, void* resource)
 {
 	const ResourceCallback* c = find_callback(type);
 
@@ -96,7 +96,7 @@ void resource_on_unload(uint32_t type, Allocator& allocator, void* resource)
 }
 
 //-----------------------------------------------------------------------------
-void resource_on_online(uint32_t type, void* resource)
+void resource_on_online(uint64_t type, void* resource)
 {
 	const ResourceCallback* c = find_callback(type);
 
@@ -106,7 +106,7 @@ void resource_on_online(uint32_t type, void* resource)
 }
 
 //-----------------------------------------------------------------------------
-void resource_on_offline(uint32_t type, void* resource)
+void resource_on_offline(uint64_t type, void* resource)
 {
 	const ResourceCallback* c = find_callback(type);
 

+ 4 - 4
engine/resource/ResourceRegistry.h

@@ -31,9 +31,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-void* resource_on_load(uint32_t type, Allocator& allocator, Bundle& bundle, ResourceId id);
-void resource_on_online(uint32_t type, void* resource);
-void resource_on_offline(uint32_t type, void* resource);
-void resource_on_unload(uint32_t type, Allocator& allocator, void* resource);
+void* resource_on_load(uint64_t type, Allocator& allocator, Bundle& bundle, ResourceId id);
+void resource_on_online(uint64_t type, void* resource);
+void resource_on_offline(uint64_t type, void* resource);
+void resource_on_unload(uint64_t type, Allocator& allocator, void* resource);
 
 } // namespace crown

+ 1 - 1
engine/resource/TextureResource.cpp

@@ -430,7 +430,7 @@ void write_dds(BinaryWriter& bw, const ImageData& image)
 		MipData mip;
 		read_mip_image(image, i, mip);
 
-		CE_LOGD("Writing mip: (%ux%u) byes = %u", mip.width, mip.height, mip.size);
+		// CE_LOGD("Writing mip: (%ux%u) byes = %u", mip.width, mip.height, mip.size);
 		bw.write(mip.data, mip.size);
 	}
 }

+ 9 - 13
engine/resource/UnitResource.cpp

@@ -220,27 +220,23 @@ void parse_renderables(JSONElement e, Array<UnitRenderable>& renderables, const
 		rn.node = find_node_index(node_name_hash, node_depths);
 		rn.visible = renderable.key("visible").to_bool();
 
-		DynamicString res_type; renderable.key("type").to_string(res_type);
-		DynamicString resource_name; renderable.key("resource").to_string(resource_name);
-		DynamicString res_name;
+		DynamicString res_type;
+		renderable.key("type").to_string(res_type);
 
 		if (res_type == "mesh")
 		{
 			rn.type = UnitRenderable::MESH;
-			res_name += resource_name;
-			res_name += ".mesh";
+			rn.resource = renderable.key("resource").to_resource_id("mesh");
 		}
 		else if (res_type == "sprite")
 		{
 			rn.type = UnitRenderable::SPRITE;
-			res_name += resource_name;
-			res_name += ".sprite";
+			rn.resource = renderable.key("resource").to_resource_id("sprite");
 		}
 		else
 		{
 			CE_ASSERT(false, "Oops, unknown renderable type: '%s'", res_type.c_str());
 		}
-		rn.resource = ResourceId(res_name.c_str());
 
 		array::push_back(renderables, rn);
 	}
@@ -343,12 +339,12 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 
 	// Check if the unit has a .physics resource
 	DynamicString unit_name(resource_path);
-	unit_name.strip_trailing("unit");
+	unit_name.strip_trailing(".unit");
 	DynamicString physics_name = unit_name;
-	physics_name += "physics";
+	physics_name += ".physics";
 	if (fs.is_file(physics_name.c_str()))
 	{
-		m_physics_resource = ResourceId(physics_name.c_str());
+		m_physics_resource = ResourceId("physics", unit_name.c_str());
 	}
 	else
 	{
@@ -357,10 +353,10 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 
 	// Check if the unit has a .material resource
 	DynamicString material_name = unit_name;
-	material_name += "material";
+	material_name += ".material";
 	if (fs.is_file(material_name.c_str()))
 	{
-		m_material_resource = ResourceId(material_name.c_str());
+		m_material_resource = ResourceId("material", unit_name.c_str());
 	}
 	else
 	{

+ 3 - 6
engine/world/Unit.cpp

@@ -188,7 +188,7 @@ void Unit::create_renderable_objects()
 	}
 
 	// Create materials
-	if (m_resource->material_resource().id != 0)
+	if (m_resource->material_resource().type != 0)
 	{
 		MaterialResource* mr = (MaterialResource*) device()->resource_manager()->get(m_resource->material_resource());
 		add_material(string::murmur2_32("default", string::strlen("default"), 0), m_world.render_world()->create_material(mr));
@@ -198,7 +198,7 @@ void Unit::create_renderable_objects()
 //-----------------------------------------------------------------------------
 void Unit::create_physics_objects()
 {
-	if (m_resource->physics_resource().id != 0)
+	if (m_resource->physics_resource().type != 0)
 	{
 		const PhysicsResource* pr = (PhysicsResource*) device()->resource_manager()->get(m_resource->physics_resource());
 
@@ -560,10 +560,7 @@ Material* Unit::material(uint32_t i)
 //-----------------------------------------------------------------------------
 bool Unit::is_a(const char* name)
 {
-	DynamicString unit(name);
-	unit += ".unit";
-
-	return m_resource_id.id == string::murmur2_64(unit.c_str(), string::strlen(unit.c_str()), 0);
+	return m_resource_id == ResourceId("unit", name);
 }
 
 //-----------------------------------------------------------------------------