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

Merge branch 'lua-env' of https://github.com/taylor001/crown into lua-env

mikymod 12 лет назад
Родитель
Сommit
da0f51aa87
95 измененных файлов с 1111 добавлено и 1004 удалено
  1. 1 1
      CMakeLists.txt
  2. 16 17
      lua/LuaEnvironment.cpp
  3. 3 4
      lua/LuaEnvironment.h
  4. 16 16
      lua/LuaStack.cpp
  5. 19 36
      samples/json/json.cpp
  6. 1 1
      samples/lua/CMakeLists.txt
  7. 7 1
      samples/lua/lua.cpp
  8. 5 5
      src/ArchiveResourceArchive.cpp
  9. 4 4
      src/ArchiveResourceArchive.h
  10. 26 22
      src/CMakeLists.txt
  11. 7 9
      src/Crown.h
  12. 49 57
      src/Device.cpp
  13. 3 3
      src/Device.h
  14. 4 4
      src/FileResourceArchive.cpp
  15. 3 3
      src/FileResourceArchive.h
  16. 197 58
      src/JSONParser.cpp
  17. 83 30
      src/JSONParser.h
  18. 3 3
      src/ResourceArchive.h
  19. 13 9
      src/ResourceManager.cpp
  20. 3 0
      src/ResourceManager.h
  21. 4 4
      src/TextResource.cpp
  22. 5 5
      src/TextureResource.cpp
  23. 2 2
      src/core/Args.cpp
  24. 3 3
      src/core/Assert.h
  25. 1 1
      src/core/bv/Box.h
  26. 1 1
      src/core/bv/Frustum.cpp
  27. 1 1
      src/core/bv/Rect.cpp
  28. 2 2
      src/core/compressors/ZipCompressor.cpp
  29. 2 2
      src/core/containers/IdTable.h
  30. 7 7
      src/core/containers/List.h
  31. 6 6
      src/core/containers/Queue.h
  32. 6 6
      src/core/containers/RBTree.h
  33. 10 10
      src/core/filesystem/BinaryReader.cpp
  34. 4 4
      src/core/filesystem/BinaryReader.h
  35. 10 28
      src/core/filesystem/BinaryWriter.cpp
  36. 4 6
      src/core/filesystem/BinaryWriter.h
  37. 27 57
      src/core/filesystem/DiskFile.cpp
  38. 22 31
      src/core/filesystem/DiskFile.h
  39. 9 9
      src/core/filesystem/File.cpp
  40. 34 42
      src/core/filesystem/File.h
  41. 8 8
      src/core/filesystem/Filesystem.cpp
  42. 4 4
      src/core/filesystem/Filesystem.h
  43. 20 39
      src/core/filesystem/MemoryFile.cpp
  44. 26 32
      src/core/filesystem/MemoryFile.h
  45. 25 36
      src/core/filesystem/NullFile.h
  46. 12 23
      src/core/filesystem/TextReader.cpp
  47. 8 11
      src/core/filesystem/TextReader.h
  48. 4 15
      src/core/filesystem/TextWriter.cpp
  49. 6 9
      src/core/filesystem/TextWriter.h
  50. 3 3
      src/core/math/Mat3.cpp
  51. 3 3
      src/core/math/Mat4.cpp
  52. 1 1
      src/core/math/MathUtils.h
  53. 4 4
      src/core/math/Point2.h
  54. 4 4
      src/core/math/Vec2.h
  55. 4 4
      src/core/math/Vec3.h
  56. 4 4
      src/core/math/Vec4.h
  57. 1 1
      src/core/mem/ProxyAllocator.cpp
  58. 50 0
      src/core/settings/StringSetting.cpp
  59. 31 0
      src/core/settings/StringSetting.h
  60. 3 3
      src/core/strings/Hash.h
  61. 13 13
      src/core/strings/Path.h
  62. 11 11
      src/core/strings/String.h
  63. 4 4
      src/input/EventDispatcher.cpp
  64. 28 38
      src/os/android/OsFile.cpp
  65. 6 8
      src/os/android/OsFile.h
  66. 2 2
      src/os/linux/CMakeLists.txt
  67. 1 1
      src/os/linux/GLXRenderWindow.cpp
  68. 3 3
      src/os/linux/LinuxOS.cpp
  69. 1 1
      src/os/linux/OsFile.h
  70. 35 44
      src/os/posix/OsFile.cpp
  71. 6 8
      src/os/posix/OsFile.h
  72. 2 2
      src/os/posix/TCPSocket.cpp
  73. 3 3
      src/os/posix/UDPSocket.cpp
  74. 4 4
      src/os/win/WinTCPSocket.cpp
  75. 7 7
      src/os/win/WinUDPSocket.cpp
  76. 11 11
      src/renderers/gl/GLRenderer.cpp
  77. 2 2
      src/renderers/gles/GLESRenderer.cpp
  78. 6 6
      src/renderers/gles/GLESUtils.h
  79. 2 2
      tests/allocators.cpp
  80. 8 8
      tests/containers.cpp
  81. 32 32
      tests/paths.cpp
  82. 12 12
      tests/strings.cpp
  83. 8 8
      tools/compilers/Compiler.cpp
  84. 9 9
      tools/compilers/Compiler.h
  85. 5 5
      tools/compilers/ps/PSCompiler.cpp
  86. 4 4
      tools/compilers/ps/PSCompiler.h
  87. 4 4
      tools/compilers/resource-linker.cpp
  88. 7 7
      tools/compilers/tga/TGACompiler.cpp
  89. 7 7
      tools/compilers/tga/TGACompiler.h
  90. 5 5
      tools/compilers/txt/TXTCompiler.cpp
  91. 5 5
      tools/compilers/txt/TXTCompiler.h
  92. 5 5
      tools/compilers/vs/VSCompiler.cpp
  93. 4 4
      tools/compilers/vs/VSCompiler.h
  94. 3 3
      tools/editors/fontgen/fontgen.cpp
  95. 2 2
      tools/editors/world-editor/terrain/Heightfield.cpp

+ 1 - 1
CMakeLists.txt

@@ -22,7 +22,7 @@ set (INCLUDES
 	${CMAKE_SOURCE_DIR}/src/core/math
 	${CMAKE_SOURCE_DIR}/src/core/mem
 	${CMAKE_SOURCE_DIR}/src/core/compressors
-	${CMAKE_SOURCE_DIR}/src/core/streams
+	${CMAKE_SOURCE_DIR}/src/core/filesystem
 	${CMAKE_SOURCE_DIR}/src/core/strings
 	${CMAKE_SOURCE_DIR}/src/core/settings
 	${CMAKE_SOURCE_DIR}/src/os

+ 16 - 17
lua/LuaEnvironment.cpp

@@ -23,24 +23,23 @@ void LuaEnvironment::load_module_function(const char* module, const char* name,
 	luaL_register(m_state, module, entry);
 }
 
-extern "C"
+
+int32_t luaopen_libcrownlua(lua_State* L)
 {
-	int32_t luaopen_libcrownlua(lua_State* L)
-	{
-		LuaEnvironment env(L);
-
-		load_vec2(env);
-		load_vec3(env);
-		load_mat4(env);
-		load_quat(env);
-		load_math(env);
-
-		load_mouse(env);
-		load_keyboard(env);
-		load_accelerometer(env);
-
-		return 1;
-	}
+	LuaEnvironment env(L);
+
+	load_vec2(env);
+	load_vec3(env);
+	load_mat4(env);
+	load_quat(env);
+	load_math(env);
+
+	load_mouse(env);
+	load_keyboard(env);
+	load_accelerometer(env);
+
+	return 1;
 }
 
+
 } // namespace crown

+ 3 - 4
lua/LuaEnvironment.h

@@ -22,10 +22,9 @@ private:
 	lua_State*		m_state;
 };
 
-extern "C"
-{
-	int32_t luaopen_libcrownlua(lua_State* L);
-}
+
+int32_t luaopen_libcrownlua(lua_State* L);
+
 
 void load_vec2(LuaEnvironment& env);
 void load_vec3(LuaEnvironment& env);

+ 16 - 16
lua/LuaStack.cpp

@@ -23,7 +23,7 @@ static uint32_t 		quat_used = 0;
 //-----------------------------------------------------------------------------
 Vec2* next_vec2()
 {
-	ce_assert(vec2_used < LUA_VEC2_BUFFER_SIZE, "Maximum number of Vec2 reached");
+	CE_ASSERT(vec2_used < LUA_VEC2_BUFFER_SIZE, "Maximum number of Vec2 reached");
 
 	return &vec2_buffer[vec2_used++];
 }
@@ -31,7 +31,7 @@ Vec2* next_vec2()
 //-----------------------------------------------------------------------------
 Vec3* next_vec3()
 {
-	ce_assert(vec3_used < LUA_VEC3_BUFFER_SIZE, "Maximum number of Vec3 reached");
+	CE_ASSERT(vec3_used < LUA_VEC3_BUFFER_SIZE, "Maximum number of Vec3 reached");
 
 	return &vec3_buffer[vec3_used++];
 }
@@ -39,7 +39,7 @@ Vec3* next_vec3()
 //-----------------------------------------------------------------------------
 Mat4* next_mat4()
 {
-	ce_assert(mat4_used < LUA_MAT4_BUFFER_SIZE, "Maximum number of Mat4 reached");
+	CE_ASSERT(mat4_used < LUA_MAT4_BUFFER_SIZE, "Maximum number of Mat4 reached");
 
 	return &mat4_buffer[mat4_used++];
 }
@@ -47,7 +47,7 @@ Mat4* next_mat4()
 //-----------------------------------------------------------------------------
 Quat* next_quat()
 {
-	ce_assert(quat_used < LUA_QUAT_BUFFER_SIZE, "Maximum number of Quat reached");
+	CE_ASSERT(quat_used < LUA_QUAT_BUFFER_SIZE, "Maximum number of Quat reached");
 
 	return &quat_buffer[quat_used++];
 }
@@ -85,7 +85,7 @@ void LuaStack::push_string(const char* str, size_t len)
 //-----------------------------------------------------------------------------
 void LuaStack::push_vec2(Vec2* v)
 {
-	ce_assert(v >= &vec2_buffer[0] && v <= &vec2_buffer[LUA_VEC2_BUFFER_SIZE-1], "Vec2 type error");
+	CE_ASSERT(v >= &vec2_buffer[0] && v <= &vec2_buffer[LUA_VEC2_BUFFER_SIZE-1], "Vec2 type error");
 
 	lua_pushlightuserdata(m_state, v);
 }
@@ -93,7 +93,7 @@ void LuaStack::push_vec2(Vec2* v)
 //-----------------------------------------------------------------------------
 void LuaStack::push_vec3(Vec3* v)
 {
-	ce_assert(v >= &vec3_buffer[0] && v <= &vec3_buffer[LUA_VEC3_BUFFER_SIZE-1], "Vec3 type error");
+	CE_ASSERT(v >= &vec3_buffer[0] && v <= &vec3_buffer[LUA_VEC3_BUFFER_SIZE-1], "Vec3 type error");
 
 	lua_pushlightuserdata(m_state, v);
 }
@@ -101,7 +101,7 @@ void LuaStack::push_vec3(Vec3* v)
 //-----------------------------------------------------------------------------
 void LuaStack::push_mat4(Mat4* m)
 {
-	ce_assert(m >= &mat4_buffer[0] && m <= &mat4_buffer[LUA_MAT4_BUFFER_SIZE-1], "Mat4 type error");
+	CE_ASSERT(m >= &mat4_buffer[0] && m <= &mat4_buffer[LUA_MAT4_BUFFER_SIZE-1], "Mat4 type error");
 
 	lua_pushlightuserdata(m_state, m);
 }
@@ -109,7 +109,7 @@ void LuaStack::push_mat4(Mat4* m)
 //-----------------------------------------------------------------------------
 void LuaStack::push_quat(Quat* q)
 {
-	ce_assert(q >= &quat_buffer[0] && q <= &quat_buffer[LUA_MAT4_BUFFER_SIZE-1], "Quat type error");
+	CE_ASSERT(q >= &quat_buffer[0] && q <= &quat_buffer[LUA_MAT4_BUFFER_SIZE-1], "Quat type error");
 
 	lua_pushlightuserdata(m_state, q);
 }
@@ -141,11 +141,11 @@ const char* LuaStack::get_string(int32_t index)
 //-----------------------------------------------------------------------------
 Vec2* LuaStack::get_vec2(int32_t index)
 {
-	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+	CE_ASSERT(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
 
 	Vec2* v = (Vec2*)lua_touserdata(m_state, index);
 
-	ce_assert(v >= &vec2_buffer[0] && v <= &vec2_buffer[LUA_VEC2_BUFFER_SIZE-1], "Vec2 type error");
+	CE_ASSERT(v >= &vec2_buffer[0] && v <= &vec2_buffer[LUA_VEC2_BUFFER_SIZE-1], "Vec2 type error");
 
 	return v;
 }
@@ -153,11 +153,11 @@ Vec2* LuaStack::get_vec2(int32_t index)
 //-----------------------------------------------------------------------------
 Vec3* LuaStack::get_vec3(int32_t index)
 {
-	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+	CE_ASSERT(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
 
 	Vec3* v = (Vec3*)lua_touserdata(m_state, index);
 
-	ce_assert(v >= &vec3_buffer[0] && v <= &vec3_buffer[LUA_VEC3_BUFFER_SIZE-1], "Vec3 type error");
+	CE_ASSERT(v >= &vec3_buffer[0] && v <= &vec3_buffer[LUA_VEC3_BUFFER_SIZE-1], "Vec3 type error");
 
 	return v;
 }
@@ -165,11 +165,11 @@ Vec3* LuaStack::get_vec3(int32_t index)
 //-----------------------------------------------------------------------------
 Mat4* LuaStack::get_mat4(int32_t index)
 {
-	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+	CE_ASSERT(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
 
 	Mat4* m = (Mat4*)lua_touserdata(m_state, index);
 
-	ce_assert(m >= &mat4_buffer[0] && m <= &mat4_buffer[LUA_MAT4_BUFFER_SIZE-1], "Mat4 type error");
+	CE_ASSERT(m >= &mat4_buffer[0] && m <= &mat4_buffer[LUA_MAT4_BUFFER_SIZE-1], "Mat4 type error");
 
 	return m;
 }
@@ -177,11 +177,11 @@ Mat4* LuaStack::get_mat4(int32_t index)
 //-----------------------------------------------------------------------------
 Quat* LuaStack::get_quat(int32_t index)
 {
-	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+	CE_ASSERT(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
 
 	Quat* q = (Quat*)lua_touserdata(m_state, index);
 
-	ce_assert(q >= &quat_buffer[0] && q <= &quat_buffer[LUA_QUAT_BUFFER_SIZE-1], "Quat type error");
+	CE_ASSERT(q >= &quat_buffer[0] && q <= &quat_buffer[LUA_QUAT_BUFFER_SIZE-1], "Quat type error");
 
 	return q;
 }

+ 19 - 36
samples/json/json.cpp

@@ -2,52 +2,35 @@
 #include <string.h>
 #include "JSONParser.h"
 #include "Filesystem.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 
 using namespace crown;
 
+// REMOVE JSON SAMPLE, ADD UNIT TEST
 int main(int argc, char** argv)
 {
-	if (argc != 2)
-	{
-		printf("Configuration root path must be provided. Aborting!");
-		return -1;
-	}
-
-	Filesystem conf_root(argv[1]);
-
-	if (!conf_root.exists("json.json"))
-	{
-		printf("Configuration file does not exists. Aborting!\n");
-		return -1;
-	}
+	// if (argc != 2)
+	// {
+	// 	printf("Configuration root path must be provided. Aborting!");
+	// 	return -1;
+	// }
+
+	// Filesystem conf_root(argv[1]);
+
+	// if (!conf_root.exists("json.json"))
+	// {
+	// 	printf("Configuration file does not exists. Aborting!\n");
+	// 	return -1;
+	// }
 	
-	char dst[10][256];
+	// char dst[10][256];
 
-	FileStream* stream = (FileStream*)conf_root.open("json.json", SOM_READ);
+	// DiskFile* stream = (DiskFile*)conf_root.open("json.json", FOM_READ);
 
- 	JSONParser* parser = new JSONParser(stream);
+ // 	JSONParser* parser = new JSONParser(stream);
 
-	JSONError error;
-	JSONToken* tokens;
 
-	error = parser->parse();
-	tokens = parser->get_tokens();
-
-	for (int i = 0; i < parser->get_tokens_number(); i++)
-	{
-		printf("token[%d]\n", i);
-		printf("type: %d\n", tokens[i].m_type);
-		printf("size: %d\n", tokens[i].m_size);
-		printf("start: %d\n",tokens[i].m_start);
-		printf("end: %d\n",tokens[i].m_end);
-		printf("parent token: %d\n",tokens[i].m_parent);
-		printf("\n");
-	}
-
-	printf("return: %d\n", error);
-
-	conf_root.close(stream);
+	// conf_root.close(stream);
 
 	return 0;
 }

+ 1 - 1
samples/lua/CMakeLists.txt

@@ -6,7 +6,7 @@ set (SRC
 
 add_definitions(-Wl,-E)
 add_library (game SHARED ${SRC})
-target_link_libraries(game crown)
+target_link_libraries(game crown crownlua)
 
 install (TARGETS game DESTINATION bin/lua_sample)
 

+ 7 - 1
samples/lua/lua.cpp

@@ -5,6 +5,8 @@
 namespace crown
 {
 
+StringSetting g_boot("boot_file", "lua main file", "lua/game.raw");
+
 lua_State* L;
 
 void init()
@@ -12,7 +14,11 @@ void init()
 	L = luaL_newstate();
 	luaL_openlibs(L);
 
-	if (luaL_loadfile(L, "/home/mikymod/test/res_linux/lua/game.raw") || lua_pcall(L, 0, 0, 0))
+	lua_cpcall(L, luaopen_libcrownlua, NULL);
+
+	const char* path = device()->filesystem()->os_path(g_boot.value());
+
+	if (luaL_loadfile(L, path) || lua_pcall(L, 0, 0, 0))
 	{
 		os::printf("error: %s", lua_tostring(L, -1));
 	}

+ 5 - 5
src/ArchiveResourceArchive.cpp

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "ArchiveResourceArchive.h"
 #include "Filesystem.h"
 #include "Resource.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Log.h"
 
 namespace crown
@@ -40,7 +40,7 @@ ArchiveResourceArchive::ArchiveResourceArchive(Filesystem& fs) :
 	m_entries(NULL)
 {
 	// FIXME Default archive name
-	m_archive_file = (FileStream*)m_filesystem.open("archive.bin", SOM_READ);
+	m_archive_file = (DiskFile*)m_filesystem.open("archive.bin", FOM_READ);
 	
 	ArchiveHeader header;
 	
@@ -76,7 +76,7 @@ ArchiveResourceArchive::~ArchiveResourceArchive()
 }
 
 //-----------------------------------------------------------------------------
-FileStream* ArchiveResourceArchive::open(ResourceId name)
+DiskFile* ArchiveResourceArchive::open(ResourceId name)
 {
 	// Search the resource in the archive
 	for (uint32_t i = 0; i < m_entries_count; i++)
@@ -86,7 +86,7 @@ FileStream* ArchiveResourceArchive::open(ResourceId name)
 			// If found, seek to the first byte of the resource data
 			m_archive_file->seek(m_entries[i].offset);
 
-			return (FileStream*)m_archive_file;
+			return (DiskFile*)m_archive_file;
 		}
 	}
 
@@ -94,7 +94,7 @@ FileStream* ArchiveResourceArchive::open(ResourceId name)
 }
 
 //-----------------------------------------------------------------------------
-void ArchiveResourceArchive::close(FileStream* resource)
+void ArchiveResourceArchive::close(DiskFile* resource)
 {
 	// Does nothing, the stream is automatically closed at exit.
 	(void)resource;

+ 4 - 4
src/ArchiveResourceArchive.h

@@ -32,7 +32,7 @@ namespace crown
 {
 
 class Filesystem;
-class FileStream;
+class DiskFile;
 
 /// Structure of the archive
 ///
@@ -62,16 +62,16 @@ public:
 					~ArchiveResourceArchive();
 
 	/// @copydoc ResourceArchive::open()
-	FileStream*		open(ResourceId name);
+	DiskFile*		open(ResourceId name);
 
 	/// @copydoc ResourceArchive::close()
-	void			close(FileStream* resource);
+	void			close(DiskFile* resource);
 
 private:
 
 	Filesystem&		m_filesystem;
 
-	FileStream*		m_archive_file;
+	DiskFile*		m_archive_file;
 
 	uint32_t		m_entries_count;
 	ArchiveEntry*	m_entries;

+ 26 - 22
src/CMakeLists.txt

@@ -1,7 +1,6 @@
 set (SRC
 	Camera.cpp
 	Device.cpp
-	Filesystem.cpp
 	MaterialResource.cpp
 	ResourceManager.cpp
 	Skybox.cpp
@@ -21,7 +20,6 @@ set (HEADERS
 	Config.h
 	Crown.h
 	Device.h
-	Filesystem.h
 	Glyph.h
 	MaterialResource.h
 	Resource.h
@@ -111,27 +109,31 @@ set (MATH_HEADERS
 	core/math/Vec4.h
 )
 
-set (STREAMS_SRC
-	core/streams/FileStream.cpp
-	core/streams/MemoryStream.cpp
-	core/streams/Stream.cpp
+set (FILESYSTEM_SRC
+	core/filesystem/DiskFile.cpp
+	core/filesystem/MemoryFile.cpp
+	core/filesystem/File.cpp
 	
-	core/streams/BinaryReader.cpp
-	core/streams/BinaryWriter.cpp
-	core/streams/TextReader.cpp
-	core/streams/TextWriter.cpp
+	core/filesystem/BinaryReader.cpp
+	core/filesystem/BinaryWriter.cpp
+	core/filesystem/TextReader.cpp
+	core/filesystem/TextWriter.cpp
+
+	core/filesystem/Filesystem.cpp
 )
 
-set (STREAMS_HEADERS
-	core/streams/FileStream.h
-	core/streams/MemoryStream.h
-	core/streams/NullStream.h
-	core/streams/Stream.h
+set (FILESYSTEM_HEADERS
+	core/filesystem/DiskFile.h
+	core/filesystem/MemoryFile.h
+	core/filesystem/NullFile.h
+	core/filesystem/File.h
+
+	core/filesystem/BinaryReader.h
+	core/filesystem/BinaryWriter.h
+	core/filesystem/TextReader.h
+	core/filesystem/TextWriter.h
 
-	core/streams/BinaryReader.h
-	core/streams/BinaryWriter.h
-	core/streams/TextReader.h
-	core/streams/TextWriter.h
+	core/filesystem/Filesystem.h
 )
 
 set (STRINGS_SRC
@@ -167,11 +169,13 @@ set (COMPRESSORS_HEADERS
 set (SETTINGS_SRC
 	core/settings/IntSetting.cpp
 	core/settings/FloatSetting.cpp
+	core/settings/StringSetting.cpp
 )
 
 set (SETTINGS_HEADERS
 	core/settings/IntSetting.h
 	core/settings/FloatSetting.h
+	core/settings/StringSetting.h
 )
 
 set (INPUT_SRC
@@ -232,7 +236,7 @@ set (CROWN_SOURCES
 	${BV_SRC}
 	${CONTAINERS_SRC}
 	${MATH_SRC}
-	${STREAMS_SRC}
+	${FILESYSTEM_SRC}
 	${MEM_SRC}
 	${COMPRESSORS_SRC}
 	${SETTINGS_SRC}
@@ -253,7 +257,7 @@ set (CROWN_HEADERS
 	${BV_HEADERS}
 	${CONTAINERS_HEADERS}
 	${MATH_HEADERS}
-	${STREAMS_HEADERS}
+	${FILESYSTEM_HEADERS}
 	${MEM_HEADERS}
 	${COMPRESSORS_HEADERS}
 	${SETTINGS_HEADERS}
@@ -297,7 +301,7 @@ install (FILES ${CORE_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core)
 install (FILES ${BV_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/bv)
 install (FILES ${CONTAINERS_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/containers)
 install (FILES ${MATH_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/math)
-install (FILES ${STREAMS_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/streams)
+install (FILES ${FILESYSTEM_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/filesystem)
 install (FILES ${MEM_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/mem)
 install (FILES ${COMPRESSORS_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/compressors)
 install (FILES ${THREADS_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/core/threads)

+ 7 - 9
src/Crown.h

@@ -75,16 +75,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "MallocAllocator.h"
 #include "ProxyAllocator.h"
 
-// Core/Streams
-#include "Stream.h"
-#include "FileStream.h"
-#include "MemoryStream.h"
-#include "NullStream.h"
-
+// Core/Filesystem
+#include "File.h"
+#include "DiskFile.h"
+#include "MemoryFile.h"
+#include "NullFile.h"
 #include "BinaryReader.h"
 #include "BinaryWriter.h"
 #include "TextReader.h"
 #include "TextWriter.h"
+#include "Filesystem.h"
 
 // Core/Threads
 #include "Thread.h"
@@ -94,6 +94,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 // Core/Settings
 #include "IntSetting.h"
 #include "FloatSetting.h"
+#include "StringSetting.h"
 
 // Engine
 #include "Camera.h"
@@ -110,9 +111,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "MaterialResource.h"
 #include "FontResource.h"
 
-// Engine/Filesystem
-#include "Filesystem.h"
-
 // Engine/Input
 #include "EventDispatcher.h"
 #include "InputManager.h"

+ 49 - 57
src/Device.cpp

@@ -46,6 +46,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Mouse.h"
 #include "Touch.h"
 #include "Accelerometer.h"
+#include "JSONParser.h"
+#include "DiskFile.h"
 
 #ifdef CROWN_BUILD_OPENGL
 	#include "renderers/gl/GLRenderer.h"
@@ -89,8 +91,8 @@ Device::Device() :
 
 	m_game_library(NULL)
 {
-	string::strcpy(m_preferred_root_path, string::EMPTY);
-	string::strcpy(m_preferred_user_path, string::EMPTY);
+	// Select executable dir by default
+	string::strncpy(m_preferred_root_path, os::get_cwd(), os::MAX_PATH_LENGTH);
 }
 
 //-----------------------------------------------------------------------------
@@ -107,35 +109,23 @@ bool Device::init(int argc, char** argv)
 		return false;
 	}
 
-	if (parse_command_line(argc, argv) == false)
-	{
-		return false;
-	}
+	parse_command_line(argc, argv);
+	check_preferred_settings();
 
 	// Initialize
 	Log::i("Initializing Crown Engine %d.%d.%d...", CROWN_VERSION_MAJOR, CROWN_VERSION_MINOR, CROWN_VERSION_MICRO);
 
 	create_filesystem();
 
-	Log::d("Filesystem created.");
-
-	Log::d("Filesystem root path: %s", m_filesystem->root_path());
-
 	create_resource_manager();
 
-	Log::d("Resource manager created.");
-
 	create_input_manager();
 
-	Log::d("Input manager created.");
-
 	create_renderer();
 
-	Log::d("Renderer created.");
-
 	create_debug_renderer();
 
-	Log::d("Debug renderer created.");
+	read_engine_settings();
 
 	Log::i("Crown Engine initialized.");
 
@@ -372,11 +362,7 @@ void Device::unload(ResourceId name)
 //-----------------------------------------------------------------------------
 void Device::reload(ResourceId name)
 {
-	const void* old_resource = m_resource_manager->data(name);
-
-	m_resource_manager->reload(name);
-
-	const void* new_resource = m_resource_manager->data(name);
+	(void)name;
 }
 
 //-----------------------------------------------------------------------------
@@ -394,15 +380,10 @@ const void* Device::data(ResourceId name)
 //-----------------------------------------------------------------------------
 void Device::create_filesystem()
 {
-	// Select current dir if no root path provided
-	if (string::strcmp(m_preferred_root_path, string::EMPTY) == 0)
-	{
-		m_filesystem = new Filesystem(os::get_cwd());
-	}
-	else
-	{
-		m_filesystem = new Filesystem(m_preferred_root_path);
-	}
+	m_filesystem = new Filesystem(m_preferred_root_path);
+
+	Log::d("Filesystem created.");
+	Log::d("Filesystem root path: %s", m_filesystem->root_path());
 }
 
 //-----------------------------------------------------------------------------
@@ -420,6 +401,9 @@ void Device::create_resource_manager()
 
 	// Create resource manager
 	m_resource_manager = new ResourceManager(*m_resource_archive, m_resource_allocator);
+
+	Log::d("Resource manager created.");
+	Log::d("Resource seed: %d", m_resource_manager->seed());
 }
 
 //-----------------------------------------------------------------------------
@@ -427,6 +411,8 @@ void Device::create_input_manager()
 {
 	// Create input manager
 	m_input_manager = new InputManager();
+
+	Log::d("Input manager created.");
 }
 
 //-----------------------------------------------------------------------------
@@ -451,6 +437,8 @@ void Device::create_renderer()
 		exit(EXIT_FAILURE);
 		#endif
 	}
+
+	Log::d("Renderer created.");
 }
 
 //-----------------------------------------------------------------------------
@@ -458,16 +446,17 @@ void Device::create_debug_renderer()
 {
 	// Create debug renderer
 	m_debug_renderer = new DebugRenderer(*m_renderer);
+
+	Log::d("Debug renderer created.");
 }
 
 //-----------------------------------------------------------------------------
-bool Device::parse_command_line(int argc, char** argv)
+void Device::parse_command_line(int argc, char** argv)
 {
 	static ArgsOption options[] = 
 	{
 		"help",       AOA_NO_ARGUMENT,       NULL,        'i',
 		"root-path",  AOA_REQUIRED_ARGUMENT, NULL,        'r',
-		"user-path",  AOA_REQUIRED_ARGUMENT, NULL,        'u',
 		"width",      AOA_REQUIRED_ARGUMENT, NULL,        'w',
 		"height",     AOA_REQUIRED_ARGUMENT, NULL,        'h',
 		"fullscreen", AOA_NO_ARGUMENT,       &m_preferred_window_fullscreen, 1,
@@ -492,27 +481,7 @@ bool Device::parse_command_line(int argc, char** argv)
 			// Root path
 			case 'r':
 			{
-				if (!os::is_absolute_path(args.optarg()))
-				{
-					os::printf("%s: error: the root path must be absolute.\n", argv[0]);
-					return false;
-				}
-
 				string::strcpy(m_preferred_root_path, args.optarg());
-
-				break;
-			}
-			// User path
-			case 'u':
-			{
-				if (!os::is_absolute_path(args.optarg()))
-				{
-					os::printf("%s: error: the user path must be absolute.\n", argv[0]);
-					return false;
-				}
-
-				string::strcpy(m_preferred_user_path, args.optarg());
-
 				break;
 			}
 			// Window width
@@ -536,10 +505,36 @@ bool Device::parse_command_line(int argc, char** argv)
 			}
 		}
 	}
+}
 
-	return true;
+//-----------------------------------------------------------------------------
+void Device::check_preferred_settings()
+{
+	if (!os::is_absolute_path(m_preferred_root_path))
+	{
+		Log::e("The root path must be absolute.");
+		exit(EXIT_FAILURE);
+	}
+
+	if (m_preferred_window_width == 0 || m_preferred_window_height == 0)
+	{
+		Log::e("Window width and height must be greater than zero.");
+		exit(EXIT_FAILURE);
+	}
 }
 
+//-----------------------------------------------------------------------------
+void Device::read_engine_settings()
+{
+	DiskFile* file = m_filesystem->open("crown.cfg", FOM_READ);
+	JSONParser json(file);
+	
+	// const char* value = json.get_array("crown").get_object("utils").get_string("file").to_string();
+
+	// os::printf("Value:\t%s\n", value);
+}
+
+
 //-----------------------------------------------------------------------------
 void Device::print_help_message()
 {
@@ -552,12 +547,9 @@ void Device::print_help_message()
 
 	"  --help                Show this help.\n"
 	"  --root-path <path>    Use <path> as the filesystem root path.\n"
-	"  --user-path <path>    Use <path> as the filesystem user path.\n"
 	"  --width <width>       Set the <width> of the render window.\n"
 	"  --height <width>      Set the <height> of the render window.\n"
 	"  --fullscreen          Start in fullscreen.\n"
-	"  --gl                  Use OpenGL as rendering backend.\n"
-	"  --gles                Use OpenGL|ES as rendering backend.\n"  
 	"  --dev                 Run the engine in development mode\n");
 }
 

+ 3 - 3
src/Device.h

@@ -114,7 +114,9 @@ private:
 	void					create_renderer();
 	void					create_debug_renderer();
 
-	bool					parse_command_line(int argc, char** argv);
+	void					parse_command_line(int argc, char** argv);
+	void					check_preferred_settings();
+	void					read_engine_settings();
 	void					print_help_message();
 
 private:
@@ -125,9 +127,7 @@ private:
 	int32_t					m_preferred_window_fullscreen;
 	int32_t					m_preferred_renderer;
 	int32_t					m_preferred_mode;
-
 	char					m_preferred_root_path[os::MAX_PATH_LENGTH];
-	char					m_preferred_user_path[os::MAX_PATH_LENGTH];
 
 	bool					m_is_init		: 1;
 	bool					m_is_running	: 1;

+ 4 - 4
src/FileResourceArchive.cpp

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "FileResourceArchive.h"
 #include "Filesystem.h"
 #include "Resource.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Log.h"
 #include "String.h"
 
@@ -46,7 +46,7 @@ FileResourceArchive::~FileResourceArchive()
 }
 
 //-----------------------------------------------------------------------------
-FileStream* FileResourceArchive::open(ResourceId name)
+DiskFile* FileResourceArchive::open(ResourceId name)
 {
 	// Convert name/type into strings
 	char resource_name[512];
@@ -60,7 +60,7 @@ FileStream* FileResourceArchive::open(ResourceId name)
 		return NULL;
 	}
 
-	FileStream* file = (FileStream*)m_filesystem.open(resource_name, SOM_READ);
+	DiskFile* file = (DiskFile*)m_filesystem.open(resource_name, FOM_READ);
 
 	file->skip(sizeof(ResourceHeader));
 
@@ -68,7 +68,7 @@ FileStream* FileResourceArchive::open(ResourceId name)
 }
 
 //-----------------------------------------------------------------------------
-void FileResourceArchive::close(FileStream* resource)
+void FileResourceArchive::close(DiskFile* resource)
 {
 	m_filesystem.close(resource);
 }

+ 3 - 3
src/FileResourceArchive.h

@@ -32,7 +32,7 @@ namespace crown
 {
 
 class Filesystem;
-class FileStream;
+class DiskFile;
 
 // The header of every compiled resource file.
 // KEEP IN SYNC WITH CompiledResource struct in Compiler.h!
@@ -54,10 +54,10 @@ public:
 					~FileResourceArchive();
 
 	/// @copydoc ResourceArchive::open()
-	FileStream*		open(ResourceId name);
+	DiskFile*		open(ResourceId name);
 
 	/// @copydoc ResourceArchive::close()
-	void			close(FileStream* resource);
+	void			close(DiskFile* resource);
 
 
 private:

+ 197 - 58
src/JSONParser.cpp

@@ -1,11 +1,18 @@
 #include "JSONParser.h"
-#include "FileStream.h"
+#include "DiskFile.h"
+#include "OS.h"
+#include "String.h"
+#include <cassert>
 
 namespace crown
 {
 
 //--------------------------------------------------------------------------
-JSONParser::JSONParser(Stream* stream, size_t size)
+JSONParser::JSONParser(File* file, size_t size) :
+	m_file(file),
+	m_next_token(0),
+	m_prev_token(-1),
+	m_nodes_count(0)
 {
 	if (size > 1024)
 	{
@@ -18,61 +25,40 @@ JSONParser::JSONParser(Stream* stream, size_t size)
 
 	m_size = size;
 
-	m_stream = stream;
+	m_pos = m_file->position();
 
-	m_pos = m_stream->position();
+	parse();
 
-	m_next_token = 0;
-
-	m_prev_token = -1;
-
-	is_init = true;
+	// Test
+	for (int i = 0; i < m_next_token; i++)
+	{
+		m_tokens[i].print();
+	}
 }
 
 //--------------------------------------------------------------------------
 JSONParser::~JSONParser()
 {
-	if (m_size > 1024)
+	if (m_size > 1024 && m_tokens != NULL)
 	{
 		delete m_tokens;
 	}
-	else
-	{
-		delete [] m_tokens_list;
-	}
 }
 
 //--------------------------------------------------------------------------
-// void
-// JSONParser::shutdown()
-// {
-// 	m_pos = 0;
-// 	m_next_token = 0;
-// 	m_prev_token = -1;
-
-// 	is_init = false;
-// }
-
-//--------------------------------------------------------------------------
-JSONError 
-JSONParser::parse()
+JSONError JSONParser::parse()
 {
-	if (!is_init)
-	{
-		return JSON_NO_INIT; 
-	}
-
 	JSONError error;
 	JSONToken* token;
 
 	char c;
 
-	while(!m_stream->end_of_stream())
+	while(!m_file->end_of_file())
 	{
 		JSONType type;
 
-		c = (char)m_stream->read_byte();
-		m_pos = m_stream->position();
+		m_file->read(&c, 1);
+		m_pos = m_file->position();
 
 		switch(c)
 		{
@@ -130,11 +116,12 @@ JSONParser::parse()
 					token = &m_tokens[token->m_parent];
 				}
 
-				token->m_size = token->m_end - token->m_start;
-
+				// token->m_size = token->m_end - token->m_start;
+				fill_token(token, type, token->m_start, token->m_end);
 				break;
 			}
 			case '\"':
+			case '\'':
 			{
 				error = parse_string();
             	if (m_prev_token != -1)
@@ -143,10 +130,13 @@ JSONParser::parse()
             	}
 				break;
 			}
+			case ':':
+			{
+				break;
+			}
             case '\t': 
             case '\r': 
             case '\n': 
-            case ':': 
             case ',': 
             case ' ': 
             {
@@ -189,8 +179,7 @@ JSONParser::parse()
 }
 
 //--------------------------------------------------------------------------
-JSONError
-JSONParser::parse_string()
+JSONError JSONParser::parse_string()
 {
 	JSONToken* token;
 
@@ -198,10 +187,10 @@ JSONParser::parse_string()
 
 	char c; 
 
-	while(!m_stream->end_of_stream())
+	while(!m_file->end_of_file())
 	{	
-		c = (char) m_stream->read_byte();
-		m_pos = m_stream->position();
+		m_file->read(&c, 1);
+		m_pos = m_file->position();
 
 		if (c == '\"' || c == '\'')
 		{
@@ -221,8 +210,8 @@ JSONParser::parse_string()
 
 		if (c == '\\')
 		{
-			c = (char)m_stream->read_byte();
-			m_pos = m_stream->position();
+			m_file->read(&c, 1);
+			m_pos = m_file->position();
 
 			switch(c)
 			{
@@ -251,23 +240,33 @@ JSONParser::parse_string()
 }
 
 //--------------------------------------------------------------------------
-JSONError
-JSONParser::parse_primitive()
+JSONError JSONParser::parse_primitive()
 {
 	JSONToken* token;
+	JSONType type = JSON_INT;
 
-	int start = m_stream->position();
+	int start = m_file->position();
 
 	char c;
 
-	while (!m_stream->end_of_stream())
+	while (!m_file->end_of_file())
 	{
-		c = (char)m_stream->read_byte();
-		m_pos = m_stream->position();
+		m_file->read(&c, 1);
+		m_pos = m_file->position();
 
 		switch (c)
 		{
-
+			case '.':
+			{
+				type = JSON_FLOAT;
+				break;
+			}
+			case 'r':
+			case 'a':
+			{
+				type = JSON_BOOL;
+				break;
+			}
 			case ' ':
 			case ',': 
 			case '}':
@@ -281,11 +280,11 @@ JSONParser::parse_primitive()
 					return JSON_NO_MEMORY;
 				}
 
-				fill_token(token, JSON_PRIMITIVE, start, m_pos);
+				fill_token(token, type, start, m_pos);
 
 				token->m_parent = m_prev_token;
 
-				m_stream->seek(start);
+				// m_file->seek(start);
 
 				return JSON_SUCCESS;
 			}
@@ -300,8 +299,7 @@ JSONParser::parse_primitive()
 }
 
 //--------------------------------------------------------------------------
-JSONToken* 
-JSONParser::allocate_token()
+JSONToken* JSONParser::allocate_token()
 {
 	JSONToken* token;
 
@@ -310,7 +308,10 @@ JSONParser::allocate_token()
 		return NULL;
 	}	
 
-	token = &m_tokens[m_next_token++];
+	int32_t id = m_next_token++;
+
+	token = &m_tokens[id];
+	token->m_id = id;
 	token->m_start = token->m_end = -1;
 	token->m_size = 0;
 	token->m_parent = -1;
@@ -321,16 +322,26 @@ JSONParser::allocate_token()
 //--------------------------------------------------------------------------
 void JSONParser::fill_token(JSONToken* token, JSONType type, int32_t start, int32_t end)
 {
+	uint32_t cur_pos = m_file->position();
+
 	token->m_type = type;
 	token->m_start = start;
 	token->m_end = end;
 	token->m_size = token->m_end - token->m_start;
+
+	char tmp[token->m_size+1];
+	m_file->seek(token->m_start-1);
+	m_file->read(tmp, token->m_size);
+	tmp[token->m_size] = '\0';
+	string::strcpy(token->m_value, tmp);
+
+	m_file->seek(cur_pos);
 }
 
 //--------------------------------------------------------------------------
 JSONToken* JSONParser::get_tokens()
 {
-	return m_tokens;
+	return m_tokens_list;
 }
 
 //--------------------------------------------------------------------------
@@ -339,4 +350,132 @@ int32_t JSONParser::get_tokens_number()
 	return m_next_token;
 }
 
+//--------------------------------------------------------------------------
+JSONParser&	JSONParser::get_object(const char* key)
+{
+	int32_t begin = m_nodes_count != 0 ? m_nodes[m_nodes_count-1].m_id : 0;
+	// For each token
+	for (int i = begin; i < m_next_token; i++)
+	{
+		// Check key and type
+		if ((string::strcmp(m_tokens[i].m_value, key) == 0)	&& m_tokens[i].m_type == JSON_STRING)
+		{
+			// Check if the successive token is an array
+			assert(m_tokens[i+1].m_type == JSON_OBJECT);
+
+			// Store token's id in a json node
+			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
+			m_nodes[m_nodes_count].m_type = JSON_OBJECT;
+			m_nodes[m_nodes_count].print();
+
+			// If token stored has parent
+			if (m_tokens[i+1].has_parent())
+			{
+				// Check if precedent token stored is the parent of current token
+				assert(m_nodes_count && m_nodes[m_nodes_count-1].m_id == m_tokens[i+1].m_parent);
+			}
+
+			break;
+		}
+	}
+	// Incremente nodes count for the next token
+	m_nodes_count++;
+
+	return *this;
+}
+
+//--------------------------------------------------------------------------
+JSONParser& JSONParser::get_array(const char* key)
+{
+	int32_t begin = m_nodes_count != 0 ? m_nodes[m_nodes_count-1].m_id : 0;
+
+	// For each token
+	for (int i = begin; i < m_next_token; i++)
+	{
+		// Check key and type
+		if ((string::strcmp(m_tokens[i].m_value, key) == 0)	&& m_tokens[i].m_type == JSON_STRING)
+		{
+			// Check if the successive token is an array
+			assert(m_tokens[i+1].m_type == JSON_ARRAY);
+
+			// Store token's id in a json node
+			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
+			m_nodes[m_nodes_count].m_type = JSON_ARRAY;
+			m_nodes[m_nodes_count].print();
+
+			// If token stored has parent
+			if (m_tokens[i+1].has_parent())
+			{
+				// Check if precedent token stored is the parent of current token
+				assert(m_nodes_count && m_nodes[m_nodes_count-1].m_id == m_tokens[i+1].m_parent);
+			}
+
+			break;
+		}
+	}
+	// Incremente nodes count for the next token
+	m_nodes_count++;
+
+	return *this;
+}
+
+//--------------------------------------------------------------------------
+JSONParser&	JSONParser::get_string(const char* key)
+{
+	int32_t begin = m_nodes_count != 0 ? m_nodes[m_nodes_count-1].m_id : 0;
+
+	// For each token
+	for (int i = begin; i < m_next_token; i++)
+	{
+		// Check key and type
+		if ((string::strcmp(m_tokens[i].m_value, key) == 0)	&& m_tokens[i].m_type == JSON_STRING)
+		{
+			// Check if the successive token is an array
+			assert(m_tokens[i+1].m_type == JSON_STRING);
+
+			// Store token's id in a json node
+			m_nodes[m_nodes_count].m_id = m_tokens[i+1].m_id;	
+			m_nodes[m_nodes_count].m_type = JSON_STRING;
+			m_nodes[m_nodes_count].print();
+
+			// If token stored has parent
+			if (m_tokens[i+1].has_parent())
+			{
+				// Check if precedent token stored is the parent of current token
+				assert(m_nodes_count && m_nodes[m_nodes_count-1].m_id == m_tokens[i+1].m_parent);
+			}
+
+			break;
+		}
+	}
+	// Incremente nodes count for the next token
+	m_nodes_count++;
+
+	return *this;
+}
+
+//--------------------------------------------------------------------------
+JSONParser& JSONParser::get_float(const char* key)
+{
+
+}
+
+//--------------------------------------------------------------------------
+JSONParser&	JSONParser::get_int(const char* key)
+{
+
+}
+
+//--------------------------------------------------------------------------
+JSONParser& JSONParser::get_bool(const char* key)
+{
+
+}
+
+const char* JSONParser::to_string()
+{
+	return m_tokens[m_nodes[m_nodes_count-1].m_id].m_value;
+}
+
+
 } //namespace crown

+ 83 - 30
src/JSONParser.h

@@ -1,8 +1,11 @@
 #pragma once
 
+#include <cstdarg>
 #include "Types.h"
 #include "OS.h"
-#include "Stream.h"
+#include "File.h"
+#include "List.h"
+#include "Dictionary.h"
 
 namespace crown
 {
@@ -13,7 +16,11 @@ enum JSONType
 	JSON_PRIMITIVE 	= 0,	// Number, boolean or null
 	JSON_OBJECT 	= 1,	// Object
 	JSON_ARRAY 		= 2,	// Array
-	JSON_STRING 	= 3		// String
+	JSON_STRING 	= 3,
+	JSON_FLOAT		= 4,
+	JSON_INT		= 5,
+	JSON_BOOL 		= 6,
+
 };
 
 /// JSON error typology
@@ -22,30 +29,52 @@ enum JSONError
 	JSON_NO_MEMORY	= 0,	// Not enough token provided
 	JSON_INV_CHAR	= 1,	// Invalid character inside JSON string
 	JSON_INV_PART	= 2,	// JSON string is incompleted
-	JSON_NO_INIT	= 3,	// JSON parser not initialized
-	JSON_SUCCESS	= 4		// Everything OK!
+	JSON_SUCCESS	= 3		// Everything OK!
 };
 
 /// JSONToken is a container which have pointer to a single json entity 
 /// (primitive, object, array or string) of a json file.
 struct JSONToken
 {
-	JSONType	m_type;
-	int32_t 	m_start;
-	int32_t 	m_end;
-	size_t 		m_size;
-	int32_t 	m_parent;
+	static const uint32_t MAX_TOKEN_LEN = 1024;
+
+	JSONType	m_type;					// Token's type
+	int32_t		m_id;					// Token's id
+	char 		m_value[MAX_TOKEN_LEN];	// Token's value
+	int32_t 	m_start;				// Starting byte
+	int32_t 	m_end;					// Ending byte
+	size_t 		m_size;					// Token's dimension
+	int32_t 	m_parent;				// Token's parent
 
 	inline void print()
 	{
-		os::printf("Type:\t%d\n",m_type);
-		os::printf("Start:\t%d\n",m_start);
-		os::printf("End:\t%d\n",m_end);
-		os::printf("Parent:\t%d\n",m_parent);
-		os::printf("Size:\t%d\n",m_size);
+		os::printf("Id:\t%d\n", m_id);
+		os::printf("Value:\t%s\n", m_value);
+		os::printf("Type:\t%d\n", m_type);
+		os::printf("Start:\t%d\n", m_start);
+		os::printf("End:\t%d\n", m_end);
+		os::printf("Parent:\t%d\n", m_parent);
+		os::printf("Size:\t%d\n", m_size);
 		os::printf("\n");		
 	}
 
+	inline bool has_parent()
+	{
+		return m_parent != -1;
+	}
+};
+
+struct JSONNode
+{
+	int32_t 	m_id;
+	JSONType 	m_type;
+
+	inline void print()
+	{
+		os::printf("----------------\n");
+		os::printf("Id:\t%d\n", m_id);
+		os::printf("----------------\n");
+	}
 };
 
 /// JSONParser parses JSON file and stores all relative tokens.
@@ -55,39 +84,60 @@ class JSONParser
 {
 public:
 	/// Constructor
-					JSONParser(Stream* stream, size_t size = 1024);
+					JSONParser(File* file, size_t size = 1024);
 	/// Destructor
 					~JSONParser();
-	// /// Init JSON parser, must be called for each different JSON string
-	// void 			init();
-	// /// Shutdown JSON parser
-	// void			shutdown();
-	/// Parse JSON data
+
+	JSONParser&		get_object(const char* key);
+
+	JSONParser&		get_array(const char* key);
+
+	JSONParser& 	get_string(const char* key);
+
+	JSONParser&		get_float(const char* key);				// MUST BE IMPLEMENTED
+
+	JSONParser&		get_int(const char* key);				// MUST BE IMPLEMENTED
+
+	JSONParser&		get_bool(const char* key);				// MUST BE IMPLEMENTED
+
+	void			to_string(List<const char*>& values);	// MUST BE IMPLEMENTED
+
+	void			to_float(float* values);				// MUST BE IMPLEMENTED
+
+	void			to_int(int* values);					// MUST BE IMPLEMENTED
+
+	void			to_bool(bool* values);					// MUST BE IMPLEMENTED
+
+private:
+	/// Parse JSON data and fill tokens
 	JSONError 		parse();
 	/// Get all tokens
-	JSONToken*		get_tokens();
+	JSONToken*		get_tokens();			// MUST BE REMOVED
 	/// Get next token
-	int32_t			get_tokens_number();
-
-private:
+	int32_t			get_tokens_number();	// MUST BE REMOVED
 	/// Parse string in JSON data
 	JSONError		parse_string();
 	/// Parse number or boolean in JSON data
-	JSONError		parse_primitive();
+	JSONError		parse_primitive();	// MUST BE REMOVED
+	/// Parse boolean in JSON data
+	JSONError		parse_bool();	// MUST BE IMPLEMENTED
+	/// Parse integer in JSON data
+	JSONError		parse_int();	// MUST BE IMPLEMENTED
+	/// Parse float in JSON data
+	JSONError		parse_float();	// MUST BE IMPLEMENTED
 	/// Allocate token node
 	JSONToken* 		allocate_token();
 	/// Fill token and set boundaries
 	void			fill_token(JSONToken* token, JSONType type, int32_t start, int32_t end);
 
-	/// JSON stream of data
-	Stream*			m_stream;
+	/// JSON file of data
+	File*			m_file;
 	/// JSON string offset
 	uint32_t 		m_pos;
 	/// Next token to allocate				
 	int32_t			m_next_token;
 	/// Previous token e.g parent or array		
 	int32_t			m_prev_token;
-
 	/// JSON tokens list, used as default
 	JSONToken		m_tokens_list[1024];
 	/// JSON tokens ptr (used only if we need more then 1024 tokens)
@@ -95,8 +145,11 @@ private:
 	/// m_tokens default size, default 1024
 	size_t			m_size;
 
-	// is JSON parser initilized
-	bool 			is_init;		
+	/// 
+	JSONNode		m_nodes[128];
+	///
+	uint32_t 		m_nodes_count;
+
 };
 
 } // namespace crown

+ 3 - 3
src/ResourceArchive.h

@@ -49,7 +49,7 @@ struct ArchiveEntry
 };
 
 class Filesystem;
-class FileStream;
+class DiskFile;
 
 class ResourceArchive
 {
@@ -63,10 +63,10 @@ public:
 	/// The resource stream points exactly at the start
 	/// of the useful resource data, so you do not have to
 	/// care about skipping headers, metadatas and so on.
-	virtual FileStream*		open(ResourceId name) = 0;
+	virtual DiskFile*		open(ResourceId name) = 0;
 
 	/// Closes the resource file.
-	virtual void			close(FileStream* resource) = 0;
+	virtual void			close(DiskFile* resource) = 0;
 };
 
 } // namespace crown

+ 13 - 9
src/ResourceManager.cpp

@@ -35,7 +35,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Device.h"
 #include "Filesystem.h"
 #include "TextReader.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "TextResource.h"
 #include "TextureResource.h"
 
@@ -53,7 +53,7 @@ ResourceManager::ResourceManager(ResourceArchive& archive, Allocator& allocator)
 	m_background_thread_should_run(true),
 	m_thread(ResourceManager::background_thread, (void*)this, "resource-loader-thread")
 {
-	FileStream* seed_file = device()->filesystem()->open("seed.ini", SOM_READ);
+	DiskFile* seed_file = device()->filesystem()->open("seed.ini", FOM_READ);
 	TextReader reader(*seed_file);
 
 	char tmp_buf[32];
@@ -62,8 +62,6 @@ ResourceManager::ResourceManager(ResourceArchive& archive, Allocator& allocator)
 	device()->filesystem()->close(seed_file);
 
 	sscanf(tmp_buf, "%u", &m_seed);
-
-	Log::d("Seed: %d", m_seed);
 }
 
 //-----------------------------------------------------------------------------
@@ -90,7 +88,7 @@ ResourceId ResourceManager::load(const char* name)
 //-----------------------------------------------------------------------------
 void ResourceManager::unload(ResourceId name)
 {
-	ce_assert(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
+	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 	
 	m_resources_mutex.lock();
 
@@ -114,7 +112,7 @@ void ResourceManager::unload(ResourceId name)
 //-----------------------------------------------------------------------------
 void ResourceManager::reload(ResourceId name)
 {
-	ce_assert(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
+	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 	
 	m_resources_mutex.lock();
 
@@ -154,7 +152,7 @@ bool ResourceManager::has(ResourceId name) const
 //-----------------------------------------------------------------------------
 const void* ResourceManager::data(ResourceId name) const
 {
-	ce_assert(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
+	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 	
 	m_resources_mutex.lock();
 
@@ -168,7 +166,7 @@ const void* ResourceManager::data(ResourceId name) const
 //-----------------------------------------------------------------------------
 bool ResourceManager::is_loaded(ResourceId name) const
 {
-	ce_assert(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
+	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 
 	m_resources_mutex.lock();
 
@@ -182,7 +180,7 @@ bool ResourceManager::is_loaded(ResourceId name) const
 //-----------------------------------------------------------------------------
 uint32_t ResourceManager::references(ResourceId name) const
 {
-	ce_assert(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
+	CE_ASSERT(has(name), "Resource not loaded: %.8X%.8X", name.name, name.type);
 
 	m_resources_mutex.lock();
 
@@ -230,6 +228,12 @@ void ResourceManager::flush()
 	}
 }
 
+//-----------------------------------------------------------------------------
+uint32_t ResourceManager::seed() const
+{
+	return m_seed;
+}
+
 //-----------------------------------------------------------------------------
 void ResourceManager::check_load_queue()
 {

+ 3 - 0
src/ResourceManager.h

@@ -119,6 +119,9 @@ public:
 	/// Forces all the loading requests to complete before preceeding.
 	void					flush();
 
+	/// Returns the seed used to generate resource name hashes.
+	uint32_t				seed() const;
+
 private:
 
 	// Checks the load queue and signal the backgroud about pending

+ 4 - 4
src/TextResource.cpp

@@ -1,5 +1,5 @@
 #include "TextResource.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "ResourceArchive.h"
 #include "Log.h"
 #include "Allocator.h"
@@ -10,9 +10,9 @@ namespace crown
 //-----------------------------------------------------------------------------
 void* TextResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
 {
-	FileStream* stream = archive.open(id);
+	DiskFile* stream = archive.open(id);
 
-	ce_assert(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
+	CE_ASSERT(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
 
 	TextResource* resource = (TextResource*)allocator.allocate(sizeof(TextResource));
 
@@ -32,7 +32,7 @@ void* TextResource::load(Allocator& allocator, ResourceArchive& archive, Resourc
 //-----------------------------------------------------------------------------
 void TextResource::unload(Allocator& allocator, void* resource)
 {
-	ce_assert(resource != NULL, "Resource not loaded");
+	CE_ASSERT(resource != NULL, "Resource not loaded");
 
 	((TextResource*)resource)->length = 0;
 

+ 5 - 5
src/TextureResource.cpp

@@ -1,7 +1,7 @@
 #include "TextureResource.h"
 #include "ResourceArchive.h"
 #include "Log.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Assert.h"
 #include "Allocator.h"
 #include "Device.h"
@@ -13,9 +13,9 @@ namespace crown
 //-----------------------------------------------------------------------------
 void* TextureResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
 {
-	FileStream* stream = archive.open(id);
+	DiskFile* stream = archive.open(id);
 
-	ce_assert(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
+	CE_ASSERT(stream != NULL, "Resource does not exist: %.8X%.8X", id.name, id.type);
 
 	TextureResource* resource = (TextureResource*)allocator.allocate(sizeof(TextureResource));
 
@@ -37,13 +37,13 @@ void* TextureResource::load(Allocator& allocator, ResourceArchive& archive, Reso
 //-----------------------------------------------------------------------------
 void TextureResource::online(void* resource)
 {
-	ce_assert(resource != NULL, "Resource not loaded");
+	CE_ASSERT(resource != NULL, "Resource not loaded");
 }
 
 //-----------------------------------------------------------------------------
 void TextureResource::unload(Allocator& allocator, void* resource)
 {
-	ce_assert(resource != NULL, "Resource not loaded");
+	CE_ASSERT(resource != NULL, "Resource not loaded");
 
 	allocator.deallocate(((TextureResource*)resource)->m_data);
 	allocator.deallocate(resource);

+ 2 - 2
src/core/Args.cpp

@@ -39,8 +39,8 @@ Args::Args(int argc, char** argv, const char* shortopts, const ArgsOption* longo
 	m_scope(argc),
 	m_optarg(NULL)
 {
-	ce_assert(argv != NULL, "Argument vector must be != NULL");
-	ce_assert(shortopts != NULL, "Short argument list must be != NULL");
+	CE_ASSERT(argv != NULL, "Argument vector must be != NULL");
+	CE_ASSERT(shortopts != NULL, "Short argument list must be != NULL");
 	// longopts could be NULL
 }
 

+ 3 - 3
src/core/Assert.h

@@ -30,10 +30,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #ifdef CROWN_DEBUG
-	#define ce_error(file, line, message, ...) do { printf(message, __VA_ARGS__);\
+	#define CE_ERROR(file, line, message, ...) do { printf(message, __VA_ARGS__);\
 				printf("\n\tIn %s:%d\n\n", file, line); abort(); } while(0)
-	#define ce_assert(condition, message, ...) do { if (!(condition)) { ce_error(__FILE__, __LINE__,\
+	#define CE_ASSERT(condition, message, ...) do { if (!(condition)) { CE_ERROR(__FILE__, __LINE__,\
 				"Assertion failed: %s\n\t" message, #condition, ##__VA_ARGS__); } } while(0)
 #else
-	#define ce_assert(condition, message, ...) ((void)0)
+	#define CE_ASSERT(condition, message, ...) ((void)0)
 #endif

+ 1 - 1
src/core/bv/Box.h

@@ -271,7 +271,7 @@ inline void Box::to_vertices(Vec3 v[8]) const
 //-----------------------------------------------------------------------------
 inline Vec3 Box::vertex(uint32_t index) const
 {
-	ce_assert(index < 8, "Index must be < 8");
+	CE_ASSERT(index < 8, "Index must be < 8");
 
 	switch (index)
 	{

+ 1 - 1
src/core/bv/Frustum.cpp

@@ -63,7 +63,7 @@ bool Frustum::contains_point(const Vec3& point) const
 //-----------------------------------------------------------------------------
 Vec3 Frustum::vertex(uint32_t index) const
 {
-	ce_assert(index < 8, "Index must be < 8");
+	CE_ASSERT(index < 8, "Index must be < 8");
 
 	// 0 = Near bottom left
 	// 1 = Near bottom right

+ 1 - 1
src/core/bv/Rect.cpp

@@ -75,7 +75,7 @@ void Rect::vertices(Vec2 v[4]) const
 //-----------------------------------------------------------------------------
 Vec2 Rect::vertex(uint32_t index) const
 {
-	ce_assert(index < 4, "Index must be < 4");
+	CE_ASSERT(index < 4, "Index must be < 4");
 
 	switch (index)
 	{

+ 2 - 2
src/core/compressors/ZipCompressor.cpp

@@ -52,7 +52,7 @@ uint8_t* ZipCompressor::compress(const void* data, size_t in_size, size_t& out_s
 	
 	int32_t ret = ::compress((Bytef*)dest, (uLongf*)&out_size, (const Bytef*)data, (uLongf)in_size);
 	
-	ce_assert(ret == Z_OK, "Failed to compress the data");
+	CE_ASSERT(ret == Z_OK, "Failed to compress the data");
 	
 	return dest;
 }
@@ -66,7 +66,7 @@ uint8_t* ZipCompressor::uncompress(const void* data, size_t in_size, size_t& out
 	
 	int32_t ret = ::uncompress((Bytef*)dest, (uLongf*)&out_size, (const Bytef*)data, (uLongf)in_size);
 	
-	ce_assert(ret == Z_OK, "Failed to uncompress the data");
+	CE_ASSERT(ret == Z_OK, "Failed to uncompress the data");
 	
 	return dest;
 }

+ 2 - 2
src/core/containers/IdTable.h

@@ -134,7 +134,7 @@ inline Id IdTable::create()
 //-----------------------------------------------------------------------------
 inline void IdTable::destroy(Id id)
 {
-	ce_assert(has(id), "IdTable does not have ID: %d,%d", id.id, id.index);
+	CE_ASSERT(has(id), "IdTable does not have ID: %d,%d", id.id, id.index);
 
 	m_ids[id.index].next = m_freelist;
 	m_freelist = id.index;
@@ -149,7 +149,7 @@ inline bool IdTable::has(Id id) const
 //-----------------------------------------------------------------------------
 inline uint16_t IdTable::next_id()
 {
-	ce_assert(m_next_id < m_max_ids, "Maximum number of IDs reached");
+	CE_ASSERT(m_next_id < m_max_ids, "Maximum number of IDs reached");
 
 	return m_next_id++;
 }

+ 7 - 7
src/core/containers/List.h

@@ -165,7 +165,7 @@ inline List<T>::~List()
 template <typename T>
 inline T& List<T>::operator[](uint32_t index)
 {
-	//ce_assert(index < m_size);
+	//CE_ASSERT(index < m_size);
 
 	return m_array[index];
 }
@@ -174,7 +174,7 @@ inline T& List<T>::operator[](uint32_t index)
 template <typename T>
 inline const T& List<T>::operator[](uint32_t index) const
 {
-	//ce_assert(index < m_size);
+	//CE_ASSERT(index < m_size);
 
 	return m_array[index];
 }
@@ -291,7 +291,7 @@ inline uint32_t List<T>::push_back(const T& item)
 template <typename T>
 inline void List<T>::pop_back()
 {
-	ce_assert(m_size > 0, "The list is empty");
+	CE_ASSERT(m_size > 0, "The list is empty");
 
 	m_size--;
 }
@@ -372,7 +372,7 @@ inline T* List<T>::end()
 template <typename T>
 inline T& List<T>::front()
 {
-	ce_assert(m_size > 0, "The list is empty");
+	CE_ASSERT(m_size > 0, "The list is empty");
 
 	return m_array[0];
 }
@@ -381,7 +381,7 @@ inline T& List<T>::front()
 template <typename T>
 inline const T& List<T>::front() const
 {
-	ce_assert(m_size > 0, "The list is empty");
+	CE_ASSERT(m_size > 0, "The list is empty");
 
 	return m_array[0];
 }
@@ -390,7 +390,7 @@ inline const T& List<T>::front() const
 template <typename T>
 inline T& List<T>::back()
 {
-	ce_assert(m_size > 0, "The list is empty");
+	CE_ASSERT(m_size > 0, "The list is empty");
 
 	return m_array[m_size - 1];
 }
@@ -399,7 +399,7 @@ inline T& List<T>::back()
 template <typename T>
 inline const T& List<T>::back() const
 {
-	ce_assert(m_size > 0, "The list is empty");
+	CE_ASSERT(m_size > 0, "The list is empty");
 
 	return m_array[m_size - 1];
 }

+ 6 - 6
src/core/containers/Queue.h

@@ -207,7 +207,7 @@ inline void Queue<T>::push_back(const T& item)
 template <typename T>
 inline void Queue<T>::pop_back()
 {
-	ce_assert(m_size > 0, "The queue is empty");
+	CE_ASSERT(m_size > 0, "The queue is empty");
 
 	m_size--;
 }
@@ -232,7 +232,7 @@ inline void Queue<T>::push_front(const T& item)
 template <typename T>
 inline void Queue<T>::pop_front()
 {
-	ce_assert(m_size > 0, "The queue is empty");
+	CE_ASSERT(m_size > 0, "The queue is empty");
 
 	m_read = (m_read + 1) % m_queue.size();
 
@@ -283,7 +283,7 @@ inline const T* Queue<T>::end() const
 template <typename T>
 inline T& Queue<T>::front()
 {
-	ce_assert(m_size > 0, "The queue is empty");
+	CE_ASSERT(m_size > 0, "The queue is empty");
 
 	return m_queue[m_read];
 }
@@ -292,7 +292,7 @@ inline T& Queue<T>::front()
 template <typename T>
 inline const T& Queue<T>::front() const
 {
-	ce_assert(m_size > 0, "The queue is empty");
+	CE_ASSERT(m_size > 0, "The queue is empty");
 
 	return m_queue[m_read];
 }
@@ -301,7 +301,7 @@ inline const T& Queue<T>::front() const
 template <typename T>
 inline T& Queue<T>::back()
 {
-	ce_assert(m_size > 0, "The queue is empty");
+	CE_ASSERT(m_size > 0, "The queue is empty");
 
 	return (*this)[m_size - 1];
 }
@@ -310,7 +310,7 @@ inline T& Queue<T>::back()
 template <typename T>
 inline const T& Queue<T>::back() const
 {
-	ce_assert(m_size > 0, "The queue is empty");
+	CE_ASSERT(m_size > 0, "The queue is empty");
 
 	return (*this)[m_size - 1];
 }

+ 6 - 6
src/core/containers/RBTree.h

@@ -656,19 +656,19 @@ int32_t RBTree<TKey, TValue>::dbg_verify(Node* n) const
 
 	if (n->left != m_sentinel)
 	{
-		ce_assert(n->left->parent == n);
-		ce_assert(n->item.key > n->left->item.key);
+		CE_ASSERT(n->left->parent == n);
+		CE_ASSERT(n->item.key > n->left->item.key);
 	}
 
 	if (n->right != m_sentinel)
 	{
-		ce_assert(n->right->parent == n);
-		ce_assert(n->item.key < n->right->item.key);
+		CE_ASSERT(n->right->parent == n);
+		CE_ASSERT(n->item.key < n->right->item.key);
 	}
 
 	int32_t bhL = dbg_verify(n->left);
 	int32_t bhR = dbg_verify(n->right);
-	ce_assert(bhL == bhR);
+	CE_ASSERT(bhL == bhR);
 
 	if (n->color == BLACK)
 	{
@@ -678,7 +678,7 @@ int32_t RBTree<TKey, TValue>::dbg_verify(Node* n) const
 	{
 		if (n->parent != NULL && n->parent->color == RED)
 		{
-			ce_assert(false);
+			CE_ASSERT(false);
 		}
 	}
 

+ 10 - 10
src/core/streams/BinaryReader.cpp → src/core/filesystem/BinaryReader.cpp

@@ -24,13 +24,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "BinaryReader.h"
-#include "Stream.h"
+#include "File.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-BinaryReader::BinaryReader(Stream& stream) : m_stream(stream)
+BinaryReader::BinaryReader(File& file) : m_file(file)
 {
 }
 
@@ -38,7 +38,7 @@ BinaryReader::BinaryReader(Stream& stream) : m_stream(stream)
 int8_t BinaryReader::read_byte()
 {
 	int8_t buffer;
-	m_stream.read(&buffer, sizeof(int8_t));
+	m_file.read(&buffer, sizeof(int8_t));
 	return buffer;
 }
 
@@ -46,7 +46,7 @@ int8_t BinaryReader::read_byte()
 int16_t BinaryReader::read_int16()
 {
 	int16_t buffer;
-	m_stream.read(&buffer, sizeof(int16_t));
+	m_file.read(&buffer, sizeof(int16_t));
 	return buffer;
 }
 
@@ -54,7 +54,7 @@ int16_t BinaryReader::read_int16()
 uint16_t BinaryReader::read_uint16()
 {
 	uint16_t buffer;
-	m_stream.read(&buffer, sizeof(uint16_t));
+	m_file.read(&buffer, sizeof(uint16_t));
 	return buffer;
 }
 
@@ -62,7 +62,7 @@ uint16_t BinaryReader::read_uint16()
 int32_t BinaryReader::read_int32()
 {
 	int32_t buffer;
-	m_stream.read(&buffer, sizeof(int32_t));
+	m_file.read(&buffer, sizeof(int32_t));
 	return buffer;
 }
 
@@ -70,7 +70,7 @@ int32_t BinaryReader::read_int32()
 uint32_t BinaryReader::read_uint32()
 {
 	uint32_t buffer;
-	m_stream.read(&buffer, sizeof(uint32_t));
+	m_file.read(&buffer, sizeof(uint32_t));
 	return buffer;
 }
 
@@ -78,7 +78,7 @@ uint32_t BinaryReader::read_uint32()
 int64_t BinaryReader::read_int64()
 {
 	int64_t buffer;
-	m_stream.read(&buffer, sizeof(int64_t));
+	m_file.read(&buffer, sizeof(int64_t));
 	return buffer;
 }
 
@@ -86,7 +86,7 @@ int64_t BinaryReader::read_int64()
 double BinaryReader::read_double()
 {
 	double buffer;
-	m_stream.read(&buffer, sizeof(double));
+	m_file.read(&buffer, sizeof(double));
 	return buffer;
 }
 
@@ -94,7 +94,7 @@ double BinaryReader::read_double()
 float BinaryReader::read_float()
 {
 	float buffer;
-	m_stream.read(&buffer, sizeof(float));
+	m_file.read(&buffer, sizeof(float));
 	return buffer;
 }
 

+ 4 - 4
src/core/streams/BinaryReader.h → src/core/filesystem/BinaryReader.h

@@ -28,14 +28,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-class Stream;
+class File;
 
-/// A reader that offers a convenient way to read from a Stream
+/// A reader that offers a convenient way to read from a File
 class BinaryReader
 {
 public:
 
-						BinaryReader(Stream& s);
+						BinaryReader(File& file);
 
 	int8_t				read_byte();
 	int16_t				read_int16();
@@ -48,7 +48,7 @@ public:
 
 private:
 
-	Stream&				m_stream;
+	File&				m_file;
 };
 
 } // namespace crown

+ 10 - 28
src/core/streams/BinaryWriter.cpp → src/core/filesystem/BinaryWriter.cpp

@@ -24,80 +24,62 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "BinaryWriter.h"
-#include "Stream.h"
+#include "File.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-BinaryWriter::BinaryWriter(Stream& stream) : m_stream(stream)
+BinaryWriter::BinaryWriter(File& file) : m_file(file)
 {
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_byte(int8_t buffer)
 {
-	m_stream.write(&buffer, sizeof(int8_t));
+	m_file.write(&buffer, sizeof(int8_t));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_int16(int16_t buffer)
 {
-	m_stream.write(&buffer, sizeof(int16_t));
+	m_file.write(&buffer, sizeof(int16_t));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_uint16(uint16_t buffer)
 {
-	m_stream.write(&buffer, sizeof(uint16_t));
+	m_file.write(&buffer, sizeof(uint16_t));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_int32(int32_t buffer)
 {
-	m_stream.write(&buffer, sizeof(int32_t));
+	m_file.write(&buffer, sizeof(int32_t));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_uint32(uint32_t buffer)
 {
-	m_stream.write(&buffer, sizeof(uint32_t));
+	m_file.write(&buffer, sizeof(uint32_t));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_int64(int64_t buffer)
 {
-	m_stream.write(&buffer, sizeof(int64_t));
+	m_file.write(&buffer, sizeof(int64_t));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_double(double buffer)
 {
-	m_stream.write(&buffer, sizeof(double));
+	m_file.write(&buffer, sizeof(double));
 }
 
 //-----------------------------------------------------------------------------
 void BinaryWriter::write_float(float buffer)
 {
-	m_stream.write(&buffer, sizeof(float));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::insert_byte(int8_t val, size_t offset)
-{
-	size_t tmpSize = m_stream.size() - offset;
-	int8_t* tmp = new int8_t[tmpSize];
-
-	m_stream.seek(offset);
-	m_stream.read(tmp, tmpSize);
-
-	m_stream.seek(offset);
-
-	m_stream.write_byte(val);
-
-	m_stream.write(tmp, tmpSize);
-
-	delete[] tmp;
+	m_file.write(&buffer, sizeof(float));
 }
 
 } // namespace crown

+ 4 - 6
src/core/streams/BinaryWriter.h → src/core/filesystem/BinaryWriter.h

@@ -28,14 +28,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-class Stream;
+class File;
 
-/// A writer that offers a convenient way to write to a Stream
+/// A writer that offers a convenient way to write to a File
 class BinaryWriter
 {
 public:
 
-						BinaryWriter(Stream& s);
+						BinaryWriter(File& file);
 
 	void				write_byte(int8_t);
 	void				write_int16(int16_t);
@@ -46,11 +46,9 @@ public:
 	void				write_double(double);
 	void				write_float(float);
 
-	void				insert_byte(int8_t val, size_t offset);
-
 private:
 
-	Stream&				m_stream;
+	File&				m_file;
 };
 
 } // namespace crown

+ 27 - 57
src/core/streams/FileStream.cpp → src/core/filesystem/DiskFile.cpp

@@ -23,7 +23,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Types.h"
 #include "Log.h"
 #include "MathUtils.h"
@@ -32,21 +32,21 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-FileStream::FileStream(StreamOpenMode mode, const char* filename) :
-	Stream(mode),
+DiskFile::DiskFile(FileOpenMode mode, const char* filename) :
+	File(mode),
+	m_file(filename, mode),
 	m_last_was_read(true)
 {
-	m_file.open(filename, mode);
 }
 
 //-----------------------------------------------------------------------------
-FileStream::~FileStream()
+DiskFile::~DiskFile()
 {
 	//m_file.close();
 }
 
 //-----------------------------------------------------------------------------
-void FileStream::seek(size_t position)
+void DiskFile::seek(size_t position)
 {
 	check_valid();
 
@@ -54,7 +54,7 @@ void FileStream::seek(size_t position)
 }
 
 //-----------------------------------------------------------------------------
-void FileStream::seek_to_end()
+void DiskFile::seek_to_end()
 {
 	check_valid();
 
@@ -62,7 +62,7 @@ void FileStream::seek_to_end()
 }
 
 //-----------------------------------------------------------------------------
-void FileStream::skip(size_t bytes)
+void DiskFile::skip(size_t bytes)
 {
 	check_valid();
 
@@ -70,7 +70,7 @@ void FileStream::skip(size_t bytes)
 }
 
 //-----------------------------------------------------------------------------
-uint8_t FileStream::read_byte()
+void DiskFile::read(void* buffer, size_t size)
 {
 	check_valid();
 
@@ -80,29 +80,27 @@ uint8_t FileStream::read_byte()
 		m_file.seek(0);
 	}
 
-	uint8_t buffer;
-
-	ce_assert(m_file.read(&buffer, 1) == 1, "Failed to read from file");
-
-	return buffer;
+	size_t bytes_read = m_file.read(buffer, size);
+	CE_ASSERT(bytes_read == size, "Failed to read from file");
 }
 
 //-----------------------------------------------------------------------------
-void FileStream::read(void* buffer, size_t size)
+void DiskFile::write(const void* buffer, size_t size)
 {
 	check_valid();
 
-	if (!m_last_was_read)
+	if (m_last_was_read)
 	{
-		m_last_was_read = true;
+		m_last_was_read = false;
 		m_file.seek(0);
 	}
 
-	ce_assert(m_file.read(buffer, size) == size, "Failed to read from file");
+	size_t bytes_written = m_file.write(buffer, size);
+	CE_ASSERT(bytes_written == size, "Failed to write to file");
 }
 
 //-----------------------------------------------------------------------------
-bool FileStream::copy_to(Stream& stream, size_t size)
+bool DiskFile::copy_to(File& file, size_t size)
 {
 	check_valid();
 
@@ -125,7 +123,7 @@ bool FileStream::copy_to(Stream& stream, size_t size)
 			{
 				if (read_bytes != 0)
 				{
-					stream.write(buff, read_bytes);
+					file.write(buff, read_bytes);
 				}
 			}
 
@@ -134,7 +132,7 @@ bool FileStream::copy_to(Stream& stream, size_t size)
 			return false;
 		}
 
-		stream.write(buff, read_bytes);
+		file.write(buff, read_bytes);
 		tot_read_bytes += read_bytes;
 	}
 
@@ -143,47 +141,19 @@ bool FileStream::copy_to(Stream& stream, size_t size)
 }
 
 //-----------------------------------------------------------------------------
-bool FileStream::end_of_stream() const
+bool DiskFile::end_of_file() const
 {
 	return position() == size();
 }
 
 //-----------------------------------------------------------------------------
-bool FileStream::is_valid() const
+bool DiskFile::is_valid() const
 {
 	return m_file.is_open();
 }
 
 //-----------------------------------------------------------------------------
-void FileStream::write_byte(uint8_t val)
-{
-	check_valid();
-
-	if (m_last_was_read)
-	{
-		m_last_was_read = false;
-		m_file.seek(0);
-	}
-
-	ce_assert(m_file.write(&val, 1) == 1, "Failed to write to file");
-}
-
-//-----------------------------------------------------------------------------
-void FileStream::write(const void* buffer, size_t size)
-{
-	check_valid();
-
-	if (m_last_was_read)
-	{
-		m_last_was_read = false;
-		m_file.seek(0);
-	}
-
-	ce_assert(m_file.write(buffer, size) == size, "Failed to write to file");
-}
-
-//-----------------------------------------------------------------------------
-void FileStream::flush()
+void DiskFile::flush()
 {
 	check_valid();
 	
@@ -191,7 +161,7 @@ void FileStream::flush()
 }
 
 //-----------------------------------------------------------------------------
-size_t FileStream::position() const
+size_t DiskFile::position() const
 {
 	check_valid();
 
@@ -199,7 +169,7 @@ size_t FileStream::position() const
 }
 
 //-----------------------------------------------------------------------------
-size_t FileStream::size() const
+size_t DiskFile::size() const
 {
 	check_valid();
 	
@@ -207,7 +177,7 @@ size_t FileStream::size() const
 }
 
 //-----------------------------------------------------------------------------
-bool FileStream::can_read() const
+bool DiskFile::can_read() const
 {
 	check_valid();
 
@@ -215,7 +185,7 @@ bool FileStream::can_read() const
 }
 
 //-----------------------------------------------------------------------------
-bool FileStream::can_write() const
+bool DiskFile::can_write() const
 {
 	check_valid();
 
@@ -223,7 +193,7 @@ bool FileStream::can_write() const
 }
 
 //-----------------------------------------------------------------------------
-bool FileStream::can_seek() const
+bool DiskFile::can_seek() const
 {
 	return true;
 }

+ 22 - 31
src/core/streams/FileStream.h → src/core/filesystem/DiskFile.h

@@ -26,82 +26,73 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Assert.h"
-
-#include "Stream.h"
+#include "OsFile.h"
 #include "File.h"
 
 namespace crown
 {
 
-
-/// File stream.
 /// Provides common facilities to access files on disk.
-class FileStream: public Stream
+class DiskFile: public File
 {
 public:
 
 	/// Opens @filename with specified @mode
-					FileStream(StreamOpenMode mode, const char* filename);
-	virtual			~FileStream();
+					DiskFile(FileOpenMode mode, const char* filename);
+	virtual			~DiskFile();
 
-	/// @copydoc Stream::seek() 
+	/// @copydoc File::seek() 
 	void			seek(size_t position);
 
-	/// @copydoc Stream::seek_to_end() 
+	/// @copydoc File::seek_to_end() 
 	void			seek_to_end();
 
-	/// @copydoc Stream::skip() 
+	/// @copydoc File::skip() 
 	void			skip(size_t bytes);
 
-	/// @copydoc Stream::read_byte() 
-	uint8_t			read_byte();
-
-	/// @copydoc Stream::read() 
+	/// @copydoc File::read() 
 	void			read(void* buffer, size_t size);
 
-	/// @copydoc Stream::write_byte() 
-	void			write_byte(uint8_t val);
-
-	/// @copydoc Stream::write() 
+	/// @copydoc File::write() 
 	void			write(const void* buffer, size_t size);
 
-	/// @copydoc Stream::copy_to() 
-	bool			copy_to(Stream& stream, size_t size = 0);
+	/// @copydoc File::copy_to() 
+	bool			copy_to(File& file, size_t size = 0);
 
-	/// @copydoc Stream::flush() 
+	/// @copydoc File::flush() 
 	void			flush();
 
-	/// @copydoc Stream::end_of_stream() 
-	bool			end_of_stream() const;
+	/// @copydoc File::end_of_file() 
+	bool			end_of_file() const;
 
-	/// @copydoc Stream::is_valid() 
+	/// @copydoc File::is_valid() 
 	bool			is_valid() const;
 
-	/// @copydoc Stream::size() 
+	/// @copydoc File::size() 
 	size_t			size() const;
 
-	/// @copydoc Stream::position() 
+	/// @copydoc File::position() 
 	size_t			position() const;
 
-	/// @copydoc Stream::can_read() 
+	/// @copydoc File::can_read() 
 	bool			can_read() const;
 
-	/// @copydoc Stream::can_write() 
+	/// @copydoc File::can_write() 
 	bool			can_write() const;
 
-	/// @copydoc Stream::can_seek() 
+	/// @copydoc File::can_seek() 
 	bool			can_seek() const;
 
 protected:
 
-	File			m_file;
+	OsFile			m_file;
 	bool			m_last_was_read;
 
 protected:
 
 	inline void		check_valid() const
 	{
-		ce_assert(m_file.is_open(), "File is not open");
+		CE_ASSERT(m_file.is_open(), "File is not open");
 	}
 };
 

+ 9 - 9
src/core/streams/Stream.cpp → src/core/filesystem/File.cpp

@@ -23,7 +23,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Stream.h"
+#include "File.h"
 #include "Types.h"
 #include "Compressor.h"
 #include "MallocAllocator.h"
@@ -32,7 +32,7 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-bool Stream::compress_to(Stream& stream, size_t size, size_t& zipped_size, Compressor& compressor)
+bool File::compress_to(File& file, size_t size, size_t& zipped_size, Compressor& compressor)
 {
 	MallocAllocator allocator;
 	void* in_buffer = (void*)allocator.allocate(size);
@@ -41,24 +41,24 @@ bool Stream::compress_to(Stream& stream, size_t size, size_t& zipped_size, Compr
 
 	void* compressed_buffer = compressor.compress(in_buffer, size, zipped_size);
 
-	stream.write(compressed_buffer, zipped_size);
+	file.write(compressed_buffer, zipped_size);
 
 	return true;
 }
 
 //-----------------------------------------------------------------------------
-bool Stream::uncompress_to(Stream& stream, size_t& unzipped_size, Compressor& compressor)
+bool File::uncompress_to(File& file, size_t& unzipped_size, Compressor& compressor)
 {
 	MallocAllocator allocator;
 
-	size_t stream_size = size();
-	void* in_buffer = (void*)allocator.allocate(stream_size);
+	size_t file_size = size();
+	void* in_buffer = (void*)allocator.allocate(file_size);
 
-	read(in_buffer, stream_size);
+	read(in_buffer, file_size);
 
-	void* uncompressed_buffer = compressor.uncompress(in_buffer, stream_size, unzipped_size);
+	void* uncompressed_buffer = compressor.uncompress(in_buffer, file_size, unzipped_size);
 
-	stream.write(uncompressed_buffer, unzipped_size);
+	file.write(uncompressed_buffer, unzipped_size);
 
 	return true;
 }

+ 34 - 42
src/core/streams/Stream.h → src/core/filesystem/File.h

@@ -30,98 +30,90 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-enum StreamOpenMode
+enum FileOpenMode
 {
-	SOM_READ		= 1,
-	SOM_WRITE		= 2
+	FOM_READ		= 1,
+	FOM_WRITE		= 2
 };
 
 class Compressor;
 
-/// An abstraction to access data streams.
+/// 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 Stream is an abstraction to interact with these in an uniform way; every stream
+/// A File is an abstraction to interact with these in an uniform way; every file
 /// comes with a convenient set of methods to facilitate reading from it, writing to
 /// it and so on.
-class Stream
+class File
 {
 public:
 
-	/// Constructor
-						Stream(StreamOpenMode mode) : m_open_mode(mode) {}
+	/// Opens the file with the given @mode
+						File(FileOpenMode mode) : m_open_mode(mode) {}
+	virtual				~File() {};
 
-	/// Destructor
-	virtual				~Stream() {};
-
-	/// Sets the position indicator of the stream to position.
+	/// Sets the position indicator of the file to position.
 	virtual void		seek(size_t position) = 0;
 
-	/// Sets the position indicator to the end of the stream
+	/// Sets the position indicator to the end of the file
 	virtual void		seek_to_end() = 0;
 
 	/// Sets the position indicator to bytes after current position
 	virtual void		skip(size_t bytes) = 0;
 
-	/// Reads a byte from the stream starting at current position.
-	virtual uint8_t		read_byte() = 0;
-
-	/// Reads a block of data from the stream.
+	/// Reads a block of data from the file.
 	virtual void		read(void* buffer, size_t size) = 0;
 
-	/// Writes a byte to the stream starting at current position.
-	virtual void		write_byte(uint8_t val) = 0;
-
-	/// Writes a block of data to the stream.
+	/// Writes a block of data to the file.
 	virtual void		write(const void* buffer, size_t size) = 0;
 
-	/// Copies a chunk of 'size' bytes of data from this to another stream.
-	virtual bool		copy_to(Stream& stream, size_t size = 0) = 0;
+	/// 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 stream using compressor.
-	virtual bool		compress_to(Stream& stream, size_t size, size_t& compressed_size, Compressor& compressor);
+	/// 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 stream of data from this to another stream using compressor.
-	virtual bool		uncompress_to(Stream& stream, size_t& uncompressed_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 Stream is attached to a file,
+	/// Generally, when a File is attached to a file,
 	/// write operations are not performed instantly, the output data
 	/// may be stored to a temporary buffer before making its way to
 	/// the file. This method forces all the pending output operations
-	/// to be written to the stream.
+	/// to be written to the file.
 	virtual void		flush() = 0;
 
-	/// Returns whether the stream is valid.
-	/// A stream is valid when the buffer where it operates
-	/// exists. (i.e. a file descriptor is attached to the stream, 
-	/// a memory area is attached to the stream etc.)
+	/// 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, 
+	/// a memory area is attached to the file etc.)
 	virtual bool		is_valid() const = 0;
 
-	/// Returns whether the position is at end of stream.
-	virtual bool		end_of_stream() const = 0;
+	/// Returns whether the position is at end of file.
+	virtual bool		end_of_file() const = 0;
 
-	/// Returns the size of stream in bytes.
+	/// Returns the size of file in bytes.
 	virtual size_t		size() const = 0;
 
-	/// Returns the current position in stream.
+	/// Returns the current position in file.
 	/// Generally, for binary data, it means the number of bytes
-	/// from the beginning of the stream.
+	/// from the beginning of the file.
 	virtual size_t		position() const = 0;
 
-	/// Returns whether the stream can be read.
+	/// Returns whether the file can be read.
 	virtual bool		can_read() const = 0;
 
-	/// Returns whether the stream can be wrote.
+	/// Returns whether the file can be wrote.
 	virtual bool		can_write() const = 0;
 
-	/// Returns whether the stream can be sought.
+	/// Returns whether the file can be sought.
 	virtual bool		can_seek() const = 0;
 
 protected:
 
-	StreamOpenMode		m_open_mode;
+	FileOpenMode		m_open_mode;
 };
 
 } // namespace crown

+ 8 - 8
src/Filesystem.cpp → src/core/filesystem/Filesystem.cpp

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Filesystem.h"
 #include "Log.h"
 #include "OS.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 
 namespace crown
 {
@@ -34,8 +34,8 @@ namespace crown
 //-----------------------------------------------------------------------------
 Filesystem::Filesystem(const char* root_path)
 {
-	ce_assert(root_path != NULL, "Root path must be != NULL");
-	ce_assert(os::is_absolute_path(root_path), "Root path must be absolute");
+	CE_ASSERT(root_path != NULL, "Root path must be != NULL");
+	CE_ASSERT(os::is_absolute_path(root_path), "Root path must be absolute");
 
 	string::strncpy(m_root_path, root_path, os::MAX_PATH_LENGTH);
 }
@@ -184,18 +184,18 @@ const char* Filesystem::os_path(const char* relative_path)
 }
 
 //-----------------------------------------------------------------------------
-FileStream* Filesystem::open(const char* relative_path, StreamOpenMode mode)
+DiskFile* Filesystem::open(const char* relative_path, FileOpenMode mode)
 {
 	FilesystemEntry info;
 
-	ce_assert(get_info(relative_path, info), "File does not exist: %s", relative_path);
-	ce_assert(info.type == FilesystemEntry::FILE, "File is not a regular file: %s", relative_path);
+	CE_ASSERT(get_info(relative_path, info), "File does not exist: %s", relative_path);
+	CE_ASSERT(info.type == FilesystemEntry::FILE, "File is not a regular file: %s", relative_path);
 
-	return new FileStream(mode, info.os_path);
+	return new DiskFile(mode, info.os_path);
 }
 
 //-----------------------------------------------------------------------------
-void Filesystem::close(FileStream* stream)
+void Filesystem::close(DiskFile* stream)
 {
 	delete stream;
 }

+ 4 - 4
src/Filesystem.h → src/core/filesystem/Filesystem.h

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "String.h"
 #include "OS.h"
-#include "Stream.h"
+#include "File.h"
 
 namespace crown
 {
@@ -49,7 +49,7 @@ struct FilesystemEntry
 	char			relative_path[os::MAX_PATH_LENGTH];	///< Relative path of the entry
 };
 
-class FileStream;
+class DiskFile;
 
 /// Provides a platform-independent way to access files and directories
 /// on the host filesystem.
@@ -139,10 +139,10 @@ public:
 	const char*			os_path(const char* relative_path);
 
 	/// Opens the file @relative_path with the specified access @mode
-	FileStream*			open(const char* relative_path, StreamOpenMode mode);
+	DiskFile*			open(const char* relative_path, FileOpenMode mode);
 
 	/// Closes a previously opened file @stream
-	void				close(FileStream* stream);
+	void				close(DiskFile* stream);
 
 private:
 

+ 20 - 39
src/core/streams/MemoryStream.cpp → src/core/filesystem/MemoryFile.cpp

@@ -24,7 +24,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include <stdlib.h>
-#include "MemoryStream.h"
+
+#include "MemoryFile.h"
 #include "MathUtils.h"
 #include "Log.h"
 #include "Types.h"
@@ -100,33 +101,34 @@ void DynamicMemoryBuffer::allocate(size_t capacity)
 {
 	// FIXME
 }
+
 //-----------------------------------------------------------------------------
-MemoryStream::MemoryStream(MemoryBuffer* buffer, StreamOpenMode mode) :
-	Stream(mode),
+MemoryFile::MemoryFile(MemoryBuffer* buffer, FileOpenMode mode) :
+	File(mode),
 	m_memory(buffer),
 	m_memory_offset(0)
 {
 }
 
 //-----------------------------------------------------------------------------
-MemoryStream::~MemoryStream()
+MemoryFile::~MemoryFile()
 {
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::seek(size_t position)
+void MemoryFile::seek(size_t position)
 {
 	check_valid();
 	
 	m_memory_offset = position;
 
-	// Allow seek to m_memory->size() position, that means end of stream,
+	// Allow seek to m_memory->size() position, that means end of file,
 	// reading not allowed but you can write if it's dynamic
-	ce_assert(m_memory_offset <= m_memory->size(), "Trying to seek beyond end of stream");
+	CE_ASSERT(m_memory_offset <= m_memory->size(), "Trying to seek beyond end of file");
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::seek_to_end()
+void MemoryFile::seek_to_end()
 {
 	check_valid();
 
@@ -134,31 +136,18 @@ void MemoryStream::seek_to_end()
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::skip(size_t bytes)
+void MemoryFile::skip(size_t bytes)
 {
 	check_valid();
 
 	m_memory_offset += bytes;
 
-	//Allow seek to m_memory->getSize() position, that means end of stream, reading not allowed but you can write if it's dynamic
-	ce_assert(m_memory_offset <= m_memory->size(), "Trying to skip beyond end of stream");
-}
-
-//-----------------------------------------------------------------------------
-uint8_t MemoryStream::read_byte()
-{
-	check_valid();
-
-	if (m_memory_offset >= m_memory->size())
-	{
-		Log::e("Trying to read beyond the end of stream.");
-	}
-
-	return m_memory->data()[m_memory_offset++];
+	//Allow seek to m_memory->getSize() position, that means end of file, reading not allowed but you can write if it's dynamic
+	CE_ASSERT(m_memory_offset <= m_memory->size(), "Trying to skip beyond end of file");
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::read(void* buffer, size_t size)
+void MemoryFile::read(void* buffer, size_t size)
 {
 	check_valid();
 	uint8_t* src = m_memory->data();
@@ -166,7 +155,7 @@ void MemoryStream::read(void* buffer, size_t size)
 
 	if (m_memory_offset + size > m_memory->size())
 	{
-		Log::e("Trying to read beyond the end of stream.");
+		Log::e("Trying to read beyond the end of file.");
 	}
 
 	for (size_t i = 0; i < size; i++)
@@ -178,25 +167,17 @@ void MemoryStream::read(void* buffer, size_t size)
 }
 
 //-----------------------------------------------------------------------------
-bool MemoryStream::copy_to(Stream& stream, size_t size)
+bool MemoryFile::copy_to(File& file, size_t size)
 {
 	check_valid();
 
-	stream.write(&(m_memory->data()[m_memory_offset]), math::min(m_memory->size()-m_memory_offset, size));
+	file.write(&(m_memory->data()[m_memory_offset]), math::min(m_memory->size()-m_memory_offset, size));
 
 	return true;
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::write_byte(uint8_t val)
-{
-	check_valid();
-	m_memory->write(&val, m_memory_offset, 1);
-	m_memory_offset++;
-}
-
-//-----------------------------------------------------------------------------
-void MemoryStream::write(const void* buffer, size_t size)
+void MemoryFile::write(const void* buffer, size_t size)
 {
 	check_valid();
 	m_memory->write((uint8_t*)buffer, m_memory_offset, size);
@@ -204,13 +185,13 @@ void MemoryStream::write(const void* buffer, size_t size)
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::flush()
+void MemoryFile::flush()
 {
 	return;
 }
 
 //-----------------------------------------------------------------------------
-void MemoryStream::dump()
+void MemoryFile::dump()
 {
 	uint8_t* buff = m_memory->data();
 

+ 26 - 32
src/core/streams/MemoryStream.h → src/core/filesystem/MemoryFile.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
-#include "Stream.h"
+#include "File.h"
 #include "Allocator.h"
 #include "Assert.h"
 
@@ -78,64 +78,58 @@ protected:
 	size_t				m_size;
 };
 
-/// Memory stream.
+/// Memory file.
 /// Access memory buffers.
-class MemoryStream: public Stream
+class MemoryFile: public File
 {
 public:
 
-	/// @copydoc Stream::Stream()
-						MemoryStream(MemoryBuffer* buffer, StreamOpenMode mode);
+	/// @copydoc File::File()
+						MemoryFile(MemoryBuffer* buffer, FileOpenMode mode);
 
-	/// @copydoc Stream::~Stream()
-	virtual				~MemoryStream();
+	/// @copydoc File::~File()
+	virtual				~MemoryFile();
 
-	/// @copydoc Stream::seek()
+	/// @copydoc File::seek()
 	void				seek(size_t position);
 
-	/// @copydoc Stream::seek_to_end()
+	/// @copydoc File::seek_to_end()
 	void				seek_to_end();
 
-	/// @copydoc Stream::skip()
+	/// @copydoc File::skip()
 	void				skip(size_t bytes);
 
-	/// @copydoc Stream::read_byte()
-	uint8_t				read_byte();
-
-	/// @copydoc Stream::read()
+	/// @copydoc File::read()
 	void				read(void* buffer, size_t size);
 
-	/// @copydoc Stream::write_byte()
-	void				write_byte(uint8_t val);
-
-	/// @copydoc Stream::write()
+	/// @copydoc File::write()
 	void				write(const void* buffer, size_t size);
 
-	/// @copydoc Stream::copy_to()
-	bool				copy_to(Stream& stream, size_t size = 0);
+	/// @copydoc File::copy_to()
+	bool				copy_to(File& file, size_t size = 0);
 
-	/// @copydoc Stream::flush()
+	/// @copydoc File::flush()
 	void				flush();
 
-	/// @copydoc Stream::end_of_stream()
-	bool				end_of_stream() const { return size() == m_memory_offset; }
+	/// @copydoc File::end_of_file()
+	bool				end_of_file() const { return size() == m_memory_offset; }
 
-	/// @copydoc Stream::is_valid()
-	bool				is_valid() const { ce_assert(m_memory != NULL, "Memory is NULL"); return m_memory->is_valid(); }
+	/// @copydoc File::is_valid()
+	bool				is_valid() const { CE_ASSERT(m_memory != NULL, "Memory is NULL"); return m_memory->is_valid(); }
 
-	/// @copydoc Stream::size()
-	size_t				size() const { ce_assert(m_memory != NULL, "Memory is NULL"); return m_memory->size(); }
+	/// @copydoc File::size()
+	size_t				size() const { CE_ASSERT(m_memory != NULL, "Memory is NULL"); return m_memory->size(); }
 
-	/// @copydoc Stream::position()
+	/// @copydoc File::position()
 	size_t				position() const { return m_memory_offset; }
 
-	/// @copydoc Stream::can_read()
+	/// @copydoc File::can_read()
 	bool				can_read() const { return true; }
 
-	/// @copydoc Stream::can_write()
+	/// @copydoc File::can_write()
 	bool				can_write() const { return true; }
 
-	/// @copydoc Stream::can_seek()
+	/// @copydoc File::can_seek()
 	bool				can_seek() const { return true; }
 
 	/// Dumps the data to the console.
@@ -143,7 +137,7 @@ public:
 
 protected:
 
-	inline void			check_valid() { ce_assert(m_memory != NULL, "Memory is NULL"); }
+	inline void			check_valid() { CE_ASSERT(m_memory != NULL, "Memory is NULL"); }
 
 	MemoryBuffer*		m_memory;
 	size_t				m_memory_offset;

+ 25 - 36
src/core/streams/NullStream.h → src/core/filesystem/NullFile.h

@@ -25,39 +25,34 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "Stream.h"
+#include "File.h"
 
 namespace crown
 {
 
 
-/// Bit bucket stream.
+/// Bit bucket file.
 /// Discards all data written to it and provides null data reading from it; plain and simple.
-class NullStream: public Stream
+class NullFile: public File
 {
 public:
 
-	/// @copydoc Stream::Stream()
-				NullStream(StreamOpenMode mode) : Stream(mode) {}
+	/// @copydoc File::File()
+				NullFile(FileOpenMode mode) : File(mode) {}
 
-	/// @copydoc Stream::~Stream()
-	virtual		~NullStream() {}
+	/// @copydoc File::~File()
+	virtual		~NullFile() {}
 
-	/// @copydoc Stream::seek()
+	/// @copydoc File::seek()
 	void		seek(size_t position) { (void)position; }
 
-	/// @copydoc Stream::seek_to_end()
+	/// @copydoc File::seek_to_end()
 	void		seek_to_end() {}
 
-	/// @copydoc Stream::skip()
+	/// @copydoc File::skip()
 	void		skip(size_t bytes) { (void)bytes; }
-
-	/// @copydoc Stream::read_byte()
-	/// @note
-	///	Returns always zero
-	uint8_t		read_byte() { return 0; }
 				
-	/// @copydoc Stream::read()
+	/// @copydoc File::read()
 	/// @note
 	///	Fills buffer with zeroes
 	void		read(void* buffer, size_t size)
@@ -68,59 +63,53 @@ public:
 		}
 	}
 
-	/// @copydoc Stream::write_byte()
-	void		write_byte(uint8_t val) { (void)val; }
-
-	/// @copydoc Stream::write()
+	/// @copydoc File::write()
 	void		write(const void* buffer, size_t size) { (void)buffer; (void)size; }
 
-	/// @copydoc Stream::copy_to()
+	/// @copydoc File::copy_to()
 	/// @note
 	///	Returns always true
-	bool		copy_to(Stream& stream, size_t size = 0)
+	bool		copy_to(File& file, size_t size = 0)
 	{
-		for (size_t i = 0; i < size; i++)
-		{
-			stream.write_byte(0);
-		}
-		
+		char zero = 0;
+		file.write(&zero, size);		
 		return true;
 	}
 
-	/// @copydoc Stream::flush()
+	/// @copydoc File::flush()
 	void		flush() {};
 				
-	/// @copydoc Stream::is_valid()
+	/// @copydoc File::is_valid()
 	/// @note
 	///	Returns always true
 	bool		is_valid() { return true; }
 				
-	/// @copydoc Stream::end_of_stream()
+	/// @copydoc File::end_of_file()
 	/// @note
 	///	Returns always false
-	bool		end_of_stream() { return false; }
+	bool		end_of_file() { return false; }
 				
-	/// @copydoc Stream::size()
+	/// @copydoc File::size()
 	/// @note
 	///	Returns always 0xFFFFFFFF
 	size_t		size() { return ~0; }
 				
-	/// @copydoc Stream::position()
+	/// @copydoc File::position()
 	/// @note
 	///	Returns always zero
 	size_t		position() { return 0; }
 				
-	/// @copydoc Stream::can_read()
+	/// @copydoc File::can_read()
 	/// @note
 	///	Returns always true
 	bool		can_read() { return true; }
 				
-	/// @copydoc Stream::can_write()
+	/// @copydoc File::can_write()
 	/// @note
 	///	Returns always true
 	bool		can_write() { return true; }
 				
-	/// @copydoc Stream::can_seek()
+	/// @copydoc File::can_seek()
 	/// @note
 	///	Returns always true
 	bool		can_seek() { return true; }

+ 12 - 23
src/core/streams/TextReader.cpp → src/core/filesystem/TextReader.cpp

@@ -24,50 +24,39 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "TextReader.h"
-#include "Stream.h"
+#include "File.h"
 #include "Types.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-TextReader::TextReader(Stream& stream) : m_stream(stream)
+TextReader::TextReader(File& file) : m_file(file)
 {
 }
 
 //-----------------------------------------------------------------------------
-char TextReader::read_char()
+size_t TextReader::read_string(char* string, size_t size)
 {
-	return m_stream.read_byte();
-}
-
-//-----------------------------------------------------------------------------
-char* TextReader::read_string(char* string, uint32_t count)
-{
-	char currentChar;
-	uint32_t i = 0;
+	char current_char;
+	size_t bytes_read = 0;
 
-	while(!m_stream.end_of_stream() && i < count - 1)
+	while(!m_file.end_of_file() && bytes_read < size - 1)
 	{
-		currentChar = m_stream.read_byte();
-		string[i] = currentChar;
+		m_file.read(&current_char, 1);
+		string[bytes_read] = current_char;
 
-		i++;
+		bytes_read++;
 
-		if (currentChar == '\n')
+		if (current_char == '\n')
 		{
 			break;
 		}
 	}
 
-	if (i == 0)
-	{
-		return NULL;
-	}
-
-	string[i] = '\0';
+	string[bytes_read] = '\0';
 
-	return string;
+	return bytes_read;
 }
 
 } // namespace crown

+ 8 - 11
src/core/streams/TextReader.h → src/core/filesystem/TextReader.h

@@ -28,31 +28,28 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-class Stream;
+class File;
 
-/// A reader that offers a convenient way to read text from a Stream
+/// A reader that offers a convenient way to read text from a File
 class TextReader
 {
 public:
 
-						TextReader(Stream& s);
+						TextReader(File& file);
 
-	/// Read a single character from the stream
-	char				read_char();
-
-	/// Reads characters from stream and stores them as a C string
-	/// into string until (count-1) characters have been read or
-	/// either a newline or the End-of-Stream is reached, whichever
+	/// Reads characters from file and stores them as a C string
+	/// into string until (size-1) characters have been read or
+	/// either a newline or the End-of-File is reached, whichever
 	/// comes first.
 	/// A newline character makes fgets stop reading, but it is considered
 	/// a valid character and therefore it is included in the string copied to string.
 	/// A null character is automatically appended in str after the characters read to
 	/// signal the end of the C string.
-	char*				read_string(char* string, uint32_t count);
+	size_t				read_string(char* string, size_t size);
 
 private:
 
-	Stream&				m_stream;
+	File&				m_file;
 };
 
 } // namespace crown

+ 4 - 15
src/core/streams/TextWriter.cpp → src/core/filesystem/TextWriter.cpp

@@ -24,32 +24,21 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "TextWriter.h"
-#include "Stream.h"
+#include "File.h"
+#include "String.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-TextWriter::TextWriter(Stream& stream) : m_stream(stream)
+TextWriter::TextWriter(File& file) : m_file(file)
 {
 }
 
-//-----------------------------------------------------------------------------
-void TextWriter::write_char(char c)
-{
-	m_stream.write_byte(c);
-}
-
 //-----------------------------------------------------------------------------
 void TextWriter::write_string(const char* string)
 {
-	size_t count = 0;
-
-	while(string[count] != '\0')
-	{
-		m_stream.write_byte(string[count]);
-		count++;
-	}
+	m_file.write(string, string::strlen(string));
 }
 
 } // namespace crown

+ 6 - 9
src/core/streams/TextWriter.h → src/core/filesystem/TextWriter.h

@@ -26,27 +26,24 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-class Stream;
+class File;
 
-/// A reader that offers a convenient way to write text to a Stream
+/// A reader that offers a convenient way to write text to a File
 class TextWriter
 {
 public:
 
-						TextWriter(Stream& s);
-
-	/// Writes a single character to the stream.
-	void				write_char(char c);
+						TextWriter(File& file);
 	
-	/// Writes the string pointed by string to the stream.
+	/// Writes the string pointed by string to the file.
 	/// The function begins copying from the address specified (string)
 	/// until it reaches the terminating null character ('\0').
-	/// This final null character is not copied to the stream.
+	/// The final null character is not copied to the file.
 	void				write_string(const char* string);
 
 private:
 
-	Stream&				m_stream;
+	File&				m_file;
 };
 
 } // namespace crown

+ 3 - 3
src/core/math/Mat3.cpp

@@ -103,7 +103,7 @@ Mat3& Mat3::operator=(const Mat3& a)
 //-----------------------------------------------------------------------------
 real Mat3::operator[](uint32_t i) const
 {
-	ce_assert(i < 9, "Index must be < 9");
+	CE_ASSERT(i < 9, "Index must be < 9");
 
 	return m[i];
 }
@@ -111,7 +111,7 @@ real Mat3::operator[](uint32_t i) const
 //-----------------------------------------------------------------------------
 real& Mat3::operator[](uint32_t i)
 {
-	ce_assert(i < 9, "Index must be < 9");
+	CE_ASSERT(i < 9, "Index must be < 9");
 
 	return m[i];
 }
@@ -119,7 +119,7 @@ real& Mat3::operator[](uint32_t i)
 //-----------------------------------------------------------------------------
 real Mat3::operator()(uint32_t row, uint32_t column) const
 {
-	ce_assert(row < 3 && column < 3, "Row and column must be < 3");
+	CE_ASSERT(row < 3 && column < 3, "Row and column must be < 3");
 
 	return m[row + column * 3];
 }

+ 3 - 3
src/core/math/Mat4.cpp

@@ -132,7 +132,7 @@ Mat4& Mat4::operator=(const Mat4& a)
 //-----------------------------------------------------------------------------
 real Mat4::operator[](uint32_t i) const
 {
-	ce_assert(i < 16, "Index must be < 16");
+	CE_ASSERT(i < 16, "Index must be < 16");
 
 	return m[i];
 }
@@ -140,7 +140,7 @@ real Mat4::operator[](uint32_t i) const
 //-----------------------------------------------------------------------------
 real& Mat4::operator[](uint32_t i)
 {
-	ce_assert(i < 16, "Index must be < 16");
+	CE_ASSERT(i < 16, "Index must be < 16");
 
 	return m[i];
 }
@@ -148,7 +148,7 @@ real& Mat4::operator[](uint32_t i)
 //-----------------------------------------------------------------------------
 real Mat4::operator()(uint32_t row, uint32_t column) const
 {
-	ce_assert(row < 4 && column < 4, "Row and column must be < 4");
+	CE_ASSERT(row < 4 && column < 4, "Row and column must be < 4");
 
 	return m[row + column * 4];
 }

+ 1 - 1
src/core/math/MathUtils.h

@@ -190,7 +190,7 @@ inline T avg(const T& a, const T& b)
 template <typename T>
 inline T clamp_to_range(const T& min, const T& max, const T& value)
 {
-	ce_assert(min < max, "Min must be < max");
+	CE_ASSERT(min < max, "Min must be < max");
 
 	if (value > max)
 	{

+ 4 - 4
src/core/math/Point2.h

@@ -119,7 +119,7 @@ inline Point2::~Point2()
 //-----------------------------------------------------------------------------
 inline int32_t Point2::operator[](uint32_t i) const
 {
-	ce_assert(i < 2, "Index must be < 2");
+	CE_ASSERT(i < 2, "Index must be < 2");
 
 	return (&x)[i];
 }
@@ -127,7 +127,7 @@ inline int32_t Point2::operator[](uint32_t i) const
 //-----------------------------------------------------------------------------
 inline int32_t& Point2::operator[](uint32_t i)
 {
-	ce_assert(i < 2, "Index must be < 2");
+	CE_ASSERT(i < 2, "Index must be < 2");
 
 	return (&x)[i];
 }
@@ -180,7 +180,7 @@ inline Point2& Point2::operator*=(int32_t k)
 //-----------------------------------------------------------------------------
 inline Point2 Point2::operator/(int32_t k) const
 {
-	ce_assert(k != 0, "Division by zero");
+	CE_ASSERT(k != 0, "Division by zero");
 
 	return Point2(x / k, y / k);
 }
@@ -188,7 +188,7 @@ inline Point2 Point2::operator/(int32_t k) const
 //-----------------------------------------------------------------------------
 inline Point2& Point2::operator/=(int32_t k)
 {
-	ce_assert(k != 0, "Division by zero");
+	CE_ASSERT(k != 0, "Division by zero");
 
 	x /= k;
 	y /= k;

+ 4 - 4
src/core/math/Vec2.h

@@ -154,7 +154,7 @@ inline Vec2::Vec2(const Vec2& a) : x(a.x), y(a.y)
 //-----------------------------------------------------------------------------
 inline real Vec2::operator[](uint32_t i) const
 {
-	ce_assert(i < 2, "Index must be < 2");
+	CE_ASSERT(i < 2, "Index must be < 2");
 
 	return (&x)[i];
 }
@@ -162,7 +162,7 @@ inline real Vec2::operator[](uint32_t i) const
 //-----------------------------------------------------------------------------
 inline real& Vec2::operator[](uint32_t i)
 {
-	ce_assert(i < 2, "Index must be < 2");
+	CE_ASSERT(i < 2, "Index must be < 2");
 
 	return (&x)[i];
 }
@@ -215,7 +215,7 @@ inline Vec2& Vec2::operator*=(real k)
 //-----------------------------------------------------------------------------
 inline Vec2 Vec2::operator/(real k) const
 {
-	ce_assert(k != (real)0.0, "Division by zero");
+	CE_ASSERT(k != (real)0.0, "Division by zero");
 
 	real inv = (real)(1.0 / k);
 
@@ -225,7 +225,7 @@ inline Vec2 Vec2::operator/(real k) const
 //-----------------------------------------------------------------------------
 inline Vec2& Vec2::operator/=(real k)
 {
-	ce_assert(k != (real)0.0, "Division by zero");
+	CE_ASSERT(k != (real)0.0, "Division by zero");
 
 	real inv = (real)(1.0 / k);
 

+ 4 - 4
src/core/math/Vec3.h

@@ -160,7 +160,7 @@ inline Vec3::Vec3(const Vec3& a) : x(a.x), y(a.y), z(a.z)
 //-----------------------------------------------------------------------------
 inline real Vec3::operator[](uint32_t i) const
 {
-	ce_assert(i < 3, "Index must be < 3");
+	CE_ASSERT(i < 3, "Index must be < 3");
 
 	return (&x)[i];
 }
@@ -168,7 +168,7 @@ inline real Vec3::operator[](uint32_t i) const
 //-----------------------------------------------------------------------------
 inline real& Vec3::operator[](uint32_t i)
 {
-	ce_assert(i < 3, "Index must be < 3");
+	CE_ASSERT(i < 3, "Index must be < 3");
 
 	return (&x)[i];
 }
@@ -224,7 +224,7 @@ inline Vec3& Vec3::operator*=(real k)
 //-----------------------------------------------------------------------------
 inline Vec3 Vec3::operator/(real k) const
 {
-	ce_assert(k != (real)0.0, "Division by zero");
+	CE_ASSERT(k != (real)0.0, "Division by zero");
 
 	real inv = (real)(1.0 / k);
 
@@ -234,7 +234,7 @@ inline Vec3 Vec3::operator/(real k) const
 //-----------------------------------------------------------------------------
 inline Vec3& Vec3::operator/=(real k)
 {
-	ce_assert(k != (real)0.0, "Division by zero");
+	CE_ASSERT(k != (real)0.0, "Division by zero");
 
 	real inv = (real)(1.0 / k);
 

+ 4 - 4
src/core/math/Vec4.h

@@ -154,7 +154,7 @@ inline Vec4::Vec4(const Vec4& a) : x(a.x), y(a.y), z(a.z), w(a.w)
 //-----------------------------------------------------------------------------
 inline real Vec4::operator[](uint32_t i) const
 {
-	ce_assert(i < 4, "Index must be < 4");
+	CE_ASSERT(i < 4, "Index must be < 4");
 
 	return (&x)[i];
 }
@@ -162,7 +162,7 @@ inline real Vec4::operator[](uint32_t i) const
 //-----------------------------------------------------------------------------
 inline real& Vec4::operator[](uint32_t i)
 {
-	ce_assert(i < 4, "Index must be < 4");
+	CE_ASSERT(i < 4, "Index must be < 4");
 
 	return (&x)[i];
 }
@@ -221,7 +221,7 @@ inline Vec4& Vec4::operator*=(real k)
 //-----------------------------------------------------------------------------
 inline Vec4 Vec4::operator/(real k) const
 {
-	ce_assert(k != (real)0.0, "Division by zero");
+	CE_ASSERT(k != (real)0.0, "Division by zero");
 
 	real inv = (real)(1.0 / k);
 
@@ -231,7 +231,7 @@ inline Vec4 Vec4::operator/(real k) const
 //-----------------------------------------------------------------------------
 inline Vec4& Vec4::operator/=(real k)
 {
-	ce_assert(k != (real)0.0, "Division by zero");
+	CE_ASSERT(k != (real)0.0, "Division by zero");
 
 	real inv = (real)(1.0 / k);
 

+ 1 - 1
src/core/mem/ProxyAllocator.cpp

@@ -35,7 +35,7 @@ ProxyAllocator::ProxyAllocator(Allocator& allocator, const char* name) :
 	m_allocator(allocator),
 	m_name(name)
 {
-	ce_assert(name != NULL, "Name must be != NULL");
+	CE_ASSERT(name != NULL, "Name must be != NULL");
 }
 
 //-----------------------------------------------------------------------------

+ 50 - 0
src/core/settings/StringSetting.cpp

@@ -0,0 +1,50 @@
+#include "StringSetting.h"
+
+namespace crown
+{
+
+static StringSetting* g_string_settings_head = NULL;
+
+StringSetting::StringSetting(const char* name, const char* synopsis, const char* value) :
+	m_name(name),
+	m_synopsis(synopsis),
+	m_value(value),
+	m_next(NULL)
+{
+	*this = value;
+
+	if (g_string_settings_head == NULL)
+	{
+		g_string_settings_head = this;
+		m_next = NULL;
+	}
+	else
+	{
+		m_next = g_string_settings_head;
+		g_string_settings_head = this;
+	}
+}
+
+const char* StringSetting::name() const
+{
+	return m_name;
+}
+
+const char* StringSetting::synopsis() const
+{
+	return m_synopsis;
+}
+
+const char*	StringSetting::value() const
+{
+	return m_value;
+}
+
+StringSetting&	StringSetting::operator=(const char* value)
+{
+	m_value = value;
+
+	return *this;
+}
+
+} // namespace crown

+ 31 - 0
src/core/settings/StringSetting.h

@@ -0,0 +1,31 @@
+#pragma once
+
+#include "Types.h"
+
+namespace crown
+{
+
+/// Facility to store global string settings.
+class StringSetting
+{
+public:
+
+						StringSetting(const char* name, const char* synopsis, const char* value);
+
+	const char*			name() const;
+	const char*			synopsis() const;
+
+	const char*			value() const;
+
+	StringSetting&		operator=(const char* value);
+
+private:
+
+	const char*			m_name;
+	const char*			m_synopsis;
+	const char*			m_value;
+
+	StringSetting*		m_next;
+};
+
+} // namespace crown

+ 3 - 3
src/core/strings/Hash.h

@@ -62,7 +62,7 @@ uint64_t fnv1a_64(const void* key, size_t len);
 ///    machines.
 inline uint32_t murmur2_32(const void* key, size_t len, uint32_t seed)
 {
-	ce_assert(key != NULL, "Key must be != NULL");
+	CE_ASSERT(key != NULL, "Key must be != NULL");
 
 	// 'm' and 'r' are mixing constants generated offline.
 	// They're not really 'magic', they just happen to work well.
@@ -112,7 +112,7 @@ inline uint32_t murmur2_32(const void* key, size_t len, uint32_t seed)
 /// FNV-1a hash, 32 bit
 inline uint32_t fnv1a_32(const void* key, size_t len)
 {
-	ce_assert(key != NULL, "Key must be != NULL");
+	CE_ASSERT(key != NULL, "Key must be != NULL");
 
 	// FNV-1a
 	uint32_t hash = FNV1A_OFFSET_BASIS_32;
@@ -132,7 +132,7 @@ inline uint32_t fnv1a_32(const void* key, size_t len)
 /// FNV-1a hash, 64 bit
 inline uint64_t fnv1a_64(const void* key, size_t len)
 {
-	ce_assert(key != NULL, "Key must be != NULL");
+	CE_ASSERT(key != NULL, "Key must be != NULL");
 
 	// FNV-1a
 	uint64_t hash = FNV1A_OFFSET_BASIS_64;

+ 13 - 13
src/core/strings/Path.h

@@ -56,7 +56,7 @@ inline void strip_trailing_separator(const char* path, char* ret, size_t len);
 /// (Thanks org.eclipse.core.runtime for the documentation ;D).
 inline bool is_valid_segment(const char* segment)
 {
-	ce_assert(segment != NULL, "Segment must be != NULL");
+	CE_ASSERT(segment != NULL, "Segment must be != NULL");
 	
 	size_t segment_len = string::strlen(segment);
 
@@ -146,8 +146,8 @@ inline bool is_valid_path(const char* path)
 /// The @path must be valid.
 inline void pathname(const char* path, char* str, size_t len)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 
 	const char* last_separator = string::find_last(path, '/');
 
@@ -171,8 +171,8 @@ inline void pathname(const char* path, char* str, size_t len)
 /// The @path must be valid.
 inline void filename(const char* path, char* str, size_t len)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 
 	const char* last_separator = string::find_last(path, '/');
 	
@@ -195,8 +195,8 @@ inline void filename(const char* path, char* str, size_t len)
 /// The @path must be valid.
 inline void basename(const char* path, char* str, size_t len)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 
 	const char* last_separator = string::find_last(path, '/');
 	const char* last_dot = string::find_last(path, '.');
@@ -227,8 +227,8 @@ inline void basename(const char* path, char* str, size_t len)
 /// The @path must be valid.
 inline void extension(const char* path, char* str, size_t len)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 	
 	const char* last_dot = string::find_last(path, '.');
 	
@@ -250,8 +250,8 @@ inline void extension(const char* path, char* str, size_t len)
 /// The @path must be valid.
 inline void filename_without_extension(const char* path, char* str, size_t len)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 	
 	const char* last_dot = string::find_last(path, '.');
 	
@@ -279,8 +279,8 @@ inline void filename_without_extension(const char* path, char* str, size_t len)
 /// The @path must be valid.
 inline void strip_trailing_separator(const char* path, char* str, size_t len)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 	
 	size_t path_len = string::strlen(path);
 	

+ 11 - 11
src/core/strings/String.h

@@ -142,9 +142,9 @@ void				substring(const char* begin, const char* end, char* out, size_t len);
 
 //inline void Remove(uint32_t start, uint32_t end)
 //{
-//	ce_assert(start <= mLength);
-//	ce_assert(end <= mLength);
-//	ce_assert(start <= end);
+//	CE_ASSERT(start <= mLength);
+//	CE_ASSERT(end <= mLength);
+//	CE_ASSERT(start <= end);
 //	uint32_t len = end - start;
 //	char* tmp = new char[mLength - len + 1];
 
@@ -177,7 +177,7 @@ void				substring(const char* begin, const char* end, char* out, size_t len);
 ////! Replaces all the occurencies of the given Str with the new one
 //inline void Replace(const Str& toFind, const Str& toReplace)
 //{
-//	ce_assert(toReplace.mLength > 0);
+//	CE_ASSERT(toReplace.mLength > 0);
 //	if (mLength < toReplace.mLength)
 //		return;
 
@@ -357,7 +357,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");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 	
 	return str;
 }
@@ -365,7 +365,7 @@ inline const char* begin(const char* str)
 //-----------------------------------------------------------------------------
 inline const char* end(const char* str)
 {
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 	
 	return str + string::strlen(str) + 1;
 }
@@ -373,7 +373,7 @@ inline const char* end(const char* str)
 //-----------------------------------------------------------------------------
 inline const char* find_first(const char* str, char c)
 {
-	ce_assert(str != NULL, "Str must be != NULL");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 
 	const char* str_begin = string::begin(str);
 	
@@ -393,7 +393,7 @@ 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");
+	CE_ASSERT(str != NULL, "Str must be != NULL");
 	
 	const char* str_end = string::end(str) - 1;
 	
@@ -413,9 +413,9 @@ inline const char* find_last(const char* str, char c)
 //-----------------------------------------------------------------------------
 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");
+	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;
 	

+ 4 - 4
src/input/EventDispatcher.cpp

@@ -47,7 +47,7 @@ EventDispatcher::~EventDispatcher()
 //-----------------------------------------------------------------------------
 void EventDispatcher::add_mouse_listener(MouseListener* listener)
 {
-	ce_assert(listener != NULL, "Listener must be != NULL");
+	CE_ASSERT(listener != NULL, "Listener must be != NULL");
 
 	m_mouse_listener_list.push_back(listener);
 }
@@ -55,7 +55,7 @@ void EventDispatcher::add_mouse_listener(MouseListener* listener)
 //-----------------------------------------------------------------------------
 void EventDispatcher::add_keyboard_listener(KeyboardListener* listener)
 {
-	ce_assert(listener != NULL, "Listener must be != NULL");
+	CE_ASSERT(listener != NULL, "Listener must be != NULL");
 
 	m_keyboard_listener_list.push_back(listener);
 }
@@ -63,14 +63,14 @@ void EventDispatcher::add_keyboard_listener(KeyboardListener* listener)
 //-----------------------------------------------------------------------------
 void EventDispatcher::add_touch_listener(TouchListener* listener)
 {
-	ce_assert(listener != NULL, "Listener must be != NULL");
+	CE_ASSERT(listener != NULL, "Listener must be != NULL");
 
 	m_touch_listener_list.push_back(listener);
 }
 
 void EventDispatcher::add_accelerometer_listener(AccelerometerListener* listener)
 {
-	ce_assert(listener != NULL, "Listener must be != NULL");
+	CE_ASSERT(listener != NULL, "Listener must be != NULL");
 	m_acc_listener_list.push_back(listener);
 }
 

+ 28 - 38
src/os/android/File.cpp → src/os/android/OsFile.cpp

@@ -24,30 +24,33 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "Assert.h"
-#include <stdio.h>
-
 #include "OS.h"
-#include "File.h"
+#include "OsFile.h"
 #include "AndroidOS.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-File::File() :
+OsFile::OsFile(const char* path, FileOpenMode mode) :
 	m_asset(NULL),
-	m_mode(SOM_READ)
 {
+	// Android assets are always read-only
+	(void) mode;
+	m_mode = SOM_READ;
+	m_asset = AAssetManager_open(os::get_android_asset_manager(), path, AASSET_MODE_RANDOM);
+
+	CE_ASSERT(m_asset != NULL, "Unable to open file: %s", path)
 }
 
 //-----------------------------------------------------------------------------
-File::~File()
+OsFile::~OsFile()
 {
 	close();
 }
 
 //-----------------------------------------------------------------------------
-void File::close()
+void OsFile::close()
 {
 	if (m_asset != NULL)
 	{
@@ -57,51 +60,35 @@ void File::close()
 }
 
 //-----------------------------------------------------------------------------
-bool File::is_open() const
+bool OsFile::is_open() const
 {
 	return m_asset != NULL;
 }
 
 //-----------------------------------------------------------------------------
-StreamOpenMode File::mode()
+FileOpenMode OsFile::mode() const
 {
 	return m_mode;
 }
 
 //-----------------------------------------------------------------------------
-size_t File::size() const
+size_t OsFile::size() const
 {
 	return AAsset_getLength(m_asset);
 }
 
 //-----------------------------------------------------------------------------
-bool File::open(const char* path, StreamOpenMode mode)
-{
-	ce_assert(!is_open(), "Asset is already open: %s", path);
-
-	// Android assets are always read-only
-	(void) mode;
-	m_mode = SOM_READ;
-
-	m_asset = AAssetManager_open(os::get_android_asset_manager(), path, AASSET_MODE_RANDOM);
-
-	ce_assert(m_asset != NULL, "Unable to open asset: %s", path)
-
-	return true;
-}
-
-//-----------------------------------------------------------------------------
-size_t File::read(void* data, size_t size)
+size_t OsFile::read(void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	return (size_t)AAsset_read(m_asset, data, size);
 }
 
 //-----------------------------------------------------------------------------
-size_t File::write(const void* data, size_t size)
+size_t OsFile::write(const void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	os::printf("Android asset directory is read-only!");
 
@@ -109,31 +96,34 @@ size_t File::write(const void* data, size_t size)
 }
 
 //-----------------------------------------------------------------------------
-void File::seek(size_t position)
+void OsFile::seek(size_t position)
 {
-	ce_assert(AAsset_seek(m_asset, (off_t)position, SEEK_SET) != (off_t) -1);
+	off_t seek_result = AAsset_seek(m_asset, (off_t)position, SEEK_SET);
+	CE_ASSERT(seek_result != (off_t) -1, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
-void File::seek_to_end()
+void OsFile::seek_to_end()
 {
-	ce_assert(AAsset_seek(m_asset, 0, SEEK_END) != (off_t) -1);
+	off_t seek_result = AAsset_seek(m_asset, 0, SEEK_END);
+	CE_ASSERT(seek_result != (off_t) -1, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
-void File::skip(size_t bytes)
+void OsFile::skip(size_t bytes)
 {
-	ce_assert(AAsset_seek(m_asset, (off_t) bytes, SEEK_CUR) != (off_t) -1);
+	off_t seek_result = AAsset_seek(m_asset, (off_t) bytes, SEEK_CUR);
+	CE_ASSERT(seek_result != (off_t) -1, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
-size_t File::position() const
+size_t OsFile::position() const
 {
 	return (size_t) (AAsset_getLength(m_asset) - AAsset_getRemainingLength(m_asset));
 }
 
 //-----------------------------------------------------------------------------
-bool File::eof() const
+bool OsFile::eof() const
 {
 	return AAsset_getRemainingLength(m_asset) == 0;
 }

+ 6 - 8
src/os/android/File.h → src/os/android/OsFile.h

@@ -29,21 +29,19 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <android/asset_manager.h>
 
 #include "Types.h"
-#include "Stream.h"
+#include "File.h"
 
 namespace crown
 {
 
 /// Android assets wrapper
-class File
+class OsFile
 {
 public:
 
-							File();
-							~File();
-
 	/// Opens the file located at @path with the given @mode.
-	bool					open(const char* path, StreamOpenMode mode);
+							OsFile(const char* path, FileOpenMode mode);
+							~OsFile();
 
 	/// Closes the file.
 	void					close();
@@ -54,7 +52,7 @@ public:
 	size_t					size() const;
 
 	/// Returs the mode used to open the file.
-	StreamOpenMode			mode();
+	FileOpenMode			mode() const;
 
 	/// Reads @size bytes from the file and stores it into @data.
 	/// Returns the number of bytes read.
@@ -84,7 +82,7 @@ public:
 private:
 
 	AAsset*					m_asset;
-	StreamOpenMode			m_mode;
+	FileOpenMode			m_mode;
 };
 
 } // namespace crown

+ 2 - 2
src/os/linux/CMakeLists.txt

@@ -8,7 +8,7 @@ set (LINUX_SRC
 	Input.cpp
 	../posix/TCPSocket.cpp
 	../posix/UDPSocket.cpp	
-	../posix/File.cpp
+	../posix/OsFile.cpp
 	../posix/Thread.cpp
 	../posix/Mutex.cpp
 	../posix/Cond.cpp
@@ -17,7 +17,7 @@ set (LINUX_SRC
 set (LINUX_HEADERS
 	TCPSocket.h
 	UDPSocket.h
-	File.h
+	OsFile.h
 	Thread.h
 	Mutex.h
 	Cond.h

+ 1 - 1
src/os/linux/GLXRenderWindow.cpp

@@ -51,7 +51,7 @@ bool create_render_window(uint32_t x, uint32_t y, uint32_t width, uint32_t heigh
 {
 	(void)fullscreen;
 
-	ce_assert(width != 0 && height != 0, "Width and height must be != 0");
+	CE_ASSERT(width != 0 && height != 0, "Width and height must be != 0");
 
 	display = XOpenDisplay(NULL);
 

+ 3 - 3
src/os/linux/LinuxOS.cpp

@@ -95,7 +95,7 @@ void log_info(const char* string, va_list arg)
 //-----------------------------------------------------------------------------
 bool is_root_path(const char* path)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
 
 	if (string::strlen(path) == 1)
 	{
@@ -111,7 +111,7 @@ bool is_root_path(const char* path)
 //-----------------------------------------------------------------------------
 bool is_absolute_path(const char* path)
 {
-	ce_assert(path != NULL, "Path must be != NULL");
+	CE_ASSERT(path != NULL, "Path must be != NULL");
 
 	if (string::strlen(path) > 0)
 	{
@@ -280,7 +280,7 @@ void* open_library(const char* path)
 //-----------------------------------------------------------------------------
 void close_library(void* library)
 {
-	ce_assert(dlclose(library) == 0, "Failed to close library");
+	CE_ASSERT(dlclose(library) == 0, "Failed to close library");
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 1
src/os/linux/File.h → src/os/linux/OsFile.h

@@ -25,4 +25,4 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "../posix/File.h"
+#include "../posix/OsFile.h"

+ 35 - 44
src/os/posix/File.cpp → src/os/posix/OsFile.cpp

@@ -23,30 +23,33 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "Assert.h"
 #include <stdio.h>
 
+#include "Assert.h"
 #include "OS.h"
-#include "File.h"
+#include "OsFile.h"
 
 namespace crown
 {
 
 //-----------------------------------------------------------------------------
-File::File() :
-	m_file_handle(NULL),
-	m_mode(SOM_READ)
+OsFile::OsFile(const char* path, FileOpenMode mode) :
+	m_file_handle(NULL)
 {
+	m_file_handle = fopen(path, (mode == FOM_READ) ? "rb" : "wb");
+	CE_ASSERT(m_file_handle != NULL, "Unable to open file: %s", path);
+
+	m_mode = mode;
 }
 
 //-----------------------------------------------------------------------------
-File::~File()
+OsFile::~OsFile()
 {
 	close();
 }
 
 //-----------------------------------------------------------------------------
-void File::close()
+void OsFile::close()
 {
 	if (m_file_handle != NULL)
 	{
@@ -56,90 +59,78 @@ void File::close()
 }
 
 //-----------------------------------------------------------------------------
-bool File::is_open() const
+bool OsFile::is_open() const
 {
 	return m_file_handle != NULL;
 }
 
 //-----------------------------------------------------------------------------
-StreamOpenMode File::mode()
+FileOpenMode OsFile::mode()
 {
 	return m_mode;
 }
 
 //-----------------------------------------------------------------------------
-size_t File::size() const
-{
-	long pos = ftell(m_file_handle);
-
-	fseek(m_file_handle, 0, SEEK_END);
-
-	long size = ftell(m_file_handle);
-
-	fseek(m_file_handle, pos, SEEK_SET);
-
-	return (size_t) size;
-}
-
-//-----------------------------------------------------------------------------
-bool File::open(const char* path, StreamOpenMode mode)
+size_t OsFile::size() const
 {
-	ce_assert(!is_open(), "File is already open: %s", path);
-
-	const char* c_mode = mode == SOM_READ ? "rb" : SOM_WRITE ? "wb" : "x";
+	size_t pos = position();
 
-	ce_assert(c_mode[0] != 'x', "Open mode not valid");
+	int fseek_result = fseek(m_file_handle, 0, SEEK_END);
+	CE_ASSERT(fseek_result == 0, "Failed to seek");
 
-	m_mode = mode;
-	m_file_handle = fopen(path, c_mode);
+	size_t size = position();
 
-	ce_assert(m_file_handle != NULL, "Unable to open file: %s", path);
+	fseek_result = fseek(m_file_handle, (long) pos, SEEK_SET);
+	CE_ASSERT(fseek_result == 0, "Failed to seek");
 
-	return true;
+	return size;
 }
 
 //-----------------------------------------------------------------------------
-size_t File::read(void* data, size_t size)
+size_t OsFile::read(void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	return fread(data, 1, size, m_file_handle);
 }
 
 //-----------------------------------------------------------------------------
-size_t File::write(const void* data, size_t size)
+size_t OsFile::write(const void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	return fwrite(data, 1, size, m_file_handle);
 }
 
 //-----------------------------------------------------------------------------
-void File::seek(size_t position)
+void OsFile::seek(size_t position)
 {
-	ce_assert(fseek(m_file_handle, (long) position, SEEK_SET) == 0, "Failed to seek");
+	int fseek_result = fseek(m_file_handle, (long) position, SEEK_SET);
+	CE_ASSERT(fseek_result == 0, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
-void File::seek_to_end()
+void OsFile::seek_to_end()
 {
-	ce_assert(fseek(m_file_handle, 0, SEEK_END) == 0, "Failed to seek");
+	int fseek_result = fseek(m_file_handle, 0, SEEK_END);
+	CE_ASSERT(fseek_result == 0, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
-void File::skip(size_t bytes)
+void OsFile::skip(size_t bytes)
 {
-	ce_assert(fseek(m_file_handle, bytes, SEEK_CUR) == 0, "Failed to seek");
+	int fseek_result = fseek(m_file_handle, bytes, SEEK_CUR);
+	CE_ASSERT(fseek_result == 0, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
-size_t File::position() const
+size_t OsFile::position() const
 {
 	return (size_t) ftell(m_file_handle);
 }
 
 //-----------------------------------------------------------------------------
-bool File::eof() const
+bool OsFile::eof() const
 {
 	return feof(m_file_handle) != 0;
 }

+ 6 - 8
src/os/posix/File.h → src/os/posix/OsFile.h

@@ -28,21 +28,19 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <cstdio>
 
 #include "Types.h"
-#include "Stream.h"
+#include "File.h"
 
 namespace crown
 {
 
 /// Standard C file wrapper
-class File
+class OsFile
 {
 public:
 
-							File();
-							~File();
-
 	/// Opens the file located at @path with the given @mode.
-	bool					open(const char* path, StreamOpenMode mode);
+							OsFile(const char* path, FileOpenMode mode);
+							~OsFile();
 
 	/// Closes the file.
 	void					close();
@@ -53,7 +51,7 @@ public:
 	size_t					size() const;
 
 	/// Returs the mode used to open the file.
-	StreamOpenMode			mode();
+	FileOpenMode			mode();
 
 	/// Reads @size bytes from the file and stores it into @data.
 	/// Returns the number of bytes read.
@@ -83,7 +81,7 @@ public:
 private:
 
 	FILE*					m_file_handle;
-	StreamOpenMode			m_mode;
+	FileOpenMode			m_mode;
 };
 
 } // namespace crown

+ 2 - 2
src/os/posix/TCPSocket.cpp

@@ -153,7 +153,7 @@ void TCPSocket::close()
 //-----------------------------------------------------------------------------
 bool TCPSocket::send(const void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	if (m_active_socket <= 0)
 	{
@@ -176,7 +176,7 @@ bool TCPSocket::send(const void* data, size_t size)
 //-----------------------------------------------------------------------------
 size_t TCPSocket::receive(void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	if (m_active_socket <= 0)
 	{

+ 3 - 3
src/os/posix/UDPSocket.cpp

@@ -55,7 +55,7 @@ UDPSocket::~UDPSocket()
 //-----------------------------------------------------------------------------
 bool UDPSocket::open(uint16_t port)
 {
-	ce_assert(!is_open(), "Socket is already open");
+	CE_ASSERT(!is_open(), "Socket is already open");
 
 	m_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
@@ -97,7 +97,7 @@ bool UDPSocket::open(uint16_t port)
 //-----------------------------------------------------------------------------
 bool UDPSocket::send(const NetAddress &receiver, const void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	sockaddr_in address;
 	address.sin_family = AF_INET;
@@ -117,7 +117,7 @@ bool UDPSocket::send(const NetAddress &receiver, const void* data, size_t size)
 //-----------------------------------------------------------------------------
 size_t UDPSocket::receive(NetAddress& sender, void* data, size_t size)
 {
-	ce_assert(data != NULL, "Data must be != NULL");
+	CE_ASSERT(data != NULL, "Data must be != NULL");
 
 	sockaddr_in from;
 	socklen_t from_length = sizeof(from);

+ 4 - 4
src/os/win/WinTCPSocket.cpp

@@ -109,8 +109,8 @@ int32_t	TCPSocket::close()
 
 bool TCPSocket::send(const void* data, int32_t size)
 {
-	ce_assert(data);
-	ce_assert(size > 0);
+	CE_ASSERT(data);
+	CE_ASSERT(size > 0);
 
 	int32_t sd = get_active_socket_id();
 	if (sd <= 0)
@@ -132,8 +132,8 @@ bool TCPSocket::send(const void* data, int32_t size)
 
 int32_t	TCPSocket::receive(void* data, int32_t size)
 {
-	ce_assert(data);
-	ce_assert(size > 0);
+	CE_ASSERT(data);
+	CE_ASSERT(size > 0);
 
 	int32_t sd = get_active_socket_id();
 

+ 7 - 7
src/os/win/WinUDPSocket.cpp

@@ -22,7 +22,7 @@ UDPSocket::~UDPSocket()
 
 bool UDPSocket::open(uint16_t port)
 {
-	ce_assert(!is_open());
+	CE_ASSERT(!is_open());
 
 	m_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 	if (m_socket <= 0)
@@ -59,16 +59,16 @@ bool UDPSocket::open(uint16_t port)
 
 bool UDPSocket::send(IPv4Address &receiver, const void* data, int32_t size )
 {
-	ce_assert(data);
-	ce_assert(size > 0);
+	CE_ASSERT(data);
+	CE_ASSERT(size > 0);
 
 	if (m_socket == 0)
 	{
 		return false;
 	}
 	
-	ce_assert(receiver.get_address() != 0);
-	ce_assert(receiver.get_port() != 0);
+	CE_ASSERT(receiver.get_address() != 0);
+	CE_ASSERT(receiver.get_port() != 0);
 
 	sockaddr_in address;
 	address.sin_family = AF_INET;
@@ -82,8 +82,8 @@ bool UDPSocket::send(IPv4Address &receiver, const void* data, int32_t size )
 
 int32_t UDPSocket::receive(IPv4Address &sender, void* data, int32_t size)
 {
-	ce_assert(data);
-	ce_assert(size > 0);
+	CE_ASSERT(data);
+	CE_ASSERT(size > 0);
 
 	if (m_socket == 0)
 	{

+ 11 - 11
src/renderers/gl/GLRenderer.cpp

@@ -95,7 +95,7 @@ GLRenderer::GLRenderer() :
 		m_matrix[i].load_identity();
 	}
 
-	ce_assert(glewInit() == GLEW_OK, "Failed to initialize GLEW");
+	CE_ASSERT(glewInit() == GLEW_OK, "Failed to initialize GLEW");
 
 	Log::i("GLEW initialized.");
 
@@ -224,7 +224,7 @@ VertexBufferId GLRenderer::create_dynamic_vertex_buffer(size_t count, VertexForm
 //-----------------------------------------------------------------------------
 void GLRenderer::update_vertex_buffer(VertexBufferId id, size_t offset, size_t count, const void* vertices)
 {
-	ce_assert(m_vertex_buffers_id_table.has(id), "Vertex buffer does not exist");
+	CE_ASSERT(m_vertex_buffers_id_table.has(id), "Vertex buffer does not exist");
 
 	GLVertexBuffer& buffer = m_vertex_buffers[id.index];
 
@@ -236,7 +236,7 @@ void GLRenderer::update_vertex_buffer(VertexBufferId id, size_t offset, size_t c
 //-----------------------------------------------------------------------------
 void GLRenderer::destroy_vertex_buffer(VertexBufferId id)
 {
-	ce_assert(m_vertex_buffers_id_table.has(id), "Vertex buffer does not exist");
+	CE_ASSERT(m_vertex_buffers_id_table.has(id), "Vertex buffer does not exist");
 
 	GLVertexBuffer& buffer = m_vertex_buffers[id.index];
 
@@ -265,7 +265,7 @@ IndexBufferId GLRenderer::create_index_buffer(size_t count, const void* indices)
 //-----------------------------------------------------------------------------
 void GLRenderer::destroy_index_buffer(IndexBufferId id)
 {
-	ce_assert(m_index_buffers_id_table.has(id), "Index buffer does not exist");
+	CE_ASSERT(m_index_buffers_id_table.has(id), "Index buffer does not exist");
 
 	GLIndexBuffer& buffer = m_index_buffers[id.index];
 
@@ -299,7 +299,7 @@ TextureId GLRenderer::create_texture(uint32_t width, uint32_t height, PixelForma
 //-----------------------------------------------------------------------------
 void GLRenderer::update_texture(TextureId id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, const void* data)
 {
-	ce_assert(m_textures_id_table.has(id), "Texture does not exist");
+	CE_ASSERT(m_textures_id_table.has(id), "Texture does not exist");
 
 	GLTexture& gl_texture = m_textures[id.index];
 
@@ -312,7 +312,7 @@ void GLRenderer::update_texture(TextureId id, uint32_t x, uint32_t y, uint32_t w
 //-----------------------------------------------------------------------------
 void GLRenderer::destroy_texture(TextureId id)
 {
-	ce_assert(m_textures_id_table.has(id), "Texture does not exist");
+	CE_ASSERT(m_textures_id_table.has(id), "Texture does not exist");
 
 	GLTexture& gl_texture = m_textures[id.index];
 
@@ -397,7 +397,7 @@ void GLRenderer::set_lighting(bool lighting)
 //-----------------------------------------------------------------------------
 void GLRenderer::bind_texture(uint32_t unit, TextureId texture)
 {
-	ce_assert(m_textures_id_table.has(texture), "Texture does not exist");
+	CE_ASSERT(m_textures_id_table.has(texture), "Texture does not exist");
 
 	if (!activate_texture_unit(unit))
 	{
@@ -790,7 +790,7 @@ void GLRenderer::set_matrix(MatrixType type, const Mat4& matrix)
 //-----------------------------------------------------------------------------
 void GLRenderer::bind_vertex_buffer(VertexBufferId vb) const
 {
-	ce_assert(m_vertex_buffers_id_table.has(vb), "Vertex buffer does not exist");
+	CE_ASSERT(m_vertex_buffers_id_table.has(vb), "Vertex buffer does not exist");
 
 	const GLVertexBuffer& vertex_buffer = m_vertex_buffers[vb.index];
 
@@ -840,7 +840,7 @@ void GLRenderer::bind_vertex_buffer(VertexBufferId vb) const
 		}
 		default:
 		{
-			ce_assert(0, "Vertex format unknown");
+			CE_ASSERT(0, "Vertex format unknown");
 			break;
 		}
 	}
@@ -849,7 +849,7 @@ void GLRenderer::bind_vertex_buffer(VertexBufferId vb) const
 //-----------------------------------------------------------------------------
 void GLRenderer::draw_triangles(IndexBufferId id) const
 {
-	ce_assert(m_index_buffers_id_table.has(id), "Index buffer does not exist");
+	CE_ASSERT(m_index_buffers_id_table.has(id), "Index buffer does not exist");
 
 	const GLIndexBuffer& index_buffer = m_index_buffers[id.index];
 
@@ -861,7 +861,7 @@ void GLRenderer::draw_triangles(IndexBufferId id) const
 //-----------------------------------------------------------------------------
 // void GLRenderer::bind_render_buffer(RenderBufferId id) const
 // {
-// 	ce_assert(m_render_buffers_id_table.has(id), "Render buffer does not exist");
+// 	CE_ASSERT(m_render_buffers_id_table.has(id), "Render buffer does not exist");
 
 // 	const GLRenderBuffer& render_buffer = m_render_buffers[id.index];
 // }

+ 2 - 2
src/renderers/gles/GLESRenderer.cpp

@@ -567,8 +567,8 @@ void GLESRenderer::set_matrix(MatrixType type, const Mat4& matrix)
 //-----------------------------------------------------------------------------
 void GLESRenderer::draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices)
 {
-	ce_assert(vertices != NULL);
-	ce_assert(indices != NULL);
+	CE_ASSERT(vertices != NULL);
+	CE_ASSERT(indices != NULL);
 
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_NORMAL_ARRAY);

+ 6 - 6
src/renderers/gles/GLESUtils.h

@@ -65,7 +65,7 @@ private:
 //-----------------------------------------------------------------------------
 inline GLenum GLES::compare_function(CompareFunction function)
 {
-	ce_assert(function < CF_COUNT);
+	CE_ASSERT(function < CF_COUNT);
 
 	return COMPARE_FUNCTION_TABLE[function];
 }
@@ -73,7 +73,7 @@ inline GLenum GLES::compare_function(CompareFunction function)
 //-----------------------------------------------------------------------------
 inline GLenum GLES::blend_function(BlendFunction function)
 {
-	ce_assert(function < BF_COUNT);
+	CE_ASSERT(function < BF_COUNT);
 
 	return BLEND_FUNCTION_TABLE[function];
 }
@@ -81,7 +81,7 @@ inline GLenum GLES::blend_function(BlendFunction function)
 //-----------------------------------------------------------------------------
 inline GLenum GLES::texture_mode(TextureMode mode)
 {
-	ce_assert(mode < TM_COUNT);
+	CE_ASSERT(mode < TM_COUNT);
 
 	return TEXTURE_MODE_TABLE[mode];
 }
@@ -89,7 +89,7 @@ inline GLenum GLES::texture_mode(TextureMode mode)
 //-----------------------------------------------------------------------------
 inline GLenum GLES::texture_wrap(TextureWrap wrap)
 {
-	ce_assert(wrap < TW_COUNT);
+	CE_ASSERT(wrap < TW_COUNT);
 
 	return TEXTURE_WRAP_TABLE[wrap];
 }
@@ -97,7 +97,7 @@ inline GLenum GLES::texture_wrap(TextureWrap wrap)
 //-----------------------------------------------------------------------------
 inline void GLES::texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter)
 {
-	ce_assert(filter < TF_COUNT);
+	CE_ASSERT(filter < TF_COUNT);
 
 	minFilter = TEXTURE_MIN_FILTER_TABLE[filter];
 	magFilter = TEXTURE_MAG_FILTER_TABLE[filter];
@@ -106,7 +106,7 @@ inline void GLES::texture_filter(TextureFilter filter, GLint& minFilter, GLint&
 //-----------------------------------------------------------------------------
 inline GLenum GLES::fog_mode(FogMode mode)
 {
-	ce_assert(mode < FM_COUNT);
+	CE_ASSERT(mode < FM_COUNT);
 
 	return FOG_MODE_TABLE[mode];
 }

+ 2 - 2
tests/allocators.cpp

@@ -10,13 +10,13 @@ int main()
 	MallocAllocator malloc_allocator;
 
 	char* char_buffer = (char*)malloc_allocator.allocate(128);
-	ce_assert(malloc_allocator.allocated_size() >= 128, "Allocated size differs from requested size");
+	CE_ASSERT(malloc_allocator.allocated_size() >= 128, "Allocated size differs from requested size");
 
 	printf("MallocAllocator::get_allocated_size(): %d\n", malloc_allocator.allocated_size());
 
 	malloc_allocator.deallocate(char_buffer);
 
 	printf("MallocAllocator::get_allocated_size(): %d\n", malloc_allocator.allocated_size());
-	//ce_assert(malloc_allocator.get_allocated_size() == 0);
+	//CE_ASSERT(malloc_allocator.get_allocated_size() == 0);
 }
 

+ 8 - 8
tests/containers.cpp

@@ -10,7 +10,7 @@ int main()
 
 	List<int> int_list(allocator);
 
-	ce_assert(int_list.size() == 0, "Size differs from expected value");
+	CE_ASSERT(int_list.size() == 0, "Size differs from expected value");
 
 	int_list.push_back(10);
 	int_list.push_back(20);
@@ -19,19 +19,19 @@ int main()
 	int_list.push_back(50);
 	int_list.push_back(60);
 
-	ce_assert(int_list.size() == 6, "Size differs from expected value");
-	ce_assert(int_list.front() == 10, "Front differs from expected value");
-	ce_assert(int_list.back() == 60, "Back differs from expected value");
+	CE_ASSERT(int_list.size() == 6, "Size differs from expected value");
+	CE_ASSERT(int_list.front() == 10, "Front differs from expected value");
+	CE_ASSERT(int_list.back() == 60, "Back differs from expected value");
 
 	int_list.pop_back();
 
-	ce_assert(int_list.size() == 5, "Size differs from expected value");
-	ce_assert(int_list.front() == 10, "Front differs from expected value");
-	ce_assert(int_list.back() == 50, "Back differs from expected value");
+	CE_ASSERT(int_list.size() == 5, "Size differs from expected value");
+	CE_ASSERT(int_list.front() == 10, "Front differs from expected value");
+	CE_ASSERT(int_list.back() == 50, "Back differs from expected value");
 
 	int_list.clear();
 
-	ce_assert(int_list.size() == 0, "Size differs from expected value");
+	CE_ASSERT(int_list.size() == 0, "Size differs from expected value");
 
 	return 0;
 }

+ 32 - 32
tests/paths.cpp

@@ -10,99 +10,99 @@ int main()
 	char path_output[128];
 	
 	// Test is_valid_segment
-	ce_assert(path::is_valid_segment(".") == false);
+	CE_ASSERT(path::is_valid_segment(".") == false);
 	
-	ce_assert(path::is_valid_segment("/") == false);
+	CE_ASSERT(path::is_valid_segment("/") == false);
 	
-	ce_assert(path::is_valid_segment("\\") == false);
+	CE_ASSERT(path::is_valid_segment("\\") == false);
 
-	ce_assert(path::is_valid_segment(":") == false);
+	CE_ASSERT(path::is_valid_segment(":") == false);
 	
-	ce_assert(path::is_valid_segment("tga/") == false);
+	CE_ASSERT(path::is_valid_segment("tga/") == false);
 	
-	ce_assert(path::is_valid_segment("tga\\foo") == false);
+	CE_ASSERT(path::is_valid_segment("tga\\foo") == false);
 	
-	ce_assert(path::is_valid_segment("tga") == true);
+	CE_ASSERT(path::is_valid_segment("tga") == true);
 	
-	ce_assert(path::is_valid_segment("back_texture") == true);
+	CE_ASSERT(path::is_valid_segment("back_texture") == true);
 	
 	// Test pathname
 	path::pathname("/home/project/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("/home/project", path_output) == 0);
+	CE_ASSERT(string::strcmp("/home/project", path_output) == 0);
 
 	path::pathname("/home/project", path_output, 128);
-	ce_assert(string::strcmp("/home", path_output) == 0);
+	CE_ASSERT(string::strcmp("/home", path_output) == 0);
 	
 	path::pathname("/home", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	path::pathname("/", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	path::pathname("", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	// Test filename
 	path::filename("/home/project/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("texture.tga", path_output) == 0);
+	CE_ASSERT(string::strcmp("texture.tga", path_output) == 0);
 	
 	path::filename("/home/project/texture", path_output, 128);
-	ce_assert(string::strcmp("texture", path_output) == 0);
+	CE_ASSERT(string::strcmp("texture", path_output) == 0);
 	
 	path::filename("/home", path_output, 128);
-	ce_assert(string::strcmp("home", path_output) == 0);
+	CE_ASSERT(string::strcmp("home", path_output) == 0);
 	
 	path::filename("/", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	path::filename("", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 
 	// Test basename
 	path::basename("/home/project/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("texture", path_output) == 0);
+	CE_ASSERT(string::strcmp("texture", path_output) == 0);
 	
 	path::basename("/home/project/textureabc", path_output, 128);
 	printf(path_output);
-	ce_assert(string::strcmp("textureabc", path_output) == 0);
+	CE_ASSERT(string::strcmp("textureabc", path_output) == 0);
 	
 	path::basename("/hom.e/proj./e.ct/textu.reabc", path_output, 128);
-	ce_assert(string::strcmp("textu", path_output) == 0);
+	CE_ASSERT(string::strcmp("textu", path_output) == 0);
 	
 	path::basename("texture.tga", path_output, 128);
-	ce_assert(string::strcmp("texture", path_output) == 0);
+	CE_ASSERT(string::strcmp("texture", path_output) == 0);
 	
 	path::basename("/home", path_output, 128);
-	ce_assert(string::strcmp("home", path_output) == 0);
+	CE_ASSERT(string::strcmp("home", path_output) == 0);
 	
 	path::basename("/", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	path::basename("", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	// Test extension
 	path::extension("/home/project/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("tga", path_output) == 0);
+	CE_ASSERT(string::strcmp("tga", path_output) == 0);
 	
 	path::extension("/home/project/texture", path_output, 128);
-	ce_assert(string::strcmp("", path_output) == 0);
+	CE_ASSERT(string::strcmp("", path_output) == 0);
 	
 	path::extension("/home/project.x/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("tga", path_output) == 0);
+	CE_ASSERT(string::strcmp("tga", path_output) == 0);
 	
 	// Test filename_without_extension
 	path::filename_without_extension("/home/project/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("/home/project/texture", path_output) == 0);
+	CE_ASSERT(string::strcmp("/home/project/texture", path_output) == 0);
 	
 	// Test strip_trailing_separator
 	path::strip_trailing_separator("/home/project/texture.tga", path_output, 128);
-	ce_assert(string::strcmp("/home/project/texture.tga", path_output) == 0);
+	CE_ASSERT(string::strcmp("/home/project/texture.tga", path_output) == 0);
 	
 	path::strip_trailing_separator("/home/project/texture2.tga/", path_output, 128);
-	ce_assert(string::strcmp("/home/project/texture2.tga", path_output) == 0);
+	CE_ASSERT(string::strcmp("/home/project/texture2.tga", path_output) == 0);
 	
 	path::strip_trailing_separator("texture.tga", path_output, 128);
-	ce_assert(string::strcmp("texture.tga", path_output) == 0);
+	CE_ASSERT(string::strcmp("texture.tga", path_output) == 0);
 }
 

+ 12 - 12
tests/strings.cpp

@@ -10,40 +10,40 @@ const char* path_string = "/home/project/texture.tga";
 int main()
 {
 	// Test strlen
-	ce_assert(string::strlen("ciao") == 4);
+	CE_ASSERT(string::strlen("ciao") == 4);
 	// FIXME add UTF-8 test case
 
 	// Test begin/end
-	ce_assert(string::begin(hello_string) == &hello_string[0]);
+	CE_ASSERT(string::begin(hello_string) == &hello_string[0]);
 	
-	ce_assert(string::end(hello_string) == &hello_string[24] + 2);
+	CE_ASSERT(string::end(hello_string) == &hello_string[24] + 2);
 	
 	// Test find_first/find_last
-	ce_assert(string::find_first(hello_string, '.') == &hello_string[2]);
+	CE_ASSERT(string::find_first(hello_string, '.') == &hello_string[2]);
 	
-	ce_assert(string::find_last(hello_string, '.') == &hello_string[17]);
+	CE_ASSERT(string::find_last(hello_string, '.') == &hello_string[17]);
 	
-	ce_assert(string::find_first(hello_string, '?') == string::end(hello_string));
+	CE_ASSERT(string::find_first(hello_string, '?') == string::end(hello_string));
 	
-	ce_assert(string::find_last(hello_string, '?') == string::end(hello_string));
+	CE_ASSERT(string::find_last(hello_string, '?') == string::end(hello_string));
 	
-	ce_assert(string::find_last(hello_string, '/') == &hello_string[22]);
+	CE_ASSERT(string::find_last(hello_string, '/') == &hello_string[22]);
 	
-	ce_assert(string::find_last(path_string, '/') == &path_string[13]);
+	CE_ASSERT(string::find_last(path_string, '/') == &path_string[13]);
 	
 	// Test substring
 	char string_buffer[64];
 	
 	memset(string_buffer, 'a', 64);
 	string::substring(string::begin(hello_string), string::end(hello_string), string_buffer, 64);
-	ce_assert(string::strcmp(hello_string, string_buffer) == 0);
+	CE_ASSERT(string::strcmp(hello_string, string_buffer) == 0);
 	
 	memset(string_buffer, 'a', 64);
 	string::substring(string::begin(hello_string), &hello_string[11], string_buffer, 64);
-	ce_assert(string::strcmp(string_buffer, "/h.ello.eve") == 0);
+	CE_ASSERT(string::strcmp(string_buffer, "/h.ello.eve") == 0);
 	
 	memset(string_buffer, 'a', 64);
 	string::substring(string::begin(hello_string), string::end(hello_string), string_buffer, 5);
-	ce_assert(string::strcmp(string_buffer, "/h.el") == 0);
+	CE_ASSERT(string::strcmp(string_buffer, "/h.el") == 0);
 }
 

+ 8 - 8
tools/compilers/Compiler.cpp

@@ -28,7 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Compiler.h"
 #include "Hash.h"
 #include "Path.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Log.h"
 
 namespace crown
@@ -77,13 +77,13 @@ size_t Compiler::compile(const char* resource, uint32_t name, uint32_t type)
 	}
 
 	// Read source file
-	FileStream* input_file = m_root_fs.open(resource, SOM_READ);
+	DiskFile* input_file = m_root_fs.open(resource, FOM_READ);
 
 	size_t header_size = read_header(input_file);
 	size_t resource_size = read_resource(input_file);
 
 	// Write compiled file
-	FileStream* output_file;
+	DiskFile* output_file;
 
 	if (m_dest_fs.exists(output_name))
 	{
@@ -91,7 +91,7 @@ size_t Compiler::compile(const char* resource, uint32_t name, uint32_t type)
 	}
 
 	m_dest_fs.create_file(output_name);
-	output_file = m_dest_fs.open(output_name, SOM_WRITE);
+	output_file = m_dest_fs.open(output_name, FOM_WRITE);
 
 	write_header(output_file, name, type, resource_size);
 	write_resource(output_file);
@@ -104,19 +104,19 @@ size_t Compiler::compile(const char* resource, uint32_t name, uint32_t type)
 }
 
 //-----------------------------------------------------------------------------
-size_t Compiler::read_header(FileStream* in_file)
+size_t Compiler::read_header(DiskFile* in_file)
 {
 	return read_header_impl(in_file);
 }
 
 //-----------------------------------------------------------------------------
-size_t Compiler::read_resource(FileStream* in_file)
+size_t Compiler::read_resource(DiskFile* in_file)
 {
 	return read_resource_impl(in_file);
 }
 
 //-----------------------------------------------------------------------------
-void Compiler::write_header(FileStream* out_file, uint32_t name, uint32_t type, uint32_t resource_size)
+void Compiler::write_header(DiskFile* out_file, uint32_t name, uint32_t type, uint32_t resource_size)
 {
 	CompiledHeader header;
 	header.magic = COMPILED_HEADER_MAGIC_NUMBER;
@@ -131,7 +131,7 @@ void Compiler::write_header(FileStream* out_file, uint32_t name, uint32_t type,
 }
 
 //-----------------------------------------------------------------------------
-void Compiler::write_resource(FileStream* out_file)
+void Compiler::write_resource(DiskFile* out_file)
 {
 	write_resource_impl(out_file);
 }

+ 9 - 9
tools/compilers/Compiler.h

@@ -50,7 +50,7 @@ struct CompiledHeader
 	uint32_t	size;		// Size of the resource data _not_ including header (in bytes)
 };
 
-class FileStream;
+class DiskFile;
 
 /// Resource compiler interface.
 /// Every specific resource compiler must inherith from this
@@ -64,11 +64,11 @@ public:
 
 	size_t					compile(const char* resource, uint32_t name, uint32_t type);
 
-	size_t					read_header(FileStream* in_file);
-	size_t					read_resource(FileStream* in_file);
+	size_t					read_header(DiskFile* in_file);
+	size_t					read_resource(DiskFile* in_file);
 
-	void					write_header(FileStream* out_file, uint32_t name, uint32_t type, uint32_t resource_size);
-	void					write_resource(FileStream* out_file);
+	void					write_header(DiskFile* out_file, uint32_t name, uint32_t type, uint32_t resource_size);
+	void					write_resource(DiskFile* out_file);
 
 	void					cleanup();
 
@@ -78,11 +78,11 @@ public:
 
 protected:
 
-	virtual size_t			read_header_impl(FileStream* in_file) = 0;
-	virtual size_t			read_resource_impl(FileStream* in_file) = 0;
+	virtual size_t			read_header_impl(DiskFile* in_file) = 0;
+	virtual size_t			read_resource_impl(DiskFile* in_file) = 0;
 
-	virtual void			write_header_impl(FileStream* out_file) = 0;
-	virtual void			write_resource_impl(FileStream* out_file) = 0;
+	virtual void			write_header_impl(DiskFile* out_file) = 0;
+	virtual void			write_resource_impl(DiskFile* out_file) = 0;
 
 	virtual void			cleanup_impl() = 0;
 

+ 5 - 5
tools/compilers/ps/PSCompiler.cpp

@@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "PSCompiler.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Resource.h"
 
 namespace crown
@@ -45,14 +45,14 @@ PSCompiler::~PSCompiler()
 }
 
 //-----------------------------------------------------------------------------
-size_t PSCompiler::read_header_impl(FileStream* in_file)
+size_t PSCompiler::read_header_impl(DiskFile* in_file)
 {
 	(void) in_file;
 	return 0;
 }
 
 //-----------------------------------------------------------------------------
-size_t PSCompiler::read_resource_impl(FileStream* in_file)
+size_t PSCompiler::read_resource_impl(DiskFile* in_file)
 {
 	m_file_size = in_file->size();
 
@@ -66,13 +66,13 @@ size_t PSCompiler::read_resource_impl(FileStream* in_file)
 }
 
 //-----------------------------------------------------------------------------
-void PSCompiler::write_header_impl(FileStream* out_file)
+void PSCompiler::write_header_impl(DiskFile* out_file)
 {
 	out_file->write(&m_file_size, sizeof(uint32_t));
 }
 
 //-----------------------------------------------------------------------------
-void PSCompiler::write_resource_impl(FileStream* out_file)
+void PSCompiler::write_resource_impl(DiskFile* out_file)
 {
 	out_file->write(m_file_data, m_file_size);
 }

+ 4 - 4
tools/compilers/ps/PSCompiler.h

@@ -37,11 +37,11 @@ public:
 					PSCompiler(const char* root_path, const char* dest_path);
 					~PSCompiler();
 
-	size_t			read_header_impl(FileStream* in_file);
-	size_t			read_resource_impl(FileStream* in_file);
+	size_t			read_header_impl(DiskFile* in_file);
+	size_t			read_resource_impl(DiskFile* in_file);
 
-	void			write_header_impl(FileStream* out_file);
-	void			write_resource_impl(FileStream* out_file);
+	void			write_header_impl(DiskFile* out_file);
+	void			write_resource_impl(DiskFile* out_file);
 
 	void			cleanup_impl();
 

+ 4 - 4
tools/compilers/resource-linker.cpp

@@ -1,12 +1,12 @@
 #include <stdio.h>
 #include "Filesystem.h"
-#include "Stream.h"
+#include "File.h"
 #include "Path.h"
 #include "String.h"
 #include "Hash.h"
 #include "Resource.h"
 #include "ResourceArchive.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include <cstring>
 
 using namespace crown;
@@ -45,7 +45,7 @@ int main(int argc, char** argv)
 	}
 
 	// Open the archive file for both reading and writing
-	FileStream* archive = (FileStream*)fs_root.open("archive.bin", (StreamOpenMode)(SOM_READ | SOM_WRITE));
+	DiskFile* archive = (DiskFile*)fs_root.open("archive.bin", (FileOpenMode)(FOM_READ | FOM_WRITE));
 	
 	// The archive header used throughout the code
 	ArchiveHeader header;
@@ -88,7 +88,7 @@ int main(int argc, char** argv)
 	//-------------------------------------------------------------------------
 
 	// Open the resource
-	FileStream* resource = (FileStream*)fs_root.open(resource_name, SOM_READ);
+	DiskFile* resource = (DiskFile*)fs_root.open(resource_name, FOM_READ);
 	
 	// If the resource is malformed, abort
 	if (resource->size() < sizeof(ArchiveEntry))

+ 7 - 7
tools/compilers/tga/TGACompiler.cpp

@@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "TGACompiler.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "PixelFormat.h"
 #include "Resource.h"
 #include "Log.h"
@@ -50,7 +50,7 @@ TGACompiler::~TGACompiler()
 }
 
 //-----------------------------------------------------------------------------
-size_t TGACompiler::read_header_impl(FileStream* in_file)
+size_t TGACompiler::read_header_impl(DiskFile* in_file)
 {
 	// Read the header
 	in_file->read(&m_tga_header, sizeof(TGAHeader));
@@ -62,7 +62,7 @@ size_t TGACompiler::read_header_impl(FileStream* in_file)
 }
 
 //-----------------------------------------------------------------------------
-size_t TGACompiler::read_resource_impl(FileStream* in_file)
+size_t TGACompiler::read_resource_impl(DiskFile* in_file)
 {
 	// Compute color channels	
 	m_image_channels = m_tga_header.pixel_depth / 8;
@@ -128,7 +128,7 @@ size_t TGACompiler::read_resource_impl(FileStream* in_file)
 }
 
 //-----------------------------------------------------------------------------
-void TGACompiler::write_header_impl(FileStream* out_file)
+void TGACompiler::write_header_impl(DiskFile* out_file)
 {
 	// Write the texture header
 	out_file->write(&m_image_format, sizeof(PixelFormat));
@@ -137,7 +137,7 @@ void TGACompiler::write_header_impl(FileStream* out_file)
 }
 
 //-----------------------------------------------------------------------------
-void TGACompiler::write_resource_impl(FileStream* out_file)
+void TGACompiler::write_resource_impl(DiskFile* out_file)
 {
 	// Write out the data
 	out_file->write(m_image_data, m_image_size * m_image_channels);
@@ -154,7 +154,7 @@ void TGACompiler::cleanup_impl()
 }
 
 //-----------------------------------------------------------------------------
-void TGACompiler::load_uncompressed(FileStream* in_file)
+void TGACompiler::load_uncompressed(DiskFile* in_file)
 {
 	uint64_t size = m_tga_header.width * m_tga_header.height;
 
@@ -184,7 +184,7 @@ void TGACompiler::load_uncompressed(FileStream* in_file)
 }
 
 //-----------------------------------------------------------------------------
-void TGACompiler::load_compressed(FileStream* in_file)
+void TGACompiler::load_compressed(DiskFile* in_file)
 {
 	uint8_t rle_id = 0;
 	uint32_t i = 0;

+ 7 - 7
tools/compilers/tga/TGACompiler.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Compiler.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "PixelFormat.h"
 
 namespace crown
@@ -54,18 +54,18 @@ public:
 					TGACompiler(const char* root_path, const char* dest_path);
 					~TGACompiler();
 
-	size_t			read_header_impl(FileStream* in_file);
-	size_t			read_resource_impl(FileStream* in_file);
+	size_t			read_header_impl(DiskFile* in_file);
+	size_t			read_resource_impl(DiskFile* in_file);
 
-	void			write_header_impl(FileStream* out_file);
-	void			write_resource_impl(FileStream* out_file);
+	void			write_header_impl(DiskFile* out_file);
+	void			write_resource_impl(DiskFile* out_file);
 
 	void			cleanup_impl();
 
 private:
 
-	void			load_uncompressed(FileStream* in_file);
-	void			load_compressed(FileStream* in_file);
+	void			load_uncompressed(DiskFile* in_file);
+	void			load_compressed(DiskFile* in_file);
 	void			swap_red_blue();
 
 private:

+ 5 - 5
tools/compilers/txt/TXTCompiler.cpp

@@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "TXTCompiler.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Resource.h"
 
 namespace crown
@@ -45,14 +45,14 @@ TXTCompiler::~TXTCompiler()
 }
 
 //-----------------------------------------------------------------------------
-size_t TXTCompiler::read_header_impl(FileStream* in_file)
+size_t TXTCompiler::read_header_impl(DiskFile* in_file)
 {
 	(void) in_file;
 	return 0;
 }
 
 //-----------------------------------------------------------------------------
-size_t TXTCompiler::read_resource_impl(FileStream* in_file)
+size_t TXTCompiler::read_resource_impl(DiskFile* in_file)
 {
 	m_file_size = in_file->size();
 
@@ -66,13 +66,13 @@ size_t TXTCompiler::read_resource_impl(FileStream* in_file)
 }
 
 //-----------------------------------------------------------------------------
-void TXTCompiler::write_header_impl(FileStream* out_file)
+void TXTCompiler::write_header_impl(DiskFile* out_file)
 {
 	out_file->write(&m_file_size, sizeof(uint32_t));
 }
 
 //-----------------------------------------------------------------------------
-void TXTCompiler::write_resource_impl(FileStream* out_file)
+void TXTCompiler::write_resource_impl(DiskFile* out_file)
 {
 	out_file->write(m_file_data, m_file_size);
 }

+ 5 - 5
tools/compilers/txt/TXTCompiler.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Compiler.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 
 namespace crown
 {
@@ -38,11 +38,11 @@ public:
 					TXTCompiler(const char* root_path, const char* dest_path);
 					~TXTCompiler();
 
-	size_t			read_header_impl(FileStream* in_file);
-	size_t			read_resource_impl(FileStream* in_file);
+	size_t			read_header_impl(DiskFile* in_file);
+	size_t			read_resource_impl(DiskFile* in_file);
 
-	void			write_header_impl(FileStream* out_file);
-	void			write_resource_impl(FileStream* out_file);
+	void			write_header_impl(DiskFile* out_file);
+	void			write_resource_impl(DiskFile* out_file);
 
 	void			cleanup_impl();
 

+ 5 - 5
tools/compilers/vs/VSCompiler.cpp

@@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "VSCompiler.h"
-#include "FileStream.h"
+#include "DiskFile.h"
 #include "Resource.h"
 
 namespace crown
@@ -45,14 +45,14 @@ VSCompiler::~VSCompiler()
 }
 
 //-----------------------------------------------------------------------------
-size_t VSCompiler::read_header_impl(FileStream* in_file)
+size_t VSCompiler::read_header_impl(DiskFile* in_file)
 {
 	(void) in_file;
 	return 0;
 }
 
 //-----------------------------------------------------------------------------
-size_t VSCompiler::read_resource_impl(FileStream* in_file)
+size_t VSCompiler::read_resource_impl(DiskFile* in_file)
 {
 	m_file_size = in_file->size();
 
@@ -66,13 +66,13 @@ size_t VSCompiler::read_resource_impl(FileStream* in_file)
 }
 
 //-----------------------------------------------------------------------------
-void VSCompiler::write_header_impl(FileStream* out_file)
+void VSCompiler::write_header_impl(DiskFile* out_file)
 {
 	out_file->write(&m_file_size, sizeof(uint32_t));
 }
 
 //-----------------------------------------------------------------------------
-void VSCompiler::write_resource_impl(FileStream* out_file)
+void VSCompiler::write_resource_impl(DiskFile* out_file)
 {
 	out_file->write(m_file_data, m_file_size);
 }

+ 4 - 4
tools/compilers/vs/VSCompiler.h

@@ -37,11 +37,11 @@ public:
 					VSCompiler(const char* root_path, const char* dest_path);
 					~VSCompiler();
 
-	size_t			read_header_impl(FileStream* in_file);
-	size_t			read_resource_impl(FileStream* in_file);
+	size_t			read_header_impl(DiskFile* in_file);
+	size_t			read_resource_impl(DiskFile* in_file);
 
-	void			write_header_impl(FileStream* out_file);
-	void			write_resource_impl(FileStream* out_file);
+	void			write_header_impl(DiskFile* out_file);
+	void			write_resource_impl(DiskFile* out_file);
 
 	void			cleanup_impl();
 

+ 3 - 3
tools/editors/fontgen/fontgen.cpp

@@ -111,7 +111,7 @@ Image* BuildFontImage(const char* ttfFont, ushort ttfSize, ushort ttfResolution)
 
 	// Find the biggest character
 	// For each range
-	ce_assert(mCodePointRangeList.GetSize() % 2 == 0);
+	CE_ASSERT(mCodePointRangeList.GetSize() % 2 == 0);
 	for (int i = 0; i < mCodePointRangeList.GetSize(); i += 2)
 	{
 		uint j = mCodePointRangeList[i + 0];
@@ -174,7 +174,7 @@ Image* BuildFontImage(const char* ttfFont, ushort ttfSize, ushort ttfResolution)
 	FileStream fileStream(SOM_WRITE, Str(ttfFont) + Str(".txt"));
 	TextWriter fileWriter(&fileStream);
 
-	ce_assert(mCodePointRangeList.GetSize() % 2 == 0);
+	CE_ASSERT(mCodePointRangeList.GetSize() % 2 == 0);
 	// For each range
 	for (int i = 0; i < mCodePointRangeList.GetSize(); i += 2)
 	{
@@ -254,7 +254,7 @@ Image* BuildFontImage(const char* ttfFont, ushort ttfSize, ushort ttfResolution)
 
 void AddCodePointRange(uint min, uint max)
 {
-	ce_assert(min <= max);
+	CE_ASSERT(min <= max);
 
 	mCodePointRangeList.Append(min);
 	mCodePointRangeList.Append(max);

+ 2 - 2
tools/editors/world-editor/terrain/Heightfield.cpp

@@ -162,8 +162,8 @@ void Heightfield::set_altitudes(float altitude)
 //-----------------------------------------------------------------------------
 uint32_t Heightfield::coords_to_index(uint32_t x, uint32_t y) const
 {
-	ce_assert(x < m_width, "X coordinates beyond heightfield width");
-	ce_assert(y < m_height, "Y coordinates beyond heightfield height");
+	CE_ASSERT(x < m_width, "X coordinates beyond heightfield width");
+	CE_ASSERT(y < m_height, "Y coordinates beyond heightfield height");
 
 	return m_width * y + x;
 }