Bladeren bron

Merge branch 'master' of github.com:taylor001/crown

Daniele Bartolini 10 jaren geleden
bovenliggende
commit
3dccdf2a1f
45 gewijzigde bestanden met toevoegingen van 318 en 296 verwijderingen
  1. 3 1
      .gitattributes
  2. 9 11
      samples/01.hello-world/boot.package
  3. 10 11
      samples/01.hello-world/camera.unit
  4. 7 9
      samples/01.hello-world/crown.config
  5. 18 20
      samples/01.hello-world/global.physics_config
  6. 7 5
      src/compilers/bundle_compiler.cpp
  7. 1 5
      src/config.h
  8. 29 34
      src/console_server.cpp
  9. 3 6
      src/console_server.h
  10. 1 1
      src/core/containers/array.h
  11. 17 10
      src/core/json/json_parser.cpp
  12. 4 3
      src/core/json/json_parser.h
  13. 37 3
      src/core/json/njson.cpp
  14. 3 0
      src/core/json/njson.h
  15. 13 0
      src/core/string_id.cpp
  16. 1 1
      src/core/strings/string_utils.h
  17. 8 0
      src/core/types.h
  18. 8 3
      src/crown.cpp
  19. 1 1
      src/crown.h
  20. 4 10
      src/device.cpp
  21. 16 14
      src/device.h
  22. 2 2
      src/lua/lua_device.cpp
  23. 1 1
      src/lua/lua_world.cpp
  24. 1 2
      src/renderers/gui.cpp
  25. 1 1
      src/renderers/shader.cpp
  26. 1 1
      src/resource/font_resource.cpp
  27. 3 8
      src/resource/level_resource.cpp
  28. 5 5
      src/resource/material_resource.cpp
  29. 1 1
      src/resource/mesh_resource.cpp
  30. 14 14
      src/resource/package_resource.cpp
  31. 2 2
      src/resource/physics_resource.cpp
  32. 0 1
      src/resource/physics_resource.h
  33. 0 58
      src/resource/resource_id.h
  34. 11 8
      src/resource/resource_loader.cpp
  35. 17 5
      src/resource/resource_loader.h
  36. 16 13
      src/resource/resource_manager.cpp
  37. 19 3
      src/resource/resource_manager.h
  38. 5 4
      src/resource/resource_registry.cpp
  39. 2 2
      src/resource/resource_registry.h
  40. 1 1
      src/resource/sound_resource.cpp
  41. 2 2
      src/resource/sprite_resource.cpp
  42. 1 1
      src/resource/texture_resource.cpp
  43. 9 9
      src/resource/unit_resource.cpp
  44. 3 3
      src/world/world.cpp
  45. 1 1
      src/world/world.h

+ 3 - 1
.gitattributes

@@ -22,4 +22,6 @@
 *.so  binary
 *.dll binary
 *.exe binary
-*.tga binary
+*.tga binary
+*.dds binary
+*.wav binary

+ 9 - 11
samples/01.hello-world/boot.package

@@ -1,11 +1,9 @@
-{
-	lua = [
-		"lua/game"
-	]
-	unit = [
-		"camera"
-	]
-	physics_config = [
-		"global"
-	]
-}
+lua = [
+	"lua/game"
+]
+unit = [
+	"camera"
+]
+physics_config = [
+	"global"
+]

+ 10 - 11
samples/01.hello-world/camera.unit

@@ -1,13 +1,12 @@
-{
-	cameras = {
-		camera = {
-			node = "root"
-			type = "perspective"
-			near_clip_distance = 0.01
-			far_clip_distance = 1000.0
-		}
-	}
-	nodes = {
-		root = { parent = null position = [0 0 0] rotation = [0 0 1 0] }
+cameras = {
+	camera = {
+		node = "root"
+		type = "perspective"
+		near_clip_distance = 0.01
+		far_clip_distance = 1000.0
 	}
 }
+
+nodes = {
+	root = { parent = null position = [0 0 0] rotation = [0 0 1 0] }
+}

+ 7 - 9
samples/01.hello-world/crown.config

@@ -1,12 +1,10 @@
-{
-	// Lua script to launch on boot
-	boot_script = "lua/game"
+// Lua script to launch on boot
+boot_script = "lua/game"
 
-	// Package to load on boot
-	boot_package = "boot"
+// Package to load on boot
+boot_package = "boot"
 
-	console_port = 10001
+console_port = 10001
 
-	window_width = 1280
-	window_height = 720
-}
+window_width = 1280
+window_height = 720

+ 18 - 20
samples/01.hello-world/global.physics_config

@@ -1,24 +1,22 @@
-{
-	materials" = {
-		default = { static_friction = 0.5 dynamic_friction = 0.5 restitution = 0.1 }
-		test = { static_friction = 0.2 dynamic_friction = 0.7 restitution = 0.5 }
-		light = { static_friction = 0.2 dynamic_friction = 0.2 restitution = 0.7}
-	}
+materials = {
+	default = { static_friction = 0.5 dynamic_friction = 0.5 restitution = 0.1 }
+	test = { static_friction = 0.2 dynamic_friction = 0.7 restitution = 0.5 }
+	light = { static_friction = 0.2 dynamic_friction = 0.2 restitution = 0.7}
+}
 
-	shapes = {
-		default = { trigger = false collision_filter = "default" }
-		trigger = { trigger = true collision_filter = "default" }
-	}
+shapes = {
+	default = { trigger = false collision_filter = "default" }
+	trigger = { trigger = true collision_filter = "default" }
+}
 
-	actors = {
-		static = { dynamic = false }
-		dynamic = { dynamic = true }
-		keyframed = { dynamic = true kinematic = true disable_gravity = true }
-		test = { dynamic = true linear_damping = 10.0 angular_damping = 23.0 }
-	}
+actors = {
+	static = { dynamic = false }
+	dynamic = { dynamic = true }
+	keyframed = { dynamic = true kinematic = true disable_gravity = true }
+	test = { dynamic = true linear_damping = 10.0 angular_damping = 23.0 }
+}
 
-	collision_filters = {
-		default = { collides_with = ["default"] }
-		foo = { collides_with = ["default" "foo"] }
-	}
+collision_filters = {
+	default = { collides_with = ["default"] }
+	foo = { collides_with = ["default" "foo"] }
 }

+ 7 - 5
src/compilers/bundle_compiler.cpp

@@ -14,7 +14,6 @@
 #include "disk_filesystem.h"
 #include "compile_options.h"
 #include "resource_registry.h"
-#include "resource_id.h"
 #include "temp_allocator.h"
 
 namespace crown
@@ -30,7 +29,8 @@ BundleCompiler::BundleCompiler(const char* source_dir, const char* bundle_dir)
 
 bool BundleCompiler::compile(const char* type, const char* name, Platform::Enum platform)
 {
-	ResourceId id(type, name);
+	StringId64 _type(type);
+	StringId64 _name(name);
 
 	TempAllocator512 alloc;
 	DynamicString path(alloc);
@@ -41,8 +41,10 @@ bool BundleCompiler::compile(const char* type, const char* name, Platform::Enum
 	src_path += ".";
 	src_path += type;
 
-	char res_name[64];
-	id.to_string(res_name);
+	char res_name[1 + 2*StringId64::STRING_LENGTH];
+	_type.to_string(res_name);
+	res_name[16] = '-';
+	_name.to_string(res_name + 17);
 
 	path::join(CROWN_DATA_DIRECTORY, res_name, path);
 
@@ -50,7 +52,7 @@ bool BundleCompiler::compile(const char* type, const char* name, Platform::Enum
 
 	File* outf = _bundle_fs.open(path.c_str(), FOM_WRITE);
 	CompileOptions opts(_source_fs, outf, platform);
-	resource_on_compile(id.type, src_path.c_str(), opts);
+	resource_on_compile(_type, src_path.c_str(), opts);
 	_bundle_fs.close(outf);
 	return true;
 }

+ 1 - 5
src/config.h

@@ -10,7 +10,7 @@
 #include "platform.h"
 
 #ifndef CROWN_DEBUG
-#	define CROWN_DEBUG 0
+	#define CROWN_DEBUG 0
 #endif // CROWN_DEBUG
 
 #if !defined(CROWN_PHYSICS_PHYSX)\
@@ -86,10 +86,6 @@
 	#define CE_MAX_SOUND_INSTANCES 64 // Per world
 #endif // CE_MAX
 
-#ifndef CE_MAX_CONSOLE_CLIENTS
-	#define CE_MAX_CONSOLE_CLIENTS 32
-#endif // CE_MAX
-
 #ifndef CROWN_MAX_DEBUG_LINES
 	#define CROWN_MAX_DEBUG_LINES 32768 // Per DebugLine
 #endif // CROWN_MAX_DEBUG_LINES

+ 29 - 34
src/console_server.cpp

@@ -17,9 +17,10 @@ namespace crown
 {
 
 ConsoleServer::ConsoleServer(uint16_t port, bool wait)
+	: _clients(default_allocator())
 {
-	m_server.bind(port);
-	m_server.listen(5);
+	_server.bind(port);
+	_server.listen(5);
 
 	if (wait)
 	{
@@ -27,7 +28,7 @@ ConsoleServer::ConsoleServer(uint16_t port, bool wait)
 		TCPSocket client;
 		do
 		{
-			result = m_server.accept(client);
+			result = _server.accept(client);
 		}
 		while (result.error != AcceptResult::NO_ERROR);
 
@@ -37,12 +38,10 @@ ConsoleServer::ConsoleServer(uint16_t port, bool wait)
 
 void ConsoleServer::shutdown()
 {
-	for (uint32_t i = 0; i < id_array::size(m_clients); i++)
-	{
-		m_clients[i].close();
-	}
+	for (uint32_t i = 0; i < vector::size(_clients); ++i)
+		_clients[i].close();
 
-	m_server.close();
+	_server.close();
 }
 
 namespace console_server_internal
@@ -88,49 +87,45 @@ void ConsoleServer::send(TCPSocket client, const char* json)
 
 void ConsoleServer::send(const char* json)
 {
-	for (uint32_t i = 0; i < id_array::size(m_clients); i++)
-	{
-		send(m_clients[i].socket, json);
-	}
+	for (uint32_t i = 0; i < vector::size(_clients); ++i)
+		send(_clients[i].socket, json);
 }
 
 void ConsoleServer::update()
 {
-	// Check for new clients only if we have room for them
-	if (id_array::size(m_clients) < CE_MAX_CONSOLE_CLIENTS - 1)
-	{
-		TCPSocket client;
-		AcceptResult result = m_server.accept_nonblock(client);
-		if (result.error == AcceptResult::NO_ERROR)
-		{
-			add_client(client);
-		}
-	}
+	TCPSocket client;
+	AcceptResult result = _server.accept_nonblock(client);
+	if (result.error == AcceptResult::NO_ERROR)
+		add_client(client);
 
 	TempAllocator256 alloc;
-	Array<Id> to_remove(alloc);
+	Array<uint32_t> to_remove(alloc);
 
 	// Update all clients
-	for (uint32_t i = 0; i < id_array::size(m_clients); i++)
+	for (uint32_t i = 0; i < vector::size(_clients); ++i)
 	{
-		ReadResult rr = update_client(m_clients[i].socket);
-		if (rr.error != ReadResult::NO_ERROR) array::push_back(to_remove, m_clients[i].id);
+		ReadResult rr = update_client(_clients[i].socket);
+		if (rr.error != ReadResult::NO_ERROR)
+			array::push_back(to_remove, i);
 	}
 
 	// Remove clients
-	for (uint32_t i = 0; i < array::size(to_remove); i++)
+	for (uint32_t i = 0; i < array::size(to_remove); ++i)
 	{
-		id_array::get(m_clients, to_remove[i]).socket.close();
-		id_array::destroy(m_clients, to_remove[i]);
+		const uint32_t last = vector::size(_clients) - 1;
+		const uint32_t c = to_remove[i];
+
+		_clients[c].close();
+		_clients[c] = _clients[last];
+		vector::pop_back(_clients);
 	}
 }
 
 void ConsoleServer::add_client(TCPSocket socket)
 {
-	Client client;
-	client.socket = socket;
-	Id id = id_array::create(m_clients, client);
-	id_array::get(m_clients, id).id = id;
+	Client cl;
+	cl.socket = socket;
+	vector::push_back(_clients, cl);
 }
 
 ReadResult ConsoleServer::update_client(TCPSocket client)
@@ -200,7 +195,7 @@ void ConsoleServer::process_command(TCPSocket /*client*/, const char* json)
 		json::parse_string(root["resource_type"], type);
 		json::parse_string(root["resource_name"], name);
 
-		device()->reload(type.c_str(), name.c_str());
+		device()->reload(StringId64(type.c_str()), StringId64(name.c_str()));
 	}
 	else if (cmd == "pause")
 	{

+ 3 - 6
src/console_server.h

@@ -5,8 +5,8 @@
 
 #pragma once
 
+#include "container_types.h"
 #include "socket.h"
-#include "id_array.h"
 #include "log.h"
 
 namespace crown
@@ -43,11 +43,8 @@ private:
 
 private:
 
-	TCPSocket m_server;
-
 	struct Client
 	{
-		Id id;
 		TCPSocket socket;
 
 		void close()
@@ -56,8 +53,8 @@ private:
 		}
 	};
 
-	typedef IdArray<CE_MAX_CONSOLE_CLIENTS, Client> ClientArray;
-	ClientArray m_clients;
+	TCPSocket _server;
+	Vector<Client> _clients;
 };
 
 /// Functions for accessing global console.

+ 1 - 1
src/core/containers/array.h

@@ -5,9 +5,9 @@
 
 #pragma once
 
+#include "container_types.h"
 #include "error.h"
 #include "macros.h"
-#include "container_types.h"
 #include "allocator.h"
 #include <cstring> // memcpy
 

+ 17 - 10
src/core/json/json_parser.cpp

@@ -79,7 +79,7 @@ JSONElement JSONElement::index_or_nil(uint32_t i)
 JSONElement JSONElement::key(const char* k)
 {
 	Map<DynamicString, const char*> object(default_allocator());
-	njson::parse_object(_at, object);
+	njson::parse(_at, object);
 
 	const char* value = map::get(object, DynamicString(k), (const char*) NULL);
 	CE_ASSERT(value != NULL, "Key not found: '%s'", k);
@@ -92,7 +92,7 @@ JSONElement JSONElement::key_or_nil(const char* k)
 	if (_at != NULL)
 	{
 		Map<DynamicString, const char*> object(default_allocator());
-		njson::parse_object(_at, object);
+		njson::parse(_at, object);
 
 		const char* value = map::get(object, DynamicString(k), (const char*) NULL);
 
@@ -106,7 +106,7 @@ JSONElement JSONElement::key_or_nil(const char* k)
 bool JSONElement::has_key(const char* k) const
 {
 	Map<DynamicString, const char*> object(default_allocator());
-	njson::parse_object(_at, object);
+	njson::parse(_at, object);
 
 	return map::has(object, DynamicString(k));
 }
@@ -214,13 +214,11 @@ StringId32 JSONElement::to_string_id(const StringId32 def) const
 	return str.to_string_id();
 }
 
-ResourceId JSONElement::to_resource_id(const char* type) const
+ResourceId JSONElement::to_resource_id() const
 {
-	CE_ASSERT_NOT_NULL(type);
-	// TempAllocator1024 alloc;
 	DynamicString str(default_allocator());
 	njson::parse_string(_at, str);
-	return ResourceId(type, str.c_str());
+	return ResourceId(str.c_str());
 }
 
 void JSONElement::to_array(Array<bool>& array) const
@@ -312,7 +310,7 @@ void JSONElement::to_array(Vector<DynamicString>& array) const
 void JSONElement::to_keys(Vector<DynamicString>& keys) const
 {
 	Map<DynamicString, const char*> object(default_allocator());
-	njson::parse_object(_at, object);
+	njson::parse(_at, object);
 
 	const Map<DynamicString, const char*>::Node* it = map::begin(object);
 	while (it != map::end(object))
@@ -398,7 +396,7 @@ uint32_t JSONElement::size() const
 		case NJSONValueType::OBJECT:
 		{
 			Map<DynamicString, const char*> object(default_allocator());
-			njson::parse_object(_at, object);
+			njson::parse(_at, object);
 			return map::size(object);
 		}
 		case NJSONValueType::ARRAY:
@@ -441,11 +439,20 @@ JSONParser::JSONParser(File& f)
 	, _document(NULL)
 {
 	const size_t size = f.size();
-	char* doc = (char*) default_allocator().allocate(size);
+	char* doc = (char*) default_allocator().allocate(size + 1);
 	f.read(doc, size);
+	doc[size] = '\0';
 	_document = doc;
 }
 
+JSONParser::JSONParser(Buffer& b)
+	: _file(false)
+	, _document(NULL)
+{
+	array::push_back(b, '\0');
+	_document = array::begin(b);
+}
+
 JSONParser::~JSONParser()
 {
 	if (_file)

+ 4 - 3
src/core/json/json_parser.h

@@ -11,7 +11,6 @@
 #include "matrix4x4.h"
 #include "quaternion.h"
 #include "macros.h"
-#include "resource_id.h"
 
 namespace crown
 {
@@ -124,8 +123,7 @@ public:
 	StringId32 to_string_id(const StringId32 def = StringId32(uint32_t(0))) const;
 
 	/// Returns the resource id value of the element.
-	/// If @a type is NULL then the string element is assumed to already contain extension.
-	ResourceId to_resource_id(const char* type) const;
+	ResourceId to_resource_id() const;
 
 	/// Returns the array value of the element.
 	/// @note
@@ -179,6 +177,9 @@ public:
 	/// Reads the JSON document from file @a f.
 	JSONParser(File& f);
 
+	typedef Array<char> Buffer;
+	JSONParser(Buffer& b);
+
 	~JSONParser();
 
 	/// Returns the root element of the JSON document.

+ 37 - 3
src/core/json/njson.cpp

@@ -53,7 +53,7 @@ namespace njson
 			case '"': json = skip_string(json); break;
 			case '[': json = skip_block(json, '[', ']'); break;
 			case '{': json = skip_block(json, '{', '}'); break;
-			default: for (; *json != ',' && *json != '\n' && *json != ' ' && *json != '}' && *json != ']'; ++json) ; break;
+			default: for (; *json != '\0' && *json != ',' && *json != '\n' && *json != ' ' && *json != '}' && *json != ']'; ++json) ; break;
 		}
 
 		return json;
@@ -149,7 +149,6 @@ namespace njson
 	static const char* parse_key(const char* json, DynamicString& key)
 	{
 		CE_ASSERT_NOT_NULL(json);
-
 		if (*json == '"')
 		{
 			parse_string(json, key);
@@ -159,7 +158,8 @@ namespace njson
 		{
 			while (true)
 			{
-				if (isspace(*json) || *json == '=') return json;
+				if (isspace(*json) || *json == '=')
+					return json;
 
 				key += *json;
 				++json;
@@ -167,6 +167,7 @@ namespace njson
 		}
 
 		CE_FATAL("Bad key");
+		return NULL;
 	}
 
 	double parse_number(const char* json)
@@ -294,6 +295,29 @@ namespace njson
 		CE_FATAL("Bad array");
 	}
 
+	void parse_root_object(const char* json, Map<DynamicString, const char*>& object)
+	{
+		CE_ASSERT_NOT_NULL(json);
+
+		json = skip_spaces(json);
+
+		while (*json)
+		{
+			DynamicString key;
+			json = parse_key(json, key);
+
+			json = skip_spaces(json);
+			json = next(json, '=');
+			json = skip_spaces(json);
+
+			map::set(object, key, json);
+
+			const char* tmp = json;
+			json = skip_value(json);
+			json = skip_spaces(json);
+		}
+	}
+
 	void parse_object(const char* json, Map<DynamicString, const char*>& object)
 	{
 		CE_ASSERT_NOT_NULL(json);
@@ -336,5 +360,15 @@ namespace njson
 
 		CE_FATAL("Bad object");
 	}
+
+	void parse(const char* json, Map<DynamicString, const char*>& object)
+	{
+		CE_ASSERT_NOT_NULL(json);
+
+		if (*json == '{')
+			parse_object(json, object);
+		else
+			parse_root_object(json, object);
+	}
 } // namespace njson
 } // namespace crown

+ 3 - 0
src/core/json/njson.h

@@ -59,5 +59,8 @@ namespace njson
 	/// Parses the NJSON object @a json and puts it into @a object as map from
 	/// key to pointer to the corresponding value into the original string @a json.
 	void parse_object(const char* json, Map<DynamicString, const char*>& object);
+
+	/// Parses the NJSON-encoded @a json.
+	void parse(const char* json, Map<DynamicString, const char*>& object);
 } // namespace njson
 } // namespace crown

+ 13 - 0
src/core/string_id.cpp

@@ -6,6 +6,7 @@
 #include "types.h"
 #include "murmur.h"
 #include "string_utils.h"
+#include <inttypes.h>
 
 namespace crown
 {
@@ -20,6 +21,12 @@ StringId32::StringId32(const char* str, uint32_t len)
 {
 }
 
+const char* StringId32::to_string(char* buf)
+{
+	snprintf(buf, STRING_LENGTH, "%.8x", _id);
+	return buf;
+}
+
 StringId64::StringId64(const char* str)
 	: _id(murmur64(str, strlen(str)))
 {
@@ -30,4 +37,10 @@ StringId64::StringId64(const char* str, uint32_t len)
 {
 }
 
+const char* StringId64::to_string(char* buf)
+{
+	snprintf(buf, STRING_LENGTH, "%.16" PRIx64, _id);
+	return buf;
+}
+
 } // namespace crown

+ 1 - 1
src/core/strings/string_utils.h

@@ -84,7 +84,7 @@ inline const char* skip_block(const char* str, char a, char b)
 {
 	uint32_t num = 0;
 
-	for (char ch = *str++; *str != '\0'; ch = *str++)
+	for (char ch = *str++; ch != '\0'; ch = *str++)
 	{
 		if (ch == a) ++num;
 		else if (ch == b)

+ 8 - 0
src/core/types.h

@@ -26,6 +26,9 @@ struct StringId32
 	bool operator!=(StringId32 a) const { return _id != a._id; }
 	bool operator<(StringId32 a) const { return _id < a._id; }
 	uint32_t id() const { return _id; }
+	const char* to_string(char* buf);
+
+	static const uint32_t STRING_LENGTH = 32;
 };
 
 struct StringId64
@@ -41,8 +44,13 @@ struct StringId64
 	bool operator!=(StringId64 a) const { return _id != a._id; }
 	bool operator<(StringId64 a) const { return _id < a._id; }
 	uint64_t id() const { return _id; }
+	const char* to_string(char* buf);
+
+	static const uint32_t STRING_LENGTH = 32;
 };
 
+typedef StringId64 ResourceId;
+
 #define INVALID_ID 65535
 
 struct Id

+ 8 - 3
src/crown.cpp

@@ -79,7 +79,6 @@ static void help(const char* msg = NULL)
 		"          windows\n"
 		"          android\n"
 		"  --continue                 Continue the execution after the resource compilation step.\n"
-		"  --host                     Read resources from a remote engine instance.\n"
 		"  --wait-console             Wait for a console connection before starting up.\n"
 	);
 }
@@ -138,6 +137,12 @@ void parse_command_line(int argc, char** argv, ConfigSettings& cs)
 	{
 		cs.parent_window = parse_uint(parent);
 	}
+
+	const char* port = cmd.get_parameter("console-port");
+	if (port)
+	{
+		cs.console_port = parse_uint(port);
+	}
 }
 
 void parse_config_file(Filesystem& fs, ConfigSettings& cs)
@@ -175,8 +180,8 @@ void parse_config_file(Filesystem& fs, ConfigSettings& cs)
 		cs.window_height = max((uint16_t)1, (uint16_t)window_height.to_int());
 	}
 
-	cs.boot_script = root.key("boot_script").to_resource_id("lua").name;
-	cs.boot_package = root.key("boot_package").to_resource_id("package").name;
+	cs.boot_script = root.key("boot_script").to_resource_id();
+	cs.boot_package = root.key("boot_package").to_resource_id();
 }
 
 bool init(Filesystem& fs, const ConfigSettings& cs)

+ 1 - 1
src/crown.h

@@ -33,7 +33,7 @@ namespace crown
 			, do_compile(false)
 			, do_continue(false)
 			, parent_window(0)
-			, console_port(10001)
+			, console_port(CROWN_DEFAULT_CONSOLE_PORT)
 			, boot_package(uint64_t(0))
 			, boot_script(uint64_t(0))
 			, window_width(CROWN_DEFAULT_WINDOW_WIDTH)

+ 4 - 10
src/device.cpp

@@ -82,7 +82,7 @@ void Device::shutdown()
 	_lua_environment->call_global("shutdown", 0);
 
 	_boot_package->unload();
-	destroy_resource_package(_boot_package);
+	destroy_resource_package(*_boot_package);
 
 	CE_DELETE(_allocator, _lua_environment);
 
@@ -193,23 +193,17 @@ void Device::destroy_world(World& w)
 	CE_ASSERT(false, "Bad world");
 }
 
-ResourcePackage* Device::create_resource_package(const char* name)
-{
-	ResourceId resid("package", name);
-	return create_resource_package((StringId64) resid.name);
-}
-
 ResourcePackage* Device::create_resource_package(StringId64 id)
 {
 	return CE_NEW(default_allocator(), ResourcePackage)(id, *_resource_manager);
 }
 
-void Device::destroy_resource_package(ResourcePackage* package)
+void Device::destroy_resource_package(ResourcePackage& package)
 {
-	CE_DELETE(default_allocator(), package);
+	CE_DELETE(default_allocator(), &package);
 }
 
-void Device::reload(const char* , const char* )
+void Device::reload(StringId64 type, StringId64 name)
 {
 }
 

+ 16 - 14
src/device.h

@@ -30,7 +30,7 @@ struct Device
 
 	void init();
 
-	/// Shutdowns the engine freeing all the allocated resources
+	/// Shutdowns the engine freeing all the allocated resources.
 	void shutdown();
 
 	/// Returns a string identifying what platform the engine is running on.
@@ -46,23 +46,22 @@ struct Device
 	/// the simulation).
 	bool is_running() const;
 
-	/// Return the number of frames rendered from the first
-	/// call to Device::start()
+	/// Return the number of frames rendered.
 	uint64_t frame_count() const;
 
-	/// Returns the time in seconds needed to render the last frame
+	/// Returns the time in seconds needed to render the last frame.
 	float last_delta_time() const;
 
-	/// Returns the time in seconds since the first call to start().
+	/// Returns the time in seconds since the the application started.
 	double time_since_start() const;
 
 	/// Quits the application.
 	void quit();
 
-	/// Pauses the engine
+	/// Pauses the engine.
 	void pause();
 
-	/// Unpauses the engine
+	/// Unpauses the engine.
 	void unpause();
 
 	void update_resolution(uint16_t width, uint16_t height)
@@ -78,31 +77,34 @@ struct Device
 		height = _height;
 	}
 
-	/// Updates all the subsystems
+	/// Updates all the subsystems.
 	void update();
 
-	/// Renders the given @a world from the point of view of the given @a camera.
+	/// Renders the given @a world from the point of view of @a camera.
 	void render_world(World* world, Camera* camera);
 
 	/// Creates a new world.
 	World* create_world();
 
-	/// Destroys the given @a world.
+	/// Destroys the world @a w.
 	void destroy_world(World& w);
 
-	/// Returns the resource package with the given @a package_name name.
-	ResourcePackage* create_resource_package(const char* name);
+	/// Returns the resource package @a id.
 	ResourcePackage* create_resource_package(StringId64 id);
 
 	/// Destroy a previously created resource @a package.
 	/// @note
 	/// To unload the resources loaded by the package, you have to call
 	/// ResourcePackage::unload() first.
-	void destroy_resource_package(ResourcePackage* package);
+	void destroy_resource_package(ResourcePackage& package);
 
-	void reload(const char* type, const char* name);
+	/// Reloads the resource @a type @a name.
+	void reload(StringId64 type, StringId64 name);
 
+	/// Returns the resource manager.
 	ResourceManager* resource_manager();
+
+	/// Returns the lua environment.
 	LuaEnvironment* lua_environment();
 
 private:

+ 2 - 2
src/lua/lua_device.cpp

@@ -85,14 +85,14 @@ static int device_render_world(lua_State* L)
 static int device_create_resource_package(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.push_resource_package(device()->create_resource_package(stack.get_string(1)));
+	stack.push_resource_package(device()->create_resource_package(stack.get_resource_id(1)));
 	return 1;
 }
 
 static int device_destroy_resource_package(lua_State* L)
 {
 	LuaStack stack(L);
-	device()->destroy_resource_package(stack.get_resource_package(1));
+	device()->destroy_resource_package(*stack.get_resource_package(1));
 	return 0;
 }
 

+ 1 - 1
src/lua/lua_world.cpp

@@ -190,7 +190,7 @@ static int world_create_debug_line(lua_State* L)
 static int world_destroy_debug_line(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.get_world(1)->destroy_debug_line(stack.get_debug_line(2));
+	stack.get_world(1)->destroy_debug_line(*stack.get_debug_line(2));
 	return 0;
 }
 

+ 1 - 2
src/renderers/gui.cpp

@@ -93,8 +93,7 @@ Gui::Gui(uint16_t width, uint16_t height, const char* material)
 {
 	set_orthographic(m_projection, 0, width, 0, height, -0.01f, 100.0f);
 
-	ResourceId id("material", material);
-	m_material = material_manager::get()->create_material(id.name);
+	m_material = material_manager::get()->create_material(ResourceId(material));
 }
 
 const GuiId Gui::id() const

+ 1 - 1
src/renderers/shader.cpp

@@ -42,7 +42,7 @@ namespace shader_resource
 	void compile(const char* path, CompileOptions& opts)
 	{
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		DynamicString vs_code2;

+ 1 - 1
src/resource/font_resource.cpp

@@ -31,7 +31,7 @@ namespace font_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		Array<FontGlyphData> m_glyphs(default_allocator());

+ 3 - 8
src/resource/level_resource.cpp

@@ -112,11 +112,6 @@ template <> inline BinaryReader& operator&(BinaryReader& br, StringId64& id)
 	return br & id._id;
 }
 
-template <> inline BinaryReader& operator&(BinaryReader& br, ResourceId& id)
-{
-	return br & id.type & id.name;
-}
-
 template <> inline BinaryWriter& operator&(BinaryWriter& bw, Vector3& v)
 {
 	return bw & v.x & v.y & v.z;
@@ -183,7 +178,7 @@ namespace level_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		Array<LevelUnit> units(default_allocator());
@@ -196,7 +191,7 @@ namespace level_resource
 			{
 				JSONElement e = sounds_arr[i];
 				LevelSound ls;
-				ls.name = e.key("name").to_resource_id("sound").name;
+				ls.name = e.key("name").to_resource_id();
 				ls.position = e.key("position").to_vector3();
 				ls.volume = e.key("volume").to_float();
 				ls.range = e.key("range").to_float();
@@ -212,7 +207,7 @@ namespace level_resource
 			{
 				JSONElement e = units_arr[i];
 				LevelUnit lu;
-				lu.name = e.key("name").to_resource_id("unit").name;
+				lu.name = e.key("name").to_resource_id();
 				lu.position = e.key("position").to_vector3();
 				lu.rotation = e.key("rotation").to_quaternion();
 				array::push_back(units, lu);

+ 5 - 5
src/resource/material_resource.cpp

@@ -54,11 +54,11 @@ namespace material_resource
 			th.sampler_handle = 0;
 			th.texture_handle = 0;
 
-			ResourceId texid = root.key("textures").key(keys[i].c_str()).to_resource_id("texture");
+			ResourceId texid = root.key("textures").key(keys[i].c_str()).to_resource_id();
 
 			TextureData td;
 			td.sampler_name_offset = array::size(names); array::push(names, keys[i].c_str(), keys[i].length()); array::push_back(names, '\0');
-			td.id = texid.name;
+			td.id = texid;
 			td.data_offset = reserve_dynamic_data(th, dynamic);
 
 			array::push_back(textures, td);
@@ -150,7 +150,7 @@ namespace material_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		Array<TextureData> texdata(default_allocator());
@@ -158,13 +158,13 @@ namespace material_resource
 		Array<char> names(default_allocator());
 		Array<char> dynblob(default_allocator());
 
-		ResourceId shader = root.key("shader").to_resource_id("shader");
+		ResourceId shader = root.key("shader").to_resource_id();
 		parse_textures(root, texdata, names, dynblob);
 		parse_uniforms(root, unidata, names, dynblob);
 
 		MaterialResource mr;
 		mr.version = VERSION;
-		mr.shader = shader.name;
+		mr.shader = shader;
 		mr.num_textures = array::size(texdata);
 		mr.texture_data_offset = sizeof(mr);
 		mr.num_uniforms = array::size(unidata);

+ 1 - 1
src/resource/mesh_resource.cpp

@@ -36,7 +36,7 @@ namespace mesh_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		// Read data arrays

+ 14 - 14
src/resource/package_resource.cpp

@@ -20,7 +20,7 @@ namespace package_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		JSONElement texture  = root.key_or_nil("texture");
@@ -107,43 +107,43 @@ namespace package_resource
 
 		// Write resource ids
 		for (uint32_t i = 0; i < num_textures; i++)
-			opts.write(texture[i].to_resource_id("texture").name);
+			opts.write(texture[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_scripts; i++)
-			opts.write(script[i].to_resource_id("lua").name);
+			opts.write(script[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_sounds; i++)
-			opts.write(sound[i].to_resource_id("sound").name);
+			opts.write(sound[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_meshes; i++)
-			opts.write(mesh[i].to_resource_id("mesh").name);
+			opts.write(mesh[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_units; i++)
-			opts.write(unit[i].to_resource_id("unit").name);
+			opts.write(unit[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_sprites; i++)
-			opts.write(sprite[i].to_resource_id("sprite").name);
+			opts.write(sprite[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_physics; i++)
-			opts.write(physics[i].to_resource_id("physics").name);
+			opts.write(physics[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_materials; i++)
-			opts.write(material[i].to_resource_id("material").name);
+			opts.write(material[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_fonts; i++)
-			opts.write(font[i].to_resource_id("font").name);
+			opts.write(font[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_levels; i++)
-			opts.write(level[i].to_resource_id("level").name);
+			opts.write(level[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_phyconfs; i++)
-			opts.write(phyconf[i].to_resource_id("physics_config").name);
+			opts.write(phyconf[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_shaders; i++)
-			opts.write(shader[i].to_resource_id("shader").name);
+			opts.write(shader[i].to_resource_id());
 
 		for (uint32_t i = 0; i < num_sprite_animations; i++)
-			opts.write(sprite_animation[i].to_resource_id("sprite_animation").name);
+			opts.write(sprite_animation[i].to_resource_id());
 	}
 
 	void* load(File& file, Allocator& a)

+ 2 - 2
src/resource/physics_resource.cpp

@@ -224,7 +224,7 @@ namespace physics_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		bool m_has_controller = false;
@@ -576,7 +576,7 @@ namespace physics_config_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		typedef Map<DynamicString, uint32_t> FilterMap;

+ 0 - 1
src/resource/physics_resource.h

@@ -10,7 +10,6 @@
 #include "filesystem_types.h"
 #include "math_types.h"
 #include "compiler_types.h"
-#include "resource_id.h"
 
 namespace crown
 {

+ 0 - 58
src/resource/resource_id.h

@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "string_utils.h"
-#include "murmur.h"
-#include "path.h"
-#include <inttypes.h>
-
-namespace crown
-{
-
-struct ResourceId
-{
-	ResourceId()
-		: type(uint64_t(0))
-		, name(uint64_t(0))
-	{
-	}
-
-	ResourceId(StringId64 type, StringId64 name)
-		: type(type)
-		, name(name)
-	{
-	}
-
-	ResourceId(const char* type, const char* name)
-		: type(murmur64(type, strlen(type), 0))
-		, name(murmur64(name, strlen(name), SEED))
-	{
-	}
-
-	const char* to_string(char out[64])
-	{
-		snprintf(out, 64, "%.16" PRIx64 "-%.16" PRIx64, type.id(), name.id());
-		return out;
-	}
-
-	bool operator==(const ResourceId& a) const
-	{
-		return type == a.type && name == a.name;
-	}
-
-	bool operator<(const ResourceId& a) const
-	{
-		return type < a.type || (type == a.type && name < a.name);
-	}
-
-	static const uint64_t SEED = 0;
-
-	StringId64 type;
-	StringId64 name;
-};
-
-} // namespace crown

+ 11 - 8
src/resource/resource_loader.cpp

@@ -30,9 +30,9 @@ ResourceLoader::~ResourceLoader()
 	_thread.stop();
 }
 
-void ResourceLoader::load(ResourceId id)
+void ResourceLoader::load(StringId64 type, StringId64 name)
 {
-	add_request(id);
+	add_request(type, name);
 }
 
 void ResourceLoader::flush()
@@ -40,10 +40,10 @@ void ResourceLoader::flush()
 	while (num_requests()) {}
 }
 
-void ResourceLoader::add_request(ResourceId id)
+void ResourceLoader::add_request(StringId64 type, StringId64 name)
 {
 	ScopedMutex sm(_mutex);
-	queue::push_back(_requests, id);
+	queue::push_back(_requests, make_request(type, name));
 }
 
 uint32_t ResourceLoader::num_requests()
@@ -79,14 +79,17 @@ int32_t ResourceLoader::run()
 			_mutex.unlock();
 			continue;
 		}
-		ResourceId id = queue::front(_requests);
+		ResourceRequest id = queue::front(_requests);
 		_mutex.unlock();
 
 		ResourceData rd;
-		rd.id = id;
+		rd.type = id.type;
+		rd.name = id.name;
 
-		char name[64];
-		id.to_string(name);
+		char name[1 + 2*StringId64::STRING_LENGTH];
+		id.type.to_string(name);
+		name[16] = '-';
+		id.name.to_string(name + 17);
 
 		TempAllocator256 alloc;
 		DynamicString path(alloc);

+ 17 - 5
src/resource/resource_loader.h

@@ -11,14 +11,14 @@
 #include "container_types.h"
 #include "mutex.h"
 #include "memory_types.h"
-#include "resource_id.h"
 
 namespace crown
 {
 
 struct ResourceData
 {
-	ResourceId id;
+	StringId64 type;
+	StringId64 name;
 	void* data;
 };
 
@@ -35,7 +35,7 @@ public:
 	~ResourceLoader();
 
 	/// Loads the @a resource in a background thread.
-	void load(ResourceId id);
+	void load(StringId64 type, StringId64 name);
 
 	/// Blocks until all pending requests have been processed.
 	void flush();
@@ -44,7 +44,7 @@ public:
 
 private:
 
-	void add_request(ResourceId id);
+	void add_request(StringId64 type, StringId64 name);
 	uint32_t num_requests();
 	void add_loaded(ResourceData data);
 
@@ -59,11 +59,23 @@ private:
 
 private:
 
+	struct ResourceRequest
+	{
+		StringId64 type;
+		StringId64 name;
+	};
+
+	ResourceRequest make_request(StringId64 type, StringId64 name)
+	{
+		ResourceRequest request = { type, name };
+		return request;
+	}
+
 	Thread _thread;
 	Filesystem& _fs;
 	Allocator& _resource_heap;
 
-	Queue<ResourceId> _requests;
+	Queue<ResourceRequest> _requests;
 	Queue<ResourceData> _loaded;
 	Mutex _mutex;
 	Mutex _loaded_mutex;

+ 16 - 13
src/resource/resource_manager.cpp

@@ -7,6 +7,7 @@
 #include "resource_registry.h"
 #include "temp_allocator.h"
 #include "sort_map.h"
+#include "array.h"
 
 namespace crown
 {
@@ -35,12 +36,12 @@ ResourceManager::~ResourceManager()
 
 void ResourceManager::load(StringId64 type, StringId64 name)
 {
-	ResourceId id(type, name);
+	ResourcePair id = make_pair(type, name);
 	ResourceEntry& entry = sort_map::get(_rm, id, ResourceEntry::NOT_FOUND);
 
 	if (entry == ResourceEntry::NOT_FOUND)
 	{
-		_loader.load(id);
+		_loader.load(type, name);
 		return;
 	}
 
@@ -51,7 +52,7 @@ void ResourceManager::unload(StringId64 type, StringId64 name)
 {
 	flush();
 
-	ResourceId id(type, name);
+	ResourcePair id = make_pair(type, name);
 	ResourceEntry& entry = sort_map::get(_rm, id, ResourceEntry::NOT_FOUND);
 
 	if (--entry.references == 0)
@@ -66,7 +67,7 @@ void ResourceManager::unload(StringId64 type, StringId64 name)
 
 void ResourceManager::reload(StringId64 type, StringId64 name)
 {
-	const ResourceId id(type, name);
+	const ResourcePair id = make_pair(type, name);
 	const ResourceEntry& entry = sort_map::get(_rm, id, ResourceEntry::NOT_FOUND);
 	const uint32_t old_refs = entry.references;
 
@@ -80,16 +81,18 @@ void ResourceManager::reload(StringId64 type, StringId64 name)
 
 bool ResourceManager::can_get(StringId64 type, StringId64 name)
 {
-	return _autoload ? true : sort_map::has(_rm, ResourceId(type, name));
+	return _autoload ? true : sort_map::has(_rm, make_pair(type, name));
 }
 
 const void* ResourceManager::get(StringId64 type, StringId64 name)
 {
-	ResourceId id(type, name);
+	const ResourcePair id = make_pair(type, name);
+	char type_buf[StringId64::STRING_LENGTH];
+	char name_buf[StringId64::STRING_LENGTH];
 
-	char buf[64];
-	CE_ASSERT(can_get(type, name), "Resource not loaded #ID(%s)", id.to_string(buf));
-	CE_UNUSED(buf);
+	CE_ASSERT(can_get(type, name), "Resource not loaded #ID(%s-%s)", type.to_string(type_buf), name.to_string(name_buf));
+	CE_UNUSED(type_buf);
+	CE_UNUSED(name_buf);
 
 	if (_autoload && !sort_map::has(_rm, id))
 	{
@@ -119,19 +122,19 @@ void ResourceManager::complete_requests()
 	_loader.get_loaded(loaded);
 
 	for (uint32_t i = 0; i < array::size(loaded); i++)
-		complete_request(loaded[i].id, loaded[i].data);
+		complete_request(loaded[i].type, loaded[i].name, loaded[i].data);
 }
 
-void ResourceManager::complete_request(ResourceId id, void* data)
+void ResourceManager::complete_request(StringId64 type, StringId64 name, void* data)
 {
 	ResourceEntry entry;
 	entry.references = 1;
 	entry.data = data;
 
-	sort_map::set(_rm, id, entry);
+	sort_map::set(_rm, make_pair(type, name), entry);
 	sort_map::sort(_rm);
 
-	resource_on_online(id.type, id.name, *this);
+	resource_on_online(type, name, *this);
 }
 
 } // namespace crown

+ 19 - 3
src/resource/resource_manager.h

@@ -54,10 +54,27 @@ public:
 
 private:
 
-	void complete_request(ResourceId id, void* data);
+	void complete_request(StringId64 type, StringId64 name, void* data);
 
 private:
 
+	struct ResourcePair
+	{
+		StringId64 type;
+		StringId64 name;
+
+		bool operator<(const ResourcePair& a) const
+		{
+			return type < a.type || (type == a.type && name < a.name);
+		}
+	};
+
+	ResourcePair make_pair(StringId64 type, StringId64 name)
+	{
+		ResourcePair pair = { type, name };
+		return pair;
+	}
+
 	struct ResourceEntry
 	{
 		bool operator==(const ResourceEntry& e)
@@ -71,13 +88,12 @@ private:
 		static const ResourceEntry NOT_FOUND;
 	};
 
-	typedef SortMap<ResourceId, ResourceEntry> ResourceMap;
+	typedef SortMap<ResourcePair, ResourceEntry> ResourceMap;
 
 	ProxyAllocator _resource_heap;
 	ResourceLoader _loader;
 	ResourceMap _rm;
 	bool _autoload;
-
 };
 
 } // namespace crown

+ 5 - 4
src/resource/resource_registry.cpp

@@ -4,6 +4,7 @@
  */
 
 #include "resource_registry.h"
+#include "error.h"
 #include "lua_resource.h"
 #include "texture_resource.h"
 #include "mesh_resource.h"
@@ -100,14 +101,14 @@ void resource_on_unload(StringId64 type, Allocator& allocator, void* resource)
 	return find_callback(type)->on_unload(allocator, resource);
 }
 
-void resource_on_online(StringId64 type, StringId64 id, ResourceManager& rm)
+void resource_on_online(StringId64 type, StringId64 name, ResourceManager& rm)
 {
-	return find_callback(type)->on_online(id, rm);
+	return find_callback(type)->on_online(name, rm);
 }
 
-void resource_on_offline(StringId64 type, StringId64 id, ResourceManager& rm)
+void resource_on_offline(StringId64 type, StringId64 name, ResourceManager& rm)
 {
-	return find_callback(type)->on_offline(id, rm);
+	return find_callback(type)->on_offline(name, rm);
 }
 
 } // namespace crown

+ 2 - 2
src/resource/resource_registry.h

@@ -16,8 +16,8 @@ namespace crown
 
 void resource_on_compile(StringId64 type, const char* path, CompileOptions& opts);
 void* resource_on_load(StringId64 type, File& file, Allocator& a);
-void resource_on_online(StringId64 type, StringId64 id, ResourceManager& rm);
-void resource_on_offline(StringId64 type, StringId64 id, ResourceManager& rm);
+void resource_on_online(StringId64 type, StringId64 name, ResourceManager& rm);
+void resource_on_offline(StringId64 type, StringId64 name, ResourceManager& rm);
 void resource_on_unload(StringId64 type, Allocator& allocator, void* resource);
 
 } // namespace crown

+ 1 - 1
src/resource/sound_resource.cpp

@@ -35,7 +35,7 @@ namespace sound_resource
 		const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		DynamicString name;

+ 2 - 2
src/resource/sprite_resource.cpp

@@ -46,7 +46,7 @@ namespace sprite_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		// Read width/height
@@ -201,7 +201,7 @@ namespace sprite_animation_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		Array<SpriteAnimationName> anim_names(default_allocator());

+ 1 - 1
src/resource/texture_resource.cpp

@@ -561,7 +561,7 @@ namespace texture_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		DynamicString name;

+ 9 - 9
src/resource/unit_resource.cpp

@@ -210,12 +210,12 @@ namespace unit_resource
 			if (res_type == "mesh")
 			{
 				rn.type = UnitRenderable::MESH;
-				rn.resource = renderable.key("resource").to_resource_id("mesh").name;
+				rn.resource = renderable.key("resource").to_resource_id();
 			}
 			else if (res_type == "sprite")
 			{
 				rn.type = UnitRenderable::SPRITE;
-				rn.resource = renderable.key("resource").to_resource_id("sprite").name;
+				rn.resource = renderable.key("resource").to_resource_id();
 			}
 			else
 			{
@@ -230,9 +230,9 @@ namespace unit_resource
 	{
 		for (uint32_t i = 0; i < e.size(); i++)
 		{
-			ResourceId mat_id = e[i].to_resource_id("material");
+			ResourceId mat_id = e[i].to_resource_id();
 			UnitMaterial um;
-			um.id = mat_id.name;
+			um.id = mat_id;
 			array::push_back(materials, um);
 		}
 	}
@@ -242,7 +242,7 @@ namespace unit_resource
 		static const uint32_t VERSION = 1;
 
 		Buffer buf = opts.read(path);
-		JSONParser json(array::begin(buf));
+		JSONParser json(buf);
 		JSONElement root = json.root();
 
 		ResourceId				m_physics_resource;
@@ -273,7 +273,7 @@ namespace unit_resource
 		physics_name += ".physics";
 		if (opts._fs.exists(physics_name.c_str()))
 		{
-			m_physics_resource = ResourceId("physics", unit_name.c_str());
+			m_physics_resource = ResourceId(unit_name.c_str());
 		}
 		else
 		{
@@ -282,13 +282,13 @@ namespace unit_resource
 
 		ResourceId sprite_anim;
 		if (root.has_key("sprite_animation"))
-			sprite_anim = root.key("sprite_animation").to_resource_id("sprite_animation");
+			sprite_anim = root.key("sprite_animation").to_resource_id();
 
 		UnitResource ur;
 		ur.version = VERSION;
 		ur.name = StringId64(unit_name.c_str());
-		ur.physics_resource = m_physics_resource.name;
-		ur.sprite_animation = sprite_anim.name;
+		ur.physics_resource = m_physics_resource;
+		ur.sprite_animation = sprite_anim;
 		ur.num_renderables = array::size(m_renderables);
 		ur.num_materials = array::size(m_materials);
 		ur.num_cameras = array::size(m_cameras);

+ 3 - 3
src/world/world.cpp

@@ -49,7 +49,7 @@ World::~World()
 		CE_DELETE(m_unit_pool, m_units[i]);
 	}
 
-	destroy_debug_line(_lines);
+	destroy_debug_line(*_lines);
 	SoundWorld::destroy(default_allocator(), _sound_world);
 	CE_DELETE(default_allocator(), _physics_world);
 	CE_DELETE(default_allocator(), _render_world);
@@ -233,9 +233,9 @@ DebugLine* World::create_debug_line(bool depth_test)
 	return CE_NEW(default_allocator(), DebugLine)(depth_test);
 }
 
-void World::destroy_debug_line(DebugLine* line)
+void World::destroy_debug_line(DebugLine& line)
 {
-	CE_DELETE(default_allocator(), line);
+	CE_DELETE(default_allocator(), &line);
 }
 
 void World::load_level(const LevelResource* lr)

+ 1 - 1
src/world/world.h

@@ -123,7 +123,7 @@ public:
 	DebugLine* create_debug_line(bool depth_test);
 
 	/// Destroys the debug @a line.
-	void destroy_debug_line(DebugLine* line);
+	void destroy_debug_line(DebugLine& line);
 
 	/// Loads the level @a name into the world.
 	void load_level(const LevelResource* lr);