mikymod před 12 roky
rodič
revize
f55056f63e

+ 3 - 3
src/JSONParser.cpp

@@ -1,7 +1,7 @@
 #include "JSONParser.h"
 #include "JSONParser.h"
 #include "DiskFile.h"
 #include "DiskFile.h"
 #include "OS.h"
 #include "OS.h"
-#include "String.h"
+#include "StringUtils.h"
 #include "Assert.h"
 #include "Assert.h"
 #include <stdlib.h>
 #include <stdlib.h>
 
 
@@ -18,7 +18,7 @@ JSONParser::JSONParser(Allocator& allocator, File* file, size_t size) :
 {
 {
 	if (size > 1024)
 	if (size > 1024)
 	{
 	{
-		m_tokens = CE_NEW(m_allocator, JSONToken[size]);
+		m_tokens = CE_NEW(m_allocator, JSONToken[1024]);
 	}
 	}
 	else
 	else
 	{
 	{
@@ -347,7 +347,7 @@ void JSONParser::fill_token(JSONToken* token, JSONType type, int32_t start, int3
 	token->m_end = end;
 	token->m_end = end;
 	token->m_size = token->m_end - token->m_start;
 	token->m_size = token->m_end - token->m_start;
 
 
-	char tmp[token->m_size+1];
+	char tmp[1024];
 	m_file->seek(token->m_start);
 	m_file->seek(token->m_start);
 	m_file->read(tmp, token->m_size);
 	m_file->read(tmp, token->m_size);
 	tmp[token->m_size] = '\0';
 	tmp[token->m_size] = '\0';

+ 2 - 0
src/core/containers/RBTree.h

@@ -25,6 +25,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #pragma once
 #pragma once
+#undef min
+#undef max
 
 
 #include <cstdlib>
 #include <cstdlib>
 #include "Assert.h"
 #include "Assert.h"

+ 2 - 0
src/input/Mouse.cpp

@@ -28,6 +28,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Device.h"
 #include "Device.h"
 #include "OsWindow.h"
 #include "OsWindow.h"
 
 
+#undef MB_RIGHT
+
 namespace crown
 namespace crown
 {
 {
 
 

+ 8 - 6
src/os/win/OsFile.cpp

@@ -52,9 +52,11 @@ OsFile::~OsFile()
 
 
 void OsFile::close()
 void OsFile::close()
 {
 {
-	bool closed = CloseHandle(m_file_handle);
-	
-	CE_ASSERT(closed, "Unable to close file\n");
+	if (is_open())
+	{
+		CloseHandle(m_file_handle);
+		m_file_handle = NULL;
+	}
 }
 }
 
 
 bool OsFile::is_open() const
 bool OsFile::is_open() const
@@ -64,11 +66,11 @@ bool OsFile::is_open() const
 
 
 size_t OsFile::size() const
 size_t OsFile::size() const
 {
 {
-	LPDWORD size;
+	DWORD size;
 
 
-	GetFileSize(m_file_handle, size);
+	size = GetFileSize(m_file_handle, NULL);
 
 
-	return *size;
+	return size;
 }
 }
 
 
 FileOpenMode OsFile::mode()
 FileOpenMode OsFile::mode()

+ 46 - 35
src/os/win/OsWindow.cpp

@@ -91,29 +91,8 @@ static Key translate_key(int32_t winKey)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 OsWindow::OsWindow(uint32_t width, uint32_t height)
 OsWindow::OsWindow(uint32_t width, uint32_t height)
 {
 {
-	// FIXME: MUST BE TAKEN FROM DEVICE
-	bool fullscreen = false;
-
 	CE_ASSERT(!width && !height, "Width and height must differ from 0.");
 	CE_ASSERT(!width && !height, "Width and height must differ from 0.");
 
 
-	if (fullscreen)
-	{
-		DEVMODE dm_screen_setting; // Device Mode
-		memset(&dm_screen_setting, 0, sizeof(dm_screen_setting)); // Makes Sure Memory's Cleared
-		dm_screen_setting.dmSize = sizeof(dm_screen_setting); // Size Of The Devmode Structure
-		dm_screen_setting.dmPelsWidth = width; // Selected Screen Width
-		dm_screen_setting.dmPelsHeight = height; // Selected Screen Height
-		dm_screen_setting.dmBitsPerPel = 32; // Selected Bits Per Pixel
-		dm_screen_setting.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
-
-		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
-		if (ChangeDisplaySettings(&dm_screen_setting, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
-		{
-			fullscreen = false;
-			Log::i("Fullscreen resolution not supported, switching to windowed mode.");
-		}
-	}
-
 	strcpy(m_window_name, "CrownWindowClass");
 	strcpy(m_window_name, "CrownWindowClass");
 	WNDCLASSEX wcex;
 	WNDCLASSEX wcex;
 	wcex.cbSize = sizeof(WNDCLASSEX);
 	wcex.cbSize = sizeof(WNDCLASSEX);
@@ -122,38 +101,32 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 	wcex.cbClsExtra = 0;
 	wcex.cbClsExtra = 0;
 	wcex.cbWndExtra = 0;
 	wcex.cbWndExtra = 0;
 	wcex.hInstance = GetModuleHandle(NULL);
 	wcex.hInstance = GetModuleHandle(NULL);
-//	wcex.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
 	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
 	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
-//	wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
 	wcex.lpszMenuName = NULL;
 	wcex.lpszMenuName = NULL;
 	wcex.lpszClassName = m_window_name;
 	wcex.lpszClassName = m_window_name;
-//	wcex.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
 
 
 	bool registered = RegisterClassEx(&wcex);
 	bool registered = RegisterClassEx(&wcex);
 	CE_ASSERT(registered, "Unable to register a Window Class.");
 	CE_ASSERT(registered, "Unable to register a Window Class.");
 
 
-	if (fullscreen)
-	{
-		m_window_handle = CreateWindowEx(0, m_window_name, "", WS_POPUP, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
-	}
-	else
-	{
-		m_window_handle = CreateWindowEx(0, m_window_name, "", WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
-	}
+	m_window_handle = CreateWindowEx(0, m_window_name, "", WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
 
 
 	CE_ASSERT(m_window_handle != NULL, "Unable to create a Window.");
 	CE_ASSERT(m_window_handle != NULL, "Unable to create a Window.");
 	
 	
 	//Save the WGLRenderWindow pointer to the window's user data
 	//Save the WGLRenderWindow pointer to the window's user data
 	SetWindowLongPtr(m_window_handle, GWLP_USERDATA, (LONG) this);
 	SetWindowLongPtr(m_window_handle, GWLP_USERDATA, (LONG) this);
 	RECT rc;
 	RECT rc;
-	rc.left = rc.top = 0;
+	rc.left = 0;
+	rc.top = 0;
 	rc.right = width;
 	rc.right = width;
 	rc.bottom = height;
 	rc.bottom = height;
+
 	int32_t style, styleEx;
 	int32_t style, styleEx;
 	style = GetWindowLong(m_window_handle, GWL_STYLE);
 	style = GetWindowLong(m_window_handle, GWL_STYLE);
 	styleEx = GetWindowLong(m_window_handle, GWL_EXSTYLE);
 	styleEx = GetWindowLong(m_window_handle, GWL_EXSTYLE);
 	AdjustWindowRectEx(&rc, style, false, styleEx);
 	AdjustWindowRectEx(&rc, style, false, styleEx);
+
 	SetWindowPos(m_window_handle, 0, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
 	SetWindowPos(m_window_handle, 0, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
+
 	PIXELFORMATDESCRIPTOR pfd;
 	PIXELFORMATDESCRIPTOR pfd;
 	int32_t pixel_format;
 	int32_t pixel_format;
 	/* get the device context (DC) */
 	/* get the device context (DC) */
@@ -165,7 +138,7 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
 	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
 	pfd.iPixelType = PFD_TYPE_RGBA;
 	pfd.iPixelType = PFD_TYPE_RGBA;
 	pfd.cColorBits = 24;
 	pfd.cColorBits = 24;
-	//pfd.cDepthBits = depth;
+	pfd.cDepthBits = 24;
 	pfd.iLayerType = PFD_MAIN_PLANE;
 	pfd.iLayerType = PFD_MAIN_PLANE;
 
 
 	pixel_format = ChoosePixelFormat(device_context, &pfd);
 	pixel_format = ChoosePixelFormat(device_context, &pfd);
@@ -180,7 +153,7 @@ OsWindow::~OsWindow()
 {
 {
 	if (m_window_handle)
 	if (m_window_handle)
 	{
 	{
-		::DestroyWindow(m_window_handle);
+		DestroyWindow(m_window_handle);
 	}
 	}
 }
 }
 
 
@@ -254,6 +227,38 @@ void OsWindow::set_cursor_xy(int32_t x, int32_t y)
 	SetCursorPos(x, y);
 	SetCursorPos(x, y);
 }
 }
 
 
+//-----------------------------------------------------------------------------
+void OsWindow::set_fullscreen(bool fs)
+{
+	if (m_fullscreen)
+	{
+		memset(&m_screen_setting, 0, sizeof(m_screen_setting)); // Makes Sure Memory's Cleared
+		m_screen_setting.dmSize = sizeof(m_screen_setting); // Size Of The Devmode Structure
+		m_screen_setting.dmPelsWidth = m_width; // Selected Screen Width
+		m_screen_setting.dmPelsHeight = m_height; // Selected Screen Height
+		m_screen_setting.dmBitsPerPel = 32; // Selected Bits Per Pixel
+		m_screen_setting.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+
+		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
+		if (ChangeDisplaySettings(&m_screen_setting, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
+		{
+			m_fullscreen = false;
+			Log::i("Fullscreen resolution not supported, switching to windowed mode.");
+		}
+		else
+		{
+			m_fullscreen = true;
+			m_window_handle = CreateWindowEx(0, m_window_name, "", WS_POPUP, 0, 0, m_width, m_height, NULL, NULL, GetModuleHandle(NULL), NULL);
+		}
+	}
+}
+
+bool OsWindow::fullscreen()
+{
+	return m_fullscreen;
+}
+
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 char* OsWindow::title()
 char* OsWindow::title()
 {
 {
@@ -408,6 +413,12 @@ void OsWindow::frame()
 		}
 		}
 	}
 	}
 
 
+}
+
+void OsWindow::set_window(uint32_t width, uint32_t height)
+{
+
+
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 9 - 0
src/os/win/OsWindow.h

@@ -54,14 +54,22 @@ public:
 	void			get_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);
 	void			set_cursor_xy(int32_t x, int32_t y);
 
 
+	void			set_fullscreen(bool fs);
+	bool			fullscreen();
+
 	char*			title();
 	char*			title();
 	void			set_title(const char* title);
 	void			set_title(const char* title);
 
 
 	void			frame();
 	void			frame();
 
 
+private:
+
+	void			set_window(uint32_t width, uint32_t height);
+
 private:
 private:
 
 
 	HWND			m_window_handle;
 	HWND			m_window_handle;
+	DEVMODE			m_screen_setting;
 
 
 	char 			m_window_name[32];
 	char 			m_window_name[32];
 
 
@@ -69,6 +77,7 @@ private:
 	uint32_t		m_y;
 	uint32_t		m_y;
 	uint32_t		m_width;
 	uint32_t		m_width;
 	uint32_t		m_height;
 	uint32_t		m_height;
+	bool			m_fullscreen;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 1 - 1
src/os/win/Thread.cpp

@@ -57,7 +57,7 @@ void Thread::join()
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void Thread::detach()
 void Thread::detach()
 {
 {
-	bool closed = CloseHandle(m_thread);
+	BOOL closed = CloseHandle(m_thread);
 
 
 	CE_ASSERT(closed, "Unable to close thread");
 	CE_ASSERT(closed, "Unable to close thread");
 }
 }

+ 2 - 2
src/os/win/WinOS.cpp

@@ -95,7 +95,7 @@ bool is_root_path(const char* path)
 
 
 	if (string::strlen(path) == 1)
 	if (string::strlen(path) == 1)
 	{
 	{
-		if (path[0] == PATH_SEPARATOR)
+		if (path[0] == 'C')
 		{
 		{
 			return true;
 			return true;
 		}
 		}
@@ -111,7 +111,7 @@ bool is_absolute_path(const char* path)
 
 
 	if (string::strlen(path) > 0)
 	if (string::strlen(path) > 0)
 	{
 	{
-		if (path[0] == PATH_SEPARATOR)
+		if (path[0] == 'C')
 		{
 		{
 			return true;
 			return true;
 		}
 		}

+ 0 - 10
src/renderers/gl/wgl/GLContext.cpp

@@ -50,16 +50,6 @@ void GLContext::create_context()
 	wglMakeCurrent(GetDC(s_handle_window), m_win_context);
 	wglMakeCurrent(GetDC(s_handle_window), m_win_context);
 
 
 	CE_ASSERT(m_win_context != NULL, "Unable to create a rendering context.");
 	CE_ASSERT(m_win_context != NULL, "Unable to create a rendering context.");
-
-	//mFull = fullscreen;
-	//mX = x;
-	//mY = y;
-	//mWidth = width;
-	//mHeight = height;
-	//mCreated = true;
-	//SetVisible(true);
-	//GetDevice()->GetRenderer()->ResizeRenderTarget(width, height);
-	//return true;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 0 - 1
src/renderers/gl/wgl/GLContext.h

@@ -46,7 +46,6 @@ public:
 private:
 private:
 
 
 	HGLRC 			m_win_context;
 	HGLRC 			m_win_context;
-
 };
 };
 
 
 } // namespace crown
 } // namespace crown