Jelajahi Sumber

Move murmur2_* to StringUtils.h

Daniele Bartolini 12 tahun lalu
induk
melakukan
d80521bab0

+ 0 - 1
engine/CMakeLists.txt

@@ -193,7 +193,6 @@ set (STRINGS_HEADERS
 	core/strings/Path.h
 	core/strings/StringUtils.h
 	core/strings/StringStream.h
-	core/strings/Hash.h
 	core/strings/DynamicString.h
 )
 

+ 1 - 1
engine/Crown.h

@@ -63,7 +63,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 // Core/Strings
 #include "StringUtils.h"
 #include "StringStream.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "Path.h"
 
 // Core/Mem

+ 1 - 1
engine/Device.cpp

@@ -485,7 +485,7 @@ void Device::reload(const char* type, const char* name)
 		m_resource_manager->flush();
 		const void* new_res = m_resource_manager->data(res_id);
 
-		uint32_t type_hash = hash::murmur2_32(type, string::strlen(type), 0);
+		uint32_t type_hash = string::murmur2_32(type, string::strlen(type), 0);
 
 		switch (type_hash)
 		{

+ 2 - 2
engine/compilers/BundleCompiler.cpp

@@ -103,11 +103,11 @@ bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir, con
 	{
 		const char* filename = files[i].c_str();
 
-		uint64_t filename_hash = hash::murmur2_64(filename, string::strlen(filename), 0);
+		uint64_t filename_hash = string::murmur2_64(filename, string::strlen(filename), 0);
 
 		char filename_extension[32];
 		path::extension(filename, filename_extension, 32);
-		uint32_t resource_type_hash = hash::murmur2_32(filename_extension, string::strlen(filename_extension), 0);
+		uint32_t resource_type_hash = string::murmur2_32(filename_extension, string::strlen(filename_extension), 0);
 
 		char out_name[65];
 		snprintf(out_name, 65, "%.16"PRIx64"", filename_hash);

+ 1 - 1
engine/core/json/JSONParser.h

@@ -118,7 +118,7 @@ public:
 	/// Returns the string value of the element.
 	void				to_string(DynamicString& str) const;
 
-	/// Returns the string id value hashed to hash::murmur2_32() of the element.
+	/// Returns the string id value hashed to string::murmur2_32() of the element.
 	StringId32			to_string_id() const;
 
 	/// Returns the array value of the element.

+ 3 - 3
engine/core/strings/DynamicString.h

@@ -33,7 +33,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Allocator.h"
 #include "StringUtils.h"
 #include "Array.h"
-#include "Hash.h"
+#include "StringUtils.h"
 
 namespace crown
 {
@@ -78,7 +78,7 @@ public:
 	/// Returns wheterh the string ends with the given @æ s string.
 	bool				ends_with(const char* s);
 
-	/// Returns the string hashed to hash::murmur2_32.
+	/// Returns the string hashed to string::murmur2_32.
 	StringId32			to_string_id();
 
 	///
@@ -236,7 +236,7 @@ inline bool DynamicString::ends_with(const char* s)
 //-----------------------------------------------------------------------------
 inline StringId32 DynamicString::to_string_id()
 {
-	return hash::murmur2_32(c_str(), length());
+	return string::murmur2_32(c_str(), length());
 }
 
 //-----------------------------------------------------------------------------

+ 0 - 174
engine/core/strings/Hash.h

@@ -1,174 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Config.h"
-#include "Assert.h"
-#include "Types.h"
-#include "StringUtils.h"
-
-namespace crown
-{
-namespace hash
-{
-
-//-----------------------------------------------------------------------------
-/// MurmurHash2, by Austin Appleby
-///
-/// @note
-/// This code makes a few assumptions about how your machine behaves
-///
-/// 1. We can read a 4-byte value from any address without crashing
-/// 2. sizeof(int) == 4
-///
-/// And it has a few limitations -
-///
-/// 1. It will not work incrementally.
-/// 2. It will not produce the same results on little-endian and big-endian
-///    machines.
-inline uint32_t murmur2_32(const void* key, size_t len, uint32_t seed = 0)
-{
-	CE_ASSERT_NOT_NULL(key);
-
-	// 'm' and 'r' are mixing constants generated offline.
-	// They're not really 'magic', they just happen to work well.
-	const unsigned int m = 0x5bd1e995;
-	const int r = 24;
-
-	// Initialize the hash to a 'random' value
-	unsigned int h = seed ^ len;
-
-	// Mix 4 bytes at a time into the hash
-	const unsigned char * data = (const unsigned char *)key;
-
-	while(len >= 4)
-	{
-		unsigned int k = *(unsigned int *)data;
-
-		k *= m; 
-		k ^= k >> r; 
-		k *= m; 
-		
-		h *= m; 
-		h ^= k;
-
-		data += 4;
-		len -= 4;
-	}
-	
-	// Handle the last few bytes of the input array
-	switch(len)
-	{
-		case 3: h ^= data[2] << 16;
-		case 2: h ^= data[1] << 8;
-		case 1: h ^= data[0];
-			h *= m;
-	};
-
-	// Do a few final mixes of the hash to ensure the last few
-	// bytes are well-incorporated.
-	h ^= h >> 13;
-	h *= m;
-	h ^= h >> 15;
-
-	return h;
-}
-
-//-----------------------------------------------------------------------------
-inline uint64_t murmur2_64(const void* key, size_t len, unsigned int seed = 0)
-{
-	CE_ASSERT_NOT_NULL(key);
-
-	const unsigned int m = 0x5bd1e995;
-	const int r = 24;
-
-	unsigned int h1 = seed ^ len;
-	unsigned int h2 = 0;
-
-	const unsigned int * data = (const unsigned int *)key;
-
-	while(len >= 8)
-	{
-		unsigned int k1 = *data++;
-		k1 *= m; k1 ^= k1 >> r; k1 *= m;
-		h1 *= m; h1 ^= k1;
-		len -= 4;
-
-		unsigned int k2 = *data++;
-		k2 *= m; k2 ^= k2 >> r; k2 *= m;
-		h2 *= m; h2 ^= k2;
-		len -= 4;
-	}
-
-	if(len >= 4)
-	{
-		unsigned int k1 = *data++;
-		k1 *= m; k1 ^= k1 >> r; k1 *= m;
-		h1 *= m; h1 ^= k1;
-		len -= 4;
-	}
-
-	switch(len)
-	{
-	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;
-	};
-
-	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;
-
-	return h;
-}
-
-#ifdef CROWN_DEBUG
-	inline uint32_t HASH32(const char *s, uint32_t value)
-	{
-		CE_ASSERT(murmur2_32(s, string::strlen(s), 0) == value, "Hash mismatch");
-		return value;
-	}
-
-	inline uint64_t HASH64(const char* s, uint64_t value)
-	{
-		CE_ASSERT(murmur2_64(s, string::strlen(s), 0) == value, "Hash mismatch");
-		return value;
-	}
-#else
-	#define HASH32(s, v) (v)
-	#define HASH64(s, v) (v)
-#endif
-
-} // namespace hash
-} // namespace crown
-

+ 134 - 0
engine/core/strings/StringUtils.h

@@ -31,6 +31,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Assert.h"
 #include "Types.h"
+#include "Config.h"
 
 namespace crown
 {
@@ -237,6 +238,139 @@ inline float parse_double(const char* string)
 	return val;
 }
 
+//-----------------------------------------------------------------------------
+/// MurmurHash2, by Austin Appleby
+///
+/// @note
+/// This code makes a few assumptions about how your machine behaves
+///
+/// 1. We can read a 4-byte value from any address without crashing
+/// 2. sizeof(int) == 4
+///
+/// And it has a few limitations -
+///
+/// 1. It will not work incrementally.
+/// 2. It will not produce the same results on little-endian and big-endian
+///    machines.
+inline uint32_t murmur2_32(const void* key, size_t len, uint32_t seed = 0)
+{
+	CE_ASSERT_NOT_NULL(key);
+
+	// 'm' and 'r' are mixing constants generated offline.
+	// They're not really 'magic', they just happen to work well.
+	const unsigned int m = 0x5bd1e995;
+	const int r = 24;
+
+	// Initialize the hash to a 'random' value
+	unsigned int h = seed ^ len;
+
+	// Mix 4 bytes at a time into the hash
+	const unsigned char * data = (const unsigned char *)key;
+
+	while(len >= 4)
+	{
+		unsigned int k = *(unsigned int *)data;
+
+		k *= m; 
+		k ^= k >> r; 
+		k *= m; 
+		
+		h *= m; 
+		h ^= k;
+
+		data += 4;
+		len -= 4;
+	}
+	
+	// Handle the last few bytes of the input array
+	switch(len)
+	{
+		case 3: h ^= data[2] << 16;
+		case 2: h ^= data[1] << 8;
+		case 1: h ^= data[0];
+			h *= m;
+	};
+
+	// Do a few final mixes of the hash to ensure the last few
+	// bytes are well-incorporated.
+	h ^= h >> 13;
+	h *= m;
+	h ^= h >> 15;
+
+	return h;
+}
+
+//-----------------------------------------------------------------------------
+inline uint64_t murmur2_64(const void* key, size_t len, unsigned int seed = 0)
+{
+	CE_ASSERT_NOT_NULL(key);
+
+	const unsigned int m = 0x5bd1e995;
+	const int r = 24;
+
+	unsigned int h1 = seed ^ len;
+	unsigned int h2 = 0;
+
+	const unsigned int * data = (const unsigned int *)key;
+
+	while(len >= 8)
+	{
+		unsigned int k1 = *data++;
+		k1 *= m; k1 ^= k1 >> r; k1 *= m;
+		h1 *= m; h1 ^= k1;
+		len -= 4;
+
+		unsigned int k2 = *data++;
+		k2 *= m; k2 ^= k2 >> r; k2 *= m;
+		h2 *= m; h2 ^= k2;
+		len -= 4;
+	}
+
+	if(len >= 4)
+	{
+		unsigned int k1 = *data++;
+		k1 *= m; k1 ^= k1 >> r; k1 *= m;
+		h1 *= m; h1 ^= k1;
+		len -= 4;
+	}
+
+	switch(len)
+	{
+	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;
+	};
+
+	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;
+
+	return h;
+}
+
+#ifdef CROWN_DEBUG
+	inline uint32_t HASH32(const char *s, uint32_t value)
+	{
+		CE_ASSERT(murmur2_32(s, string::strlen(s), 0) == value, "Hash mismatch");
+		return value;
+	}
+
+	inline uint64_t HASH64(const char* s, uint64_t value)
+	{
+		CE_ASSERT(murmur2_64(s, string::strlen(s), 0) == value, "Hash mismatch");
+		return value;
+	}
+#else
+	#define HASH32(s, v) (v)
+	#define HASH64(s, v) (v)
+#endif
+
 } // namespace string
 } // namespace crown
 

+ 1 - 1
engine/lua/LuaGui.cpp

@@ -197,7 +197,7 @@ CE_EXPORT int gui_create_image(lua_State* L)
 	const Vector2 size = stack.get_vector2(4);
 
 	ResourceId mat_id;
-	mat_id.id = hash::murmur2_64(mat_name, string::strlen(mat_name), 0);
+	mat_id.id = string::murmur2_64(mat_name, string::strlen(mat_name), 0);
 
 	GuiImageId image_id = gui->create_image(mat_id, pos, size);
 

+ 1 - 1
engine/physics/PhysicsWorld.cpp

@@ -34,7 +34,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Joint.h"
 #include "PhysicsCallback.h"
 #include "ProxyAllocator.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "StringUtils.h"
 #include "Actor.h"
 #include "ResourceManager.h"

+ 1 - 1
engine/renderers/backend/gl/GLRenderer.cpp

@@ -39,7 +39,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Assert.h"
 #include "Device.h"
 #include "GLContext.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "Log.h"
 #include "Matrix3x3.h"
 #include "Matrix4x4.h"

+ 2 - 2
engine/resource/FontResource.cpp

@@ -28,7 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "JSONParser.h"
 #include "Allocator.h"
 #include "Filesystem.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "Bundle.h"
 #include "Types.h"
 
@@ -96,7 +96,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	fs.close(file);
 	default_allocator().deallocate(buf);
 
-	h.material.id = hash::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
+	h.material.id = string::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
 	h.num_glyphs = array::size(m_glyphs);
 	h.texture_size = size.to_int();
 	h.font_size = font_size.to_int();

+ 2 - 2
engine/resource/GuiResource.cpp

@@ -31,7 +31,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Allocator.h"
 #include "Filesystem.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "JSONParser.h"
 #include "GuiResource.h"
 #include "StringUtils.h"
@@ -76,7 +76,7 @@ void parse_image(JSONElement image, StringId64& material, Array<float>& position
 	mat.to_string(material_name);
 	material_name += ".material";
 
-	material = hash::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
+	material = string::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
 	position.to_array(positions);
 	size.to_array(sizes);
 }

+ 2 - 2
engine/resource/MaterialResource.cpp

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "MaterialResource.h"
 #include "DynamicString.h"
 #include "StringUtils.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "JSONParser.h"
 #include "Filesystem.h"
 
@@ -54,7 +54,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	{
 		DynamicString tex;
 		tl[i].to_string(tex); tex += ".texture";
-		ResourceId tex_id; tex_id.id = hash::murmur2_64(tex.c_str(), tex.length(), 0);
+		ResourceId tex_id; tex_id.id = string::murmur2_64(tex.c_str(), tex.length(), 0);
 		array::push_back(texture_layers, tex_id);
 	}
 

+ 11 - 11
engine/resource/PackageResource.cpp

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Allocator.h"
 #include "File.h"
 #include "Filesystem.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "JSONParser.h"
 #include "Log.h"
 #include "PackageResource.h"
@@ -79,7 +79,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(texture_name.c_str(), texture_name.length(), 0);
+			id.id = string::murmur2_64(texture_name.c_str(), texture_name.length(), 0);
 			array::push_back(m_texture, id);
 		}
 	}
@@ -103,7 +103,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(lua_name.c_str(), lua_name.length(), 0);
+			id.id = string::murmur2_64(lua_name.c_str(), lua_name.length(), 0);
 			array::push_back(m_script, id);
 		}
 	}
@@ -126,7 +126,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(sound_name.c_str(), string::strlen(sound_name.c_str()), 0);
+			id.id = string::murmur2_64(sound_name.c_str(), string::strlen(sound_name.c_str()), 0);
 			array::push_back(m_sound, id);
 		}
 	}
@@ -149,7 +149,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(mesh_name.c_str(), mesh_name.length(), 0);
+			id.id = string::murmur2_64(mesh_name.c_str(), mesh_name.length(), 0);
 			array::push_back(m_mesh, id);
 		}
 	}
@@ -171,7 +171,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(unit_name.c_str(), unit_name.length(), 0);
+			id.id = string::murmur2_64(unit_name.c_str(), unit_name.length(), 0);
 			array::push_back(m_unit, id);
 		}
 	}
@@ -194,7 +194,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(sprite_name.c_str(), sprite_name.length(), 0);
+			id.id = string::murmur2_64(sprite_name.c_str(), sprite_name.length(), 0);
 			array::push_back(m_sprite, id);
 		}
 	}
@@ -217,7 +217,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(physics_name.c_str(), physics_name.length(), 0);
+			id.id = string::murmur2_64(physics_name.c_str(), physics_name.length(), 0);
 			array::push_back(m_physics, id);
 		}	
 	}
@@ -240,7 +240,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(materials_name.c_str(), materials_name.length(), 0);
+			id.id = string::murmur2_64(materials_name.c_str(), materials_name.length(), 0);
 			array::push_back(m_materials, id);
 		}
 	}
@@ -263,7 +263,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(guis_name.c_str(), guis_name.length(), 0);
+			id.id = string::murmur2_64(guis_name.c_str(), guis_name.length(), 0);
 			array::push_back(m_guis, id);
 		}
 	}
@@ -286,7 +286,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 			}
 
 			ResourceId id;
-			id.id = hash::murmur2_64(font_name.c_str(), font_name.length(), 0);
+			id.id = string::murmur2_64(font_name.c_str(), font_name.length(), 0);
 			array::push_back(m_fonts, id);
 		}
 	}

+ 3 - 3
engine/resource/PhysicsResource.cpp

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <algorithm>
 #include "Allocator.h"
 #include "Filesystem.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "JSONParser.h"
 #include "PhysicsResource.h"
 #include "StringUtils.h"
@@ -156,7 +156,7 @@ void parse_shapes(JSONElement e, Array<PhysicsShape>& shapes)
 				resource.to_string(mesh_name);
 				mesh_name += ".mesh";
 
-				StringId64 mesh_id = hash::murmur2_64(mesh_name.c_str(), string::strlen(mesh_name.c_str()), 0);
+				StringId64 mesh_id = string::murmur2_64(mesh_name.c_str(), string::strlen(mesh_name.c_str()), 0);
 
 				ps.resource.id = mesh_id;
 
@@ -399,7 +399,7 @@ namespace physics_config_resource
 
 	uint32_t collision_filter_to_mask(const char* filter, Array<NameToMask> name_to_mask)
 	{
-		StringId32 filter_hash = hash::murmur2_32(filter, string::strlen(filter));
+		StringId32 filter_hash = string::murmur2_32(filter, string::strlen(filter));
 		for (uint32_t i = 0; i < array::size(name_to_mask); i++)
 		{
 			if (name_to_mask[i].name == filter_hash) return name_to_mask[i].mask;

+ 1 - 1
engine/resource/Resource.h

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "StringUtils.h"
 
 namespace crown

+ 3 - 3
engine/resource/ResourceManager.cpp

@@ -30,7 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "ResourceManager.h"
 #include "ResourceRegistry.h"
 #include "StringUtils.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "TempAllocator.h"
 #include "DynamicString.h"
 #include "Queue.h"
@@ -58,7 +58,7 @@ ResourceManager::~ResourceManager()
 //-----------------------------------------------------------------------------
 ResourceId ResourceManager::load(const char* type, const char* name)
 {
-	return load(hash::murmur2_32(type, string::strlen(type), 0), resource_id(type, name));
+	return load(string::murmur2_32(type, string::strlen(type), 0), resource_id(type, name));
 }
 
 //-----------------------------------------------------------------------------
@@ -151,7 +151,7 @@ ResourceId ResourceManager::resource_id(const char* type, const char* name) cons
 	res_name += type;
 
 	ResourceId res_id;
-	res_id.id = hash::murmur2_64(res_name.c_str(), string::strlen(res_name.c_str()), m_seed);
+	res_id.id = string::murmur2_64(res_name.c_str(), string::strlen(res_name.c_str()), m_seed);
 
 	return res_id;
 }

+ 2 - 2
engine/resource/SpriteResource.cpp

@@ -29,7 +29,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Allocator.h"
 #include "Filesystem.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "JSONParser.h"
 #include "SpriteResource.h"
 #include "StringUtils.h"
@@ -61,7 +61,7 @@ void parse_frame(JSONElement frame, Array<StringId32>& names, Array<FrameData>&
 	DynamicString frame_name;
 	name.to_string(frame_name);
 
-	StringId32 name_hash = hash::murmur2_32(frame_name.c_str(), frame_name.length(), 0);
+	StringId32 name_hash = string::murmur2_32(frame_name.c_str(), frame_name.length(), 0);
 	FrameData fd;
 	fd.x0 = region[0].to_float();
 	fd.y0 = region[1].to_float();

+ 10 - 10
engine/resource/UnitResource.cpp

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Allocator.h"
 #include "File.h"
 #include "Filesystem.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "JSONParser.h"
 #include "ContainerTypes.h"
 #include "Log.h"
@@ -130,14 +130,14 @@ void parse_nodes(JSONElement e, Array<GraphNode>& nodes, Array<GraphNodeDepth>&
 		JSONElement node = e.key(node_name);
 
 		GraphNode gn;
-		gn.name = hash::murmur2_32(node_name, string::strlen(node_name));
+		gn.name = string::murmur2_32(node_name, string::strlen(node_name));
 		gn.parent = NO_PARENT;
 
 		if (!node.key("parent").is_nil())
 		{
 			DynamicString parent_name;
 			node.key("parent").to_string(parent_name);
-			gn.parent = hash::murmur2_32(parent_name.c_str(), parent_name.length(), 0);
+			gn.parent = string::murmur2_32(parent_name.c_str(), parent_name.length(), 0);
 		}
 
 		JSONElement pos = node.key("position");
@@ -169,10 +169,10 @@ void parse_cameras(JSONElement e, Array<UnitCamera>& cameras, const Array<GraphN
 		DynamicString node_name;
 		camera.key("node").to_string(node_name);
 
-		StringId32 node_name_hash = hash::murmur2_32(node_name.c_str(), node_name.length());
+		StringId32 node_name_hash = string::murmur2_32(node_name.c_str(), node_name.length());
 
 		UnitCamera cn;
-		cn.name = hash::murmur2_32(camera_name, string::strlen(camera_name));
+		cn.name = string::murmur2_32(camera_name, string::strlen(camera_name));
 		cn.node = find_node_index(node_name_hash, node_depths);
 
 		array::push_back(cameras, cn);
@@ -191,10 +191,10 @@ void parse_renderables(JSONElement e, Array<UnitRenderable>& renderables, const
 		JSONElement renderable = e.key(renderable_name);
 
 		DynamicString node_name; renderable.key("node").to_string(node_name);
-		StringId32 node_name_hash = hash::murmur2_32(node_name.c_str(), node_name.length(), 0);
+		StringId32 node_name_hash = string::murmur2_32(node_name.c_str(), node_name.length(), 0);
 
 		UnitRenderable rn;
-		rn.name = hash::murmur2_32(renderable_name, string::strlen(renderable_name), 0);
+		rn.name = string::murmur2_32(renderable_name, string::strlen(renderable_name), 0);
 		rn.node = find_node_index(node_name_hash, node_depths);
 		rn.visible = renderable.key("visible").to_bool();
 
@@ -218,7 +218,7 @@ void parse_renderables(JSONElement e, Array<UnitRenderable>& renderables, const
 		{
 			CE_ASSERT(false, "Oops, unknown renderable type: '%s'", res_type.c_str());
 		}
-		rn.resource.id = hash::murmur2_64(res_name.c_str(), res_name.length(), 0);
+		rn.resource.id = string::murmur2_64(res_name.c_str(), res_name.length(), 0);
 
 		array::push_back(renderables, rn);
 	}
@@ -263,7 +263,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	physics_name += "physics";
 	if (fs.is_file(physics_name.c_str()))
 	{
-		m_physics_resource.id = hash::murmur2_64(physics_name.c_str(), string::strlen(physics_name.c_str()), 0);
+		m_physics_resource.id = string::murmur2_64(physics_name.c_str(), string::strlen(physics_name.c_str()), 0);
 	}
 	else
 	{
@@ -275,7 +275,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	material_name += "material";
 	if (fs.is_file(material_name.c_str()))
 	{
-		m_material_resource.id = hash::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
+		m_material_resource.id = string::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
 	}
 	else
 	{

+ 3 - 4
engine/world/SceneGraph.cpp

@@ -24,11 +24,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include <string.h>
 #include "SceneGraph.h"
 #include "Quaternion.h"
 #include "Allocator.h"
-#include <string.h>
-#include "Hash.h"
 #include "StringUtils.h"
 
 #define CLEAN		0
@@ -95,7 +94,7 @@ void SceneGraph::destroy()
 //-----------------------------------------------------------------------------
 int32_t SceneGraph::node(const char* name) const
 {
-	return node(hash::murmur2_32(name, string::strlen(name)));
+	return node(string::murmur2_32(name, string::strlen(name)));
 }
 
 //-----------------------------------------------------------------------------
@@ -115,7 +114,7 @@ int32_t SceneGraph::node(StringId32 name) const
 //-----------------------------------------------------------------------------
 bool SceneGraph::has_node(const char* name) const
 {
-	StringId32 name_hash = hash::murmur2_32(name, string::strlen(name), 0);
+	StringId32 name_hash = string::murmur2_32(name, string::strlen(name), 0);
 
 	for (uint32_t i = 0; i < m_num_nodes; i++)
 	{

+ 3 - 3
engine/world/Unit.cpp

@@ -184,7 +184,7 @@ void Unit::create_renderable_objects()
 	if (m_resource->material_resource().id != 0)
 	{
 		MaterialResource* mr = (MaterialResource*) device()->resource_manager()->data(m_resource->material_resource());
-		add_material(hash::murmur2_32("default", string::strlen("default"), 0), m_world.render_world()->create_material(mr));
+		add_material(string::murmur2_32("default", string::strlen("default"), 0), m_world.render_world()->create_material(mr));
 	}
 }
 
@@ -347,7 +347,7 @@ void Unit::add_component(StringId32 name, Id component, uint32_t& size, Componen
 //-----------------------------------------------------------------------------
 Id Unit::find_component(const char* name, uint32_t size, Component* array)
 {
-	uint32_t name_hash = hash::murmur2_32(name, string::strlen(name), 0);
+	uint32_t name_hash = string::murmur2_32(name, string::strlen(name), 0);
 
 	Id comp;
 	comp.id = INVALID_ID;
@@ -568,7 +568,7 @@ bool Unit::is_a(const char* name)
 	DynamicString unit(name);
 	unit += ".unit";
 
-	return m_resource_id.id == hash::murmur2_64(unit.c_str(), string::strlen(unit.c_str()), 0);
+	return m_resource_id.id == string::murmur2_64(unit.c_str(), string::strlen(unit.c_str()), 0);
 }
 
 

+ 1 - 1
engine/world/Unit.h

@@ -30,7 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Vector3.h"
 #include "Quaternion.h"
 #include "Matrix4x4.h"
-#include "Hash.h"
+#include "StringUtils.h"
 #include "SceneGraph.h"
 #include "StringUtils.h"
 #include "PhysicsTypes.h"