Explorar o código

Merge branch 'master' into rpc

Conflicts:
	engine/Android.mk
	engine/CMakeLists.txt
	engine/ConsoleServer.h
	engine/Device.cpp
	engine/Device.h
	engine/lua/LuaKeyboard.cpp
Daniele Bartolini %!s(int64=12) %!d(string=hai) anos
pai
achega
d1f763b2b3
Modificáronse 86 ficheiros con 3873 adicións e 3925 borrados
  1. 0 11
      engine/Android.mk
  2. 13 29
      engine/CMakeLists.txt
  3. 1 3
      engine/Crown.h
  4. 95 323
      engine/Device.cpp
  5. 14 31
      engine/Device.h
  6. 0 94
      engine/EventBuffer.cpp
  7. 67 36
      engine/EventBuffer.h
  8. 0 204
      engine/FPSSystem.cpp
  9. 0 74
      engine/FPSSystem.h
  10. 30 19
      engine/compilers/BundleCompiler.cpp
  11. 2 2
      engine/compilers/BundleCompiler.h
  12. 1 1
      engine/compilers/lua/LuaCompiler.h
  13. 1 1
      engine/compilers/mesh/MeshCompiler.h
  14. 1 1
      engine/compilers/package/PackageCompiler.h
  15. 1 1
      engine/compilers/texture/TextureCompiler.h
  16. 1 1
      engine/core/Args.h
  17. 3 1
      engine/core/Assert.h
  18. 4 3
      engine/core/Log.cpp
  19. 2 2
      engine/core/Log.h
  20. 2 0
      engine/core/Types.h
  21. 47 4
      engine/core/containers/Queue.h
  22. 1 1
      engine/core/mem/Allocator.h
  23. 2 2
      engine/core/mem/Memory.h
  24. 1 1
      engine/core/mem/ProxyAllocator.h
  25. 11 24
      engine/input/Accelerometer.h
  26. 0 178
      engine/input/EventDispatcher.cpp
  27. 0 79
      engine/input/EventDispatcher.h
  28. 0 237
      engine/input/InputManager.cpp
  29. 0 74
      engine/input/InputManager.h
  30. 129 131
      engine/input/KeyCode.h
  31. 0 90
      engine/input/Keyboard.cpp
  32. 62 59
      engine/input/Keyboard.h
  33. 0 131
      engine/input/Mouse.cpp
  34. 93 51
      engine/input/Mouse.h
  35. 0 66
      engine/input/Touch.cpp
  36. 22 31
      engine/input/Touch.h
  37. 4 2
      engine/lua/LuaEnvironment.cpp
  38. 0 1
      engine/lua/LuaEnvironment.h
  39. 114 116
      engine/lua/LuaKeyboard.cpp
  40. 5 5
      engine/lua/LuaMouse.cpp
  41. 1 42
      engine/lua/LuaWindow.cpp
  42. 3 8
      engine/os/OS.h
  43. 142 0
      engine/os/OsEventQueue.h
  44. 61 31
      engine/os/OsTypes.h
  45. 21 5
      engine/os/android/AndroidDevice.cpp
  46. 3 3
      engine/os/android/AndroidOS.cpp
  47. 1 1
      engine/os/android/OsThread.h
  48. 1 1
      engine/os/android/OsWindow.cpp
  49. 1 1
      engine/os/android/OsWindow.h
  50. 0 300
      engine/os/linux/Input.cpp
  51. 0 2
      engine/os/linux/LinuxOS.cpp
  52. 1 1
      engine/os/linux/OsThread.h
  53. 14 289
      engine/os/linux/OsWindow.cpp
  54. 7 9
      engine/os/linux/OsWindow.h
  55. 2 12
      engine/os/linux/Semaphore.h
  56. 574 8
      engine/os/linux/main.cpp
  57. 0 320
      engine/os/linux/main2.cpp
  58. 14 14
      engine/os/posix/OsThread.h
  59. 38 10
      engine/os/win/AtomicInt.h
  60. 0 55
      engine/os/win/Cond.cpp
  61. 23 0
      engine/os/win/Cond.h
  62. 24 0
      engine/os/win/Mutex.h
  63. 156 0
      engine/os/win/OsThread.h
  64. 27 319
      engine/os/win/OsWindow.cpp
  65. 11 15
      engine/os/win/OsWindow.h
  66. 33 12
      engine/os/win/Semaphore.h
  67. 0 112
      engine/os/win/Thread.cpp
  68. 0 76
      engine/os/win/Thread.h
  69. 4 5
      engine/os/win/WinOS.cpp
  70. 819 10
      engine/os/win/main.cpp
  71. 12 12
      engine/renderers/DebugRenderer.cpp
  72. 5 5
      engine/renderers/Renderer.h
  73. 1 1
      engine/renderers/gl/GLRenderer.cpp
  74. 1 0
      engine/renderers/gl/glx/GLContext.cpp
  75. 48 10
      engine/renderers/gl/wgl/GLContext.cpp
  76. 5 2
      engine/renderers/gl/wgl/GLContext.h
  77. 951 0
      engine/renderers/gl/wgl/wglext.h
  78. 2 2
      engine/resource/ResourceLoader.h
  79. 13 1
      engine/rpc/RPCHandler.cpp
  80. 23 27
      engine/tests/CMakeLists.txt
  81. 71 52
      engine/tests/events.cpp
  82. 0 31
      engine/tests/threads.cpp
  83. 8 0
      engine/third/win32/CMakeLists.txt
  84. 8 0
      engine/third/win64/CMakeLists.txt
  85. 7 0
      engine/third/x86/CMakeLists.txt
  86. 8 1
      engine/third/x86_64/CMakeLists.txt

+ 0 - 11
engine/Android.mk

@@ -52,14 +52,6 @@ LOCAL_SRC_FILES :=\
 	core/Args.cpp\
 	core/Args.cpp\
 	core/Log.cpp\
 	core/Log.cpp\
 \
 \
-	input/Accelerometer.cpp\
-	input/Keyboard.cpp\
-	input/Mouse.cpp\
-	input/Touch.cpp\
-	input/EventDispatcher.cpp\
-	input/InputManager.cpp\
-\
-	os/OS.cpp\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidOS.cpp\
 	os/android/AndroidDevice.cpp\
 	os/android/AndroidDevice.cpp\
 	os/android/OsWindow.cpp\
 	os/android/OsWindow.cpp\
@@ -99,8 +91,6 @@ LOCAL_SRC_FILES :=\
 \
 \
 	Camera.cpp\
 	Camera.cpp\
 	Device.cpp\
 	Device.cpp\
-	FPSSystem.cpp\
-	EventBuffer.cpp\
 \
 \
 
 
 LOCAL_C_INCLUDES	:=\
 LOCAL_C_INCLUDES	:=\
@@ -136,4 +126,3 @@ LOCAL_STATIC_LIBRARIES := android_native_app_glue
 include $(BUILD_SHARED_LIBRARY)
 include $(BUILD_SHARED_LIBRARY)
 
 
 $(call import-module,android/native_app_glue)
 $(call import-module,android/native_app_glue)
-

+ 13 - 29
engine/CMakeLists.txt

@@ -67,8 +67,6 @@ set (CROWN_INCLUDES
 set (SRC
 set (SRC
 	Camera.cpp
 	Camera.cpp
 	Device.cpp
 	Device.cpp
-	EventBuffer.cpp
-	FPSSystem.cpp
 )
 )
 
 
 set (HEADERS
 set (HEADERS
@@ -76,8 +74,6 @@ set (HEADERS
 	Config.h
 	Config.h
 	Crown.h
 	Crown.h
 	Device.h
 	Device.h
-	EventBuffer.h
-	FPSSystem.h
 )
 )
 
 
 set (CORE_SRC
 set (CORE_SRC
@@ -228,17 +224,9 @@ set (SETTINGS_HEADERS
 )
 )
 
 
 set (INPUT_SRC
 set (INPUT_SRC
-	input/EventDispatcher.cpp
-	input/InputManager.cpp
-	input/Keyboard.cpp
-	input/Mouse.cpp
-	input/Touch.cpp
-	input/Accelerometer.cpp
 )
 )
 
 
 set (INPUT_HEADERS
 set (INPUT_HEADERS
-	input/EventDispatcher.h
-	input/InputManager.h
 	input/Keyboard.h
 	input/Keyboard.h
 	input/KeyCode.h
 	input/KeyCode.h
 	input/Mouse.h
 	input/Mouse.h
@@ -307,13 +295,13 @@ set (RPC_HEADERS
 )
 )
 
 
 set (OS_SRC
 set (OS_SRC
-	os/OS.cpp
 )
 )
 
 
 set (OS_HEADERS
 set (OS_HEADERS
 	os/OS.h
 	os/OS.h
+	os/OsEventQueue.h
 	os/NetAddress.h
 	os/NetAddress.h
-	os/OsEvents.h
+	os/OsTypes.h
 )
 )
 
 
 set (LUA_SRC
 set (LUA_SRC
@@ -369,10 +357,8 @@ if (LINUX)
 
 
 	list (APPEND OS_HEADERS
 	list (APPEND OS_HEADERS
 		os/linux/OsWindow.h
 		os/linux/OsWindow.h
-		os/linux/TCPSocket.h
-		os/linux/UDPSocket.h
 		os/linux/OsFile.h
 		os/linux/OsFile.h
-		os/linux/Thread.h
+		os/linux/OsThread.h
 		os/linux/Mutex.h
 		os/linux/Mutex.h
 		os/linux/Cond.h
 		os/linux/Cond.h
 		os/posix/Semaphore.h
 		os/posix/Semaphore.h
@@ -447,21 +433,20 @@ if (WINDOWS)
 	)
 	)
 
 
 	list (APPEND OS_HEADERS
 	list (APPEND OS_HEADERS
-		os/win/OsWindow.h
 		os/win/OsFile.h
 		os/win/OsFile.h
-		os/win/Thread.h
+		os/win/OsThread.h
+		os/win/OsWindow.h
 		os/win/Mutex.h
 		os/win/Mutex.h
 		os/win/Cond.h
 		os/win/Cond.h
+		os/win/Semaphore.h
+		os/win/AtomicInt.h
 		os/win/inttypes.h
 		os/win/inttypes.h
 	)
 	)
 
 
 	list (APPEND OS_SRC
 	list (APPEND OS_SRC
 		os/win/WinOS.cpp
 		os/win/WinOS.cpp
-		os/win/OsWindow.cpp
 		os/win/OsFile.cpp
 		os/win/OsFile.cpp
-		os/win/Thread.cpp
-		os/win/Mutex.cpp
-		os/win/Cond.cpp
+		os/win/OsWindow.cpp
 	)
 	)
 
 
 	list (APPEND RENDERERS_SRC
 	list (APPEND RENDERERS_SRC
@@ -472,6 +457,7 @@ if (WINDOWS)
 	list (APPEND RENDERERS_HEADERS
 	list (APPEND RENDERERS_HEADERS
 		renderers/gl/GLRenderer.h
 		renderers/gl/GLRenderer.h
 		renderers/gl/wgl/GLContext.h
 		renderers/gl/wgl/GLContext.h
+		renderers/gl/wgl/wglext.h
 	)
 	)
 
 
 	list (APPEND CROWN_LIBRARIES
 	list (APPEND CROWN_LIBRARIES
@@ -482,7 +468,6 @@ if (WINDOWS)
 	)
 	)
 
 
 	set (COMPILER_FLAGS
 	set (COMPILER_FLAGS
-		/Wall
 	)
 	)
 
 
 	set (CROWN_MAIN_SRC os/win/main.cpp)
 	set (CROWN_MAIN_SRC os/win/main.cpp)
@@ -544,16 +529,15 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ORIGIN")
 add_executable(${CROWN_EXECUTABLE_NAME} ${CROWN_MAIN_SRC})
 add_executable(${CROWN_EXECUTABLE_NAME} ${CROWN_MAIN_SRC})
 target_link_libraries(${CROWN_EXECUTABLE_NAME} crown)
 target_link_libraries(${CROWN_EXECUTABLE_NAME} crown)
 
 
-add_executable(crown-linux-renderer-evo os/linux/main2.cpp)
-target_link_libraries(crown-linux-renderer-evo crown)
-
 if (CROWN_BUILD_TESTS)
 if (CROWN_BUILD_TESTS)
-	#add_subdirectory(tests)
+	add_subdirectory(tests)
 endif (CROWN_BUILD_TESTS)
 endif (CROWN_BUILD_TESTS)
 
 
+
 install (TARGETS crown DESTINATION bin)
 install (TARGETS crown DESTINATION bin)
 install (TARGETS ${CROWN_EXECUTABLE_NAME} DESTINATION bin)
 install (TARGETS ${CROWN_EXECUTABLE_NAME} DESTINATION bin)
-install (TARGETS crown-linux-renderer-evo DESTINATION bin)
+
+install (TARGETS crown DESTINATION test)
 
 
 #install (FILES ${HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME})
 #install (FILES ${HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME})
 
 

+ 1 - 3
engine/Crown.h

@@ -104,8 +104,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Device.h"
 #include "Device.h"
 
 
 // Engine/Input
 // Engine/Input
-#include "EventDispatcher.h"
-#include "InputManager.h"
 #include "Keyboard.h"
 #include "Keyboard.h"
 #include "KeyCode.h"
 #include "KeyCode.h"
 #include "Mouse.h"
 #include "Mouse.h"
@@ -116,7 +114,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "LuaEnvironment.h"
 #include "LuaEnvironment.h"
 
 
 // Engine/Os
 // Engine/Os
-#include "Thread.h"
+#include "OsThread.h"
 #include "Mutex.h"
 #include "Mutex.h"
 #include "Cond.h"
 #include "Cond.h"
 #include "OsFile.h"
 #include "OsFile.h"

+ 95 - 323
engine/Device.cpp

@@ -34,7 +34,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "DebugRenderer.h"
 #include "DebugRenderer.h"
 #include "DiskFile.h"
 #include "DiskFile.h"
 #include "DiskFilesystem.h"
 #include "DiskFilesystem.h"
-#include "InputManager.h"
 #include "JSONParser.h"
 #include "JSONParser.h"
 #include "Keyboard.h"
 #include "Keyboard.h"
 #include "Log.h"
 #include "Log.h"
@@ -53,7 +52,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Bundle.h"
 #include "Bundle.h"
 #include "TempAllocator.h"
 #include "TempAllocator.h"
 #include "ResourcePackage.h"
 #include "ResourcePackage.h"
-#include "EventBuffer.h"
 #include "RPCServer.h"
 #include "RPCServer.h"
 
 
 #if defined(LINUX) || defined(WINDOWS)
 #if defined(LINUX) || defined(WINDOWS)
@@ -68,45 +66,32 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 namespace crown
 namespace crown
 {
 {
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-Device::Device() : 
-	m_allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP),
-
-	m_preferred_window_width(1000),
-	m_preferred_window_height(625),
-	m_preferred_window_fullscreen(0),
-	m_parent_window_handle(0),
-	m_compile(0),
-	m_continue(0),
-	m_wait(0),
-
-	m_quit_after_init(0),
+Device::Device()
+	: m_allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP)
+	, m_is_init(false)
+	, m_is_running(false)
+	, m_is_paused(false)
+	, m_is_really_paused(false)
 
 
-	m_is_init(false),
-	m_is_running(false),
-	m_is_paused(false),
-	m_is_really_paused(false),
+	, m_frame_count(0)
 
 
-	m_frame_count(0),
+	, m_last_time(0)
+	, m_current_time(0)
+	, m_last_delta_time(0.0f)
+	, m_time_since_start(0.0)
 
 
-	m_last_time(0),
-	m_current_time(0),
-	m_last_delta_time(0.0f),
-	m_time_since_start(0.0),
+	, m_filesystem(NULL)
+	, m_lua_environment(NULL)
+	, m_renderer(NULL)
+	, m_debug_renderer(NULL)
 
 
-	m_filesystem(NULL),
-	m_input_manager(NULL),
-	m_lua_environment(NULL),
-	m_renderer(NULL),
-	m_debug_renderer(NULL),
+	, m_bundle_compiler(NULL)
+	, m_rpc(NULL)
+	, m_resource_manager(NULL)
+	, m_resource_bundle(NULL)
 
 
-	m_bundle_compiler(NULL),
-	m_rpc(NULL),
-	m_resource_manager(NULL),
-	m_resource_bundle(NULL),
-
-	m_renderer_init_request(false)
+	, m_renderer_init_request(false)
 {
 {
 	// Bundle dir is current dir by default.
 	// Bundle dir is current dir by default.
 	string::strncpy(m_bundle_dir, os::get_cwd(), MAX_PATH_LENGTH);
 	string::strncpy(m_bundle_dir, os::get_cwd(), MAX_PATH_LENGTH);
@@ -120,12 +105,10 @@ Device::~Device()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-bool Device::init(int argc, char** argv)
+void Device::init()
 {
 {
-	CE_ASSERT(!is_init(), "Engine already initialized");
-
-	parse_command_line(argc, argv);
-	check_preferred_settings();
+	// Initialize
+	Log::i("Initializing Crown Engine %d.%d.%d...", CROWN_VERSION_MAJOR, CROWN_VERSION_MINOR, CROWN_VERSION_MICRO);
 
 
 	// RPC only in debug or development builds
 	// RPC only in debug or development builds
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
@@ -134,42 +117,9 @@ bool Device::init(int argc, char** argv)
 		m_rpc->add_handler(&m_script_handler);
 		m_rpc->add_handler(&m_script_handler);
 		m_rpc->add_handler(&m_stats_handler);
 		m_rpc->add_handler(&m_stats_handler);
 		m_rpc->add_handler(&m_ping_handler);
 		m_rpc->add_handler(&m_ping_handler);
-		m_rpc->init((bool) m_wait);
-	#endif
-
-	// Resource compilation only in debug or development mode and only on linux or windows builds
-	#if (defined(LINUX) || defined(WINDOWS)) && (defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT))
-		if (m_compile == 1)
-		{
-			m_bundle_compiler = CE_NEW(m_allocator, BundleCompiler);
-			if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir))
-			{
-				CE_DELETE(m_allocator, m_bundle_compiler);
-				m_allocator.clear();
-				Log::e("Exiting.");
-				exit(EXIT_FAILURE);
-			}
-
-			if (!m_continue)
-			{
-				CE_DELETE(m_allocator, m_bundle_compiler);
-				m_allocator.clear();
-				exit(EXIT_SUCCESS);
-			}
-		}
+		m_rpc->init(false);
 	#endif
 	#endif
 
 
-	init();
-
-	return true;
-}
-
-//-----------------------------------------------------------------------------
-void Device::init()
-{
-	// Initialize
-	Log::i("Initializing Crown Engine %d.%d.%d...", CROWN_VERSION_MAJOR, CROWN_VERSION_MINOR, CROWN_VERSION_MICRO);
-
 	// Default bundle filesystem
 	// Default bundle filesystem
 	#if defined (LINUX) || defined(WINDOWS)
 	#if defined (LINUX) || defined(WINDOWS)
 		m_filesystem = CE_NEW(m_allocator, DiskFilesystem)(m_bundle_dir);
 		m_filesystem = CE_NEW(m_allocator, DiskFilesystem)(m_bundle_dir);
@@ -183,39 +133,22 @@ void Device::init()
 
 
 	m_resource_bundle = Bundle::create(m_allocator, *m_filesystem);
 	m_resource_bundle = Bundle::create(m_allocator, *m_filesystem);
 
 
-	// // Read resource seed
-	// DiskFile* seed_file = (DiskFile*)filesystem()->open(g_default_mountpoint.value(), "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
 	// Create resource manager
 	m_resource_manager = CE_NEW(m_allocator, ResourceManager)(*m_resource_bundle, 0);
 	m_resource_manager = CE_NEW(m_allocator, ResourceManager)(*m_resource_bundle, 0);
 	Log::d("Resource manager created.");
 	Log::d("Resource manager created.");
 	Log::d("Resource seed: %d", m_resource_manager->seed());
 	Log::d("Resource seed: %d", m_resource_manager->seed());
 
 
-	// Create input manager
-	m_input_manager = CE_NEW(m_allocator, InputManager)();
-	Log::d("Input manager created.");
-
-	// default_allocator, maybe it needs fix
-	m_window = CE_NEW(m_allocator, OsWindow)(m_preferred_window_width, m_preferred_window_height, m_parent_window_handle);
+	// Create window
+	m_window = CE_NEW(m_allocator, OsWindow);
 
 
-	CE_ASSERT(m_window != NULL, "Unable to create the window");
-
-	// Create main window
-	m_window->set_title("Crown Game Engine");
-	Log::d("Window created.");
+	// Create input devices
+	m_keyboard = CE_NEW(m_allocator, Keyboard);
+	m_mouse = CE_NEW(m_allocator, Mouse);
+	m_touch = CE_NEW(m_allocator, Touch);
 
 
 	// Create renderer
 	// Create renderer
 	m_renderer = CE_NEW(m_allocator, Renderer)(m_allocator);
 	m_renderer = CE_NEW(m_allocator, Renderer)(m_allocator);
 	m_renderer->init();
 	m_renderer->init();
-	m_renderer_init_request = false;
 	Log::d("Renderer created.");
 	Log::d("Renderer created.");
 
 
 	// Create debug renderer
 	// Create debug renderer
@@ -232,9 +165,6 @@ void Device::init()
 	m_is_init = true;
 	m_is_init = true;
 	start();
 	start();
 
 
-	// Show main window
-	m_window->show();
-
 	// Execute lua boot file
 	// Execute lua boot file
 	if (m_lua_environment->load_and_execute(m_boot_file))
 	if (m_lua_environment->load_and_execute(m_boot_file))
 	{
 	{
@@ -249,12 +179,6 @@ void Device::init()
 	}
 	}
 
 
 	Log::d("Total allocated size: %llu", m_allocator.allocated_size());
 	Log::d("Total allocated size: %llu", m_allocator.allocated_size());
-
-	if (m_quit_after_init == 1)
-	{
-		stop();
-		shutdown();
-	}
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -273,11 +197,10 @@ void Device::shutdown()
 		CE_DELETE(m_allocator, m_lua_environment);
 		CE_DELETE(m_allocator, m_lua_environment);
 	}
 	}
 
 
-	Log::i("Releasing InputManager...");
-	if (m_input_manager)
-	{
-		CE_DELETE(m_allocator, m_input_manager);
-	}
+	Log::i("Releasing Input Devices...");
+	CE_DELETE(m_allocator, m_touch);
+	CE_DELETE(m_allocator, m_mouse);
+	CE_DELETE(m_allocator, m_keyboard);
 
 
 	Log::i("Releasing DebugRenderer...");
 	Log::i("Releasing DebugRenderer...");
 	if (m_debug_renderer)
 	if (m_debug_renderer)
@@ -292,12 +215,6 @@ void Device::shutdown()
 		CE_DELETE(m_allocator, m_renderer);
 		CE_DELETE(m_allocator, m_renderer);
 	}
 	}
 
 
-	Log::i("Releasing Window...");
-	if (m_window)
-	{
-		CE_DELETE(m_allocator, m_window);
-	}
-
 	Log::i("Releasing ResourceManager...");
 	Log::i("Releasing ResourceManager...");
 	if (m_resource_manager)
 	if (m_resource_manager)
 	{
 	{
@@ -315,23 +232,14 @@ void Device::shutdown()
 		CE_DELETE(m_allocator, m_filesystem);
 		CE_DELETE(m_allocator, m_filesystem);
 	}
 	}
 
 
-	#if (defined(LINUX) || defined(WINDOWS)) && (defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT))
-		Log::i("Releasing BundleCompiler...");
-		if (m_bundle_compiler)
-		{
-			CE_DELETE(m_allocator, m_bundle_compiler);
-		}
-	#endif
-
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
 	#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
-		Log::flush(m_rpc);
+		Log::flush();
 		m_rpc->execute_callbacks();
 		m_rpc->execute_callbacks();
 		m_rpc->shutdown();
 		m_rpc->shutdown();
 		CE_DELETE(m_allocator, m_rpc);
 		CE_DELETE(m_allocator, m_rpc);
 	#endif
 	#endif
 
 
 	m_allocator.clear();
 	m_allocator.clear();
-
 	m_is_init = false;
 	m_is_init = false;
 }
 }
 
 
@@ -359,12 +267,6 @@ ResourceManager* Device::resource_manager()
 	return m_resource_manager;
 	return m_resource_manager;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-InputManager* Device::input_manager()
-{
-	return m_input_manager;
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 LuaEnvironment* Device::lua_environment()
 LuaEnvironment* Device::lua_environment()
 {
 {
@@ -392,25 +294,25 @@ DebugRenderer* Device::debug_renderer()
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Keyboard* Device::keyboard()
 Keyboard* Device::keyboard()
 {
 {
-	return m_input_manager->keyboard();
+	return m_keyboard;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Mouse* Device::mouse()
 Mouse* Device::mouse()
 {
 {
-	return m_input_manager->mouse();
+	return m_mouse;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Touch* Device::touch()
 Touch* Device::touch()
 {
 {
-	return m_input_manager->touch();
+	return m_touch;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Accelerometer* Device::accelerometer()
 Accelerometer* Device::accelerometer()
 {
 {
-	return m_input_manager->accelerometer();
+	return NULL;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -434,17 +336,12 @@ void Device::stop()
 void Device::pause()
 void Device::pause()
 {
 {
 	m_is_paused = true;
 	m_is_paused = true;
-
-	Log::d("Engine paused");
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void Device::unpause()
 void Device::unpause()
 {
 {
 	m_is_paused = false;
 	m_is_paused = false;
-	m_is_really_paused = false;
-
-	Log::d("Engine unpaused");
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -472,7 +369,7 @@ double Device::time_since_start() const
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void Device::frame(cb callback)
+void Device::frame()
 {
 {
 	m_current_time = os::microseconds();
 	m_current_time = os::microseconds();
 	m_last_delta_time = (m_current_time - m_last_time) / 1000000.0f;
 	m_last_delta_time = (m_current_time - m_last_time) / 1000000.0f;
@@ -485,22 +382,19 @@ void Device::frame(cb callback)
 	{
 	{
 		m_resource_manager->poll_resource_loader();
 		m_resource_manager->poll_resource_loader();
 
 
-		m_window->frame();
-		m_input_manager->frame(frame_count());
+		m_renderer->set_layer_clear(0, CLEAR_COLOR | CLEAR_DEPTH, Color4::LIGHTBLUE, 1.0f);
+		m_renderer->commit(0);
 
 
 		if (!m_lua_environment->call_global("frame", 1, ARGUMENT_FLOAT, last_delta_time()))
 		if (!m_lua_environment->call_global("frame", 1, ARGUMENT_FLOAT, last_delta_time()))
 		{
 		{
 			pause();
 			pause();
 		}
 		}
 
 
-		callback(m_last_delta_time);
 		m_renderer->frame();
 		m_renderer->frame();
 	}
 	}
 
 
-	Log::flush(m_rpc);
-
+	Log::flush();
 	m_rpc->execute_callbacks();
 	m_rpc->execute_callbacks();
-	os_event_buffer()->clear();
 
 
 	m_frame_count++;
 	m_frame_count++;
 }
 }
@@ -534,202 +428,86 @@ void Device::compile(const char* , const char* , const char* )
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void Device::reload(ResourceId name)
+void Device::reload(const char* type, const char* name)
 {
 {
-	(void)name;
-}
+	TempAllocator4096 temp;
+	DynamicString filename(temp);
+	filename += name;
+	filename += '.';
+	filename += type;
 
 
-//-----------------------------------------------------------------------------
-void Device::parse_command_line(int argc, char** argv)
-{
-	static ArgsOption options[] = 
+	if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir, filename.c_str()))
 	{
 	{
-		{ "help",             AOA_NO_ARGUMENT,       NULL,        'i' },
-		{ "source-dir",       AOA_REQUIRED_ARGUMENT, NULL,        's' },
-		{ "bundle-dir",       AOA_REQUIRED_ARGUMENT, NULL,        'b' },
-		{ "compile",          AOA_NO_ARGUMENT,       &m_compile,   1 },
-		{ "continue",         AOA_NO_ARGUMENT,       &m_continue,  1 },
-		{ "wait",             AOA_NO_ARGUMENT,       &m_wait,      1 },
-		{ "width",            AOA_REQUIRED_ARGUMENT, NULL,        'w' },
-		{ "height",           AOA_REQUIRED_ARGUMENT, NULL,        'h' },
-		{ "fullscreen",       AOA_NO_ARGUMENT,       &m_preferred_window_fullscreen, 1 },
-		{ "parent-window",    AOA_REQUIRED_ARGUMENT, NULL,        'p' },
-		{ "quit-after-init",  AOA_NO_ARGUMENT,       &m_quit_after_init, 1 },
-		{ NULL, 0, NULL, 0 }
-	};
-
-	Args args(argc, argv, "", options);
-
-	int32_t opt;
-
-	while ((opt = args.getopt()) != -1)
-	{
-		switch (opt)
-		{
-			case 0:
-			{
-				break;
-			}
-			// Source directory
-			case 's':
-			{
-				string::strncpy(m_source_dir, args.optarg(), MAX_PATH_LENGTH);
-				break;
-			}
-			// Bundle directory
-			case 'b':
-			{
-				string::strncpy(m_bundle_dir, args.optarg(), MAX_PATH_LENGTH);
-				break;
-			}
-			// Window width
-			case 'w':
-			{
-				m_preferred_window_width = atoi(args.optarg());
-				break;
-			}
-			// Window height
-			case 'h':
-			{
-				m_preferred_window_height = atoi(args.optarg());
-				break;
-			}
-			// Parent window
-			case 'p':
-			{
-				m_parent_window_handle = string::parse_uint(args.optarg());
-				break;
-			}
-			case 'i':
-			case '?':
-			default:
-			{
-				print_help_message();
-				exit(EXIT_FAILURE);
-			}
-		}
+		Log::d("Compilation failed.");
+		return;
 	}
 	}
-}
 
 
-//-----------------------------------------------------------------------------
-void Device::check_preferred_settings()
-{
-	if (m_compile == 1)
+	uint32_t type_hash = hash::murmur2_32(type, string::strlen(type), 0);
+
+	switch (type_hash)
 	{
 	{
-		if (string::strcmp(m_source_dir, "") == 0)
+		case LUA_TYPE:
 		{
 		{
-			Log::e("You have to specify the source directory when running in compile mode.");
-			exit(EXIT_FAILURE);
+			m_lua_environment->load_and_execute(name);
+			break;
 		}
 		}
-
-		if (!os::is_absolute_path(m_source_dir))
+		default:
 		{
 		{
-			Log::e("The source directory must be absolute.");
-			exit(EXIT_FAILURE);
+			CE_ASSERT(false, "Oops, unknown resource type: %s", type);
+			break;
 		}
 		}
 	}
 	}
-
-	if (!os::is_absolute_path(m_bundle_dir))
-	{
-		Log::e("The bundle directory must be absolute.");
-		exit(EXIT_FAILURE);
-	}
-
-	if (m_preferred_window_width == 0 || m_preferred_window_height == 0)
-	{
-		Log::e("Window width and height must be greater than zero.");
-		exit(EXIT_FAILURE);
-	}
 }
 }
-
-//-----------------------------------------------------------------------------
+//-------------------------------------------------------------------------
 void Device::read_engine_settings()
 void Device::read_engine_settings()
 {
 {
-	// Check crown.config existance
-	CE_ASSERT(m_filesystem->is_file("crown.config"), "Unable to open crown.config");
+	// // Check crown.config existance
+	// CE_ASSERT(m_filesystem->is_file("crown.config"), "Unable to open crown.config");
 
 
-	// Copy crown config in a buffer
-	TempAllocator4096 allocator;
+	// // Copy crown config in a buffer
+	// TempAllocator4096 allocator;
 
 
-	File* config_file = m_filesystem->open("crown.config", FOM_READ);
+	// File* config_file = m_filesystem->open("crown.config", FOM_READ);
 
 
-	char* json_string = (char*)allocator.allocate(config_file->size());
+	// char* json_string = (char*)allocator.allocate(config_file->size());
 
 
-	config_file->read(json_string, config_file->size());
+	// config_file->read(json_string, config_file->size());
 
 
-	m_filesystem->close(config_file);
+	// m_filesystem->close(config_file);
 
 
-	// Parse crown.config
-	JSONParser parser(json_string);
+	// // Parse crown.config
+	// JSONParser parser(json_string);
 
 
-	JSONElement root = parser.root();
+	// JSONElement root = parser.root();
 
 
-	// Boot
-	if (root.has_key("boot"))
-	{
-		const char* boot = root.key("boot").string_value();
-		const size_t boot_length = string::strlen(boot) + 1;
+	// // Boot
+	// if (root.has_key("boot"))
+	// {
+	// 	const char* boot = root.key("boot").string_value();
+	// 	const size_t boot_length = string::strlen(boot) + 1;
 
 
-		string::strncpy(m_boot_file, boot, boot_length);
-	}
-	// Window width
-	if (root.has_key("window_width"))
-	{
-		m_preferred_window_width = root.key("window_width").int_value();
-	}
-	// Window height
-	if (root.has_key("window_height"))
-	{
-		m_preferred_window_height = root.key("window_height").int_value();
-	}
-
-	allocator.deallocate(json_string);
-
-	Log::i("Configuration set");
-}
-
-//-----------------------------------------------------------------------------
-void Device::print_help_message()
-{
-	os::printf(
-	"Usage: crown [options]\n"
-	"Options:\n\n"
+	// 	string::strncpy(m_boot_file, boot, boot_length);
+	// }
+	// // Window width
+	// if (root.has_key("window_width"))
+	// {
+	// 	m_preferred_window_width = root.key("window_width").int_value();
+	// }
+	// // Window height
+	// if (root.has_key("window_height"))
+	// {
+	// 	m_preferred_window_height = root.key("window_height").int_value();
+	// }
 
 
-	"All of the following options take precedence over\n"
-	"environment variables and configuration files.\n\n"
+	// allocator.deallocate(json_string);
 
 
-	"  --help                     Show this help.\n"
-	"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
-	"  --width <width>            Set the <width> of the main window.\n"
-	"  --height <width>           Set the <height> of the main window.\n"
-	"  --fullscreen               Start in fullscreen.\n"
-	"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
-	"                             Used only by tools.\n"
-
-	"\nAvailable only in debug and development builds:\n\n"
-
-	"  --source-dir <path>        Use <path> as the source directory for resource compilation.\n"
-	"  --compile                  Run the engine as resource compiler.\n"
-	"  --continue                 Do a full compile of the resources and continue the execution.\n"
-	"  --wait                     Wait until a clent connects to the engine.\n"
-	"  --quit-after-init          Quit the engine immediately after the initialization.\n");
+	// Log::i("Configuration set");
 }
 }
 
 
-static Device* g_device = NULL;
-
-//-----------------------------------------------------------------------------
-void init()
+static Device* g_device;
+void set_device(Device* device)
 {
 {
-	crown::memory::init();
-	crown::os::init_os();
-	g_device = CE_NEW(default_allocator(), Device);
-}
-
-//-----------------------------------------------------------------------------
-void shutdown()
-{
-	CE_DELETE(default_allocator(), g_device);
-	crown::memory::shutdown();
+	g_device = device;
 }
 }
 
 
 Device* device()
 Device* device()
@@ -737,10 +515,4 @@ Device* device()
 	return g_device;
 	return g_device;
 }
 }
 
 
-void nothing(float)
-{
-	device()->renderer()->set_layer_clear(0, CLEAR_COLOR | CLEAR_DEPTH, Color4::LIGHTBLUE, 1.0f);
-	device()->renderer()->commit(0);
-}
-
 } // namespace crown
 } // namespace crown

+ 14 - 31
engine/Device.h

@@ -42,7 +42,6 @@ class OsWindow;
 class Bundle;
 class Bundle;
 class Renderer;
 class Renderer;
 class DebugRenderer;
 class DebugRenderer;
-class InputManager;
 class Keyboard;
 class Keyboard;
 class Mouse;
 class Mouse;
 class Touch;
 class Touch;
@@ -52,9 +51,6 @@ class BundleCompiler;
 class ResourcePackage;
 class ResourcePackage;
 class RPCServer;
 class RPCServer;
 
 
-typedef void (*cb)(float);
-void nothing(float);
-
 /// The Engine.
 /// The Engine.
 /// It is the place where to look for accessing all of
 /// It is the place where to look for accessing all of
 /// the engine subsystems and related stuff.
 /// the engine subsystems and related stuff.
@@ -65,9 +61,7 @@ public:
 							Device();
 							Device();
 							~Device();
 							~Device();
 
 
-	/// Initializes the engine allowing to pass command line
-	/// parameters to configure some parameters.
-	bool					init(int argc, char** argv);
+	void					init();
 
 
 	/// Shutdowns the engine freeing all the allocated resources
 	/// Shutdowns the engine freeing all the allocated resources
 	void					shutdown();
 	void					shutdown();
@@ -105,9 +99,10 @@ public:
 	/// Unpauses the engine
 	/// Unpauses the engine
 	void					unpause();
 	void					unpause();
 
 
+	virtual int32_t			run(int argc, char** argv) = 0;
+
 	/// Updates all the subsystems
 	/// Updates all the subsystems
-	void					frame(cb callback);
-	void					frame() { frame(nothing); }
+	void					frame();
 
 
 	/// Returns the resource package with the given @a package_name name.
 	/// Returns the resource package with the given @a package_name name.
 	ResourcePackage*		create_resource_package(const char* name);
 	ResourcePackage*		create_resource_package(const char* name);
@@ -120,11 +115,10 @@ public:
 
 
 	void					compile(const char* bundle_dir, const char* source_dir, const char* resource);
 	void					compile(const char* bundle_dir, const char* source_dir, const char* resource);
 
 
-	void					reload(ResourceId name);
+	void					reload(const char* type, const char* name);
 
 
 	Filesystem*				filesystem();
 	Filesystem*				filesystem();
 	ResourceManager*		resource_manager();
 	ResourceManager*		resource_manager();
-	InputManager*			input_manager();
 	LuaEnvironment*			lua_environment();
 	LuaEnvironment*			lua_environment();
 
 
 	OsWindow*				window();
 	OsWindow*				window();
@@ -135,33 +129,21 @@ public:
 	Mouse*					mouse();
 	Mouse*					mouse();
 	Touch*					touch();
 	Touch*					touch();
 	Accelerometer*			accelerometer();
 	Accelerometer*			accelerometer();
+	RPCServer*				rpc() { return m_rpc; }
 
 
 private:
 private:
 
 
-	void					init();
-	void					parse_command_line(int argc, char** argv);
-	void					check_preferred_settings();
 	void					read_engine_settings();
 	void					read_engine_settings();
-	void					print_help_message();
 
 
-private:
+protected:
 
 
 	// Used to allocate all subsystems
 	// Used to allocate all subsystems
 	LinearAllocator			m_allocator;
 	LinearAllocator			m_allocator;
 
 
 	// Preferred settings
 	// Preferred settings
-	int32_t					m_preferred_window_width;
-	int32_t					m_preferred_window_height;
-	int32_t					m_preferred_window_fullscreen;
-	uint32_t				m_parent_window_handle;
 	char					m_source_dir[MAX_PATH_LENGTH];
 	char					m_source_dir[MAX_PATH_LENGTH];
 	char 					m_bundle_dir[MAX_PATH_LENGTH];
 	char 					m_bundle_dir[MAX_PATH_LENGTH];
 	char 					m_boot_file[MAX_PATH_LENGTH];
 	char 					m_boot_file[MAX_PATH_LENGTH];
-	int32_t					m_compile;
-	int32_t					m_continue;
-	int32_t					m_wait;
-
-	int32_t					m_quit_after_init;
 
 
 	bool					m_is_init		: 1;
 	bool					m_is_init		: 1;
 	bool					m_is_running	: 1;
 	bool					m_is_running	: 1;
@@ -180,7 +162,11 @@ private:
 	Filesystem*				m_filesystem;
 	Filesystem*				m_filesystem;
 
 
 	OsWindow*				m_window;
 	OsWindow*				m_window;
-	InputManager*			m_input_manager;
+
+	Keyboard*				m_keyboard;
+	Mouse*					m_mouse;
+	Touch*					m_touch;
+
 	LuaEnvironment*			m_lua_environment;
 	LuaEnvironment*			m_lua_environment;
 	Renderer*				m_renderer;
 	Renderer*				m_renderer;
 	DebugRenderer*			m_debug_renderer;
 	DebugRenderer*			m_debug_renderer;
@@ -203,13 +189,10 @@ private:
 	// Disable copying
 	// Disable copying
 	Device(const Device&);
 	Device(const Device&);
 	Device& operator=(const Device&);
 	Device& operator=(const Device&);
-
-	friend class MainThread;
 };
 };
 
 
-CE_EXPORT void init();
-CE_EXPORT void shutdown();
 CE_EXPORT Device* device();
 CE_EXPORT Device* device();
 
 
-} // namespace crown
+CE_EXPORT void set_device(Device* device);
 
 
+} // namespace crown

+ 0 - 94
engine/EventBuffer.cpp

@@ -1,94 +0,0 @@
-#include "EventBuffer.h"
-#include "Log.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-EventBuffer::EventBuffer() : m_size(0), m_read(0)
-{
-}
-
-//-----------------------------------------------------------------------------
-void EventBuffer::push_event(uint32_t event_type, void* event_data, size_t event_size)
-{
-	if (m_size + sizeof(event_type) + sizeof(event_size) + event_size > MAX_OS_EVENT_BUFFER_SIZE)
-	{
-		flush();
-	}
-
-	char* cur = m_buffer + m_size;
-
-	*(uint32_t*) cur = event_type;
-	*(size_t*) (cur + sizeof(event_type)) = event_size;
-	memcpy(cur + sizeof(event_type) + sizeof(event_size), event_data, event_size);
-
-	m_size += sizeof(event_type) + sizeof(event_size) + event_size;
-}
-
-//-----------------------------------------------------------------------------
-void EventBuffer::push_event_buffer(char* event_buffer, size_t buffer_size)
-{
-	if (m_size + buffer_size > MAX_OS_EVENT_BUFFER_SIZE)
-	{
-		flush();
-	}
-
-	char* cur = m_buffer + m_size;
-
-	memcpy(cur, event_buffer, buffer_size);
-
-	m_size += buffer_size;
-}
-
-
-//-----------------------------------------------------------------------------
-void* EventBuffer::get_next_event(uint32_t& event_type, size_t& event_size)
-{
-	if (m_read < m_size)
-	{
-		char* cur = m_buffer + m_read;
-
-		// Saves type
-		event_type = *(uint32_t*) cur;
-		// Saves size
-		event_size = *(size_t*)(cur + sizeof(uint32_t));
-
-		// Set read to next event
-		m_read += sizeof(size_t) + sizeof(uint32_t) + event_size;
-
-		return cur + sizeof(size_t) + sizeof(uint32_t);
-	}
-
-	m_read = 0;
-
-	return NULL;
-}
-
-//-----------------------------------------------------------------------------
-void EventBuffer::clear()
-{
-	m_size = 0;
-	m_read = 0;
-}
-
-//-----------------------------------------------------------------------------
-void EventBuffer::flush()
-{
-	m_size = 0;
-	m_read = 0;
-}
-
-//-----------------------------------------------------------------------------
-size_t EventBuffer::size() const
-{
-	return m_size;
-}
-
-//-----------------------------------------------------------------------------
-char* EventBuffer::buffer()
-{
-	return m_buffer;
-}
-
-} // namespace crown

+ 67 - 36
engine/EventBuffer.h

@@ -28,48 +28,79 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #include <cstring>
 #include <cstring>
 
 
-#include "Types.h"
+#include "OsTypes.h"
 
 
-#define MAX_OS_EVENT_BUFFER_SIZE 1024
+#define EVENT_BUFFER_MAX_SIZE 1024 * 4
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-
-///	__EventBuffer__ is a global buffer used for storing events.
-///	Each subsystem can read its relative events and modifies its behaviour consequently.
-///
-/// [type #0][size #0][data #0] ... [type #n][size #n][data #n]
-class EventBuffer
+struct EventBuffer
 {
 {
-
-public:
-	/// Constructor
-				EventBuffer();
-
-	/// Pushes an @a event_data of size @a event_size with type @a event_type 
-	void		push_event(uint32_t event_type, void* event_data, size_t event_size);
-	/// Pushes an entire @a event_buffer of size @a buffer_size
-	void		push_event_buffer(char* event_buffer, size_t buffer_size);
-	/// Retrieves the @a event_type and @a event_size of next os event
-	void*		get_next_event(uint32_t& event_type, size_t& event_size);
-
-	/// Clears entire os buffer
-	void		clear();
-	/// Flushes entire os buffer
-	void		flush();
-
-	/// Returns buffer's size
-	size_t		size() const;
-	/// Return buffer
-	char*		buffer();
-
-public:
-
-	size_t		m_size;
-	char		m_buffer[MAX_OS_EVENT_BUFFER_SIZE];
-
-	uint32_t	m_read;
+	char m_buffer[EVENT_BUFFER_MAX_SIZE];
+	
+	size_t m_size;
+	size_t m_read;
+
+	//-----------------------------------------------------------------------------
+	EventBuffer() 
+		: m_size(0), m_read(0)
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_event(uint32_t event_type, void* event_data, size_t event_size)
+	{
+		if (m_size + sizeof(event_type) + sizeof(event_size) + event_size > EVENT_BUFFER_MAX_SIZE)
+		{
+			flush();
+		}
+
+		char* cur = m_buffer + m_size;
+
+		*(uint32_t*) cur = event_type;
+		*(size_t*) (cur + sizeof(event_type)) = event_size;
+		memcpy(cur + sizeof(event_type) + sizeof(event_size), event_data, event_size);
+
+		m_size += sizeof(event_type) + sizeof(event_size) + event_size;
+	}
+
+	//-----------------------------------------------------------------------------
+	void* get_next_event(uint32_t& event_type, size_t& event_size)
+	{
+		if (m_read < m_size)
+		{
+			char* cur = m_buffer + m_read;
+
+			// Saves type
+			event_type = *(uint32_t*) cur;
+			// Saves size
+			event_size = *(size_t*)(cur + sizeof(uint32_t));
+
+			// Set read to next event
+			m_read += sizeof(size_t) + sizeof(uint32_t) + event_size;
+
+			return cur + sizeof(size_t) + sizeof(uint32_t);
+		}
+
+		m_read = 0;
+
+		return NULL;
+	}
+
+	//-----------------------------------------------------------------------------
+	void clear()
+	{
+		m_size = 0;
+		m_read = 0;
+	}
+
+	//-----------------------------------------------------------------------------
+	void flush()
+	{
+		m_size = 0;
+		m_read = 0;
+	}
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 204
engine/FPSSystem.cpp

@@ -1,204 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "InputManager.h"
-#include "Camera.h"
-#include "FPSSystem.h"
-#include "Vec2.h"
-#include "Vec3.h"
-#include "Mat3.h"
-#include "OS.h"
-#include "Device.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------
-FPSSystem::FPSSystem(Camera* camera, float speed, float sensibility) :
-	m_camera(camera),
-	m_camera_speed(speed),
-	m_camera_sensibility(sensibility),
-
-	m_angle_x(0),
-	m_angle_y(0),
-
-	m_up_pressed(false),
-	m_right_pressed(false),
-	m_down_pressed(false),
-	m_left_pressed(false)
-{
-	device()->input_manager()->register_keyboard_listener(this);
-	device()->input_manager()->register_accelerometer_listener(this);
-	//device()->input_manager()->register_mouse_listener(this);
-	device()->mouse()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
-	
-}
-
-//-----------------------------------------------------------------------
-void FPSSystem::key_pressed(const KeyboardEvent& event)
-{
-	switch (event.key)
-	{
-		case 'w':
-		case 'W':
-		{
-			m_up_pressed = true;
-			break;
-		}
-		case 'a':
-		case 'A':
-		{
-			m_left_pressed = true;
-			break;
-		}
-		case 's':
-		case 'S':
-		{
-			m_down_pressed = true;
-			break;
-		}
-		case 'd':
-		case 'D':
-		{
-			m_right_pressed = true;
-			break;
-		}
-		default:
-		{
-			break;
-		}
-	}
-}
-
-//-----------------------------------------------------------------------
-void FPSSystem::key_released(const KeyboardEvent& event)
-{
-	switch (event.key)
-	{
-		case 'w':
-		case 'W':
-		{
-			m_up_pressed = false;
-			break;
-		}
-		case 'a':
-		case 'A':
-		{
-			m_left_pressed = false;
-			break;
-		}
-		case 's':
-		case 'S':
-		{
-			m_down_pressed = false;
-			break;
-		}
-		case 'd':
-		case 'D':
-		{
-			m_right_pressed = false;
-			break;
-		}
-		default:
-		{
-			break;
-		}
-	}
-}
-
-//-----------------------------------------------------------------------
-void FPSSystem::accelerometer_changed(const AccelerometerEvent& event)
-{
-	(void)event;
-	set_view_by_cursor();
-}
-//-----------------------------------------------------------------------
-void FPSSystem::set_camera(Camera* camera)
-{
-	m_camera = camera;
-}
-
-//-----------------------------------------------------------------------
-Camera* FPSSystem::camera()
-{
-	return m_camera;
-}
-
-//-----------------------------------------------------------------------
-void FPSSystem::update(float dt)
-{
-	if (m_up_pressed)
-	{
-		m_camera->move_forward(m_camera_speed * dt);
-	}
-
-	if (m_left_pressed)
-	{
-		m_camera->strafe_left(m_camera_speed * dt);
-	}		
-
-	if (m_down_pressed)
-	{
-		m_camera->move_backward(m_camera_speed * dt);
-	}
-
-	if (m_right_pressed)
-	{
-		m_camera->strafe_right(m_camera_speed * dt);
-	}
-
-	// device()->renderer()->set_matrix(MT_VIEW, m_camera->view_matrix());
-	// device()->renderer()->set_matrix(MT_PROJECTION, m_camera->projection_matrix());
-}
-
-//-----------------------------------------------------------------------	
-void FPSSystem::set_view_by_cursor()
-{
-	static Vec2 lastPos = device()->mouse()->cursor_relative_xy();
-	Vec2 currentPos = device()->mouse()->cursor_relative_xy();
-	device()->mouse()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
-
-	if (lastPos == currentPos)
-	{
-		return;
-	}
-
-	Vec2 delta = lastPos - currentPos;
-
-	device()->mouse()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
-	lastPos = device()->mouse()->cursor_relative_xy();
-
-	m_angle_x += delta.y * m_camera_sensibility;
-	m_angle_y += delta.x * m_camera_sensibility;
-
-	m_angle_x = math::clamp_to_range(-89.999f * math::DEG_TO_RAD, 89.999f * math::DEG_TO_RAD, m_angle_x);
-	m_angle_y = math::fmod(m_angle_y, math::TWO_PI);
-
-	m_camera->set_rotation(m_angle_x, m_angle_y);
-}
-
-} // namespace crown
-

+ 0 - 74
engine/FPSSystem.h

@@ -1,74 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "Camera.h"
-#include "Vec2.h"
-#include "Mouse.h"
-#include "Keyboard.h"
-#include "Touch.h"
-#include "Accelerometer.h"
-#include "Renderer.h"
-
-namespace crown
-{
-/// TODO: set_view_by_cursor must be implemented through scripting
-class FPSSystem : public MouseListener, public KeyboardListener, public AccelerometerListener
-{
-public:
-
-					/// Constructor
-					FPSSystem(Camera* camera, float speed, float sensibility);
-
-	void 			set_camera(Camera* camera);
-	Camera*			camera();
-
-	void			update(float dt);
-	void			set_view_by_cursor();	
-
-	virtual void 	key_pressed(const KeyboardEvent& event);
-	virtual void 	key_released(const KeyboardEvent& event);
-	virtual void 	accelerometer_changed(const AccelerometerEvent& event);
-
-private:
-
-	Camera*			m_camera;
-
-	float			m_camera_speed;
-	float			m_camera_sensibility;
-
-	float 			m_angle_x;
-	float 			m_angle_y;
-
-	bool			m_up_pressed	: 1;
-	bool			m_right_pressed	: 1;
-	bool			m_down_pressed	: 1;
-	bool			m_left_pressed	: 1;
-};
-
-} // namespace crown

+ 30 - 19
engine/compilers/BundleCompiler.cpp

@@ -45,34 +45,44 @@ BundleCompiler::BundleCompiler()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir)
+bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir, const char* resource)
 {
 {
 	Vector<DynamicString> files(default_allocator());
 	Vector<DynamicString> files(default_allocator());
-	BundleCompiler::scan(source_dir, "", files);
 
 
-	// Create bundle dir if does not exist
-	DiskFilesystem temp;
-	if (!temp.is_directory(bundle_dir) || !temp.is_file(bundle_dir))
+	if (resource == NULL)
 	{
 	{
-		temp.create_directory(bundle_dir);
-	}
+		BundleCompiler::scan(source_dir, "", files);
+
+		// Create bundle dir if does not exist
+		DiskFilesystem temp;
+		if (!temp.is_directory(bundle_dir) || !temp.is_file(bundle_dir))
+		{
+			temp.create_directory(bundle_dir);
+		}
 
 
-	// Copy crown.config to bundle dir
-	DiskFilesystem src_fs(source_dir);
-	DiskFilesystem dst_fs(bundle_dir);
+		// Copy crown.config to bundle dir
+		DiskFilesystem src_fs(source_dir);
+		DiskFilesystem dst_fs(bundle_dir);
 
 
-	if (src_fs.is_file("crown.config"))
-	{
-		File* src = src_fs.open("crown.config", FOM_READ);
-		File* dst = dst_fs.open("crown.config", FOM_WRITE);
-		src->copy_to(*dst, src->size());
-		src_fs.close(src);
-		dst_fs.close(dst);
+		if (src_fs.is_file("crown.config"))
+		{
+			File* src = src_fs.open("crown.config", FOM_READ);
+			File* dst = dst_fs.open("crown.config", FOM_WRITE);
+			src->copy_to(*dst, src->size());
+			src_fs.close(src);
+			dst_fs.close(dst);
+		}
+		else
+		{
+			Log::d("'crown.config' does not exist.");
+			return false;
+		}
 	}
 	}
 	else
 	else
 	{
 	{
-		Log::d("'crown.config' does not exist.");
-		return false;
+		DynamicString filename(default_allocator());
+		filename = resource;
+		files.push_back(filename);
 	}
 	}
 
 
 	// Compile all resources
 	// Compile all resources
@@ -96,6 +106,7 @@ bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir)
 		}
 		}
 
 
 		Log::i("%s <= %s", out_name, filename);
 		Log::i("%s <= %s", out_name, filename);
+		Log::flush();
 
 
 		bool result = false;
 		bool result = false;
 		if (resource_type_hash == MESH_TYPE)
 		if (resource_type_hash == MESH_TYPE)

+ 2 - 2
engine/compilers/BundleCompiler.h

@@ -37,13 +37,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class BundleCompiler
+class CE_EXPORT BundleCompiler
 {
 {
 public:
 public:
 
 
 	BundleCompiler();
 	BundleCompiler();
 
 
-	bool compile(const char* bundle_dir, const char* source_dir);
+	bool compile(const char* bundle_dir, const char* source_dir, const char* resource = NULL);
 
 
 private:
 private:
 
 

+ 1 - 1
engine/compilers/lua/LuaCompiler.h

@@ -31,7 +31,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class LuaCompiler : public Compiler
+class CE_EXPORT LuaCompiler : public Compiler
 {
 {
 public:
 public:
 
 

+ 1 - 1
engine/compilers/mesh/MeshCompiler.h

@@ -49,7 +49,7 @@ struct MeshVertex
 	}
 	}
 };
 };
 
 
-class MeshCompiler : public Compiler
+class CE_EXPORT MeshCompiler : public Compiler
 {
 {
 public:
 public:
 
 

+ 1 - 1
engine/compilers/package/PackageCompiler.h

@@ -33,7 +33,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class PackageCompiler : public Compiler
+class CE_EXPORT PackageCompiler : public Compiler
 {
 {
 public:
 public:
 
 

+ 1 - 1
engine/compilers/texture/TextureCompiler.h

@@ -47,7 +47,7 @@ struct TGAHeader
 	char		image_descriptor;	// 11h  Image descriptor byte
 	char		image_descriptor;	// 11h  Image descriptor byte
 };
 };
 
 
-class TextureCompiler : public Compiler
+class CE_EXPORT TextureCompiler : public Compiler
 {
 {
 public:
 public:
 
 

+ 1 - 1
engine/core/Args.h

@@ -55,7 +55,7 @@ struct ArgsOption
 };
 };
 
 
 /// Parses the command line arguments in a way very similar to GNU getopt.
 /// Parses the command line arguments in a way very similar to GNU getopt.
-class Args
+class CE_EXPORT Args
 {
 {
 public:
 public:
 
 

+ 3 - 1
engine/core/Assert.h

@@ -35,9 +35,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 	#define CE_ASSERT(condition, ...) do { if (!(condition)) {\
 	#define CE_ASSERT(condition, ...) do { if (!(condition)) {\
 		crown::Log::e("Assertion failed: %s", #condition);\
 		crown::Log::e("Assertion failed: %s", #condition);\
 		crown::Log::e("\t" __VA_ARGS__);\
 		crown::Log::e("\t" __VA_ARGS__);\
-		crown::Log::e("\n\tIn %s:%d\n\n", __FILE__, __LINE__); abort();} } while (0)
+		crown::Log::e("\n\tIn %s:%d\n\n", __FILE__, __LINE__);\
+		crown::Log::flush(); abort();} } while (0)
 #else
 #else
 	#define CE_ASSERT(...) ((void)0)
 	#define CE_ASSERT(...) ((void)0)
 #endif
 #endif
 
 
 #define CE_ASSERT_NOT_NULL(x) CE_ASSERT(x != NULL, "Parameter must be not null")
 #define CE_ASSERT_NOT_NULL(x) CE_ASSERT(x != NULL, "Parameter must be not null")
+#define CE_FATAL(msg) CE_ASSERT(false, msg)

+ 4 - 3
engine/core/Log.cpp

@@ -27,6 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Log.h"
 #include "Log.h"
 #include "LinearAllocator.h"
 #include "LinearAllocator.h"
 #include "StringStream.h"
 #include "StringStream.h"
+#include "Device.h"
 #include "RPCServer.h"
 #include "RPCServer.h"
 
 
 namespace crown
 namespace crown
@@ -111,14 +112,14 @@ void Log::i(const char* message, ...)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void Log::flush(RPCServer* server)
+void Log::flush()
 {
 {
 	os::printf(g_stream.c_str());
 	os::printf(g_stream.c_str());
 	::fflush(stdout);
 	::fflush(stdout);
 
 
-	if (server != NULL)
+	if (device()->rpc() != NULL)
 	{
 	{
-		server->send_message_to_all(g_stream.c_str());
+		device()->rpc()->send_message_to_all(g_stream.c_str());
 	}
 	}
 
 
 	g_stream.clear();
 	g_stream.clear();

+ 2 - 2
engine/core/Log.h

@@ -45,7 +45,7 @@ enum LogLevel
 class RPCServer;
 class RPCServer;
 
 
 /// Used to log messages.
 /// Used to log messages.
-class Log
+class CE_EXPORT Log
 {
 {
 
 
 public:
 public:
@@ -63,7 +63,7 @@ public:
 	static void			w(const char* message, ...);
 	static void			w(const char* message, ...);
 	static void			i(const char* message, ...);
 	static void			i(const char* message, ...);
 
 
-	static void			flush(RPCServer* server);
+	static void			flush();
 
 
 private:
 private:
 
 

+ 2 - 0
engine/core/Types.h

@@ -33,8 +33,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #ifdef WINDOWS
 #ifdef WINDOWS
 	#define CE_EXPORT __declspec(dllexport)
 	#define CE_EXPORT __declspec(dllexport)
+	#define CE_INLINE __inline
 #else
 #else
 	#define CE_EXPORT __attribute__ ((visibility("default")))
 	#define CE_EXPORT __attribute__ ((visibility("default")))
+	#define CE_INLINE inline
 #endif
 #endif
 
 
 #ifndef NULL
 #ifndef NULL

+ 47 - 4
engine/core/containers/Queue.h

@@ -75,18 +75,24 @@ public:
 	/// time of call.
 	/// time of call.
 	void			grow(uint32_t min_capacity);
 	void			grow(uint32_t min_capacity);
 
 
-	/// Adds an @a item to the back of the queue
+	/// Appends an @a item to the back of the queue
 	void			push_back(const T& item);
 	void			push_back(const T& item);
 
 
 	/// Removes the last item from the queue
 	/// Removes the last item from the queue
 	void			pop_back();
 	void			pop_back();
 
 
-	/// Adds an @a item to the front of the queue
+	/// Appends an @a item to the front of the queue
 	void			push_front(const T& item);
 	void			push_front(const T& item);
 
 
 	/// Removes the first item from the queue
 	/// Removes the first item from the queue
 	void			pop_front();
 	void			pop_front();
-	
+
+	/// Appends @a n @a items to the back of the queue
+	void			push(const T *items, uint32_t n);
+
+	/// Removes @a n items from the front of the queue
+	void			pop(uint32_t n);
+
 	/// Clears the content of the queue.
 	/// Clears the content of the queue.
 	/// @note
 	/// @note
 	/// Does not free memory nor call destructors, it only zeroes
 	/// Does not free memory nor call destructors, it only zeroes
@@ -236,10 +242,47 @@ inline void Queue<T>::pop_front()
 	CE_ASSERT(m_size > 0, "The queue is empty");
 	CE_ASSERT(m_size > 0, "The queue is empty");
 
 
 	m_read = (m_read + 1) % m_queue.size();
 	m_read = (m_read + 1) % m_queue.size();
-
 	m_size--;
 	m_size--;
 }
 }
 
 
+//-----------------------------------------------------------------------------
+template <typename T>
+inline void Queue<T>::push(const T *items, uint32_t n)
+{
+	if (space() < n)
+	{
+		grow(size() + n);		
+	}
+
+	const uint32_t size = m_queue.size();
+	const uint32_t insert = (m_read + m_size) % size;
+
+	uint32_t to_insert = n;
+	if (insert + to_insert > size)
+	{
+		to_insert = size - insert;
+	}
+
+	memcpy(m_queue.begin() + insert, items, to_insert * sizeof(T));
+
+	m_size += to_insert;
+	items += to_insert;
+	n -= to_insert;
+	memcpy(m_queue.begin(), items, n * sizeof(T));
+
+	m_size += n;
+}
+
+//-----------------------------------------------------------------------------
+template <typename T>
+inline void Queue<T>::pop(uint32_t n)
+{
+	CE_ASSERT(m_size > 0, "The queue is empty");
+
+	m_read = (m_read + n) % m_queue.size();
+	m_size -= n;
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T>
 template <typename T>
 inline void Queue<T>::clear()
 inline void Queue<T>::clear()

+ 1 - 1
engine/core/mem/Allocator.h

@@ -59,7 +59,7 @@ private:
 	Allocator&			operator=(const Allocator&);
 	Allocator&			operator=(const Allocator&);
 };
 };
 
 
-Allocator& default_allocator();
+CE_EXPORT Allocator& default_allocator();
 
 
 /// Respects standard behaviour when calling on NULL @a ptr
 /// Respects standard behaviour when calling on NULL @a ptr
 template <typename T>
 template <typename T>

+ 2 - 2
engine/core/mem/Memory.h

@@ -40,12 +40,12 @@ const size_t	DEFAULT_ALIGN	= 4;			//!< Default memory alignment in bytes
 /// Constructs the initial default allocators.
 /// Constructs the initial default allocators.
 /// @note
 /// @note
 /// Has to be called before anything else during the engine startup.
 /// Has to be called before anything else during the engine startup.
-void init();
+CE_EXPORT void init();
 
 
 /// Destroys the allocators created with memory::init().
 /// Destroys the allocators created with memory::init().
 /// @note
 /// @note
 /// Should be the last call of the program.
 /// Should be the last call of the program.
-void shutdown();
+CE_EXPORT void shutdown();
 
 
 /// Returns the pointer @a p aligned to the desired @a align byte
 /// Returns the pointer @a p aligned to the desired @a align byte
 inline void* align_top(void* p, size_t align)
 inline void* align_top(void* p, size_t align)

+ 1 - 1
engine/core/mem/ProxyAllocator.h

@@ -36,7 +36,7 @@ namespace crown
 /// Offers the facility to tag allocators by a string identifier.
 /// Offers the facility to tag allocators by a string identifier.
 /// Proxy allocator is appended to a global linked list when instantiated
 /// Proxy allocator is appended to a global linked list when instantiated
 /// so that it is possible to later visit that list for debugging purposes.
 /// so that it is possible to later visit that list for debugging purposes.
-class ProxyAllocator : public Allocator
+class CE_EXPORT ProxyAllocator : public Allocator
 {
 {
 public:
 public:
 
 

+ 11 - 24
engine/input/Accelerometer.h

@@ -32,38 +32,25 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class InputManager;
-
-struct AccelerometerEvent
-{
-	float x;
-	float y;
-	float z;
-};
-
-class AccelerometerListener
-{
-public:
-
-	virtual void accelerometer_changed(const AccelerometerEvent& event) { (void)event; }
-};
-
 /// Interface for accessing accelerometer input device.
 /// Interface for accessing accelerometer input device.
-class Accelerometer
+struct Accelerometer
 {
 {
-public:
-	
-					Accelerometer();
+	//-----------------------------------------------------------------------------
+	Accelerometer()
+		: m_orientation(0.0f, 0.0f, 0.0f)
+	{
+	}
 
 
 	/// Returns the orientation of the accelerometer.
 	/// Returns the orientation of the accelerometer.
 	/// FIXME NEED MORE DOCUMENTATION
 	/// FIXME NEED MORE DOCUMENTATION
-	const Vec3&		orientation() const;
+	const Vec3& orientation() const
+	{
+		return m_orientation;
+	}
 
 
-private:
+public:
 
 
 	Vec3			m_orientation;
 	Vec3			m_orientation;
-
-	friend class	InputManager;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 178
engine/input/EventDispatcher.cpp

@@ -1,178 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "EventDispatcher.h"
-#include "Allocator.h"
-#include "Log.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-EventDispatcher::EventDispatcher() :
-	m_mouse_listener_list(default_allocator()),
-	m_keyboard_listener_list(default_allocator()),
-	m_touch_listener_list(default_allocator()),
-	m_acc_listener_list(default_allocator())
-{
-}
-
-//-----------------------------------------------------------------------------
-EventDispatcher::~EventDispatcher()
-{
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::add_mouse_listener(MouseListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-
-	m_mouse_listener_list.push_back(listener);
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::add_keyboard_listener(KeyboardListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-
-	m_keyboard_listener_list.push_back(listener);
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::add_touch_listener(TouchListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-
-	m_touch_listener_list.push_back(listener);
-}
-
-void EventDispatcher::add_accelerometer_listener(AccelerometerListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-	m_acc_listener_list.push_back(listener);
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::button_pressed(const MouseEvent& event)
-{
-	for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
-	{
-		m_mouse_listener_list[i]->button_pressed(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::button_released(const MouseEvent& event)
-{
-	for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
-	{
-		m_mouse_listener_list[i]->button_released(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::cursor_moved(const MouseEvent& event)
-{
-	for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
-	{
-		m_mouse_listener_list[i]->cursor_moved(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::key_pressed(const KeyboardEvent& event)
-{
-	for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
-	{
-		m_keyboard_listener_list[i]->key_pressed(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::key_released(const KeyboardEvent& event)
-{
-	for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
-	{
-		m_keyboard_listener_list[i]->key_released(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::text_input(const KeyboardEvent& event)
-{
-	for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
-	{
-		m_keyboard_listener_list[i]->text_input(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_down(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_down(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_up(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_up(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_move(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_move(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_cancel(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_cancel(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::accelerometer_changed(const AccelerometerEvent& event)
-{
-	for (uint32_t i = 0; i < m_acc_listener_list.size(); i++)
-	{
-		m_acc_listener_list[i]->accelerometer_changed(event);
-	}
-}
-
-} // namespace crown
-

+ 0 - 79
engine/input/EventDispatcher.h

@@ -1,79 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "List.h"
-#include "Mouse.h"
-#include "Keyboard.h"
-#include "Touch.h"
-#include "Accelerometer.h"
-
-namespace crown
-{
-
-class EventDispatcher
-{
-	typedef List<MouseListener*>			MouseListenerList;
-	typedef List<KeyboardListener*>			KeyboardListenerList;
-	typedef List<TouchListener*>			TouchListenerList;
-	typedef List<AccelerometerListener*>	AccelerometerListenerList;
-
-public:
-
-	EventDispatcher();
-	~EventDispatcher();
-
-	void add_mouse_listener(MouseListener* listener);
-	void add_keyboard_listener(KeyboardListener* listener);
-	void add_touch_listener(TouchListener* listener);
-	void add_accelerometer_listener(AccelerometerListener* listener);
-
-	void button_pressed(const MouseEvent&);
-	void button_released(const MouseEvent&);
-	void cursor_moved(const MouseEvent&);
-
-	void key_pressed(const KeyboardEvent&);
-	void key_released(const KeyboardEvent&);
-	void text_input(const KeyboardEvent&);
-
-	void touch_down(const TouchEvent& event);
-	void touch_up(const TouchEvent& event);
-	void touch_move(const TouchEvent& event);
-	void touch_cancel(const TouchEvent& event);
-
-	void accelerometer_changed(const AccelerometerEvent& event);
-
-private:
-
-	MouseListenerList			m_mouse_listener_list;
-	KeyboardListenerList		m_keyboard_listener_list;
-	TouchListenerList			m_touch_listener_list;
-	AccelerometerListenerList	m_acc_listener_list;
-};
-
-} // namespace crown
-

+ 0 - 237
engine/input/InputManager.cpp

@@ -1,237 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "InputManager.h"
-#include "OS.h"
-#include "Log.h"
-#include "EventBuffer.h"
-#include "OsEvents.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-InputManager::InputManager()
-{
-}
-
-//-----------------------------------------------------------------------------
-InputManager::~InputManager()
-{
-}
-
-//-----------------------------------------------------------------------------
-Keyboard* InputManager::keyboard()
-{
-	return &m_keyboard;
-}
-
-//-----------------------------------------------------------------------------
-Mouse* InputManager::mouse()
-{
-	return &m_mouse;
-}
-
-//-----------------------------------------------------------------------------
-Touch* InputManager::touch()
-{
-	return &m_touch;
-}
-
-//-----------------------------------------------------------------------------
-Accelerometer* InputManager::accelerometer()
-{
-	return &m_accelerometer;
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_mouse_listener(MouseListener* listener)
-{
-	m_event_dispatcher.add_mouse_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_keyboard_listener(KeyboardListener* listener)
-{
-	m_event_dispatcher.add_keyboard_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_touch_listener(TouchListener* listener)
-{
-	m_event_dispatcher.add_touch_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_accelerometer_listener(AccelerometerListener* listener)
-{
-	m_event_dispatcher.add_accelerometer_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-EventDispatcher* InputManager::get_event_dispatcher()
-{
-	return &m_event_dispatcher;
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::frame(uint64_t frame_count)
-{
-	void* event;
-	uint32_t event_type;
-	size_t event_size;
-
-	// Update input devices
-	m_keyboard.m_current_frame = frame_count;
-	m_mouse.m_current_frame = frame_count;
-
-	while (1)
-	{
-		if ((event = os_event_buffer()->get_next_event(event_type, event_size)) == NULL)
-		{
-			break;
-		}
-
-		switch (event_type)
-		{
-			case OSET_NONE:
-			{
-				return;
-			}
-			case OSET_BUTTON_PRESS:
-			case OSET_BUTTON_RELEASE:
-			{
-				MouseEvent mouse_event;
-				mouse_event.x = ((OsMouseEvent*)event)->x;
-				mouse_event.y = ((OsMouseEvent*)event)->y;
-				mouse_event.button = ((OsMouseEvent*)event)->button == 0 ? MB_LEFT : ((OsMouseEvent*)event)->button == 1 ? MB_MIDDLE : MB_RIGHT;
-				mouse_event.wheel = 0.0f;
-
-				if (event_type == OSET_BUTTON_PRESS)
-				{
-					m_mouse.update(frame_count, mouse_event.button, true);
-					m_event_dispatcher.button_pressed(mouse_event);
-				}
-				else
-				{
-					m_mouse.update(frame_count, mouse_event.button, false);
-					m_event_dispatcher.button_released(mouse_event);
-				}
-
-				break;
-			}
-			case OSET_KEY_PRESS:
-			case OSET_KEY_RELEASE:
-			{
-				KeyboardEvent keyboard_event;
-				keyboard_event.key = (KeyCode) ((OsKeyboardEvent*)event)->key;
-				keyboard_event.modifier = (uint8_t) ((OsKeyboardEvent*)event)->modifier;
-
-				m_keyboard.m_modifier = keyboard_event.modifier;
-
-				if (event_type == OSET_KEY_PRESS)
-				{
-					m_keyboard.update(frame_count, keyboard_event.key, true);
-					m_event_dispatcher.key_pressed(keyboard_event);
-				}
-				else
-				{
-					m_keyboard.update(frame_count, keyboard_event.key, false);
-					m_event_dispatcher.key_released(keyboard_event);
-				}
-
-				break;
-			}
-			case OSET_TOUCH_DOWN:
-			case OSET_TOUCH_UP:
-			{
-				TouchEvent touch_event;
-				touch_event.pointer_id = ((OsTouchEvent*)event)->pointer_id;
-				touch_event.x = ((OsTouchEvent*)event)->x;
-				touch_event.y = ((OsTouchEvent*)event)->y;
-
-				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
-				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;
-
-				// FIXME
-				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
-				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;
-
-				if (event_type == OSET_TOUCH_DOWN)
-				{
-					m_touch.m_pointers[touch_event.pointer_id].up = false;
-					m_event_dispatcher.touch_down(touch_event);
-				}
-				else
-				{
-					m_touch.m_pointers[touch_event.pointer_id].up = true;
-					m_event_dispatcher.touch_up(touch_event);
-				}
-
-				break;
-			}
-			case OSET_TOUCH_MOVE:
-			{
-				TouchEvent touch_event;
-				touch_event.pointer_id = ((OsTouchEvent*)event)->pointer_id;
-				touch_event.x = ((OsTouchEvent*)event)->x;
-				touch_event.y = ((OsTouchEvent*)event)->y;
-
-				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
-				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;
-
-				// FIXME
-				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
-				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;
-
-				m_event_dispatcher.touch_move(touch_event);
-
-				break;
-			}
-			// case OSET_ACCELEROMETER:
-			// {
-			// 	AccelerometerEvent sensor_event;
-			// 	sensor_event.x = event.data_a.float_value;
-			// 	sensor_event.y = event.data_b.float_value;
-			// 	sensor_event.z = event.data_c.float_value;
-
-			// 	m_accelerometer.m_orientation.x = sensor_event.x;
-			// 	m_accelerometer.m_orientation.y = sensor_event.y;
-			// 	m_accelerometer.m_orientation.z = sensor_event.z;
-
-			// 	m_event_dispatcher.accelerometer_changed(sensor_event);
-			// 	break;
-			// }
-			default:
-			{
-				break;
-			}
-		}
-	}
-}
-
-} // namespace crown
-

+ 0 - 74
engine/input/InputManager.h

@@ -1,74 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "EventDispatcher.h"
-#include "Mouse.h"
-#include "Keyboard.h"
-#include "Touch.h"
-#include "Accelerometer.h"
-
-namespace crown
-{
-
-class MouseListener;
-class KeyboardListener;
-class TouchListener;
-
-class InputManager
-{
-public:
-
-						InputManager();
-						~InputManager();
-
-	Keyboard*			keyboard();
-	Mouse*				mouse();
-	Touch*				touch();
-	Accelerometer*		accelerometer();
-
-	void				register_mouse_listener(MouseListener* listener);
-	void				register_keyboard_listener(KeyboardListener* listener);
-	void				register_touch_listener(TouchListener* listener);
-	void				register_accelerometer_listener(AccelerometerListener* listener);
-
-	EventDispatcher*	get_event_dispatcher();
-
-	void				frame(uint64_t frame_count);
-
-private:
-
-	EventDispatcher		m_event_dispatcher;
-
-	Keyboard			m_keyboard;
-	Mouse				m_mouse;
-	Touch				m_touch;
-	Accelerometer		m_accelerometer;
-};
-
-} // namespace crown
-

+ 129 - 131
engine/input/KeyCode.h

@@ -29,138 +29,136 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-const uint16_t MAX_KEYCODES = 256;
-
-typedef uint8_t Key;
-
-/// A KeyCode is the number which uniquely identifies a key
-/// on the keyboard.
-enum KeyCode
+/// Uniquely identifies a button on the keyboard.
+struct KeyboardButton
 {
 {
-	KC_NOKEY		= 0x00,
-
-	KC_TAB			= 0x09,		// ASCII value
-	KC_ENTER		= 0x0D,		// ASCII value
-	KC_ESCAPE		= 0x1B,		// ASCII value
-	KC_SPACE		= 0x20,		// ASCII value
-	KC_BACKSPACE	= 0x7F,		// ASCII value
-
-	/* KeyPad */
-	KC_KP_0			= 0x80,
-	KC_KP_1			= 0x81,
-	KC_KP_2			= 0x82,
-	KC_KP_3			= 0x83,
-	KC_KP_4			= 0x84,
-	KC_KP_5			= 0x85,
-	KC_KP_6			= 0x86,
-	KC_KP_7			= 0x87,
-	KC_KP_8			= 0x88,
-	KC_KP_9			= 0x89,
-
-	/* Function keys */
-	KC_F1			= 0x90,
-	KC_F2			= 0x91,
-	KC_F3			= 0x92,
-	KC_F4			= 0x93,
-	KC_F5			= 0x94,
-	KC_F6			= 0x95,
-	KC_F7			= 0x96,
-	KC_F8			= 0x97,
-	KC_F9			= 0x98,
-	KC_F10			= 0x99,
-	KC_F11			= 0x9A,
-	KC_F12			= 0x9B,
-
-	/* Other keys */
-	KC_HOME			= 0xA0,
-	KC_LEFT			= 0xA1,
-	KC_UP			= 0xA2,
-	KC_RIGHT		= 0xA3,
-	KC_DOWN			= 0xA4,
-	KC_PAGE_UP		= 0xA5,
-	KC_PAGE_DOWN	= 0xA6,
-
-	/* Modifier keys */
-	KC_LCONTROL		= 0xB0,
-	KC_RCONTROL		= 0xB1,
-	KC_LSHIFT		= 0xB2,
-	KC_RSHIFT		= 0xB3,
-	KC_CAPS_LOCK	= 0xB4,
-	KC_LALT			= 0xB5,
-	KC_RALT			= 0xB6,
-	KC_LSUPER		= 0xB7,
-	KC_RSUPER		= 0xB8,
-
-	/* [0x30, 0x39] reserved for ASCII digits */
-	KC_0			= 0x30,
-	KC_1			= 0x31,
-	KC_2			= 0x32,
-	KC_3			= 0x33,
-	KC_4			= 0x34,
-	KC_5			= 0x35,
-	KC_6			= 0x36,
-	KC_7			= 0x37,
-	KC_8			= 0x38,
-	KC_9			= 0x39,
-
-	/* [0x41, 0x5A] reserved for ASCII alphabet */
-	KC_A			= 0x41,
-	KC_B			= 0x42,
-	KC_C			= 0x43,
-	KC_D			= 0x44,
-	KC_E			= 0x45,
-	KC_F			= 0x46,
-	KC_G			= 0x47,
-	KC_H			= 0x48,
-	KC_I			= 0x49,
-	KC_J			= 0x4A,
-	KC_K			= 0x4B,
-	KC_L			= 0x4C,
-	KC_M			= 0x4D,
-	KC_N			= 0x4E,
-	KC_O			= 0x4F,
-	KC_P			= 0x50,
-	KC_Q			= 0x51,
-	KC_R			= 0x52,
-	KC_S			= 0x53,
-	KC_T			= 0x54,
-	KC_U			= 0x55,
-	KC_V			= 0x56,
-	KC_W			= 0x57,
-	KC_X			= 0x58,
-	KC_Y			= 0x59,
-	KC_Z			= 0x5A,
-
-	/* [0x61, 0x7A] reserved for ASCII alphabet */
-	KC_a			= 0x61,
-	KC_b			= 0x62,
-	KC_c			= 0x63,
-	KC_d			= 0x64,
-	KC_e			= 0x65,
-	KC_f			= 0x66,
-	KC_g			= 0x67,
-	KC_h			= 0x68,
-	KC_i			= 0x69,
-	KC_j			= 0x6A,
-	KC_k			= 0x6B,
-	KC_l			= 0x6C,
-	KC_m			= 0x6D,
-	KC_n			= 0x6E,
-	KC_o			= 0x6F,
-	KC_p			= 0x70,
-	KC_q			= 0x71,
-	KC_r			= 0x72,
-	KC_s			= 0x73,
-	KC_t			= 0x74,
-	KC_u			= 0x75,
-	KC_v			= 0x76,
-	KC_w			= 0x77,
-	KC_x			= 0x78,
-	KC_y			= 0x79,
-	KC_z			= 0x7A,
-
-	// The last key _must_ be <= 0xFF
-	KC_COUNT		= 0xFF
+	enum Enum
+	{
+		NONE		= 0x00,
+
+		TAB			= 0x09,		// ASCII value
+		ENTER		= 0x0D,		// ASCII value
+		ESCAPE		= 0x1B,		// ASCII value
+		SPACE		= 0x20,		// ASCII value
+		BACKSPACE	= 0x7F,		// ASCII value
+
+		/* KeyPad */
+		KP_0		= 0x80,
+		KP_1		= 0x81,
+		KP_2		= 0x82,
+		KP_3		= 0x83,
+		KP_4		= 0x84,
+		KP_5		= 0x85,
+		KP_6		= 0x86,
+		KP_7		= 0x87,
+		KP_8		= 0x88,
+		KP_9		= 0x89,
+
+		/* Function keys */
+		F1			= 0x90,
+		F2			= 0x91,
+		F3			= 0x92,
+		F4			= 0x93,
+		F5			= 0x94,
+		F6			= 0x95,
+		F7			= 0x96,
+		F8			= 0x97,
+		F9			= 0x98,
+		F10			= 0x99,
+		F11			= 0x9A,
+		F12			= 0x9B,
+
+		/* Other keys */
+		HOME		= 0xA0,
+		LEFT		= 0xA1,
+		UP			= 0xA2,
+		RIGHT		= 0xA3,
+		DOWN		= 0xA4,
+		PAGE_UP		= 0xA5,
+		PAGE_DOWN	= 0xA6,
+
+		/* Modifier keys */
+		LCONTROL	= 0xB0,
+		RCONTROL	= 0xB1,
+		LSHIFT		= 0xB2,
+		RSHIFT		= 0xB3,
+		CAPS_LOCK	= 0xB4,
+		LALT		= 0xB5,
+		RALT		= 0xB6,
+		LSUPER		= 0xB7,
+		RSUPER		= 0xB8,
+
+		/* [0x30, 0x39] reserved for ASCII digits */
+		NUM_0		= 0x30,
+		NUM_1		= 0x31,
+		NUM_2		= 0x32,
+		NUM_3		= 0x33,
+		NUM_4		= 0x34,
+		NUM_5		= 0x35,
+		NUM_6		= 0x36,
+		NUM_7		= 0x37,
+		NUM_8		= 0x38,
+		NUM_9		= 0x39,
+
+		/* [0x41, 0x5A] reserved for ASCII alphabet */
+		A			= 0x41,
+		B			= 0x42,
+		C			= 0x43,
+		D			= 0x44,
+		E			= 0x45,
+		F			= 0x46,
+		G			= 0x47,
+		H			= 0x48,
+		I			= 0x49,
+		J			= 0x4A,
+		K			= 0x4B,
+		L			= 0x4C,
+		M			= 0x4D,
+		N			= 0x4E,
+		O			= 0x4F,
+		P			= 0x50,
+		Q			= 0x51,
+		R			= 0x52,
+		S			= 0x53,
+		T			= 0x54,
+		U			= 0x55,
+		V			= 0x56,
+		W			= 0x57,
+		X			= 0x58,
+		Y			= 0x59,
+		Z			= 0x5A,
+
+		/* [0x61, 0x7A] reserved for ASCII alphabet */
+		a			= 0x61,
+		b			= 0x62,
+		c			= 0x63,
+		d			= 0x64,
+		e			= 0x65,
+		f			= 0x66,
+		g			= 0x67,
+		h			= 0x68,
+		i			= 0x69,
+		j			= 0x6A,
+		k			= 0x6B,
+		l			= 0x6C,
+		m			= 0x6D,
+		n			= 0x6E,
+		o			= 0x6F,
+		p			= 0x70,
+		q			= 0x71,
+		r			= 0x72,
+		s			= 0x73,
+		t			= 0x74,
+		u			= 0x75,
+		v			= 0x76,
+		w			= 0x77,
+		x			= 0x78,
+		y			= 0x79,
+		z			= 0x7A,
+
+		// The last key _must_ be <= 0xFF
+		COUNT		= 0xFF
+	};
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 90
engine/input/Keyboard.cpp

@@ -1,90 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Keyboard.h"
-#include "Assert.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Keyboard::Keyboard() :
-	m_modifier(0),
-	m_current_frame(0),
-	m_last_key(KC_NOKEY)
-{
-	for (uint32_t i = 0; i < MAX_KEYCODES; i++)
-	{
-		m_keys[i] = ~0;
-		m_state[i] = false;
-	}
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::modifier_pressed(ModifierKey modifier) const
-{
-	return (m_modifier & modifier) == modifier;
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::key_pressed(KeyCode key) const
-{
-	CE_ASSERT(key >= 0 && key < MAX_KEYCODES, "KeyCode out of range: %d", key);
-
-	return (m_state[key] == true) && (m_keys[key] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::key_released(KeyCode key) const
-{
-	CE_ASSERT(key >= 0 && key < MAX_KEYCODES, "KeyCode out of range: %d", key);
-
-	return (m_state[key] == false) && (m_keys[key] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::any_pressed() const
-{
-	return key_pressed(m_last_key);
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::any_released() const
-{
-	return key_released(m_last_key);
-}
-
-//-----------------------------------------------------------------------------
-void Keyboard::update(uint64_t frame, KeyCode k, bool state)
-{
-	CE_ASSERT(k >= 0 && k < MAX_KEYCODES, "KeyCode out of range: %d", k);
-
-	m_last_key = k;
-	m_keys[k] = frame;
-	m_state[k] = state;
-}
-
-} // namespace crown

+ 62 - 59
engine/input/Keyboard.h

@@ -26,50 +26,34 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
+#include <cstring>
 #include "Types.h"
 #include "Types.h"
 #include "KeyCode.h"
 #include "KeyCode.h"
-#include "OS.h"
-
-#undef MK_SHIFT
-#undef MK_ALT
+#include "Assert.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-class InputManager;
-
-
 /// Enumerates modifier keys.
 /// Enumerates modifier keys.
-enum ModifierKey
-{
-	MK_SHIFT	= 1,
-	MK_CTRL		= 2,
-	MK_ALT		= 4
-};
-
-struct KeyboardEvent
+struct ModifierButton
 {
 {
-	KeyCode		key;
-	uint8_t		modifier;
-	char		text[4];
-};
-
-class KeyboardListener
-{
-
-public:
-
-	virtual void key_pressed(const KeyboardEvent& event) { (void)event; }
-	virtual void key_released(const KeyboardEvent& event) { (void)event; }
-	virtual void text_input(const KeyboardEvent& event) { (void)event; }
+	enum Enum
+	{
+		SHIFT	= 1,
+		CTRL	= 2,
+		ALT		= 4
+	};
 };
 };
 
 
 /// Interface for accessing keyboard input device.
 /// Interface for accessing keyboard input device.
-class Keyboard
+struct Keyboard
 {
 {
-public:
-
-					Keyboard();
+	Keyboard()
+		: m_modifier(0), m_last_button(KeyboardButton::NONE)
+	{
+		memset(m_last_state, 0, KeyboardButton::COUNT);
+		memset(m_current_state, 0, KeyboardButton::COUNT);
+	}
 
 
 	/// Returns whether the specified @a modifier is pressed.
 	/// Returns whether the specified @a modifier is pressed.
 	/// @note
 	/// @note
@@ -77,36 +61,55 @@ public:
 	/// of another key when the two are pressed in combination. (Thanks wikipedia.)
 	/// of another key when the two are pressed in combination. (Thanks wikipedia.)
 	/// @note
 	/// @note
 	/// Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
 	/// Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
-	bool			modifier_pressed(ModifierKey modifier) const;
-
-	/// Returns whether the specified @a key is pressed in the current frame.
-	bool			key_pressed(KeyCode key) const;
-
-	/// Returns whether the specified @a key is released in the current frame.
-	bool			key_released(KeyCode key) const;
-
-	/// Returns wheter any key is pressed in the current frame.
-	bool			any_pressed() const;
-
-	/// Returns whether any key is released in the current frame.
-	bool			any_released() const;
+	bool modifier_pressed(ModifierButton::Enum modifier) const
+	{
+		return (m_modifier & (uint8_t) modifier) == modifier;
+	}
+
+	/// Returns whether the specified @a b button is pressed in the current frame.
+	bool button_pressed(KeyboardButton::Enum b) const
+	{
+		return bool(~m_last_state[b] & m_current_state[b]);
+	}
+
+	/// Returns whether the specified @a b button is released in the current frame.
+	bool button_released(KeyboardButton::Enum b) const
+	{
+		return bool(m_last_state[b] & ~m_current_state[b]);
+	}
+
+	/// Returns wheter any button is pressed in the current frame.
+	bool any_pressed()
+	{
+		return button_pressed(m_last_button);
+	}
+
+	/// Returns whether any button is released in the current frame.
+	bool any_released()
+	{
+		return button_released(m_last_button);
+	}
+
+	//-------------------------------------------------------------------------
+	void set_button_state(KeyboardButton::Enum b, bool state)
+	{
+		m_last_button = b;
+		m_current_state[b] = state;
+	}
+
+	//-------------------------------------------------------------------------
+	void update()
+	{
+		memcpy(m_last_state, m_current_state, KeyboardButton::COUNT);
+	}
 
 
-private:
-
-	void			update(uint64_t frame, KeyCode k, bool state);
-
-	uint8_t			m_modifier;
-
-	// The current frame number
-	uint64_t		m_current_frame;
+public:
 
 
-	// Last key updated
-	KeyCode			m_last_key;
-	uint64_t		m_keys[MAX_KEYCODES];
-	bool			m_state[MAX_KEYCODES];
+	uint8_t m_modifier;
 
 
-	friend class	InputManager;
+	KeyboardButton::Enum m_last_button;
+	uint8_t m_last_state[KeyboardButton::COUNT];
+	uint8_t m_current_state[KeyboardButton::COUNT];
 };
 };
 
 
 } // namespace crown
 } // namespace crown
-

+ 0 - 131
engine/input/Mouse.cpp

@@ -1,131 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Mouse.h"
-#include "Device.h"
-#include "OsWindow.h"
-
-#undef MB_RIGHT
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Mouse::Mouse() :
-	m_current_frame(0),
-	m_last_button(MB_LEFT)
-{
-	m_buttons[MB_LEFT] = ~0;
-	m_buttons[MB_MIDDLE] = ~0;
-	m_buttons[MB_RIGHT] = ~0;
-
-	m_state[MB_LEFT] = false;
-	m_state[MB_MIDDLE] = false;
-	m_state[MB_RIGHT] = false;
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::button_pressed(MouseButton button) const
-{
-	CE_ASSERT(button >= 0 && button < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", button);
-
-	return (m_state[button] == true) && (m_buttons[button] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::button_released(MouseButton button) const
-{
-	CE_ASSERT(button >= 0 && button < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", button);
-
-	return (m_state[button] == false) && (m_buttons[button] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::any_pressed() const
-{
-	return button_pressed(m_last_button);
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::any_released() const
-{
-	return button_released(m_last_button);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 Mouse::cursor_xy() const
-{
-	int32_t x, y;
-
-	device()->window()->get_cursor_xy(x, y);
-
-	return Vec2(x, y);
-}
-
-//-----------------------------------------------------------------------------
-void Mouse::set_cursor_xy(const Vec2& position)
-{
-	device()->window()->set_cursor_xy((int32_t) position.x, (int32_t) position.y);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 Mouse::cursor_relative_xy() const
-{
-	uint32_t window_width;
-	uint32_t window_height;
-
-	device()->window()->get_size(window_width, window_height);
-
-	Vec2 pos = cursor_xy();
-
-	pos.x = pos.x / (float) window_width;
-	pos.y = pos.y / (float) window_height;
-
-	return pos;
-}
-
-//-----------------------------------------------------------------------------
-void Mouse::set_cursor_relative_xy(const Vec2& position)
-{
-	uint32_t window_width;
-	uint32_t window_height;
-
-	device()->window()->get_size(window_width, window_height);
-
-	set_cursor_xy(Vec2(position.x * (float) window_width, position.y * (float) window_height));
-}
-
-//-----------------------------------------------------------------------------
-void Mouse::update(uint64_t frame, MouseButton b, bool state)
-{
-	CE_ASSERT(b >= 0 && b < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", b);
-
-	m_last_button = b;
-	m_buttons[b] = frame;
-	m_state[b] = state;
-}
-
-} // namespace crown

+ 93 - 51
engine/input/Mouse.h

@@ -25,41 +25,25 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #pragma once
 #pragma once
-#undef MB_RIGHT
 
 
+#include <cstring>
 #include "Types.h"
 #include "Types.h"
 #include "Vec2.h"
 #include "Vec2.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-const uint32_t MAX_MOUSE_BUTTONS = 3;
-
 /// Enumerates mouse buttons.
 /// Enumerates mouse buttons.
-enum MouseButton
-{
-	MB_LEFT		= 0,
-	MB_MIDDLE	= 1,
-	MB_RIGHT	= 2
-};
-
-struct MouseEvent
+struct MouseButton
 {
 {
-	MouseButton button;
-	int32_t x;
-	int32_t y;
-	float wheel;
-};
-
-/// Interface for managing mouse input.
-class MouseListener
-{
-
-public:
-
-	virtual void button_pressed(const MouseEvent& event) { (void)event; }
-	virtual void button_released(const MouseEvent& event) { (void)event; }
-	virtual void cursor_moved(const MouseEvent& event) { (void)event; }
+	enum Enum
+	{
+		NONE,
+		LEFT,
+		MIDDLE,
+		RIGHT,
+		COUNT
+	};
 };
 };
 
 
 /// Interface for accessing mouse input device.
 /// Interface for accessing mouse input device.
@@ -67,34 +51,58 @@ class Mouse
 {
 {
 public:
 public:
 
 
-					Mouse();
-
-
-	/// Returns whether @a button is pressed in the current frame.
-	bool			button_pressed(MouseButton button) const;
-
-	/// Returns whether @a button is released in the current frame.
-	bool			button_released(MouseButton button) const;
+	//-----------------------------------------------------------------------------
+	Mouse()
+		: m_last_button(MouseButton::NONE)
+	{
+		memset(m_last_state, 0, MouseButton::COUNT);
+		memset(m_current_state, 0, MouseButton::COUNT);
+	}
+
+	/// Returns whether the @a b button is pressed in the current frame.
+	bool button_pressed(MouseButton::Enum b)
+	{
+		return bool(~m_last_state[b] & m_current_state[b]);
+	}
+
+	/// Returns whether the @a b button is released in the current frame.
+	bool button_released(MouseButton::Enum b)
+	{
+		return bool(m_last_state[b] & ~m_current_state[b]);
+	}
 
 
 	/// Returns wheter any button is pressed in the current frame.
 	/// Returns wheter any button is pressed in the current frame.
-	bool			any_pressed() const;
+	bool any_pressed()
+	{
+		return button_pressed(m_last_button);
+	}
 
 
 	/// Returns whether any button is released in the current frame.
 	/// Returns whether any button is released in the current frame.
-	bool			any_released() const;
+	bool any_released()
+	{
+		return button_released(m_last_button);
+	}
 
 
 	/// Returns the position of the cursor in window space.
 	/// Returns the position of the cursor in window space.
 	/// @note
 	/// @note
 	/// Coordinates in window space have the origin at the
 	/// Coordinates in window space have the origin at the
 	/// upper-left corner of the window. +X extends from left
 	/// upper-left corner of the window. +X extends from left
 	/// to right and +Y extends from top to bottom.
 	/// to right and +Y extends from top to bottom.
-	Vec2			cursor_xy() const;
+	Vec2 cursor_xy()
+	{
+		return Vec2(m_x, m_y);
+	}
 
 
 	/// Sets the position of the cursor in window space.
 	/// Sets the position of the cursor in window space.
 	/// @note
 	/// @note
 	/// Coordinates in window space have the origin at the
 	/// Coordinates in window space have the origin at the
 	/// upper-left corner of the window. +X extends from left
 	/// upper-left corner of the window. +X extends from left
 	/// to right and +Y extends from top to bottom.
 	/// to right and +Y extends from top to bottom.
-	void			set_cursor_xy(const Vec2& position);
+	void set_cursor_xy(const Vec2& position)
+	{
+		m_x = (uint16_t) position.x;
+		m_y = (uint16_t) position.y;
+	}
 
 
 	/// Returns the relative position of the cursor in window space.
 	/// Returns the relative position of the cursor in window space.
 	/// @note
 	/// @note
@@ -105,7 +113,10 @@ public:
 	/// Relative coordinates are mapped to a float varying
 	/// Relative coordinates are mapped to a float varying
 	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 	/// maximum extent of the cosidered axis.
 	/// maximum extent of the cosidered axis.
-	Vec2			cursor_relative_xy() const;
+	Vec2 cursor_relative_xy()
+	{
+		return Vec2(m_x / m_width, m_y / m_height);
+	}
 
 
 	/// Sets the relative position of the cursor in window space.
 	/// Sets the relative position of the cursor in window space.
 	/// @note
 	/// @note
@@ -116,22 +127,53 @@ public:
 	/// Relative coordinates are mapped to a float varying
 	/// Relative coordinates are mapped to a float varying
 	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 	/// maximum extent of the cosidered axis.
 	/// maximum extent of the cosidered axis.
-	void			set_cursor_relative_xy(const Vec2& position);
-
-private:
+	void set_cursor_relative_xy(const Vec2& position)
+	{
+		set_cursor_xy(Vec2(position.x * (float) m_width, position.y * (float) m_height));
+	}
+
+	//-----------------------------------------------------------------------------
+	void set_position(uint16_t x, uint16_t y)
+	{
+		m_x = x;
+		m_y = y;
+	}
+
+	//-----------------------------------------------------------------------------
+	void set_metrics(uint16_t width, uint16_t height)
+	{
+		m_width = width;
+		m_height = height;
+	}
+
+	//-----------------------------------------------------------------------------
+	void set_button_state(uint16_t x, uint16_t y, MouseButton::Enum b, bool state)
+	{
+		set_position(x, y);
+
+		m_last_button = b;
+		m_current_state[b] = state;
+	}
+
+	//-----------------------------------------------------------------------------
+	void update()
+	{
+		memcpy(m_last_state, m_current_state, MouseButton::COUNT);
+	}
 
 
-	void			update(uint64_t frame, MouseButton b, bool state);
-
-	// The current frame number
-	uint64_t		m_current_frame;
+public:
 
 
-	// Last button updated
-	MouseButton		m_last_button;
+	MouseButton::Enum m_last_button;
+	uint8_t m_last_state[MouseButton::COUNT];
+	uint8_t m_current_state[MouseButton::COUNT];
 
 
-	uint64_t		m_buttons[MAX_MOUSE_BUTTONS];
-	bool			m_state[MAX_MOUSE_BUTTONS];
+	// Position within the window
+	uint16_t m_x;
+	uint16_t m_y;
 
 
-	friend class	InputManager;
+	// Window size
+	uint16_t m_width;
+	uint16_t m_height;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 66
engine/input/Touch.cpp

@@ -1,66 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Touch.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Touch::Touch()
-{
-
-}
-
-//-----------------------------------------------------------------------------
-bool Touch::touch_up(uint16_t id) const
-{
-	return m_pointers[id].up == true;
-}
-
-//-----------------------------------------------------------------------------
-bool Touch::touch_down(uint16_t id) const
-{
-	return m_pointers[id].up == false;
-}
-
-//----------------------------------------------------------------------------- 
-Vec2 Touch::touch_xy(uint16_t id) const
-{
-	const PointerData& data = m_pointers[id];
-
-	return Vec2(data.x, data.y);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 Touch::touch_relative_xy(uint16_t id)
-{
-	const PointerData& data = m_pointers[id];
-
-	return Vec2(data.relative_x, data.relative_y);
-}
-
-} // namespace crown

+ 22 - 31
engine/input/Touch.h

@@ -43,44 +43,32 @@ struct PointerData
 	bool		up;
 	bool		up;
 };
 };
 
 
-struct TouchEvent
-{
-	uint32_t	pointer_id;
-	uint32_t	x;
-	uint32_t	y;
-};
-
-/// Interface for managing touch input device.
-class TouchListener
-{
-
-public:
-
-	virtual void touch_down(const TouchEvent& event) { (void)event; }
-	virtual void touch_up(const TouchEvent& event) { (void)event; }
-	virtual void touch_move(const TouchEvent& event) { (void)event; }
-	virtual void touch_cancel(const TouchEvent& event) { (void)event; }
-};
-
 /// Interface for accessing touch input device.
 /// Interface for accessing touch input device.
-class Touch
+struct Touch
 {
 {
-public:
-
-					Touch();
-
 	/// Returns whether the touch pointer @a id is up.
 	/// Returns whether the touch pointer @a id is up.
-	bool			touch_up(uint16_t id) const;
+	bool touch_up(uint16_t id) const
+	{
+		return m_pointers[id].up == true;
+	}
 
 
 	/// Returns whether the touch pointer @a id is down.
 	/// Returns whether the touch pointer @a id is down.
-	bool			touch_down(uint16_t id) const;
+	bool touch_down(uint16_t id) const
+	{
+		return m_pointers[id].up == false;
+	}
 
 
 	/// Returns the position of the pointer @a id in windows space.
 	/// Returns the position of the pointer @a id in windows space.
 	/// @note
 	/// @note
 	/// Coordinates in window space have the origin at the
 	/// Coordinates in window space have the origin at the
 	/// upper-left corner of the window. +X extends from left
 	/// upper-left corner of the window. +X extends from left
 	/// to right and +Y extends from top to bottom.
 	/// to right and +Y extends from top to bottom.
-	Vec2			touch_xy(uint16_t id) const;
+	Vec2 touch_xy(uint16_t id) const
+	{
+		const PointerData& data = m_pointers[id];
+
+		return Vec2(data.x, data.y);
+	}
 
 
 	/// Returns the relative position of the pointer @a id in window space.
 	/// Returns the relative position of the pointer @a id in window space.
 	/// @note
 	/// @note
@@ -91,13 +79,16 @@ public:
 	/// Relative coordinates are mapped to a float varying
 	/// Relative coordinates are mapped to a float varying
 	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 	/// maximum extent of the cosidered axis.
 	/// maximum extent of the cosidered axis.
-	Vec2			touch_relative_xy(uint16_t id);
+	Vec2 touch_relative_xy(uint16_t id)
+	{
+		const PointerData& data = m_pointers[id];
 
 
-private:
+		return Vec2(data.relative_x, data.relative_y);
+	}
 
 
-	PointerData		m_pointers[MAX_POINTER_IDS];
+public:
 
 
-	friend class	InputManager;
+	PointerData		m_pointers[MAX_POINTER_IDS];
 };
 };
 
 
 }
 }

+ 4 - 2
engine/lua/LuaEnvironment.cpp

@@ -25,8 +25,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #include <stdarg.h>
 #include <stdarg.h>
-#include "Assert.h"
+
 #include "LuaEnvironment.h"
 #include "LuaEnvironment.h"
+#include "Assert.h"
 #include "StringUtils.h"
 #include "StringUtils.h"
 #include "LuaStack.h"
 #include "LuaStack.h"
 #include "Device.h"
 #include "Device.h"
@@ -44,16 +45,17 @@ CE_EXPORT int luaopen_libcrown(lua_State* /*L*/)
 	load_int_setting(*env);
 	load_int_setting(*env);
 	load_float_setting(*env);
 	load_float_setting(*env);
 	load_string_setting(*env);
 	load_string_setting(*env);
+
 	load_vec2(*env);
 	load_vec2(*env);
 	load_vec3(*env);
 	load_vec3(*env);
 	load_mat4(*env);
 	load_mat4(*env);
 	load_quat(*env);
 	load_quat(*env);
 	load_math(*env);
 	load_math(*env);
+	load_window(*env);
 	load_mouse(*env);
 	load_mouse(*env);
 	load_keyboard(*env);
 	load_keyboard(*env);
 	load_accelerometer(*env);
 	load_accelerometer(*env);
 	load_device(*env);
 	load_device(*env);
-	load_window(*env);
 	load_resource_package(*env);
 	load_resource_package(*env);
 
 
 	return 1;
 	return 1;

+ 0 - 1
engine/lua/LuaEnvironment.h

@@ -92,7 +92,6 @@ private:
 	bool					m_is_used;
 	bool					m_is_used;
 };
 };
 
 
-
 void load_int_setting(LuaEnvironment& env);
 void load_int_setting(LuaEnvironment& env);
 void load_float_setting(LuaEnvironment& env);
 void load_float_setting(LuaEnvironment& env);
 void load_string_setting(LuaEnvironment& env);
 void load_string_setting(LuaEnvironment& env);

+ 114 - 116
engine/lua/LuaKeyboard.cpp

@@ -39,31 +39,31 @@ CE_EXPORT int keyboard_modifier_pressed(lua_State* L)
 
 
 	int32_t modifier = stack.get_int(1);
 	int32_t modifier = stack.get_int(1);
 
 
-	stack.push_bool(device()->keyboard()->modifier_pressed((ModifierKey) modifier));
+	stack.push_bool(device()->keyboard()->modifier_pressed((ModifierButton::Enum) modifier));
 
 
 	return 1;
 	return 1;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-CE_EXPORT int keyboard_key_pressed(lua_State* L)
+CE_EXPORT int keyboard_button_pressed(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
 
 
-	int32_t key = stack.get_int(1);
+	int32_t button = stack.get_int(1);
 
 
-	stack.push_bool(device()->keyboard()->key_pressed((KeyCode) key));
+	stack.push_bool(device()->keyboard()->button_pressed((KeyboardButton::Enum) button));
 
 
 	return 1;
 	return 1;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-CE_EXPORT int keyboard_key_released(lua_State* L)
+CE_EXPORT int keyboard_button_released(lua_State* L)
 {
 {
 	LuaStack stack(L);
 	LuaStack stack(L);
 
 
-	int32_t key = stack.get_int(1);
+	int32_t button = stack.get_int(1);
 
 
-	stack.push_bool(device()->keyboard()->key_released((KeyCode) key));
+	stack.push_bool(device()->keyboard()->button_released((KeyboardButton::Enum) button));
 
 
 	return 1;
 	return 1;
 }
 }
@@ -92,132 +92,130 @@ CE_EXPORT int keyboard_any_released(lua_State* L)
 void load_keyboard(LuaEnvironment& env)
 void load_keyboard(LuaEnvironment& env)
 {
 {
 	env.load_module_function("Keyboard", "modifier_pressed",	keyboard_modifier_pressed);
 	env.load_module_function("Keyboard", "modifier_pressed",	keyboard_modifier_pressed);
-	env.load_module_function("Keyboard", "key_pressed",			keyboard_key_pressed);
-	env.load_module_function("Keyboard", "key_released",		keyboard_key_released);
+	env.load_module_function("Keyboard", "button_pressed",		keyboard_button_pressed);
+	env.load_module_function("Keyboard", "button_released",		keyboard_button_released);
 	env.load_module_function("Keyboard", "any_pressed",			keyboard_any_pressed);
 	env.load_module_function("Keyboard", "any_pressed",			keyboard_any_pressed);
 	env.load_module_function("Keyboard", "any_released",		keyboard_any_released);
 	env.load_module_function("Keyboard", "any_released",		keyboard_any_released);
 
 
-	env.load_module_enum("Keyboard", "KC_NOKEY",		KC_NOKEY);
-
-	env.load_module_enum("Keyboard", "KC_TAB",			KC_TAB);
-	env.load_module_enum("Keyboard", "KC_ENTER",		KC_ENTER);
-	env.load_module_enum("Keyboard", "KC_ESCAPE",		KC_ESCAPE);
-	env.load_module_enum("Keyboard", "KC_SPACE",		KC_SPACE);
-	env.load_module_enum("Keyboard", "KC_BACKSPACE",	KC_BACKSPACE);
+	env.load_module_enum("Keyboard", "TAB",			KeyboardButton::TAB);
+	env.load_module_enum("Keyboard", "ENTER",		KeyboardButton::ENTER);
+	env.load_module_enum("Keyboard", "ESCAPE",		KeyboardButton::ESCAPE);
+	env.load_module_enum("Keyboard", "SPACE",		KeyboardButton::SPACE);
+	env.load_module_enum("Keyboard", "BACKSPACE",	KeyboardButton::BACKSPACE);
 
 
 	/* KeyPad */
 	/* KeyPad */
-	env.load_module_enum("Keyboard", "KC_KP_0",			KC_KP_0);
-	env.load_module_enum("Keyboard", "KC_KP_1",			KC_KP_1);
-	env.load_module_enum("Keyboard", "KC_KP_2",			KC_KP_2);
-	env.load_module_enum("Keyboard", "KC_KP_3",			KC_KP_3);
-	env.load_module_enum("Keyboard", "KC_KP_4",			KC_KP_4);
-	env.load_module_enum("Keyboard", "KC_KP_5",			KC_KP_5);
-	env.load_module_enum("Keyboard", "KC_KP_6",			KC_KP_6);
-	env.load_module_enum("Keyboard", "KC_KP_7",			KC_KP_7);
-	env.load_module_enum("Keyboard", "KC_KP_8",			KC_KP_8);
-	env.load_module_enum("Keyboard", "KC_KP_9",			KC_KP_9);
+	env.load_module_enum("Keyboard", "KP_0",		KeyboardButton::KP_0);
+	env.load_module_enum("Keyboard", "KP_1",		KeyboardButton::KP_1);
+	env.load_module_enum("Keyboard", "KP_2",		KeyboardButton::KP_2);
+	env.load_module_enum("Keyboard", "KP_3",		KeyboardButton::KP_3);
+	env.load_module_enum("Keyboard", "KP_4",		KeyboardButton::KP_4);
+	env.load_module_enum("Keyboard", "KP_5",		KeyboardButton::KP_5);
+	env.load_module_enum("Keyboard", "KP_6",		KeyboardButton::KP_6);
+	env.load_module_enum("Keyboard", "KP_7",		KeyboardButton::KP_7);
+	env.load_module_enum("Keyboard", "KP_8",		KeyboardButton::KP_8);
+	env.load_module_enum("Keyboard", "KP_9",		KeyboardButton::KP_9);
 
 
 	/* Function keys */
 	/* Function keys */
-	env.load_module_enum("Keyboard", "KC_F1",			KC_F1);
-	env.load_module_enum("Keyboard", "KC_F2",			KC_F2);
-	env.load_module_enum("Keyboard", "KC_F3",			KC_F3);
-	env.load_module_enum("Keyboard", "KC_F4",			KC_F4);
-	env.load_module_enum("Keyboard", "KC_F5",			KC_F5);
-	env.load_module_enum("Keyboard", "KC_F6",			KC_F6);
-	env.load_module_enum("Keyboard", "KC_F7",			KC_F7);
-	env.load_module_enum("Keyboard", "KC_F8",			KC_F8);
-	env.load_module_enum("Keyboard", "KC_F9",			KC_F9);
-	env.load_module_enum("Keyboard", "KC_F10",			KC_F10);
-	env.load_module_enum("Keyboard", "KC_F11",			KC_F11);
-	env.load_module_enum("Keyboard", "KC_F12",			KC_F12);
+	env.load_module_enum("Keyboard", "F1",			KeyboardButton::F1);
+	env.load_module_enum("Keyboard", "F2",			KeyboardButton::F2);
+	env.load_module_enum("Keyboard", "F3",			KeyboardButton::F3);
+	env.load_module_enum("Keyboard", "F4",			KeyboardButton::F4);
+	env.load_module_enum("Keyboard", "F5",			KeyboardButton::F5);
+	env.load_module_enum("Keyboard", "F6",			KeyboardButton::F6);
+	env.load_module_enum("Keyboard", "F7",			KeyboardButton::F7);
+	env.load_module_enum("Keyboard", "F8",			KeyboardButton::F8);
+	env.load_module_enum("Keyboard", "F9",			KeyboardButton::F9);
+	env.load_module_enum("Keyboard", "F10",			KeyboardButton::F10);
+	env.load_module_enum("Keyboard", "F11",			KeyboardButton::F11);
+	env.load_module_enum("Keyboard", "F12",			KeyboardButton::F12);
 
 
 	/* Other keys */
 	/* Other keys */
-	env.load_module_enum("Keyboard", "KC_HOME",			KC_HOME);
-	env.load_module_enum("Keyboard", "KC_LEFT",			KC_LEFT);
-	env.load_module_enum("Keyboard", "KC_UP",			KC_UP);
-	env.load_module_enum("Keyboard", "KC_RIGHT",		KC_RIGHT);
-	env.load_module_enum("Keyboard", "KC_DOWN",			KC_DOWN);
-	env.load_module_enum("Keyboard", "KC_PAGE_UP",		KC_PAGE_UP);
-	env.load_module_enum("Keyboard", "KC_PAGE_DOWN",	KC_PAGE_DOWN);
+	env.load_module_enum("Keyboard", "HOME",		KeyboardButton::HOME);
+	env.load_module_enum("Keyboard", "LEFT",		KeyboardButton::LEFT);
+	env.load_module_enum("Keyboard", "UP",			KeyboardButton::UP);
+	env.load_module_enum("Keyboard", "RIGHT",		KeyboardButton::RIGHT);
+	env.load_module_enum("Keyboard", "DOWN",		KeyboardButton::DOWN);
+	env.load_module_enum("Keyboard", "PAGE_UP",		KeyboardButton::PAGE_UP);
+	env.load_module_enum("Keyboard", "PAGE_DOWN",	KeyboardButton::PAGE_DOWN);
 
 
 	/* Modifier keys */
 	/* Modifier keys */
-	env.load_module_enum("Keyboard", "KC_LCONTROL",		KC_LCONTROL);
-	env.load_module_enum("Keyboard", "KC_RCONTROL",		KC_RCONTROL);
-	env.load_module_enum("Keyboard", "KC_LSHIFT",		KC_LSHIFT);
-	env.load_module_enum("Keyboard", "KC_RSHIFT",		KC_RSHIFT);
-	env.load_module_enum("Keyboard", "KC_CAPS_LOCK",	KC_CAPS_LOCK);
-	env.load_module_enum("Keyboard", "KC_LALT",			KC_LALT);
-	env.load_module_enum("Keyboard", "KC_RALT",			KC_RALT);
-	env.load_module_enum("Keyboard", "KC_LSUPER",		KC_LSUPER);
-	env.load_module_enum("Keyboard", "KC_RSUPER",		KC_RSUPER);
+	env.load_module_enum("Keyboard", "LCONTROL",	KeyboardButton::LCONTROL);
+	env.load_module_enum("Keyboard", "RCONTROL",	KeyboardButton::RCONTROL);
+	env.load_module_enum("Keyboard", "LSHIFT",		KeyboardButton::LSHIFT);
+	env.load_module_enum("Keyboard", "RSHIFT",		KeyboardButton::RSHIFT);
+	env.load_module_enum("Keyboard", "CAPS_LOCK",	KeyboardButton::CAPS_LOCK);
+	env.load_module_enum("Keyboard", "LALT",		KeyboardButton::LALT);
+	env.load_module_enum("Keyboard", "RALT",		KeyboardButton::RALT);
+	env.load_module_enum("Keyboard", "LSUPER",		KeyboardButton::LSUPER);
+	env.load_module_enum("Keyboard", "RSUPER",		KeyboardButton::RSUPER);
 
 
 	/* [0x30, 0x39] reserved for ASCII digits */
 	/* [0x30, 0x39] reserved for ASCII digits */
-	env.load_module_enum("Keyboard", "KC_0",			KC_0);
-	env.load_module_enum("Keyboard", "KC_1",			KC_1);
-	env.load_module_enum("Keyboard", "KC_2",			KC_2);
-	env.load_module_enum("Keyboard", "KC_3",			KC_3);
-	env.load_module_enum("Keyboard", "KC_4",			KC_4);
-	env.load_module_enum("Keyboard", "KC_5",			KC_5);
-	env.load_module_enum("Keyboard", "KC_6",			KC_6);
-	env.load_module_enum("Keyboard", "KC_7",			KC_7);
-	env.load_module_enum("Keyboard", "KC_8",			KC_8);
-	env.load_module_enum("Keyboard", "KC_9",			KC_9);
+	env.load_module_enum("Keyboard", "NUM_0",		KeyboardButton::NUM_0);
+	env.load_module_enum("Keyboard", "NUM_1",		KeyboardButton::NUM_1);
+	env.load_module_enum("Keyboard", "NUM_2",		KeyboardButton::NUM_2);
+	env.load_module_enum("Keyboard", "NUM_3",		KeyboardButton::NUM_3);
+	env.load_module_enum("Keyboard", "NUM_4",		KeyboardButton::NUM_4);
+	env.load_module_enum("Keyboard", "NUM_5",		KeyboardButton::NUM_5);
+	env.load_module_enum("Keyboard", "NUM_6",		KeyboardButton::NUM_6);
+	env.load_module_enum("Keyboard", "NUM_7",		KeyboardButton::NUM_7);
+	env.load_module_enum("Keyboard", "NUM_8",		KeyboardButton::NUM_8);
+	env.load_module_enum("Keyboard", "NUM_9",		KeyboardButton::NUM_9);
 
 
 	/* [0x41, 0x5A] reserved for ASCII alph,abet */
 	/* [0x41, 0x5A] reserved for ASCII alph,abet */
-	env.load_module_enum("Keyboard", "KC_A",			KC_A);
-	env.load_module_enum("Keyboard", "KC_B",			KC_B);
-	env.load_module_enum("Keyboard", "KC_C",			KC_C);
-	env.load_module_enum("Keyboard", "KC_D",			KC_D);
-	env.load_module_enum("Keyboard", "KC_E",			KC_E);
-	env.load_module_enum("Keyboard", "KC_F",			KC_F);
-	env.load_module_enum("Keyboard", "KC_G",			KC_G);
-	env.load_module_enum("Keyboard", "KC_H",			KC_H);
-	env.load_module_enum("Keyboard", "KC_I",			KC_I);
-	env.load_module_enum("Keyboard", "KC_J",			KC_J);
-	env.load_module_enum("Keyboard", "KC_K",			KC_K);
-	env.load_module_enum("Keyboard", "KC_L",			KC_L);
-	env.load_module_enum("Keyboard", "KC_M",			KC_M);
-	env.load_module_enum("Keyboard", "KC_N",			KC_N);
-	env.load_module_enum("Keyboard", "KC_O",			KC_O);
-	env.load_module_enum("Keyboard", "KC_P",			KC_P);
-	env.load_module_enum("Keyboard", "KC_Q",			KC_Q);
-	env.load_module_enum("Keyboard", "KC_R",			KC_R);
-	env.load_module_enum("Keyboard", "KC_S",			KC_S);
-	env.load_module_enum("Keyboard", "KC_T",			KC_T);
-	env.load_module_enum("Keyboard", "KC_U",			KC_U);
-	env.load_module_enum("Keyboard", "KC_V",			KC_V);
-	env.load_module_enum("Keyboard", "KC_W",			KC_W);
-	env.load_module_enum("Keyboard", "KC_X",			KC_X);
-	env.load_module_enum("Keyboard", "KC_Y",			KC_Y);
-	env.load_module_enum("Keyboard", "KC_Z",			KC_Z);
+	env.load_module_enum("Keyboard", "A",			KeyboardButton::A);
+	env.load_module_enum("Keyboard", "B",			KeyboardButton::B);
+	env.load_module_enum("Keyboard", "C",			KeyboardButton::C);
+	env.load_module_enum("Keyboard", "D",			KeyboardButton::D);
+	env.load_module_enum("Keyboard", "E",			KeyboardButton::E);
+	env.load_module_enum("Keyboard", "F",			KeyboardButton::F);
+	env.load_module_enum("Keyboard", "G",			KeyboardButton::G);
+	env.load_module_enum("Keyboard", "H",			KeyboardButton::H);
+	env.load_module_enum("Keyboard", "I",			KeyboardButton::I);
+	env.load_module_enum("Keyboard", "J",			KeyboardButton::J);
+	env.load_module_enum("Keyboard", "K",			KeyboardButton::K);
+	env.load_module_enum("Keyboard", "L",			KeyboardButton::L);
+	env.load_module_enum("Keyboard", "M",			KeyboardButton::M);
+	env.load_module_enum("Keyboard", "N",			KeyboardButton::N);
+	env.load_module_enum("Keyboard", "O",			KeyboardButton::O);
+	env.load_module_enum("Keyboard", "P",			KeyboardButton::P);
+	env.load_module_enum("Keyboard", "Q",			KeyboardButton::Q);
+	env.load_module_enum("Keyboard", "R",			KeyboardButton::R);
+	env.load_module_enum("Keyboard", "S",			KeyboardButton::S);
+	env.load_module_enum("Keyboard", "T",			KeyboardButton::T);
+	env.load_module_enum("Keyboard", "U",			KeyboardButton::U);
+	env.load_module_enum("Keyboard", "V",			KeyboardButton::V);
+	env.load_module_enum("Keyboard", "W",			KeyboardButton::W);
+	env.load_module_enum("Keyboard", "X",			KeyboardButton::X);
+	env.load_module_enum("Keyboard", "Y",			KeyboardButton::Y);
+	env.load_module_enum("Keyboard", "Z",			KeyboardButton::Z);
 
 
 	/* [0x61, 0x7A] reserved for ASCII alphabet */
 	/* [0x61, 0x7A] reserved for ASCII alphabet */
-	env.load_module_enum("Keyboard", "KC_a",			KC_a);
-	env.load_module_enum("Keyboard", "KC_b",			KC_b);
-	env.load_module_enum("Keyboard", "KC_c",			KC_c);
-	env.load_module_enum("Keyboard", "KC_d",			KC_d);
-	env.load_module_enum("Keyboard", "KC_e",			KC_e);
-	env.load_module_enum("Keyboard", "KC_f",			KC_f);
-	env.load_module_enum("Keyboard", "KC_g",			KC_g);
-	env.load_module_enum("Keyboard", "KC_h",			KC_h);
-	env.load_module_enum("Keyboard", "KC_i",			KC_i);
-	env.load_module_enum("Keyboard", "KC_j",			KC_j);
-	env.load_module_enum("Keyboard", "KC_k",			KC_k);
-	env.load_module_enum("Keyboard", "KC_l",			KC_l);
-	env.load_module_enum("Keyboard", "KC_m",			KC_m);
-	env.load_module_enum("Keyboard", "KC_n",			KC_n);
-	env.load_module_enum("Keyboard", "KC_o",			KC_o);
-	env.load_module_enum("Keyboard", "KC_p",			KC_p);
-	env.load_module_enum("Keyboard", "KC_q",			KC_q);
-	env.load_module_enum("Keyboard", "KC_r",			KC_r);
-	env.load_module_enum("Keyboard", "KC_s",			KC_s);
-	env.load_module_enum("Keyboard", "KC_t",			KC_t);
-	env.load_module_enum("Keyboard", "KC_u",			KC_u);
-	env.load_module_enum("Keyboard", "KC_v",			KC_v);
-	env.load_module_enum("Keyboard", "KC_w",			KC_w);
-	env.load_module_enum("Keyboard", "KC_x",			KC_x);
-	env.load_module_enum("Keyboard", "KC_y",			KC_y);
-	env.load_module_enum("Keyboard", "KC_z",			KC_z);
+	env.load_module_enum("Keyboard", "a",			KeyboardButton::a);
+	env.load_module_enum("Keyboard", "b",			KeyboardButton::b);
+	env.load_module_enum("Keyboard", "c",			KeyboardButton::c);
+	env.load_module_enum("Keyboard", "d",			KeyboardButton::d);
+	env.load_module_enum("Keyboard", "e",			KeyboardButton::e);
+	env.load_module_enum("Keyboard", "f",			KeyboardButton::f);
+	env.load_module_enum("Keyboard", "g",			KeyboardButton::g);
+	env.load_module_enum("Keyboard", "h",			KeyboardButton::h);
+	env.load_module_enum("Keyboard", "i",			KeyboardButton::i);
+	env.load_module_enum("Keyboard", "j",			KeyboardButton::j);
+	env.load_module_enum("Keyboard", "k",			KeyboardButton::k);
+	env.load_module_enum("Keyboard", "l",			KeyboardButton::l);
+	env.load_module_enum("Keyboard", "m",			KeyboardButton::m);
+	env.load_module_enum("Keyboard", "n",			KeyboardButton::n);
+	env.load_module_enum("Keyboard", "o",			KeyboardButton::o);
+	env.load_module_enum("Keyboard", "p",			KeyboardButton::p);
+	env.load_module_enum("Keyboard", "q",			KeyboardButton::q);
+	env.load_module_enum("Keyboard", "r",			KeyboardButton::r);
+	env.load_module_enum("Keyboard", "s",			KeyboardButton::s);
+	env.load_module_enum("Keyboard", "t",			KeyboardButton::t);
+	env.load_module_enum("Keyboard", "u",			KeyboardButton::u);
+	env.load_module_enum("Keyboard", "v",			KeyboardButton::v);
+	env.load_module_enum("Keyboard", "w",			KeyboardButton::w);
+	env.load_module_enum("Keyboard", "x",			KeyboardButton::x);
+	env.load_module_enum("Keyboard", "y",			KeyboardButton::y);
+	env.load_module_enum("Keyboard", "z",			KeyboardButton::z);
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 5 - 5
engine/lua/LuaMouse.cpp

@@ -40,7 +40,7 @@ CE_EXPORT int mouse_button_pressed(lua_State* L)
 
 
 	int32_t button = stack.get_int(1);
 	int32_t button = stack.get_int(1);
 
 
-	stack.push_bool(device()->mouse()->button_pressed((MouseButton) button));
+	stack.push_bool(device()->mouse()->button_pressed((MouseButton::Enum) button));
 
 
 	return 1;
 	return 1;
 }
 }
@@ -52,7 +52,7 @@ CE_EXPORT int mouse_button_released(lua_State* L)
 
 
 	int32_t button = stack.get_int(1);
 	int32_t button = stack.get_int(1);
 
 
-	stack.push_bool(device()->mouse()->button_released((MouseButton) button));
+	stack.push_bool(device()->mouse()->button_released((MouseButton::Enum) button));
 
 
 	return 1;
 	return 1;
 }
 }
@@ -133,9 +133,9 @@ void load_mouse(LuaEnvironment& env)
 	env.load_module_function("Mouse", "cursor_relative_xy",		mouse_cursor_relative_xy);
 	env.load_module_function("Mouse", "cursor_relative_xy",		mouse_cursor_relative_xy);
 	env.load_module_function("Mouse", "set_cursor_relative_xy",	mouse_set_cursor_relative_xy);
 	env.load_module_function("Mouse", "set_cursor_relative_xy",	mouse_set_cursor_relative_xy);
 
 
-	env.load_module_enum("Mouse", "MB_LEFT",		MB_LEFT);
-	env.load_module_enum("Mouse", "KB_MIDDLE",		MB_MIDDLE);
-	env.load_module_enum("Mouse", "MB_RIGHT",		MB_RIGHT);
+	env.load_module_enum("Mouse", "LEFT",						MouseButton::LEFT);
+	env.load_module_enum("Mouse", "MIDDLE",						MouseButton::MIDDLE);
+	env.load_module_enum("Mouse", "RIGHT", 						MouseButton::RIGHT);
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 1 - 42
engine/lua/LuaWindow.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
-#include "Device.h"
 #include "OsWindow.h"
 #include "OsWindow.h"
+#include "Device.h"
 #include "LuaStack.h"
 #include "LuaStack.h"
 #include "LuaEnvironment.h"
 #include "LuaEnvironment.h"
 
 
@@ -142,44 +142,6 @@ CE_EXPORT int window_set_resizable(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-CE_EXPORT int window_show_cursor(lua_State* L)
-{
-	LuaStack stack(L);
-
-	device()->window()->show_cursor(stack.get_bool(1));
-
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int window_get_cursor_xy(lua_State* L)
-{
-	LuaStack stack(L);
-
-	int32_t x, y;
-
-	device()->window()->get_cursor_xy(x, y);
-
-	stack.push_int32(x);
-	stack.push_int32(y);
-
-	return 2;
-}
-
-//-----------------------------------------------------------------------------
-CE_EXPORT int window_set_cursor_xy(lua_State* L)
-{
-	LuaStack stack(L);
-
-	const int32_t x = stack.get_int(1);
-	const int32_t y = stack.get_int(2);
-
-	device()->window()->set_cursor_xy(x, y);
-
-	return 0;
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 CE_EXPORT int window_title(lua_State* L)
 CE_EXPORT int window_title(lua_State* L)
 {
 {
@@ -217,9 +179,6 @@ void load_window(LuaEnvironment& env)
 	env.load_module_function("Window", "restore",		window_restore);
 	env.load_module_function("Window", "restore",		window_restore);
 	env.load_module_function("Window", "is_resizable",	window_is_resizable);
 	env.load_module_function("Window", "is_resizable",	window_is_resizable);
 	env.load_module_function("Window", "set_resizable",	window_set_resizable);
 	env.load_module_function("Window", "set_resizable",	window_set_resizable);
-	env.load_module_function("Window", "show_cursor",	window_show_cursor);
-	env.load_module_function("Window", "get_cursor_xy",	window_get_cursor_xy);
-	env.load_module_function("Window", "set_cursor_xy",	window_set_cursor_xy);
 	env.load_module_function("Window", "title",			window_title);
 	env.load_module_function("Window", "title",			window_title);
 	env.load_module_function("Window", "set_title",		window_set_title);
 	env.load_module_function("Window", "set_title",		window_set_title);
 }
 }

+ 3 - 8
engine/os/OS.h

@@ -32,7 +32,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Types.h"
 #include "Vector.h"
 #include "Vector.h"
 #include "DynamicString.h"
 #include "DynamicString.h"
-#include "EventBuffer.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -47,8 +46,6 @@ namespace crown
 
 
 	#define snprintf _snprintf
 	#define snprintf _snprintf
 
 
-	#define Thread os::Thread
-
 	#undef MK_SHIFT
 	#undef MK_SHIFT
 	#undef MK_ALT
 	#undef MK_ALT
 #elif defined(ANDROID)
 #elif defined(ANDROID)
@@ -63,7 +60,7 @@ namespace os
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // Print and log functions
 // Print and log functions
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void			printf(const char* string, ...);				//!< Printf wrapper
+void CE_EXPORT	printf(const char* string, ...);				//!< Printf wrapper
 void			vprintf(const char* string, va_list arg);		//!< VPrintf wrapper
 void			vprintf(const char* string, va_list arg);		//!< VPrintf wrapper
 
 
 void			log_debug(const char* string, va_list arg);		//!< Print debug message
 void			log_debug(const char* string, va_list arg);		//!< Print debug message
@@ -74,8 +71,8 @@ void			log_info(const char* string, va_list arg);		//!< Print info message
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // Paths
 // Paths
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-bool			is_root_path(const char* path);
-bool			is_absolute_path(const char* path);
+bool CE_EXPORT	is_root_path(const char* path);
+bool CE_EXPORT	is_absolute_path(const char* path);
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // File management
 // File management
@@ -160,7 +157,5 @@ void			execute_process(const char* args[]);
 
 
 } // namespace os
 } // namespace os
 
 
-EventBuffer* 	os_event_buffer();
-
 } // namespace crown
 } // namespace crown
 
 

+ 142 - 0
engine/os/OsEventQueue.h

@@ -0,0 +1,142 @@
+/*
+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 <cstring>
+#include "Queue.h"
+#include "Mutex.h"
+#include "ProxyAllocator.h"
+#include "OsTypes.h"
+
+namespace crown
+{
+
+struct OsEventQueue
+{
+	//-----------------------------------------------------------------------------
+	OsEventQueue() 
+		: m_allocator("os-event-queue", default_allocator()), m_queue(m_allocator)
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_mouse_event(uint16_t x, uint16_t y)
+	{
+		OsEvent ev;
+		ev.type = OsEvent::MOUSE;
+		ev.mouse.type = OsMouseEvent::MOVE;
+		ev.mouse.x = x;
+		ev.mouse.y = y;
+
+		push_event(&ev);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_mouse_event(uint16_t x, uint16_t y, MouseButton::Enum b, bool pressed)
+	{
+		OsEvent ev;
+		ev.type = OsEvent::MOUSE;
+		ev.mouse.type = OsMouseEvent::BUTTON;
+		ev.mouse.x = x;
+		ev.mouse.y = y;
+		ev.mouse.button = b;
+		ev.mouse.pressed = pressed;
+
+		push_event(&ev);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_keyboard_event(uint32_t modifier, KeyboardButton::Enum b, bool pressed)
+	{
+		OsEvent ev;
+		ev.type = OsEvent::KEYBOARD;
+		ev.keyboard.button = b;
+		ev.keyboard.modifier = modifier;
+		ev.keyboard.pressed = pressed;
+
+		push_event(&ev);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_exit_event(int32_t code)
+	{
+		OsEvent ev;
+		ev.type = OsEvent::EXIT;
+		ev.exit.code = code;
+
+		push_event(&ev);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_metrics_event(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
+	{
+		OsEvent ev;
+		ev.type = OsEvent::METRICS;
+		ev.metrics.x = x;
+		ev.metrics.y = y;
+		ev.metrics.width = width;
+		ev.metrics.height = height;
+
+		push_event(&ev);
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_event(OsEvent* ev)
+	{
+		CE_ASSERT_NOT_NULL(ev);
+
+		m_mutex.lock();
+		m_queue.push(ev, sizeof(OsEvent));
+		m_mutex.unlock();
+	}
+
+	//-----------------------------------------------------------------------------
+	void pop_event(OsEvent* ev)
+	{
+		CE_ASSERT_NOT_NULL(ev);
+
+		m_mutex.lock();
+		if (m_queue.size() > 0)
+		{
+			memcpy(ev, m_queue.begin(), sizeof(OsEvent));
+			m_queue.pop(sizeof(OsEvent));
+		}
+		else
+		{
+			ev->type = OsEvent::NONE;
+		}
+		m_mutex.unlock();
+	}
+
+private:
+
+	ProxyAllocator m_allocator;
+	Queue<OsEvent> m_queue;
+	Mutex m_mutex;
+};
+
+} // namespace crown

+ 61 - 31
engine/os/OsEvents.h → engine/os/OsTypes.h

@@ -27,62 +27,92 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 #pragma once
 
 
 #include "Types.h"
 #include "Types.h"
+#include "Mouse.h"
+#include "Keyboard.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-/// __OsEventType__ represents an event fired by the OS
-enum OsEventType
+struct OsMetricsEvent
 {
 {
-	OSET_NONE				= 0,
-
-	OSET_KEY_PRESS			= 1,
-	OSET_KEY_RELEASE		= 2,
-
-	OSET_BUTTON_PRESS		= 3,
-	OSET_BUTTON_RELEASE		= 4,
+	uint16_t x;
+	uint16_t y;
+	uint16_t width;
+	uint16_t height;
+};
 
 
-	OSET_MOTION_NOTIFY		= 5,
-	OSET_TOUCH_DOWN			= 6,
-	OSET_TOUCH_MOVE			= 7,
-	OSET_TOUCH_UP			= 8,
-	
-	OSET_ACCELEROMETER		= 9
+struct OsExitEvent
+{
+	int32_t code;
 };
 };
 
 
-/// __OsMouseEvent__ represents an event fired by mouse.
-/// It is processed by InputManager.
+/// Represents an event fired by mouse.
 struct OsMouseEvent
 struct OsMouseEvent
 {
 {
-	uint32_t button;
-	uint32_t x;
-	uint32_t y;
+	enum Enum
+	{
+		BUTTON,
+		MOVE
+	};
+
+	OsMouseEvent::Enum type;
+	MouseButton::Enum button;
+	uint16_t x;
+	uint16_t y;
+	bool pressed;
 };
 };
 
 
-/// __OsKeyboardEvent__ represents an event fired by keyboard.
-/// it is processed by InputManager.
+/// Represents an event fired by keyboard.
 struct OsKeyboardEvent
 struct OsKeyboardEvent
 {
 {
-	uint32_t key;
+	KeyboardButton::Enum button;
 	uint32_t modifier;
 	uint32_t modifier;
+	bool pressed;
 };
 };
 
 
-/// __OsTouchEvent__ represents an event fired by touch screen.
-/// It is processed by InputManager.
+/// Represents an event fired by touch screen.
 struct OsTouchEvent
 struct OsTouchEvent
 {
 {
-	uint32_t pointer_id;
-	uint32_t x;
-	uint32_t y;
+	uint8_t pointer_id;
+	uint16_t x;
+	uint16_t y;
 };
 };
 
 
-/// __OsAccelerometerEvent__ represents an event fired by accelerometer.
-/// It is processed by InputManager.
+/// Represents an event fired by accelerometer.
 struct OsAccelerometerEvent
 struct OsAccelerometerEvent
 {
 {
 	float x;
 	float x;
 	float y;
 	float y;
-	float z;	
+	float z;
+};
+
+struct OsEvent
+{
+	/// Represents an event fired by the OS
+	enum Enum
+	{
+		NONE			= 0,
+
+		KEYBOARD		= 1,
+		MOUSE			= 2,
+		TOUCH			= 3,
+		ACCELEROMETER	= 4,
+
+		METRICS,
+		// Exit from program
+		EXIT
+	};
+
+	OsEvent::Enum type;
+	union
+	{
+		OsMetricsEvent metrics;
+		OsExitEvent exit;
+		OsMouseEvent mouse;
+		OsKeyboardEvent keyboard;
+		OsTouchEvent touch;
+		OsAccelerometerEvent accelerometer;
+	};
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 21 - 5
engine/os/android/AndroidDevice.cpp

@@ -28,28 +28,44 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Device.h"
 #include "Device.h"
 #include "Renderer.h"
 #include "Renderer.h"
 #include "Log.h"
 #include "Log.h"
+#include "Allocator.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
+class AndroidDevice : public Device
+{
+public:
+
+	int32_t run(int, char**)
+	{
+		// Do nothing, the game loop is java-side
+	}
+};
+
+static AndroidDevice* g_engine;
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initCrown(JNIEnv* /*env*/, jobject /*obj*/)
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initCrown(JNIEnv* /*env*/, jobject /*obj*/)
 {
 {
-	crown::init();
+	memory::init();
+	os::init_os();
+
+	g_engine = CE_NEW(default_allocator(), AndroidDevice);
+	set_device(g_engine);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdownCrown(JNIEnv* /*env*/, jobject /*obj*/)
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdownCrown(JNIEnv* /*env*/, jobject /*obj*/)
 {
 {
-	crown::shutdown();
+	CE_DELETE(default_allocator(), g_engine);
+	memory::shutdown();
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initDevice(JNIEnv* /*env*/, jobject /*obj*/)
 extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_initDevice(JNIEnv* /*env*/, jobject /*obj*/)
 {
 {
-	const char* argv[] = { "crown-android" };
-
-	device()->init(1, (char**)argv);
+	device()->init();
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 3 - 3
engine/os/android/AndroidOS.cpp

@@ -39,9 +39,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <unistd.h>
 #include <unistd.h>
 
 
 #include "OS.h"
 #include "OS.h"
-#include "OsEvents.h"
 #include "Assert.h"
 #include "Assert.h"
 #include "StringUtils.h"
 #include "StringUtils.h"
+#include "OsTypes.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -319,7 +319,7 @@ extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushTouchEvent(JNI
 	event.x = x;
 	event.x = x;
 	event.y = y;
 	event.y = y;
 
 
-	os_event_buffer()->push_event((OsEventType)type, &event, sizeof(OsTouchEvent));
+	//os_event_buffer()->push_event((OsEventType)type, &event, sizeof(OsTouchEvent));
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -331,7 +331,7 @@ extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_pushAccelerometerE
 	event.y = y;
 	event.y = y;
 	event.z = z;
 	event.z = z;
 
 
-	os_event_buffer()->push_event((OsEventType)type, &event, sizeof(OsAccelerometerEvent));
+	//os_event_buffer()->push_event((OsEventType)type, &event, sizeof(OsAccelerometerEvent));
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 1 - 1
engine/os/android/Thread.h → engine/os/android/OsThread.h

@@ -26,4 +26,4 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
-#include "../posix/Thread.h"
+#include "../posix/OsThread.h"

+ 1 - 1
engine/os/android/OsWindow.cpp

@@ -35,7 +35,7 @@ namespace crown
 ANativeWindow* g_android_window = NULL;
 ANativeWindow* g_android_window = NULL;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsWindow::OsWindow(uint32_t /*width*/, uint32_t /*height*/, uint32_t /*parent*/)
+OsWindow::OsWindow()
 	: m_x(0), m_y(0), m_width(0), m_height(0)
 	: m_x(0), m_y(0), m_width(0), m_height(0)
 {
 {
 	m_width = ANativeWindow_getWidth(g_android_window);
 	m_width = ANativeWindow_getWidth(g_android_window);

+ 1 - 1
engine/os/android/OsWindow.h

@@ -38,7 +38,7 @@ class OsWindow
 public:
 public:
 
 
 	/// Stub method, does nothing under Android.
 	/// Stub method, does nothing under Android.
-					OsWindow(uint32_t width, uint32_t height, uint32_t parent);
+					OsWindow();
 					~OsWindow();
 					~OsWindow();
 
 
 	/// Stub method, does nothing under Android.
 	/// Stub method, does nothing under Android.

+ 0 - 300
engine/os/linux/Input.cpp

@@ -1,300 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/XKBlib.h>
-#include "Keyboard.h"
-#include "OS.h"
-#include "Log.h"
-
-namespace crown
-{
-
-namespace os
-{
-
-//-----------------------------------------------------------------------------
-extern Display*		display;
-extern Window		window;
-extern uint32_t		window_x;
-extern uint32_t		window_y;
-extern uint32_t		window_width;
-extern uint32_t		window_height;
-
-static bool			x11_detectable_autorepeat = false;
-static Cursor		x11_hidden_cursor = None;
-
-//-----------------------------------------------------------------------------
-static void x11_create_hidden_cursor()
-{
-	// Build hidden cursor
-	Pixmap bm_no;
-	XColor black, dummy;
-	Colormap colormap;
-	static char no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-	colormap = DefaultColormap(display, DefaultScreen(display));
-	XAllocNamedColor(display, colormap, "black", &black, &dummy);
-	bm_no = XCreateBitmapFromData(display, window, no_data, 8, 8);
-	x11_hidden_cursor = XCreatePixmapCursor(display, bm_no, bm_no, &black, &black, 0, 0);
-}
-
-//-----------------------------------------------------------------------------
-static Key x11_translate_key(int32_t x11_key)
-{
-	if ((x11_key > 0x40 && x11_key < 0x5B) || (x11_key > 0x60 && x11_key < 0x7B) || (x11_key > 0x2F && x11_key < 0x3A))
-	{
-		return (Key)x11_key;
-	}
-
-	switch (x11_key)
-	{
-		case XK_BackSpace:	return KC_BACKSPACE;
-		case XK_Tab:		return KC_TAB;
-		case XK_space:		return KC_SPACE;
-		case XK_Escape:		return KC_ESCAPE;
-		case XK_Return:		return KC_ENTER;
-		case XK_F1:			return KC_F1;
-		case XK_F2:			return KC_F2;
-		case XK_F3:			return KC_F3;
-		case XK_F4:			return KC_F4;
-		case XK_F5:			return KC_F5;
-		case XK_F6:			return KC_F6;
-		case XK_F7:			return KC_F7;
-		case XK_F8:			return KC_F8;
-		case XK_F9:			return KC_F9;
-		case XK_F10:		return KC_F10;
-		case XK_F11:		return KC_F11;
-		case XK_F12:		return KC_F12;
-		case XK_Home:		return KC_HOME;
-		case XK_Left:		return KC_LEFT;
-		case XK_Up:			return KC_UP;
-		case XK_Right:		return KC_RIGHT;
-		case XK_Down:		return KC_DOWN;
-		case XK_Page_Up:	return KC_PAGE_UP;
-		case XK_Page_Down:	return KC_PAGE_DOWN;
-		case XK_Shift_L:	return KC_LSHIFT;
-		case XK_Shift_R:	return KC_RSHIFT;
-		case XK_Control_L:	return KC_LCONTROL;
-		case XK_Control_R:	return KC_RCONTROL;
-		case XK_Caps_Lock:	return KC_CAPS_LOCK;
-		case XK_Alt_L:		return KC_LALT;
-		case XK_Alt_R:		return KC_RALT;
-		case XK_Super_L:	return KC_LSUPER;
-		case XK_Super_R:	return KC_RSUPER;
-		case XK_KP_0:		return KC_KP_0;
-		case XK_KP_1:		return KC_KP_1;
-		case XK_KP_2:		return KC_KP_2;
-		case XK_KP_3:		return KC_KP_3;
-		case XK_KP_4:		return KC_KP_4;
-		case XK_KP_5:		return KC_KP_5;
-		case XK_KP_6:		return KC_KP_6;
-		case XK_KP_7:		return KC_KP_7;
-		case XK_KP_8:		return KC_KP_8;
-		case XK_KP_9:		return KC_KP_9;
-		default:			return KC_NOKEY;
-	}
-}
-
-//-----------------------------------------------------------------------------
-void init_input()
-{
-	// We want to track keyboard and mouse events
-	XSelectInput(display, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
-
-	// Check presence of detectable autorepeat
-	Bool detectable;
-	x11_detectable_autorepeat = (bool) XkbSetDetectableAutoRepeat(display, true, &detectable);
-
-	x11_create_hidden_cursor();
-}
-
-//-----------------------------------------------------------------------------
-void get_cursor_xy(int32_t& x, int32_t& y)
-{
-	Window unused;
-	int32_t pointer_x, pointer_y, dummy;
-	uint32_t dummy2;
-
-	XQueryPointer(display, window, &unused, &unused, &dummy, &dummy, &pointer_x, &pointer_y, &dummy2);
-
-	x = pointer_x;
-	y = pointer_y;
-}
-
-//-----------------------------------------------------------------------------
-void set_cursor_xy(int32_t x, int32_t y)
-{
-	uint32_t width;
-	uint32_t height;
-
-	get_render_window_metrics(width, height);
-
-	XWarpPointer(display, None, window, 0, 0, width, height, x, y);
-
-	XFlush(display);
-}
-
-//-----------------------------------------------------------------------------
-void hide_cursor()
-{
-	XDefineCursor(display, window, x11_hidden_cursor);
-}
-
-//-----------------------------------------------------------------------------
-void show_cursor()
-{
-	XDefineCursor(display, window, None);
-}
-
-//-----------------------------------------------------------------------------
-void event_loop()
-{
-	XEvent event;
-
-	OSEventParameter data_button[4] = {0, 0, 0, 0};
-	OSEventParameter data_key[4] = {0, 0, 0, 0};
-
-	while (XPending(display))
-	{
-		XNextEvent(display, &event);
-
-		switch (event.type)
-		{
-			case ConfigureNotify:
-			{
-				window_x = event.xconfigure.x;
-				window_y = event.xconfigure.y;
-				window_width = event.xconfigure.width;
-				window_height = event.xconfigure.height;
-
-				break;
-			}
-			case ButtonPress:
-			case ButtonRelease:
-			{
-				OSEventType oset_type = event.type == ButtonPress ? OSET_BUTTON_PRESS : OSET_BUTTON_RELEASE;
-
-				data_button[0].int_value = event.xbutton.x;
-				data_button[1].int_value = event.xbutton.y;
-
-				switch (event.xbutton.button)
-				{
-					case Button1:
-					{
-						data_button[2].int_value = 0;
-						push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
-						break;
-					}
-					case Button2:
-					{
-						data_button[2].int_value = 1;
-						push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
-						break;
-					}
-					case Button3:
-					{
-						data_button[2].int_value = 2;
-						push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
-						break;
-					}
-				}
-
-				break;
-			}
-			case MotionNotify:
-			{
-				push_event(OSET_MOTION_NOTIFY, data_button[0], data_button[1], data_button[2], data_button[3]);
-				break;
-			}
-			case KeyPress:
-			case KeyRelease:
-			{
-				char string[4] = {0, 0, 0, 0};
-				int32_t len = -1;
-				KeySym key;
-
-				len = XLookupString(&event.xkey, string, 4, &key, NULL);
-
-				Key kc = x11_translate_key(key);
-
-				// Check if any modifier key is pressed or released
-				int32_t modifier_mask = 0;
-
-				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-				{
-					(event.type == KeyPress) ? modifier_mask |= MK_SHIFT : modifier_mask &= ~MK_SHIFT;
-				}
-				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-				{
-					(event.type == KeyPress) ? modifier_mask |= MK_CTRL : modifier_mask &= ~MK_CTRL;
-				}
-				else if (kc == KC_LALT || kc == KC_RALT)
-				{
-					(event.type == KeyPress) ? modifier_mask |= MK_ALT : modifier_mask &= ~MK_ALT;
-				}
-
-				OSEventType oset_type = event.type == KeyPress ? OSET_KEY_PRESS : OSET_KEY_RELEASE;
-
-				data_key[0].int_value = ((int32_t)kc);
-				data_key[1].int_value = modifier_mask;
-
-				push_event(oset_type, data_key[0], data_key[1], data_key[2], data_key[3]);
-
-//				// Text input part
-//				if (event.type == KeyPress && len > 0)
-//				{
-//					//crownEvent.event_type = ET_TEXT;
-//					//crownEvent.text.type = TET_TEXT_INPUT;
-//					strncpy(keyboardEvent.text, string, 4);
-
-//					if (mListener)
-//					{
-//						mListener->TextInput(keyboardEvent);
-//					}
-//				}
-
-				break;
-			}
-			case KeymapNotify:
-			{
-				XRefreshKeyboardMapping(&event.xmapping);
-				break;
-			}
-			default:
-			{
-				break;
-			}
-		}
-	}
-}
-
-
-} // namespace os
-
-} // namespace crown
-

+ 0 - 2
engine/os/linux/LinuxOS.cpp

@@ -274,8 +274,6 @@ const char* get_env(const char* env)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void init_os()
 void init_os()
 {
 {
-	XInitThreads();
-
 	// Initilize the base time
 	// Initilize the base time
 	clock_gettime(CLOCK_MONOTONIC, &base_time);
 	clock_gettime(CLOCK_MONOTONIC, &base_time);
 }
 }

+ 1 - 1
engine/os/linux/Thread.h → engine/os/linux/OsThread.h

@@ -26,4 +26,4 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
-#include "../posix/Thread.h"
+#include "../posix/OsThread.h"

+ 14 - 289
engine/os/linux/OsWindow.cpp

@@ -25,156 +25,35 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #include "OsWindow.h"
 #include "OsWindow.h"
 #include "Assert.h"
 #include "Assert.h"
-#include "Keyboard.h"
-#include "OS.h"
-#include "GLContext.h"
 #include "StringUtils.h"
 #include "StringUtils.h"
-#include "OsEvents.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-//-----------------------------------------------------------------------------
-static Key x11_translate_key(int32_t x11_key)
-{
-	if ((x11_key > 0x40 && x11_key < 0x5B) || (x11_key > 0x60 && x11_key < 0x7B) || (x11_key > 0x2F && x11_key < 0x3A))
-	{
-		return (Key)x11_key;
-	}
+Display* m_x11_display = NULL;
+Window m_x11_window = None;
 
 
-	switch (x11_key)
-	{
-		case XK_BackSpace:	return KC_BACKSPACE;
-		case XK_Tab:		return KC_TAB;
-		case XK_space:		return KC_SPACE;
-		case XK_Escape:		return KC_ESCAPE;
-		case XK_Return:		return KC_ENTER;
-		case XK_F1:			return KC_F1;
-		case XK_F2:			return KC_F2;
-		case XK_F3:			return KC_F3;
-		case XK_F4:			return KC_F4;
-		case XK_F5:			return KC_F5;
-		case XK_F6:			return KC_F6;
-		case XK_F7:			return KC_F7;
-		case XK_F8:			return KC_F8;
-		case XK_F9:			return KC_F9;
-		case XK_F10:		return KC_F10;
-		case XK_F11:		return KC_F11;
-		case XK_F12:		return KC_F12;
-		case XK_Home:		return KC_HOME;
-		case XK_Left:		return KC_LEFT;
-		case XK_Up:			return KC_UP;
-		case XK_Right:		return KC_RIGHT;
-		case XK_Down:		return KC_DOWN;
-		case XK_Page_Up:	return KC_PAGE_UP;
-		case XK_Page_Down:	return KC_PAGE_DOWN;
-		case XK_Shift_L:	return KC_LSHIFT;
-		case XK_Shift_R:	return KC_RSHIFT;
-		case XK_Control_L:	return KC_LCONTROL;
-		case XK_Control_R:	return KC_RCONTROL;
-		case XK_Caps_Lock:	return KC_CAPS_LOCK;
-		case XK_Alt_L:		return KC_LALT;
-		case XK_Alt_R:		return KC_RALT;
-		case XK_Super_L:	return KC_LSUPER;
-		case XK_Super_R:	return KC_RSUPER;
-		case XK_KP_0:		return KC_KP_0;
-		case XK_KP_1:		return KC_KP_1;
-		case XK_KP_2:		return KC_KP_2;
-		case XK_KP_3:		return KC_KP_3;
-		case XK_KP_4:		return KC_KP_4;
-		case XK_KP_5:		return KC_KP_5;
-		case XK_KP_6:		return KC_KP_6;
-		case XK_KP_7:		return KC_KP_7;
-		case XK_KP_8:		return KC_KP_8;
-		case XK_KP_9:		return KC_KP_9;
-		default:			return KC_NOKEY;
-	}
+void oswindow_set_window(Display* dpy, Window win)
+{
+	m_x11_display = dpy;
+	m_x11_window = win;	
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsWindow::OsWindow(uint32_t width, uint32_t height, uint32_t parent) :
-	m_x11_display(NULL),
-	m_x11_window(None),
-	m_x11_parent_window(None),
-	m_x(0),
-	m_y(0),
-	m_width(width),
-	m_height(height),
-	m_resizable(true),
-	m_x11_detectable_autorepeat(false),
-	m_x11_hidden_cursor(None)
+OsWindow::OsWindow()
+	: m_x(0)
+	, m_y(0)
+	, m_width(0)
+	, m_height(0)
+	, m_resizable(true)
+	, m_x11_detectable_autorepeat(false)
 {
 {
-	CE_ASSERT(width != 0 || height != 0, "Width and height must differ from zero");
-
-	m_x11_display = XOpenDisplay(NULL);
-
-	CE_ASSERT(m_x11_display != NULL, "Unable to open X11 display");
-
-	int screen = DefaultScreen(m_x11_display);
-	int depth = DefaultDepth(m_x11_display, screen);
-	Visual* visual = DefaultVisual(m_x11_display, screen);
-
-	if (parent != 0)
-	{
-		m_x11_parent_window = (Window) parent;
-	}
-	else
-	{
-		m_x11_parent_window = RootWindow(m_x11_display, screen);
-	}
-
-	// We want to track keyboard and mouse events
-	XSetWindowAttributes win_attribs;
-	win_attribs.background_pixmap = 0;
-	win_attribs.border_pixel = 0;
-	win_attribs.event_mask = FocusChangeMask | StructureNotifyMask | KeyPressMask | 
-		KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
-
-	m_x11_window = XCreateWindow(
-				   m_x11_display,
-				   m_x11_parent_window,
-				   0, 0,
-				   width, height,
-				   0,
-				   depth,
-				   InputOutput,
-				   visual,
-				   CWBorderPixel | CWEventMask,
-				   &win_attribs
-			   );
-
-	CE_ASSERT(m_x11_window != None, "Unable to create X window");
-
-	// Check presence of detectable autorepeat
-	Bool detectable;
-	m_x11_detectable_autorepeat = (bool) XkbSetDetectableAutoRepeat(m_x11_display, true, &detectable);
-
-	// Build hidden cursor
-	Pixmap bm_no;
-	XColor black, dummy;
-	Colormap colormap;
-	static char no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-	colormap = XDefaultColormap(m_x11_display, screen);
-	XAllocNamedColor(m_x11_display, colormap, "black", &black, &dummy);
-	bm_no = XCreateBitmapFromData(m_x11_display, m_x11_window, no_data, 8, 8);
-	m_x11_hidden_cursor = XCreatePixmapCursor(m_x11_display, bm_no, bm_no, &black, &black, 0, 0);
-
-	set_x11_display_and_window(m_x11_display, m_x11_window);
+	set_title("");
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 OsWindow::~OsWindow()
 OsWindow::~OsWindow()
 {
 {
-	if (m_x11_display)
-	{
-		if (m_x11_window != None)
-		{
-			XDestroyWindow(m_x11_display, m_x11_window);
-		}
-
-		XCloseDisplay(m_x11_display);
-	}
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -248,40 +127,6 @@ void OsWindow::set_resizable(bool resizable)
 	m_resizable = resizable;
 	m_resizable = resizable;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-void OsWindow::show_cursor(bool show)
-{
-	if (show)
-	{
-		XDefineCursor(m_x11_display, m_x11_window, None);
-	}
-	else
-	{
-		XDefineCursor(m_x11_display, m_x11_window, m_x11_hidden_cursor);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void OsWindow::get_cursor_xy(int32_t& x, int32_t& y)
-{
-	Window unused;
-	int32_t pointer_x, pointer_y, dummy;
-	uint32_t dummy2;
-
-	XQueryPointer(m_x11_display, m_x11_window, &unused, &unused, &dummy, &dummy, &pointer_x, &pointer_y, &dummy2);
-
-	x = pointer_x;
-	y = pointer_y;
-}
-
-//-----------------------------------------------------------------------------
-void OsWindow::set_cursor_xy(int32_t x, int32_t y)
-{
-	XWarpPointer(m_x11_display, None, m_x11_window, 0, 0, m_width, m_height, x, y);
-
-	XFlush(m_x11_display);
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 char* OsWindow::title()
 char* OsWindow::title()
 {
 {
@@ -302,124 +147,4 @@ void OsWindow::set_title(const char* title)
 	XStoreName(m_x11_display, m_x11_window, title);
 	XStoreName(m_x11_display, m_x11_window, title);
 }
 }
 
 
-//-----------------------------------------------------------------------------
-void OsWindow::frame()
-{
-	XEvent event;
-
-	OsMouseEvent mouse_event;
-	OsKeyboardEvent keyboard_event;
-
-	while (XPending(m_x11_display))
-	{
-		XNextEvent(m_x11_display, &event);
-
-		switch (event.type)
-		{
-			case ConfigureNotify:
-			{
-				m_x = event.xconfigure.x;
-				m_y = event.xconfigure.y;
-				m_width = event.xconfigure.width;
-				m_height = event.xconfigure.height;
-				break;
-			}
-			case ButtonPress:
-			case ButtonRelease:
-			{
-				OsEventType oset_type = event.type == ButtonPress ? OSET_BUTTON_PRESS : OSET_BUTTON_RELEASE;
-
-				mouse_event.x = event.xbutton.x;
-				mouse_event.y = event.xbutton.y;
-
-				switch (event.xbutton.button)
-				{
-					case Button1:
-					{
-						mouse_event.button = 0;
-						os_event_buffer()->push_event(oset_type, &mouse_event, sizeof(OsMouseEvent));
-						break;
-					}
-					case Button2:
-					{
-						mouse_event.button = 1;
-						os_event_buffer()->push_event(oset_type, &mouse_event, sizeof(OsMouseEvent));
-						break;
-					}
-					case Button3:
-					{
-						mouse_event.button = 2;
-						os_event_buffer()->push_event(oset_type, &mouse_event, sizeof(OsMouseEvent));
-						break;
-					}
-				}
-
-				break;
-			}
-			// case MotionNotify:
-			// {
-			// 	push_event(OSET_MOTION_NOTIFY, data_button[0], data_button[1], data_button[2], data_button[3]);
-			// 	break;
-			// }
-			case KeyPress:
-			case KeyRelease:
-			{
-				char string[4] = {0, 0, 0, 0};
-				KeySym key;
-
-				XLookupString(&event.xkey, string, 4, &key, NULL);
-
-				Key kc = x11_translate_key(key);
-
-				// Check if any modifier key is pressed or released
-				int32_t modifier_mask = 0;
-
-				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-				{
-					(event.type == KeyPress) ? modifier_mask |= MK_SHIFT : modifier_mask &= ~MK_SHIFT;
-				}
-				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-				{
-					(event.type == KeyPress) ? modifier_mask |= MK_CTRL : modifier_mask &= ~MK_CTRL;
-				}
-				else if (kc == KC_LALT || kc == KC_RALT)
-				{
-					(event.type == KeyPress) ? modifier_mask |= MK_ALT : modifier_mask &= ~MK_ALT;
-				}
-
-				OsEventType oset_type = event.type == KeyPress ? OSET_KEY_PRESS : OSET_KEY_RELEASE;
-
-				keyboard_event.key = ((int32_t)kc);
-				keyboard_event.modifier = modifier_mask;
-
-				os_event_buffer()->push_event(oset_type, &keyboard_event, sizeof(OsKeyboardEvent));
-
-//				// Text input part
-//				if (event.type == KeyPress && len > 0)
-//				{
-//					//crownEvent.event_type = ET_TEXT;
-//					//crownEvent.text.type = TET_TEXT_INPUT;
-//					strncpy(keyboardEvent.text, string, 4);
-
-//					if (mListener)
-//					{
-//						mListener->TextInput(keyboardEvent);
-//					}
-//				}
-
-				break;
-			}
-			case KeymapNotify:
-			{
-				XRefreshKeyboardMapping(&event.xmapping);
-				break;
-			}
-			default:
-			{
-				break;
-			}
-		}
-	}
-}
-
 } // namespace crown
 } // namespace crown

+ 7 - 9
engine/os/linux/OsWindow.h

@@ -1,4 +1,5 @@
 /*
 /*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
 Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
 Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
 
 
 Permission is hereby granted, free of charge, to any person
 Permission is hereby granted, free of charge, to any person
@@ -35,6 +36,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
+void oswindow_set_window(Display* dpy, Window win);
+
+
 class OsWindow
 class OsWindow
 {
 {
 public:
 public:
@@ -42,9 +46,9 @@ public:
 	/// Creates the window with the given @a width and @a height.
 	/// Creates the window with the given @a width and @a height.
 	/// When @a parent is != 0, it is interpreted as the OS-specific
 	/// When @a parent is != 0, it is interpreted as the OS-specific
 	/// handle of the parent window.
 	/// handle of the parent window.
-					OsWindow(uint32_t width, uint32_t height, uint32_t parent);
+					OsWindow();
 					~OsWindow();
 					~OsWindow();
-
+					
 	void			show();
 	void			show();
 	void			hide();
 	void			hide();
 
 
@@ -68,14 +72,8 @@ public:
 	char*			title();
 	char*			title();
 	void			set_title(const char* title);
 	void			set_title(const char* title);
 
 
-	void			frame();
-
 private:
 private:
 
 
-	Display*		m_x11_display;
-	Window			m_x11_window;
-	Window			m_x11_parent_window;
-
 	uint32_t		m_x;
 	uint32_t		m_x;
 	uint32_t		m_y;
 	uint32_t		m_y;
 	uint32_t		m_width;
 	uint32_t		m_width;
@@ -83,7 +81,7 @@ private:
 	bool			m_resizable;
 	bool			m_resizable;
 
 
 	bool			m_x11_detectable_autorepeat;
 	bool			m_x11_detectable_autorepeat;
-	Cursor			m_x11_hidden_cursor;
+
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 2 - 12
engine/os/OS.cpp → engine/os/linux/Semaphore.h

@@ -24,16 +24,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
-#include "OS.h"
+#pragma once
 
 
-namespace crown
-{
-
-EventBuffer g_os_event_buffer;
-
-EventBuffer* os_event_buffer()
-{
-	return &g_os_event_buffer;
-}
-
-} // namespace crown
+#include "../posix/Semaphore.h"

+ 574 - 8
engine/os/linux/main.cpp

@@ -24,23 +24,589 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include "Config.h"
 #include "Crown.h"
 #include "Crown.h"
+#include "Device.h"
+#include "OsTypes.h"
+#include "OsEventQueue.h"
+#include "BundleCompiler.h"
 
 
-int main(int argc, char** argv)
+namespace crown
 {
 {
-	crown::init();
 
 
-	crown::Device* engine = crown::device();
-	if (!engine->init(argc, argv))
+extern void set_x11_display_and_window(Display* dpy, Window win);
+
+//-----------------------------------------------------------------------------
+void init()
+{
+	crown::memory::init();
+	crown::os::init_os();
+}
+
+//-----------------------------------------------------------------------------
+void shutdown()
+{
+	crown::memory::shutdown();
+}
+
+//-----------------------------------------------------------------------------
+static KeyboardButton::Enum x11_translate_key(KeySym x11_key)
+{
+	if ((x11_key > 0x40 && x11_key < 0x5B) || (x11_key > 0x60 && x11_key < 0x7B) || (x11_key > 0x2F && x11_key < 0x3A))
+	{
+		return (KeyboardButton::Enum) x11_key;
+	}
+
+	switch (x11_key)
+	{
+		case XK_BackSpace:	return KeyboardButton::BACKSPACE;
+		case XK_Tab:		return KeyboardButton::TAB;
+		case XK_space:		return KeyboardButton::SPACE;
+		case XK_Escape:		return KeyboardButton::ESCAPE;
+		case XK_Return:		return KeyboardButton::ENTER;
+		case XK_F1:			return KeyboardButton::F1;
+		case XK_F2:			return KeyboardButton::F2;
+		case XK_F3:			return KeyboardButton::F3;
+		case XK_F4:			return KeyboardButton::F4;
+		case XK_F5:			return KeyboardButton::F5;
+		case XK_F6:			return KeyboardButton::F6;
+		case XK_F7:			return KeyboardButton::F7;
+		case XK_F8:			return KeyboardButton::F8;
+		case XK_F9:			return KeyboardButton::F9;
+		case XK_F10:		return KeyboardButton::F10;
+		case XK_F11:		return KeyboardButton::F11;
+		case XK_F12:		return KeyboardButton::F12;
+		case XK_Home:		return KeyboardButton::HOME;
+		case XK_Left:		return KeyboardButton::LEFT;
+		case XK_Up:			return KeyboardButton::UP;
+		case XK_Right:		return KeyboardButton::RIGHT;
+		case XK_Down:		return KeyboardButton::DOWN;
+		case XK_Page_Up:	return KeyboardButton::PAGE_UP;
+		case XK_Page_Down:	return KeyboardButton::PAGE_DOWN;
+		case XK_Shift_L:	return KeyboardButton::LSHIFT;
+		case XK_Shift_R:	return KeyboardButton::RSHIFT;
+		case XK_Control_L:	return KeyboardButton::LCONTROL;
+		case XK_Control_R:	return KeyboardButton::RCONTROL;
+		case XK_Caps_Lock:	return KeyboardButton::CAPS_LOCK;
+		case XK_Alt_L:		return KeyboardButton::LALT;
+		case XK_Alt_R:		return KeyboardButton::RALT;
+		case XK_Super_L:	return KeyboardButton::LSUPER;
+		case XK_Super_R:	return KeyboardButton::RSUPER;
+		case XK_KP_0:		return KeyboardButton::KP_0;
+		case XK_KP_1:		return KeyboardButton::KP_1;
+		case XK_KP_2:		return KeyboardButton::KP_2;
+		case XK_KP_3:		return KeyboardButton::KP_3;
+		case XK_KP_4:		return KeyboardButton::KP_4;
+		case XK_KP_5:		return KeyboardButton::KP_5;
+		case XK_KP_6:		return KeyboardButton::KP_6;
+		case XK_KP_7:		return KeyboardButton::KP_7;
+		case XK_KP_8:		return KeyboardButton::KP_8;
+		case XK_KP_9:		return KeyboardButton::KP_9;
+		default:			return KeyboardButton::NONE;
+	}
+}
+
+struct MainArgs
+{
+	int argc;
+	char** argv;
+	class LinuxDevice* device;
+};
+
+class LinuxDevice : public Device
+{
+public:
+
+	//-----------------------------------------------------------------------------
+	LinuxDevice()
+		: m_x11_display(NULL)
+		, m_x11_window(None)
+		, m_x11_parent_window(None)
+		, m_x11_hidden_cursor(None)
+		, m_exit(false)
+		, m_x(0)
+		, m_y(0)
+		, m_width(1000)
+		, m_height(625)
+		, m_parent_window_handle(0)
+		, m_fullscreen(0)
+		, m_compile(0)
+		, m_continue(0)
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	void init(int argc, char** argv)
+	{
+		parse_command_line(argc, argv);
+		check_preferred_settings();
+
+		#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
+			if (m_compile == 1)
+			{
+				m_bundle_compiler = CE_NEW(default_allocator(), BundleCompiler);
+				if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir))
+				{
+					CE_DELETE(default_allocator(), m_bundle_compiler);
+					Log::e("Exiting.");
+					exit(EXIT_FAILURE);
+				}
+
+				if (!m_continue)
+				{
+					CE_DELETE(default_allocator(), m_bundle_compiler);
+					exit(EXIT_SUCCESS);
+				}
+			}
+		#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	void shutdown()
+	{
+		#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
+			CE_DELETE(default_allocator(), m_bundle_compiler);
+		#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	int32_t run(int argc, char** argv)
+	{
+		init(argc, argv);
+
+		XInitThreads();
+		CE_ASSERT(m_width != 0 || m_height != 0, "Width and height must differ from zero");
+
+		m_x11_display = XOpenDisplay(NULL);
+
+		CE_ASSERT(m_x11_display != NULL, "Unable to open X11 display");
+
+		int screen = DefaultScreen(m_x11_display);
+		int depth = DefaultDepth(m_x11_display, screen);
+		Visual* visual = DefaultVisual(m_x11_display, screen);
+
+		if (m_parent_window_handle != 0)
+		{
+			m_x11_parent_window = (Window) m_parent_window_handle;
+		}
+		else
+		{
+			m_x11_parent_window = RootWindow(m_x11_display, screen);
+		}
+
+		// We want to track keyboard and mouse events
+		XSetWindowAttributes win_attribs;
+		win_attribs.background_pixmap = 0;
+		win_attribs.border_pixel = 0;
+		win_attribs.event_mask = FocusChangeMask | StructureNotifyMask | KeyPressMask | 
+			KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
+
+		m_x11_window = XCreateWindow(
+					   m_x11_display,
+					   m_x11_parent_window,
+					   0, 0,
+					   m_width, m_height,
+					   0,
+					   depth,
+					   InputOutput,
+					   visual,
+					   CWBorderPixel | CWEventMask,
+					   &win_attribs
+				   );
+
+		CE_ASSERT(m_x11_window != None, "Unable to create X window");
+
+		// Check presence of detectable autorepeat
+		Bool detectable;
+		m_x11_detectable_autorepeat = (bool) XkbSetDetectableAutoRepeat(m_x11_display, true, &detectable);
+
+		// Build hidden cursor
+		Pixmap bm_no;
+		XColor black, dummy;
+		Colormap colormap;
+		static char no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+		colormap = XDefaultColormap(m_x11_display, screen);
+		XAllocNamedColor(m_x11_display, colormap, "black", &black, &dummy);
+		bm_no = XCreateBitmapFromData(m_x11_display, m_x11_window, no_data, 8, 8);
+		m_x11_hidden_cursor = XCreatePixmapCursor(m_x11_display, bm_no, bm_no, &black, &black, 0, 0);
+
+		m_wm_delete_message = XInternAtom(m_x11_display, "WM_DELETE_WINDOW", False);
+		XSetWMProtocols(m_x11_display, m_x11_window, &m_wm_delete_message, 1);
+
+		XMapRaised(m_x11_display, m_x11_window);
+
+		oswindow_set_window(m_x11_display, m_x11_window);
+		set_x11_display_and_window(m_x11_display, m_x11_window);
+
+		OsThread game_thread("game-thread");
+		game_thread.start(main_loop, (void*)this);
+
+		while (!m_exit)
+		{
+			LinuxDevice::pump_events();
+		}
+
+		game_thread.stop();
+
+		LinuxDevice::shutdown();
+		XDestroyWindow(m_x11_display, m_x11_window);
+		XCloseDisplay(m_x11_display);
+
+		return EXIT_SUCCESS;
+	}
+
+	//-----------------------------------------------------------------------------
+	int32_t loop()
+	{
+		Device::init();
+
+		while(!process_events() && is_running())
+		{
+			Device::frame();
+
+			m_keyboard->update();
+			m_mouse->update();
+		}
+
+		Device::shutdown();
+
+		m_exit = true;
+
+		return 0;
+	}
+
+	//-----------------------------------------------------------------------------
+	static int32_t main_loop(void* thiz)
 	{
 	{
-		exit(EXIT_FAILURE);
+		return ((LinuxDevice*)thiz)->loop();
 	}
 	}
 
 
-	while (engine->is_running())
+	//-----------------------------------------------------------------------------
+	bool process_events()
 	{
 	{
-		engine->frame();
+		OsEvent event;
+		do
+		{
+			m_queue.pop_event(&event);
+
+			if (event.type != OsEvent::NONE)
+			{
+				switch (event.type)
+				{
+					case OsEvent::MOUSE:
+					{
+						const OsMouseEvent& ev = event.mouse;
+						switch (ev.type)
+						{
+							case OsMouseEvent::BUTTON: m_mouse->set_button_state(ev.x, ev.y, ev.button, ev.pressed); break;
+							case OsMouseEvent::MOVE: m_mouse->set_position(ev.x, ev.y); break;
+							default: CE_FATAL("Oops, unknown mouse event type"); break;
+						}
+
+						break;
+					}
+					case OsEvent::KEYBOARD:
+					{
+						const OsKeyboardEvent& ev = event.keyboard;
+						m_keyboard->set_button_state(ev.button, ev.pressed);
+						break;
+					}
+					case OsEvent::METRICS:
+					{
+						const OsMetricsEvent& ev = event.metrics;
+						m_mouse->set_metrics(ev.width, ev.height);
+						break;
+					}
+					case OsEvent::EXIT:
+					{
+						return true;
+					}
+					default:
+					{
+						Log::d("Unmanaged");
+						break;
+					}
+				}
+			}
+		}
+		while (event.type != OsEvent::NONE);
+
+		return false;
+	}
+
+	//-----------------------------------------------------------------------------
+	void pump_events()
+	{
+		while (XPending(m_x11_display))
+		{
+			XEvent event;
+			XNextEvent(m_x11_display, &event);
+
+			switch (event.type)
+			{
+				case ClientMessage:
+				{
+					if ((Atom)event.xclient.data.l[0] == m_wm_delete_message)
+					{
+						m_queue.push_exit_event(0);
+					}
+					break;
+				}
+				case ConfigureNotify:
+				{
+					m_x = event.xconfigure.x;
+					m_y = event.xconfigure.y;
+					m_width = event.xconfigure.width;
+					m_height = event.xconfigure.height;
+
+					m_queue.push_metrics_event(event.xconfigure.x, event.xconfigure.y,
+												event.xconfigure.width, event.xconfigure.height);
+
+					break;
+				}
+				case ButtonPress:
+				case ButtonRelease:
+				{
+					MouseButton::Enum mb;
+					switch (event.xbutton.button)
+					{
+						case Button1: mb = MouseButton::LEFT; break;
+						case Button2: mb = MouseButton::MIDDLE; break;
+						case Button3: mb = MouseButton::RIGHT; break;
+						default: mb = MouseButton::NONE; break;
+					}
+
+					if (mb != MouseButton::NONE)
+					{
+						m_queue.push_mouse_event(event.xbutton.x, event.xbutton.y, mb, event.type == ButtonPress);
+					}
+
+					break;
+				}
+				case MotionNotify:
+				{
+					m_queue.push_mouse_event(event.xmotion.x, event.xmotion.y);
+					break;
+				}
+				case KeyPress:
+				case KeyRelease:
+				{
+					char string[4] = {0, 0, 0, 0};
+					KeySym key;
+
+					XLookupString(&event.xkey, string, 4, &key, NULL);
+
+					KeyboardButton::Enum kb = x11_translate_key(key);
+
+					// Check if any modifier key is pressed or released
+					int32_t modifier_mask = 0;
+
+					if (kb == KeyboardButton::LSHIFT || kb == KeyboardButton::RSHIFT)
+					{
+						(event.type == KeyPress) ? modifier_mask |= ModifierButton::SHIFT : modifier_mask &= ~ModifierButton::SHIFT;
+					}
+					else if (kb == KeyboardButton::LCONTROL || kb == KeyboardButton::RCONTROL)
+					{
+						(event.type == KeyPress) ? modifier_mask |= ModifierButton::CTRL : modifier_mask &= ~ModifierButton::CTRL;
+					}
+					else if (kb == KeyboardButton::LALT || kb == KeyboardButton::RALT)
+					{
+						(event.type == KeyPress) ? modifier_mask |= ModifierButton::ALT : modifier_mask &= ~ModifierButton::ALT;
+					}
+
+					m_queue.push_keyboard_event(modifier_mask, kb, event.type == KeyPress);
+
+	//				// Text input part
+	//				if (event.type == KeyPress && len > 0)
+	//				{
+	//					//crownEvent.event_type = ET_TEXT;
+	//					//crownEvent.text.type = TET_TEXT_INPUT;
+	//					strncpy(keyboardEvent.text, string, 4);
+
+	//					if (mListener)
+	//					{
+	//						mListener->TextInput(keyboardEvent);
+	//					}
+	//				}
+
+					break;
+				}
+				case KeymapNotify:
+				{
+					XRefreshKeyboardMapping(&event.xmapping);
+					break;
+				}
+				default:
+				{
+					break;
+				}
+			}
+		}
 	}
 	}
 
 
-	engine->shutdown();
+	//-----------------------------------------------------------------------------
+	void parse_command_line(int argc, char** argv)
+	{
+		static const char* help_message =
+			"Usage: crown [options]\n"
+			"Options:\n\n"
+
+			"All of the following options take precedence over\n"
+			"environment variables and configuration files.\n\n"
+
+			"  --help                     Show this help.\n"
+			"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
+			"  --width <width>            Set the <width> of the main window.\n"
+			"  --height <width>           Set the <height> of the main window.\n"
+			"  --fullscreen               Start in fullscreen.\n"
+			"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
+			"                             Used only by tools.\n"
+
+			"\nAvailable only in debug and development builds:\n\n"
+
+			"  --source-dir <path>        Use <path> as the source directory for resource compilation.\n"
+			"  --compile                  Run the engine as resource compiler.\n"
+			"  --continue                 Do a full compile of the resources and continue the execution.\n";
+
+		static ArgsOption options[] = 
+		{
+			{ "help",             AOA_NO_ARGUMENT,       NULL,        'i' },
+			{ "source-dir",       AOA_REQUIRED_ARGUMENT, NULL,        's' },
+			{ "bundle-dir",       AOA_REQUIRED_ARGUMENT, NULL,        'b' },
+			{ "compile",          AOA_NO_ARGUMENT,       &m_compile,   1 },
+			{ "continue",         AOA_NO_ARGUMENT,       &m_continue,  1 },
+			{ "width",            AOA_REQUIRED_ARGUMENT, NULL,        'w' },
+			{ "height",           AOA_REQUIRED_ARGUMENT, NULL,        'h' },
+			{ "fullscreen",       AOA_NO_ARGUMENT,       &m_fullscreen, 1 },
+			{ "parent-window",    AOA_REQUIRED_ARGUMENT, NULL,        'p' },
+			{ NULL, 0, NULL, 0 }
+		};
+
+		Args args(argc, argv, "", options);
+
+		int32_t opt;
+		while ((opt = args.getopt()) != -1)
+		{
+			switch (opt)
+			{
+				case 0:
+				{
+					break;
+				}
+				// Source directory
+				case 's':
+				{
+					string::strncpy(m_source_dir, args.optarg(), MAX_PATH_LENGTH);
+					break;
+				}
+				// Bundle directory
+				case 'b':
+				{
+					string::strncpy(m_bundle_dir, args.optarg(), MAX_PATH_LENGTH);
+					break;
+				}
+				// Window width
+				case 'w':
+				{
+					m_width = atoi(args.optarg());
+					break;
+				}
+				// Window height
+				case 'h':
+				{
+					m_height = atoi(args.optarg());
+					break;
+				}
+				// Parent window
+				case 'p':
+				{
+					m_parent_window_handle = string::parse_uint(args.optarg());
+					break;
+				}
+				case 'i':
+				case '?':
+				default:
+				{
+					os::printf(help_message);
+					exit(EXIT_FAILURE);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------------------------------
+	void check_preferred_settings()
+	{
+		if (m_compile == 1)
+		{
+			if (string::strcmp(m_source_dir, "") == 0)
+			{
+				Log::e("You have to specify the source directory when running in compile mode.");
+				exit(EXIT_FAILURE);
+			}
+
+			if (!os::is_absolute_path(m_source_dir))
+			{
+				Log::e("The source directory must be absolute.");
+				exit(EXIT_FAILURE);
+			}
+		}
+
+		if (!os::is_absolute_path(m_bundle_dir))
+		{
+			Log::e("The bundle directory must be absolute.");
+			exit(EXIT_FAILURE);
+		}
+
+		if (m_width == 0 || m_height == 0)
+		{
+			Log::e("Window width and height must be greater than zero.");
+			exit(EXIT_FAILURE);
+		}
+	}
+
+
+private:
+
+	Display* m_x11_display;
+	Window m_x11_window;
+	Window m_x11_parent_window;
+	Cursor m_x11_hidden_cursor;
+	Atom m_wm_delete_message;
+
+	bool m_exit;
+	uint32_t m_x;
+	uint32_t m_y;
+	uint32_t m_width;
+	uint32_t m_height;
+	bool m_x11_detectable_autorepeat;
+
+	uint32_t m_parent_window_handle;
+	int32_t m_fullscreen;
+	int32_t m_compile;
+	int32_t m_continue;
+
+	OsEventQueue m_queue;
+};
+
+} // namespace crown
+
+int main(int argc, char** argv)
+{
+	crown::init();
+
+	crown::LinuxDevice* engine = CE_NEW(crown::default_allocator(), crown::LinuxDevice)();
+	crown::set_device(engine);
+	
+	int32_t ret = engine->run(argc, argv);
+
+	CE_DELETE(crown::default_allocator(), engine);
+
 	crown::shutdown();
 	crown::shutdown();
+	return ret;
 }
 }

+ 0 - 320
engine/os/linux/main2.cpp

@@ -1,320 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Crown.h"
-#include "FPSSystem.h"
-
-using namespace crown;
-
-Renderer* r;
-IndexBufferId monkey_ib;
-VertexBufferId monkey_vb;
-IndexBufferId cube_ib;
-VertexBufferId cube_vb;
-IndexBufferId cone_ib;
-VertexBufferId cone_vb;
-
-GPUProgramId default_program;
-GPUProgramId texture_program;
-Camera* camera;
-FPSSystem* fps;
-
-TextureId grass_texture;
-TextureId lightmap_texture;
-IndexBufferId quad_ib;
-VertexBufferId quad_vb;
-
-UniformId u_albedo_0;
-UniformId u_lightmap_0;
-UniformId u_brightness;
-
-static float quad_vertices[] =
-{
-	-1.0f, -1.0f, 0.0f, 
-	 0.0f, 0.0f, 1.0f,
-	 1.0f, 1.0f, 1.0f, 1.0f,
-	 0.0f, 0.0f,
-
-	 1.0f, -1.0f, 0.0f,
-	 0.0f, 0.0f, 1.0f,
-	 1.0f, 1.0f, 1.0f, 1.0f,
-	 1.0f, 0.0f,
-
-	 1.0f,  1.0f, 0.0f,
-	 0.0f, 0.0f, 1.0f,
-	 1.0f, 1.0f, 1.0f, 1.0f,
-	 1.0f, 1.0f,
-
-	-1.0f,  1.0f, 0.0f,
-	 0.0f, 0.0f, 1.0f,
-	 1.0f, 1.0f, 1.0f, 1.0f,
-	 0.0f, 1.0f
-};
-
-static uint16_t quad_indices[] =
-{
-	0, 1, 3,
-	1, 2, 3
-};
-
-static const char* default_vertex =
-	"in vec4           a_position;"
-	"in vec4           a_normal;"
-	"in vec2           a_tex_coord0;"
-	"in vec4           a_color;"
-
-	"uniform mat4      u_model;"
-	"uniform mat4      u_model_view_projection;"
-
-	"varying out vec2  tex_coord0;"
-	"varying out vec4  color;"
-
-	"void main(void)"
-	"{"
-	"	tex_coord0 = a_tex_coord0;"
-	"   color = a_color;"
-	"	gl_Position = u_model_view_projection * a_position;"
-	"}";
-
-static const char* default_fragment = 
-	"void main(void)"
-	"{"
-	"	gl_FragColor = vec4(1, 0, 0, 0);"
-	"}";
-
-static const char* texture_fragment = 
-	"in vec2            tex_coord0;"
-	"in vec4            color;"
-
-	"uniform sampler2D  u_albedo_0;"
-	"uniform sampler2D  u_lightmap_0;"
-	"uniform float      u_brightness;"
-
-	"void main(void)"
-	"{"
-	"	gl_FragColor = texture(u_albedo_0, tex_coord0);"
-	"}";
-
-void draw(float dt)
-{
-	Mat4 pose; pose.load_identity();
-
-	fps->update(dt);
-	fps->set_view_by_cursor();
-
-	//-----------------------
-	r->set_layer_view(0, camera->view_matrix());
-	r->set_layer_projection(0, camera->projection_matrix());
-	r->set_layer_viewport(0, 0, 0, 1000, 625);
-	r->set_layer_clear(0, CLEAR_COLOR | CLEAR_DEPTH, Color4::LIGHTBLUE, 1.0f);
-
-	r->set_state(STATE_DEPTH_WRITE | STATE_COLOR_WRITE | STATE_CULL_CCW);
-	r->commit(0);
-
-	static uint64_t prim = STATE_PRIMITIVE_TRIANGLES;
-	if (device()->keyboard()->key_pressed(KC_z))
-	{
-		prim = STATE_PRIMITIVE_TRIANGLES;
-	}
-	else if (device()->keyboard()->key_pressed(KC_x))
-	{
-		prim = STATE_PRIMITIVE_POINTS;
-	}
-	else if (device()->keyboard()->key_pressed(KC_c))
-	{
-		prim = STATE_PRIMITIVE_LINES;
-	}
-
-	static uint32_t filter = TEXTURE_FILTER_NEAREST;
-	if (device()->keyboard()->key_pressed(KC_1))
-	{
-		filter = TEXTURE_FILTER_NEAREST;
-	}
-	else if (device()->keyboard()->key_pressed(KC_2))
-	{
-		filter = TEXTURE_FILTER_LINEAR;
-	}
-	else if (device()->keyboard()->key_pressed(KC_3))
-	{
-		filter = TEXTURE_FILTER_BILINEAR;
-	}
-	else if (device()->keyboard()->key_pressed(KC_4))
-	{
-		filter = TEXTURE_FILTER_TRILINEAR;
-	}
-	static float brightness = 1.0f;
-	if (device()->keyboard()->key_pressed(KC_UP))
-	{
-		brightness += 0.01f;
-	}
-	else if (device()->keyboard()->key_pressed(KC_DOWN))
-	{
-		brightness += -0.01f;
-	}
-	if (brightness > 1.0f)
-		brightness = 1.0f;
-
-	//-----------------------
-	// r->set_state(prim | STATE_DEPTH_WRITE | STATE_COLOR_WRITE | STATE_CULL_CW);
-	// r->set_vertex_buffer(monkey_vb);
-	// r->set_index_buffer(monkey_ib);
-	// r->set_program(default_program);
-	// pose.set_translation(Vec3(-3, 0, -3));
-	// r->set_pose(pose);
-	// r->commit(0);
-
-	//-----------------------
-	r->set_state(prim | STATE_DEPTH_WRITE | STATE_COLOR_WRITE | STATE_CULL_CW);
-	r->set_vertex_buffer(cube_vb);
-	r->set_index_buffer(cube_ib);
-	r->set_program(texture_program);
-	r->set_texture(0, u_albedo_0, grass_texture, filter | TEXTURE_WRAP_CLAMP_EDGE);
-	r->set_texture(1, u_lightmap_0, lightmap_texture, filter | TEXTURE_WRAP_CLAMP_EDGE);
-	r->set_uniform(u_brightness, UNIFORM_FLOAT_1, &brightness, 1);
-
-	pose.set_translation(Vec3(0, 0, -3));
-	r->set_pose(pose);
-	r->commit(0);
-
-	//-----------------------
-	// r->set_state(prim | STATE_DEPTH_WRITE | STATE_COLOR_WRITE | STATE_ALPHA_WRITE | STATE_CULL_CW);
-	// r->set_vertex_buffer(cone_vb);
-	// r->set_index_buffer(cone_ib);
-	// r->set_program(default_program);
-
-	// pose.set_translation(Vec3(3, 0, -3));
-	// r->set_pose(pose);
-	// r->commit(0);
-
-	//-----------------------
-	// r->set_state(prim | STATE_DEPTH_WRITE | STATE_COLOR_WRITE | STATE_ALPHA_WRITE | STATE_CULL_CW);
-	// r->set_vertex_buffer(quad_vb);
-	// r->set_index_buffer(quad_ib);
-	// r->set_program(texture_program);
-	// r->set_texture(0, u_albedo_0, grass_texture, filter | TEXTURE_WRAP_CLAMP_EDGE);
-	// r->set_texture(1, u_lightmap_0, lightmap_texture, filter | TEXTURE_WRAP_CLAMP_EDGE);
-	// r->set_uniform(u_brightness, UNIFORM_FLOAT_1, &brightness, 1);
-
-	// pose.set_translation(Vec3(0, 0, -1));
-	// r->set_pose(pose);
-	// r->commit(0);
-}
-
-int main(int argc, char** argv)
-{
-	crown::init();
-
-	Device* engine = device();
-	engine->init(argc, argv);
-
-	// Load resources
-	ResourceManager* resman = engine->resource_manager();
-	ResourceId texture = resman->load("texture", "ship");
-	ResourceId lightmap = resman->load("texture", "lightmap");
-	ResourceId monkey = resman->load("mesh", "monkey");
-	ResourceId cube = resman->load("mesh", "ship");
-	ResourceId cone = resman->load("mesh", "cone");
-	resman->flush();
-
-	TextureResource* texture_resource = (TextureResource*)resman->data(texture);
-	TextureResource* lightmap_resource = (TextureResource*)resman->data(lightmap);
-	MeshResource* monkey_resource = (MeshResource*)resman->data(monkey);
-	MeshResource* cube_resource = (MeshResource*)resman->data(cube);
-	MeshResource* cone_resource = (MeshResource*)resman->data(cone);
-
-	Log::d("monkey format = %d", monkey_resource->vertex_format());
-	Log::d("monkey vcount = %d", monkey_resource->num_vertices());
-	Log::d("cube format   = %d", cube_resource->vertex_format());
-	Log::d("cube vcount   = %d", cube_resource->num_vertices());
-	Log::d("cone format = %d", cone_resource->vertex_format());
-	Log::d("cone vcount = %d", cone_resource->num_vertices());
-
-	// Create vb/ib
-	r = engine->renderer();
-	monkey_vb = r->create_vertex_buffer(monkey_resource->num_vertices(), monkey_resource->vertex_format(), monkey_resource->vertices());
-	monkey_ib = r->create_index_buffer(monkey_resource->num_indices(), monkey_resource->indices());
-	cube_vb = r->create_vertex_buffer(cube_resource->num_vertices(), cube_resource->vertex_format(), cube_resource->vertices());
-	cube_ib = r->create_index_buffer(cube_resource->num_indices(), cube_resource->indices());
-	cone_vb = r->create_vertex_buffer(cone_resource->num_vertices(), cone_resource->vertex_format(), cone_resource->vertices());
-	cone_ib = r->create_index_buffer(cone_resource->num_indices(), cone_resource->indices());
-
-	// Create texture
-	grass_texture = r->create_texture(texture_resource->width(), texture_resource->height(), texture_resource->format(),
-										texture_resource->data());
-	lightmap_texture = r->create_texture(lightmap_resource->width(), lightmap_resource->height(), lightmap_resource->format(),
-										lightmap_resource->data());
-
-	quad_vb = r->create_vertex_buffer(4, VERTEX_P3_N3_C4_T2, quad_vertices);
-	quad_ib = r->create_index_buffer(6, quad_indices);
-
-	ShaderId default_vs = r->create_shader(SHADER_VERTEX, default_vertex);
-	ShaderId default_fs = r->create_shader(SHADER_FRAGMENT, default_fragment);
-	ShaderId texture_fs = r->create_shader(SHADER_FRAGMENT, texture_fragment);
-
-	u_albedo_0 = r->create_uniform("u_albedo_0", UNIFORM_INTEGER_1, 1);
-	u_lightmap_0 = r->create_uniform("u_lightmap_0", UNIFORM_INTEGER_1, 1);
-	u_brightness = r->create_uniform("u_brightness", UNIFORM_FLOAT_1, 1);
-
-	default_program = r->create_gpu_program(default_vs, default_fs);
-	texture_program = r->create_gpu_program(default_vs, texture_fs);
-
-	// Create camera
-	TempAllocator2048 alloc;
-	camera = CE_NEW(alloc, Camera)(Vec3(0, 0, 3), 90.0f, 16.0f/9.0f);
-	fps = CE_NEW(alloc, FPSSystem)(camera, 3.0f, 2.5f);
-
-	while (engine->is_running())
-	{
-		engine->frame(draw);
-	}
-
-	//resman->unload(mesh);
-	resman->unload(texture);
-	resman->unload(lightmap);
-	resman->unload(monkey);
-	resman->unload(cube);
-	resman->unload(cone);
-	r->destroy_index_buffer(monkey_ib);
-	r->destroy_vertex_buffer(monkey_vb);
-	r->destroy_index_buffer(cube_ib);
-	r->destroy_vertex_buffer(cube_vb);
-	r->destroy_index_buffer(cone_ib);
-	r->destroy_vertex_buffer(cone_vb);
-
-	r->destroy_shader(default_vs);
-	r->destroy_shader(default_fs);
-	r->destroy_shader(texture_fs);
-	r->destroy_gpu_program(default_program);
-	r->destroy_gpu_program(texture_program);
-	r->destroy_vertex_buffer(quad_vb);
-	r->destroy_index_buffer(quad_ib);
-	r->destroy_uniform(u_albedo_0);
-	r->destroy_uniform(u_lightmap_0);
-	r->destroy_uniform(u_brightness);
-
-	engine->shutdown();
-	crown::shutdown();
-}

+ 14 - 14
engine/os/posix/Thread.h → engine/os/posix/OsThread.h

@@ -38,12 +38,12 @@ namespace crown
 
 
 typedef int32_t (*ThreadFunction)(void*);
 typedef int32_t (*ThreadFunction)(void*);
 
 
-class Thread
+class OsThread
 {
 {
 public:
 public:
 
 
-						Thread(const char* name);
-						~Thread();
+						OsThread(const char* name);
+						~OsThread();
 
 
 	void				start(ThreadFunction func, void* data = NULL, size_t stack_size = 0);
 	void				start(ThreadFunction func, void* data = NULL, size_t stack_size = 0);
 	void				stop();
 	void				stop();
@@ -70,7 +70,7 @@ private:
 };
 };
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline Thread::Thread(const char* name) :
+inline OsThread::OsThread(const char* name) :
 	m_name(name),
 	m_name(name),
 	m_handle(0),
 	m_handle(0),
 	m_function(NULL),
 	m_function(NULL),
@@ -82,14 +82,14 @@ inline Thread::Thread(const char* name) :
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline Thread::~Thread()
+inline OsThread::~OsThread()
 {
 {
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline void Thread::start(ThreadFunction func, void* data, size_t stack_size)
+inline void OsThread::start(ThreadFunction func, void* data, size_t stack_size)
 {
 {
-	CE_ASSERT(!m_is_running, "Thread is already running");
+	CE_ASSERT(!m_is_running, "OsThread is already running");
 	CE_ASSERT(func != NULL, "Function must be != NULL");
 	CE_ASSERT(func != NULL, "Function must be != NULL");
 
 
 	m_function = func;
 	m_function = func;
@@ -122,25 +122,25 @@ inline void Thread::start(ThreadFunction func, void* data, size_t stack_size)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline void Thread::stop()
+inline void OsThread::stop()
 {
 {
-	CE_ASSERT(m_is_running, "Thread is not running");
+	CE_ASSERT(m_is_running, "OsThread is not running");
 	
 	
 	int32_t result = pthread_join(m_handle, NULL);
 	int32_t result = pthread_join(m_handle, NULL);
-	CE_ASSERT(result == 0, "Thread join failed. errno: %d", result);
+	CE_ASSERT(result == 0, "OsThread join failed. errno: %d", result);
 
 
 	m_is_running = false;
 	m_is_running = false;
 	m_handle = 0;
 	m_handle = 0;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline bool Thread::is_running()
+inline bool OsThread::is_running()
 {
 {
 	return m_is_running;
 	return m_is_running;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline int32_t Thread::run()
+inline int32_t OsThread::run()
 {
 {
 	m_sem.post();
 	m_sem.post();
 	
 	
@@ -148,10 +148,10 @@ inline int32_t Thread::run()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline void* Thread::thread_proc(void* arg)
+inline void* OsThread::thread_proc(void* arg)
 {
 {
 	static int32_t result = -1;
 	static int32_t result = -1;
-	result = ((Thread*)arg)->run();
+	result = ((OsThread*)arg)->run();
 
 
 	return (void*)&result;
 	return (void*)&result;
 }
 }

+ 38 - 10
engine/input/Accelerometer.cpp → engine/os/win/AtomicInt.h

@@ -24,21 +24,49 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
-#include "Accelerometer.h"
+#pragma once
+
+#include "Types.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-//-----------------------------------------------------------------------------
-Accelerometer::Accelerometer() :
-	m_orientation(0.0f, 0.0f, 0.0f)
+struct AtomicInt
 {
 {
-}
+	explicit AtomicInt(int32_t value)
+	{
+		m_value = value;
+	}
 
 
-//-----------------------------------------------------------------------------
-const Vec3& Accelerometer::orientation() const
-{
-	return m_orientation;
-}
+	AtomicInt& operator+=(int32_t value)
+	{
+		InterlockedAdd(&m_value, value);
+		return *this;
+	}
+
+	AtomicInt& operator++(void)
+	{
+		InterlockedIncrement(&m_value);
+	}
+
+	AtomicInt& operator--(void)
+	{
+		InterlockedDecrement(&m_value);
+	}
+
+	AtomicInt& operator=(int32_t value)
+	{
+		InterlockedExchange(&m_value, value);
+	}
+
+	operator int32_t()
+	{
+		return m_value;
+	}
+
+private:
+
+	LONG m_value;
+};
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 55
engine/os/win/Cond.cpp

@@ -1,55 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Cond.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-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 crown

+ 23 - 0
engine/os/win/Cond.h

@@ -54,4 +54,27 @@ private:
 	CONDITION_VARIABLE	m_cond;
 	CONDITION_VARIABLE	m_cond;
 };
 };
 
 
+//-----------------------------------------------------------------------------
+inline Cond::Cond()
+{
+	InitializeConditionVariable(&m_cond);
+}
+
+//-----------------------------------------------------------------------------
+inline Cond::~Cond()
+{
+}
+
+//-----------------------------------------------------------------------------
+inline void Cond::signal()
+{
+	WakeConditionVariable(&m_cond);
+}
+
+//-----------------------------------------------------------------------------
+inline void Cond::wait(Mutex& mutex)
+{
+	SleepConditionVariableCS(&m_cond, &mutex.m_cs, INFINITE);
+}
+
 } // namespace crown
 } // namespace crown

+ 24 - 0
engine/os/win/Mutex.h

@@ -55,4 +55,28 @@ private:
 	friend class		Cond;
 	friend class		Cond;
 };
 };
 
 
+//-----------------------------------------------------------------------------
+inline Mutex::Mutex()
+{
+	InitializeCriticalSection(&m_cs);
+}
+
+//-----------------------------------------------------------------------------
+inline Mutex::~Mutex()
+{
+	DeleteCriticalSection(&m_cs);
+}
+
+//-----------------------------------------------------------------------------
+inline void Mutex::lock()
+{
+    EnterCriticalSection(&m_cs); 
+}
+
+//-----------------------------------------------------------------------------
+inline void Mutex::unlock()
+{
+    LeaveCriticalSection(&m_cs);
+}
+
 } // namespace crown
 } // namespace crown

+ 156 - 0
engine/os/win/OsThread.h

@@ -0,0 +1,156 @@
+/*
+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 <windows.h>
+#include <process.h>
+#include <WinBase.h>
+
+#include "Types.h"
+#include "OS.h"
+#include "Semaphore.h"
+#include "Assert.h"
+
+namespace crown
+{
+
+typedef int32_t (*ThreadFunction)(void*);
+
+class OsThread
+{
+public:
+						OsThread(const char* name);
+						~OsThread();
+
+	void				start(ThreadFunction func, void* data = NULL, size_t stack_size = 0);
+	void				stop();
+
+	bool				is_running();
+
+private:
+
+	int32_t				run();
+
+	static DWORD WINAPI	thread_proc(void* arg);
+
+	OsThread(const OsThread& t); // no copy constructor
+	OsThread& operator=(const OsThread& t); // no assignment operator	
+
+private:
+
+	const char*			m_name;
+	HANDLE				m_handle;
+
+	ThreadFunction 		m_function;
+	void*				m_data;
+	Semaphore			m_sem;
+	size_t 				m_stack_size;
+
+	bool				m_is_running :1;
+
+	DWORD				m_exit_code;
+};
+
+//-----------------------------------------------------------------------------
+CE_INLINE OsThread::OsThread(const char* name) :
+	m_name(name),
+	m_handle(INVALID_HANDLE_VALUE),
+	m_function(NULL),
+	m_data(NULL),
+	m_stack_size(0),
+	m_is_running(false),
+	m_exit_code(0)
+{
+	memset(&m_handle, 0, sizeof(HANDLE));
+}
+
+//-----------------------------------------------------------------------------
+CE_INLINE OsThread::~OsThread()
+{
+	if (m_is_running)
+	{
+		stop();
+	}
+}
+
+//-----------------------------------------------------------------------------
+CE_INLINE void OsThread::start(ThreadFunction func, void* data, size_t stack_size)
+{
+	CE_ASSERT(!m_is_running, "Thread is already running");
+	CE_ASSERT(func != NULL, "Function must be != NULL");
+
+	m_function = func;
+	m_data = data;
+	m_stack_size = stack_size;
+
+	m_handle = CreateThread(NULL, stack_size, OsThread::thread_proc, this, 0, NULL);
+
+	CE_ASSERT(m_handle != NULL, "Failed to create the thread '%s'", m_name);
+
+	m_is_running = true;
+
+	m_sem.wait();
+}
+
+//-----------------------------------------------------------------------------
+CE_INLINE void OsThread::stop()
+{
+	CE_ASSERT(m_is_running, "Thread is not running");
+
+	WaitForSingleObject(m_handle, INFINITE);
+	GetExitCodeThread(m_handle, &m_exit_code);
+	CloseHandle(m_handle);
+	m_handle = INVALID_HANDLE_VALUE;
+
+	m_is_running = false;
+}
+
+//-----------------------------------------------------------------------------
+CE_INLINE bool OsThread::is_running()
+{
+	return m_is_running;
+}
+
+//-----------------------------------------------------------------------------
+CE_INLINE int32_t OsThread::run()
+{
+	m_sem.post();
+
+	return m_function(m_data);
+}
+
+//-----------------------------------------------------------------------------
+CE_INLINE DWORD WINAPI OsThread::thread_proc(void* arg)
+{
+	OsThread* thread = (OsThread*)arg;
+
+	int32_t result = thread->run();
+	
+	return result;
+}
+
+} // namespace crown

+ 27 - 319
engine/os/win/OsWindow.cpp

@@ -24,159 +24,44 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #include "OsWindow.h"
 #include "OsWindow.h"
-#include "GLContext.h"
-#include "Assert.h"
-#include "Keyboard.h"
 #include "StringUtils.h"
 #include "StringUtils.h"
-#include "Log.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-//-----------------------------------------------------------------------------
-static Key translate_key(int32_t winKey)
-{
-	if ((winKey > 0x40 && winKey < 0x5B) || (winKey > 0x60 && winKey < 0x7B) || (winKey > 0x2F && winKey < 0x3A))
-	{
-		return (Key)winKey;
-	}
+HWND m_windows_window = 0;
 
 
-	switch (winKey)
-	{
-		case VK_BACK:		return KC_BACKSPACE;
-		case VK_TAB:		return KC_TAB;
-		case VK_SPACE:		return KC_SPACE;
-		case VK_ESCAPE:		return KC_ESCAPE;
-		case VK_RETURN:		return KC_ENTER;
-		case VK_F1:			return KC_F1;
-		case VK_F2:			return KC_F2;
-		case VK_F3:			return KC_F3;
-		case VK_F4:			return KC_F4;
-		case VK_F5:			return KC_F5;
-		case VK_F6:			return KC_F6;
-		case VK_F7:			return KC_F7;
-		case VK_F8:			return KC_F8;
-		case VK_F9:			return KC_F9;
-		case VK_F10:		return KC_F10;
-		case VK_F11:		return KC_F11;
-		case VK_F12:		return KC_F12;
-		case VK_HOME:		return KC_HOME;
-		case VK_LEFT:		return KC_LEFT;
-		case VK_UP:			return KC_UP;
-		case VK_RIGHT:		return KC_RIGHT;
-		case VK_DOWN:		return KC_DOWN;
-		case VK_PRIOR:		return KC_PAGE_UP;
-		case VK_NEXT:		return KC_PAGE_DOWN;
-		case VK_LSHIFT:		return KC_LSHIFT;
-		case VK_RSHIFT:		return KC_RSHIFT;
-		case VK_LCONTROL:	return KC_LCONTROL;
-		case VK_RCONTROL:	return KC_RCONTROL;
-		case VK_CAPITAL:	return KC_CAPS_LOCK;
-		case VK_LMENU:		return KC_LALT;
-		case VK_RMENU:		return KC_RALT;
-		case VK_LWIN:		return KC_LSUPER;
-		case VK_RWIN:		return KC_RSUPER;
-		case VK_NUMPAD0:	return KC_KP_0;
-		case VK_NUMPAD1:	return KC_KP_1;
-		case VK_NUMPAD2:	return KC_KP_2;
-		case VK_NUMPAD3:	return KC_KP_3;
-		case VK_NUMPAD4:	return KC_KP_4;
-		case VK_NUMPAD5:	return KC_KP_5;
-		case VK_NUMPAD6:	return KC_KP_6;
-		case VK_NUMPAD7:	return KC_KP_7;
-		case VK_NUMPAD8:	return KC_KP_8;
-		case VK_NUMPAD9:	return KC_KP_9;
-		default:			return KC_NOKEY;
-	}
+void oswindow_set_window(HWND handle_win)
+{
+	m_windows_window = handle_win;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-OsWindow::OsWindow(uint32_t width, uint32_t height, uint32_t /*window*/) :
-	m_window_handle(NULL),
-	m_x(0),
-	m_y(0),
-	m_fullscreen(false)
+OsWindow::OsWindow() 
+	: m_x(0)
+	, m_y(0)
+	, m_width(0)
+	, m_height(0)
+	, m_resizable(true)
 {
 {
-	CE_ASSERT(width != 0 || height != 0, "Width and height must differ from 0.");
-
-	string::strncpy(m_window_name, "CrownWindowClass", 32);
-	WNDCLASSEX wcex;
-	wcex.cbSize = sizeof(WNDCLASSEX);
-	wcex.style = CS_OWNDC;
-	wcex.lpfnWndProc = (WNDPROC) DefWindowProc;
-	wcex.cbClsExtra = 0;
-	wcex.cbWndExtra = 0;
-	wcex.hInstance = GetModuleHandle(NULL);
-    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
-	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
-	wcex.lpszMenuName = NULL;
-	wcex.lpszClassName = m_window_name;
-    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
-
-	uint32_t registered = RegisterClassEx(&wcex);
-	CE_ASSERT(registered != 0, "Unable to register a Window Class.");
-
-	m_window_handle = CreateWindowEx(0, m_window_name, "", WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
-	CE_ASSERT(m_window_handle != NULL, "Unable to create a Window.");
-	
-	//Save the WGLRenderWindow pointer to the window's user data
-	SetWindowLongPtr(m_window_handle, GWLP_USERDATA, (LONG) this);
-	RECT rc;
-	rc.left = 0;
-	rc.top = 0;
-	rc.right = width;
-	rc.bottom = height;
-
-	int32_t style, styleEx;
-	style = GetWindowLong(m_window_handle, GWL_STYLE);
-	styleEx = GetWindowLong(m_window_handle, GWL_EXSTYLE);
-	AdjustWindowRectEx(&rc, style, false, styleEx);
-
-	SetWindowPos(m_window_handle, 0, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
-
-	PIXELFORMATDESCRIPTOR pfd;
-	int32_t pixel_format;
-	/* get the device context (DC) */
-	HDC device_context = GetDC(m_window_handle);
-	/* set the pixel format for the DC */
-	ZeroMemory(&pfd, sizeof (pfd));
-	pfd.nSize = sizeof (pfd);
-	pfd.nVersion = 1;
-	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
-	pfd.iPixelType = PFD_TYPE_RGBA;
-	pfd.cColorBits = 24;
-	pfd.cDepthBits = 24;
-	pfd.iLayerType = PFD_MAIN_PLANE;
-
-	pixel_format = ChoosePixelFormat(device_context, &pfd);
-	CE_ASSERT(pixel_format != 0, "Pixel format not supported.");
-	
-	bool pf_set = SetPixelFormat(device_context, pixel_format, &pfd);
-	CE_ASSERT(pf_set, "Unable to set the pixel format, altough it seems to be supported.");
-
-	set_win_handle_window(m_window_handle);
+	set_title("");
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 OsWindow::~OsWindow()
 OsWindow::~OsWindow()
 {
 {
-	if (m_window_handle)
-	{
-		DestroyWindow(m_window_handle);
-	}
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void OsWindow::show()
 void OsWindow::show()
 {
 {
-	ShowWindow(m_window_handle, SW_SHOW);
+	ShowWindow(m_windows_window, SW_SHOW);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void OsWindow::hide()
 void OsWindow::hide()
 {
 {
-	ShowWindow(m_window_handle, SW_HIDE);
+	ShowWindow(m_windows_window, SW_HIDE);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -196,227 +81,50 @@ void OsWindow::get_position(uint32_t& x, uint32_t& y)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void OsWindow::resize(uint32_t width, uint32_t height)
 void OsWindow::resize(uint32_t width, uint32_t height)
 {
 {
-	SetWindowPos(m_window_handle, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
+	SetWindowPos(m_windows_window, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void OsWindow::move(uint32_t x, uint32_t y)
 void OsWindow::move(uint32_t x, uint32_t y)
 {
 {
-	SetWindowPos(m_window_handle, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);	
+	SetWindowPos(m_windows_window, NULL, x, y, 0, 0, SWP_NOMOVE | SWP_NOZORDER);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void OsWindow::show_cursor(bool show)
+void OsWindow::minimize()
 {
 {
-	ShowCursor(show);
+	ShowWindow(m_windows_window, SW_MINIMIZE);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void OsWindow::get_cursor_xy(int32_t& x, int32_t& y)
+void OsWindow::restore()
 {
 {
-	POINT p;
-
-	if (!GetCursorPos(&p))
-	{
-		CE_ASSERT(false, "Unable to get cursor coordinates\n");
-	}
-
-	x = p.x;
-	y = p.y;
+	ShowWindow(m_windows_window, SW_RESTORE);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void OsWindow::set_cursor_xy(int32_t x, int32_t y)
+bool OsWindow::is_resizable() const
 {
 {
-	SetCursorPos(x, y);
+	return m_resizable;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void OsWindow::set_fullscreen(bool fs)
-{
-	if (m_fullscreen)
-	{
-		memset(&m_screen_setting, 0, sizeof(m_screen_setting)); // Makes Sure Memory's Cleared
-		m_screen_setting.dmSize = sizeof(m_screen_setting); // Size Of The Devmode Structure
-		m_screen_setting.dmPelsWidth = m_width; // Selected Screen Width
-		m_screen_setting.dmPelsHeight = m_height; // Selected Screen Height
-		m_screen_setting.dmBitsPerPel = 32; // Selected Bits Per Pixel
-		m_screen_setting.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
-
-		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
-		if (ChangeDisplaySettings(&m_screen_setting, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
-		{
-			m_fullscreen = false;
-			Log::i("Fullscreen resolution not supported, switching to windowed mode.");
-		}
-		else
-		{
-			m_fullscreen = true;
-			m_window_handle = CreateWindowEx(0, m_window_name, "", WS_POPUP, 0, 0, m_width, m_height, NULL, NULL, GetModuleHandle(NULL), NULL);
-		}
-	}
-}
-
-bool OsWindow::fullscreen()
+void OsWindow::set_resizable(bool resizable)
 {
 {
-	return m_fullscreen;
+	m_resizable = resizable;
 }
 }
 
 
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 char* OsWindow::title()
 char* OsWindow::title()
 {
 {
-	return m_window_name;
+	return m_title;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void OsWindow::set_title(const char* title)
 void OsWindow::set_title(const char* title)
 {
 {
-	string::strncpy(m_window_name, title, 32);
-	SetWindowText(m_window_handle, m_window_name);
-}
-
-//-----------------------------------------------------------------------------
-void OsWindow::frame()
-{
-	MSG msg;
-
-	OsEventParameter data_button[4] = {0, 0, 0, 0};
-	OsEventParameter data_key[4] = {0, 0, 0, 0};
-
-	// Message are removed with PM_REMOVE
-	while (PeekMessage(&msg, m_window_handle, 0, 0, PM_REMOVE))
-	{
-		TranslateMessage(&msg);
-		DispatchMessage(&msg);
-
-		switch (msg.message)
-		{
-			// Mouse
-			case WM_LBUTTONDOWN:
-			case WM_LBUTTONUP:
-			{
-				OsEventType oset_type;
-
-				if (msg.message == WM_LBUTTONDOWN)
-				{
-					oset_type = OSET_BUTTON_PRESS;
-				}
-				if (msg.message == WM_LBUTTONUP)
-				{
-					oset_type = OSET_BUTTON_RELEASE;
-				}
-
-				data_button[0].int_value = LOWORD(msg.lParam);
-				data_button[1].int_value = HIWORD(msg.lParam);
-				data_button[2].int_value = 0;	// MIDDLE_BUTTON
-
-				push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
-
-				break;
-			}
-			case WM_RBUTTONDOWN:
-			case WM_RBUTTONUP:
-			{
-				OsEventType oset_type;
-
-				if (msg.message == WM_RBUTTONDOWN)
-				{
-					oset_type = OSET_BUTTON_PRESS;
-				}
-				if (msg.message == WM_RBUTTONUP)
-				{
-					oset_type = OSET_BUTTON_RELEASE;
-				}
-
-				data_button[0].int_value = LOWORD(msg.lParam);
-				data_button[1].int_value = HIWORD(msg.lParam);
-				data_button[2].int_value = 1;	// RIGHT BUTTON
-
-				push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
-
-				break;
-			}
-			case WM_MBUTTONDOWN:
-			case WM_MBUTTONUP:
-			{
-				OsEventType oset_type;
-
-				if (msg.message == WM_MBUTTONDOWN)
-				{
-					oset_type = OSET_BUTTON_PRESS;
-				}
-				if (msg.message == WM_MBUTTONUP)
-				{
-					oset_type = OSET_BUTTON_RELEASE;
-				}
-
-				data_button[0].int_value = LOWORD(msg.lParam);
-				data_button[1].int_value = HIWORD(msg.lParam);
-				data_button[2].int_value = 2;	// MIDDLE_BUTTON
-
-				push_event(oset_type, data_button[0], data_button[1], data_button[2], data_button[3]);
-
-				break;
-			}
-			case WM_MOUSEMOVE:
-			{
-				data_button[0].int_value = LOWORD(msg.lParam);
-				data_button[0].int_value = HIWORD(msg.lParam);
-				push_event(OSET_MOTION_NOTIFY, data_button[0], data_button[1], data_button[2], data_button[3]);
-				break;
-			}
-
-			// Keyboard
-			case WM_KEYDOWN:
-			case WM_KEYUP:
-			{
-				Key kc = translate_key(msg.wParam);
-
-				int32_t modifier_mask = 0;
-
-				// Check if any modifier key is pressed or released
-				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-				{
-					(msg.message == WM_KEYDOWN) ? modifier_mask |= MK_SHIFT : modifier_mask &= ~MK_SHIFT;
-				}
-				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-				{
-					(msg.message == WM_KEYDOWN) ? modifier_mask |= MK_CTRL : modifier_mask &= ~MK_CTRL;
-				}
-				else if (kc == KC_LALT || kc == KC_RALT)
-				{
-					(msg.message == WM_KEYDOWN) ? modifier_mask |= MK_ALT : modifier_mask &= ~MK_ALT;
-				}
-
-				OsEventType oset_type = msg.message == WM_KEYDOWN ? OSET_KEY_PRESS : OSET_KEY_RELEASE;
-
-				data_key[0].int_value = ((int32_t)kc);
-				data_key[1].int_value = modifier_mask;
-
-				push_event(oset_type, data_key[0], data_key[1], data_key[2], data_key[3]);
-
-				break;
-			}
-			case WM_CHAR:
-			{
-				// MUST BE IMPLEMENTED
-				break;
-			}
-
-			default:
-			{
-				break;
-			}
-
-			// Touch
-			// TODO
-
-			// Accelerometer
-			// TODO
-		}
-	}
-
+	string::strncpy(m_title, title, 32);
+	SetWindowText(m_windows_window, m_title);	
 }
 }
 
 
-} // namespace crown
+} // namespace crown

+ 11 - 15
engine/os/win/OsWindow.h

@@ -1,4 +1,5 @@
 /*
 /*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
 Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
 Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
 
 
 Permission is hereby granted, free of charge, to any person
 Permission is hereby granted, free of charge, to any person
@@ -32,11 +33,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
+CE_EXPORT void oswindow_set_window(HWND handle_win);
+
 class OsWindow
 class OsWindow
 {
 {
 public:
 public:
 
 
-					OsWindow(uint32_t width, uint32_t height, uint32_t window);
+					OsWindow();
 					~OsWindow();
 					~OsWindow();
 
 
 	void			show();
 	void			show();
@@ -48,31 +51,24 @@ public:
 	void			resize(uint32_t width, uint32_t height);
 	void			resize(uint32_t width, uint32_t height);
 	void			move(uint32_t x, uint32_t y);
 	void			move(uint32_t x, uint32_t y);
 
 
-	void			show_cursor(bool show);
-
-	void			get_cursor_xy(int32_t& x, int32_t& y);
-	void			set_cursor_xy(int32_t x, int32_t y);
+	void			minimize();
+	void			restore();
 
 
-	void			set_fullscreen(bool fs);
-	bool			fullscreen();
+	bool			is_resizable() const;
+	void			set_resizable(bool resizable);
 
 
 	char*			title();
 	char*			title();
 	void			set_title(const char* title);
 	void			set_title(const char* title);
 
 
-	void			frame();
-
 private:
 private:
 
 
-	HWND			m_window_handle;
-	DEVMODE			m_screen_setting;
-
-	char 			m_window_name[32];
+	char 			m_title[32];
 
 
 	uint32_t		m_x;
 	uint32_t		m_x;
 	uint32_t		m_y;
 	uint32_t		m_y;
 	uint32_t		m_width;
 	uint32_t		m_width;
 	uint32_t		m_height;
 	uint32_t		m_height;
-	bool			m_fullscreen;
+	bool			m_resizable;
 };
 };
 
 
-} // namespace crown
+} // namespace crown

+ 33 - 12
engine/os/win/Mutex.cpp → engine/os/win/Semaphore.h

@@ -24,34 +24,55 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
-#include "Mutex.h"
+#pragma once
+
+#include <windows.h>
+#include <limits.h>
+
 #include "Assert.h"
 #include "Assert.h"
 
 
-namespace crown
+class Semaphore
 {
 {
+public:
+
+	Semaphore();
+	~Semaphore();
+
+	void post(uint32_t count = 1) const;
+	void wait(int32_t msecs = -1) const;
+
+private:
+
+	Semaphore(const Semaphore& s); // no copy constructor
+	Semaphore& operator=(const Semaphore& s); // no assignment operator
+
+	HANDLE m_handle;
+};
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-Mutex::Mutex()
+inline Semaphore::Semaphore()
 {
 {
-	InitializeCriticalSection(&m_cs);
+	m_handle = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
+	CE_ASSERT(m_handle != NULL, "Unable to create semaphore!");
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-Mutex::~Mutex()
+inline Semaphore::~Semaphore()
 {
 {
-	DeleteCriticalSection(&m_cs);
+	CloseHandle(m_handle);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void Mutex::lock()
+inline void Semaphore::post(uint32_t count) const
 {
 {
-    EnterCriticalSection(&m_cs); 
+	ReleaseSemaphore(m_handle, count, NULL);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void Mutex::unlock()
+inline void Semaphore::wait(int32_t msecs) const
 {
 {
-    LeaveCriticalSection(&m_cs);
-}
+	DWORD milliseconds = (0 > msecs) ? INFINITE : msecs;
+	DWORD result = WaitForSingleObject(m_handle, milliseconds);
 
 
-} // namespace crown
+	CE_ASSERT(result == WAIT_OBJECT_0, "Semaphore can not signal!");
+}

+ 0 - 112
engine/os/win/Thread.cpp

@@ -1,112 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Thread.h"
-#include "Assert.h"
-#include "StringUtils.h"
-
-namespace crown
-{
-namespace os
-{
-
-//-----------------------------------------------------------------------------
-Thread::Thread(const char* name) :
-	m_name(name),
-	m_is_running(false),
-	m_is_terminating(false)
-{
-}
-
-//-----------------------------------------------------------------------------
-Thread::~Thread()
-{
-}
-
-//-----------------------------------------------------------------------------
-bool Thread::is_running() const
-{
-	return m_is_running;
-}
-
-//-----------------------------------------------------------------------------
-bool Thread::is_terminating() const
-{
-	return m_is_terminating;
-}
-
-//-----------------------------------------------------------------------------
-void Thread::start()
-{
-	m_is_terminating = false;
-
-	m_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Thread::background_proc, this, 0, NULL);
-
-	CE_ASSERT(m_thread != NULL, "Failed to create the thread '%s'", m_name);
-
-	m_is_running = true;
-}
-
-//-----------------------------------------------------------------------------
-void Thread::stop()
-{
-	m_is_terminating = true;
-}
-
-//-----------------------------------------------------------------------------
-int32_t	Thread::run()
-{
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-void Thread::join()
-{
-	WaitForSingleObject(m_thread, INFINITE);
-}
-
-//-----------------------------------------------------------------------------
-void Thread::detach()
-{
-	BOOL closed = CloseHandle(m_thread);
-
-	CE_ASSERT(closed, "Unable to close thread");
-}
-
-void* Thread::background_proc(void* thiz)
-{
-	Thread* thread  = (Thread*)thiz;
-
-	thread->run();
-
-	thread->m_is_running = false;
-
-	return NULL;
-}
-
-
-} // namespace os
-} // namespace crown

+ 0 - 76
engine/os/win/Thread.h

@@ -1,76 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <windows.h>
-#include <process.h>
-#include <WinBase.h>
-
-#include "Types.h"
-#include "OS.h"
-
-namespace crown
-{
-namespace os
-{
-
-typedef void* (*ThreadFunction)(void*);
-
-class Thread
-{
-public:
-
-					Thread(const char* name);
-					~Thread();
-
-	const char*		name() const;
-
-	void			join();
-	void			detach();
-
-	bool			is_running() const;
-	bool			is_terminating() const;
-
-	void			start();
-	void			stop();
-
-	virtual int32_t	run();
-
-private:
-
-	static void*	background_proc(void* thiz);
-
-private:
-	
-	const char*		m_name;
-	bool			m_is_running;
-	bool			m_is_terminating;
-	HANDLE			m_thread;
-};
-
-} // namespace os
-} // namespace crown

+ 4 - 5
engine/os/win/WinOS.cpp

@@ -24,21 +24,20 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
-#include "OS.h"
 #include <windows.h>
 #include <windows.h>
 #include <cstdio>
 #include <cstdio>
 #include <cstdarg>
 #include <cstdarg>
 #include "StringUtils.h"
 #include "StringUtils.h"
 
 
+#include "OS.h"
+
 namespace crown
 namespace crown
 {
 {
 namespace os
 namespace os
 {
 {
 
 
-// FIXME: timespec does not exists in win
-// static timespec base_time;
-	LARGE_INTEGER frequency;
-	LARGE_INTEGER base_time;
+LARGE_INTEGER frequency;
+LARGE_INTEGER base_time;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void printf(const char* string, ...)
 void printf(const char* string, ...)

+ 819 - 10
engine/os/win/main.cpp

@@ -24,26 +24,835 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
+#include <windowsx.h>
+
+#define WM_USER_SET_WINDOW_SIZE     (WM_USER+0)
+#define WM_USER_TOGGLE_WINDOW_FRAME (WM_USER+1)
+#define WM_USER_MOUSE_LOCK          (WM_USER+2)
+
 #include "Crown.h"
 #include "Crown.h"
+#include "OsTypes.h"
+#include "OsEventQueue.h"
+#include "GLContext.h"
+#include "BundleCompiler.h"
 
 
-int main(int argc, char** argv)
+#include "OS.h"
+
+#define ENTRY_DEFAULT_WIDTH 1024
+#define ENTRY_DEFAULT_HEIGHT 768
+
+namespace crown
+{
+
+extern void set_win_handle_window(HWND hwnd);
+
+//-----------------------------------------------------------------------------
+void init()
+{
+	memory::init();
+	os::init_os();
+}
+
+//-----------------------------------------------------------------------------
+void shutdown()
+{
+	memory::shutdown();
+}
+
+//-----------------------------------------------------------------------------
+static KeyboardButton::Enum win_translate_key(int32_t winKey)
+{
+	if ((winKey > 0x40 && winKey < 0x5B) || (winKey > 0x60 && winKey < 0x7B) || (winKey > 0x2F && winKey < 0x3A))
+	{
+		return (KeyboardButton::Enum)winKey;
+	}
+
+	switch (winKey)
+	{
+		case VK_BACK:		return KeyboardButton::BACKSPACE;
+		case VK_TAB:		return KeyboardButton::TAB;
+		case VK_SPACE:		return KeyboardButton::SPACE;
+		case VK_ESCAPE:		return KeyboardButton::ESCAPE;
+		case VK_RETURN:		return KeyboardButton::ENTER;
+		case VK_F1:			return KeyboardButton::F1;
+		case VK_F2:			return KeyboardButton::F2;
+		case VK_F3:			return KeyboardButton::F3;
+		case VK_F4:			return KeyboardButton::F4;
+		case VK_F5:			return KeyboardButton::F5;
+		case VK_F6:			return KeyboardButton::F6;
+		case VK_F7:			return KeyboardButton::F7;
+		case VK_F8:			return KeyboardButton::F8;
+		case VK_F9:			return KeyboardButton::F9;
+		case VK_F10:		return KeyboardButton::F10;
+		case VK_F11:		return KeyboardButton::F11;
+		case VK_F12:		return KeyboardButton::F12;
+		case VK_HOME:		return KeyboardButton::HOME;
+		case VK_LEFT:		return KeyboardButton::LEFT;
+		case VK_UP:			return KeyboardButton::UP;
+		case VK_RIGHT:		return KeyboardButton::RIGHT;
+		case VK_DOWN:		return KeyboardButton::DOWN;
+		case VK_PRIOR:		return KeyboardButton::PAGE_UP;
+		case VK_NEXT:		return KeyboardButton::PAGE_DOWN;
+		case VK_LSHIFT:		return KeyboardButton::LSHIFT;
+		case VK_RSHIFT:		return KeyboardButton::RSHIFT;
+		case VK_LCONTROL:	return KeyboardButton::LCONTROL;
+		case VK_RCONTROL:	return KeyboardButton::RCONTROL;
+		case VK_CAPITAL:	return KeyboardButton::CAPS_LOCK;
+		case VK_LMENU:		return KeyboardButton::LALT;
+		case VK_RMENU:		return KeyboardButton::RALT;
+		case VK_LWIN:		return KeyboardButton::LSUPER;
+		case VK_RWIN:		return KeyboardButton::RSUPER;
+		case VK_NUMPAD0:	return KeyboardButton::KP_0;
+		case VK_NUMPAD1:	return KeyboardButton::KP_1;
+		case VK_NUMPAD2:	return KeyboardButton::KP_2;
+		case VK_NUMPAD3:	return KeyboardButton::KP_3;
+		case VK_NUMPAD4:	return KeyboardButton::KP_4;
+		case VK_NUMPAD5:	return KeyboardButton::KP_5;
+		case VK_NUMPAD6:	return KeyboardButton::KP_6;
+		case VK_NUMPAD7:	return KeyboardButton::KP_7;
+		case VK_NUMPAD8:	return KeyboardButton::KP_8;
+		case VK_NUMPAD9:	return KeyboardButton::KP_9;
+		default:			return KeyboardButton::NONE;
+	}
+}
+
+//-----------------------------------------------------------------------------
+class CE_EXPORT WindowsDevice : public Device
 {
 {
-	crown::os::init_os();
+public:
+
+	WindowsDevice() 
+		: m_hwnd(0)
+		, m_rect()
+		, m_style(0)
+		, m_width(0)
+		, m_height(0)
+		, m_old_width(0)
+		, m_old_height(0)
+		, m_frame_width(0)
+		, m_frame_height(0)
+		, m_aspect_ratio(0.0f)
+		, m_x(0)
+		, m_y(0)
+		, m_frame(true)
+		, m_mouse_lock(false)
+		, m_started(false)
+		, m_exit(false)
+	{
+
+	}
+
+	//-----------------------------------------------------------------------------
+	void init(int argc, char** argv)
+	{
+		parse_command_line(argc, argv);
+		check_preferred_settings();
+
+		#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
+			if (m_compile == 1)
+			{
+				m_bundle_compiler = CE_NEW(default_allocator(), BundleCompiler);
+				if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir))
+				{
+					CE_DELETE(default_allocator(), m_bundle_compiler);
+					Log::e("Exiting.");
+					exit(EXIT_FAILURE);
+				}
+
+				if (!m_continue)
+				{
+					CE_DELETE(default_allocator(), m_bundle_compiler);
+					exit(EXIT_SUCCESS);
+				}
+			}
+		#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	void shutdown()
+	{
+		#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
+			CE_DELETE(default_allocator(), m_bundle_compiler);
+		#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	int32_t	run(int argc, char** argv)
+	{
+		init(argc, argv);
+
+		HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL);
+
+		WNDCLASSEX wnd;
+		memset(&wnd, 0, sizeof(wnd));
+		wnd.cbSize = sizeof(wnd);
+		wnd.lpfnWndProc = DefWindowProc;
+		wnd.hInstance = instance;
+		wnd.hIcon = LoadIcon(instance, IDI_APPLICATION);
+		wnd.hCursor = LoadCursor(instance, IDC_ARROW);
+		wnd.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+		wnd.lpszClassName = "crown_letterbox";
+		wnd.hIconSm = LoadIcon(instance, IDI_APPLICATION);
+		RegisterClassExA(&wnd);
+
+		memset(&wnd, 0, sizeof(wnd));
+		wnd.cbSize = sizeof(wnd);
+		wnd.style = CS_HREDRAW | CS_VREDRAW;
+		wnd.lpfnWndProc = window_proc;
+		wnd.hInstance = instance;
+		wnd.hIcon = LoadIcon(instance, IDI_APPLICATION);
+		wnd.hCursor = LoadCursor(instance, IDC_ARROW);
+		wnd.lpszClassName = "crown";
+		wnd.hIconSm = LoadIcon(instance, IDI_APPLICATION);
+		RegisterClassExA(&wnd);
 
 
-	crown::Device* engine = crown::device();
+		HWND hwnd = CreateWindowA(
+						"crown_letterbox", 
+						"CrownUnknown",
+						WS_POPUP|WS_SYSMENU,
+						-32000,
+						-32000,
+						0,
+						0,
+						NULL,
+						NULL,
+						instance,
+						0
+					);
 
 
-	if (!engine->init(argc, argv))
+		m_hwnd = CreateWindowA(
+					"crown",
+					"Crown",
+					WS_OVERLAPPEDWINDOW|WS_VISIBLE,
+					0,
+					0,
+					ENTRY_DEFAULT_WIDTH,
+					ENTRY_DEFAULT_HEIGHT,
+					0,
+					NULL,
+					instance,
+					0
+				);
+
+		oswindow_set_window(m_hwnd);
+		glcontext_set_window(m_hwnd);
+
+		adjust(ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, true);
+		m_width = ENTRY_DEFAULT_WIDTH;
+		m_height = ENTRY_DEFAULT_HEIGHT;
+		m_old_width = ENTRY_DEFAULT_WIDTH;
+		m_old_height = ENTRY_DEFAULT_HEIGHT;
+
+		m_argc = argc;
+		m_argv = argv;
+
+		OsThread thread("game-loop");
+		thread.start(WindowsDevice::main_loop, this);
+		m_started = true;
+
+		MSG msg;
+		msg.message = WM_NULL;
+
+		while (!m_exit)
+		{
+			WaitMessage();
+
+			while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0)
+			{
+				TranslateMessage(&msg);
+				DispatchMessage(&msg);
+			}
+		}
+
+		thread.stop();
+
+		shutdown();
+
+		DestroyWindow(m_hwnd);
+		DestroyWindow(hwnd);
+
+		return 0;
+	}
+
+	//-----------------------------------------------------------------------------
+	int32_t loop()
+	{
+		Device::init();
+
+		while(!process_events() && is_running())
+		{
+			Device::frame();
+
+			m_keyboard->update();
+			m_mouse->update();
+		}
+
+		Device::shutdown();
+
+		m_exit = true;
+
+		return 0;
+	}
+
+	//-----------------------------------------------------------------------------
+	void adjust(uint32_t width, uint32_t height, bool window_frame)
 	{
 	{
-		exit(-1);
+		m_width = width;
+		m_height = height;
+		m_aspect_ratio = float(width) / float(height);
+
+		ShowWindow(m_hwnd, SW_SHOWNORMAL);
+		RECT rect;
+		RECT newrect = {0, 0, (LONG)width, (LONG)height};
+		DWORD style = WS_POPUP|WS_SYSMENU;
+
+		if (m_frame)
+		{
+			GetWindowRect(m_hwnd, &m_rect);
+			m_style = GetWindowLong(m_hwnd, GWL_STYLE);
+		}
+
+		if (window_frame)
+		{
+			rect = m_rect;
+			style = m_style;
+		}
+		else
+		{
+			HMONITOR monitor = MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTONEAREST);
+			MONITORINFO mi;
+			mi.cbSize = sizeof(mi);
+			GetMonitorInfo(monitor, &mi);
+			newrect = mi.rcMonitor;
+			rect = mi.rcMonitor;
+		}
+
+		SetWindowLong(m_hwnd, GWL_STYLE, style);
+		uint32_t prewidth = newrect.right - newrect.left;
+		uint32_t preheight = newrect.bottom - newrect.top;
+		AdjustWindowRect(&newrect, style, FALSE);
+		m_frame_width = (newrect.right - newrect.left) - prewidth;
+		m_frame_height = (newrect.bottom - newrect.top) - preheight;
+		UpdateWindow(m_hwnd);
+
+		if (rect.left < 0 || rect.top < 0)
+		{
+			rect.left = 0;
+			rect.top = 0;
+		}
+
+		int32_t left_t = rect.left;
+		int32_t top_t = rect.top;
+		int32_t width_t = (newrect.right-newrect.left);
+		int32_t height_t = (newrect.bottom-newrect.top);
+
+		if (!window_frame)
+		{
+			float aspect_ratio = 1.0f / m_aspect_ratio;
+			width_t = math::max(uint32_t(ENTRY_DEFAULT_WIDTH / 4), width);
+			height_t = uint32_t(float(width) * aspect_ratio);
+
+			left_t = newrect.left+(newrect.right-newrect.left-width) / 2;
+			top_t = newrect.top+(newrect.bottom-newrect.top-height) / 2;
+		}
+
+		HWND parent = GetWindow(m_hwnd, GW_OWNER);
+		if (NULL != parent)
+		{
+			if (window_frame)
+			{
+				SetWindowPos(parent, HWND_TOP, -32000, -32000, 0, 0, SWP_SHOWWINDOW);
+			}
+			else
+			{
+				SetWindowPos(parent, HWND_TOP, newrect.left, newrect.top, newrect.right-newrect.left, newrect.bottom-newrect.top, SWP_SHOWWINDOW);
+			}
+		}
+
+		SetWindowPos(m_hwnd, HWND_TOP, left_t, top_t, width_t, height_t, SWP_SHOWWINDOW);
+
+		ShowWindow(m_hwnd, SW_RESTORE);
+
+		m_frame = window_frame;
 	}
 	}
 
 
-	// Main loop
-	while (engine->is_running())
+	//-----------------------------------------------------------------------------
+	void set_mouse_pos(int32_t x, int32_t y)
 	{
 	{
-		engine->frame();
+		POINT pt = {x, y};
+		ClientToScreen(m_hwnd, &pt);
+		SetCursorPos(pt.x, pt.y);
 	}
 	}
 
 
-	engine->shutdown();
+	//-----------------------------------------------------------------------------
+	void set_mouse_lock(bool lock)
+	{
+		if (lock != m_mouse_lock)
+		{
+			if (lock)
+			{
+				m_x = m_width / 2;
+				m_y = m_height / 2;
+				ShowCursor(false);
+				set_mouse_pos(m_x, m_y);
+			}
+			else
+			{
+				set_mouse_pos(m_x, m_y);
+				ShowCursor(true);
+			}
+
+			m_mouse_lock = lock;
+		}
+	}
+	
+	//-----------------------------------------------------------------------------
+	static int32_t main_loop(void* data)
+	{
+		return ((WindowsDevice*)data)->loop();
+	}
+
+	//-----------------------------------------------------------------------------
+	bool process_events()
+	{
+		OsEvent event;
+		do
+		{
+			m_queue.pop_event(&event);
+
+			if (event.type != OsEvent::NONE)
+			{
+				switch (event.type)
+				{
+					case OsEvent::MOUSE:
+					{
+						const OsMouseEvent& ev = event.mouse;
+						switch (ev.type)
+						{
+							case OsMouseEvent::BUTTON: m_mouse->set_button_state(ev.x, ev.y, ev.button, ev.pressed); break;
+							case OsMouseEvent::MOVE: m_mouse->set_position(ev.x, ev.y); break;
+							default: CE_FATAL("Oops, unknown mouse event type"); break;
+						}
+
+						break;
+					}
+					case OsEvent::KEYBOARD:
+					{
+						const OsKeyboardEvent& ev = event.keyboard;
+						m_keyboard->set_button_state(ev.button, ev.pressed);
+						break;
+					}
+					case OsEvent::METRICS:
+					{
+						const OsMetricsEvent& ev = event.metrics;
+						m_mouse->set_metrics(ev.width, ev.height);
+						break;
+					}
+					case OsEvent::EXIT:
+					{
+						return true;
+					}
+					default:
+					{
+						Log::d("Unmanaged");
+						break;
+					}
+				}
+			}
+		}
+		while (event.type != OsEvent::NONE);
+
+		return false;
+	}
+
+	//-----------------------------------------------------------------------------
+	LRESULT bump_events(HWND hwnd, UINT id, WPARAM wparam, LPARAM lparam)
+	{		
+		if (m_started)
+		{
+			switch (id)
+			{
+			case WM_USER_SET_WINDOW_SIZE:
+			{
+				uint32_t width = GET_X_LPARAM(lparam);
+				uint32_t height = GET_Y_LPARAM(lparam);
+				adjust(width, height, true);
+
+				m_queue.push_metrics_event(m_x, m_y, m_width, m_height);
+
+				break;
+			}
+			case WM_USER_TOGGLE_WINDOW_FRAME:
+			{
+				if (m_frame)
+				{
+					m_old_width = m_width;
+					m_old_height = m_height;
+				}
+				adjust(m_old_width, m_old_height, !m_frame);
+
+				m_queue.push_metrics_event(m_x, m_y, m_width, m_height);
+
+				break;
+			}
+			case WM_USER_MOUSE_LOCK:
+			{
+				set_mouse_lock(!!lparam);
+				break;
+			}
+			case WM_DESTROY:
+			{
+				break;
+			}
+			case WM_QUIT:
+			case WM_CLOSE:
+			{
+				m_exit = true;
+
+				OsExitEvent event;
+				event.code = 0;
+				m_queue.push_exit_event(0);
+
+				break;
+			}
+			case WM_SIZING:
+			{
+				RECT& rect = *(RECT*)lparam;
+				uint32_t width = rect.right - rect.left - m_frame_width;
+				uint32_t height = rect.bottom - rect.top - m_frame_height;
+
+				//Recalculate size according to aspect ratio
+				switch (wparam)
+				{
+				case WMSZ_LEFT:
+				case WMSZ_RIGHT:
+					{
+						float aspect_ratio = 1.0f / m_aspect_ratio;
+						width = math::max((uint32_t)ENTRY_DEFAULT_WIDTH / 4, width);
+						height = uint32_t(float(width)*aspect_ratio);
+					}
+					break;
+
+				default:
+					{
+						float aspect_ratio = m_aspect_ratio;
+						height = math::max((uint32_t)ENTRY_DEFAULT_HEIGHT / 4, height);
+						width = uint32_t(float(height)*aspect_ratio);
+					}
+					break;
+				}
+
+				//Recalculate position using different anchor points
+				switch(wparam)
+				{
+				case WMSZ_LEFT:
+				case WMSZ_TOPLEFT:
+				case WMSZ_BOTTOMLEFT:
+					rect.left = rect.right - width - m_frame_width;
+					rect.bottom = rect.top + height + m_frame_height;
+					break;
+
+				default:
+					rect.right = rect.left + width + m_frame_width;
+					rect.bottom = rect.top + height + m_frame_height;
+					break;
+				}
+
+				return 0;
+			}
+			case WM_SIZE:
+			{
+				uint32_t width = GET_X_LPARAM(lparam);
+				uint32_t height = GET_Y_LPARAM(lparam);
+
+				m_width = width;
+				m_height = height;
+
+				m_queue.push_metrics_event(m_x, m_y, m_width, m_height);
+
+				break;
+			}
+			case WM_SYSCOMMAND:
+			{
+				switch (wparam)
+				{
+					case SC_MINIMIZE:
+					case SC_RESTORE:
+					{
+						HWND parent = GetWindow(hwnd, GW_OWNER);
+						if (NULL != parent)
+						{
+							PostMessage(parent, id, wparam, lparam);
+						}
+					}
+				}
+				break;
+			}
+			case WM_MOUSEMOVE:
+			{
+				int32_t mx = GET_X_LPARAM(lparam);
+				int32_t my = GET_Y_LPARAM(lparam);
+
+				if (m_mouse_lock)
+				{
+					mx -= m_x;
+					my -= m_y;
+
+					if (mx == 0	&& my == 0)
+					{
+						break;
+					}
+
+					set_mouse_pos(m_x, m_y);
+				}
+				
+				m_queue.push_mouse_event(m_x, m_y);
+
+				break;
+			}
+			case WM_LBUTTONDOWN:
+			case WM_LBUTTONUP:
+			{
+				int32_t mx = GET_X_LPARAM(lparam);
+				int32_t my = GET_Y_LPARAM(lparam);
+				
+				m_queue.push_mouse_event(mx, my, MouseButton::LEFT, id == WM_LBUTTONDOWN);
+
+				break;
+			}
+			case WM_RBUTTONUP:
+			case WM_RBUTTONDOWN:
+			{
+				int32_t mx = GET_X_LPARAM(lparam);
+				int32_t my = GET_Y_LPARAM(lparam);
+
+				m_queue.push_mouse_event(mx, my, MouseButton::RIGHT, id == WM_RBUTTONDOWN);
+
+				break;
+			}
+			case WM_MBUTTONDOWN:
+			case WM_MBUTTONUP:
+			{
+				int32_t mx = GET_X_LPARAM(lparam);
+				int32_t my = GET_Y_LPARAM(lparam);
+
+				m_queue.push_mouse_event(mx, my, MouseButton::MIDDLE, id == WM_MBUTTONDOWN);
+
+				break;
+			}
+			case WM_KEYDOWN:
+			case WM_SYSKEYDOWN:
+			case WM_KEYUP:
+			case WM_SYSKEYUP:
+			{
+				KeyboardButton::Enum kb = win_translate_key(wparam);
+
+				int32_t modifier_mask = 0;
+
+				if (kb == KeyboardButton::LSHIFT || kb == KeyboardButton::RSHIFT)
+				{
+					(id == WM_KEYDOWN || id == WM_SYSKEYDOWN) ? modifier_mask |= ModifierButton::SHIFT : modifier_mask &= ~ModifierButton::SHIFT;
+				}
+				else if (kb == KeyboardButton::LCONTROL || kb == KeyboardButton::RCONTROL)
+				{
+					(id == WM_KEYDOWN || id == WM_SYSKEYDOWN) ? modifier_mask |= ModifierButton::CTRL : modifier_mask &= ~ModifierButton::CTRL;
+				}
+				else if (kb == KeyboardButton::LALT || kb == KeyboardButton::RALT)
+				{
+					(id == WM_KEYDOWN || id == WM_SYSKEYDOWN) ? modifier_mask |= ModifierButton::ALT : modifier_mask &= ~ModifierButton::ALT;
+				}
+
+				m_queue.push_keyboard_event(modifier_mask, kb, id == WM_KEYDOWN || id == WM_SYSKEYDOWN);
+		
+				break;
+			}
+			default:
+				break;
+			}
+		}
+
+		return DefWindowProc(hwnd, id, wparam, lparam);
+	}
+
+	//-----------------------------------------------------------------------------
+	void parse_command_line(int argc, char** argv)
+	{
+		static const char* help_message =
+			"Usage: crown [options]\n"
+			"Options:\n\n"
+
+			"All of the following options take precedence over\n"
+			"environment variables and configuration files.\n\n"
+
+			"  --help                     Show this help.\n"
+			"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
+			"  --width <width>            Set the <width> of the main window.\n"
+			"  --height <width>           Set the <height> of the main window.\n"
+			"  --fullscreen               Start in fullscreen.\n"
+			"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
+			"                             Used only by tools.\n"
+
+			"\nAvailable only in debug and development builds:\n\n"
+
+			"  --source-dir <path>        Use <path> as the source directory for resource compilation.\n"
+			"  --compile                  Run the engine as resource compiler.\n"
+			"  --continue                 Do a full compile of the resources and continue the execution.\n";
+
+		static ArgsOption options[] = 
+		{
+			{ "help",             AOA_NO_ARGUMENT,       NULL,        'i' },
+			{ "source-dir",       AOA_REQUIRED_ARGUMENT, NULL,        's' },
+			{ "bundle-dir",       AOA_REQUIRED_ARGUMENT, NULL,        'b' },
+			{ "compile",          AOA_NO_ARGUMENT,       &m_compile,   1 },
+			{ "continue",         AOA_NO_ARGUMENT,       &m_continue,  1 },
+			{ "width",            AOA_REQUIRED_ARGUMENT, NULL,        'w' },
+			{ "height",           AOA_REQUIRED_ARGUMENT, NULL,        'h' },
+			{ "fullscreen",       AOA_NO_ARGUMENT,       &m_fullscreen, 1 },
+			{ "parent-window",    AOA_REQUIRED_ARGUMENT, NULL,        'p' },
+			{ NULL, 0, NULL, 0 }
+		};
+
+		Args args(argc, argv, "", options);
+
+		int32_t opt;
+		while ((opt = args.getopt()) != -1)
+		{
+			switch (opt)
+			{
+				case 0:
+				{
+					break;
+				}
+				// Source directory
+				case 's':
+				{
+					string::strncpy(m_source_dir, args.optarg(), MAX_PATH_LENGTH);
+					break;
+				}
+				// Bundle directory
+				case 'b':
+				{
+					string::strncpy(m_bundle_dir, args.optarg(), MAX_PATH_LENGTH);
+					break;
+				}
+				// Window width
+				case 'w':
+				{
+					m_width = atoi(args.optarg());
+					break;
+				}
+				// Window height
+				case 'h':
+				{
+					m_height = atoi(args.optarg());
+					break;
+				}
+				// Parent window
+				case 'p':
+				{
+					m_parent_window_handle = string::parse_uint(args.optarg());
+					break;
+				}
+				case 'i':
+				case '?':
+				default:
+				{
+					os::printf(help_message);
+					exit(EXIT_FAILURE);
+				}
+			}
+		}
+	}
+
+	//-----------------------------------------------------------------------------
+	void check_preferred_settings()
+	{
+		if (m_compile == 1)
+		{
+			if (string::strcmp(m_source_dir, "") == 0)
+			{
+				Log::e("You have to specify the source directory when running in compile mode.");
+				exit(EXIT_FAILURE);
+			}
+
+			if (!os::is_absolute_path(m_source_dir))
+			{
+				Log::e("The source directory must be absolute.");
+				exit(EXIT_FAILURE);
+			}
+		}
+
+		if (!os::is_absolute_path(m_bundle_dir))
+		{
+			Log::e("The bundle directory must be absolute.");
+			exit(EXIT_FAILURE);
+		}
+
+		// if (m_width == 0 || m_height == 0)
+		// {
+		// 	Log::e("Window width and height must be greater than zero.");
+		// 	exit(EXIT_FAILURE);
+		// }
+	}
+
+private:
+
+	static LRESULT CALLBACK window_proc(HWND hwnd, UINT id, WPARAM wparam, LPARAM lparam);
+
+public:
+
+	HWND m_hwnd;
+	HDC m_hdc;
+	RECT m_rect;
+	DWORD m_style;
+	uint32_t m_width;
+	uint32_t m_height;
+	uint32_t m_old_width;
+	uint32_t m_old_height;
+	uint32_t m_frame_width;
+	uint32_t m_frame_height;
+	float m_aspect_ratio;
+	int32_t m_x;
+	int32_t m_y;
+	bool m_frame;
+	bool m_mouse_lock;
+	bool m_started;
+	bool m_exit;
+
+	int32_t m_argc;
+	char**	m_argv;
+
+	uint32_t m_parent_window_handle;
+	int32_t m_fullscreen;
+	int32_t m_compile;
+	int32_t m_continue;	
+
+	OsEventQueue m_queue;
+};
+
+WindowsDevice* engine;
+
+LRESULT CALLBACK WindowsDevice::window_proc(HWND hwnd, UINT id, WPARAM wparam, LPARAM lparam)
+{
+	return ((WindowsDevice*)engine)->bump_events(hwnd, id, wparam, lparam);
+}
+
+} // namespace crown
+
+
+int main(int argc, char** argv)
+{
+	using namespace crown;
+	init();
+
+	engine = CE_NEW(default_allocator(), WindowsDevice)();
+	set_device(engine);
+	
+	int32_t ret = ((WindowsDevice*)engine)->run(argc, argv);
+
+	CE_DELETE(default_allocator(), engine);
+
+	shutdown();
 
 
-	return 0;
+	return ret;
 }
 }

+ 12 - 12
engine/renderers/DebugRenderer.cpp

@@ -71,11 +71,11 @@ void DebugRenderer::add_sphere(const Vec3& center, const float radius, const Col
 	// XZ plane
 	// XZ plane
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	{
 	{
-		float rad0 = math::deg_to_rad(deg);
-		float rad1 = math::deg_to_rad(deg + deg_step);
+		float rad_0 = math::deg_to_rad(deg);
+		float rad_1 = math::deg_to_rad(deg + deg_step);
 
 
-		Vec3 start(math::cos(rad0) * radius, 0, -math::sin(rad0) * radius);
-		Vec3 end  (math::cos(rad1) * radius, 0, -math::sin(rad1) * radius);
+		Vec3 start(math::cos(rad_0) * radius, 0, -math::sin(rad_0) * radius);
+		Vec3 end  (math::cos(rad_1) * radius, 0, -math::sin(rad_1) * radius);
 
 
 		add_line(center + start, center + end, color, depth_write);
 		add_line(center + start, center + end, color, depth_write);
 	}
 	}
@@ -83,11 +83,11 @@ void DebugRenderer::add_sphere(const Vec3& center, const float radius, const Col
 	// XY plane
 	// XY plane
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	{
 	{
-		float rad0 = math::deg_to_rad(deg);
-		float rad1 = math::deg_to_rad(deg + deg_step);
+		float rad_0 = math::deg_to_rad(deg);
+		float rad_1 = math::deg_to_rad(deg + deg_step);
 
 
-		Vec3 start(math::cos(rad0) * radius, math::sin(rad0) * radius, 0);
-		Vec3 end  (math::cos(rad1) * radius, math::sin(rad1) * radius, 0);
+		Vec3 start(math::cos(rad_0) * radius, math::sin(rad_0) * radius, 0);
+		Vec3 end  (math::cos(rad_1) * radius, math::sin(rad_1) * radius, 0);
 
 
 		add_line(center + start, center + end, color, depth_write);
 		add_line(center + start, center + end, color, depth_write);
 	}
 	}
@@ -95,11 +95,11 @@ void DebugRenderer::add_sphere(const Vec3& center, const float radius, const Col
 	// YZ plane
 	// YZ plane
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	for (uint32_t deg = 0; deg < 360; deg += deg_step)
 	{
 	{
-		float rad0 = math::deg_to_rad(deg);
-		float rad1 = math::deg_to_rad(deg + deg_step);
+		float rad_0 = math::deg_to_rad(deg);
+		float rad_1 = math::deg_to_rad(deg + deg_step);
 
 
-		Vec3 start(0, math::sin(rad0) * radius, -math::cos(rad0) * radius);
-		Vec3 end  (0, math::sin(rad1) * radius, -math::cos(rad1) * radius);
+		Vec3 start(0, math::sin(rad_0) * radius, -math::cos(rad_0) * radius);
+		Vec3 end  (0, math::sin(rad_1) * radius, -math::cos(rad_1) * radius);
 
 
 		add_line(center + start, center + end, color, depth_write);
 		add_line(center + start, center + end, color, depth_write);
 	}
 	}

+ 5 - 5
engine/renderers/Renderer.h

@@ -32,7 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "VertexFormat.h"
 #include "VertexFormat.h"
 #include "StringUtils.h"
 #include "StringUtils.h"
 #include "RenderContext.h"
 #include "RenderContext.h"
-#include "Thread.h"
+#include "OsThread.h"
 #include "OS.h"
 #include "OS.h"
 
 
 namespace crown
 namespace crown
@@ -95,7 +95,6 @@ public:
 			m_submit->m_commands.write(COMMAND_SHUTDOWN_RENDERER);
 			m_submit->m_commands.write(COMMAND_SHUTDOWN_RENDERER);
 			frame();
 			frame();
 
 
-			m_should_run = false;
 			m_thread.stop();		
 			m_thread.stop();		
 		}
 		}
 	}
 	}
@@ -314,6 +313,7 @@ public:
 				{
 				{
 					shutdown_impl();
 					shutdown_impl();
 					m_is_initialized = false;
 					m_is_initialized = false;
+					m_should_run = false;
 					break;
 					break;
 				}
 				}
 				case COMMAND_CREATE_VERTEX_BUFFER:
 				case COMMAND_CREATE_VERTEX_BUFFER:
@@ -653,8 +653,6 @@ public:
 		RenderContext* temp = m_submit;
 		RenderContext* temp = m_submit;
 		m_submit = m_draw;
 		m_submit = m_draw;
 		m_draw = temp;
 		m_draw = temp;
-
-		m_main_wait.post();
 	}
 	}
 
 
 	inline void frame()
 	inline void frame()
@@ -679,6 +677,8 @@ public:
 		{
 		{
 			render_impl();
 			render_impl();
 		}
 		}
+
+		m_main_wait.post();
 	}
 	}
 
 
 protected:
 protected:
@@ -686,7 +686,7 @@ protected:
 	Allocator& m_allocator;
 	Allocator& m_allocator;
 	RendererImplementation* m_impl;
 	RendererImplementation* m_impl;
 
 
-	Thread m_thread;
+	OsThread m_thread;
 	Semaphore m_render_wait;
 	Semaphore m_render_wait;
 	Semaphore m_main_wait;
 	Semaphore m_main_wait;
 
 

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

@@ -167,7 +167,7 @@ public:
 	{
 	{
 		m_gl_context.create_context();
 		m_gl_context.create_context();
 
 
-		#if defined(LINUX) || defined(WINDOW)
+		#if defined(LINUX) || defined(WINDOWS)
 			GLenum err = glewInit();
 			GLenum err = glewInit();
 			CE_ASSERT(err == GLEW_OK, "Failed to initialize GLEW");
 			CE_ASSERT(err == GLEW_OK, "Failed to initialize GLEW");
 		#endif
 		#endif

+ 1 - 0
engine/renderers/gl/glx/GLContext.cpp

@@ -98,6 +98,7 @@ void GLContext::destroy_context()
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLContext::swap_buffers()
 void GLContext::swap_buffers()
 {
 {
+	glXMakeCurrent(s_x11_display, s_x11_window, m_glx_context);
 	glXSwapBuffers(s_x11_display, s_x11_window);
 	glXSwapBuffers(s_x11_display, s_x11_window);
 }
 }
 
 

+ 48 - 10
engine/renderers/gl/wgl/GLContext.cpp

@@ -26,45 +26,83 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "GLContext.h"
 #include "GLContext.h"
 #include "Assert.h"
 #include "Assert.h"
 #include "Types.h"
 #include "Types.h"
+#include "Log.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-static HWND s_handle_window = 0;
+static HWND g_handle_window;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void set_win_handle_window(HWND win)
+void glcontext_set_window(HWND handle)
 {
 {
-	s_handle_window = win;
+	g_handle_window = handle;
+
+	CE_ASSERT(g_handle_window != 0, "Unable to set Windows handle");
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 GLContext::GLContext() :
 GLContext::GLContext() :
-	m_win_context(NULL)
+	m_win_context(NULL),
+	m_hdc(0)
 {
 {
-	
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLContext::create_context()
 void GLContext::create_context()
 {
 {
-	m_win_context = wglCreateContext(GetDC(s_handle_window));
+	// Sets window device context
+	m_hdc = GetDC(g_handle_window);
+	CE_ASSERT(m_hdc != NULL, "Fail to retrieves window device context");
+
+	// Sets pixel format
+	PIXELFORMATDESCRIPTOR pfd;
+	int32_t pixel_format;
+	ZeroMemory(&pfd, sizeof (pfd));
+	pfd.nSize = sizeof (pfd);
+	pfd.nVersion = 1;
+	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+	pfd.iPixelType = PFD_TYPE_RGBA;
+	pfd.cColorBits = 24;
+	pfd.cDepthBits = 24;
+	pfd.iLayerType = PFD_MAIN_PLANE;
+
+	pixel_format = ChoosePixelFormat(m_hdc, &pfd);
+	CE_ASSERT(pixel_format != 0, "Pixel format not supported");
 
 
-	wglMakeCurrent(GetDC(s_handle_window), m_win_context);
+	bool pf_set = SetPixelFormat(m_hdc, pixel_format, &pfd);
+	CE_ASSERT(pf_set, "Unable to set the pixel format");
 
 
-	CE_ASSERT(m_win_context != NULL, "Unable to create a rendering context.");
+	m_win_context = wglCreateContext(m_hdc);
+	CE_ASSERT(m_win_context != NULL, "Unable to create a WGL context. errno: %d", GetLastError());
+
+	BOOL result = wglMakeCurrent(m_hdc, m_win_context);
+	CE_ASSERT(result == TRUE , "Unable to make current WGL context.");	
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLContext::destroy_context()
 void GLContext::destroy_context()
 {
 {
-	wglMakeCurrent(NULL, NULL);
+	if (g_handle_window != NULL)
+	{
+		wglMakeCurrent(NULL, NULL);
+
+		wglDeleteContext(m_win_context);
+		m_win_context = NULL;
+		
+		ReleaseDC(g_handle_window, m_hdc);
+		m_hdc = NULL;
+	}
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLContext::swap_buffers()
 void GLContext::swap_buffers()
 {
 {
-	SwapBuffers(GetDC(s_handle_window));
+	if (g_handle_window != NULL)
+	{
+		wglMakeCurrent(m_hdc, m_win_context);
+		SwapBuffers(m_hdc);
+	}
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 5 - 2
engine/renderers/gl/wgl/GLContext.h

@@ -26,12 +26,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
-#include <windows.h>
+#include "wglext.h"
+
+#include "Types.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-void set_win_handle_window(HWND win);
+CE_EXPORT void glcontext_set_window(HWND handle);
 
 
 class GLContext
 class GLContext
 {
 {
@@ -46,6 +48,7 @@ public:
 private:
 private:
 
 
 	HGLRC 			m_win_context;
 	HGLRC 			m_win_context;
+	HDC				m_hdc;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 951 - 0
engine/renderers/gl/wgl/wglext.h

@@ -0,0 +1,951 @@
+#ifndef __wglext_h_
+#define __wglext_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <gl/glew.h>
+
+/*
+** THIS FILE IS OBSOLETE. Please migrate away from using the
+** ".spec" files and the headers generated from them to the
+** XML Registry and headers generated from that. See
+**   http://www.opengl.org/registry/api/README.txt
+** for more information.
+** 
+** 
+** Copyright (c) 2007-2013 The Khronos Group Inc.
+** 
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are 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 Materials.
+** 
+** THE MATERIALS ARE 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
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Function declaration macros - to move into glplatform.h */
+#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
+#ifndef APIENTRYP
+#define APIENTRYP APIENTRY *
+#endif
+#ifndef GLAPI
+#define GLAPI extern
+#endif
+
+/*************************************************************/
+
+/* Header file version number */
+/* wglext.h last updated 2013/06/10 */
+/* Current version at http://www.opengl.org/registry/ */
+#define WGL_WGLEXT_VERSION 26
+
+#ifndef WGL_ARB_buffer_region
+#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
+#define WGL_BACK_COLOR_BUFFER_BIT_ARB  0x00000002
+#define WGL_DEPTH_BUFFER_BIT_ARB       0x00000004
+#define WGL_STENCIL_BUFFER_BIT_ARB     0x00000008
+#endif
+
+#ifndef WGL_ARB_multisample
+#define WGL_SAMPLE_BUFFERS_ARB         0x2041
+#define WGL_SAMPLES_ARB                0x2042
+#endif
+
+#ifndef WGL_ARB_extensions_string
+#endif
+
+#ifndef WGL_ARB_pixel_format
+#define WGL_NUMBER_PIXEL_FORMATS_ARB   0x2000
+#define WGL_DRAW_TO_WINDOW_ARB         0x2001
+#define WGL_DRAW_TO_BITMAP_ARB         0x2002
+#define WGL_ACCELERATION_ARB           0x2003
+#define WGL_NEED_PALETTE_ARB           0x2004
+#define WGL_NEED_SYSTEM_PALETTE_ARB    0x2005
+#define WGL_SWAP_LAYER_BUFFERS_ARB     0x2006
+#define WGL_SWAP_METHOD_ARB            0x2007
+#define WGL_NUMBER_OVERLAYS_ARB        0x2008
+#define WGL_NUMBER_UNDERLAYS_ARB       0x2009
+#define WGL_TRANSPARENT_ARB            0x200A
+#define WGL_TRANSPARENT_RED_VALUE_ARB  0x2037
+#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
+#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
+#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
+#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
+#define WGL_SHARE_DEPTH_ARB            0x200C
+#define WGL_SHARE_STENCIL_ARB          0x200D
+#define WGL_SHARE_ACCUM_ARB            0x200E
+#define WGL_SUPPORT_GDI_ARB            0x200F
+#define WGL_SUPPORT_OPENGL_ARB         0x2010
+#define WGL_DOUBLE_BUFFER_ARB          0x2011
+#define WGL_STEREO_ARB                 0x2012
+#define WGL_PIXEL_TYPE_ARB             0x2013
+#define WGL_COLOR_BITS_ARB             0x2014
+#define WGL_RED_BITS_ARB               0x2015
+#define WGL_RED_SHIFT_ARB              0x2016
+#define WGL_GREEN_BITS_ARB             0x2017
+#define WGL_GREEN_SHIFT_ARB            0x2018
+#define WGL_BLUE_BITS_ARB              0x2019
+#define WGL_BLUE_SHIFT_ARB             0x201A
+#define WGL_ALPHA_BITS_ARB             0x201B
+#define WGL_ALPHA_SHIFT_ARB            0x201C
+#define WGL_ACCUM_BITS_ARB             0x201D
+#define WGL_ACCUM_RED_BITS_ARB         0x201E
+#define WGL_ACCUM_GREEN_BITS_ARB       0x201F
+#define WGL_ACCUM_BLUE_BITS_ARB        0x2020
+#define WGL_ACCUM_ALPHA_BITS_ARB       0x2021
+#define WGL_DEPTH_BITS_ARB             0x2022
+#define WGL_STENCIL_BITS_ARB           0x2023
+#define WGL_AUX_BUFFERS_ARB            0x2024
+#define WGL_NO_ACCELERATION_ARB        0x2025
+#define WGL_GENERIC_ACCELERATION_ARB   0x2026
+#define WGL_FULL_ACCELERATION_ARB      0x2027
+#define WGL_SWAP_EXCHANGE_ARB          0x2028
+#define WGL_SWAP_COPY_ARB              0x2029
+#define WGL_SWAP_UNDEFINED_ARB         0x202A
+#define WGL_TYPE_RGBA_ARB              0x202B
+#define WGL_TYPE_COLORINDEX_ARB        0x202C
+#endif
+
+#ifndef WGL_ARB_make_current_read
+#define ERROR_INVALID_PIXEL_TYPE_ARB   0x2043
+#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054
+#endif
+
+#ifndef WGL_ARB_pbuffer
+#define WGL_DRAW_TO_PBUFFER_ARB        0x202D
+#define WGL_MAX_PBUFFER_PIXELS_ARB     0x202E
+#define WGL_MAX_PBUFFER_WIDTH_ARB      0x202F
+#define WGL_MAX_PBUFFER_HEIGHT_ARB     0x2030
+#define WGL_PBUFFER_LARGEST_ARB        0x2033
+#define WGL_PBUFFER_WIDTH_ARB          0x2034
+#define WGL_PBUFFER_HEIGHT_ARB         0x2035
+#define WGL_PBUFFER_LOST_ARB           0x2036
+#endif
+
+#ifndef WGL_ARB_render_texture
+#define WGL_BIND_TO_TEXTURE_RGB_ARB    0x2070
+#define WGL_BIND_TO_TEXTURE_RGBA_ARB   0x2071
+#define WGL_TEXTURE_FORMAT_ARB         0x2072
+#define WGL_TEXTURE_TARGET_ARB         0x2073
+#define WGL_MIPMAP_TEXTURE_ARB         0x2074
+#define WGL_TEXTURE_RGB_ARB            0x2075
+#define WGL_TEXTURE_RGBA_ARB           0x2076
+#define WGL_NO_TEXTURE_ARB             0x2077
+#define WGL_TEXTURE_CUBE_MAP_ARB       0x2078
+#define WGL_TEXTURE_1D_ARB             0x2079
+#define WGL_TEXTURE_2D_ARB             0x207A
+#define WGL_MIPMAP_LEVEL_ARB           0x207B
+#define WGL_CUBE_MAP_FACE_ARB          0x207C
+#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D
+#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E
+#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F
+#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080
+#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081
+#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082
+#define WGL_FRONT_LEFT_ARB             0x2083
+#define WGL_FRONT_RIGHT_ARB            0x2084
+#define WGL_BACK_LEFT_ARB              0x2085
+#define WGL_BACK_RIGHT_ARB             0x2086
+#define WGL_AUX0_ARB                   0x2087
+#define WGL_AUX1_ARB                   0x2088
+#define WGL_AUX2_ARB                   0x2089
+#define WGL_AUX3_ARB                   0x208A
+#define WGL_AUX4_ARB                   0x208B
+#define WGL_AUX5_ARB                   0x208C
+#define WGL_AUX6_ARB                   0x208D
+#define WGL_AUX7_ARB                   0x208E
+#define WGL_AUX8_ARB                   0x208F
+#define WGL_AUX9_ARB                   0x2090
+#endif
+
+#ifndef WGL_ARB_pixel_format_float
+#define WGL_TYPE_RGBA_FLOAT_ARB        0x21A0
+#endif
+
+#ifndef WGL_ARB_framebuffer_sRGB
+#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
+#endif
+
+#ifndef WGL_ARB_create_context
+#define WGL_CONTEXT_DEBUG_BIT_ARB      0x00000001
+#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
+#define WGL_CONTEXT_MAJOR_VERSION_ARB  0x2091
+#define WGL_CONTEXT_MINOR_VERSION_ARB  0x2092
+#define WGL_CONTEXT_LAYER_PLANE_ARB    0x2093
+#define WGL_CONTEXT_FLAGS_ARB          0x2094
+#define ERROR_INVALID_VERSION_ARB      0x2095
+#endif
+
+#ifndef WGL_ARB_create_context_profile
+#define WGL_CONTEXT_PROFILE_MASK_ARB   0x9126
+#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
+#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
+#define ERROR_INVALID_PROFILE_ARB      0x2096
+#endif
+
+#ifndef WGL_ARB_create_context_robustness
+#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
+#define WGL_LOSE_CONTEXT_ON_RESET_ARB  0x8252
+#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
+#define WGL_NO_RESET_NOTIFICATION_ARB  0x8261
+#endif
+
+#ifndef WGL_EXT_make_current_read
+#define ERROR_INVALID_PIXEL_TYPE_EXT   0x2043
+#endif
+
+#ifndef WGL_EXT_pixel_format
+#define WGL_NUMBER_PIXEL_FORMATS_EXT   0x2000
+#define WGL_DRAW_TO_WINDOW_EXT         0x2001
+#define WGL_DRAW_TO_BITMAP_EXT         0x2002
+#define WGL_ACCELERATION_EXT           0x2003
+#define WGL_NEED_PALETTE_EXT           0x2004
+#define WGL_NEED_SYSTEM_PALETTE_EXT    0x2005
+#define WGL_SWAP_LAYER_BUFFERS_EXT     0x2006
+#define WGL_SWAP_METHOD_EXT            0x2007
+#define WGL_NUMBER_OVERLAYS_EXT        0x2008
+#define WGL_NUMBER_UNDERLAYS_EXT       0x2009
+#define WGL_TRANSPARENT_EXT            0x200A
+#define WGL_TRANSPARENT_VALUE_EXT      0x200B
+#define WGL_SHARE_DEPTH_EXT            0x200C
+#define WGL_SHARE_STENCIL_EXT          0x200D
+#define WGL_SHARE_ACCUM_EXT            0x200E
+#define WGL_SUPPORT_GDI_EXT            0x200F
+#define WGL_SUPPORT_OPENGL_EXT         0x2010
+#define WGL_DOUBLE_BUFFER_EXT          0x2011
+#define WGL_STEREO_EXT                 0x2012
+#define WGL_PIXEL_TYPE_EXT             0x2013
+#define WGL_COLOR_BITS_EXT             0x2014
+#define WGL_RED_BITS_EXT               0x2015
+#define WGL_RED_SHIFT_EXT              0x2016
+#define WGL_GREEN_BITS_EXT             0x2017
+#define WGL_GREEN_SHIFT_EXT            0x2018
+#define WGL_BLUE_BITS_EXT              0x2019
+#define WGL_BLUE_SHIFT_EXT             0x201A
+#define WGL_ALPHA_BITS_EXT             0x201B
+#define WGL_ALPHA_SHIFT_EXT            0x201C
+#define WGL_ACCUM_BITS_EXT             0x201D
+#define WGL_ACCUM_RED_BITS_EXT         0x201E
+#define WGL_ACCUM_GREEN_BITS_EXT       0x201F
+#define WGL_ACCUM_BLUE_BITS_EXT        0x2020
+#define WGL_ACCUM_ALPHA_BITS_EXT       0x2021
+#define WGL_DEPTH_BITS_EXT             0x2022
+#define WGL_STENCIL_BITS_EXT           0x2023
+#define WGL_AUX_BUFFERS_EXT            0x2024
+#define WGL_NO_ACCELERATION_EXT        0x2025
+#define WGL_GENERIC_ACCELERATION_EXT   0x2026
+#define WGL_FULL_ACCELERATION_EXT      0x2027
+#define WGL_SWAP_EXCHANGE_EXT          0x2028
+#define WGL_SWAP_COPY_EXT              0x2029
+#define WGL_SWAP_UNDEFINED_EXT         0x202A
+#define WGL_TYPE_RGBA_EXT              0x202B
+#define WGL_TYPE_COLORINDEX_EXT        0x202C
+#endif
+
+#ifndef WGL_EXT_pbuffer
+#define WGL_DRAW_TO_PBUFFER_EXT        0x202D
+#define WGL_MAX_PBUFFER_PIXELS_EXT     0x202E
+#define WGL_MAX_PBUFFER_WIDTH_EXT      0x202F
+#define WGL_MAX_PBUFFER_HEIGHT_EXT     0x2030
+#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT  0x2031
+#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032
+#define WGL_PBUFFER_LARGEST_EXT        0x2033
+#define WGL_PBUFFER_WIDTH_EXT          0x2034
+#define WGL_PBUFFER_HEIGHT_EXT         0x2035
+#endif
+
+#ifndef WGL_EXT_depth_float
+#define WGL_DEPTH_FLOAT_EXT            0x2040
+#endif
+
+#ifndef WGL_3DFX_multisample
+#define WGL_SAMPLE_BUFFERS_3DFX        0x2060
+#define WGL_SAMPLES_3DFX               0x2061
+#endif
+
+#ifndef WGL_EXT_multisample
+#define WGL_SAMPLE_BUFFERS_EXT         0x2041
+#define WGL_SAMPLES_EXT                0x2042
+#endif
+
+#ifndef WGL_I3D_digital_video_control
+#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050
+#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051
+#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052
+#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053
+#endif
+
+#ifndef WGL_I3D_gamma
+#define WGL_GAMMA_TABLE_SIZE_I3D       0x204E
+#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D  0x204F
+#endif
+
+#ifndef WGL_I3D_genlock
+#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044
+#define WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D 0x2045
+#define WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D 0x2046
+#define WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D 0x2047
+#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048
+#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049
+#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A
+#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B
+#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C
+#endif
+
+#ifndef WGL_I3D_image_buffer
+#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001
+#define WGL_IMAGE_BUFFER_LOCK_I3D      0x00000002
+#endif
+
+#ifndef WGL_I3D_swap_frame_lock
+#endif
+
+#ifndef WGL_NV_render_depth_texture
+#define WGL_BIND_TO_TEXTURE_DEPTH_NV   0x20A3
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4
+#define WGL_DEPTH_TEXTURE_FORMAT_NV    0x20A5
+#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6
+#define WGL_DEPTH_COMPONENT_NV         0x20A7
+#endif
+
+#ifndef WGL_NV_render_texture_rectangle
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1
+#define WGL_TEXTURE_RECTANGLE_NV       0x20A2
+#endif
+
+#ifndef WGL_ATI_pixel_format_float
+#define WGL_TYPE_RGBA_FLOAT_ATI        0x21A0
+#endif
+
+#ifndef WGL_NV_float_buffer
+#define WGL_FLOAT_COMPONENTS_NV        0x20B0
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3
+#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4
+#define WGL_TEXTURE_FLOAT_R_NV         0x20B5
+#define WGL_TEXTURE_FLOAT_RG_NV        0x20B6
+#define WGL_TEXTURE_FLOAT_RGB_NV       0x20B7
+#define WGL_TEXTURE_FLOAT_RGBA_NV      0x20B8
+#endif
+
+#ifndef WGL_3DL_stereo_control
+#define WGL_STEREO_EMITTER_ENABLE_3DL  0x2055
+#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056
+#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057
+#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058
+#endif
+
+#ifndef WGL_EXT_pixel_format_packed_float
+#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8
+#endif
+
+#ifndef WGL_EXT_framebuffer_sRGB
+#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9
+#endif
+
+#ifndef WGL_NV_present_video
+#define WGL_NUM_VIDEO_SLOTS_NV         0x20F0
+#endif
+
+#ifndef WGL_NV_video_out
+#define WGL_BIND_TO_VIDEO_RGB_NV       0x20C0
+#define WGL_BIND_TO_VIDEO_RGBA_NV      0x20C1
+#define WGL_BIND_TO_VIDEO_RGB_AND_DEPTH_NV 0x20C2
+#define WGL_VIDEO_OUT_COLOR_NV         0x20C3
+#define WGL_VIDEO_OUT_ALPHA_NV         0x20C4
+#define WGL_VIDEO_OUT_DEPTH_NV         0x20C5
+#define WGL_VIDEO_OUT_COLOR_AND_ALPHA_NV 0x20C6
+#define WGL_VIDEO_OUT_COLOR_AND_DEPTH_NV 0x20C7
+#define WGL_VIDEO_OUT_FRAME            0x20C8
+#define WGL_VIDEO_OUT_FIELD_1          0x20C9
+#define WGL_VIDEO_OUT_FIELD_2          0x20CA
+#define WGL_VIDEO_OUT_STACKED_FIELDS_1_2 0x20CB
+#define WGL_VIDEO_OUT_STACKED_FIELDS_2_1 0x20CC
+#endif
+
+#ifndef WGL_NV_swap_group
+#endif
+
+#ifndef WGL_NV_gpu_affinity
+#define ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0
+#define ERROR_MISSING_AFFINITY_MASK_NV 0x20D1
+#endif
+
+#ifndef WGL_AMD_gpu_association
+#define WGL_GPU_VENDOR_AMD             0x1F00
+#define WGL_GPU_RENDERER_STRING_AMD    0x1F01
+#define WGL_GPU_OPENGL_VERSION_STRING_AMD 0x1F02
+#define WGL_GPU_FASTEST_TARGET_GPUS_AMD 0x21A2
+#define WGL_GPU_RAM_AMD                0x21A3
+#define WGL_GPU_CLOCK_AMD              0x21A4
+#define WGL_GPU_NUM_PIPES_AMD          0x21A5
+#define WGL_GPU_NUM_SIMD_AMD           0x21A6
+#define WGL_GPU_NUM_RB_AMD             0x21A7
+#define WGL_GPU_NUM_SPI_AMD            0x21A8
+#endif
+
+#ifndef WGL_NV_video_capture
+#define WGL_UNIQUE_ID_NV               0x20CE
+#define WGL_NUM_VIDEO_CAPTURE_SLOTS_NV 0x20CF
+#endif
+
+#ifndef WGL_NV_copy_image
+#endif
+
+#ifndef WGL_NV_multisample_coverage
+#define WGL_COVERAGE_SAMPLES_NV        0x2042
+#define WGL_COLOR_SAMPLES_NV           0x20B9
+#endif
+
+#ifndef WGL_EXT_create_context_es2_profile
+#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
+#endif
+
+#ifndef WGL_NV_DX_interop
+#define WGL_ACCESS_READ_ONLY_NV        0x00000000
+#define WGL_ACCESS_READ_WRITE_NV       0x00000001
+#define WGL_ACCESS_WRITE_DISCARD_NV    0x00000002
+#endif
+
+#ifndef WGL_NV_DX_interop2
+#endif
+
+#ifndef WGL_EXT_swap_control_tear
+#endif
+
+
+/*************************************************************/
+
+#ifndef WGL_ARB_pbuffer
+DECLARE_HANDLE(HPBUFFERARB);
+#endif
+#ifndef WGL_EXT_pbuffer
+DECLARE_HANDLE(HPBUFFEREXT);
+#endif
+#ifndef WGL_NV_present_video
+DECLARE_HANDLE(HVIDEOOUTPUTDEVICENV);
+#endif
+#ifndef WGL_NV_video_output
+DECLARE_HANDLE(HPVIDEODEV);
+#endif
+#ifndef WGL_NV_gpu_affinity
+DECLARE_HANDLE(HPGPUNV);
+DECLARE_HANDLE(HGPUNV);
+
+typedef struct _GPU_DEVICE {
+    DWORD  cb;
+    CHAR   DeviceName[32];
+    CHAR   DeviceString[128];
+    DWORD  Flags;
+    RECT   rcVirtualScreen;
+} GPU_DEVICE, *PGPU_DEVICE;
+#endif
+#ifndef WGL_NV_video_capture
+DECLARE_HANDLE(HVIDEOINPUTDEVICENV);
+#endif
+
+#ifndef WGL_ARB_buffer_region
+#define WGL_ARB_buffer_region 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern HANDLE WINAPI wglCreateBufferRegionARB (HDC hDC, int iLayerPlane, UINT uType);
+extern VOID WINAPI wglDeleteBufferRegionARB (HANDLE hRegion);
+extern BOOL WINAPI wglSaveBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height);
+extern BOOL WINAPI wglRestoreBufferRegionARB (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType);
+typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion);
+typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height);
+typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
+#endif
+
+#ifndef WGL_ARB_multisample
+#define WGL_ARB_multisample 1
+#endif
+
+#ifndef WGL_ARB_extensions_string
+#define WGL_ARB_extensions_string 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern const char * WINAPI wglGetExtensionsStringARB (HDC hdc);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
+#endif
+
+#ifndef WGL_ARB_pixel_format
+#define WGL_ARB_pixel_format 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
+extern BOOL WINAPI wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
+extern BOOL WINAPI wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
+typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues);
+typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
+#endif
+
+#ifndef WGL_ARB_make_current_read
+#define WGL_ARB_make_current_read 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglMakeContextCurrentARB (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
+extern HDC WINAPI wglGetCurrentReadDCARB (void);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
+typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (void);
+#endif
+
+#ifndef WGL_ARB_pbuffer
+#define WGL_ARB_pbuffer 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern HPBUFFERARB WINAPI wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
+extern HDC WINAPI wglGetPbufferDCARB (HPBUFFERARB hPbuffer);
+extern int WINAPI wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC);
+extern BOOL WINAPI wglDestroyPbufferARB (HPBUFFERARB hPbuffer);
+extern BOOL WINAPI wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
+typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer);
+typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC);
+typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer);
+typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
+#endif
+
+#ifndef WGL_ARB_render_texture
+#define WGL_ARB_render_texture 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
+extern BOOL WINAPI wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
+extern BOOL WINAPI wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
+typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
+typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList);
+#endif
+
+#ifndef WGL_ARB_pixel_format_float
+#define WGL_ARB_pixel_format_float 1
+#endif
+
+#ifndef WGL_ARB_framebuffer_sRGB
+#define WGL_ARB_framebuffer_sRGB 1
+#endif
+
+#ifndef WGL_ARB_create_context
+#define WGL_ARB_create_context 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern HGLRC WINAPI wglCreateContextAttribsARB (HDC hDC, HGLRC hShareContext, const int *attribList);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
+#endif
+
+#ifndef WGL_ARB_create_context_profile
+#define WGL_ARB_create_context_profile 1
+#endif
+
+#ifndef WGL_ARB_create_context_robustness
+#define WGL_ARB_create_context_robustness 1
+#endif
+
+#ifndef WGL_EXT_display_color_table
+#define WGL_EXT_display_color_table 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern GLboolean WINAPI wglCreateDisplayColorTableEXT (GLushort id);
+extern GLboolean WINAPI wglLoadDisplayColorTableEXT (const GLushort *table, GLuint length);
+extern GLboolean WINAPI wglBindDisplayColorTableEXT (GLushort id);
+extern VOID WINAPI wglDestroyDisplayColorTableEXT (GLushort id);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id);
+typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (const GLushort *table, GLuint length);
+typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id);
+typedef VOID (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id);
+#endif
+
+#ifndef WGL_EXT_extensions_string
+#define WGL_EXT_extensions_string 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern const char * WINAPI wglGetExtensionsStringEXT (void);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void);
+#endif
+
+#ifndef WGL_EXT_make_current_read
+#define WGL_EXT_make_current_read 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglMakeContextCurrentEXT (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
+extern HDC WINAPI wglGetCurrentReadDCEXT (void);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
+typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (void);
+#endif
+
+#ifndef WGL_EXT_pbuffer
+#define WGL_EXT_pbuffer 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern HPBUFFEREXT WINAPI wglCreatePbufferEXT (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
+extern HDC WINAPI wglGetPbufferDCEXT (HPBUFFEREXT hPbuffer);
+extern int WINAPI wglReleasePbufferDCEXT (HPBUFFEREXT hPbuffer, HDC hDC);
+extern BOOL WINAPI wglDestroyPbufferEXT (HPBUFFEREXT hPbuffer);
+extern BOOL WINAPI wglQueryPbufferEXT (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
+typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer);
+typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC);
+typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer);
+typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int *piValue);
+#endif
+
+#ifndef WGL_EXT_pixel_format
+#define WGL_EXT_pixel_format 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetPixelFormatAttribivEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
+extern BOOL WINAPI wglGetPixelFormatAttribfvEXT (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
+extern BOOL WINAPI wglChoosePixelFormatEXT (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
+typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
+typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
+#endif
+
+#ifndef WGL_EXT_swap_control
+#define WGL_EXT_swap_control 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglSwapIntervalEXT (int interval);
+extern int WINAPI wglGetSwapIntervalEXT (void);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
+typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
+#endif
+
+#ifndef WGL_EXT_depth_float
+#define WGL_EXT_depth_float 1
+#endif
+
+#ifndef WGL_NV_vertex_array_range
+#define WGL_NV_vertex_array_range 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern void* WINAPI wglAllocateMemoryNV (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
+extern void WINAPI wglFreeMemoryNV (void *pointer);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef void* (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
+typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer);
+#endif
+
+#ifndef WGL_3DFX_multisample
+#define WGL_3DFX_multisample 1
+#endif
+
+#ifndef WGL_EXT_multisample
+#define WGL_EXT_multisample 1
+#endif
+
+#ifndef WGL_OML_sync_control
+#define WGL_OML_sync_control 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetSyncValuesOML (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc);
+extern BOOL WINAPI wglGetMscRateOML (HDC hdc, INT32 *numerator, INT32 *denominator);
+extern INT64 WINAPI wglSwapBuffersMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
+extern INT64 WINAPI wglSwapLayerBuffersMscOML (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
+extern BOOL WINAPI wglWaitForMscOML (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc);
+extern BOOL WINAPI wglWaitForSbcOML (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64 *ust, INT64 *msc, INT64 *sbc);
+typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32 *numerator, INT32 *denominator);
+typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
+typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, int fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
+typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64 *ust, INT64 *msc, INT64 *sbc);
+typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64 *ust, INT64 *msc, INT64 *sbc);
+#endif
+
+#ifndef WGL_I3D_digital_video_control
+#define WGL_I3D_digital_video_control 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetDigitalVideoParametersI3D (HDC hDC, int iAttribute, int *piValue);
+extern BOOL WINAPI wglSetDigitalVideoParametersI3D (HDC hDC, int iAttribute, const int *piValue);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue);
+typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue);
+#endif
+
+#ifndef WGL_I3D_gamma
+#define WGL_I3D_gamma 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetGammaTableParametersI3D (HDC hDC, int iAttribute, int *piValue);
+extern BOOL WINAPI wglSetGammaTableParametersI3D (HDC hDC, int iAttribute, const int *piValue);
+extern BOOL WINAPI wglGetGammaTableI3D (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue);
+extern BOOL WINAPI wglSetGammaTableI3D (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int *piValue);
+typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int *piValue);
+typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT *puRed, USHORT *puGreen, USHORT *puBlue);
+typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT *puRed, const USHORT *puGreen, const USHORT *puBlue);
+#endif
+
+#ifndef WGL_I3D_genlock
+#define WGL_I3D_genlock 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglEnableGenlockI3D (HDC hDC);
+extern BOOL WINAPI wglDisableGenlockI3D (HDC hDC);
+extern BOOL WINAPI wglIsEnabledGenlockI3D (HDC hDC, BOOL *pFlag);
+extern BOOL WINAPI wglGenlockSourceI3D (HDC hDC, UINT uSource);
+extern BOOL WINAPI wglGetGenlockSourceI3D (HDC hDC, UINT *uSource);
+extern BOOL WINAPI wglGenlockSourceEdgeI3D (HDC hDC, UINT uEdge);
+extern BOOL WINAPI wglGetGenlockSourceEdgeI3D (HDC hDC, UINT *uEdge);
+extern BOOL WINAPI wglGenlockSampleRateI3D (HDC hDC, UINT uRate);
+extern BOOL WINAPI wglGetGenlockSampleRateI3D (HDC hDC, UINT *uRate);
+extern BOOL WINAPI wglGenlockSourceDelayI3D (HDC hDC, UINT uDelay);
+extern BOOL WINAPI wglGetGenlockSourceDelayI3D (HDC hDC, UINT *uDelay);
+extern BOOL WINAPI wglQueryGenlockMaxSourceDelayI3D (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC);
+typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC);
+typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL *pFlag);
+typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource);
+typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT *uSource);
+typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge);
+typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT *uEdge);
+typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate);
+typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT *uRate);
+typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay);
+typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT *uDelay);
+typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT *uMaxLineDelay, UINT *uMaxPixelDelay);
+#endif
+
+#ifndef WGL_I3D_image_buffer
+#define WGL_I3D_image_buffer 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern LPVOID WINAPI wglCreateImageBufferI3D (HDC hDC, DWORD dwSize, UINT uFlags);
+extern BOOL WINAPI wglDestroyImageBufferI3D (HDC hDC, LPVOID pAddress);
+extern BOOL WINAPI wglAssociateImageBufferEventsI3D (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count);
+extern BOOL WINAPI wglReleaseImageBufferEventsI3D (HDC hDC, const LPVOID *pAddress, UINT count);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags);
+typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress);
+typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const HANDLE *pEvent, const LPVOID *pAddress, const DWORD *pSize, UINT count);
+typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hDC, const LPVOID *pAddress, UINT count);
+#endif
+
+#ifndef WGL_I3D_swap_frame_lock
+#define WGL_I3D_swap_frame_lock 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglEnableFrameLockI3D (void);
+extern BOOL WINAPI wglDisableFrameLockI3D (void);
+extern BOOL WINAPI wglIsEnabledFrameLockI3D (BOOL *pFlag);
+extern BOOL WINAPI wglQueryFrameLockMasterI3D (BOOL *pFlag);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (void);
+typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (void);
+typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL *pFlag);
+typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL *pFlag);
+#endif
+
+#ifndef WGL_I3D_swap_frame_usage
+#define WGL_I3D_swap_frame_usage 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetFrameUsageI3D (float *pUsage);
+extern BOOL WINAPI wglBeginFrameTrackingI3D (void);
+extern BOOL WINAPI wglEndFrameTrackingI3D (void);
+extern BOOL WINAPI wglQueryFrameTrackingI3D (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float *pUsage);
+typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void);
+typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void);
+typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD *pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
+#endif
+
+#ifndef WGL_ATI_pixel_format_float
+#define WGL_ATI_pixel_format_float 1
+#endif
+
+#ifndef WGL_NV_float_buffer
+#define WGL_NV_float_buffer 1
+#endif
+
+#ifndef WGL_3DL_stereo_control
+#define WGL_3DL_stereo_control 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglSetStereoEmitterState3DL (HDC hDC, UINT uState);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState);
+#endif
+
+#ifndef WGL_EXT_pixel_format_packed_float
+#define WGL_EXT_pixel_format_packed_float 1
+#endif
+
+#ifndef WGL_EXT_framebuffer_sRGB
+#define WGL_EXT_framebuffer_sRGB 1
+#endif
+
+#ifndef WGL_NV_present_video
+#define WGL_NV_present_video 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern int WINAPI wglEnumerateVideoDevicesNV (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList);
+extern BOOL WINAPI wglBindVideoDeviceNV (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList);
+extern BOOL WINAPI wglQueryCurrentContextNV (int iAttribute, int *piValue);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef int (WINAPI * PFNWGLENUMERATEVIDEODEVICESNVPROC) (HDC hDC, HVIDEOOUTPUTDEVICENV *phDeviceList);
+typedef BOOL (WINAPI * PFNWGLBINDVIDEODEVICENVPROC) (HDC hDC, unsigned int uVideoSlot, HVIDEOOUTPUTDEVICENV hVideoDevice, const int *piAttribList);
+typedef BOOL (WINAPI * PFNWGLQUERYCURRENTCONTEXTNVPROC) (int iAttribute, int *piValue);
+#endif
+
+#ifndef WGL_NV_video_output
+#define WGL_NV_video_output 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglGetVideoDeviceNV (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice);
+extern BOOL WINAPI wglReleaseVideoDeviceNV (HPVIDEODEV hVideoDevice);
+extern BOOL WINAPI wglBindVideoImageNV (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer);
+extern BOOL WINAPI wglReleaseVideoImageNV (HPBUFFERARB hPbuffer, int iVideoBuffer);
+extern BOOL WINAPI wglSendPbufferToVideoNV (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock);
+extern BOOL WINAPI wglGetVideoInfoNV (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLGETVIDEODEVICENVPROC) (HDC hDC, int numDevices, HPVIDEODEV *hVideoDevice);
+typedef BOOL (WINAPI * PFNWGLRELEASEVIDEODEVICENVPROC) (HPVIDEODEV hVideoDevice);
+typedef BOOL (WINAPI * PFNWGLBINDVIDEOIMAGENVPROC) (HPVIDEODEV hVideoDevice, HPBUFFERARB hPbuffer, int iVideoBuffer);
+typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOIMAGENVPROC) (HPBUFFERARB hPbuffer, int iVideoBuffer);
+typedef BOOL (WINAPI * PFNWGLSENDPBUFFERTOVIDEONVPROC) (HPBUFFERARB hPbuffer, int iBufferType, unsigned long *pulCounterPbuffer, BOOL bBlock);
+typedef BOOL (WINAPI * PFNWGLGETVIDEOINFONVPROC) (HPVIDEODEV hpVideoDevice, unsigned long *pulCounterOutputPbuffer, unsigned long *pulCounterOutputVideo);
+#endif
+
+#ifndef WGL_NV_swap_group
+#define WGL_NV_swap_group 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglJoinSwapGroupNV (HDC hDC, GLuint group);
+extern BOOL WINAPI wglBindSwapBarrierNV (GLuint group, GLuint barrier);
+extern BOOL WINAPI wglQuerySwapGroupNV (HDC hDC, GLuint *group, GLuint *barrier);
+extern BOOL WINAPI wglQueryMaxSwapGroupsNV (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers);
+extern BOOL WINAPI wglQueryFrameCountNV (HDC hDC, GLuint *count);
+extern BOOL WINAPI wglResetFrameCountNV (HDC hDC);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLJOINSWAPGROUPNVPROC) (HDC hDC, GLuint group);
+typedef BOOL (WINAPI * PFNWGLBINDSWAPBARRIERNVPROC) (GLuint group, GLuint barrier);
+typedef BOOL (WINAPI * PFNWGLQUERYSWAPGROUPNVPROC) (HDC hDC, GLuint *group, GLuint *barrier);
+typedef BOOL (WINAPI * PFNWGLQUERYMAXSWAPGROUPSNVPROC) (HDC hDC, GLuint *maxGroups, GLuint *maxBarriers);
+typedef BOOL (WINAPI * PFNWGLQUERYFRAMECOUNTNVPROC) (HDC hDC, GLuint *count);
+typedef BOOL (WINAPI * PFNWGLRESETFRAMECOUNTNVPROC) (HDC hDC);
+#endif
+
+#ifndef WGL_NV_gpu_affinity
+#define WGL_NV_gpu_affinity 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglEnumGpusNV (UINT iGpuIndex, HGPUNV *phGpu);
+extern BOOL WINAPI wglEnumGpuDevicesNV (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
+extern HDC WINAPI wglCreateAffinityDCNV (const HGPUNV *phGpuList);
+extern BOOL WINAPI wglEnumGpusFromAffinityDCNV (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
+extern BOOL WINAPI wglDeleteDCNV (HDC hdc);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu);
+typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
+typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList);
+typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
+typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc);
+#endif
+
+#ifndef WGL_AMD_gpu_association
+#define WGL_AMD_gpu_association 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern UINT WINAPI wglGetGPUIDsAMD (UINT maxCount, UINT *ids);
+extern INT WINAPI wglGetGPUInfoAMD (UINT id, int property, GLenum dataType, UINT size, void *data);
+extern UINT WINAPI wglGetContextGPUIDAMD (HGLRC hglrc);
+extern HGLRC WINAPI wglCreateAssociatedContextAMD (UINT id);
+extern HGLRC WINAPI wglCreateAssociatedContextAttribsAMD (UINT id, HGLRC hShareContext, const int *attribList);
+extern BOOL WINAPI wglDeleteAssociatedContextAMD (HGLRC hglrc);
+extern BOOL WINAPI wglMakeAssociatedContextCurrentAMD (HGLRC hglrc);
+extern HGLRC WINAPI wglGetCurrentAssociatedContextAMD (void);
+extern VOID WINAPI wglBlitContextFramebufferAMD (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef UINT (WINAPI * PFNWGLGETGPUIDSAMDPROC) (UINT maxCount, UINT *ids);
+typedef INT (WINAPI * PFNWGLGETGPUINFOAMDPROC) (UINT id, int property, GLenum dataType, UINT size, void *data);
+typedef UINT (WINAPI * PFNWGLGETCONTEXTGPUIDAMDPROC) (HGLRC hglrc);
+typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTAMDPROC) (UINT id);
+typedef HGLRC (WINAPI * PFNWGLCREATEASSOCIATEDCONTEXTATTRIBSAMDPROC) (UINT id, HGLRC hShareContext, const int *attribList);
+typedef BOOL (WINAPI * PFNWGLDELETEASSOCIATEDCONTEXTAMDPROC) (HGLRC hglrc);
+typedef BOOL (WINAPI * PFNWGLMAKEASSOCIATEDCONTEXTCURRENTAMDPROC) (HGLRC hglrc);
+typedef HGLRC (WINAPI * PFNWGLGETCURRENTASSOCIATEDCONTEXTAMDPROC) (void);
+typedef VOID (WINAPI * PFNWGLBLITCONTEXTFRAMEBUFFERAMDPROC) (HGLRC dstCtx, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+
+#ifndef WGL_NV_video_capture
+#define WGL_NV_video_capture 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglBindVideoCaptureDeviceNV (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
+extern UINT WINAPI wglEnumerateVideoCaptureDevicesNV (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
+extern BOOL WINAPI wglLockVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
+extern BOOL WINAPI wglQueryVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
+extern BOOL WINAPI wglReleaseVideoCaptureDeviceNV (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLBINDVIDEOCAPTUREDEVICENVPROC) (UINT uVideoSlot, HVIDEOINPUTDEVICENV hDevice);
+typedef UINT (WINAPI * PFNWGLENUMERATEVIDEOCAPTUREDEVICESNVPROC) (HDC hDc, HVIDEOINPUTDEVICENV *phDeviceList);
+typedef BOOL (WINAPI * PFNWGLLOCKVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
+typedef BOOL (WINAPI * PFNWGLQUERYVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice, int iAttribute, int *piValue);
+typedef BOOL (WINAPI * PFNWGLRELEASEVIDEOCAPTUREDEVICENVPROC) (HDC hDc, HVIDEOINPUTDEVICENV hDevice);
+#endif
+
+#ifndef WGL_NV_copy_image
+#define WGL_NV_copy_image 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglCopyImageSubDataNV (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLCOPYIMAGESUBDATANVPROC) (HGLRC hSrcRC, GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, HGLRC hDstRC, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+
+#ifndef WGL_NV_multisample_coverage
+#define WGL_NV_multisample_coverage 1
+#endif
+
+#ifndef WGL_NV_DX_interop
+#define WGL_NV_DX_interop 1
+#ifdef WGL_WGLEXT_PROTOTYPES
+extern BOOL WINAPI wglDXSetResourceShareHandleNV (void *dxObject, HANDLE shareHandle);
+extern HANDLE WINAPI wglDXOpenDeviceNV (void *dxDevice);
+extern BOOL WINAPI wglDXCloseDeviceNV (HANDLE hDevice);
+extern HANDLE WINAPI wglDXRegisterObjectNV (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
+extern BOOL WINAPI wglDXUnregisterObjectNV (HANDLE hDevice, HANDLE hObject);
+extern BOOL WINAPI wglDXObjectAccessNV (HANDLE hObject, GLenum access);
+extern BOOL WINAPI wglDXLockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects);
+extern BOOL WINAPI wglDXUnlockObjectsNV (HANDLE hDevice, GLint count, HANDLE *hObjects);
+#endif /* WGL_WGLEXT_PROTOTYPES */
+typedef BOOL (WINAPI * PFNWGLDXSETRESOURCESHAREHANDLENVPROC) (void *dxObject, HANDLE shareHandle);
+typedef HANDLE (WINAPI * PFNWGLDXOPENDEVICENVPROC) (void *dxDevice);
+typedef BOOL (WINAPI * PFNWGLDXCLOSEDEVICENVPROC) (HANDLE hDevice);
+typedef HANDLE (WINAPI * PFNWGLDXREGISTEROBJECTNVPROC) (HANDLE hDevice, void *dxObject, GLuint name, GLenum type, GLenum access);
+typedef BOOL (WINAPI * PFNWGLDXUNREGISTEROBJECTNVPROC) (HANDLE hDevice, HANDLE hObject);
+typedef BOOL (WINAPI * PFNWGLDXOBJECTACCESSNVPROC) (HANDLE hObject, GLenum access);
+typedef BOOL (WINAPI * PFNWGLDXLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects);
+typedef BOOL (WINAPI * PFNWGLDXUNLOCKOBJECTSNVPROC) (HANDLE hDevice, GLint count, HANDLE *hObjects);
+#endif
+
+#ifndef WGL_NV_DX_interop2
+#define WGL_NV_DX_interop2 1
+#endif
+
+#ifndef WGL_EXT_swap_control_tear
+#define WGL_EXT_swap_control_tear 1
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 2 - 2
engine/resource/ResourceLoader.h

@@ -28,7 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #include "Types.h"
 #include "Types.h"
 #include "Resource.h"
 #include "Resource.h"
-#include "Thread.h"
+#include "OsThread.h"
 #include "Queue.h"
 #include "Queue.h"
 #include "List.h"
 #include "List.h"
 #include "Mutex.h"
 #include "Mutex.h"
@@ -108,7 +108,7 @@ private:
 
 
 private:
 private:
 
 
-	Thread					m_thread;
+	OsThread				m_thread;
 	bool					m_should_run;
 	bool					m_should_run;
 
 
 	// Whether to look for resources
 	// Whether to look for resources

+ 13 - 1
engine/rpc/RPCHandler.cpp

@@ -59,7 +59,19 @@ void RPCCommandHandler::execute_command(RPCServer* server, ClientId client, cons
 
 
 		if (string::strcmp("reload", cmd) == 0)
 		if (string::strcmp("reload", cmd) == 0)
 		{
 		{
-			Log::d("Unimplemented");
+			JSONElement resource_type = root.key_or_nil("resource_type");
+			if (!resource_type.is_nil())
+			{
+				JSONElement resource_name = root.key_or_nil("resource_name");
+				if (!resource_name.is_nil())
+				{
+					char t[256];
+					char n[256];
+					string::strncpy(t, resource_type.string_value(), 256);
+					string::strncpy(n, resource_name.string_value(), 256);
+					device()->reload(t, n);
+				}
+			}
 		}
 		}
 		else if (string::strcmp("pause", cmd) == 0)
 		else if (string::strcmp("pause", cmd) == 0)
 		{
 		{

+ 23 - 27
engine/tests/CMakeLists.txt

@@ -2,34 +2,30 @@ cmake_minimum_required(VERSION 2.8)
 
 
 project(crown-tests)
 project(crown-tests)
 
 
-enable_testing()
-
-add_executable(allocators allocators.cpp)
-add_executable(containers containers.cpp)
-add_executable(compressors compressors.cpp)
-add_executable(strings strings.cpp)
-add_executable(paths paths.cpp)
-add_executable(dynamic-strings dynamic-strings.cpp)
-add_executable(json json.cpp)
+#add_executable(allocators allocators.cpp)
+#add_executable(containers containers.cpp)
+#add_executable(compressors compressors.cpp)
+#add_executable(strings strings.cpp)
+#add_executable(paths paths.cpp)
+#add_executable(dynamic-strings dynamic-strings.cpp)
+#add_executable(json json.cpp)
 add_executable(events events.cpp)
 add_executable(events events.cpp)
-add_executable(threads threads.cpp)
 
 
-target_link_libraries(allocators crown)
-target_link_libraries(containers crown)
-target_link_libraries(compressors crown)
-target_link_libraries(strings crown)
-target_link_libraries(paths crown)
-target_link_libraries(dynamic-strings crown)
-target_link_libraries(json crown)
+#target_link_libraries(allocators crown)
+#target_link_libraries(containers crown)
+#target_link_libraries(compressors crown)
+#target_link_libraries(strings crown)
+#target_link_libraries(paths crown)
+#target_link_libraries(dynamic-strings crown)
+#target_link_libraries(json crown)
 target_link_libraries(events crown)
 target_link_libraries(events crown)
-target_link_libraries(threads crown)
 
 
-add_test(allocators-test ${EXECUTABLE_OUTPUT_PATH}/allocators)
-add_test(containers-test ${EXECUTABLE_OUTPUT_PATH}/containers)
-add_test(compressors-test ${EXECUTABLE_OUTPUT_PATH}/compressors)
-add_test(strings-test ${EXECUTABLE_OUTPUT_PATH}/strings)
-add_test(paths-test ${EXECUTABLE_OUTPUT_PATH}/paths)
-add_test(dynamic-string-test ${EXECUTABLE_OUTPUT_PATH}/dynamic-strings)
-add_test(json-test ${EXECUTABLE_OUTPUT_PATH}/json)
-add_test(events-test ${EXECUTABLE_OUTPUT_PATH}/events)
-add_test(threads-test ${EXECUTABLE_OUTPUT_PATH}/threads)
+#install (TARGETS allocators DESTINATION test)
+#install (TARGETS containers DESTINATION test)
+#install (TARGETS compressors DESTINATION test)
+#install (TARGETS strings DESTINATION test)
+#install (TARGETS paths DESTINATION test)
+#install (TARGETS dynamic-strings DESTINATION test)
+#install (TARGETS json DESTINATION test)
+install (TARGETS events DESTINATION test)
+

+ 71 - 52
engine/tests/events.cpp

@@ -1,90 +1,109 @@
+#include <cstdlib>
+#include <ctime>
+
 #include "Crown.h"
 #include "Crown.h"
 #include "EventBuffer.h"
 #include "EventBuffer.h"
+#include "OsTypes.h"
+#include "Mouse.h"
+#include "OsThread.h"
+#include "Log.h"
 
 
 using namespace crown;
 using namespace crown;
 
 
+EventBuffer* g_write;
+EventBuffer* g_read;
+
+OsThread g_thread("consumer-thread");
+Semaphore g_write_sem;
+Semaphore g_read_sem;
+
+bool g_exit = false;
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-struct TestEvent
+void push_event(int32_t x, int32_t y)
 {
 {
-	uint32_t a;
-	uint32_t b;
-	uint32_t c;
-};
+	OsMouseEvent ome;
+	ome.button = MouseButton::LEFT;
+	ome.x = x;
+	ome.y = y;
+	ome.pressed = true;
+
+	g_write->push_event((uint32_t)OsEvent::MOUSE, &ome, sizeof(OsMouseEvent));
+	Log::i("Event pushed");
+}
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void fill_events(EventBuffer& event_buffer, uint32_t num)
+void swap()
 {
 {
-	TestEvent event;
-	event.a = 1;
-	event.b = 2;
-	event.c = 3;
-
-	for (uint32_t i = 0; i < num; i++)
-	{
-		event_buffer.push_event(0, &event, sizeof(TestEvent));
-	}
+	EventBuffer* tmp;
 
 
-	uint32_t size = num * (sizeof(TestEvent) + sizeof(uint32_t) + sizeof(size_t));
+	tmp = g_write;
+	g_write = g_read;
+	g_read = tmp;
 
 
-	CE_ASSERT(event_buffer.size() == size, "Something ha gone wrong, size is %d, should be %d", event_buffer.size(), size);
+	Log::i("Buffers swapped");
 }
 }
 
 
-void get_events(EventBuffer& event_buffer, uint32_t num)
+//-----------------------------------------------------------------------------
+int32_t thread_proc(void* /*user_data*/)
 {
 {
-	TestEvent* result;
-	uint32_t type = 0;
-	size_t size = 0;
+	static uint32_t count = 0;
 
 
-	uint32_t count = 0;
+	OsMouseEvent* result;
+	uint32_t et; size_t es;
 
 
-	for (uint32_t i = 0; i < num; i++)
+	while (true)
 	{
 	{
-		result = (TestEvent*)event_buffer.get_next_event(type, size);
-
-		if (result)
+		Log::i("%p", g_read);
+		
+		do
 		{
 		{
-			count++;
-		}
+			result = (OsMouseEvent*)g_read->get_next_event(et, es);
 
 
-		Log::i("count: %d", count);
-	}
-
-	CE_ASSERT(count == num, "Something ha gone wrong, count: %d, num: %d", count, num);
-}
+			if (result != NULL)
+			{
+				Log::d("x: %d, y: %d", result->x, result->y);
+			}
+		}
+		while (result != NULL);
 
 
-void get_event_until_end(EventBuffer& event_buffer)
-{
-	TestEvent* result;
-	uint32_t type = 0;
-	size_t size = 0;
+		g_exit = ++count == 3 ? true : false;
 
 
-	int32_t count = 0;
+		g_read->clear();
 
 
-	while ((result = (TestEvent*)event_buffer.get_next_event(type, size)) != NULL)
-	{
-		count++;
+		g_write_sem.post();
+		g_read_sem.wait();
 	}
 	}
 
 
-	Log::i("count: %d", count);
+	return 0;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 int main()
 int main()
 {
 {
-	EventBuffer event_buffer;
+	memory::init();
 
 
-	fill_events(event_buffer, 10);
-	get_events(event_buffer, 10);
+	g_write = CE_NEW(default_allocator(), EventBuffer);
+	g_read = CE_NEW(default_allocator(), EventBuffer);
 
 
-	event_buffer.clear();
+	g_thread.start(thread_proc);
 
 
-	fill_events(event_buffer, 5);
-	get_events(event_buffer, 5);
+	while (!g_exit)
+	{
+		g_write_sem.wait();
+
+		push_event(10, 10);
+		push_event(20, 20);
+		push_event(30, 30);
+
+		swap();
+
+		g_read_sem.post();
+	}
 
 
-	event_buffer.clear();
+	g_thread.stop();
 
 
-	fill_events(event_buffer, 30);
-	get_event_until_end(event_buffer);
+	memory::shutdown();
 
 
 	return 0;
 	return 0;
 }
 }

+ 0 - 31
engine/tests/threads.cpp

@@ -1,31 +0,0 @@
-#include "Thread.h"
-#include "Log.h"
-
-#include <unistd.h>
-
-using namespace crown;
-
-int32_t first_function(void* ft)
-{
-	Thread* thread = (Thread*)ft;
-
-	while(thread->is_running())
-	{
-		Log::i("I'm in the first thread");
-	}
-
-	return 0;
-}
-	
-int main()
-{
-	Thread ft("first-thread");
-
-	ft.start(first_function, &ft);
-
-	sleep(2);
-
-	ft.stop();
-
-	return 0;
-}

+ 8 - 0
engine/third/win32/CMakeLists.txt

@@ -16,3 +16,11 @@ endif (WINDOWS)
 
 
 install (PROGRAMS luajit/bin/luajit.exe DESTINATION bin)
 install (PROGRAMS luajit/bin/luajit.exe DESTINATION bin)
 install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)
 install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)
+
+if (WINDOWS)
+	install (FILES luajit/lib/lua51.dll DESTINATION test)
+	install (FILES luajit/lib/luajit-5.1.dll DESTINATION test)	
+endif (WINDOWS)
+
+install (PROGRAMS luajit/bin/luajit.exe DESTINATION test)
+install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION test)

+ 8 - 0
engine/third/win64/CMakeLists.txt

@@ -16,3 +16,11 @@ endif (WINDOWS)
 
 
 install (PROGRAMS luajit/bin/luajit.exe DESTINATION bin)
 install (PROGRAMS luajit/bin/luajit.exe DESTINATION bin)
 install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)
 install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)
+
+if (WINDOWS)
+	install (FILES luajit/lib/lua51.dll DESTINATION test)
+	install (FILES luajit/lib/luajit-5.1.dll DESTINATION test)	
+endif (WINDOWS)
+
+install (PROGRAMS luajit/bin/luajit.exe DESTINATION test)
+install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION test)

+ 7 - 0
engine/third/x86/CMakeLists.txt

@@ -14,3 +14,10 @@ install (FILES luajit/lib/libluajit-5.1.so.2.0.2
 install (PROGRAMS luajit/bin/luajit-2.0.2 DESTINATION bin)
 install (PROGRAMS luajit/bin/luajit-2.0.2 DESTINATION bin)
 install (FILES luajit/bin/luajit DESTINATION bin)
 install (FILES luajit/bin/luajit DESTINATION bin)
 install (DIRECTORY luajit/share/luajit-2.0.2/jit DESTINATION bin)
 install (DIRECTORY luajit/share/luajit-2.0.2/jit DESTINATION bin)
+
+install (FILES luajit/lib/libluajit-5.1.so.2.0.2 
+			   luajit/lib/libluajit-5.1.so.2 DESTINATION test)
+
+install (PROGRAMS luajit/bin/luajit-2.0.2 DESTINATION test)
+install (FILES luajit/bin/luajit DESTINATION test)
+install (DIRECTORY luajit/share/luajit-2.0.2/jit DESTINATION test)

+ 8 - 1
engine/third/x86_64/CMakeLists.txt

@@ -13,4 +13,11 @@ install (FILES luajit/lib/libluajit-5.1.so.2.0.1
 
 
 install (PROGRAMS luajit/bin/luajit-2.0.1 DESTINATION bin)
 install (PROGRAMS luajit/bin/luajit-2.0.1 DESTINATION bin)
 install (FILES luajit/bin/luajit DESTINATION bin)
 install (FILES luajit/bin/luajit DESTINATION bin)
-install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)
+install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)
+
+install (FILES luajit/lib/libluajit-5.1.so.2.0.1 
+			   luajit/lib/libluajit-5.1.so.2 DESTINATION test)
+
+install (PROGRAMS luajit/bin/luajit-2.0.1 DESTINATION test)
+install (FILES luajit/bin/luajit DESTINATION test)
+install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION test)