Selaa lähdekoodia

Merge branch 'master' into world

Conflicts:
	engine/lua/LuaStack.h
Daniele Bartolini 12 vuotta sitten
vanhempi
sitoutus
684e754dbb
51 muutettua tiedostoa jossa 796 lisäystä ja 627 poistoa
  1. 2 7
      CMakeLists.txt
  2. 1 0
      engine/Android.mk
  3. 11 1
      engine/CMakeLists.txt
  4. 71 71
      engine/ConsoleServer.cpp
  5. 32 32
      engine/ConsoleServer.h
  6. 1 0
      engine/Crown.h
  7. 26 40
      engine/Device.cpp
  8. 0 5
      engine/Device.h
  9. 9 0
      engine/core/mem/ProxyAllocator.cpp
  10. 6 3
      engine/core/mem/ProxyAllocator.h
  11. 2 3
      engine/lua/LuaFloatSetting.cpp
  12. 2 3
      engine/lua/LuaIntSetting.cpp
  13. 8 2
      engine/lua/LuaStack.cpp
  14. 2 1
      engine/lua/LuaStack.h
  15. 4 5
      engine/lua/LuaStringSetting.cpp
  16. 1 2
      engine/lua/LuaWindow.cpp
  17. 0 3
      engine/os/posix/Cond.cpp
  18. 6 3
      engine/os/posix/Cond.h
  19. 0 4
      engine/os/posix/Mutex.cpp
  20. 6 3
      engine/os/posix/Mutex.h
  21. 59 13
      engine/os/posix/Thread.cpp
  22. 48 7
      engine/os/posix/Thread.h
  23. 4 4
      engine/os/win/Cond.cpp
  24. 10 8
      engine/os/win/Cond.h
  25. 0 3
      engine/os/win/Mutex.cpp
  26. 5 3
      engine/os/win/Mutex.h
  27. 1 1
      engine/resource/FontResource.cpp
  28. 2 2
      engine/resource/FontResource.h
  29. 1 1
      engine/resource/MaterialResource.cpp
  30. 4 4
      engine/resource/MaterialResource.h
  31. 1 1
      engine/resource/MeshResource.cpp
  32. 2 2
      engine/resource/MeshResource.h
  33. 24 12
      engine/resource/Resource.h
  34. 102 0
      engine/resource/ResourceLoader.cpp
  35. 90 0
      engine/resource/ResourceLoader.h
  36. 56 260
      engine/resource/ResourceManager.cpp
  37. 29 90
      engine/resource/ResourceManager.h
  38. 101 0
      engine/resource/ResourceRegistry.cpp
  39. 39 0
      engine/resource/ResourceRegistry.h
  40. 1 1
      engine/resource/SoundResource.cpp
  41. 2 2
      engine/resource/SoundResource.h
  42. 1 1
      engine/resource/TextureResource.cpp
  43. 2 2
      engine/resource/TextureResource.h
  44. 0 2
      engine/tests/CMakeLists.txt
  45. 0 0
      engine/tests/allocators.cpp
  46. 1 1
      engine/tests/compressors.cpp
  47. 0 0
      engine/tests/containers.cpp
  48. 0 0
      engine/tests/messages.cpp
  49. 0 0
      engine/tests/paths.cpp
  50. 0 0
      engine/tests/strings.cpp
  51. 21 19
      samples/CMakeLists.txt

+ 2 - 7
CMakeLists.txt

@@ -8,7 +8,7 @@ set (CROWN_VERSION_MICRO 9)
 
 option (CROWN_BUILD_SAMPLES "Whether to build the samples" ON)
 option (CROWN_BUILD_TOOLS "Whether to build the tools" ON)
-option (CROWN_BUILD_TESTS "Whether to build unit tests" OFF)
+option (CROWN_BUILD_TESTS "Whether to build unit tests" ON)
 
 # always debug mode for now
 set (CROWN_DEBUG 1)
@@ -29,12 +29,7 @@ add_subdirectory(engine)
 if (CROWN_BUILD_TOOLS)
 	add_subdirectory(tools)
 endif (CROWN_BUILD_TOOLS)
+
 if (CROWN_BUILD_SAMPLES)
 	add_subdirectory(samples)
 endif (CROWN_BUILD_SAMPLES)
-
-if (CROWN_BUILD_TESTS)
-	add_subdirectory(tests)
-endif (CROWN_BUILD_TESTS)
-
-

+ 1 - 0
engine/Android.mk

@@ -89,6 +89,7 @@ LOCAL_SRC_FILES :=\
 	resource/FontResource.cpp\
 	resource/MaterialResource.cpp\
 	resource/PixelShaderResource.cpp\
+	resource/ResourceLoader.cpp\
 	resource/ResourceManager.cpp\
 	resource/TextResource.cpp\
 	resource/TextureResource.cpp\

+ 11 - 1
engine/CMakeLists.txt

@@ -270,7 +270,9 @@ set (RENDERERS_HEADERS
 
 set (RESOURCE_SRC
 	resource/MaterialResource.cpp
+	resource/ResourceLoader.cpp
 	resource/ResourceManager.cpp
+	resource/ResourceRegistry.cpp
 	resource/TextureResource.cpp
 	resource/MeshResource.cpp
 	resource/FontResource.cpp
@@ -282,7 +284,9 @@ set (RESOURCE_SRC
 set (RESOURCE_HEADERS
 	resource/MaterialResource.h
 	resource/Resource.h
+	resource/ResourceLoader.h
 	resource/ResourceManager.h
+	resource/ResourceRegistry.h
 	resource/Bundle.h
 	resource/TextureResource.h
 	resource/MeshResource.h
@@ -391,7 +395,7 @@ if (LINUX)
 		-g
 		-pg
 		-fPIC
-		-fvisibility=hidden
+		#-fvisibility=hidden
 	)
 
 	set (CROWN_EXECUTABLE_NAME crown-linux)
@@ -489,6 +493,8 @@ set (CROWN_HEADERS
 
 	${RESOURCE_HEADERS}
 
+	${RPC_HEADERS}
+
 #	${NETWORK_HEADERS}
 
 	${OS_HEADERS}
@@ -510,6 +516,10 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN")
 add_executable(${CROWN_EXECUTABLE_NAME} ${CROWN_MAIN_SRC})
 target_link_libraries(${CROWN_EXECUTABLE_NAME} crown)
 
+if (CROWN_BUILD_TESTS)
+	add_subdirectory(tests)
+endif (CROWN_BUILD_TESTS)
+
 install (TARGETS crown DESTINATION bin)
 install (TARGETS ${CROWN_EXECUTABLE_NAME} DESTINATION bin)
 

+ 71 - 71
engine/ConsoleServer.cpp

@@ -38,93 +38,93 @@ namespace crown
 
 static IntSetting g_port("read_port", "port used for reading", 10000, 9999, 65535);
 
-//-----------------------------------------------------------------------------
-ConsoleServer::ConsoleServer() :
-	m_thread(ConsoleServer::background_thread, (void*)this, "console-thread"),
-	m_active(false)
-{
-	string::strncpy(m_cmd_buffer, "", 1024);
-	string::strncpy(m_err_buffer, "", 1024);
-}
-
-//-----------------------------------------------------------------------------
-void ConsoleServer::init()
-{
-	m_active = true;
-}
-
-//-----------------------------------------------------------------------------
-void ConsoleServer::shutdown()
-{
-	m_active = false;
-
-	m_socket.close();
-}
-
-//-----------------------------------------------------------------------------
-void ConsoleServer::read_eval_loop()
-{
-	m_socket.open(g_port);
+// //-----------------------------------------------------------------------------
+// ConsoleServer::ConsoleServer() :
+// 	m_thread("console-thread"),
+// 	m_active(false)
+// {
+// 	// string::strncpy(m_cmd_buffer, "", 1024);
+// 	// string::strncpy(m_err_buffer, "", 1024);
+// }
+
+// //-----------------------------------------------------------------------------
+// void ConsoleServer::init()
+// {
+// 	// m_active = true;
+// }
+
+// //-----------------------------------------------------------------------------
+// void ConsoleServer::shutdown()
+// {
+// 	// m_active = false;
+
+// 	// m_socket.close();
+// }
+
+// //-----------------------------------------------------------------------------
+// void ConsoleServer::read_eval_loop()
+// {
+// 	// m_socket.open(g_port);
 	
-	char cmd[1024];
+// 	// char cmd[1024];
 
-	while (m_active)
-	{
-		string::strncpy(cmd, "", 1024);
-		receive((char*)cmd, 1024);
+// 	// while (m_active)
+// 	// {
+// 	// 	string::strncpy(cmd, "", 1024);
+// 	// 	receive((char*)cmd, 1024);
 
-		// Fill command buffer
-		string::strncpy(m_cmd_buffer, cmd, 1024);
-	}
+// 	// 	// Fill command buffer
+// 	// 	string::strncpy(m_cmd_buffer, cmd, 1024);
+// 	// }
 
-	Log::i("End read-eval loop");
-	m_socket.close();
-}
+// 	// Log::i("End read-eval loop");
+// 	// m_socket.close();
+// }
 
-//-----------------------------------------------------------------------------
-void ConsoleServer::execute()
-{
-	m_command_mutex.lock();
+// //-----------------------------------------------------------------------------
+// void ConsoleServer::execute()
+// {
+// 	// m_command_mutex.lock();
 
-	LuaEnvironment* lua = device()->lua_environment();
+// 	// LuaEnvironment* lua = device()->lua_environment();
 
-	lua->load_buffer(m_cmd_buffer, string::strlen(m_cmd_buffer));
-	lua->execute(0, 0);
+// 	// lua->load_buffer(m_cmd_buffer, string::strlen(m_cmd_buffer));
+// 	// lua->execute(0, 0);
 
-	string::strncpy(m_cmd_buffer, "", 1024);
+// 	// string::strncpy(m_cmd_buffer, "", 1024);
 
-	string::strncpy(m_err_buffer, lua->error(),  1024);
+// 	// string::strncpy(m_err_buffer, lua->error(),  1024);
 
-	if (string::strcmp(m_err_buffer, "") != 0)
-	{
-		// Fill error buffer
-		send((char*)m_err_buffer, 1024);
-	}
+// 	// if (string::strcmp(m_err_buffer, "") != 0)
+// 	// {
+// 	// 	// Fill error buffer
+// 	// 	send((char*)m_err_buffer, 1024);
+// 	// }
 
-	string::strncpy(m_err_buffer, "", 1024);
+// 	// string::strncpy(m_err_buffer, "", 1024);
 
-	m_command_mutex.unlock();
-}
+// 	// m_command_mutex.unlock();
+// }
 
-//-----------------------------------------------------------------------------
-void ConsoleServer::send(const void* data, size_t size)
-{
-	m_socket.send(data, size);
-}
+// //-----------------------------------------------------------------------------
+// void ConsoleServer::send(const void* data, size_t size)
+// {
+// 	// m_socket.send(data, size);
+// }
 
-//-----------------------------------------------------------------------------
-void ConsoleServer::receive(char* data, size_t size)
-{
-	m_socket.receive(data, size);
-}
+// //-----------------------------------------------------------------------------
+// void ConsoleServer::receive(char* data, size_t size)
+// {
+// 	// m_socket.receive(data, size);
+// }
 
-//-----------------------------------------------------------------------------
-void* ConsoleServer::background_thread(void* thiz)
-{
-	((ConsoleServer*)thiz)->read_eval_loop();
+// //-----------------------------------------------------------------------------
+// void* ConsoleServer::background_thread(void* thiz)
+// {
+// 	// ((ConsoleServer*)thiz)->read_eval_loop();
 
-	return NULL;
-}
+// 	// return NULL;
+// }
 
 
 } // namespace crown

+ 32 - 32
engine/ConsoleServer.h

@@ -38,38 +38,38 @@ class ConsoleServer
 {
 public:
 
-	/// Constructor
-							ConsoleServer();
-	/// Start listening on @port
-	void					init();
-	/// Stop listening
-	void					shutdown();
-	/// Read-evaluation loop, executed on a different thread
-	void					read_eval_loop();
-	/// Execute commands, executed on main thread
-	void					execute();
-	/// Send data to client
-	void					send(const void* data, size_t size = 1024);
-	/// Receive data to client
-	void					receive(char* data, size_t size = 1024);
-
-private:
-
-	static void*			background_thread(void* thiz);
-
-private:
-
-	os::TCPSocket			m_socket;
-
-	os::Thread				m_thread;
-	os::Mutex				m_command_mutex;
-
-	// Is console active?
-	bool					m_active;
-	// Commands buffer
-	char					m_cmd_buffer[1024];
-
-	char 					m_err_buffer[1024];
+// 	/// Constructor
+// 							ConsoleServer();
+// 	/// Start listening on @port
+// 	void					init();
+// 	/// Stop listening
+// 	void					shutdown();
+// 	/// Read-evaluation loop, executed on a different thread
+// 	void					read_eval_loop();
+// 	/// Execute commands, executed on main thread
+// 	void					execute();
+// 	/// Send data to client
+// 	void					send(const void* data, size_t size = 1024);
+// 	/// Receive data to client
+// 	void					receive(char* data, size_t size = 1024);
+
+// private:
+
+// 	static void*			background_thread(void* thiz);
+
+// private:
+
+// 	os::TCPSocket			m_socket;
+
+// 	Thread					m_thread;
+// 	Mutex					m_command_mutex;
+
+// 	// Is console active?
+// 	bool					m_active;
+// 	// Commands buffer
+// 	char					m_cmd_buffer[1024];
+
+// 	char 					m_err_buffer[1024];
 
 };
 

+ 1 - 0
engine/Crown.h

@@ -135,6 +135,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Bundle.h"
 #include "ArchiveBundle.h"
 #include "FileBundle.h"
+#include "ResourceLoader.h"
 #include "ResourceManager.h"
 #include "TextureResource.h"
 #include "MeshResource.h"

+ 26 - 40
engine/Device.cpp

@@ -51,6 +51,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Memory.h"
 #include "LuaEnvironment.h"
 #include "ConsoleServer.h"
+#include "TextReader.h"
 
 namespace crown
 {
@@ -162,7 +163,7 @@ void Device::shutdown()
 	Log::i("Releasing ConsoleServer...");
 	if (m_console_server)
 	{
-		m_console_server->shutdown();
+		//m_console_server->shutdown();
 
 		CE_DELETE(m_allocator, m_console_server);
 	}
@@ -350,15 +351,14 @@ void Device::frame()
 	m_last_delta_time = (m_current_time - m_last_time) / 1000000.0f;
 	m_last_time = m_current_time;
 
-	m_resource_manager->check_load_queue();
-	m_resource_manager->bring_loaded_online();
+	m_resource_manager->poll_resource_loader();
 
 	m_window->frame();
 	m_input_manager->frame(frame_count());
 
 	m_lua_environment->game_frame(last_delta_time());
 
-	m_console_server->execute();
+	//m_console_server->execute();
 
 	m_debug_renderer->draw_all();
 	m_renderer->frame();
@@ -366,36 +366,12 @@ void Device::frame()
 	m_frame_count++;
 }
 
-//-----------------------------------------------------------------------------
-ResourceId Device::load(const char* name)
-{
-	return m_resource_manager->load(name);
-}
-
-//-----------------------------------------------------------------------------
-void Device::unload(ResourceId name)
-{
-	m_resource_manager->unload(name);
-}
-
 //-----------------------------------------------------------------------------
 void Device::reload(ResourceId name)
 {
 	(void)name;
 }
 
-//-----------------------------------------------------------------------------
-bool Device::is_loaded(ResourceId name)
-{
-	return m_resource_manager->is_loaded(name);
-}
-
-//-----------------------------------------------------------------------------
-const void* Device::data(ResourceId name)
-{
-	return m_resource_manager->data(name);
-}
-
 //-----------------------------------------------------------------------------
 void Device::create_filesystem()
 {
@@ -418,8 +394,19 @@ void Device::create_resource_manager()
 		m_resource_bundle = CE_NEW(m_allocator, ArchiveBundle)(*m_filesystem);
 	}
 
+	// Read resource seed
+	DiskFile* seed_file = filesystem()->open("seed.ini", FOM_READ);
+	TextReader reader(*seed_file);
+
+	char tmp_buf[32];
+	reader.read_string(tmp_buf, 32);
+
+	filesystem()->close(seed_file);
+
+	uint32_t seed = string::parse_uint(tmp_buf);
+
 	// Create resource manager
-	m_resource_manager = CE_NEW(m_allocator, ResourceManager)(*m_resource_bundle);
+	m_resource_manager = CE_NEW(m_allocator, ResourceManager)(*m_resource_bundle, seed);
 
 	Log::d("Resource manager created.");
 	Log::d("Resource seed: %d", m_resource_manager->seed());
@@ -477,9 +464,9 @@ void Device::create_lua_environment()
 
 void Device::create_console_server()
 {
-	m_console_server = CE_NEW(m_allocator, ConsoleServer)();
+	m_console_server = NULL;//CE_NEW(m_allocator, ConsoleServer)();
 
-	m_console_server->init();
+	//m_console_server->init();
 
 	Log::d("Console server created.");
 }
@@ -489,15 +476,14 @@ void Device::parse_command_line(int argc, char** argv)
 {
 	static ArgsOption options[] = 
 	{
-
-		"help",             AOA_NO_ARGUMENT,       NULL,        'i',
-		"root-path",        AOA_REQUIRED_ARGUMENT, NULL,        'r',
-		"width",            AOA_REQUIRED_ARGUMENT, NULL,        'w',
-		"height",           AOA_REQUIRED_ARGUMENT, NULL,        'h',
-		"fullscreen",       AOA_NO_ARGUMENT,       &m_preferred_window_fullscreen, 1,
-		"dev",              AOA_NO_ARGUMENT,       &m_preferred_mode, MODE_DEVELOPMENT,
-		"quit-after-init",  AOA_NO_ARGUMENT,       &m_quit_after_init, 1,
-		NULL, 0, NULL, 0
+		{ "help",             AOA_NO_ARGUMENT,       NULL,        'i' },
+		{ "root-path",        AOA_REQUIRED_ARGUMENT, NULL,        'r' },
+		{ "width",            AOA_REQUIRED_ARGUMENT, NULL,        'w' },
+		{ "height",           AOA_REQUIRED_ARGUMENT, NULL,        'h' },
+		{ "fullscreen",       AOA_NO_ARGUMENT,       &m_preferred_window_fullscreen, 1 },
+		{ "dev",              AOA_NO_ARGUMENT,       &m_preferred_mode, MODE_DEVELOPMENT },
+		{ "quit-after-init",  AOA_NO_ARGUMENT,       &m_quit_after_init, 1 },
+		{ NULL, 0, NULL, 0 }
 	};
 
 	Args args(argc, argv, "", options);

+ 0 - 5
engine/Device.h

@@ -93,12 +93,7 @@ public:
 	/// Updates all the subsystems
 	void					frame();
 
-	/// Loads a resource and returns its unique identifier.
-	ResourceId				load(const char* name);
-	void					unload(ResourceId name);
 	void					reload(ResourceId name);
-	bool					is_loaded(ResourceId name);
-	const void*				data(ResourceId name);
 
 	Filesystem*				filesystem();
 	ResourceManager*		resource_manager();

+ 9 - 0
engine/core/mem/ProxyAllocator.cpp

@@ -38,6 +38,7 @@ static ProxyAllocator* g_proxy_allocators_head = NULL;
 ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
 	m_allocator(allocator),
 	m_name(name),
+	m_total_allocated(0),
 	m_next(NULL)
 {
 	CE_ASSERT(name != NULL, "Name must be != NULL");
@@ -53,6 +54,8 @@ ProxyAllocator::ProxyAllocator(const char* name, Allocator& allocator) :
 //-----------------------------------------------------------------------------
 void* ProxyAllocator::allocate(size_t size, size_t align)
 {
+	m_total_allocated += size;
+
 	return m_allocator.allocate(size, align);
 }
 
@@ -62,6 +65,12 @@ void ProxyAllocator::deallocate(void* data)
 	m_allocator.deallocate(data);
 }
 
+//-----------------------------------------------------------------------------
+size_t ProxyAllocator::allocated_size()
+{
+	return m_total_allocated;
+}
+
 //-----------------------------------------------------------------------------
 const char* ProxyAllocator::name() const
 {

+ 6 - 3
engine/core/mem/ProxyAllocator.h

@@ -28,16 +28,15 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Memory.h"
+#include "Allocator.h"
 
 namespace crown
 {
 
-class Allocator;
-
 /// Offers the facility to tag allocators by a string identifier.
 /// Proxy allocator is appended to a global linked list when instantiated
 /// so that it is possible to later visit that list for debugging purposes.
-class ProxyAllocator
+class ProxyAllocator : public Allocator
 {
 public:
 
@@ -50,6 +49,9 @@ public:
 	/// @copydoc Allocator::deallocate()
 	void					deallocate(void* data);
 
+	/// @copydoc Allocator::allocated_size()
+	size_t					allocated_size();
+
 	/// Returns the name of the proxy allocator
 	const char*				name() const;
 
@@ -74,6 +76,7 @@ private:
 
 	Allocator&				m_allocator;
 	const char*				m_name;
+	size_t					m_total_allocated;
 
 	ProxyAllocator*			m_next;
 };

+ 2 - 3
engine/lua/LuaFloatSetting.cpp

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "FloatSetting.h"
 #include "LuaStack.h"
 #include "LuaEnvironment.h"
-#include "StringUtils.h"
 
 namespace crown
 {
@@ -64,11 +63,11 @@ CE_EXPORT int float_setting_synopsis(lua_State* L)
 
 	if (setting != NULL)
 	{
-		stack.push_string(setting->synopsis(), string::strlen(setting->synopsis()));
+		stack.push_string(setting->synopsis());
 	}
 	else
 	{
-		stack.push_string("", string::strlen(""));
+		stack.push_string("");
 	}
 
 	return 1;

+ 2 - 3
engine/lua/LuaIntSetting.cpp

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "IntSetting.h"
 #include "LuaStack.h"
 #include "LuaEnvironment.h"
-#include "StringUtils.h"
 
 namespace crown
 {
@@ -64,11 +63,11 @@ CE_EXPORT int int_setting_query_synopsis(lua_State* L)
 
 	if (setting != NULL)
 	{
-		stack.push_string(setting->synopsis(), string::strlen(setting->synopsis()));
+		stack.push_string(setting->synopsis());
 	}
 	else
 	{
-		stack.push_string("", string::strlen(""));
+		stack.push_string("");
 	}
 
 	return 1;

+ 8 - 2
engine/lua/LuaStack.cpp

@@ -138,9 +138,15 @@ void LuaStack::push_float(float value)
 }
 
 //-----------------------------------------------------------------------------
-void LuaStack::push_string(const char* str, size_t len)
+void LuaStack::push_string(const char* s)
 {
-	lua_pushlstring(m_state, str, len);
+	lua_pushstring(m_state, s);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_literal(const char* s, size_t len)
+{
+	lua_pushlstring(m_state, s, len);
 }
 
 //-----------------------------------------------------------------------------

+ 2 - 1
engine/lua/LuaStack.h

@@ -57,7 +57,8 @@ public:
 	void					push_int64(int64_t value);
 	void					push_uint64(uint64_t value);
 	void 					push_float(float value);
-	void 					push_string(const char* str, size_t len);
+	void 					push_string(const char* s);
+	void					push_literal(const char* s, size_t len);
 	void					push_lightdata(void* data);
 
 	void					push_vec2(const Vec2& v);

+ 4 - 5
engine/lua/LuaStringSetting.cpp

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "StringSetting.h"
 #include "LuaStack.h"
 #include "LuaEnvironment.h"
-#include "StringUtils.h"
 
 namespace crown
 {
@@ -43,11 +42,11 @@ CE_EXPORT int string_setting_value(lua_State* L)
 
 	if (setting != NULL)
 	{
-		stack.push_string(setting->value(), string::strlen(setting->value()));
+		stack.push_string(setting->value());
 	}
 	else
 	{
-		stack.push_string("", string::strlen(""));
+		stack.push_string("");
 	}
 
 	return 1;
@@ -64,11 +63,11 @@ CE_EXPORT int string_setting_synopsis(lua_State* L)
 
 	if (setting != NULL)
 	{
-		stack.push_string(setting->synopsis(), string::strlen(setting->synopsis()));
+		stack.push_string(setting->synopsis());
 	}
 	else
 	{
-		stack.push_string("", string::strlen(""));
+		stack.push_string("");
 	}
 
 	return 1;

+ 1 - 2
engine/lua/LuaWindow.cpp

@@ -28,7 +28,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "OsWindow.h"
 #include "LuaStack.h"
 #include "LuaEnvironment.h"
-#include "StringUtils.h"
 
 namespace crown
 {
@@ -164,7 +163,7 @@ CE_EXPORT int window_title(lua_State* L)
 
 	const char* title = device()->window()->title();
 
-	stack.push_string(title, string::strlen(title));
+	stack.push_string(title);
 
 	return 1;
 }

+ 0 - 3
engine/os/posix/Cond.cpp

@@ -30,8 +30,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 //-----------------------------------------------------------------------------
 Cond::Cond()
@@ -59,5 +57,4 @@ void Cond::wait(Mutex& mutex)
 	pthread_cond_wait(&m_cond, &(mutex.m_mutex));
 }
 
-} // namespace os
 } // namespace crown

+ 6 - 3
engine/os/posix/Cond.h

@@ -34,8 +34,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 class Cond
 {
@@ -50,7 +48,12 @@ public:
 private:
 
 	pthread_cond_t	m_cond;
+
+private:
+
+	// Disable copying.
+					Cond(const Cond&);
+	Cond&			operator=(const Cond&);
 };
 
-} // namespace os
 } // namespace crown

+ 0 - 4
engine/os/posix/Mutex.cpp

@@ -30,8 +30,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 //-----------------------------------------------------------------------------
 Mutex::Mutex()
@@ -59,6 +57,4 @@ void Mutex::unlock()
 	pthread_mutex_unlock(&m_mutex);
 }
 
-} // namespace os
 } // namespace crown
-

+ 6 - 3
engine/os/posix/Mutex.h

@@ -33,8 +33,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 class Mutex
 {
@@ -50,8 +48,13 @@ private:
 
 	pthread_mutex_t		m_mutex;
 
+private:
+
+	// Disable copying.
+						Mutex(const Mutex&);
+	Mutex&				operator=(const Mutex&);
+
 	friend class		Cond;
 };
 
-} // namespace os
 } // namespace crown

+ 59 - 13
engine/os/posix/Thread.cpp

@@ -28,17 +28,36 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <string.h>
 
 #include "Thread.h"
+#include "Assert.h"
 
 namespace crown
 {
-namespace os
-{
 
 //-----------------------------------------------------------------------------
-Thread::Thread(os::ThreadFunction f, void* params, const char* name) :
-	m_name(name)
+Thread::Thread(const char* name) :
+	m_name(name),
+	m_is_running(false),
+	m_is_terminating(false),
+	m_thread(0)
 {
 	memset(&m_thread, 0, sizeof(pthread_t));
+}
+
+//-----------------------------------------------------------------------------
+Thread::~Thread()
+{
+}
+
+//-----------------------------------------------------------------------------
+const char* Thread::name() const
+{
+	return m_name;
+}
+
+//-----------------------------------------------------------------------------
+void Thread::start()
+{
+	m_is_terminating = false;
 
 	// Make thread joinable
 	pthread_attr_t attr;
@@ -46,21 +65,49 @@ Thread::Thread(os::ThreadFunction f, void* params, const char* name) :
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 
 	// Create thread
-	int rc = pthread_create(&m_thread, &attr, f, (void*)params);
-
-	if (rc != 0)
-	{
-		os::printf("Unable to create the thread '%s' Error code: %d\n", name, rc);
-		exit(-1);
-	}
+	int rc = pthread_create(&m_thread, &attr, Thread::background_proc, (void*) this);
+	CE_ASSERT(rc == 0, "Failed to create the thread '%s': errno: %d", m_name, rc);
 
 	// Free attr memory
 	pthread_attr_destroy(&attr);
+
+	m_is_running = true;
 }
 
 //-----------------------------------------------------------------------------
-Thread::~Thread()
+bool Thread::is_running() const
+{
+	return m_is_running;
+}
+
+//-----------------------------------------------------------------------------
+bool Thread::is_terminating() const
+{
+	return m_is_terminating;
+}
+
+//-----------------------------------------------------------------------------
+void Thread::stop()
+{
+	m_is_terminating = true;
+}
+
+//-----------------------------------------------------------------------------
+int32_t Thread::run()
 {
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+void* Thread::background_proc(void* thiz)
+{
+	Thread* thread = ((Thread*) thiz);
+
+	thread->run();
+
+	thread->m_is_running = false;
+
+	return NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -75,5 +122,4 @@ void Thread::detach()
 	pthread_detach(m_thread);
 }
 
-} // namespace os
 } // namespace crown

+ 48 - 7
engine/os/posix/Thread.h

@@ -29,12 +29,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <pthread.h>
 
 #include "Types.h"
-#include "OS.h"
 
 namespace crown
 {
-namespace os
-{
 
 typedef void* (*ThreadFunction)(void*);
 
@@ -42,17 +39,61 @@ class Thread
 {
 public:
 
-					Thread(os::ThreadFunction f, void* params, const char* name);
-					~Thread();
+	/// Constructs the thread and gives it a @a name.
+	/// @note
+	/// The actual OS thread creation and execution is
+	/// deferred to the first call to Thread::start().
+					Thread(const char* name);
+
+	/// Does not stop the thread. The user must call
+	/// Thread::stop() to effectively stop the thread. 
+	virtual			~Thread();
+
+	/// Returns the name of the thread.
+	const char*		name() const;
 
 	void			join();
 	void			detach();
 
+	/// Returns whether the thread is currently running.
+	bool			is_running() const;
+
+	/// Returns whether the thread is being asked to stop running.
+	/// @note
+	/// The implementer tipically polls this function to
+	/// determine whether to stop the execution or not.
+	bool			is_terminating() const;
+
+	/// Starts the execution of the thread.
+	/// The function creates the OS thread and starts
+	/// its execution.
+	void			start();
+
+	/// Stops the execution of the thread if it is running.
+	/// The function releases the OS thread causing its
+	/// termination.
+	void			stop();
+
+	/// Executes in background when the thead is running.
+	/// The thread has to be started with Thread::start()
+	virtual int32_t	run();
+
+private:
+
+	static void*	background_proc(void* thiz);
+
 private:
 
-	pthread_t		m_thread;
 	const char*		m_name;
+	bool			m_is_running;
+	bool			m_is_terminating;
+	pthread_t		m_thread;
+
+private:
+
+	// Disable copying
+					Thread(const Thread&);
+	Thread&			operator=(const Thread&);
 };
 
-} // namespace os
 } // namespace crown

+ 4 - 4
engine/os/win/Cond.cpp

@@ -28,28 +28,28 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
+//-----------------------------------------------------------------------------
 Cond::Cond()
 {
 	InitializeConditionVariable(&m_cond);
 }
 
+//-----------------------------------------------------------------------------
 Cond::~Cond()
 {
-	
 }
 
+//-----------------------------------------------------------------------------
 void Cond::signal()
 {
 	WakeConditionVariable(&m_cond);
 }
 
+//-----------------------------------------------------------------------------
 void Cond::wait(Mutex& mutex)
 {
 	SleepConditionVariableCS(&m_cond, &mutex.m_cs, INFINITE);
 }
 
-} // namespace os
 } // namespace crown

+ 10 - 8
engine/os/win/Cond.h

@@ -33,23 +33,25 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 class Cond
 {
 public:
 
-							Cond();
-							~Cond();
+						Cond();
+						~Cond();
+
+	void				signal();
+	void				wait(Mutex& mutex);
+
+private:
 
-	void					signal();
-	void					wait(Mutex& mutex);
+						Cond(const Cond&);
+	Cond&				operator=(const Cond&);
 
 private:
 
-	CONDITION_VARIABLE		m_cond;
+	CONDITION_VARIABLE	m_cond;
 };
 
-} // namespace os
 } // namespace crown

+ 0 - 3
engine/os/win/Mutex.cpp

@@ -29,8 +29,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 //-----------------------------------------------------------------------------
 Mutex::Mutex()
@@ -56,5 +54,4 @@ void Mutex::unlock()
     LeaveCriticalSection(&m_cs);
 }
 
-} // namespace os
 } // namespace crown

+ 5 - 3
engine/os/win/Mutex.h

@@ -32,8 +32,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-namespace os
-{
 
 class Mutex
 {
@@ -49,8 +47,12 @@ private:
 
 	CRITICAL_SECTION	m_cs;
 
+private:
+
+						Mutex(const Mutex&);
+	Mutex&				operator=(const Mutex&);
+
 	friend class		Cond;
 };
 
-} // namespace os
 } // namespace crown

+ 1 - 1
engine/resource/FontResource.cpp

@@ -49,7 +49,7 @@ void FontResource::unload(Allocator& /*allocator*/, void* /*resource*/)
 }
 
 //-----------------------------------------------------------------------------
-void FontResource::offline()
+void FontResource::offline(void* /*resource*/)
 {
 }
 

+ 2 - 2
engine/resource/FontResource.h

@@ -40,9 +40,9 @@ class FontResource
 public:
 
 	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			online(void* resource);
 	static void			unload(Allocator& allocator, void* resource);
-	static void			offline();
+	static void			online(void* resource);
+	static void			offline(void* resource);
 
 public:
 

+ 1 - 1
engine/resource/MaterialResource.cpp

@@ -51,7 +51,7 @@ void MaterialResource::unload(Allocator& /*allocator*/, void* /*material*/)
 }
 
 //-----------------------------------------------------------------------------
-void MaterialResource::offline()
+void MaterialResource::offline(void* /*resource*/)
 {
 	// TODO
 }

+ 4 - 4
engine/resource/MaterialResource.h

@@ -51,10 +51,10 @@ class MaterialResource
 {
 public:
 
-	static void*	load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void		online(void* resource);
-	static void		unload(Allocator& allocator, void* texture);
-	static void		offline();
+	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
+	static void			unload(Allocator& allocator, void* resource);
+	static void			online(void* resource);
+	static void			offline(void* resource);
 
 private:
 

+ 1 - 1
engine/resource/MeshResource.cpp

@@ -72,7 +72,7 @@ void MeshResource::unload(Allocator& , void* )
 }
 
 //-----------------------------------------------------------------------------
-void MeshResource::offline()
+void MeshResource::offline(void* /*resource*/)
 {
 
 }

+ 2 - 2
engine/resource/MeshResource.h

@@ -53,9 +53,9 @@ class MeshResource
 public:
 
 	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			online(void* resource);
 	static void			unload(Allocator& allocator, void* resource);
-	static void			offline();
+	static void			online(void* resource);
+	static void			offline(void* resource);
 
 public:
 

+ 24 - 12
engine/resource/Resource.h

@@ -48,13 +48,12 @@ const uint32_t TEXT_TYPE					= 0x9000BF0B;
 const uint32_t MATERIAL_TYPE				= 0x46807A92;
 const uint32_t SOUND_TYPE					= 0x8E128AA1;
 
-
 /// Enumerates the loading states of a resource
 enum ResourceState
 {
-	RS_UNLOADED		= 0,		//< The resource is not loaded, so it cannot be used
-	RS_LOADING		= 1,		//< The resource loader started to load the resource but it is yet not ready to use
-	RS_LOADED		= 2			//< The resource loader finished to load the texture meaning it can be used
+	RS_UNLOADED		= 0,		// The resource is not loaded, so it cannot be used
+	RS_LOADING		= 1,		// The resource loader started to load the resource but it is yet not ready to use
+	RS_LOADED		= 2			// The resource loader finished to load the texture meaning it can be used
 };
 
 /// ResourceId uniquely identifies a resource by its name and type.
@@ -62,14 +61,27 @@ enum ResourceState
 /// the index to the resource list where it is stored.
 struct ResourceId
 {
-	uint32_t		name;		// Hashed resource name
-	uint32_t		type;		// Hashed resource type
-	uint32_t		index;		// Index into the ResourceManager internal list
-
-	bool			operator==(const ResourceId& b)
-	{
-		return name == b.name && type == b.type && index == b.index;
-	}
+	bool operator==(const ResourceId& b) const { return name == b.name && type == b.type; }
+
+	uint32_t		name;
+	uint32_t		type;
+};
+
+class Allocator;
+class Bundle;
+
+typedef void*	(*ResourceLoadCallback)(Allocator& a, Bundle& b, ResourceId id);
+typedef void	(*ResourceUnloadCallback)(Allocator& a, void* resource);
+typedef void	(*ResourceOnlineCallback)(void* resource);
+typedef void	(*ResourceOfflineCallback)(void* resource);
+
+struct ResourceCallback
+{
+	uint32_t					type;
+	ResourceLoadCallback		on_load;
+	ResourceUnloadCallback		on_unload;
+	ResourceOnlineCallback		on_online;
+	ResourceOfflineCallback		on_offline;
 };
 
 } // namespace crown

+ 102 - 0
engine/resource/ResourceLoader.cpp

@@ -0,0 +1,102 @@
+/*
+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.
+*/
+
+#include "ResourceLoader.h"
+#include "ResourceRegistry.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+ResourceLoader::ResourceLoader(Bundle& bundle, Allocator& resource_heap) :
+	Thread("resource-loader"),
+	m_bundle(bundle),
+	m_resource_heap(resource_heap),
+	m_load_queue(default_allocator()),
+	m_done_queue(default_allocator())
+{
+}
+
+//-----------------------------------------------------------------------------
+void ResourceLoader::load(ResourceId resource)
+{
+	m_load_mutex.lock();
+	m_load_queue.push_back(resource);
+	m_load_requests.signal();
+	m_load_mutex.unlock();
+}
+
+//-----------------------------------------------------------------------------
+uint32_t ResourceLoader::remaining() const
+{
+	return m_load_queue.size();
+}
+
+//-----------------------------------------------------------------------------
+uint32_t ResourceLoader::num_loaded() const
+{
+	return m_done_queue.size();
+}
+
+//-----------------------------------------------------------------------------
+void ResourceLoader::get_loaded(List<LoadedResource>& l)
+{
+	m_done_mutex.lock();
+	for (uint32_t i = 0; i < m_done_queue.size(); i++)
+	{
+		l.push_back(m_done_queue[i]);
+	}
+
+	m_done_queue.clear();
+	m_done_mutex.unlock();
+}
+
+//-----------------------------------------------------------------------------
+int32_t ResourceLoader::run()
+{
+	while (!is_terminating())
+	{
+		m_load_mutex.lock();
+		while (m_load_queue.size() == 0)
+		{
+			m_load_requests.wait(m_load_mutex);
+		}
+
+		ResourceId resource = m_load_queue.front();
+		m_load_queue.pop_front();
+		m_load_mutex.unlock();
+
+		void* data = resource_on_load(resource.type, m_resource_heap, m_bundle, resource);
+
+		m_done_mutex.lock();
+		m_done_queue.push_back(LoadedResource(resource, data));
+		m_done_mutex.unlock();
+	}
+
+	return 0;
+}
+
+} // namespace crown

+ 90 - 0
engine/resource/ResourceLoader.h

@@ -0,0 +1,90 @@
+/*
+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 "Types.h"
+#include "Resource.h"
+#include "Thread.h"
+#include "Queue.h"
+#include "List.h"
+#include "Mutex.h"
+#include "Cond.h"
+
+namespace crown
+{
+
+struct LoadedResource
+{
+	LoadedResource(ResourceId r, void* d) : resource(r), data(d) {}
+
+	ResourceId	resource;
+	void*		data;
+};
+
+class Bundle;
+class Allocator;
+
+/// Loads resources in a background thread.
+class ResourceLoader : public Thread
+{
+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);
+
+	/// Loads the @a resource in a background thread.
+	void		load(ResourceId resource);
+
+	/// Returns the number of resources still in the loading queue.
+	uint32_t	remaining() const;
+
+	/// Returns the number of resources already loaded.
+	uint32_t	num_loaded() const;
+
+	/// Returns a list of the last loaded resources.
+	void		get_loaded(List<LoadedResource>& l);
+
+	// Loads resources in the loading queue.
+	int32_t		run();
+
+private:
+
+	// Whether to look for resources
+	Bundle&					m_bundle;
+
+	// Used to strore resource memory
+	Allocator&				m_resource_heap;
+
+	Queue<ResourceId>		m_load_queue;
+	List<LoadedResource>	m_done_queue;
+	Mutex					m_load_mutex;
+	Mutex					m_done_mutex;
+	Cond					m_load_requests;
+};
+
+} // namespace crown

+ 56 - 260
engine/resource/ResourceManager.cpp

@@ -25,143 +25,71 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include <algorithm>
-#include <cstdio>
 
 #include "Types.h"
 #include "ResourceManager.h"
+#include "ResourceRegistry.h"
 #include "StringUtils.h"
 #include "Hash.h"
-#include "Path.h"
-#include "Log.h"
-#include "Device.h"
-#include "Filesystem.h"
-#include "TextReader.h"
-#include "DiskFile.h"
-#include "TextureResource.h"
-#include "MeshResource.h"
-#include "SoundResource.h"
+#include "TempAllocator.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-ResourceManager::ResourceManager(Bundle& bundle) :
-	m_resource_bundle(bundle),
-	m_resources(m_allocator),
-	m_loading_queue(m_allocator),
-	m_loaded_queue(m_allocator),
-	m_seed(0),
-	m_background_thread_should_run(true),
-	m_thread(ResourceManager::background_thread, (void*)this, "resource-loader-thread")
+ResourceManager::ResourceManager(Bundle& bundle, uint32_t seed) :
+	m_resource_heap("resource", default_allocator()),
+	m_loader(bundle, m_resource_heap),
+	m_seed(seed),
+	m_resources(default_allocator())
 {
-	DiskFile* seed_file = device()->filesystem()->open("seed.ini", FOM_READ);
-	TextReader reader(*seed_file);
-
-	char tmp_buf[32];
-	reader.read_string(tmp_buf, 32);
-
-	device()->filesystem()->close(seed_file);
-
-	sscanf(tmp_buf, "%u", &m_seed);
+	m_loader.start();
 }
 
 //-----------------------------------------------------------------------------
 ResourceManager::~ResourceManager()
 {
-	m_background_thread_should_run = false;
+	m_loader.stop();
 }
 
 //-----------------------------------------------------------------------------
-ResourceId ResourceManager::load(const char* name)
+ResourceId ResourceManager::load(const char* type, const char* name)
 {
-	char basename[512];
-	char extension[512];
-
-	path::filename_without_extension(name, basename, 512);
-	path::extension(name, extension, 512);
-
-	uint32_t name_hash = hash::murmur2_32(basename, string::strlen(basename), m_seed);
-	uint32_t type_hash = hash::murmur2_32(extension, string::strlen(extension), 0);
-
-	return load(name_hash, type_hash);
+	return load(resource_id(type, name));
 }
 
 //-----------------------------------------------------------------------------
 void ResourceManager::unload(ResourceId name)
 {
 	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
-	
-	m_resources_mutex.lock();
 
-	ResourceEntry& entry = m_resources[name.index];
+	ResourceEntry* entry = find(name);
 	
-	entry.references--;
+	entry->references--;
 	
-	if (entry.references == 0 && entry.state == RS_LOADED)
+	if (entry->references == 0 && entry->state == RS_LOADED)
 	{
-		unload_by_type(name, entry.resource);
-
-		entry.state = RS_UNLOADED;
-		entry.resource = NULL;
-
+		resource_on_unload(name.type, m_resource_heap, entry->resource);
 
+		entry->state = RS_UNLOADED;
+		entry->resource = NULL;
 	}
-
-	m_resources_mutex.unlock();
-}
-
-//-----------------------------------------------------------------------------
-void ResourceManager::reload(ResourceId name)
-{
-	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
-	
-	m_resources_mutex.lock();
-
-	ResourceEntry& entry = m_resources[name.index];
-	
-	if (entry.state == RS_LOADED)
-	{
-		unload_by_type(name, entry.resource);
-
-		entry.state = RS_UNLOADED;
-		entry.resource = NULL;
-
-		entry.resource = load_by_type(name);
-		entry.state = RS_LOADED;
-	}
-
-	m_resources_mutex.unlock();
 }
 
 //-----------------------------------------------------------------------------
 bool ResourceManager::has(ResourceId name) const
 {
-	bool has_resource = false;
-
-	m_resources_mutex.lock();
+	ResourceEntry* entry = find(name);
 
-	if (m_resources.size() > name.index)
-	{
-		 has_resource = (m_resources[name.index].id.name == name.name);
-	}
-
-	m_resources_mutex.unlock();
-	
-	return has_resource;
+	return entry != NULL;
 }
 
 //-----------------------------------------------------------------------------
 const void* ResourceManager::data(ResourceId name) const
 {
 	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
-	
-	m_resources_mutex.lock();
 
-	void* resource = m_resources[name.index].resource;
-
-	m_resources_mutex.unlock();
-
-	return resource;
+	return find(name)->resource;
 }
 
 //-----------------------------------------------------------------------------
@@ -169,13 +97,7 @@ bool ResourceManager::is_loaded(ResourceId name) const
 {
 	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 
-	m_resources_mutex.lock();
-
-	bool loaded = m_resources[name.index].state == RS_LOADED;
-
-	m_resources_mutex.unlock();
-
-	return loaded;
+	return find(name)->state == RS_LOADED;
 }
 
 //-----------------------------------------------------------------------------
@@ -183,50 +105,15 @@ uint32_t ResourceManager::references(ResourceId name) const
 {
 	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 
-	m_resources_mutex.lock();
-
-	bool loaded = m_resources[name.index].references;
-
-	m_resources_mutex.unlock();
-
-	return loaded;
-}
-
-//-----------------------------------------------------------------------------
-uint32_t ResourceManager::remaining() const
-{
-	uint32_t count = 0;
-
-	m_loading_mutex.lock();
-
-	count = m_loading_queue.size();
-
-	m_loading_mutex.unlock();
-
-	return count;
+	return find(name)->references;
 }
 
 //-----------------------------------------------------------------------------
 void ResourceManager::flush()
 {
-	check_load_queue();
-
-	while (true)
-	{
-		// Wait for all the resources to be loaded
-		// by the background thread
-		m_loading_mutex.lock();
-		while (m_loading_queue.size() > 0)
-		{
-			m_all_loaded.wait(m_loading_mutex);
-		}
-		m_loading_mutex.unlock();
-
-		// When all loaded, bring them online
-		bring_loaded_online();
+	while (m_loader.remaining() > 0) ;
 
-		return;
-	}
+	poll_resource_loader();
 }
 
 //-----------------------------------------------------------------------------
@@ -236,63 +123,61 @@ uint32_t ResourceManager::seed() const
 }
 
 //-----------------------------------------------------------------------------
-void ResourceManager::check_load_queue()
+ResourceId ResourceManager::resource_id(const char* type, const char* name) const
 {
-	m_loading_mutex.lock();
-
-	if (m_loading_queue.size() > 0)
-	{
-		m_loading_requests.signal();
-	}
+	ResourceId id;
+	id.type = hash::murmur2_32(type, string::strlen(type), 0);
+	id.name = hash::murmur2_32(name, string::strlen(name), m_seed);
 
-	m_loading_mutex.unlock();
+	return id;
 }
 
 //-----------------------------------------------------------------------------
-void ResourceManager::bring_loaded_online()
+ResourceEntry* ResourceManager::find(ResourceId id) const
 {
-	m_loaded_mutex.lock();
+	const ResourceEntry* entry = std::find(m_resources.begin(), m_resources.end(), id);
+
+	return entry != m_resources.end() ? const_cast<ResourceEntry*>(entry) : NULL;
+}
 
-	while (m_loaded_queue.size() > 0)
+//-----------------------------------------------------------------------------
+void ResourceManager::poll_resource_loader()
+{
+	if (m_loader.num_loaded() != 0)
 	{
-		LoadedResource lr = m_loaded_queue.front();
-		m_loaded_queue.pop_front();
+		TempAllocator1024 alloc;
+		List<LoadedResource> loaded(alloc);
+		m_loader.get_loaded(loaded);
 
-		online(lr.resource, lr.data);
+		for (uint32_t i = 0; i < loaded.size(); i++)
+		{
+			online(loaded[i].resource, loaded[i].data);
+		}
 	}
-
-	m_loaded_mutex.unlock();
 }
 
 //-----------------------------------------------------------------------------
-ResourceId ResourceManager::load(uint32_t name, uint32_t type)
+ResourceId ResourceManager::load(ResourceId name)
 {
-	ResourceId id;
-	id.name = name;
-	id.type = type;
-
 	// Search for an already existent resource
-	ResourceEntry* entry = std::find(m_resources.begin(), m_resources.end(), id);
+	ResourceEntry* entry = find(name);
 
 	// If resource not found, create a new one
-	if (entry == m_resources.end())
+	if (entry == NULL)
 	{
-		id.index = m_resources.size();
-
 		ResourceEntry entry;
 
-		entry.id = id;
+		entry.id = name;
 		entry.state = RS_UNLOADED;
 		entry.references = 1;
 		entry.resource = NULL;
 
 		m_resources.push_back(entry);
 
-		m_loading_mutex.lock();
-		m_loading_queue.push_back(id);
-		m_loading_mutex.unlock();
+		// Issue request to resource loader
+		m_loader.load(name);
 
-		return id;
+		return name;
 	}
 
 	// Else, increment its reference count
@@ -301,103 +186,14 @@ ResourceId ResourceManager::load(uint32_t name, uint32_t type)
 	return entry->id;
 }
 
-//-----------------------------------------------------------------------------
-void ResourceManager::background_load()
-{
-	while (m_background_thread_should_run)
-	{
-		m_loading_mutex.lock();
-		while (m_loading_queue.size() == 0)
-		{
-			m_loading_requests.wait(m_loading_mutex);
-		}
-
-		ResourceId resource = m_loading_queue.front();
-		m_loading_queue.pop_front();
-
-		m_loading_mutex.unlock();
-
-		void* data = load_by_type(resource);
-
-		LoadedResource lr;
-		lr.resource = resource;
-		lr.data = data;
-
-		m_loaded_mutex.lock();
-		m_loaded_queue.push_back(lr);
-		m_loaded_mutex.unlock();
-
-		m_loading_mutex.lock();
-		if (m_loading_queue.size() == 0)
-		{
-			m_all_loaded.signal();
-		}
-		m_loading_mutex.unlock();
-	}
-}
-
-//-----------------------------------------------------------------------------
-void* ResourceManager::load_by_type(ResourceId name)
-{
-	switch (name.type)
-	{
-		case TEXTURE_TYPE: return TextureResource::load(m_resource_allocator, m_resource_bundle, name);
-		case MESH_TYPE: return MeshResource::load(m_resource_allocator, m_resource_bundle, name);
-		case SOUND_TYPE: return SoundResource::load(m_resource_allocator, m_resource_bundle, name);
-		default: return NULL;
-	}
-}
-
-//-----------------------------------------------------------------------------
-void ResourceManager::unload_by_type(ResourceId name, void* resource)
-{
-	switch (name.type)
-	{
-		case TEXTURE_TYPE: return TextureResource::unload(m_resource_allocator, resource);
-		case MESH_TYPE: return MeshResource::unload(m_resource_allocator, resource);
-		case SOUND_TYPE: return SoundResource::unload(m_resource_allocator, resource);
-	}
-
-	return;
-}
-
 //-----------------------------------------------------------------------------
 void ResourceManager::online(ResourceId name, void* resource)
 {
-	switch (name.type)
-	{
-		case TEXTURE_TYPE:
-		{
-			TextureResource::online(resource);
-			break;
-		}
-		case MESH_TYPE:
-		{
-			MeshResource::online(resource);
-			break;
-		}
-		case SOUND_TYPE:
-		{
-			SoundResource::online(resource);
-			break;
-		}
-	}
-
-	m_resources_mutex.lock();
-
-	ResourceEntry& entry = m_resources[name.index];
-	entry.resource = resource;
-	entry.state = RS_LOADED;
-
-	m_resources_mutex.unlock();
-}
-
-//-----------------------------------------------------------------------------
-void* ResourceManager::background_thread(void* thiz)
-{
-	((ResourceManager*)thiz)->background_load();
+	resource_on_online(name.type, resource);
 
-	return NULL;
+	ResourceEntry* entry = find(name);
+	entry->resource = resource;
+	entry->state = RS_LOADED;
 }
 
 } // namespace crown

+ 29 - 90
engine/resource/ResourceManager.h

@@ -28,96 +28,63 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "List.h"
-#include "Queue.h"
 #include "Resource.h"
-#include "HeapAllocator.h"
-#include "Thread.h"
-#include "Mutex.h"
-#include "Cond.h"
+#include "ProxyAllocator.h"
+#include "ResourceLoader.h"
 
 namespace crown
 {
 
 struct ResourceEntry
 {
+	bool operator==(const ResourceId& resource) const { return id == resource; }
+	bool operator==(const ResourceEntry& b) const { return id == b.id; }
+
 	ResourceId		id;
 	ResourceState	state;
-
 	uint32_t		references;
-
 	void*			resource;
-
-	bool			operator==(const ResourceId& resource)
-					{
-						return id == resource;
-					}
-
-	bool			operator==(const ResourceEntry& b)
-					{
-						return id == b.id;
-					}
-};
-
-struct LoadedResource
-{
-	ResourceId	resource;
-	void*		data;
 };
 
 class Bundle;
 
-/// Resource manager.
+/// Keeps track and manages resources loaded by ResourceLoader.
 class ResourceManager
 {
 public:
 
-	/// Read resources from @a bundle and store resource data using @a allocator.
-							ResourceManager(Bundle& bundle);
+	/// The resources will be loaded from @a bundle.
+							ResourceManager(Bundle& bundle, uint32_t seed);
 							~ResourceManager();
 
-	/// Loads the resource by @a name and returns its ResourceId.
+	/// Loads the resource by @a type and @a name and returns its ResourceId.
 	/// @note
-	/// The resource data may be not immediately available,
-	/// the resource gets pushed in a queue of load requests and loadead as
-	/// soon as possible by the ResourceLoader.
-	/// You have to explicitly call is_loaded() method to check if the
-	/// loading process is actually completed.
-	ResourceId				load(const char* name);
-
-	/// Unloads the @a resource, freeing up all the memory associated by it
+	/// You have to call is_loaded() to check if the loading process is actually completed.
+	ResourceId				load(const char* type, const char* name);
+
+	/// Unloads the resource @a name, freeing up all the memory associated by it
 	/// and eventually any global object associated with it.
-	/// (Such as texture objects, vertex buffers etc.)
 	void					unload(ResourceId name);
 
-	/// Reloads the @a resource
-	void					reload(ResourceId name);
-
 	/// Returns whether the manager has the @a name resource into
 	/// its list of resources.
-	/// @note
+	/// @warning
 	/// Having a resource does not mean that the resource is
-	/// available for using; instead, you have to check is_loaded() to
-	/// obtain the resource availability status.
+	/// ready to be used; See is_loaded().
 	bool					has(ResourceId name) const;
 
 	/// Returns the data associated with the @a name resource.
-	/// The resource data contains resource-specific metadata
-	/// and the actual resource data. In order to correctly use
-	/// it, you have to know which type of data @a name refers to
-	/// and cast accordingly.
+	/// You will have to cast the returned pointer accordingly.
 	const void*				data(ResourceId name) 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;
 
-	/// Returns the number of references to the @a resource
+	/// Returns the number of references to the resource @a name;
 	uint32_t				references(ResourceId name) const;
 
-	/// Returns the number of resources still waiting to load.
-	uint32_t				remaining() const;
-
-	/// Forces all the loading requests to complete before preceeding.
+	/// Forces all of the loading requests to complete before preceeding.
 	void					flush();
 
 	/// Returns the seed used to generate resource name hashes.
@@ -125,54 +92,26 @@ public:
 
 private:
 
-	// Checks the load queue and signal the backgroud about pending
-	// requests. It is normally called only by the Device.
-	void					check_load_queue();
-	// Calls online() on loaded resources. Must be called only
-	// in the main thread and generally only by Device.
-	void					bring_loaded_online();
+	ResourceId				resource_id(const char* type, const char* name) const;
 
-	// Loads the resource by name and type and returns its ResourceId.
-	ResourceId				load(uint32_t name, uint32_t type);
+	// Returns the entry of the given id.
+	ResourceEntry*			find(ResourceId id) const;
 
-	void					background_load();
+	// Polls the resource loader for loaded resources.
+	void					poll_resource_loader();
 
-	void*					load_by_type(ResourceId name);
-	void					unload_by_type(ResourceId name, void* resource);
+	// Loads the resource by name and type and returns its ResourceId.
+	ResourceId				load(ResourceId name);
 	void					online(ResourceId name, void* resource);
 
 private:
 
-	static void*			background_thread(void* thiz);
-
-private:
-
-	// Archive whether to look for resources
-	Bundle&					m_resource_bundle;
-	// Used to strore resource memory
-	HeapAllocator			m_resource_allocator;
-
-	HeapAllocator			m_allocator;
-	// The master lookup table
-	List<ResourceEntry>		m_resources;
-
-	// Resources waiting for loading
-	Queue<ResourceId>		m_loading_queue;
-	// Resources already loaded, ready to bring online
-	Queue<LoadedResource>	m_loaded_queue;
-
+	ProxyAllocator			m_resource_heap;
+	ResourceLoader			m_loader;
 	uint32_t				m_seed;
+	List<ResourceEntry>		m_resources;
 
-	// Background loading thread
-	bool 					m_background_thread_should_run;
-	os::Thread				m_thread;
-
-	mutable os::Mutex		m_loading_mutex;
-	os::Cond 				m_loading_requests;
-	os::Cond 				m_all_loaded;
-
-	os::Mutex				m_loaded_mutex;
-	mutable os::Mutex		m_resources_mutex;
+private:
 
 	friend class			Device;
 };

+ 101 - 0
engine/resource/ResourceRegistry.cpp

@@ -0,0 +1,101 @@
+/*
+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.
+*/
+
+#include "ResourceRegistry.h"
+#include "TextureResource.h"
+#include "MeshResource.h"
+#include "SoundResource.h"
+
+namespace crown
+{
+
+static const ResourceCallback RESOURCE_CALLBACK_REGISTRY[] =
+{
+	{ TEXTURE_TYPE, TextureResource::load, TextureResource::unload, TextureResource::online, TextureResource::offline },
+	{ MESH_TYPE, MeshResource::load, MeshResource::unload, MeshResource::online, MeshResource::offline },
+	{ SOUND_TYPE, SoundResource::load, SoundResource::unload, SoundResource::online, SoundResource::offline },
+	{ 0, NULL, NULL, NULL, NULL }
+};
+
+//-----------------------------------------------------------------------------
+static const ResourceCallback* find_callback(uint32_t type)
+{
+	const ResourceCallback* c = RESOURCE_CALLBACK_REGISTRY;
+
+	while (c->type != 0)
+	{
+		if (c->type == type)
+		{
+			return c;
+		}
+
+		c++;
+	}
+
+	return NULL;
+}
+
+//-----------------------------------------------------------------------------
+void* resource_on_load(uint32_t type, Allocator& allocator, Bundle& bundle, ResourceId id)
+{
+	const ResourceCallback* c = find_callback(type);
+
+	CE_ASSERT_NOT_NULL(c);
+
+	return c->on_load(allocator, bundle, id);
+}
+
+//-----------------------------------------------------------------------------
+void resource_on_unload(uint32_t type, Allocator& allocator, void* resource)
+{
+	const ResourceCallback* c = find_callback(type);
+
+	CE_ASSERT_NOT_NULL(c);
+
+	return c->on_unload(allocator, resource);
+}
+
+//-----------------------------------------------------------------------------
+void resource_on_online(uint32_t type, void* resource)
+{
+	const ResourceCallback* c = find_callback(type);
+
+	CE_ASSERT_NOT_NULL(c);
+
+	return c->on_online(resource);
+}
+
+//-----------------------------------------------------------------------------
+void resource_on_offline(uint32_t type, void* resource)
+{
+	const ResourceCallback* c = find_callback(type);
+
+	CE_ASSERT_NOT_NULL(c);
+
+	return c->on_offline(resource);
+}
+
+} // namespace crown

+ 39 - 0
engine/resource/ResourceRegistry.h

@@ -0,0 +1,39 @@
+/*
+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 "Resource.h"
+
+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);
+
+} // namespace crown

+ 1 - 1
engine/resource/SoundResource.cpp

@@ -73,7 +73,7 @@ void SoundResource::unload(Allocator& allocator, void* resource)
 }
 
 //-----------------------------------------------------------------------------
-void SoundResource::offline()
+void SoundResource::offline(void* /*resource*/)
 {
 
 }

+ 2 - 2
engine/resource/SoundResource.h

@@ -50,9 +50,9 @@ class SoundResource
 public:
 
 	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			online(void* resource);
 	static void			unload(Allocator& allocator, void* resource);
-	static void			offline();
+	static void			online(void* resource);
+	static void			offline(void* resource);
 
 public:
 

+ 1 - 1
engine/resource/TextureResource.cpp

@@ -74,7 +74,7 @@ void TextureResource::unload(Allocator& allocator, void* resource)
 }
 
 //-----------------------------------------------------------------------------
-void TextureResource::offline()
+void TextureResource::offline(void* /*resource*/)
 {
 
 }

+ 2 - 2
engine/resource/TextureResource.h

@@ -53,9 +53,9 @@ class TextureResource
 public:
 
 	static void*		load(Allocator& allocator, Bundle& bundle, ResourceId id);
-	static void			online(void* resource);
 	static void			unload(Allocator& allocator, void* resource);
-	static void			offline();
+	static void			online(void* resource);
+	static void			offline(void* resource);
 
 public:
 

+ 0 - 2
tests/CMakeLists.txt → engine/tests/CMakeLists.txt

@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 2.8)
 
 project(crown-tests)
 
-link_directories(${CROWN_BINARY_DIR})
-
 enable_testing()
 
 add_executable(allocators allocators.cpp)

+ 0 - 0
tests/allocators.cpp → engine/tests/allocators.cpp


+ 1 - 1
tests/compressors.cpp → engine/tests/compressors.cpp

@@ -5,7 +5,7 @@
 
 using namespace crown;
 
-int main(int argc, char** argv)
+int main()
 {
 	
 	HeapAllocator allocator;

+ 0 - 0
tests/containers.cpp → engine/tests/containers.cpp


+ 0 - 0
tests/messages.cpp → engine/tests/messages.cpp


+ 0 - 0
tests/paths.cpp → engine/tests/paths.cpp


+ 0 - 0
tests/strings.cpp → engine/tests/strings.cpp


+ 21 - 19
samples/CMakeLists.txt

@@ -4,21 +4,23 @@ project(crown-samples)
 
 # platform independent includes
 set (CROWN_INCLUDES
-	${CMAKE_SOURCE_DIR}/src
-	${CMAKE_SOURCE_DIR}/src/core
-	${CMAKE_SOURCE_DIR}/src/core/bv
-	${CMAKE_SOURCE_DIR}/src/core/containers
-	${CMAKE_SOURCE_DIR}/src/core/math
-	${CMAKE_SOURCE_DIR}/src/core/mem
-	${CMAKE_SOURCE_DIR}/src/core/compressors
-	${CMAKE_SOURCE_DIR}/src/core/filesystem
-	${CMAKE_SOURCE_DIR}/src/core/strings
-	${CMAKE_SOURCE_DIR}/src/core/settings
-	${CMAKE_SOURCE_DIR}/src/os
-	${CMAKE_SOURCE_DIR}/src/input
-	${CMAKE_SOURCE_DIR}/src/renderers
-	${CMAKE_SOURCE_DIR}/src/network
-	${CMAKE_SOURCE_DIR}/src/lua
+	${CMAKE_SOURCE_DIR}/engine
+	${CMAKE_SOURCE_DIR}/engine/core
+	${CMAKE_SOURCE_DIR}/engine/core/bv
+	${CMAKE_SOURCE_DIR}/engine/core/containers
+	${CMAKE_SOURCE_DIR}/engine/core/math
+	${CMAKE_SOURCE_DIR}/engine/core/mem
+	${CMAKE_SOURCE_DIR}/engine/core/compressors
+	${CMAKE_SOURCE_DIR}/engine/core/filesystem
+	${CMAKE_SOURCE_DIR}/engine/core/json
+	${CMAKE_SOURCE_DIR}/engine/core/strings
+	${CMAKE_SOURCE_DIR}/engine/core/settings
+	${CMAKE_SOURCE_DIR}/engine/os
+	${CMAKE_SOURCE_DIR}/engine/input
+	${CMAKE_SOURCE_DIR}/engine/renderers
+	${CMAKE_SOURCE_DIR}/engine/resource
+	${CMAKE_SOURCE_DIR}/engine/network
+	${CMAKE_SOURCE_DIR}/engine/lua
 )
 
 # detect operating system
@@ -26,8 +28,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	set (LINUX 1)
 
 	list (APPEND CROWN_INCLUDES
-		${CMAKE_SOURCE_DIR}/src/os/linux
-		${CMAKE_SOURCE_DIR}/src/renderers/glx
+		${CMAKE_SOURCE_DIR}/engine/os/linux
+		${CMAKE_SOURCE_DIR}/engine/renderers/glx
 	)
 endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 
@@ -35,8 +37,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
 	set(WINDOWS 1)
 
 	list (APPEND CROWN_INCLUDES
-		${CMAKE_SOURCE_DIR}/src/os/win
-		${CMAKE_SOURCE_DIR}/src/renderers/gl/wgl
+		${CMAKE_SOURCE_DIR}/engine/os/win
+		${CMAKE_SOURCE_DIR}/engine/renderers/gl/wgl
 	)
 endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")