Просмотр исходного кода

Merge branch 'master' into bgfx

Conflicts:
	engine/Crown.h
	engine/device.cpp
	engine/os/android/android_device.cpp
	engine/os/android/os_window.cpp
	engine/os/linux/main.cpp
	engine/renderers/backend/command_buffer.h
	engine/renderers/backend/constant_buffer.h
	engine/renderers/backend/gl/egl/gl_context.cpp
	engine/renderers/backend/gl/egl/gl_context.h
	engine/renderers/backend/gl/gl_renderer.cpp
	engine/renderers/backend/gl/glx/gl_context.cpp
	engine/renderers/backend/gl/glx/gl_context.h
	engine/renderers/backend/gl/wgl/gl_context.cpp
	engine/renderers/backend/gl/wgl/gl_context.h
	engine/renderers/backend/pixel_format.h
	engine/renderers/backend/render_context.h
	engine/renderers/backend/renderer.h
	engine/renderers/backend/renderer_types.h
	engine/renderers/backend/vertex_format.h
	engine/renderers/debug_line.cpp
	engine/renderers/gui.cpp
	engine/renderers/material.cpp
	engine/renderers/material.h
	engine/renderers/mesh.h
	engine/renderers/render_world.cpp
	engine/renderers/render_world.h
	engine/renderers/sprite.cpp
	engine/renderers/sprite.h
	engine/resource/material_resource.cpp
	engine/resource/material_resource.h
	engine/resource/mesh_resource.h
	engine/resource/sprite_resource.cpp
	engine/resource/sprite_resource.h
	engine/resource/texture_resource.cpp
	engine/resource/texture_resource.h
	premake/premake4.lua
Daniele Bartolini 11 лет назад
Родитель
Сommit
2bd3c8df3e
100 измененных файлов с 1933 добавлено и 848 удалено
  1. 3 3
      Doxyfile.doxygen
  2. 0 129
      engine/Crown.h
  3. 10 10
      engine/audio/backend/al_sound_world.cpp
  4. 14 14
      engine/audio/backend/sles_sound_world.cpp
  5. 2 2
      engine/audio/sound_world.h
  6. 11 15
      engine/compilers/bundle_compiler.cpp
  7. 3 3
      engine/compilers/bundle_compiler.h
  8. 5 5
      engine/config.h
  9. 14 14
      engine/console_server.cpp
  10. 7 7
      engine/console_server.h
  11. 3 3
      engine/core/args.h
  12. 2 2
      engine/core/assert.h
  13. 0 64
      engine/core/compressors/Compressor.h
  14. 0 60
      engine/core/compressors/ZipCompressor.cpp
  15. 0 49
      engine/core/compressors/ZipCompressor.h
  16. 3 3
      engine/core/containers/array.h
  17. 2 2
      engine/core/containers/blob.h
  18. 4 4
      engine/core/containers/container_types.h
  19. 2 2
      engine/core/containers/dynamic_blob.h
  20. 4 4
      engine/core/containers/event_stream.h
  21. 5 5
      engine/core/containers/hash.h
  22. 3 3
      engine/core/containers/id_array.h
  23. 3 3
      engine/core/containers/id_table.h
  24. 4 4
      engine/core/containers/map.h
  25. 2 2
      engine/core/containers/priority_queue.h
  26. 5 5
      engine/core/containers/queue.h
  27. 1 1
      engine/core/containers/sort_map.h
  28. 3 3
      engine/core/containers/vector.h
  29. 7 8
      engine/core/error.h
  30. 0 65
      engine/core/filesystem/File.cpp
  31. 7 7
      engine/core/filesystem/disk_file.cpp
  32. 17 17
      engine/core/filesystem/disk_file.h
  33. 20 8
      engine/core/filesystem/disk_filesystem.cpp
  34. 5 2
      engine/core/filesystem/disk_filesystem.h
  35. 3 9
      engine/core/filesystem/file.h
  36. 6 3
      engine/core/filesystem/filesystem.h
  37. 0 0
      engine/core/filesystem/filesystem_types.h
  38. 11 11
      engine/core/filesystem/network_file.cpp
  39. 18 18
      engine/core/filesystem/network_file.h
  40. 13 7
      engine/core/filesystem/network_filesystem.cpp
  41. 7 4
      engine/core/filesystem/network_filesystem.h
  42. 10 10
      engine/core/filesystem/null_file.h
  43. 2 2
      engine/core/filesystem/reader_writer.h
  44. 0 0
      engine/core/functional.h
  45. 6 6
      engine/core/json/json.cpp
  46. 5 5
      engine/core/json/json.h
  47. 13 13
      engine/core/json/json_parser.cpp
  48. 5 5
      engine/core/json/json_parser.h
  49. 2 2
      engine/core/log.h
  50. 0 0
      engine/core/macros.h
  51. 7 7
      engine/core/math/aabb.h
  52. 1 1
      engine/core/math/color4.cpp
  53. 8 8
      engine/core/math/color4.h
  54. 5 5
      engine/core/math/frustum.h
  55. 7 7
      engine/core/math/intersection.h
  56. 2 2
      engine/core/math/math_types.h
  57. 7 7
      engine/core/math/math_utils.h
  58. 13 13
      engine/core/math/matrix3x3.h
  59. 22 22
      engine/core/math/matrix4x4.h
  60. 4 4
      engine/core/math/plane.h
  61. 11 11
      engine/core/math/quaternion.h
  62. 0 0
      engine/core/math/random.h
  63. 2 2
      engine/core/math/ray.h
  64. 9 9
      engine/core/math/sphere.h
  65. 5 5
      engine/core/math/vector2.h
  66. 6 6
      engine/core/math/vector3.h
  67. 6 6
      engine/core/math/vector4.h
  68. 1 1
      engine/core/mem/allocator.h
  69. 2 2
      engine/core/mem/linear_allocator.cpp
  70. 1 1
      engine/core/mem/linear_allocator.h
  71. 3 3
      engine/core/mem/memory.cpp
  72. 6 6
      engine/core/mem/memory.h
  73. 0 0
      engine/core/mem/memory_types.h
  74. 2 2
      engine/core/mem/pool_allocator.cpp
  75. 1 1
      engine/core/mem/pool_allocator.h
  76. 4 4
      engine/core/mem/proxy_allocator.cpp
  77. 2 2
      engine/core/mem/proxy_allocator.h
  78. 2 2
      engine/core/mem/stack_allocator.cpp
  79. 1 1
      engine/core/mem/stack_allocator.h
  80. 2 2
      engine/core/mem/temp_allocator.h
  81. 24 13
      engine/core/network/net_address.h
  82. 500 0
      engine/core/network/socket.h
  83. 467 0
      engine/core/os.h
  84. 6 6
      engine/core/profiler.h
  85. 2 2
      engine/core/settings/float_setting.cpp
  86. 1 1
      engine/core/settings/float_setting.h
  87. 2 2
      engine/core/settings/int_setting.cpp
  88. 1 1
      engine/core/settings/int_setting.h
  89. 3 3
      engine/core/settings/string_setting.cpp
  90. 2 2
      engine/core/settings/string_setting.h
  91. 6 6
      engine/core/strings/dynamic_string.h
  92. 10 10
      engine/core/strings/path.cpp
  93. 2 2
      engine/core/strings/path.h
  94. 3 3
      engine/core/strings/string_stream.h
  95. 27 29
      engine/core/strings/string_utils.h
  96. 18 2
      engine/core/thread/atomic_int.h
  97. 143 0
      engine/core/thread/mutex.h
  98. 129 0
      engine/core/thread/semaphore.h
  99. 172 0
      engine/core/thread/thread.h
  100. 1 1
      engine/core/types.h

+ 3 - 3
Doxyfile.in → Doxyfile.doxygen

@@ -38,7 +38,7 @@ PROJECT_NAME           = Crown
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER         = @CROWN_VERSION_MAJOR@.@CROWN_VERSION_MINOR@.@CROWN_VERSION_MICRO@
+PROJECT_NUMBER         = 0.1.13
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
@@ -58,7 +58,7 @@ PROJECT_LOGO           =
 # entered, it will be relative to the location where doxygen was started. If
 # left blank the current directory will be used.
 
-OUTPUT_DIRECTORY       = @CMAKE_CURRENT_BINARY_DIR@/documentation
+OUTPUT_DIRECTORY       = .build/documentation
 
 # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub-
 # directories (in 2 levels) under the output directory of each output format and
@@ -753,7 +753,7 @@ WARN_LOGFILE           =
 # spaces.
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = @CMAKE_CURRENT_SOURCE_DIR@/engine
+INPUT                  = engine
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

+ 0 - 129
engine/Crown.h

@@ -1,129 +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
-
-// Core
-#include "Assert.h"
-#include "Types.h"
-#include "Args.h"
-#include "Log.h"
-
-// Core/Math
-#include "AABB.h"
-#include "Color4.h"
-#include "Frustum.h"
-#include "Intersection.h"
-#include "MathUtils.h"
-#include "Matrix3x3.h"
-#include "Matrix4x4.h"
-#include "Plane.h"
-#include "Quaternion.h"
-#include "Random.h"
-#include "Ray.h"
-#include "Sphere.h"
-#include "Vector2.h"
-#include "Vector3.h"
-#include "Vector4.h"
-
-// Core/Containers
-#include "ContainerTypes.h"
-#include "EventStream.h"
-#include "Hash.h"
-#include "IdArray.h"
-#include "IdTable.h"
-#include "Map.h"
-#include "PriorityQueue.h"
-#include "Queue.h"
-#include "Vector.h"
-
-// Core/Strings
-#include "StringUtils.h"
-#include "StringStream.h"
-#include "StringUtils.h"
-#include "Path.h"
-
-// Core/Mem
-#include "Memory.h"
-#include "Allocator.h"
-#include "TempAllocator.h"
-#include "LinearAllocator.h"
-#include "StackAllocator.h"
-#include "ProxyAllocator.h"
-#include "PoolAllocator.h"
-
-// Core/Filesystem
-#include "DiskFile.h"
-#include "File.h"
-#include "Filesystem.h"
-#include "NullFile.h"
-#include "ReaderWriter.h"
-
-// Core/Json
-#include "JSON.h"
-#include "JSONParser.h"
-
-// Core/Settings
-#include "IntSetting.h"
-#include "FloatSetting.h"
-#include "StringSetting.h"
-
-// Engine
-#include "Camera.h"
-#include "Device.h"
-#include "ConsoleServer.h"
-
-// Engine/Input
-#include "Keyboard.h"
-#include "KeyCode.h"
-#include "Mouse.h"
-#include "Touch.h"
-
-// Engine/Lua
-#include "LuaStack.h"
-#include "LuaEnvironment.h"
-
-// Engine/Os
-#include "OsThread.h"
-#include "Mutex.h"
-#include "ScopedMutex.h"
-#include "Cond.h"
-#include "OsFile.h"
-#include "OsWindow.h"
-#include "OsSocket.h"
-
-// Engine/Resource
-#include "Bundle.h"
-#include "ResourceLoader.h"
-#include "ResourceManager.h"
-#include "TextureResource.h"
-#include "MeshResource.h"
-#include "SoundResource.h"
-#include "MaterialResource.h"
-#include "FontResource.h"
-
-// Engine/Audio
-#include "SoundWorld.h"

+ 10 - 10
engine/audio/backend/ALSoundWorld.cpp → engine/audio/backend/al_sound_world.cpp

@@ -27,16 +27,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <AL/al.h>
 #include <AL/alc.h>
 
-#include "SoundWorld.h"
-#include "IdArray.h"
-#include "Allocator.h"
-#include "Vector3.h"
-#include "Matrix4x4.h"
-#include "Resource.h"
-#include "SoundResource.h"
-#include "ContainerTypes.h"
-#include "TempAllocator.h"
-#include "Log.h"
+#include "sound_world.h"
+#include "id_array.h"
+#include "allocator.h"
+#include "vector3.h"
+#include "matrix4x4.h"
+#include "resource.h"
+#include "sound_resource.h"
+#include "container_types.h"
+#include "temp_allocator.h"
+#include "log.h"
 
 namespace crown
 {

+ 14 - 14
engine/audio/backend/SLESSoundWorld.cpp → engine/audio/backend/sles_sound_world.cpp

@@ -27,16 +27,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <SLES/OpenSLES.h>
 #include <SLES/OpenSLES_Android.h>
 
-#include "SoundWorld.h"
-#include "IdArray.h"
-#include "Allocator.h"
-#include "Vector3.h"
-#include "Matrix4x4.h"
-#include "Resource.h"
-#include "SoundResource.h"
-#include "ContainerTypes.h"
-#include "TempAllocator.h"
-#include "Queue.h"
+#include "sound_world.h"
+#include "id_array.h"
+#include "allocator.h"
+#include "vector3.h"
+#include "matrix4x4.h"
+#include "resource.h"
+#include "sound_resource.h"
+#include "container_types.h"
+#include "temp_allocator.h"
+#include "queue.h"
 
 namespace crown
 {
@@ -93,7 +93,7 @@ namespace audio_system
 		const SLInterfaceID ids1[] = {SL_IID_VOLUME};
 		const SLboolean reqs1[] = {SL_BOOLEAN_FALSE};
 
-		SL_CHECK((*s_sl_engine_itf)->CreateOutputMix(s_sl_engine_itf, &s_sl_output_mix, 1, ids1, reqs1)); 
+		SL_CHECK((*s_sl_engine_itf)->CreateOutputMix(s_sl_engine_itf, &s_sl_output_mix, 1, ids1, reqs1));
 		SL_CHECK((*s_sl_output_mix)->Realize(s_sl_output_mix, SL_BOOLEAN_FALSE));
 	}
 
@@ -196,7 +196,7 @@ struct SoundInstance
 			case 96000: format_pcm.samplesPerSec = SL_SAMPLINGRATE_96; break;
 			case 192000: format_pcm.samplesPerSec = SL_SAMPLINGRATE_192; break;
 			default: CE_FATAL("Oops, sample rate not supported"); break;
-		}	
+		}
 
 		format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
 		format_pcm.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
@@ -287,7 +287,7 @@ struct SoundInstance
 	{
 		SLuint32 state;
 		SL_CHECK((*play_itf())->GetPlayState(play_itf(), &state));
-		return state == SL_PLAYSTATE_PLAYING;	
+		return state == SL_PLAYSTATE_PLAYING;
 	}
 
 	bool finished()
@@ -326,7 +326,7 @@ struct SoundInstance
 		// 	{
 		// 		s->m_decoder.rewind();
 		// 		s->m_decoder.stream();
-		// 		(*s->m_player_bufferqueue)->Enqueue(s->m_player_bufferqueue, s->m_decoder.data(), s->m_decoder.size());	
+		// 		(*s->m_player_bufferqueue)->Enqueue(s->m_player_bufferqueue, s->m_decoder.data(), s->m_decoder.size());
 		// 	}
 		// 	else
 		// 	{

+ 2 - 2
engine/audio/SoundWorld.h → engine/audio/sound_world.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {
@@ -101,4 +101,4 @@ public:
 	static void destroy(Allocator& a, SoundWorld* sw);
 };
 
-} // namespace crown 
+} // namespace crown

+ 11 - 15
engine/compilers/BundleCompiler.cpp → engine/compilers/bundle_compiler.cpp

@@ -24,16 +24,16 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "BundleCompiler.h"
-#include "Vector.h"
-#include "DynamicString.h"
-#include "Allocator.h"
-#include "OS.h"
-#include "Log.h"
-#include "Resource.h"
-#include "Path.h"
-#include "DiskFilesystem.h"
-#include "TempAllocator.h"
+#include "bundle_compiler.h"
+#include "vector.h"
+#include "dynamic_string.h"
+#include "allocator.h"
+#include "os.h"
+#include "log.h"
+#include "resource.h"
+#include "path.h"
+#include "disk_filesystem.h"
+#include "temp_allocator.h"
 #include <inttypes.h>
 
 namespace crown
@@ -66,12 +66,8 @@ bool BundleCompiler::compile(const char* bundle_dir, const char* source_dir, con
 	{
 		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);
-		}
+		temp.create_directory(bundle_dir);
 
 		// Copy crown.config to bundle dir
 		DiskFilesystem src_fs(source_dir);

+ 3 - 3
engine/compilers/BundleCompiler.h → engine/compilers/bundle_compiler.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "DiskFilesystem.h"
-#include "DynamicString.h"
-#include "Vector.h"
+#include "disk_filesystem.h"
+#include "dynamic_string.h"
+#include "vector.h"
 
 namespace crown
 {

+ 5 - 5
engine/Config.h → engine/config.h

@@ -75,8 +75,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 // http://msdn.microsoft.com/en-us/library/6sehtctf.aspx
 	#if !defined(WINVER) && !defined(_WIN32_WINNT)
 // Windows Server 2003 with SP1, Windows XP with SP2 and above
-		#define WINVER 0x0600
-		#define _WIN32_WINNT 0x0600
+		#define WINVER 0x0502
+		#define _WIN32_WINNT 0x0502
 	#endif // !defined(WINVER) && !defined(_WIN32_WINNT)
 	#define CROWN_PLATFORM_WINDOWS 1
 #elif defined(__ANDROID__)
@@ -99,7 +99,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #define CROWN_PLATFORM_POSIX (CROWN_PLATFORM_ANDROID \
 						|| CROWN_PLATFORM_IOS \
 						|| CROWN_PLATFORM_LINUX \
-						|| CROWN_PLATFORM_OSX \
+						|| CROWN_PLATFORM_OSX)
 
 // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures
 #if defined(__arm__)
@@ -122,7 +122,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 	#undef CROWN_CPU_JIT
 	#define CROWN_CPU_JIT 1
 	#define CROWN_CACHE_LINE_SIZE 64
-#endif // 
+#endif //
 
 #if defined(__x86_64__) || defined(_M_X64) || defined(__64BIT__) || defined(__powerpc64__) || defined(__ppc64__)
 	#undef CROWN_ARCH_64BIT
@@ -205,7 +205,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #define CE_MAX_MESH_COMPONENTS				16					// Per unit
 #define CE_MAX_SPRITE_COMPONENTS			16					// Per unit
 #define CE_MAX_ACTOR_COMPONENTS				16					// Per unit
-#define CE_MAX_MATERIAL_COMPONENTS			16					// Per unit				
+#define CE_MAX_MATERIAL_COMPONENTS			16					// Per unit
 
 #define CE_MAX_CONSOLE_CLIENTS				32
 

+ 14 - 14
engine/ConsoleServer.cpp → engine/console_server.cpp

@@ -24,18 +24,18 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "ConsoleServer.h"
-#include "JSONParser.h"
-#include "TempAllocator.h"
-#include "StringStream.h"
-#include "Log.h"
-#include "Device.h"
-#include "ProxyAllocator.h"
-#include "LuaEnvironment.h"
-#include "File.h"
-#include "Filesystem.h"
-#include "MathUtils.h"
-#include "Memory.h"
+#include "console_server.h"
+#include "json_parser.h"
+#include "temp_allocator.h"
+#include "string_stream.h"
+#include "log.h"
+#include "device.h"
+#include "proxy_allocator.h"
+#include "lua_environment.h"
+#include "file.h"
+#include "filesystem.h"
+#include "math_utils.h"
+#include "memory.h"
 
 namespace crown
 {
@@ -43,7 +43,7 @@ namespace crown
 //-----------------------------------------------------------------------------
 void ConsoleServer::init(uint16_t port, bool wait)
 {
-	m_server.open(port);
+	m_server.bind(port);
 	m_server.listen(5);
 
 	if (wait)
@@ -209,7 +209,7 @@ ReadResult ConsoleServer::update_client(TCPSocket client)
 void ConsoleServer::process(TCPSocket client, const char* request)
 {
 	JSONParser parser(request);
-	DynamicString type; 
+	DynamicString type;
 	parser.root().key("type").to_string(type);
 
 	// Determine request type

+ 7 - 7
engine/ConsoleServer.h → engine/console_server.h

@@ -26,11 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "OsSocket.h"
-#include "ContainerTypes.h"
-#include "Queue.h"
-#include "IdArray.h"
-#include "Config.h"
+#include "socket.h"
+#include "container_types.h"
+#include "queue.h"
+#include "id_array.h"
+#include "config.h"
 
 namespace crown
 {
@@ -44,7 +44,7 @@ struct LogSeverity
 		WARN	= 1,
 		ERROR	= 2,
 		DEBUG	= 3
-	};	
+	};
 };
 
 struct Client
@@ -92,7 +92,7 @@ private:
 
 private:
 
-	TCPServer m_server;
+	TCPSocket m_server;
 	ClientArray m_clients;
 };
 

+ 3 - 3
engine/core/Args.h → engine/core/args.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Types.h"
-#include "StringUtils.h"
+#include "assert.h"
+#include "types.h"
+#include "string_utils.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/Assert.h → engine/core/assert.h

@@ -28,8 +28,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include <cstdlib>
 #include <cstdio>
-#include "Config.h"
-#include "Error.h"
+#include "config.h"
+#include "error.h"
 
 #if defined(CROWN_DEBUG)
 	#define CE_ASSERT(condition, msg, ...) do { if (!(condition)) {\

+ 0 - 64
engine/core/compressors/Compressor.h

@@ -1,64 +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 "Allocator.h"
-
-namespace crown
-{
-
-class Compressor
-{
-public:
-						Compressor(Allocator& allocator);
-	virtual 			~Compressor() {}
-
-	/// Compresses the data pointed by @a data of size @a in_size (in bytes) and returns it.
-	/// The function also returns the size in bytes of the compressed data in @a out_size.
-	/// @note
-	/// The returned data is automatically allocated using the passed allocator.
-	virtual uint8_t* 	compress(const void* data, size_t in_size, size_t& out_size) = 0;
-
-	/// Uncompresses the data pointed by @a data of size @a in_size (in bytes) and returns it.
-	/// The function also returns the size in bytes of the uncompressed data in @a out_size.
-	/// @note
-	/// The returned data is automatically allocated using the passed allocator.
-	virtual uint8_t* 	uncompress(const void* data, size_t in_size, size_t& out_size) = 0;
-
-protected:
-	
-	Allocator& 			m_allocator;
-};
-
-//-----------------------------------------------------------------------------
-inline Compressor::Compressor(Allocator& allocator) :
-	m_allocator(allocator)
-{
-}
-
-} // namespace crown

+ 0 - 60
engine/core/compressors/ZipCompressor.cpp

@@ -1,60 +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 <cstring>
-
-//#include "zlib.h"
-#include "Assert.h"
-#include "ZipCompressor.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-ZipCompressor::ZipCompressor(Allocator& allocator) :
-	Compressor(allocator)
-{
-}
-
-//-----------------------------------------------------------------------------
-ZipCompressor::~ZipCompressor()
-{
-}
-
-//-----------------------------------------------------------------------------
-uint8_t* ZipCompressor::compress(const void* /*data*/, size_t /*in_size*/, size_t& /*out_size*/)
-{
-	return NULL;
-}
-
-//-----------------------------------------------------------------------------
-uint8_t* ZipCompressor::uncompress(const void* /*data*/, size_t /*in_size*/, size_t& /*out_size*/)
-{
-	return NULL;
-}
-
-} // namespace crown
-

+ 0 - 49
engine/core/compressors/ZipCompressor.h

@@ -1,49 +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 "Compressor.h"
-
-namespace crown
-{
-
-/// Generic data compressor which uses zlib.
-class ZipCompressor : public Compressor
-{
-public:
-
-				ZipCompressor(Allocator& allocator);
-				~ZipCompressor();
-	
-	/// @copydoc Compressor::compress()
-	uint8_t* 	compress(const void* data, size_t in_size, size_t& out_size);
-
-	/// @copydoc Compressor::uncompress()
-	uint8_t* 	uncompress(const void* data, size_t in_size, size_t& out_size);
-};
-
-} // namespace crown

+ 3 - 3
engine/core/containers/Array.h → engine/core/containers/array.h

@@ -27,9 +27,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include <cstring>
-#include "Assert.h"
-#include "ContainerTypes.h"
-#include "Allocator.h"
+#include "assert.h"
+#include "container_types.h"
+#include "allocator.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/containers/Blob.h → engine/core/containers/blob.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "Assert.h"
+#include "types.h"
+#include "assert.h"
 
 namespace crown
 {

+ 4 - 4
engine/core/containers/ContainerTypes.h → engine/core/containers/container_types.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "MemoryTypes.h"
-#include "Functional.h"
+#include "types.h"
+#include "memory_types.h"
+#include "functional.h"
 
 namespace crown
 {
@@ -125,7 +125,7 @@ template<typename T>
 struct Hash
 {
 	Hash(Allocator &a);
-	
+
 	struct Entry
 	{
 		uint64_t key;

+ 2 - 2
engine/core/containers/DynamicBlob.h → engine/core/containers/dynamic_blob.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Allocator.h"
-#include "Array.h"
+#include "allocator.h"
+#include "array.h"
 
 namespace crown
 {

+ 4 - 4
engine/core/containers/EventStream.h → engine/core/containers/event_stream.h

@@ -26,14 +26,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Array.h"
+#include "assert.h"
+#include "array.h"
 
 namespace crown
 {
 
 /// Array of generic event structs.
-/// 
+///
 /// @ingroup Containers
 typedef Array<char> EventStream;
 
@@ -51,7 +51,7 @@ namespace event_stream
 		uint32_t size;
 	};
 
-	/// Appends the @a event of the given @a type and @a size to the stream @a s. 
+	/// Appends the @a event of the given @a type and @a size to the stream @a s.
 	inline void write(EventStream& s, uint32_t type, uint32_t size, const void* event)
 	{
 		Header header;

+ 5 - 5
engine/core/containers/Hash.h → engine/core/containers/hash.h

@@ -25,13 +25,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Array.h"
-#include "ContainerTypes.h"
+#include "array.h"
+#include "container_types.h"
 
 namespace crown {
 
 	/// The hash function stores its data in a "list-in-an-array" where
-	/// indices are used instead of pointers. 
+	/// indices are used instead of pointers.
 	///
 	/// When items are removed, the array-list is repacked to always keep
 	/// it tightly ordered.
@@ -96,7 +96,7 @@ namespace crown {
 	namespace hash_internal
 	{
 		const uint32_t END_OF_LIST = 0xffffffffu;
-		
+
 		struct FindResult
 		{
 			uint32_t hash_i;
@@ -208,7 +208,7 @@ namespace crown {
 
 			h._data[i].next = fr.data_i;
 			return i;
-		}	
+		}
 
 		template<typename T> void find_and_erase(Hash<T> &h, uint64_t key)
 		{

+ 3 - 3
engine/core/containers/IdArray.h → engine/core/containers/id_array.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Types.h"
-#include "ContainerTypes.h"
+#include "assert.h"
+#include "types.h"
+#include "container_types.h"
 
 namespace crown
 {

+ 3 - 3
engine/core/containers/IdTable.h → engine/core/containers/id_table.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Allocator.h"
-#include "Types.h"
+#include "assert.h"
+#include "allocator.h"
+#include "types.h"
 
 namespace crown
 {

+ 4 - 4
engine/core/containers/Map.h → engine/core/containers/map.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "ContainerTypes.h"
-#include "Vector.h"
+#include "container_types.h"
+#include "vector.h"
 
 // #define RBTREE_VERIFY
 
@@ -83,14 +83,14 @@ namespace map_internal
 		CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
 		return m.m_data[n].parent;
 	}
-	
+
 	template <typename TKey, typename TValue>
 	inline uint32_t left(const Map<TKey, TValue>& m, uint32_t n)
 	{
 		CE_ASSERT(n < vector::size(m.m_data), "Index out of bounds (size = %d, n = %d)", vector::size(m.m_data), n);
 		return m.m_data[n].left;
 	}
-	
+
 	template <typename TKey, typename TValue>
 	inline uint32_t right(const Map<TKey, TValue>& m, uint32_t n)
 	{

+ 2 - 2
engine/core/containers/PriorityQueue.h → engine/core/containers/priority_queue.h

@@ -27,8 +27,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include <algorithm>
-#include "ContainerTypes.h"
-#include "Array.h"
+#include "container_types.h"
+#include "array.h"
 
 namespace crown
 {

+ 5 - 5
engine/core/containers/Queue.h → engine/core/containers/queue.h

@@ -27,9 +27,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include <cstring>
-#include "ContainerTypes.h"
-#include "Array.h"
-#include "Assert.h"
+#include "container_types.h"
+#include "array.h"
+#include "assert.h"
 
 namespace crown
 {
@@ -58,7 +58,7 @@ namespace queue
 
 	/// Grows the queue to contain at least @a min_capacity items.
 	/// If @a min_capacity is set to 0, the queue automatically
-	/// determines the new capacity based on its size at the 
+	/// determines the new capacity based on its size at the
 	/// time of call.
 	template<typename T> void grow(Queue<T>& q, uint32_t min_capacity);
 
@@ -205,7 +205,7 @@ namespace queue
 	{
 		if (q.space() < n)
 		{
-			q.grow(q.size() + n);		
+			q.grow(q.size() + n);
 		}
 
 		const uint32_t size = array::size(q.m_queue);

+ 1 - 1
engine/core/containers/SortMap.h → engine/core/containers/sort_map.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Array.h"
+#include "array.h"
 #include <algorithm>
 
 namespace crown

+ 3 - 3
engine/core/containers/Vector.h → engine/core/containers/vector.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "Assert.h"
-#include "Array.h"
+#include "types.h"
+#include "assert.h"
+#include "array.h"
 
 namespace crown
 {

+ 7 - 8
engine/core/Error.h → engine/core/error.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Config.h"
-#include "Types.h"
-#include "Macros.h"
+#include "config.h"
+#include "types.h"
+#include "macros.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -46,6 +46,7 @@ namespace error
 inline void log_backtrace()
 {
 	#if CROWN_PLATFORM_LINUX && CROWN_COMPILER_GCC
+	printf("Backtrace:\n");
 	void* array[50];
 	int size = backtrace(array, 50);
 
@@ -59,11 +60,11 @@ inline void log_backtrace()
 		// find parantheses and +address offset surrounding mangled name
 		for (char *p = messages[i]; *p; ++p)
 		{
-			if (*p == '(') 
+			if (*p == '(')
 			{
-				mangled_name = p; 
+				mangled_name = p;
 			}
-			else if (*p == '+') 
+			else if (*p == '+')
 			{
 				offset_begin = p;
 			}
@@ -106,8 +107,6 @@ inline void abort(const char* file, int line, const char* message, ...)
 	vprintf(message, ap);
 	va_end(ap);
 	printf("\tIn: %s:%d\n", file, line);
-	printf("Backtrace:\n");
-	//fflush(0);
 	log_backtrace();
 	exit(EXIT_FAILURE);
 }

+ 0 - 65
engine/core/filesystem/File.cpp

@@ -1,65 +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 "File.h"
-#include "Types.h"
-#include "Compressor.h"
-#include "Memory.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-bool File::compress_to(File& file, size_t size, size_t& zipped_size, Compressor& compressor)
-{
-	void* in_buffer = (void*) default_allocator().allocate(size);
-
-	read(in_buffer, size);
-
-	void* compressed_buffer = compressor.compress(in_buffer, size, zipped_size);
-
-	file.write(compressed_buffer, zipped_size);
-
-	return true;
-}
-
-//-----------------------------------------------------------------------------
-bool File::uncompress_to(File& file, size_t& unzipped_size, Compressor& compressor)
-{
-	size_t file_size = size();
-	void* in_buffer = (void*) default_allocator().allocate(file_size);
-
-	read(in_buffer, file_size);
-
-	void* uncompressed_buffer = compressor.uncompress(in_buffer, file_size, unzipped_size);
-
-	file.write(uncompressed_buffer, unzipped_size);
-
-	return true;
-}
-
-} // namespace crown
-

+ 7 - 7
engine/core/filesystem/DiskFile.cpp → engine/core/filesystem/disk_file.cpp

@@ -24,11 +24,11 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "DiskFile.h"
-#include "Types.h"
-#include "Log.h"
-#include "MathUtils.h"
-#include "Memory.h"
+#include "disk_file.h"
+#include "types.h"
+#include "log.h"
+#include "math_utils.h"
+#include "memory.h"
 
 namespace crown
 {
@@ -158,7 +158,7 @@ bool DiskFile::is_valid()
 void DiskFile::flush()
 {
 	check_valid();
-	
+
 	// FIXME implement flush in File
 }
 
@@ -174,7 +174,7 @@ size_t DiskFile::position()
 size_t DiskFile::size()
 {
 	check_valid();
-	
+
 	return m_file.size();
 }
 

+ 17 - 17
engine/core/filesystem/DiskFile.h → engine/core/filesystem/disk_file.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "OsFile.h"
-#include "File.h"
+#include "assert.h"
+#include "os_file.h"
+#include "file.h"
 
 namespace crown
 {
@@ -44,46 +44,46 @@ public:
 	DiskFile(FileOpenMode mode, const char* filename);
 	virtual ~DiskFile();
 
-	/// @copydoc File::seek() 
+	/// @copydoc File::seek()
 	void seek(size_t position);
 
-	/// @copydoc File::seek_to_end() 
+	/// @copydoc File::seek_to_end()
 	void seek_to_end();
 
-	/// @copydoc File::skip() 
+	/// @copydoc File::skip()
 	void skip(size_t bytes);
 
-	/// @copydoc File::read() 
+	/// @copydoc File::read()
 	void read(void* buffer, size_t size);
 
-	/// @copydoc File::write() 
+	/// @copydoc File::write()
 	void write(const void* buffer, size_t size);
 
-	/// @copydoc File::copy_to() 
+	/// @copydoc File::copy_to()
 	bool copy_to(File& file, size_t size = 0);
 
-	/// @copydoc File::flush() 
+	/// @copydoc File::flush()
 	void flush();
 
-	/// @copydoc File::end_of_file() 
+	/// @copydoc File::end_of_file()
 	bool end_of_file();
 
-	/// @copydoc File::is_valid() 
+	/// @copydoc File::is_valid()
 	bool is_valid();
 
-	/// @copydoc File::size() 
+	/// @copydoc File::size()
 	size_t size();
 
-	/// @copydoc File::position() 
+	/// @copydoc File::position()
 	size_t position();
 
-	/// @copydoc File::can_read() 
+	/// @copydoc File::can_read()
 	bool can_read() const;
 
-	/// @copydoc File::can_write() 
+	/// @copydoc File::can_write()
 	bool can_write() const;
 
-	/// @copydoc File::can_seek() 
+	/// @copydoc File::can_seek()
 	bool can_seek() const;
 
 protected:

+ 20 - 8
engine/core/filesystem/DiskFilesystem.cpp → engine/core/filesystem/disk_filesystem.cpp

@@ -24,11 +24,11 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "DiskFilesystem.h"
-#include "StringUtils.h"
-#include "TempAllocator.h"
-#include "DiskFile.h"
-#include "Vector.h"
+#include "disk_filesystem.h"
+#include "string_utils.h"
+#include "temp_allocator.h"
+#include "disk_file.h"
+#include "vector.h"
 
 namespace crown
 {
@@ -36,14 +36,13 @@ namespace crown
 //-----------------------------------------------------------------------------
 DiskFilesystem::DiskFilesystem()
 {
-	string::strncpy(m_root_path, os::get_cwd(), MAX_PATH_LENGTH);
+	os::getcwd(m_root_path, MAX_PATH_LENGTH);
 }
 
 //-----------------------------------------------------------------------------
 DiskFilesystem::DiskFilesystem(const char* root_path)
 {
 	CE_ASSERT_NOT_NULL(root_path);
-
 	string::strncpy(m_root_path, root_path, MAX_PATH_LENGTH);
 }
 
@@ -67,6 +66,18 @@ void DiskFilesystem::close(File* file)
 	CE_DELETE(default_allocator(), file);
 }
 
+//-----------------------------------------------------------------------------
+bool DiskFilesystem::exists(const char* path)
+{
+	CE_ASSERT_NOT_NULL(path);
+
+	TempAllocator256 alloc;
+	DynamicString abs_path(alloc);
+	get_absolute_path(path, abs_path);
+
+	return os::exists(abs_path.c_str());
+}
+
 //-----------------------------------------------------------------------------
 bool DiskFilesystem::is_directory(const char* path)
 {
@@ -100,7 +111,8 @@ void DiskFilesystem::create_directory(const char* path)
 	DynamicString abs_path(alloc);
 	get_absolute_path(path, abs_path);
 
-	os::create_directory(abs_path.c_str());
+	if (!os::exists(abs_path.c_str()))
+		os::create_directory(abs_path.c_str());
 }
 
 //-----------------------------------------------------------------------------

+ 5 - 2
engine/core/filesystem/DiskFilesystem.h → engine/core/filesystem/disk_filesystem.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Filesystem.h"
-#include "OS.h" // For MAX_PATH_LENGTH
+#include "filesystem.h"
+#include "os.h" // for max_path_length
 
 namespace crown
 {
@@ -59,6 +59,9 @@ public:
 	/// Closes the given @a file.
 	void close(File* file);
 
+	/// Returns whether @a path exists.
+	bool exists(const char* path);
+
 	/// Returns true if @a path is a directory.
 	bool is_directory(const char* path);
 

+ 3 - 9
engine/core/filesystem/File.h → engine/core/filesystem/file.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {
@@ -40,7 +40,7 @@ enum FileOpenMode
 class Compressor;
 
 /// An abstraction to access data files.
-/// 
+///
 /// It represents a flow of data attached to a 'file' which can be an archived file,
 /// a regular file, a location in memory or anything that can be read or wrote.
 /// A File is an abstraction to interact with these in an uniform way; every file
@@ -74,12 +74,6 @@ public:
 	/// Copies a chunk of 'size' bytes of data from this to another file.
 	virtual bool copy_to(File& file, size_t size = 0) = 0;
 
-	/// Zips a chunk of 'size' bytes of data from this to another file using compressor.
-	virtual bool compress_to(File& file, size_t size, size_t& compressed_size, Compressor& compressor);
-
-	/// Unzip a zipped file of data from this to another file using compressor.
-	virtual bool uncompress_to(File& file, size_t& uncompressed_size, Compressor& compressor);
-
 	/// Forces the previouses write operations to complete.
 	/// Generally, when a File is attached to a file,
 	/// write operations are not performed instantly, the output data
@@ -90,7 +84,7 @@ public:
 
 	/// Returns whether the file is valid.
 	/// A file is valid when the buffer where it operates
-	/// exists. (i.e. a file descriptor is attached to the file, 
+	/// exists. (i.e. a file descriptor is attached to the file,
 	/// a memory area is attached to the file etc.)
 	virtual bool is_valid() = 0;
 

+ 6 - 3
engine/core/filesystem/Filesystem.h → engine/core/filesystem/filesystem.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "File.h"
-#include "ContainerTypes.h"
-#include "DynamicString.h"
+#include "file.h"
+#include "container_types.h"
+#include "dynamic_string.h"
 
 namespace crown
 {
@@ -95,6 +95,9 @@ public:
 	/// Closes the given @a file.
 	virtual void close(File* file) = 0;
 
+	/// Returns whether @a path exists.
+	virtual bool exists(const char* path) = 0;
+
 	/// Returns true if @a path is a directory.
 	virtual bool is_directory(const char* path) = 0;
 

+ 0 - 0
engine/core/filesystem/FilesystemTypes.h → engine/core/filesystem/filesystem_types.h


+ 11 - 11
engine/core/filesystem/NetworkFile.cpp → engine/core/filesystem/network_file.cpp

@@ -24,17 +24,17 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "JSONParser.h"
-#include "ContainerTypes.h"
-#include "Log.h"
-#include "MathUtils.h"
-#include "NetworkFile.h"
-#include "NetworkFilesystem.h"
-#include "StringStream.h"
-#include "StringUtils.h"
-#include "TempAllocator.h"
-#include "Types.h"
-#include "DynamicString.h"
+#include "json_parser.h"
+#include "container_types.h"
+#include "log.h"
+#include "math_utils.h"
+#include "network_file.h"
+#include "network_filesystem.h"
+#include "string_stream.h"
+#include "string_utils.h"
+#include "temp_allocator.h"
+#include "types.h"
+#include "dynamic_string.h"
 
 namespace crown
 {

+ 18 - 18
engine/core/filesystem/NetworkFile.h → engine/core/filesystem/network_file.h

@@ -26,10 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "File.h"
-#include "OsSocket.h"
-#include "File.h"
+#include "assert.h"
+#include "socket.h"
+#include "os.h"
+#include "file.h"
 
 namespace crown
 {
@@ -45,46 +45,46 @@ public:
 	NetworkFile(const NetAddress& addr, uint16_t port, const char* filename);
 	virtual ~NetworkFile();
 
-	/// @copydoc File::seek() 
+	/// @copydoc File::seek()
 	void seek(size_t position);
 
-	/// @copydoc File::seek_to_end() 
+	/// @copydoc File::seek_to_end()
 	void seek_to_end();
 
-	/// @copydoc File::skip() 
+	/// @copydoc File::skip()
 	void skip(size_t bytes);
 
-	/// @copydoc File::read() 
+	/// @copydoc File::read()
 	void read(void* buffer, size_t size);
 
-	/// @copydoc File::write() 
+	/// @copydoc File::write()
 	void write(const void* buffer, size_t size);
 
-	/// @copydoc File::copy_to() 
+	/// @copydoc File::copy_to()
 	bool copy_to(File& file, size_t size = 0);
 
-	/// @copydoc File::flush() 
+	/// @copydoc File::flush()
 	void flush();
 
-	/// @copydoc File::end_of_file() 
+	/// @copydoc File::end_of_file()
 	bool end_of_file();
 
-	/// @copydoc File::is_valid() 
+	/// @copydoc File::is_valid()
 	bool is_valid();
 
-	/// @copydoc File::size() 
+	/// @copydoc File::size()
 	size_t size();
 
-	/// @copydoc File::position() 
+	/// @copydoc File::position()
 	size_t position();
 
-	/// @copydoc File::can_read() 
+	/// @copydoc File::can_read()
 	bool can_read() const;
 
-	/// @copydoc File::can_write() 
+	/// @copydoc File::can_write()
 	bool can_write() const;
 
-	/// @copydoc File::can_seek() 
+	/// @copydoc File::can_seek()
 	bool can_seek() const;
 
 private:

+ 13 - 7
engine/core/filesystem/NetworkFilesystem.cpp → engine/core/filesystem/network_filesystem.cpp

@@ -24,13 +24,13 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "JSONParser.h"
-#include "NetworkFile.h"
-#include "NetworkFilesystem.h"
-#include "OS.h"
-#include "StringUtils.h"
-#include "TempAllocator.h"
-#include "StringStream.h"
+#include "json_parser.h"
+#include "network_file.h"
+#include "network_filesystem.h"
+#include "os.h"
+#include "string_utils.h"
+#include "temp_allocator.h"
+#include "string_stream.h"
 
 namespace crown
 {
@@ -60,6 +60,12 @@ void NetworkFilesystem::close(File* file)
 	CE_DELETE(default_allocator(), file);
 }
 
+//-----------------------------------------------------------------------------
+bool NetworkFilesystem::exists(const char* path)
+{
+	return false;
+}
+
 //-----------------------------------------------------------------------------
 bool NetworkFilesystem::is_directory(const char* path)
 {

+ 7 - 4
engine/core/filesystem/NetworkFilesystem.h → engine/core/filesystem/network_filesystem.h

@@ -26,10 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Filesystem.h"
-#include "OsSocket.h"
-#include "OS.h" // For MAX_PATH_LENGTH
-#include "Log.h"
+#include "filesystem.h"
+#include "socket.h"
+#include "os.h" // for max_path_length
+#include "log.h"
 
 namespace crown
 {
@@ -83,6 +83,9 @@ public:
 	/// Closes the given @a file.
 	void close(File* file);
 
+	/// Returns whether @a path exists.
+	bool exists(const char* path);
+
 	/// Returns true if @a path is a directory.
 	bool is_directory(const char* path);
 

+ 10 - 10
engine/core/filesystem/NullFile.h → engine/core/filesystem/null_file.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "File.h"
+#include "file.h"
 
 namespace crown
 {
@@ -54,7 +54,7 @@ public:
 
 	/// @copydoc File::skip()
 	void		skip(size_t bytes) { (void)bytes; }
-				
+
 	/// @copydoc File::read()
 	/// @note
 	///	Fills buffer with zeroes
@@ -75,43 +75,43 @@ public:
 	bool		copy_to(File& file, size_t size = 0)
 	{
 		char zero = 0;
-		file.write(&zero, size);		
+		file.write(&zero, size);
 		return true;
 	}
 
 	/// @copydoc File::flush()
 	void		flush() {};
-				
+
 	/// @copydoc File::is_valid()
 	/// @note
 	///	Returns always true
 	bool		is_valid() { return true; }
-				
+
 	/// @copydoc File::end_of_file()
 	/// @note
 	///	Returns always false
 	bool		end_of_file() { return false; }
-				
+
 	/// @copydoc File::size()
 	/// @note
 	///	Returns always 0xFFFFFFFF
 	size_t		size() { return ~0; }
-				
+
 	/// @copydoc File::position()
 	/// @note
 	///	Returns always zero
 	size_t		position() { return 0; }
-				
+
 	/// @copydoc File::can_read()
 	/// @note
 	///	Returns always true
 	bool		can_read() { return true; }
-				
+
 	/// @copydoc File::can_write()
 	/// @note
 	///	Returns always true
 	bool		can_write() { return true; }
-				
+
 	/// @copydoc File::can_seek()
 	/// @note
 	///	Returns always true

+ 2 - 2
engine/core/filesystem/ReaderWriter.h → engine/core/filesystem/reader_writer.h

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Types.h"
-#include "File.h"
+#include "types.h"
+#include "file.h"
 
 namespace crown
 {

+ 0 - 0
engine/core/Functional.h → engine/core/functional.h


+ 6 - 6
engine/core/json/JSON.cpp → engine/core/json/json.cpp

@@ -24,11 +24,11 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "JSON.h"
-#include "ContainerTypes.h"
-#include "StringUtils.h"
-#include "DynamicString.h"
-#include "Map.h"
+#include "json.h"
+#include "container_types.h"
+#include "string_utils.h"
+#include "dynamic_string.h"
+#include "map.h"
 
 namespace crown
 {
@@ -362,7 +362,7 @@ namespace json
 				ch = next(ch, 'f');
 				ch = next(ch, 'a');
 				ch = next(ch, 'l');
-				ch = next(ch, 's');			
+				ch = next(ch, 's');
 				ch = next(ch, 'e');
 				return false;
 			}

+ 5 - 5
engine/core/json/JSON.h → engine/core/json/json.h

@@ -24,9 +24,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Types.h"
-#include "DynamicString.h"
-#include "ContainerTypes.h"
+#include "types.h"
+#include "dynamic_string.h"
+#include "container_types.h"
 
 #pragma once
 
@@ -56,13 +56,13 @@ struct JSONType
 /// @ingroup JSON
 namespace json
 {
-	/// Returns the data type of the JSON string @a s. 
+	/// Returns the data type of the JSON string @a s.
 	JSONType::Enum type(const char* s);
 
 	/// Parses the JSON string @a s ad puts it into @a str.
 	void parse_string(const char* s, DynamicString& str);
 
-	/// Returns the JSON number @a s as double. 
+	/// Returns the JSON number @a s as double.
 	double parse_number(const char* s);
 
 	/// Returns the JSON number @a s as int.

+ 13 - 13
engine/core/json/JSONParser.cpp → engine/core/json/json_parser.cpp

@@ -24,18 +24,18 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "JSONParser.h"
-#include "JSON.h"
-#include "TempAllocator.h"
-#include "StringUtils.h"
-#include "Vector.h"
-#include "Map.h"
-#include "Vector2.h"
-#include "Vector3.h"
-#include "Vector4.h"
-#include "Quaternion.h"
-#include "Matrix4x4.h"
-#include "File.h"
+#include "json_parser.h"
+#include "json.h"
+#include "temp_allocator.h"
+#include "string_utils.h"
+#include "vector.h"
+#include "map.h"
+#include "vector2.h"
+#include "vector3.h"
+#include "vector4.h"
+#include "quaternion.h"
+#include "matrix4x4.h"
+#include "file.h"
 
 namespace crown
 {
@@ -378,7 +378,7 @@ bool JSONElement::is_number() const
 {
 	if (m_at != NULL)
 	{
-		return json::type(m_at) == JSONType::NUMBER;		
+		return json::type(m_at) == JSONType::NUMBER;
 	}
 
 	return false;

+ 5 - 5
engine/core/json/JSONParser.h → engine/core/json/json_parser.h

@@ -26,11 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "ContainerTypes.h"
-#include "MathTypes.h"
-#include "Macros.h"
-#include "Resource.h"
+#include "types.h"
+#include "container_types.h"
+#include "math_types.h"
+#include "macros.h"
+#include "resource.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/Log.h → engine/core/log.h

@@ -27,8 +27,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #if defined(CROWN_DEBUG)
-	#include "Device.h"
-	#include "ConsoleServer.h"
+	#include "device.h"
+	#include "console_server.h"
 	#define CE_LOGI(msg, ...) crown::device()->console()->log_to_all(crown::LogSeverity::INFO, msg, ##__VA_ARGS__)
 	#define CE_LOGD(msg, ...) crown::device()->console()->log_to_all(crown::LogSeverity::DEBUG, msg, ##__VA_ARGS__)
 	#define CE_LOGE(msg, ...) crown::device()->console()->log_to_all(crown::LogSeverity::ERROR, msg, ##__VA_ARGS__)

+ 0 - 0
engine/core/Macros.h → engine/core/macros.h


+ 7 - 7
engine/core/math/AABB.h → engine/core/math/aabb.h

@@ -26,12 +26,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "MathTypes.h"
-#include "Matrix4x4.h"
-#include "Sphere.h"
-#include "Types.h"
-#include "Vector3.h"
+#include "assert.h"
+#include "math_types.h"
+#include "matrix4x4.h"
+#include "sphere.h"
+#include "types.h"
+#include "vector3.h"
 
 namespace crown
 {
@@ -62,7 +62,7 @@ namespace aabb
 	bool contains_point(const AABB& b, const Vector3& p);
 
 	/// Returns the @a index -th vertex of the box.
-	Vector3 vertex(const AABB& b, uint32_t index);		
+	Vector3 vertex(const AABB& b, uint32_t index);
 
 	/// Returns the box enclosing @a b transformed by @a m.
 	AABB transformed(const AABB& b, const Matrix4x4& m);

+ 1 - 1
engine/core/math/Color4.cpp → engine/core/math/color4.cpp

@@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Color4.h"
+#include "color4.h"
 
 namespace crown
 {

+ 8 - 8
engine/core/math/Color4.h → engine/core/math/color4.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "MathUtils.h"
+#include "types.h"
+#include "math_utils.h"
 
 namespace crown
 {
@@ -38,16 +38,16 @@ namespace crown
 struct Color4
 {
 	Color4();
-	Color4(float r, float g, float b);		
+	Color4(float r, float g, float b);
 	Color4(int r, int g, int b);
 	Color4(float r, float g, float b, float a);
-	Color4(int r, int g, int b, int a);		
+	Color4(int r, int g, int b, int a);
 	explicit Color4(float c[4]);
 
 	/// Construct from 32-bit integer (red at MSB, alpha at LSB)
 	explicit Color4(uint32_t rgba);
 
-	float& operator[](uint32_t i);				
+	float& operator[](uint32_t i);
 	const float& operator[](uint32_t i) const;
 
 	Color4& operator+=(const Color4& c);
@@ -244,7 +244,7 @@ inline Color4 operator*(float k, Color4 a)
 
 /// Functions to mamipulate Color4
 ///
-/// @ingroup Math 
+/// @ingroup Math
 namespace color4
 {
 	/// Returns the color as a packed 32-bit integer. (RGBA order, alpha assumed = 255)
@@ -253,7 +253,7 @@ namespace color4
 	/// Returns the color as a packed 32-bit integer. (ABGR order, alpha assumed = 255)
 	uint32_t to_bgr(const Color4& c);
 
-	/// Returns the color as a packed 32-bit integer. (RGBA order)	
+	/// Returns the color as a packed 32-bit integer. (RGBA order)
 	uint32_t to_rgba(const Color4& c);
 
 	/// Returns the color as a packed 32-bit integer. (ABGR order)
@@ -262,7 +262,7 @@ namespace color4
 	/// Returns the pointer to the color's data.
 	float* to_float_ptr(Color4& c);
 
-	/// Returns the pointer to the color's data.						
+	/// Returns the pointer to the color's data.
 	const float* to_float_ptr(const Color4& c);
 } // namespace color4
 

+ 5 - 5
engine/core/math/Frustum.h → engine/core/math/frustum.h

@@ -26,11 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "MathTypes.h"
-#include "Vector3.h"
-#include "Plane.h"
-#include "Intersection.h"
+#include "types.h"
+#include "math_types.h"
+#include "vector3.h"
+#include "plane.h"
+#include "intersection.h"
 
 namespace crown
 {

+ 7 - 7
engine/core/math/Intersection.h → engine/core/math/intersection.h

@@ -26,13 +26,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Ray.h"
-#include "Plane.h"
-#include "Sphere.h"
-#include "Frustum.h"
-#include "MathUtils.h"
-#include "Types.h"
-#include "AABB.h"
+#include "ray.h"
+#include "plane.h"
+#include "sphere.h"
+#include "frustum.h"
+#include "math_utils.h"
+#include "types.h"
+#include "aabb.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/math/MathTypes.h → engine/core/math/math_types.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {
@@ -177,7 +177,7 @@ struct AABB
 struct Plane
 {
 	/// Does nothing for efficiency.
-	Plane();						
+	Plane();
 	Plane(const Vector3& n, float d);
 
 	Vector3 n;

+ 7 - 7
engine/core/math/MathUtils.h → engine/core/math/math_utils.h

@@ -28,9 +28,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include <math.h>
 
-#include "Assert.h"
-#include "Types.h"
-#include "Memory.h"
+#include "assert.h"
+#include "types.h"
+#include "memory.h"
 
 namespace crown
 {
@@ -216,7 +216,7 @@ inline float sqrt(float x)
 //-----------------------------------------------------------------------------
 inline float inv_sqrt(float x)
 {
-	return 1.0 / sqrt(x);
+	return 1.0f / sqrt(x);
 }
 
 //-----------------------------------------------------------------------------
@@ -270,7 +270,7 @@ inline float fmod(float n, float d)
 //-----------------------------------------------------------------------------
 inline bool solve_quadratic_equation(float a, float b, float c, float& x1, float& x2)
 {
-	float delta = (b * b) - (4.0 * a * c);
+	float delta = (b * b) - (4.0f * a * c);
 
 	// If the equation has no float solutions
 	if (delta < 0.0)
@@ -278,8 +278,8 @@ inline bool solve_quadratic_equation(float a, float b, float c, float& x1, float
 		return false;
 	}
 
-	x1 = (-b + sqrt(delta)) / (2.0 * a);
-	x2 = (-b - sqrt(delta)) / (2.0 * a);
+	x1 = (-b + sqrt(delta)) / (2.0f * a);
+	x2 = (-b - sqrt(delta)) / (2.0f * a);
 
 	if (x2 > x1)
 	{

+ 13 - 13
engine/core/math/Matrix3x3.h → engine/core/math/matrix3x3.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "MathTypes.h"
-#include "Vector3.h"
-#include "Assert.h"
+#include "math_types.h"
+#include "vector3.h"
+#include "assert.h"
 
 namespace crown
 {
@@ -60,7 +60,7 @@ Matrix3x3 operator*(Matrix3x3 a, const Matrix3x3& b);
 namespace matrix3x3
 {
 	const Matrix3x3 IDENTITY = Matrix3x3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
-	
+
 	/// Transposes the matrix @a m and returns the result.
 	Matrix3x3& transpose(Matrix3x3& m);
 
@@ -77,18 +77,18 @@ namespace matrix3x3
 	Matrix3x3 get_inverted(Matrix3x3 m);
 
 	/// Sets the matrix @a m to identity.
-	void set_identity(Matrix3x3& m);							
+	void set_identity(Matrix3x3& m);
 
 	/// Returns the pointer to the matrix's data
 	float* to_float_ptr(Matrix3x3& m);
 
-	/// Returns the pointer to the matrix's data				
+	/// Returns the pointer to the matrix's data
 	const float* to_float_ptr(const Matrix3x3& m);
 
-	/// Returns a 4x4 matrix according to the matrix's rotation portion						
+	/// Returns a 4x4 matrix according to the matrix's rotation portion
 	Matrix4x4 to_matrix4x4(const Matrix3x3& m);
 
-	/// Returns a quaternion according to the matrix's rotation portion							
+	/// Returns a quaternion according to the matrix's rotation portion
 	Quaternion to_quaternion(const Matrix3x3& m);
 } // namespace matrix3x3
 
@@ -185,7 +185,7 @@ namespace matrix3x3
 		mat.x.y = (m.x.y * m.z.z - m.z.y * m.x.z);
 		mat.x.z = (m.x.y * m.y.z - m.y.y * m.x.z);
 
-		const float inv_det = 1.0 / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z);
+		const float inv_det = 1.0f / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z);
 
 		mat.y.x = (m.y.x * m.z.z - m.z.x * m.y.z);
 		mat.y.y = (m.x.x * m.z.z - m.z.x * m.x.z);
@@ -321,9 +321,9 @@ inline Matrix3x3::Matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z
 
 //-----------------------------------------------------------------------------
 inline Matrix3x3::Matrix3x3(const Quaternion& r)
-	: x(1.0 - 2.0 * r.y * r.y - 2.0 * r.z * r.z, 2.0 * r.x * r.y + 2.0 * r.w * r.z, 2.0 * r.x * r.z - 2.0 * r.w * r.y)
-	, y(2.0 * r.x * r.y - 2.0 * r.w * r.z, 1.0 - 2.0 * r.x * r.x - 2.0 * r.z * r.z, 2.0 * r.y * r.z + 2.0 * r.w * r.x)
-	, z(2.0 * r.x * r.z + 2.0 * r.w * r.y, 2.0 * r.y * r.z - 2.0 * r.w * r.x, 1.0 - 2.0 * r.x * r.x - 2.0 * r.y * r.y)
+	: x(1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z, 2.0f * r.x * r.y + 2.0f * r.w * r.z, 2.0f * r.x * r.z - 2.0f * r.w * r.y)
+	, y(2.0f * r.x * r.y - 2.0f * r.w * r.z, 1.0f - 2.0f * r.x * r.x - 2.0f * r.z * r.z, 2.0f * r.y * r.z + 2.0f * r.w * r.x)
+	, z(2.0f * r.x * r.z + 2.0f * r.w * r.y, 2.0f * r.y * r.z - 2.0f * r.w * r.x, 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y)
 {
 }
 
@@ -393,7 +393,7 @@ inline Matrix3x3& Matrix3x3::operator*=(float k)
 //-----------------------------------------------------------------------------
 inline Matrix3x3& Matrix3x3::operator/=(float k)
 {
-	const float inv_k = 1.0 / k;
+	const float inv_k = 1.0f / k;
 
 	x *= inv_k;
 	y *= inv_k;

+ 22 - 22
engine/core/math/Matrix4x4.h → engine/core/math/matrix4x4.h

@@ -26,11 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "MathTypes.h"
-#include "Matrix3x3.h"
-#include "Quaternion.h"
-#include "Vector4.h"
-#include "Types.h"
+#include "math_types.h"
+#include "matrix3x3.h"
+#include "quaternion.h"
+#include "vector4.h"
+#include "types.h"
 
 namespace crown
 {
@@ -82,18 +82,18 @@ namespace matrix4x4
 	void set_look_rh(Matrix4x4& m, const Vector3& pos, const Vector3& target, const Vector3& up);
 
 	/// Transposes the matrix @a m and returns the result.
-	Matrix4x4& transpose(Matrix4x4& m);					
+	Matrix4x4& transpose(Matrix4x4& m);
 
-	/// Returns the transposed of the matrix @a m.			
+	/// Returns the transposed of the matrix @a m.
 	Matrix4x4 get_transposed(Matrix4x4 m);
 
-	/// Returns the determinant of the matrix @a m.						
+	/// Returns the determinant of the matrix @a m.
 	float determinant(const Matrix4x4& m);
 
 	/// Inverts the matrix @a m and returns the result.
 	Matrix4x4& invert(Matrix4x4& m);
 
-	/// Returns the inverse of the matrix @a m.				
+	/// Returns the inverse of the matrix @a m.
 	Matrix4x4 get_inverted(Matrix4x4 m);
 
 	/// Sets the matrix @a m to identity.
@@ -118,7 +118,7 @@ namespace matrix4x4
 	void set_z(Matrix4x4& m, const Vector3& z);
 
 	/// Returns the translation portion of the matrix @a m.
-	Vector3 translation(const Matrix4x4& m);	
+	Vector3 translation(const Matrix4x4& m);
 
 	/// Sets the translation portion of the matrix @a m.
 	void set_translation(Matrix4x4& m, const Vector3& trans);
@@ -220,21 +220,21 @@ namespace matrix4x4
 	//-----------------------------------------------------------------------------
 	inline void set_perspective_rh(Matrix4x4& m, float fovy, float aspect, float near, float far)
 	{
-		const double top = math::tan(((double)fovy / 360.0 * math::PI)) * (double)near;
-		const double right = top * aspect;
+		const float top = math::tan(fovy / 360.0f * math::PI) * near;
+		const float right = top * aspect;
 
 		m.x = Vector4(near / right, 0, 0, 0);
 		m.y = Vector4(0, near / top, 0, 0);
 		m.z = Vector4(0, 0, (far + near) / (near - far), -1);
-		m.t = Vector4(0, 0, (2.0 * far * near) / (near - far), 0);
+		m.t = Vector4(0, 0, (2.0f * far * near) / (near - far), 0);
 	}
 
 	//-----------------------------------------------------------------------------
 	inline void set_orthographic_rh(Matrix4x4& m, float left, float right, float bottom, float top, float near, float far)
 	{
-		m.x = Vector4(2.0 / (right - left), 0, 0, 0);
-		m.y = Vector4(0, 2.0 / (top - bottom), 0, 0);
-		m.z = Vector4(0, 0, -2.0 / (far - near), 0);
+		m.x = Vector4(2.0f / (right - left), 0, 0, 0);
+		m.y = Vector4(0, 2.0f / (top - bottom), 0, 0);
+		m.z = Vector4(0, 0, -2.0f / (far - near), 0);
 		m.t = Vector4(-((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((far + near) / (far - near)), 1.0);
 	}
 
@@ -351,7 +351,7 @@ namespace matrix4x4
 		mat.x.z = (+ m.x.y * m06m15_m14m07 - m.y.y * m02m15_m14m03 + m.t.y * m02m07_m06m03);
 		mat.x.w = (+ m.x.y * m06m11_m10m07 - m.y.y * m02m11_m10m03 + m.z.y * m02m07_m06m03);
 
-		const float inv_det = 1.0 / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z - m.t.x * mat.x.w);
+		const float inv_det = 1.0f / (m.x.x * mat.x.x - m.y.x * mat.x.y + m.z.x * mat.x.z - m.t.x * mat.x.w);
 
 		mat.y.x = (+ m.y.x * m10m15_m14m11 - m.z.x * m06m15_m14m07 + m.t.x * m06m11_m10m07);
 		mat.y.y = (+ m.x.x * m10m15_m14m11 - m.z.x * m02m15_m14m03 + m.t.x * m02m11_m10m03);
@@ -508,9 +508,9 @@ inline Matrix4x4::Matrix4x4(float r1c1, float r2c1, float r3c1, float r4c1,
 
 //-----------------------------------------------------------------------------
 inline Matrix4x4::Matrix4x4(const Quaternion& r, const Vector3& p)
-	: x(1.0 - 2.0 * r.y * r.y - 2.0 * r.z * r.z, 2.0 * r.x * r.y + 2.0 * r.w * r.z, 2.0 * r.x * r.z - 2.0 * r.w * r.y, 0)
-	, y(2.0 * r.x * r.y - 2.0 * r.w * r.z, 1.0 - 2.0 * r.x * r.x - 2.0 * r.z * r.z, 2.0 * r.y * r.z + 2.0 * r.w * r.x, 0)
-	, z(2.0 * r.x * r.z + 2.0 * r.w * r.y, 2.0 * r.y * r.z - 2.0 * r.w * r.x, 1.0 - 2.0 * r.x * r.x - 2.0 * r.y * r.y, 0)
+	: x(1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z, 2.0f * r.x * r.y + 2.0f * r.w * r.z, 2.0f * r.x * r.z - 2.0f * r.w * r.y, 0)
+	, y(2.0f * r.x * r.y - 2.0f * r.w * r.z, 1.0f - 2.0f * r.x * r.x - 2.0f * r.z * r.z, 2.0f * r.y * r.z + 2.0f * r.w * r.x, 0)
+	, z(2.0f * r.x * r.z + 2.0f * r.w * r.y, 2.0f * r.y * r.z - 2.0f * r.w * r.x, 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y, 0)
 	, t(p, 1)
 {
 }
@@ -585,8 +585,8 @@ inline Matrix4x4& Matrix4x4::operator*=(float k)
 //-----------------------------------------------------------------------------
 inline Matrix4x4& Matrix4x4::operator/=(float k)
 {
-	const float inv_k = 1.0 / k;
-	
+	const float inv_k = 1.0f / k;
+
 	x *= inv_k;
 	y *= inv_k;
 	z *= inv_k;

+ 4 - 4
engine/core/math/Plane.h → engine/core/math/plane.h

@@ -26,10 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "Sphere.h"
-#include "Vector3.h"
-#include "MathTypes.h"
+#include "types.h"
+#include "sphere.h"
+#include "vector3.h"
+#include "math_types.h"
 
 namespace crown
 {

+ 11 - 11
engine/core/math/Quaternion.h → engine/core/math/quaternion.h

@@ -26,10 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "Vector3.h"
-#include "MathTypes.h"
-#include "Matrix3x3.h"
+#include "types.h"
+#include "vector3.h"
+#include "math_types.h"
+#include "matrix3x3.h"
 
 namespace crown
 {
@@ -110,7 +110,7 @@ namespace quaternion
 
 	inline Quaternion inverse(const Quaternion& q)
 	{
-		return conjugate(q) * (1.0 / length(q));
+		return conjugate(q) * (1.0f / length(q));
 	}
 
 	inline Quaternion power(const Quaternion& q, float exp)
@@ -159,21 +159,21 @@ inline Quaternion::Quaternion(float nx, float ny, float nz, float nw)
 
 //-----------------------------------------------------------------------------
 inline Quaternion::Quaternion(const Vector3& axis, float angle)
-	: x(axis.x * math::sin(angle * 0.5))
-	, y(axis.y * math::sin(angle * 0.5))
-	, z(axis.z * math::sin(angle * 0.5))
-	, w(math::cos(angle * 0.5))
+	: x(axis.x * math::sin(angle * 0.5f))
+	, y(axis.y * math::sin(angle * 0.5f))
+	, z(axis.z * math::sin(angle * 0.5f))
+	, w(math::cos(angle * 0.5f))
 {
 }
 
-//-----------------------------------------------------------------------------	
+//-----------------------------------------------------------------------------
 inline float& Quaternion::operator[](uint32_t i)
 {
 	CE_ASSERT(i < 4, "Index out of bounds");
 	return (&x)[i];
 }
 
-//-----------------------------------------------------------------------------	
+//-----------------------------------------------------------------------------
 inline const float& Quaternion::operator[](uint32_t i) const
 {
 	CE_ASSERT(i < 4, "Index out of bounds");

+ 0 - 0
engine/core/math/Random.h → engine/core/math/random.h


+ 2 - 2
engine/core/math/Ray.h → engine/core/math/ray.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "Vector3.h"
+#include "types.h"
+#include "vector3.h"
 
 namespace crown
 {

+ 9 - 9
engine/core/math/Sphere.h → engine/core/math/sphere.h

@@ -26,9 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
-#include "MathUtils.h"
-#include "Vector3.h"
+#include "types.h"
+#include "math_utils.h"
+#include "vector3.h"
 
 namespace crown
 {
@@ -48,21 +48,21 @@ public:
 					Sphere(const Vector3& center, float radius);
 					Sphere(const Sphere& a);
 
-	const Vector3&	center() const;		
-	float			radius() const;	
-	float			volume() const;	
+	const Vector3&	center() const;
+	float			radius() const;
+	float			volume() const;
 
 	void			set_center(const Vector3& center);
 	void			set_radius(float radius);
 
 	/// Adds @a count @a points to the sphere expanding if necessary.
-	void			add_points(const Vector3* points, uint32_t count);	
+	void			add_points(const Vector3* points, uint32_t count);
 
 	/// Adds @a count @a spheres expanding if necessary.
-	void			add_spheres(const Sphere* spheres, uint32_t count);	
+	void			add_spheres(const Sphere* spheres, uint32_t count);
 
 	/// Returns whether point @a p is contained into the sphere.
-	bool			contains_point(const Vector3& p) const;		
+	bool			contains_point(const Vector3& p) const;
 
 private:
 

+ 5 - 5
engine/core/math/Vector2.h → engine/core/math/vector2.h

@@ -26,10 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Types.h"
-#include "MathUtils.h"
-#include "MathTypes.h"
+#include "assert.h"
+#include "types.h"
+#include "math_utils.h"
+#include "math_types.h"
 
 namespace crown
 {
@@ -163,7 +163,7 @@ namespace vector2
 	//-----------------------------------------------------------------------------
 	inline Vector2 normalize(Vector2& a)
 	{
-		float inv_len = 1.0 / length(a);
+		float inv_len = 1.0f / length(a);
 
 		a.x *= inv_len;
 		a.y *= inv_len;

+ 6 - 6
engine/core/math/Vector3.h → engine/core/math/vector3.h

@@ -26,11 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Types.h"
-#include "MathUtils.h"
-#include "Vector2.h"
-#include "MathTypes.h"
+#include "assert.h"
+#include "types.h"
+#include "math_utils.h"
+#include "vector2.h"
+#include "math_types.h"
 
 namespace crown
 {
@@ -179,7 +179,7 @@ namespace vector3
 	//-----------------------------------------------------------------------------
 	inline Vector3 normalize(Vector3& a)
 	{
-		float inv_len = 1.0 / length(a);
+		float inv_len = 1.0f / length(a);
 
 		a.x *= inv_len;
 		a.y *= inv_len;

+ 6 - 6
engine/core/math/Vector4.h → engine/core/math/vector4.h

@@ -26,10 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Assert.h"
-#include "Types.h"
-#include "MathUtils.h"
-#include "Vector3.h"
+#include "assert.h"
+#include "types.h"
+#include "math_utils.h"
+#include "vector3.h"
 
 namespace crown
 {
@@ -171,7 +171,7 @@ namespace vector4
 	//-----------------------------------------------------------------------------
 	inline Vector4 normalize(Vector4& a)
 	{
-		float inv_len = 1.0 / length(a);
+		float inv_len = 1.0f / length(a);
 
 		a.x *= inv_len;
 		a.y *= inv_len;
@@ -209,7 +209,7 @@ namespace vector4
 	inline Vector3 to_vector3(const Vector4& a)
 	{
 		return Vector3(a.x, a.y, a.z);
-	}	
+	}
 }
 
 //-----------------------------------------------------------------------------

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

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/mem/LinearAllocator.cpp → engine/core/mem/linear_allocator.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "LinearAllocator.h"
-#include "Memory.h"
+#include "linear_allocator.h"
+#include "memory.h"
 
 namespace crown
 {

+ 1 - 1
engine/core/mem/LinearAllocator.h → engine/core/mem/linear_allocator.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Allocator.h"
+#include "allocator.h"
 
 namespace crown
 {

+ 3 - 3
engine/core/mem/Memory.cpp → engine/core/mem/memory.cpp

@@ -24,9 +24,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Memory.h"
-#include "Allocator.h"
-#include "ScopedMutex.h"
+#include "memory.h"
+#include "allocator.h"
+#include "mutex.h"
 
 // //-----------------------------------------------------------------------------
 // void* operator new(size_t) throw (std::bad_alloc)

+ 6 - 6
engine/core/mem/Memory.h → engine/core/mem/memory.h

@@ -27,14 +27,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include <new>
-#include "Types.h"
-#include "Assert.h"
-#include "Allocator.h"
+#include "types.h"
+#include "assert.h"
+#include "allocator.h"
 
 namespace crown
 {
 
-CE_EXPORT Allocator& default_allocator();
+Allocator& default_allocator();
 
 /// @defgroup Memory Memory
 namespace memory
@@ -46,12 +46,12 @@ const uint32_t PADDING_VALUE = 0xFFFFFFFFu;
 /// Constructs the initial default allocators.
 /// @note
 /// Has to be called before anything else during the engine startup.
-CE_EXPORT void init();
+void init();
 
 /// Destroys the allocators created with memory::init().
 /// @note
 /// Should be the last call of the program.
-CE_EXPORT void shutdown();
+void shutdown();
 
 /// Returns the pointer @a p aligned to the desired @a align byte
 inline void* align_top(void* p, size_t align)

+ 0 - 0
engine/core/mem/MemoryTypes.h → engine/core/mem/memory_types.h


+ 2 - 2
engine/core/mem/PoolAllocator.cpp → engine/core/mem/pool_allocator.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "PoolAllocator.h"
-#include "Assert.h"
+#include "pool_allocator.h"
+#include "assert.h"
 
 namespace crown
 {

+ 1 - 1
engine/core/mem/PoolAllocator.h → engine/core/mem/pool_allocator.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Allocator.h"
+#include "allocator.h"
 
 namespace crown
 {

+ 4 - 4
engine/core/mem/ProxyAllocator.cpp → engine/core/mem/proxy_allocator.cpp

@@ -24,10 +24,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Assert.h"
-#include "ProxyAllocator.h"
-#include "StringUtils.h"
-#include "ScopedMutex.h"
+#include "assert.h"
+#include "proxy_allocator.h"
+#include "string_utils.h"
+#include "mutex.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/mem/ProxyAllocator.h → engine/core/mem/proxy_allocator.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Allocator.h"
-#include "Macros.h"
+#include "allocator.h"
+#include "macros.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/mem/StackAllocator.cpp → engine/core/mem/stack_allocator.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "StackAllocator.h"
-#include "Memory.h"
+#include "stack_allocator.h"
+#include "memory.h"
 
 namespace crown
 {

+ 1 - 1
engine/core/mem/StackAllocator.h → engine/core/mem/stack_allocator.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Allocator.h"
+#include "allocator.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/mem/TempAllocator.h → engine/core/mem/temp_allocator.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Allocator.h"
-#include "Memory.h"
+#include "allocator.h"
+#include "memory.h"
 
 namespace crown
 {

+ 24 - 13
engine/os/linux/AtomicInt.h → engine/core/network/net_address.h

@@ -26,34 +26,45 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#ifndef __GNUG__
-	#error "Compiler not supported"
-#endif
+#include "config.h"
+#include "types.h"
 
 namespace crown
 {
 
-struct AtomicInt
+/// Netwotk address helper
+///
+/// @ingroup Network
+struct NetAddress
 {
-	AtomicInt(int val)
+	/// Initializes the address to 127.0.0.1
+	NetAddress()
+		: m_addr(0)
 	{
-		store(val);
+		set(127, 0, 0, 1);
 	}
 
-	int load() const
+	NetAddress(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
+		: m_addr(0)
 	{
-		__sync_fetch_and_add(&m_val, 0);
-		return m_val;
+		set(a, b, c, d);
 	}
 
-	void store(int val)
+	/// Returns the IP address as packed 32-bit integer.
+	uint32_t address() const
 	{
-		__sync_lock_test_and_set(&m_val, val);
+		return m_addr;
 	}
 
-private:
+	void set(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
+	{
+		m_addr = uint32_t(a) << 24
+			| uint32_t(b) << 16
+			| uint32_t(c) << 8
+			| uint32_t(d);
+	}
 
-	mutable int m_val;
+	uint32_t m_addr;
 };
 
 } // namespace crown

+ 500 - 0
engine/core/network/socket.h

@@ -0,0 +1,500 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "config.h"
+#include "types.h"
+#include "assert.h"
+#include "net_address.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <sys/socket.h>
+	#include <sys/types.h>
+	#include <netinet/in.h>
+	#include <fcntl.h>
+	#include <unistd.h>
+	#include <errno.h>
+#elif CROWN_PLATFORM_WINDOWS
+//Undefined in WinHeaders.h, but winsock2 ecc need it.
+	#ifndef NEAR
+	#define NEAR
+	#endif
+	#ifndef FAR
+	#define FAR
+	#endif
+	#include <winsock2.h>
+	#include <win_headers.h>
+	//Re-undef NEAR and FAR after use
+	#undef NEAR
+	#undef FAR
+	#pragma comment(lib, "Ws2_32.lib")
+#endif
+
+namespace crown
+{
+
+struct ConnectResult
+{
+	enum { NO_ERROR, BAD_SOCKET, REFUSED, TIMEOUT, UNKNOWN } error;
+};
+
+struct ReadResult
+{
+	enum { NO_ERROR, BAD_SOCKET, REMOTE_CLOSED, TIMEOUT, UNKNOWN } error;
+	size_t bytes_read;
+};
+
+struct WriteResult
+{
+	enum { NO_ERROR, BAD_SOCKET, REMOTE_CLOSED, TIMEOUT, UNKNOWN } error;
+	size_t bytes_wrote;
+};
+
+struct AcceptResult
+{
+	enum { NO_ERROR, BAD_SOCKET, NO_CONNECTION, UNKNOWN } error;
+};
+
+/// TCP socket
+///
+/// @ingroup Network
+struct TCPSocket
+{
+	//-----------------------------------------------------------------------------
+	TCPSocket()
+#if CROWN_PLATFORM_POSIX
+		: m_socket(0)
+#elif CROWN_PLATFORM_WINDOWS
+		: m_socket(INVALID_SOCKET)
+#endif
+	{
+	}
+
+	//-----------------------------------------------------------------------------
+	void open()
+	{
+#if CROWN_PLATFORM_POSIX
+		m_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+		CE_ASSERT(m_socket >= 0, "socket: errno = %d", errno);
+#elif CROWN_PLATFORM_WINDOWS
+		m_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+		CE_ASSERT(m_socket >= 0, "socket: WSAGetLastError = %d", WSAGetLastError());
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	ConnectResult connect(const NetAddress& ip, uint16_t port)
+	{
+		close();
+		open();
+
+		ConnectResult cr;
+		cr.error = ConnectResult::NO_ERROR;
+
+#if CROWN_PLATFORM_POSIX
+		sockaddr_in addr_in;
+		addr_in.sin_family = AF_INET;
+		addr_in.sin_addr.s_addr = htonl(ip.address());
+		addr_in.sin_port = htons(port);
+
+		int err = ::connect(m_socket, (const sockaddr*)&addr_in, sizeof(sockaddr_in));
+
+		if (err == 0)
+			return cr;
+
+		if (errno == ECONNREFUSED)
+			cr.error = ConnectResult::REFUSED;
+		else if (errno == ETIMEDOUT)
+			cr.error = ConnectResult::TIMEOUT;
+		else
+			cr.error = ConnectResult::UNKNOWN;
+
+		return cr;
+#elif CROWN_PLATFORM_WINDOWS
+		sockaddr_in addr_in;
+		addr_in.sin_family = AF_INET;
+		addr_in.sin_addr.s_addr = ::htonl(ip.address());
+		addr_in.sin_port = ::htons(port);
+
+		int err = ::connect(m_socket, (const sockaddr*)&addr_in, sizeof(sockaddr_in));
+
+		if (err == 0)
+			return cr;
+
+		int wsaerr = WSAGetLastError();
+		if (wsaerr == WSAECONNREFUSED)
+			cr.error = ConnectResult::REFUSED;
+		else if (wsaerr == WSAETIMEDOUT)
+			cr.error = ConnectResult::TIMEOUT;
+		else
+			cr.error = ConnectResult::UNKNOWN;
+
+		return cr;
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	bool bind(uint16_t port)
+	{
+		close();
+		open();
+		set_resuse_address(true);
+#if CROWN_PLATFORM_POSIX
+		sockaddr_in address;
+		address.sin_family = AF_INET;
+		address.sin_addr.s_addr = htonl(INADDR_ANY);
+		address.sin_port = htons(port);
+
+		int err = ::bind(m_socket, (const sockaddr*) &address, sizeof(sockaddr_in));
+		CE_ASSERT(err == 0, "bind: errno = %d", errno);
+		CE_UNUSED(err);
+		return true;
+#elif CROWN_PLATFORM_WINDOWS
+		sockaddr_in address;
+		address.sin_family = AF_INET;
+		address.sin_addr.s_addr = htonl(INADDR_ANY);
+		address.sin_port = htons(port);
+
+		int err = ::bind(m_socket, (const sockaddr*) &address, sizeof(sockaddr_in));
+		CE_ASSERT(err == 0, "bind: WSAGetLastError = %d", WSAGetLastError());
+		CE_UNUSED(err);
+		return true;
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	void listen(uint32_t max)
+	{
+#if CROWN_PLATFORM_POSIX
+		int err = ::listen(m_socket, max);
+		CE_ASSERT(err == 0, "listen: errno = %d", errno);
+		CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+		int err = ::listen(m_socket, max);
+		CE_ASSERT(err == 0, "listen: WSAGetLastError = %d", WSAGetLastError());
+		CE_UNUSED(err);
+#endif
+	}
+
+	AcceptResult accept_internal(TCPSocket& c)
+	{
+		AcceptResult ar;
+		ar.error = AcceptResult::NO_ERROR;
+
+#if CROWN_PLATFORM_POSIX
+		int err = ::accept(m_socket, NULL, NULL);
+
+		if (err >= 0)
+			c.m_socket = err;
+		else if (err == -1 && errno == EBADF)
+			ar.error = AcceptResult::BAD_SOCKET;
+		else if (err == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
+			ar.error = AcceptResult::NO_CONNECTION;
+		else
+			ar.error = AcceptResult::UNKNOWN;
+
+		return ar;
+#elif CROWN_PLATFORM_WINDOWS
+		int err = ::accept(m_socket, NULL, NULL);
+
+		if (err != INVALID_SOCKET)
+		{
+			c.m_socket = err;
+			return ar;
+		}
+
+		int wsaerr = WSAGetLastError();
+		if (wsaerr == WSAEWOULDBLOCK)
+			ar.error = AcceptResult::NO_CONNECTION;
+		else
+			ar.error = AcceptResult::UNKNOWN;
+
+		return ar;
+#endif		
+	}
+
+	//-----------------------------------------------------------------------------
+	AcceptResult accept_nonblock(TCPSocket& c)
+	{
+		set_blocking(false);
+		return accept_internal(c);
+	}
+
+	//-----------------------------------------------------------------------------
+	AcceptResult accept(TCPSocket& c)
+	{
+		set_blocking(true);
+		return accept_internal(c);
+	}
+
+	//-----------------------------------------------------------------------------
+	void close()
+	{
+#if CROWN_PLATFORM_POSIX
+		if (m_socket != 0)
+		{
+			::close(m_socket);
+			m_socket = 0;
+		}
+#elif CROWN_PLATFORM_WINDOWS
+		if (m_socket != INVALID_SOCKET)
+		{
+			::closesocket(m_socket);
+			m_socket = INVALID_SOCKET;
+		}
+#endif
+	}
+
+	ReadResult read_internal(void* data, size_t size)
+	{
+		ReadResult rr;
+		rr.error = ReadResult::NO_ERROR;
+		rr.bytes_read = 0;
+
+#if CROWN_PLATFORM_POSIX
+		char* buf = (char*) data;
+		size_t to_read = size;
+
+		while (to_read > 0)
+		{
+			ssize_t read_bytes = ::recv(m_socket, buf, to_read, 0);
+
+			if (read_bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
+			{
+				return rr;
+			}
+			else if (read_bytes == -1 && errno == ETIMEDOUT)
+			{
+				rr.error = ReadResult::TIMEOUT;
+				return rr;
+			}
+			else if (read_bytes == 0)
+			{
+				rr.error = ReadResult::REMOTE_CLOSED;
+				return rr;
+			}
+
+			buf += read_bytes;
+			to_read -= read_bytes;
+			rr.bytes_read += read_bytes;
+		}
+
+		return rr;
+#elif CROWN_PLATFORM_WINDOWS
+		char* buf = (char*) data;
+		size_t to_read = size;
+
+		while (to_read > 0)
+		{
+			int read_bytes = ::recv(m_socket, buf, to_read, 0);
+
+			if (read_bytes == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
+				return rr;
+			else if (read_bytes == SOCKET_ERROR && WSAGetLastError() == WSAETIMEDOUT)
+			{
+				rr.error = ReadResult::TIMEOUT;
+				return rr;
+			}
+			else if (read_bytes == 0)
+			{
+				rr.error = ReadResult::REMOTE_CLOSED;
+				return rr;
+			}
+
+			buf += read_bytes;
+			to_read -= read_bytes;
+			rr.bytes_read += read_bytes;
+		}
+
+		return rr;
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	ReadResult read_nonblock(void* data, size_t size)
+	{
+		set_blocking(false);
+		return read_internal(data, size);
+	}
+
+	//-----------------------------------------------------------------------------
+	ReadResult read(void* data, size_t size)
+	{
+		set_blocking(true);
+		return read_internal(data, size);
+	}
+
+	WriteResult write_internal(const void* data, size_t size)
+	{
+		WriteResult wr;
+		wr.error = WriteResult::NO_ERROR;
+		wr.bytes_wrote = 0;
+
+#if CROWN_PLATFORM_POSIX
+		const char* buf = (const char*) data;
+		size_t to_send = size;
+
+		while (to_send > 0)
+		{
+			ssize_t bytes_wrote = ::send(m_socket, (const char*) buf, to_send, 0);
+
+			if (bytes_wrote == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
+				return wr;
+			else if (bytes_wrote == -1 && errno == ETIMEDOUT)
+			{
+				wr.error = WriteResult::TIMEOUT;
+				return wr;
+			}
+			else if (bytes_wrote == 0)
+			{
+				wr.error = WriteResult::REMOTE_CLOSED;
+				return wr;
+			}
+			else
+			{
+				wr.error = WriteResult::UNKNOWN;
+				return wr;
+			}
+
+			buf += bytes_wrote;
+			to_send -= bytes_wrote;
+			wr.bytes_wrote += bytes_wrote;
+		}
+
+		return wr;
+#elif CROWN_PLATFORM_WINDOWS
+		const char* buf = (const char*) data;
+		size_t to_send = size;
+
+		while (to_send > 0)
+		{
+			int bytes_wrote = ::send(m_socket, (const char*) buf, to_send, 0);
+
+			if (bytes_wrote == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
+			{
+				return wr;
+			}
+			else if (bytes_wrote == SOCKET_ERROR && WSAGetLastError() == WSAETIMEDOUT)
+			{
+				wr.error = WriteResult::TIMEOUT;
+				return wr;
+			}
+			else if (bytes_wrote == 0)
+			{
+				wr.error = WriteResult::REMOTE_CLOSED;
+				return wr;
+			}
+			else
+			{
+				wr.error = WriteResult::UNKNOWN;
+				return wr;
+			}
+
+			buf += bytes_wrote;
+			to_send -= bytes_wrote;
+			wr.bytes_wrote += bytes_wrote;
+		}
+
+		return wr;
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	WriteResult write_nonblock(const void* data, size_t size)
+	{
+		set_blocking(false);
+		return write_internal(data, size);
+	}
+
+	//-----------------------------------------------------------------------------
+	WriteResult write(const void* data, size_t size)
+	{
+		set_blocking(true);
+		return write_internal(data, size);
+	}
+
+	//-----------------------------------------------------------------------------
+	void set_blocking(bool blocking)
+	{
+#if CROWN_PLATFORM_POSIX
+		int flags = fcntl(m_socket, F_GETFL, 0);
+		fcntl(m_socket, F_SETFL, blocking ? (flags & ~O_NONBLOCK) : O_NONBLOCK);
+#elif CROWN_PLATFORM_WINDOWS
+		//Warning! http://www.sockets.com/winsock.htm#IoctlSocket
+		u_long non_blocking = blocking ? 0 : 1;
+		ioctlsocket(m_socket, FIONBIO, &non_blocking);
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	void set_resuse_address(bool reuse)
+	{
+#if CROWN_PLATFORM_POSIX
+		int optval = (int) reuse;
+		int err = setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
+		CE_ASSERT(err == 0, "setsockopt: errno = %d", errno);
+#elif CROWN_PLATFORM_WINDOWS
+		int optval = (int) reuse;
+		int err = setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, (const char*) &optval, sizeof(optval));
+		CE_ASSERT(err == 0, "setsockopt: WSAGetLastError = %d", WSAGetLastError());
+#endif
+	}
+
+	//-----------------------------------------------------------------------------
+	void set_timeout(uint32_t seconds)
+	{
+#if CROWN_PLATFORM_POSIX
+		struct timeval timeout;
+		timeout.tv_sec = seconds;
+		timeout.tv_usec = 0;
+		int err;
+		err = setsockopt (m_socket, SOL_SOCKET, SO_RCVTIMEO, (char*) &timeout, sizeof(timeout));
+		CE_ASSERT(err == 0, "setsockopt: errno: %d", errno);
+		err = setsockopt (m_socket, SOL_SOCKET, SO_SNDTIMEO, (char*) &timeout, sizeof(timeout));
+		CE_ASSERT(err == 0, "setsockopt: errno: %d", errno);
+#elif CROWN_PLATFORM_WINDOWS
+		struct timeval timeout;
+		timeout.tv_sec = seconds;
+		timeout.tv_usec = 0;
+		int err;
+		err = setsockopt (m_socket, SOL_SOCKET, SO_RCVTIMEO, (char*) &timeout, sizeof(timeout));
+		CE_ASSERT(err == 0, "setsockopt: WSAGetLastError: %d", WSAGetLastError());
+		err = setsockopt (m_socket, SOL_SOCKET, SO_SNDTIMEO, (char*) &timeout, sizeof(timeout));
+		CE_ASSERT(err == 0, "setsockopt: WSAGetLastError: %d", WSAGetLastError());
+#endif
+	}
+
+private:
+
+#if CROWN_PLATFORM_POSIX
+	int m_socket;
+#elif CROWN_PLATFORM_WINDOWS
+	SOCKET m_socket;
+#endif
+};
+
+} // namespace crown

+ 467 - 0
engine/core/os.h

@@ -0,0 +1,467 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "config.h"
+#include "types.h"
+#include "vector.h"
+#include "dynamic_string.h"
+#include "string_utils.h"
+#include "temp_allocator.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include "assert.h"
+	#include <cstdarg>
+	#include <cstdio>
+	#include <cstdlib>
+	#include <dirent.h>
+	#include <dlfcn.h>
+	#include <sys/stat.h>
+	#include <sys/time.h>
+	#include <sys/types.h>
+	#include <sys/wait.h>
+	#include <errno.h>
+	#include <time.h>
+	#include <unistd.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include <win_headers.h>
+	#include <io.h>
+#endif
+
+#if CROWN_PLATFORM_ANDROID
+	#include <android/log.h>
+#endif
+
+namespace crown
+{
+
+#if CROWN_PLATFORM_LINUX
+	const size_t	MAX_PATH_LENGTH = 1024;
+	const char		PATH_SEPARATOR = '/';
+#elif CROWN_PLATFORM_WINDOWS
+	const size_t	MAX_PATH_LENGTH = 1024;
+	const char		PATH_SEPARATOR = '\\';
+	#define snprintf _snprintf
+#elif CROWN_PLATFORM_ANDROID
+	const size_t	MAX_PATH_LENGTH = 1024;
+	const char		PATH_SEPARATOR = '/';
+#endif
+
+namespace os
+{
+
+//-----------------------------------------------------------------------------
+inline void log_debug(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_DEBUG, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline void log_error(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_ERROR, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline void log_warning(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_WARN, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline void log_info(const char* string, va_list arg)
+{
+#if CROWN_PLATFORM_ANDROID
+	__android_log_vprint(ANDROID_LOG_INFO, "crown", string, arg);
+#else
+	vprintf(string, arg);
+	printf("\n");
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline bool is_root_path(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return (path != NULL && string::strlen(path) == 1 && path[0] == PATH_SEPARATOR);
+#elif CROWN_PLATFORM_WINDOWS
+	return (path != NULL && string::strlen(path) == 3 && string::is_alpha(path[0]) &&
+		path[1] == ':' && path[2] == PATH_SEPARATOR);
+#endif
+}
+
+//-----------------------------------------------------------------------------
+inline bool is_absolute_path(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return (path != NULL && string::strlen(path) >= 1 && path[0] == PATH_SEPARATOR);
+#elif CROWN_PLATFORM_WINDOWS
+	return (path != NULL && string::strlen(path) >= 3 && string::is_alpha(path[0]) &&
+		path[1] == ':' && path[2] == PATH_SEPARATOR);
+#endif
+}
+
+inline bool exists(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return access(path, F_OK) != -1;
+#elif CROWN_PLATFORM_WINDOWS
+	return _access(path, 0) != -1;
+#endif
+}
+
+/// Returns whether the path is a directory.
+inline bool is_directory(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	struct stat info;
+	memset(&info, 0, sizeof(struct stat));
+	int err = lstat(path, &info);
+	CE_ASSERT(err == 0, "lstat: errno = %d", errno);
+	CE_UNUSED(err);
+	return ((S_ISDIR(info.st_mode) == 1) && (S_ISLNK(info.st_mode) == 0));
+#elif CROWN_PLATFORM_WINDOWS
+	DWORD fattr = GetFileAttributes(path);
+	return (fattr != INVALID_FILE_ATTRIBUTES && (fattr & FILE_ATTRIBUTE_DIRECTORY) != 0);
+#endif
+}
+
+/// Returns whether the path is a regular file.
+inline bool is_file(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	struct stat info;
+	memset(&info, 0, sizeof(struct stat));
+	int err = lstat(path, &info);
+	CE_ASSERT(err == 0, "lstat: errno = %d", errno);
+	CE_UNUSED(err);
+	return ((S_ISREG(info.st_mode) == 1) && (S_ISLNK(info.st_mode) == 0));
+#elif CROWN_PLATFORM_WINDOWS
+	DWORD fattr = GetFileAttributes(path);
+	return (fattr != INVALID_FILE_ATTRIBUTES && (fattr & FILE_ATTRIBUTE_DIRECTORY) == 0);
+#endif
+}
+
+/// Creates a regular file.
+inline void create_file(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	// Permission mask: rw-r--r--
+	int err = ::mknod(path, S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, 0);
+	CE_ASSERT(err == 0, "mknod: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE hfile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+	CE_ASSERT(hfile != INVALID_HANDLE_VALUE, "CreateFile: GetLastError = %d", GetLastError());
+	CloseHandle(hfile);
+#endif
+}
+
+/// Deletes a regular file.
+inline void delete_file(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	int err = ::unlink(path);
+	CE_ASSERT(err == 0, "unlink: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	BOOL err = DeleteFile(path);
+	CE_ASSERT(err != 0, "DeleteFile: GetLastError = %d", GetLastError());
+	CE_UNUSED(err);
+#endif
+}
+
+/// Creates a directory. Returns true if success, false if not
+inline void create_directory(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	// rwxr-xr-x
+	int err = ::mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+	CE_ASSERT(err == 0, "mkdir: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	BOOL err = CreateDirectory(path, NULL);
+	CE_ASSERT(err != 0, "CreateDirectory: GetLastError = %d", GetLastError());
+	CE_UNUSED(err);
+#endif
+}
+
+/// Deletes a directory. Returns true if success, false if not
+inline void delete_directory(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	int err = ::rmdir(path);
+	CE_ASSERT(err == 0, "rmdir: errno = %d", errno);
+	CE_UNUSED(err);
+#elif CROWN_PLATFORM_WINDOWS
+	BOOL err = RemoveDirectory(path);
+	CE_ASSERT(err != 0, "RemoveDirectory: GetLastError = %d", GetLastError());
+	CE_UNUSED(err);
+#endif
+}
+
+/// Returns the list of @a files in the given @a dir directory. Optionally walks into
+/// subdirectories whether @a recursive is true.
+/// @note
+/// Does not follow symbolic links.
+inline void list_files(const char* path, Vector<DynamicString>& files)
+{
+#if CROWN_PLATFORM_POSIX
+	DIR *dir;
+	struct dirent *entry;
+
+	if (!(dir = opendir(path)))
+	{
+		return;
+	}
+
+	while ((entry = readdir(dir)))
+	{
+		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+		{
+			continue;
+		}
+
+		DynamicString filename(default_allocator());
+
+		filename = entry->d_name;
+		vector::push_back(files, filename);
+	}
+
+	closedir(dir);
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE file = INVALID_HANDLE_VALUE;
+	WIN32_FIND_DATA ffd;
+
+	char cur_path[MAX_PATH_LENGTH];
+
+	string::strncpy(cur_path, path, string::strlen(path) + 1);
+	string::strncat(cur_path, "\\*", 2);
+
+	file = FindFirstFile(cur_path, &ffd);
+
+	do
+	{
+		CE_ASSERT(file != INVALID_HANDLE_VALUE, "Unable to list files. errono %d", GetLastError());
+
+		if ((string::strcmp(ffd.cFileName, ".") == 0) || (string::strcmp(ffd.cFileName, "..") == 0))
+		{
+			continue;
+		}
+
+		DynamicString filename(default_allocator());
+
+		filename = ffd.cFileName;
+		vector::push_back(files, filename);
+	}
+	while (FindNextFile(file, &ffd) != 0);
+
+	FindClose(file);
+#endif
+}
+
+/// Returns os-dependent path from os-indipendent @a path
+inline const char* normalize_path(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	static char norm[MAX_PATH_LENGTH];
+	char* cur = norm;
+
+	while ((*path) != '\0')
+	{
+		if ((*path) == '\\')
+		{
+			(*cur) = PATH_SEPARATOR;
+		}
+		else
+		{
+			(*cur) = (*path);
+		}
+
+		path++;
+		cur++;
+	}
+
+	return norm;
+#elif CROWN_PLATFORM_WINDOWS
+	static char norm[MAX_PATH_LENGTH];
+
+	for (uint32_t i = 0; i < string::strlen(path)+1; i++)
+	{
+		if (path[i] == '/')
+		{
+			norm[i] = '\\';
+		}
+		else
+		{
+			norm[i] = path[i];
+		}
+	}
+
+	return norm;
+#endif
+}
+
+inline const char* getcwd(char* buf, size_t size)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::getcwd(buf, size);
+#elif CROWN_PLATFORM_WINDOWS
+	GetCurrentDirectory(size, buf);
+	return buf;
+#endif
+}
+
+inline const char* getenv(const char* name)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::getenv(name);
+#elif CROWN_PLATFORM_WINDOWS
+	// GetEnvironmentVariable(name, buf, size);
+#endif
+}
+
+inline int64_t clocktime()
+{
+#if CROWN_PLATFORM_POSIX
+	timespec ttime;
+	clock_gettime(CLOCK_MONOTONIC, &ttime);
+	return ttime.tv_sec * int64_t(1000000000) + ttime.tv_nsec;
+#elif CROWN_PLATFORM_WINDOWS
+	LARGE_INTEGER ttime;
+	QueryPerformanceCounter(&ttime);
+	return (int64_t) ttime.QuadPart;
+#endif
+}
+
+inline int64_t clockfrequency()
+{
+#if CROWN_PLATFORM_POSIX
+	return int32_t(1000000000);
+#elif CROWN_PLATFORM_WINDOWS
+	LARGE_INTEGER freq;
+	QueryPerformanceFrequency(&freq);
+	return (int64_t) freq.QuadPart;
+#endif
+}
+
+inline void* open_library(const char* path)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::dlopen(path, RTLD_LAZY);
+#elif CROWN_PLATFORM_WINDOWS
+	return (void*) LoadLibraryA(path);
+#endif
+}
+
+inline void close_library(void* library)
+{
+#if CROWN_PLATFORM_POSIX
+	dlclose(library);
+#elif CROWN_PLATFORM_WINDOWS
+	FreeLibrary((HMODULE) library);
+#endif
+}
+
+inline void* lookup_symbol(void* library, const char* name)
+{
+#if CROWN_PLATFORM_POSIX
+	return ::dlsym(library, name);
+#elif CROWN_PLATFORM_WINDOWS
+	return (void*) GetProcAddress((HMODULE) library, name);
+#endif
+}
+
+/// Executes a process.
+/// @a args is an array of arguments where:
+/// @a args[0] is the path to the program executable,
+/// @a args[1, 2, ..., n-1] is a list of arguments to pass to the executable,
+/// @a args[n] is NULL.
+inline void execute_process(const char* args[])
+{
+#if CROWN_PLATFORM_POSIX
+	pid_t pid = fork();
+	CE_ASSERT(pid != -1, "fork: errno = %d", errno);
+	if (pid)
+	{
+		int32_t dummy;
+		wait(&dummy);
+	}
+	else
+	{
+		int err = execv(args[0], (char* const*)args);
+		CE_ASSERT(err != -1, "execv: errno = %d", errno);
+		CE_UNUSED(err);
+		exit(EXIT_SUCCESS);
+	}
+#elif CROWN_PLATFORM_WINDOWS
+	STARTUPINFO info;
+	memset(&info, 0, sizeof(info));
+	info.cb = sizeof(info);
+
+	PROCESS_INFORMATION process;
+	memset(&process, 0, sizeof(process));
+
+	DynamicString cmds(default_allocator());
+
+	for (uint32_t i = 0; args[i] != NULL; i++)
+	{
+		cmds += args[i];
+		cmds += ' ';
+	}
+
+	// Necessary because CreateProcess second argument must be non-const
+	char tmp[1024];
+	string::strncpy(tmp, normalize_path(cmds.c_str()), string::strlen(cmds.c_str()));
+
+	int err = CreateProcess(args[0], tmp, NULL, NULL, TRUE, 0, NULL, NULL, &info, &process);
+	CE_ASSERT(err != 0, "CreateProcess: GetLastError = %d", GetLastError());
+	CE_UNUSED(err);
+
+	::WaitForSingleObject(process.hProcess, INFINITE);
+	CloseHandle(process.hProcess);
+	CloseHandle(process.hThread);
+#endif
+}
+
+} // namespace os
+} // namespace crown

+ 6 - 6
engine/core/Profiler.h → engine/core/profiler.h

@@ -26,11 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "OS.h"
-#include "Memory.h"
-#include "Mutex.h"
-#include "ScopedMutex.h"
-#include "Macros.h"
+#include "os.h"
+#include "memory.h"
+#include "mutex.h"
+#include "scoped_mutex.h"
+#include "macros.h"
 
 namespace crown
 {
@@ -52,7 +52,7 @@ namespace profiler
 	struct RecordFloat
 	{
 		const char* name;
-		float value; 
+		float value;
 	};
 
 	struct RecordVector3

+ 2 - 2
engine/core/settings/FloatSetting.cpp → engine/core/settings/float_setting.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "FloatSetting.h"
-#include "StringUtils.h"
+#include "float_setting.h"
+#include "string_utils.h"
 
 namespace crown
 {

+ 1 - 1
engine/core/settings/FloatSetting.h → engine/core/settings/float_setting.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {

+ 2 - 2
engine/core/settings/IntSetting.cpp → engine/core/settings/int_setting.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "IntSetting.h"
-#include "StringUtils.h"
+#include "int_setting.h"
+#include "string_utils.h"
 
 namespace crown
 {

+ 1 - 1
engine/core/settings/IntSetting.h → engine/core/settings/int_setting.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {

+ 3 - 3
engine/core/settings/StringSetting.cpp → engine/core/settings/string_setting.cpp

@@ -24,8 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "StringSetting.h"
-#include "StringUtils.h"
+#include "string_setting.h"
+#include "string_utils.h"
 
 namespace crown
 {
@@ -93,4 +93,4 @@ StringSetting* StringSetting::find_setting(const char* name)
 	return NULL;
 }
 
-} // namespace crown
+} // namespace crown

+ 2 - 2
engine/core/settings/StringSetting.h → engine/core/settings/string_setting.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Types.h"
+#include "types.h"
 
 namespace crown
 {
@@ -59,4 +59,4 @@ private:
 	StringSetting*			m_next;
 };
 
-} // namespace crown
+} // namespace crown

+ 6 - 6
engine/core/strings/DynamicString.h → engine/core/strings/dynamic_string.h

@@ -29,11 +29,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <algorithm>
 #include <cstring>
 
-#include "Assert.h"
-#include "Memory.h"
-#include "StringUtils.h"
-#include "Array.h"
-#include "StringUtils.h"
+#include "assert.h"
+#include "memory.h"
+#include "string_utils.h"
+#include "array.h"
+#include "string_utils.h"
 
 namespace crown
 {
@@ -251,4 +251,4 @@ inline const char* DynamicString::c_str() const
 	return array::begin(m_string);
 }
 
-} // namespace crown
+} // namespace crown

+ 10 - 10
engine/core/strings/Path.cpp → engine/core/strings/path.cpp

@@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Path.h"
+#include "path.h"
 
 namespace crown
 {
@@ -34,7 +34,7 @@ namespace path
 	bool is_valid_segment(const char* segment)
 	{
 		CE_ASSERT(segment != NULL, "Segment must be != NULL");
-		
+
 		size_t segment_len = string::strlen(segment);
 
 		// Empty segment is not valid
@@ -119,7 +119,7 @@ namespace path
 	/// e.g. "/home/project" -> "/home"
 	/// e.g. "/home" -> "/"
 	/// e.g. "home" -> ""
-	/// 
+	///
 	/// The @a path must be valid.
 	void pathname(const char* path, char* str, size_t len)
 	{
@@ -152,7 +152,7 @@ namespace path
 		CE_ASSERT(str != NULL, "Str must be != NULL");
 
 		const char* last_separator = string::find_last(path, '/');
-		
+
 		if (last_separator == string::end(path))
 		{
 			string::strncpy(str, "", len);
@@ -206,9 +206,9 @@ namespace path
 	{
 		CE_ASSERT(path != NULL, "Path must be != NULL");
 		CE_ASSERT(str != NULL, "Str must be != NULL");
-		
+
 		const char* last_dot = string::find_last(path, '.');
-		
+
 		if (last_dot == string::end(path))
 		{
 			string::strncpy(str, "", len);
@@ -229,9 +229,9 @@ namespace path
 	{
 		CE_ASSERT(path != NULL, "Path must be != NULL");
 		CE_ASSERT(str != NULL, "Str must be != NULL");
-		
+
 		const char* last_dot = string::find_last(path, '.');
-		
+
 		string::substring(string::begin(path), last_dot, str, len);
 	}
 
@@ -258,9 +258,9 @@ namespace path
 	{
 		CE_ASSERT(path != NULL, "Path must be != NULL");
 		CE_ASSERT(str != NULL, "Str must be != NULL");
-		
+
 		size_t path_len = string::strlen(path);
-		
+
 		if (path[path_len - 1] == '/')
 		{
 			string::substring(string::begin(path), string::end(path) - 2, str, len);

+ 2 - 2
engine/core/strings/Path.h → engine/core/strings/path.h

@@ -26,12 +26,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "StringUtils.h"
+#include "string_utils.h"
 
 namespace crown
 {
 
-/// @defgroup Path Path 
+/// @defgroup Path Path
 
 /// Functions for operating on strings as file paths.
 ///

+ 3 - 3
engine/core/strings/StringStream.h → engine/core/strings/string_stream.h

@@ -27,9 +27,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include <stdio.h>
-#include "ContainerTypes.h"
-#include "StringUtils.h"
-#include "OS.h"
+#include "container_types.h"
+#include "string_utils.h"
+#include "os.h"
 
 namespace crown
 {

+ 27 - 29
engine/core/strings/StringUtils.h → engine/core/strings/string_utils.h

@@ -29,18 +29,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <cstdio>
 #include <cstring>
 
-#include "Assert.h"
-#include "Types.h"
-#include "Config.h"
-#include "Macros.h"
+#include "assert.h"
+#include "types.h"
+#include "config.h"
+#include "macros.h"
 
 namespace crown
 {
 namespace string
 {
 
-const char* const	EMPTY = "";
-
 //-----------------------------------------------------------------------------
 inline bool is_alpha(char c)
 {
@@ -120,7 +118,7 @@ inline char* strncat(char* dest, const char* src, size_t len)
 inline const char* begin(const char* str)
 {
 	CE_ASSERT(str != NULL, "Str must be != NULL");
-	
+
 	return str;
 }
 
@@ -128,7 +126,7 @@ inline const char* begin(const char* str)
 inline const char* end(const char* str)
 {
 	CE_ASSERT(str != NULL, "Str must be != NULL");
-	
+
 	return str + string::strlen(str) + 1;
 }
 
@@ -138,17 +136,17 @@ inline const char* find_first(const char* str, char c)
 	CE_ASSERT(str != NULL, "Str must be != NULL");
 
 	const char* str_begin = string::begin(str);
-	
+
 	while (str_begin != string::end(str))
 	{
 		if ((*str_begin) == c)
 		{
 			return str_begin;
 		}
-		
+
 		str_begin++;
 	}
-	
+
 	return string::end(str);
 }
 
@@ -156,19 +154,19 @@ inline const char* find_first(const char* str, char c)
 inline const char* find_last(const char* str, char c)
 {
 	CE_ASSERT(str != NULL, "Str must be != NULL");
-	
+
 	const char* str_end = string::end(str) - 1;
-	
+
 	while (str_end != string::begin(str) - 1)
 	{
 		if ((*str_end) == c)
 		{
 			return str_end;
 		}
-		
+
 		str_end--;
 	}
-	
+
 	return string::end(str);
 }
 
@@ -178,15 +176,15 @@ inline void substring(const char* begin, const char* end, char* out, size_t len)
 	CE_ASSERT(begin != NULL, "Begin must be != NULL");
 	CE_ASSERT(end != NULL, "End must be != NULL");
 	CE_ASSERT(out != NULL, "Out must be != NULL");
-	
+
 	size_t i = 0;
-	
+
 	char* out_iterator = out;
 
 	while (begin != end && i < len)
 	{
 		(*out_iterator) = (*begin);
-		
+
 		begin++;
 		out_iterator++;
 		i++;
@@ -232,7 +230,7 @@ inline float parse_float(const char* string)
 }
 
 //-----------------------------------------------------------------------------
-inline float parse_double(const char* string)
+inline double parse_double(const char* string)
 {
 	double val;
 	int ok = sscanf(string, "%lf", &val);
@@ -276,17 +274,17 @@ inline uint32_t murmur2_32(const void* key, size_t len, uint32_t seed = 0)
 	{
 		unsigned int k = *(unsigned int *)data;
 
-		k *= m; 
-		k ^= k >> r; 
-		k *= m; 
-		
-		h *= m; 
+		k *= m;
+		k ^= k >> r;
+		k *= m;
+
+		h *= m;
 		h ^= k;
 
 		data += 4;
 		len -= 4;
 	}
-	
+
 	// Handle the last few bytes of the input array
 	switch(len)
 	{
@@ -319,12 +317,12 @@ inline uint64_t murmur2_64(const void* key, int len, uint64_t seed = 0)
 	{
 		uint64_t k = *data++;
 
-		k *= m; 
-		k ^= k >> r; 
-		k *= m; 
+		k *= m;
+		k ^= k >> r;
+		k *= m;
 
 		h ^= k;
-		h *= m; 
+		h *= m;
 	}
 
 	const unsigned char * data2 = (const unsigned char*)data;

+ 18 - 2
engine/os/android/AtomicInt.h → engine/core/thread/atomic_int.h

@@ -26,8 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#ifndef __GNUG__
-	#error "Compiler not supported"
+#include "config.h"
+
+#if CROWN_PLATFORM_WINDOWS
+	#include "types.h"
+	#include "win_headers.h"
 #endif
 
 namespace crown
@@ -42,18 +45,31 @@ struct AtomicInt
 
 	int load() const
 	{
+#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
 		__sync_fetch_and_add(&m_val, 0);
 		return m_val;
+#elif CROWN_PLATFORM_WINDOWS
+		InterlockedExchangeAdd(&m_val, (int32_t)0);
+		return m_val;
+#endif
 	}
 
 	void store(int val)
 	{
+#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
 		__sync_lock_test_and_set(&m_val, val);
+#elif CROWN_PLATFORM_WINDOWS
+		InterlockedExchange(&m_val, val);
+#endif
 	}
 
 private:
 
+#if CROWN_PLATFORM_POSIX && CROWN_COMPILER_GCC
 	mutable int m_val;
+#elif CROWN_PLATFORM_WINDOWS
+	mutable LONG m_val;
+#endif
 };
 
 } // namespace crown

+ 143 - 0
engine/core/thread/mutex.h

@@ -0,0 +1,143 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "config.h"
+#include "types.h"
+#include "assert.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <pthread.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#ifndef WIN32_LEAN_AND_MEAN
+	#define WIN32_LEAN_AND_MEAN 1
+	#endif
+	#include <windows.h>
+#endif
+
+namespace crown
+{
+
+struct Mutex
+{
+	Mutex()
+	{
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutexattr_init(&m_attr);
+		CE_ASSERT(result == 0, "pthread_mutexattr_init: errno = %d", result);
+		result = pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_ERRORCHECK);
+		CE_ASSERT(result == 0, "pthread_mutexattr_settype: errno = %d", result);
+		result = pthread_mutex_init(&m_mutex, &m_attr);
+		CE_ASSERT(result == 0, "pthread_mutex_init: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		InitializeCriticalSection(&m_cs);
+#endif
+	}
+
+	~Mutex()
+	{
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutex_destroy(&m_mutex);
+		CE_ASSERT(result == 0, "pthread_mutex_destroy: errno = %d", result);
+		result = pthread_mutexattr_destroy(&m_attr);
+		CE_ASSERT(result == 0, "pthread_mutexattr_destroy: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		DeleteCriticalSection(&m_cs);
+#endif
+
+	}
+
+	void lock()
+	{
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutex_lock(&m_mutex);
+		CE_ASSERT(result == 0, "pthread_mutex_lock: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		EnterCriticalSection(&m_cs);
+#endif
+	}
+
+	void unlock()
+	{
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_mutex_unlock(&m_mutex);
+		CE_ASSERT(result == 0, "pthread_mutex_unlock: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		LeaveCriticalSection(&m_cs);
+#endif
+	}
+
+public:
+
+#if CROWN_PLATFORM_POSIX
+	pthread_mutex_t m_mutex;
+	pthread_mutexattr_t m_attr;
+#elif CROWN_PLATFORM_WINDOWS
+	CRITICAL_SECTION m_cs;
+#endif
+
+private:
+
+	// Disable copying.
+	Mutex(const Mutex&);
+	Mutex& operator=(const Mutex&);
+};
+
+/// Automatically locks a mutex when created and unlocks when destroyed.
+class ScopedMutex
+{
+public:
+
+	/// Locks the given @a m mutex.
+	ScopedMutex(Mutex& m)
+		: m_mutex(m)
+	{
+		m_mutex.lock();
+	}
+
+	/// Unlocks the mutex passed to ScopedMutex::ScopedMutex()
+	~ScopedMutex()
+	{
+		m_mutex.unlock();
+	}
+
+private:
+
+	Mutex& m_mutex;
+
+private:
+
+	// Disable copying
+	ScopedMutex(const ScopedMutex&);
+	ScopedMutex& operator=(const ScopedMutex&);
+};
+
+} // namespace crown

+ 129 - 0
engine/core/thread/semaphore.h

@@ -0,0 +1,129 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "config.h"
+#include "assert.h"
+#include "mutex.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <pthread.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include "win_headers.h"
+	#include <limits.h>
+#endif
+
+namespace crown
+{
+
+struct Semaphore
+{
+	Semaphore()
+#if CROWN_PLATFORM_POSIX
+		: m_count(0)
+#elif CROWN_PLATFORM_WINDOWS
+		: m_handle(INVALID_HANDLE_VALUE)
+#endif
+	{
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_cond_init(&m_cond, NULL);
+		CE_ASSERT(result == 0, "pthread_cond_init: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		m_handle = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
+		CE_ASSERT(m_handle != NULL, "Unable to create semaphore!");
+		CE_UNUSED(m_handle);
+#endif
+	}
+
+	~Semaphore()
+	{
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_cond_destroy(&m_cond);
+		CE_ASSERT(result == 0, "pthread_cond_destroy: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		CloseHandle(m_handle);
+#endif
+	}
+
+	void post(uint32_t count = 1)
+	{
+#if CROWN_PLATFORM_POSIX
+		m_mutex.lock();
+		for (uint32_t i = 0; i < count; i++)
+		{
+			int result = pthread_cond_signal(&m_cond);
+			CE_ASSERT(result == 0, "pthread_cond_signal: errno = %d", result);
+			CE_UNUSED(result);
+		}
+
+		m_count += count;
+		m_mutex.unlock();
+#elif CROWN_PLATFORM_WINDOWS
+		ReleaseSemaphore(m_handle, count, NULL);
+#endif
+	}
+
+	void wait()
+	{
+#if CROWN_PLATFORM_POSIX
+		m_mutex.lock();
+		while (m_count <= 0)
+		{
+			int result = pthread_cond_wait(&m_cond, &(m_mutex.m_mutex));
+			CE_ASSERT(result == 0, "pthread_cond_wait: errno = %d", result);
+			CE_UNUSED(result);
+		}
+
+		m_count--;
+		m_mutex.unlock();
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD result = WaitForSingleObject(m_handle, INFINITE);
+		CE_ASSERT(result == WAIT_OBJECT_0, "WaitForSingleObject: GetLastError = %d", GetLastError());
+		CE_UNUSED(result);
+#endif
+	}
+
+private:
+
+#if CROWN_PLATFORM_POSIX
+	Mutex m_mutex;
+	pthread_cond_t m_cond;
+	int32_t m_count;
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE m_handle;
+#endif
+
+private:
+
+	// Disable copying
+	Semaphore(const Semaphore& s);
+	Semaphore& operator=(const Semaphore& s);
+};
+
+} // namespace crown

+ 172 - 0
engine/core/thread/thread.h

@@ -0,0 +1,172 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "config.h"
+#include "assert.h"
+#include "types.h"
+#include "semaphore.h"
+
+#if CROWN_PLATFORM_POSIX
+	#include <pthread.h>
+#elif CROWN_PLATFORM_WINDOWS
+	#include "win_headers.h"
+	#include <process.h>
+#endif
+
+namespace crown
+{
+
+typedef int32_t (*ThreadFunction)(void*);
+
+struct Thread
+{
+	Thread()
+#if CROWN_PLATFORM_POSIX
+		: m_handle(0)
+#elif CROWN_PLATFORM_WINDOWS
+		: m_handle(INVALID_HANDLE_VALUE)
+#endif
+		, m_function(NULL)
+		, m_data(NULL)
+		, m_stack_size(0)
+		, m_is_running(false)
+	{
+	}
+
+	~Thread()
+	{
+		if (m_is_running)
+			stop();
+	}
+
+	void start(ThreadFunction func, void* data = NULL, size_t stack_size = 0)
+	{
+		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;
+
+#if CROWN_PLATFORM_POSIX
+		pthread_attr_t attr;
+		int result = pthread_attr_init(&attr);
+		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+		CE_ASSERT(result == 0, "pthread_attr_init: errno = %d", result);
+
+		if (m_stack_size != 0)
+		{
+			result = pthread_attr_setstacksize(&attr, m_stack_size);
+			CE_ASSERT(result == 0, "pthread_attr_setstacksize: errno = %d", result);
+		}
+
+		result = pthread_create(&m_handle, &attr, thread_proc, this);
+		CE_ASSERT(result == 0, "pthread_create: errno = %d", result);
+
+		// Free attr memory
+		result = pthread_attr_destroy(&attr);
+		CE_ASSERT(result == 0, "pthread_attr_destroy: errno = %d", result);
+		CE_UNUSED(result);
+#elif CROWN_PLATFORM_WINDOWS
+		m_handle = CreateThread(NULL, stack_size, Thread::thread_proc, this, 0, NULL);
+		CE_ASSERT(m_handle != NULL, "CreateThread: GetLastError = %d", GetLastError());
+#endif
+
+		m_is_running = true;
+		m_sem.wait();
+	}
+
+	void stop()
+	{
+		CE_ASSERT(m_is_running, "Thread is not running");
+
+#if CROWN_PLATFORM_POSIX
+		int result = pthread_join(m_handle, NULL);
+		CE_ASSERT(result == 0, "pthread_join: errno = %d", result);
+		CE_UNUSED(result);
+		m_handle = 0;
+#elif CROWN_PLATFORM_WINDOWS
+		WaitForSingleObject(m_handle, INFINITE);
+		// GetExitCodeThread(m_handle, &m_exit_code);
+		CloseHandle(m_handle);
+		m_handle = INVALID_HANDLE_VALUE;
+#endif
+
+		m_is_running = false;
+	}
+
+	bool is_running()
+	{
+		return m_is_running;
+	}
+
+private:
+
+	int32_t run()
+	{
+		m_sem.post();
+		return m_function(m_data);
+	}
+
+#if CROWN_PLATFORM_POSIX
+	static void* thread_proc(void* arg)
+	{
+		static int32_t result = -1;
+		result = ((Thread*)arg)->run();
+		return (void*)&result;
+	}
+#elif CROWN_PLATFORM_WINDOWS
+	static DWORD WINAPI thread_proc(void* arg)
+	{
+		Thread* thread = (Thread*) arg;
+		int32_t result = thread->run();
+		return result;
+	}
+#endif
+
+private:
+
+#if CROWN_PLATFORM_POSIX
+	pthread_t m_handle;
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE m_handle;
+#endif
+
+	ThreadFunction m_function;
+	void* m_data;
+	Semaphore m_sem;
+	size_t m_stack_size;
+	bool m_is_running;
+
+private:
+
+	// Disable copying
+	Thread(const Thread&);
+	Thread& operator=(const Thread&);
+};
+
+} // namespace crown

+ 1 - 1
engine/core/Types.h → engine/core/types.h

@@ -29,7 +29,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #define NOMINMAX
 #include <cstddef>
 #include <stdint.h>
-#include "Config.h"
+#include "config.h"
 
 typedef uint32_t StringId32;
 typedef uint64_t StringId64;

Некоторые файлы не были показаны из-за большого количества измененных файлов