Przeglądaj źródła

Reorganize os stuff prior to next move

Daniele Bartolini 11 lat temu
rodzic
commit
a84c01113c

+ 1 - 1
engine/compilers/bundle_compiler.h

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

+ 0 - 0
engine/os/win/inttypes.h → engine/core/compat/msvc/inttypes.h


+ 2 - 61
engine/core/error.h

@@ -29,75 +29,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "config.h"
 #include "types.h"
 #include "macros.h"
+#include "stacktrace.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
 
-#if CROWN_PLATFORM_LINUX && CROWN_COMPILER_GCC
-	#include <cxxabi.h>
-	#include <execinfo.h>
-#endif
-
 namespace crown
 {
 namespace error
 {
 
-inline void log_backtrace()
-{
-	#if CROWN_PLATFORM_LINUX && CROWN_COMPILER_GCC
-	printf("Backtrace:\n");
-	void* array[50];
-	int size = backtrace(array, 50);
-
-	char** messages = backtrace_symbols(array, size);
-
-	// skip first stack frame (points here)
-	for (int i = 1; i < size && messages != NULL; ++i)
-	{
-		char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;
-
-		// find parantheses and +address offset surrounding mangled name
-		for (char *p = messages[i]; *p; ++p)
-		{
-			if (*p == '(')
-			{
-				mangled_name = p;
-			}
-			else if (*p == '+')
-			{
-				offset_begin = p;
-			}
-			else if (*p == ')')
-			{
-				offset_end = p;
-				break;
-			}
-		}
-
-		// if the line could be processed, attempt to demangle the symbol
-		if (mangled_name && offset_begin && offset_end && mangled_name < offset_begin)
-		{
-			*mangled_name++ = '\0';
-			*offset_begin++ = '\0';
-			*offset_end++ = '\0';
-
-			int status;
-			char* real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);
-
-			printf("\t[%d] %s: (%s)+%s %s\n", i, messages[i], (status == 0 ? real_name : mangled_name), offset_begin, offset_end);
-			free(real_name);
-		}
-		// otherwise, print the whole line
-		else
-		{
-			printf("\t[%d] %s\n", i, messages[i]);
-		}
-	}
-	free(messages);
-	#endif
-}
-
 /// Aborts the program execution logging an error message and the stacktrace if
 /// the platform supports it.
 inline void abort(const char* file, int line, const char* message, ...)
@@ -107,7 +48,7 @@ inline void abort(const char* file, int line, const char* message, ...)
 	vprintf(message, ap);
 	va_end(ap);
 	printf("\tIn: %s:%d\n", file, line);
-	log_backtrace();
+	stacktrace();
 	exit(EXIT_FAILURE);
 }
 

+ 6 - 0
engine/os/android/apk_file.cpp → engine/core/filesystem/apk_file.cpp

@@ -24,6 +24,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include "config.h"
+
+#if CROWN_PLATFORM_ANDROID
+
 #include "apk_file.h"
 #include "assert.h"
 #include "macros.h"
@@ -155,3 +159,5 @@ bool ApkFile::can_seek() const
 }
 
 } // namespace crown
+
+#endif // CROWN_PLATFORM_ANDROID

+ 0 - 0
engine/os/android/apk_file.h → engine/core/filesystem/apk_file.h


+ 6 - 0
engine/os/android/apk_filesystem.cpp → engine/core/filesystem/apk_filesystem.cpp

@@ -24,6 +24,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include "config.h"
+
+#if CROWN_PLATFORM_ANDROID
+
 #include <sys/types.h>
 #include <android/asset_manager.h>
 #include "apk_filesystem.h"
@@ -125,3 +129,5 @@ void ApkFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
 }
 
 } // namespace crown
+
+#endif // CROWN_PLATFORM_ANDROID

+ 0 - 0
engine/os/android/apk_filesystem.h → engine/core/filesystem/apk_filesystem.h


+ 16 - 17
engine/core/filesystem/null_file.h

@@ -41,24 +41,24 @@ class NullFile: public File
 public:
 
 	/// @copydoc File::File()
-				NullFile(FileOpenMode mode) : File(mode) {}
+	NullFile(FileOpenMode mode) : File(mode) {}
 
 	/// @copydoc File::~File()
-	virtual		~NullFile() {}
+	virtual ~NullFile() {}
 
 	/// @copydoc File::seek()
-	void		seek(size_t position) { (void)position; }
+	void seek(size_t position) { (void)position; }
 
 	/// @copydoc File::seek_to_end()
-	void		seek_to_end() {}
+	void seek_to_end() {}
 
 	/// @copydoc File::skip()
-	void		skip(size_t bytes) { (void)bytes; }
+	void skip(size_t bytes) { (void)bytes; }
 
 	/// @copydoc File::read()
 	/// @note
 	///	Fills buffer with zeroes
-	void		read(void* buffer, size_t size)
+	void read(void* buffer, size_t size)
 	{
 		for (size_t i = 0; i < size; i++)
 		{
@@ -67,12 +67,12 @@ public:
 	}
 
 	/// @copydoc File::write()
-	void		write(const void* buffer, size_t size) { (void)buffer; (void)size; }
+	void write(const void* buffer, size_t size) { (void)buffer; (void)size; }
 
 	/// @copydoc File::copy_to()
 	/// @note
 	///	Returns always true
-	bool		copy_to(File& file, size_t size = 0)
+	bool copy_to(File& file, size_t size = 0)
 	{
 		char zero = 0;
 		file.write(&zero, size);
@@ -80,43 +80,42 @@ public:
 	}
 
 	/// @copydoc File::flush()
-	void		flush() {};
+	void flush() {};
 
 	/// @copydoc File::is_valid()
 	/// @note
 	///	Returns always true
-	bool		is_valid() { return true; }
+	bool is_valid() { return true; }
 
 	/// @copydoc File::end_of_file()
 	/// @note
 	///	Returns always false
-	bool		end_of_file() { return false; }
+	bool end_of_file() { return false; }
 
 	/// @copydoc File::size()
 	/// @note
 	///	Returns always 0xFFFFFFFF
-	size_t		size() { return ~0; }
+	size_t size() { return ~0; }
 
 	/// @copydoc File::position()
 	/// @note
 	///	Returns always zero
-	size_t		position() { return 0; }
+	size_t position() { return 0; }
 
 	/// @copydoc File::can_read()
 	/// @note
 	///	Returns always true
-	bool		can_read() { return true; }
+	bool can_read() { return true; }
 
 	/// @copydoc File::can_write()
 	/// @note
 	///	Returns always true
-	bool		can_write() { return true; }
+	bool can_write() { return true; }
 
 	/// @copydoc File::can_seek()
 	/// @note
 	///	Returns always true
-	bool		can_seek() { return true; }
+	bool can_seek() { return true; }
 };
 
 } // namespace crown
-

+ 231 - 0
engine/core/filesystem/os_file.h

@@ -0,0 +1,231 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include <cstdio>
+#include "types.h"
+#include "assert.h"
+#include "config.h"
+#include "file.h" // FileOpenMode
+
+#if CROWN_PLATFORM_WINDOWS
+	#include "tchar.h"
+#endif
+
+namespace crown
+{
+
+/// Standard C file wrapper
+class OsFile
+{
+public:
+
+	/// Opens the file located at @a path with the given @a mode.
+	OsFile(const char* path, FileOpenMode mode)
+#if CROWN_PLATFORM_WINDOWS
+		: _eof(false)
+#endif
+	{
+#if CROWN_PLATFORM_POSIX
+		_file = fopen(path, (mode == FOM_READ) ? "rb" : "wb");
+		CE_ASSERT(_file != NULL, "Unable to open file: %s", path);
+#elif CROWN_PLATFORM_WINDOWS
+		_file = CreateFile(path,
+			mode == FOM_READ ? GENERIC_READ : GENERIC_WRITE,
+			0,
+			NULL,
+			OPEN_ALWAYS,
+			FILE_ATTRIBUTE_NORMAL,
+			NULL);
+		CE_ASSERT(_file != INVALID_HANDLE_VALUE, "Unable to open file: %s", path);
+#endif
+	}
+
+	~OsFile()
+	{
+		close();
+	}
+
+	/// Closes the file.
+	void close()
+	{
+#if CROWN_PLATFORM_POSIX
+		if (_file != NULL)
+		{
+			fclose(_file);
+			_file = NULL;
+		}
+#elif CROWN_PLATFORM_WINDOWS
+		if (is_open())
+		{
+			CloseHandle(_file);
+			_file = NULL;
+		}
+#endif
+	}
+
+	bool is_open() const
+	{
+		return _file != NULL;
+	}
+
+	/// Return the size of the file in bytes.
+	size_t size() const
+	{
+#if CROWN_PLATFORM_POSIX
+		size_t pos = position();
+
+		int fseek_result = fseek(_file, 0, SEEK_END);
+		CE_ASSERT(fseek_result == 0, "Failed to seek");
+
+		size_t size = position();
+
+		fseek_result = fseek(_file, (long) pos, SEEK_SET);
+		CE_ASSERT(fseek_result == 0, "Failed to seek");
+		CE_UNUSED(fseek_result);
+
+		return size;
+#elif CROWN_PLATFORM_WINDOWS
+		return GetFileSize(_file, NULL);
+#endif		
+	}
+
+	/// Reads @a size bytes from the file and stores it into @a data.
+	/// Returns the number of bytes read.
+	size_t read(void* data, size_t size)
+	{
+		CE_ASSERT(data != NULL, "Data must be != NULL");
+#if CROWN_PLATFORM_POSIX
+		return fread(data, 1, size, _file);
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD bytes_read;
+
+		BOOL result = ReadFile(_file, data, size, &bytes_read, NULL);
+
+		CE_ASSERT(result == TRUE, "Unable to read from file");
+
+		if (result && bytes_read == 0)
+		{
+			_eof = true;
+		}
+
+		return bytes_read;
+#endif
+	}
+
+	/// Writes @a size bytes of data stored in @a data and returns the
+	/// number of bytes written.
+	size_t write(const void* data, size_t size)
+	{
+		CE_ASSERT(data != NULL, "Data must be != NULL");
+#if CROWN_PLATFORM_POSIX
+		return fwrite(data, 1, size, _file);
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD bytes_written;
+		bool write = WriteFile(_file, data, size, &bytes_written, NULL);
+		CE_ASSERT(size == bytes_written, "Cannot read from file\n");
+		return size;
+#endif
+	}
+
+	/// Moves the file pointer to the given @a position.
+	void seek(size_t position)
+	{
+#if CROWN_PLATFORM_POSIX
+		int err = fseek(_file, (long) position, SEEK_SET);
+		CE_ASSERT(err == 0, "Failed to seek");
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD err = SetFilePointer(_file, position, NULL, FILE_BEGIN);
+		CE_ASSERT(err != INVALID_SET_FILE_POINTER, "Failed to seek");
+#endif		
+		CE_UNUSED(err);
+	}
+
+	/// Moves the file pointer to the end of the file.
+	void seek_to_end()
+	{
+#if CROWN_PLATFORM_POSIX
+		int fseek_result = fseek(_file, 0, SEEK_END);
+		CE_ASSERT(fseek_result == 0, "Failed to seek");
+		CE_UNUSED(fseek_result);
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD seek_result = SetFilePointer(_file, 0, NULL, FILE_END);
+		CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to seek to end");
+#endif
+	}
+
+	/// Moves the file pointer @a bytes bytes ahead the current
+	/// file pointer position.
+	void skip(size_t bytes)
+	{
+#if CROWN_PLATFORM_POSIX
+		int fseek_result = fseek(_file, bytes, SEEK_CUR);
+		CE_ASSERT(fseek_result == 0, "Failed to seek");
+		CE_UNUSED(fseek_result);
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD seek_result = SetFilePointer(_file, bytes, NULL, FILE_CURRENT);
+
+		CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to skip");
+#endif
+	}
+
+	/// Returns the position of the file pointer from the
+	/// start of the file in bytes.
+	size_t position() const
+	{
+#if CROWN_PLATFORM_POSIX		
+		return (size_t) ftell(_file);
+#elif CROWN_PLATFORM_WINDOWS
+		DWORD position = SetFilePointer(_file, 0, NULL, FILE_CURRENT);
+
+		CE_ASSERT(position != INVALID_SET_FILE_POINTER, "Failed to get position");
+
+		return position;
+#endif
+	}
+
+	/// Returns whether the file pointer is at the end of the file.
+	bool eof() const
+	{
+#if CROWN_PLATFORM_POSIX
+		return feof(_file) != 0;
+#elif CROWN_PLATFORM_WINDOWS
+		return _eof;
+#endif		
+	}
+
+private:
+
+#if CROWN_PLATFORM_POSIX
+	FILE* _file;
+#elif CROWN_PLATFORM_WINDOWS
+	HANDLE _file;
+	bool _eof;
+#endif
+};
+
+} // namespace crown

+ 2 - 2
engine/core/json/json_parser.h

@@ -44,7 +44,7 @@ class File;
 /// which has generated them, will exist.
 ///
 /// @ingroup JSON
-class CE_EXPORT JSONElement
+class JSONElement
 {
 public:
 
@@ -185,7 +185,7 @@ private:
 /// Parses JSON documents.
 ///
 /// @ingroup JSON
-class CE_EXPORT JSONParser
+class JSONParser
 {
 public:
 

+ 97 - 3
engine/os/os_event_queue.h → engine/core/os_event_queue.h

@@ -27,14 +27,108 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include <cstring>
-#include "os_types.h"
+#include "types.h"
+#include "mouse.h"
+#include "keyboard.h"
 #include "atomic_int.h"
 
-#define MAX_OS_EVENTS 64
-
 namespace crown
 {
 
+struct OsMetricsEvent
+{
+	uint16_t x;
+	uint16_t y;
+	uint16_t width;
+	uint16_t height;
+};
+
+struct OsExitEvent
+{
+	int32_t code;
+};
+
+/// Represents an event fired by mouse.
+struct OsMouseEvent
+{
+	enum Enum
+	{
+		BUTTON,
+		MOVE
+	};
+
+	OsMouseEvent::Enum type;
+	MouseButton::Enum button;
+	uint16_t x;
+	uint16_t y;
+	bool pressed;
+};
+
+/// Represents an event fired by keyboard.
+struct OsKeyboardEvent
+{
+	KeyboardButton::Enum button;
+	uint32_t modifier;
+	bool pressed;
+};
+
+/// Represents an event fired by touch screen.
+struct OsTouchEvent
+{
+	enum Enum
+	{
+		POINTER,
+		MOVE
+	};
+
+	OsTouchEvent::Enum type;
+	uint8_t pointer_id;
+	uint16_t x;
+	uint16_t y;
+	bool pressed;
+};
+
+/// Represents an event fired by accelerometer.
+struct OsAccelerometerEvent
+{
+	float x;
+	float y;
+	float z;
+};
+
+struct OsEvent
+{
+	/// Represents an event fired by the OS
+	enum Enum
+	{
+		NONE			= 0,
+
+		KEYBOARD		= 1,
+		MOUSE			= 2,
+		TOUCH			= 3,
+		ACCELEROMETER	= 4,
+
+		METRICS,
+		PAUSE,
+		RESUME,
+		// Exit from program
+		EXIT
+	};
+
+	OsEvent::Enum type;
+	union
+	{
+		OsMetricsEvent metrics;
+		OsExitEvent exit;
+		OsMouseEvent mouse;
+		OsKeyboardEvent keyboard;
+		OsTouchEvent touch;
+		OsAccelerometerEvent accelerometer;
+	};
+};
+
+#define MAX_OS_EVENTS 64
+
 /// Single Producer Single Consumer event queue.
 /// Used only to pass events from os thread to main thread.
 struct OsEventQueue

+ 7 - 1
engine/os/android/os_window.cpp → engine/core/os_window_android.cpp

@@ -24,7 +24,11 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "os_window.h"
+#include "config.h"
+
+#if CROWN_PLATFORM_ANDROID
+
+#include "os_window_android.h"
 #include "assert.h"
 #include "log.h"
 
@@ -132,3 +136,5 @@ void OsWindow::frame()
 }
 
 } // namespace crown
+
+#endif // CROWN_PLATFORM_ANDROID

+ 0 - 0
engine/os/android/os_window.h → engine/core/os_window_android.h


+ 7 - 3
engine/os/linux/os_window.cpp → engine/core/os_window_linux.cpp

@@ -23,7 +23,11 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "os_window.h"
+#include "config.h"
+
+#if CROWN_PLATFORM_LINUX
+
+#include "os_window_linux.h"
 #include "assert.h"
 #include "string_utils.h"
 #include "log.h"
@@ -47,9 +51,7 @@ OsWindow::OsWindow()
 	, m_width(0)
 	, m_height(0)
 	, m_resizable(true)
-	, m_x11_detectable_autorepeat(false)
 {
-	set_title("");
 }
 
 //-----------------------------------------------------------------------------
@@ -149,3 +151,5 @@ void OsWindow::set_title(const char* title)
 }
 
 } // namespace crown
+
+#endif // CROWN_PLATFORM_LINUX

+ 24 - 29
engine/os/linux/os_window.h → engine/core/os_window_linux.h

@@ -26,57 +26,52 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
+#include "types.h"
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
 #include <X11/XKBlib.h>
 
-#include "types.h"
-
 namespace crown
 {
 
 void oswindow_set_window(Display* dpy, Window win);
 
-
-class OsWindow
+struct OsWindow
 {
-public:
-					OsWindow();
-					~OsWindow();
+	OsWindow();
+	~OsWindow();
 
-	void			show();
-	void			hide();
+	void show();
+	void hide();
 
-	void			get_size(uint32_t& width, uint32_t& height);
-	void			get_position(uint32_t& x, uint32_t& y);
+	void get_size(uint32_t& width, uint32_t& height);
+	void get_position(uint32_t& x, uint32_t& y);
 
-	void			resize(uint32_t width, uint32_t height);
-	void			move(uint32_t x, uint32_t y);
+	void resize(uint32_t width, uint32_t height);
+	void move(uint32_t x, uint32_t y);
 
-	void			minimize();
-	void			restore();
+	void minimize();
+	void restore();
 
-	bool			is_resizable() const;
-	void			set_resizable(bool resizable);
+	bool is_resizable() const;
+	void set_resizable(bool resizable);
 
-	void			show_cursor(bool show);
+	void show_cursor(bool show);
 
-	void			get_cursor_xy(int32_t& x, int32_t& y);
-	void			set_cursor_xy(int32_t x, int32_t y);
+	void get_cursor_xy(int32_t& x, int32_t& y);
+	void set_cursor_xy(int32_t x, int32_t y);
 
-	char*			title();
-	void			set_title(const char* title);
+	char* title();
+	void set_title(const char* title);
 
 public:
 
-	uint32_t		m_x;
-	uint32_t		m_y;
-	uint32_t		m_width;
-	uint32_t		m_height;
-	bool			m_resizable;
-
-	bool			m_x11_detectable_autorepeat;
+	uint32_t m_x;
+	uint32_t m_y;
+	uint32_t m_width;
+	uint32_t m_height;
+	bool m_resizable;
 };
 
 } // namespace crown

+ 6 - 0
engine/os/win/os_window.cpp → engine/core/os_window_windows.cpp

@@ -23,6 +23,10 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include "config.h"
+
+#if CROWN_PLATFORM_WINDOWS
+
 #include "os_window.h"
 #include "string_utils.h"
 
@@ -128,3 +132,5 @@ void OsWindow::set_title(const char* title)
 }
 
 } // namespace crown
+
+#endif // CROWN_PLATFORM_WINDOWS

+ 16 - 17
engine/os/win/os_window.h → engine/core/os_window_windows.h

@@ -27,39 +27,38 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "win_headers.h"
-
 #include "types.h"
 #include "macros.h"
 
 namespace crown
 {
 
-CE_EXPORT void oswindow_set_window(HWND handle_win);
+void oswindow_set_window(HWND handle_win);
 
-class OsWindow
+struct OsWindow
 {
 public:
 
-					OsWindow();
-					~OsWindow();
+	OsWindow();
+	~OsWindow();
 
-	void			show();
-	void			hide();
+	void show();
+	void hide();
 
-	void			get_size(uint32_t& width, uint32_t& height);
-	void			get_position(uint32_t& x, uint32_t& y);
+	void get_size(uint32_t& width, uint32_t& height);
+	void get_position(uint32_t& x, uint32_t& y);
 
-	void			resize(uint32_t width, uint32_t height);
-	void			move(uint32_t x, uint32_t y);
+	void resize(uint32_t width, uint32_t height);
+	void move(uint32_t x, uint32_t y);
 
-	void			minimize();
-	void			restore();
+	void minimize();
+	void restore();
 
-	bool			is_resizable() const;
-	void			set_resizable(bool resizable);
+	bool is_resizable() const;
+	void set_resizable(bool resizable);
 
-	char*			title();
-	void			set_title(const char* title);
+	char* title();
+	void set_title(const char* title);
 
 public:
 

+ 6 - 1
engine/os/linux/os_file.h → engine/core/stacktrace.h

@@ -26,4 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "../posix/os_file.h"
+namespace crown
+{
+
+void stacktrace();
+
+} // namespace crown

+ 13 - 2
engine/os/android/os_file.h → engine/core/stacktrace_android.cpp

@@ -24,6 +24,17 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#pragma once
+#include "config.h"
 
-#include "../posix/os_file.h"
+#if CROWN_PLATFORM_ANDROID
+
+namespace crown
+{
+
+void stacktrace()
+{
+}
+
+} // namespace crown
+
+#endif // CROWN_PLATFORM_ANDROID

+ 94 - 0
engine/core/stacktrace_linux.cpp

@@ -0,0 +1,94 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "config.h"
+
+#if CROWN_PLATFORM_LINUX && CROWN_COMPILER_GCC
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <cxxabi.h>
+#include <execinfo.h>
+
+namespace crown
+{
+
+void stacktrace()
+{
+	printf("Stacktrace:\n");
+	void* array[50];
+	int size = backtrace(array, 50);
+
+	char** messages = backtrace_symbols(array, size);
+
+	// skip first stack frame (points here)
+	for (int i = 1; i < size && messages != NULL; ++i)
+	{
+		char *mangled_name = 0, *offset_begin = 0, *offset_end = 0;
+
+		// find parantheses and +address offset surrounding mangled name
+		for (char *p = messages[i]; *p; ++p)
+		{
+			if (*p == '(')
+			{
+				mangled_name = p;
+			}
+			else if (*p == '+')
+			{
+				offset_begin = p;
+			}
+			else if (*p == ')')
+			{
+				offset_end = p;
+				break;
+			}
+		}
+
+		// if the line could be processed, attempt to demangle the symbol
+		if (mangled_name && offset_begin && offset_end && mangled_name < offset_begin)
+		{
+			*mangled_name++ = '\0';
+			*offset_begin++ = '\0';
+			*offset_end++ = '\0';
+
+			int status;
+			char* real_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);
+
+			printf("\t[%d] %s: (%s)+%s %s\n", i, messages[i], (status == 0 ? real_name : mangled_name), offset_begin, offset_end);
+			free(real_name);
+		}
+		// otherwise, print the whole line
+		else
+		{
+			printf("\t[%d] %s\n", i, messages[i]);
+		}
+	}
+	free(messages);
+}
+
+} // namespace crown
+
+#endif // CROWN_PLATFORM_LINUX && CROWN_COMPILER_GCC

+ 40 - 0
engine/core/stacktrace_windows.cpp

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

+ 0 - 5
engine/device.cpp

@@ -40,7 +40,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "memory.h"
 #include "mouse.h"
 #include "os.h"
-#include "os_window.h"
 #include "resource_manager.h"
 #include "string_setting.h"
 #include "string_utils.h"
@@ -152,10 +151,6 @@ void Device::init()
 	CE_LOGD("Creating world manager...");
 	m_world_manager = CE_NEW(m_allocator, WorldManager)();
 
-	// Create window
-	CE_LOGD("Creating main window...");
-	m_window = CE_NEW(m_allocator, OsWindow);
-
 	// Create input devices
 	m_keyboard = CE_NEW(m_allocator, Keyboard);
 	m_mouse = CE_NEW(m_allocator, Mouse);

+ 2 - 2
engine/device.h

@@ -225,8 +225,8 @@ private:
 	Device& operator=(const Device&);
 };
 
-CE_EXPORT Device* device();
+Device* device();
 
-CE_EXPORT void set_device(Device* device);
+void set_device(Device* device);
 
 } // namespace crown

+ 10 - 1
engine/lua/lua_window.cpp

@@ -24,7 +24,16 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "os_window.h"
+#include "config.h"
+
+#if CROWN_PLATFORM_LINUX
+	#include "os_window_linux.h"
+#elif CROWN_PLATFORM_WINDOWS
+	#include "os_window_windows.h"
+#elif CROWN_PLATFORM_ANDROID
+	#include "os_window_android.h"
+#endif
+
 #include "device.h"
 #include "lua_stack.h"
 #include "lua_environment.h"

+ 0 - 0
engine/os/android/AndroidManifest.xml → engine/main/AndroidManifest.xml


+ 0 - 0
engine/os/android/CrownActivity.java → engine/main/CrownActivity.java


+ 8 - 2
engine/os/android/android_device.cpp → engine/main/main_android.cpp

@@ -24,13 +24,17 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include "config.h"
+
+#if CROWN_PLATFORM_ANDROID
+
 #include "allocator.h"
 #include "device.h"
 #include "log.h"
 #include "os_event_queue.h"
-#include "touch.h"
-#include "os_window.h"
+#include "os_window_android.h"
 #include "thread.h"
+#include "touch.h"
 #include <jni.h>
 #include <android/sensor.h>
 #include <android_native_app_glue.h>
@@ -358,3 +362,5 @@ void android_main(struct android_app* app)
 	CE_DELETE(crown::default_allocator(), engine);
 	crown::memory::shutdown();
 }
+
+#endif // CROWN_PLATFORM_ANDROID

+ 14 - 6
engine/os/linux/main.cpp → engine/main/main_linux.cpp

@@ -25,16 +25,18 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "config.h"
-#include "device.h"
-#include "os_types.h"
-#include "os_event_queue.h"
+
+#if CROWN_PLATFORM_LINUX
+
+#include "args.h"
 #include "bundle_compiler.h"
-#include "memory.h"
+#include "device.h"
 #include "json_parser.h"
 #include "log.h"
-#include "args.h"
+#include "memory.h"
+#include "os_event_queue.h"
+#include "os_window_linux.h"
 #include "thread.h"
-#include "os_window.h"
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
@@ -314,6 +316,10 @@ public:
 		Thread game_thread;
 		game_thread.start(main_loop, (void*)this);
 
+		// Create window
+		CE_LOGD("Creating main window...");
+		m_window = CE_NEW(m_allocator, OsWindow);
+
 		while (!m_exit)
 		{
 			LinuxDevice::pump_events();
@@ -769,3 +775,5 @@ int main(int argc, char** argv)
 	crown::shutdown();
 	return ret;
 }
+
+#endif // CROWN_PLATFORM_LINUX

+ 11 - 6
engine/os/win/main.cpp → engine/main/main_windows.cpp

@@ -24,22 +24,25 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include "config.h"
+
+#if CROWN_PLATFORM_WINDOWS
+
 #include <windowsx.h>
 
 #define WM_USER_SET_WINDOW_SIZE     (WM_USER+0)
 #define WM_USER_TOGGLE_WINDOW_FRAME (WM_USER+1)
 #define WM_USER_MOUSE_LOCK          (WM_USER+2)
 
-#include "os_types.h"
-#include "os_event_queue.h"
+#include "args.h"
 #include "bundle_compiler.h"
 #include "device.h"
-#include "thread.h"
-#include "log.h"
-#include "os_window.h"
-#include "args.h"
 #include "json_parser.h"
+#include "log.h"
 #include "os.h"
+#include "os_event_queue.h"
+#include "os_window_windows.h"
+#include "thread.h"
 #include <bgfxplatform.h>
 
 #define ENTRY_DEFAULT_WIDTH 1000
@@ -701,3 +704,5 @@ int main(int argc, char** argv)
 
 	return ret;
 }
+
+#endif // CROWN_PLATFORM_WINDOWS

+ 0 - 0
engine/os/win/win_headers.h → engine/main/win_headers.h


+ 0 - 128
engine/os/os_types.h

@@ -1,128 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "types.h"
-#include "mouse.h"
-#include "keyboard.h"
-
-namespace crown
-{
-
-struct OsMetricsEvent
-{
-	uint16_t x;
-	uint16_t y;
-	uint16_t width;
-	uint16_t height;
-};
-
-struct OsExitEvent
-{
-	int32_t code;
-};
-
-/// Represents an event fired by mouse.
-struct OsMouseEvent
-{
-	enum Enum
-	{
-		BUTTON,
-		MOVE
-	};
-
-	OsMouseEvent::Enum type;
-	MouseButton::Enum button;
-	uint16_t x;
-	uint16_t y;
-	bool pressed;
-};
-
-/// Represents an event fired by keyboard.
-struct OsKeyboardEvent
-{
-	KeyboardButton::Enum button;
-	uint32_t modifier;
-	bool pressed;
-};
-
-/// Represents an event fired by touch screen.
-struct OsTouchEvent
-{
-	enum Enum
-	{
-		POINTER,
-		MOVE
-	};
-
-	OsTouchEvent::Enum type;
-	uint8_t pointer_id;
-	uint16_t x;
-	uint16_t y;
-	bool pressed;
-};
-
-/// Represents an event fired by accelerometer.
-struct OsAccelerometerEvent
-{
-	float x;
-	float y;
-	float z;
-};
-
-struct OsEvent
-{
-	/// Represents an event fired by the OS
-	enum Enum
-	{
-		NONE			= 0,
-
-		KEYBOARD		= 1,
-		MOUSE			= 2,
-		TOUCH			= 3,
-		ACCELEROMETER	= 4,
-
-		METRICS,
-		PAUSE,
-		RESUME,
-		// Exit from program
-		EXIT
-	};
-
-	OsEvent::Enum type;
-	union
-	{
-		OsMetricsEvent metrics;
-		OsExitEvent exit;
-		OsMouseEvent mouse;
-		OsKeyboardEvent keyboard;
-		OsTouchEvent touch;
-		OsAccelerometerEvent accelerometer;
-	};
-};
-
-} // namespace crown

+ 0 - 144
engine/os/posix/os_file.cpp

@@ -1,144 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <stdio.h>
-
-#include "assert.h"
-#include "os.h"
-#include "os_file.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-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;
-}
-
-//-----------------------------------------------------------------------------
-OsFile::~OsFile()
-{
-	close();
-}
-
-//-----------------------------------------------------------------------------
-void OsFile::close()
-{
-	if (m_file_handle != NULL)
-	{
-		fclose(m_file_handle);
-		m_file_handle = NULL;
-	}
-}
-
-//-----------------------------------------------------------------------------
-bool OsFile::is_open() const
-{
-	return m_file_handle != NULL;
-}
-
-//-----------------------------------------------------------------------------
-FileOpenMode OsFile::mode()
-{
-	return m_mode;
-}
-
-//-----------------------------------------------------------------------------
-size_t OsFile::size() const
-{
-	size_t pos = position();
-
-	int fseek_result = fseek(m_file_handle, 0, SEEK_END);
-	CE_ASSERT(fseek_result == 0, "Failed to seek");
-
-	size_t size = position();
-
-	fseek_result = fseek(m_file_handle, (long) pos, SEEK_SET);
-	CE_ASSERT(fseek_result == 0, "Failed to seek");
-	CE_UNUSED(fseek_result);
-
-	return size;
-}
-
-//-----------------------------------------------------------------------------
-size_t OsFile::read(void* data, size_t size)
-{
-	CE_ASSERT(data != NULL, "Data must be != NULL");
-
-	return fread(data, 1, size, m_file_handle);
-}
-
-//-----------------------------------------------------------------------------
-size_t OsFile::write(const void* data, size_t size)
-{
-	CE_ASSERT(data != NULL, "Data must be != NULL");
-
-	return fwrite(data, 1, size, m_file_handle);
-}
-
-//-----------------------------------------------------------------------------
-void OsFile::seek(size_t position)
-{
-	int fseek_result = fseek(m_file_handle, (long) position, SEEK_SET);
-	CE_ASSERT(fseek_result == 0, "Failed to seek");
-	CE_UNUSED(fseek_result);
-}
-
-//-----------------------------------------------------------------------------
-void OsFile::seek_to_end()
-{
-	int fseek_result = fseek(m_file_handle, 0, SEEK_END);
-	CE_ASSERT(fseek_result == 0, "Failed to seek");
-	CE_UNUSED(fseek_result);
-}
-
-//-----------------------------------------------------------------------------
-void OsFile::skip(size_t bytes)
-{
-	int fseek_result = fseek(m_file_handle, bytes, SEEK_CUR);
-	CE_ASSERT(fseek_result == 0, "Failed to seek");
-	CE_UNUSED(fseek_result);
-}
-
-//-----------------------------------------------------------------------------
-size_t OsFile::position() const
-{
-	return (size_t) ftell(m_file_handle);
-}
-
-//-----------------------------------------------------------------------------
-bool OsFile::eof() const
-{
-	return feof(m_file_handle) != 0;
-}
-
-} // namespace crown
-

+ 0 - 89
engine/os/posix/os_file.h

@@ -1,89 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <cstdio>
-
-#include "types.h"
-#include "file.h"
-
-namespace crown
-{
-
-/// Standard C file wrapper
-class OsFile
-{
-public:
-
-	/// Opens the file located at @a path with the given @a mode.
-							OsFile(const char* path, FileOpenMode mode);
-							~OsFile();
-
-	/// Closes the file.
-	void					close();
-
-	bool					is_open() const;
-
-	/// Return the size of the file in bytes.
-	size_t					size() const;
-
-	/// Returs the mode used to open the file.
-	FileOpenMode			mode();
-
-	/// Reads @a size bytes from the file and stores it into @a data.
-	/// Returns the number of bytes read.
-	size_t					read(void* data, size_t size);
-
-	/// Writes @a size bytes of data stored in @a data and returns the
-	/// number of bytes written.
-	size_t					write(const void* data, size_t size);
-
-	/// Moves the file pointer to the given @a position.
-	void					seek(size_t position);
-
-	/// Moves the file pointer to the end of the file.
-	void					seek_to_end();
-
-	/// Moves the file pointer @a bytes bytes ahead the current
-	/// file pointer position.
-	void					skip(size_t bytes);
-
-	/// Returns the position of the file pointer from the
-	/// start of the file in bytes.
-	size_t					position() const;
-
-	/// Returns whether the file pointer is at the end of the file.
-	bool					eof() const;
-
-private:
-
-	FILE*					m_file_handle;
-	FileOpenMode			m_mode;
-};
-
-} // namespace crown
-

+ 0 - 147
engine/os/win/os_file.cpp

@@ -1,147 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "os_file.h"
-#include "assert.h"
-#include "os.h"
-#include "tchar.h"
-
-namespace crown
-{
-
-OsFile::OsFile(const char* path, FileOpenMode mode) :
-	m_eof(false)
-{
-	m_file_handle = CreateFile(path,
-							   mode == FOM_READ ? GENERIC_READ : GENERIC_WRITE,
-							   0,
-							   NULL,
-							   OPEN_ALWAYS,
-        					   FILE_ATTRIBUTE_NORMAL,
-        					   NULL);
-
-	CE_ASSERT(m_file_handle != INVALID_HANDLE_VALUE, "Unable to open file: %s", path);
-
-	m_mode = mode;
-}
-
-OsFile::~OsFile()
-{
-	close();
-}
-
-void OsFile::close()
-{
-	if (is_open())
-	{
-		CloseHandle(m_file_handle);
-		m_file_handle = NULL;
-	}
-}
-
-bool OsFile::is_open() const
-{
-	return m_file_handle != NULL;
-}
-
-size_t OsFile::size() const
-{
-	DWORD size;
-
-	size = GetFileSize(m_file_handle, NULL);
-
-	return size;
-}
-
-FileOpenMode OsFile::mode()
-{
-	return m_mode;
-}
-
-size_t OsFile::read(void* data, size_t size)
-{
-	DWORD bytes_read;
-
-	BOOL result = ReadFile(m_file_handle, data, size, &bytes_read, NULL);
-
-	CE_ASSERT(result == TRUE, "Unable to read from file");
-
-	if (result && bytes_read == 0)
-	{
-		m_eof = true;
-	}
-
-	return bytes_read;
-}
-
-size_t OsFile::write(const void* data, size_t size)
-{
-	DWORD bytes_written;
-
-	bool write = WriteFile(m_file_handle, data, size, &bytes_written, NULL);
-
-	CE_ASSERT(size == bytes_written, "Cannot read from file\n");
-
-	return size;
-}
-
-void OsFile::seek(size_t position)
-{
-	DWORD seek_result = SetFilePointer(m_file_handle, position, NULL, FILE_BEGIN);
-
-	CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to seek");
-}
-
-void OsFile::seek_to_end()
-{
-	DWORD seek_result = SetFilePointer(m_file_handle, 0, NULL, FILE_END);
-
-	CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to seek to end");
-}
-
-void OsFile::skip(size_t bytes)
-{
-	DWORD seek_result = SetFilePointer(m_file_handle, bytes, NULL, FILE_CURRENT);
-
-	CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to skip");
-}
-
-size_t OsFile::position() const
-{
-	DWORD position = SetFilePointer(m_file_handle, 0, NULL, FILE_CURRENT);
-
-	CE_ASSERT(position != INVALID_SET_FILE_POINTER, "Failed to get position");
-
-	return position;
-}
-
-bool OsFile::eof() const
-{
-	return m_eof;
-}
-
-} // namespace crown
-

+ 0 - 90
engine/os/win/os_file.h

@@ -1,90 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <cstdio>
-#include "win_headers.h"
-#include "types.h"
-#include "file.h"
-
-namespace crown
-{
-
-/// Standard C file wrapper
-class OsFile
-{
-public:
-
-	/// Opens the file located at @a path with the given @a mode.
-							OsFile(const char* path, FileOpenMode mode);
-							~OsFile();
-
-	/// Closes the file.
-	void					close();
-
-	bool					is_open() const;
-
-	/// Return the size of the file in bytes.
-	size_t					size() const;
-
-	/// Returs the mode used to open the file.
-	FileOpenMode			mode();
-
-	/// Reads @a size bytes from the file and stores it into @a data.
-	/// Returns the number of bytes read.
-	size_t					read(void* data, size_t size);
-
-	/// Writes @a size bytes of data stored in @a data and returns the
-	/// number of bytes written.
-	size_t					write(const void* data, size_t size);
-
-	/// Moves the file pointer to the given @a position.
-	void					seek(size_t position);
-
-	/// Moves the file pointer to the end of the file.
-	void					seek_to_end();
-
-	/// Moves the file pointer @a bytes bytes ahead the current
-	/// file pointer position.
-	void					skip(size_t bytes);
-
-	/// Returns the position of the file pointer from the
-	/// start of the file in bytes.
-	size_t					position() const;
-
-	/// Returns whether the file pointer is at the end of the file.
-	bool					eof() const;
-
-private:
-
-	HANDLE					m_file_handle;
-	FileOpenMode			m_mode;
-	bool					m_eof;
-};
-
-} // namespace crown
-

+ 2 - 11
premake/premake4.lua

@@ -172,7 +172,7 @@ solution "crown"
 			CROWN_SOURCE_DIR .. "/engine/core/settings",
 			CROWN_SOURCE_DIR .. "/engine/core/strings",
 			CROWN_SOURCE_DIR .. "/engine/core/thread",
-			CROWN_SOURCE_DIR .. "/engine/os",
+			CROWN_SOURCE_DIR .. "/engine/main",
 			CROWN_SOURCE_DIR .. "/engine/input",
 			CROWN_SOURCE_DIR .. "/engine/renderers",
 			CROWN_SOURCE_DIR .. "/engine/resource",
@@ -216,7 +216,6 @@ solution "crown"
 			}
 
 			includedirs {
-				CROWN_SOURCE_DIR .. "/engine/os/linux",
 				CROWN_THIRD_DIR .. "luajit/src",
 				CROWN_THIRD_DIR .. "openal/include",
 				CROWN_THIRD_DIR .. "freetype",
@@ -245,8 +244,6 @@ solution "crown"
 			}
 
 			excludes {
-				CROWN_SOURCE_DIR .. "engine/os/android/*",
-				CROWN_SOURCE_DIR .. "engine/os/win/*",
 				CROWN_SOURCE_DIR .. "engine/audio/backend/sles_sound_world.cpp",
 			}
 			
@@ -452,7 +449,6 @@ solution "crown"
 			}
 
 			includedirs {
-				CROWN_SOURCE_DIR .. "engine/os/android",
 				CROWN_THIRD_DIR .. "luajit/src",
 				CROWN_THIRD_DIR .. "bgfx/include",
 				CROWN_THIRD_DIR .. "bx/include",
@@ -491,8 +487,6 @@ solution "crown"
 			}
 
 			excludes {
-				CROWN_SOURCE_DIR .. "engine/os/linux/*",
-				CROWN_SOURCE_DIR .. "engine/os/win/*",
 				CROWN_SOURCE_DIR .. "engine/audio/backend/al_sound_world.cpp"
 			}
 
@@ -589,12 +583,12 @@ solution "crown"
 			}
 
 			includedirs {
+				CROWN_SOURCE_DIR .. "core/compat/msvc",
 				CROWN_THIRD_DIR .. "luajit/src",
 				CROWN_THIRD_DIR .. "openal/include",
 				CROWN_THIRD_DIR .. "freetype",
 				CROWN_THIRD_DIR .. "stb_image",
 				CROWN_THIRD_DIR .. "stb_vorbis",
-				CROWN_SOURCE_DIR .. "/engine/os/win",
 				CROWN_THIRD_DIR .. "bgfx/src",
 				CROWN_THIRD_DIR .. "bgfx/include",
 				CROWN_THIRD_DIR .. "bx/include",
@@ -619,9 +613,6 @@ solution "crown"
 			}
 
 			excludes {
-				CROWN_SOURCE_DIR .. "engine/os/android/*",
-				CROWN_SOURCE_DIR .. "engine/os/linux/*",
-				CROWN_SOURCE_DIR .. "engine/os/posix/*",
 				CROWN_SOURCE_DIR .. "engine/audio/backend/sles_sound_world.cpp"
 			}