Explorar o código

updates for win64

mikymod %!s(int64=12) %!d(string=hai) anos
pai
achega
f9ae0539d0

+ 4 - 4
CMakeLists.txt

@@ -48,11 +48,11 @@ if (CROWN_ARCH MATCHES "win64")
 	set (CROWN_THIRD ${CMAKE_SOURCE_DIR}/third/win64)
 endif (CROWN_ARCH MATCHES "win64")
 
-set (CROWN_LUAJIT_INCLUDES
+set (CROWN_THIRD_INCLUDES
 	${CROWN_THIRD}/luajit/include/luajit-2.0
 )
 
-set (CROWN_LUAJIT_LIBS
+set (CROWN_THIRD_LIBS
 	${CROWN_THIRD}/luajit/lib
 )
 
@@ -75,8 +75,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
 	)
 endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
 
-include_directories(${CROWN_INCLUDES} ${CROWN_LUAJIT_INCLUDES})
-link_directories(${CROWN_LUAJIT_LIBS})
+include_directories(${CROWN_INCLUDES} ${CROWN_THIRD_INCLUDES})
+link_directories(${CROWN_THIRD_LIBS})
 
 # add build directories
 add_subdirectory(src)

+ 22 - 16
src/CMakeLists.txt

@@ -240,19 +240,17 @@ set (OS_HEADERS
 # FIXME: not so platform independent, name changes between different os
 # so, is better to include them in os specific chunk of cmake file
 set (CROWN_LIBRARIES
-	rt
-	z
 	luajit-5.1
 )
 
 set (CROWN_COMPILER_FLAGS
 	-pipe
 	-ansi
-	-W    	# VS2010 compiler does not agreed O.o
+#	-W    	# VS2010 compiler does not agreed O.o
 	-Wall
-	-Wextra
-	-Wno-long-long
-	-Wno-variadic-macros
+#	-Wextra
+#	-Wno-long-long
+#	-Wno-variadic-macros
 	-g
 	-pg
 )
@@ -294,6 +292,8 @@ if (LINUX)
 	)
 
 	list (APPEND CROWN_LIBRARIES
+		rt
+		z
 		X11
 		Xrandr
 		pthread
@@ -311,10 +311,11 @@ if (WINDOWS)
 		os/win/OsWindow.h
 		os/win/OsFile.h
 		os/win/Thread.h
+		os/win/Mutex.h
+		os/win/Cond.h
 #		os/win/TCPSocket.h
 #		os/win/UDPSocket.h
-#		os/win/Mutex.h
-#		os/win/Cond.h
+
 	)
 
 	list (APPEND OS_SRC
@@ -322,6 +323,8 @@ if (WINDOWS)
 		os/win/OsWindow.cpp
 		os/win/OsFile.cpp
 		os/win/Thread.cpp
+		os/win/Mutex.h
+		os/win/Cond.h
 	)
 
 	list (APPEND RENDERERS_SRC
@@ -336,14 +339,18 @@ if (WINDOWS)
 		renderers/gl/wgl/GLContext.h
 	)
 
-	list (
-		zlib
-		# MUST INCLUDE OTHERS
+	list (APPEND CROWN_THIRD_LIBRARIES
+		${CROWN_THIRD}/zlib/lib/zlib
+		OpenGL
+		GLEW
 	)
 
+	list (APPEND CROWN_THIRD_INCLUDES
+		${CROWN_THIRD}/zlib/include
+	)
+	
 	set (CROWN_EXECUTABLE_NAME crown-win)
 	set (CROWN_MAIN_SRC os/win/main.cpp)
-
 endif(WINDOWS)
 
 set (CROWN_SOURCES
@@ -386,15 +393,14 @@ set (CROWN_HEADERS
 
 	${OS_HEADERS}
 
-	${SCRIPT_HEADERS}
 )
 
 configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/Config.h)
 
-include_directories(${CROWN_INCLUDES} ${CROWN_LUAJIT_INCLUDES})
+include_directories(${CROWN_INCLUDES} ${CROWN_THIRD_INCLUDES})
 
-link_directories(${CROWN_LUAJIT_LIBS})
-link_libraries(${CROWN_LIBRARIES})
+link_directories(${CROWN_THIRD_LIBS})
+link_libraries(${CROWN_LIBRARIES} ${WIN_LIB})
 
 add_definitions(${CROWN_COMPILER_FLAGS})
 

+ 3 - 2
src/FileBundle.cpp

@@ -24,13 +24,14 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include <cstdio>
+#include <stdio.h>
 #include "FileBundle.h"
 #include "Filesystem.h"
 #include "Resource.h"
 #include "DiskFile.h"
 #include "Log.h"
-#include "StringUtils.h"
+#include "StringUtils.h" 
+#include "OS.h"
 
 namespace crown
 {

+ 1 - 0
src/FontResource.cpp

@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "FontResource.h"
+#include "Bundle.h"
 
 namespace crown
 {

+ 1 - 0
src/MaterialResource.cpp

@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "MaterialResource.h"
+#include "Bundle.h"
 
 namespace crown
 {

+ 3 - 0
src/core/math/MathUtils.h

@@ -26,6 +26,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
+#undef min
+#undef max
+
 #include "Assert.h"
 #include <cmath>
 #include "Types.h"

+ 4 - 0
src/core/mem/Memory.cpp

@@ -31,12 +31,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 void* operator new(size_t)
 {
 	CE_ASSERT(false, "operator new forbidden");
+
+	return NULL;
 }
 
 //-----------------------------------------------------------------------------
 void* operator new[](size_t)
 {
 	CE_ASSERT(false, "operator new[] forbidden");
+
+	return NULL;
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 0
src/input/Keyboard.h

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "KeyCode.h"
+#include "OS.h"
 
 namespace crown
 {

+ 1 - 1
src/network/BitMessage.cpp

@@ -523,7 +523,7 @@ void BitMessage::begin_reading() const
 //---------------------------------------------------------------------------------------------
 int32_t BitMessage::get_remaing_data() const
 {
-	m_cur_size - m_read_count;
+	return m_cur_size - m_read_count;
 }
 
 //---------------------------------------------------------------------------------------------

+ 7 - 0
src/os/OS.h

@@ -41,8 +41,15 @@ const char		PATH_SEPARATOR = '/';
 #endif
 
 #ifdef WINDOWS
+
 const size_t	MAX_PATH_LENGTH = 1024;
 const char		PATH_SEPARATOR = '\\';
+
+#define snprintf _snprintf
+
+#undef MK_SHIFT
+#undef MK_ALT
+
 #endif
 
 namespace os

+ 1 - 1
src/os/posix/OsFile.h

@@ -81,7 +81,7 @@ public:
 
 private:
 
-	FILE*					m_file_handle;
+	HANDLE					m_file_handle;
 	FileOpenMode			m_mode;
 };
 

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

@@ -27,7 +27,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "OsFile.h"
-
+#include "Assert.h"
 
 namespace crown
 {
@@ -54,7 +54,7 @@ OsFile::~OsFile()
 
 void OsFile::close()
 {
-	bool closed = CloseHandle(m_file_handle))
+	bool closed = CloseHandle(m_file_handle);
 	
 	CE_ASSERT(closed, "Unable to close file\n");
 }
@@ -70,7 +70,7 @@ size_t OsFile::size() const
 
 	GetFileSize(m_file_handle, size);
 
-	return size;
+	return *size;
 }
 
 FileOpenMode OsFile::mode()
@@ -80,7 +80,9 @@ FileOpenMode OsFile::mode()
 
 size_t OsFile::read(void* data, size_t size)
 {
-	bool read = ReadFile(m_file_handle, data, size, NULL, NULL))
+	DWORD bytes_read;
+
+	bool read = ReadFile(m_file_handle, data, size, &bytes_read, NULL);
 	
 	CE_ASSERT(read, "Cannot read from file\n");
 
@@ -89,7 +91,7 @@ size_t OsFile::read(void* data, size_t size)
 
 size_t OsFile::write(const void* data, size_t size)
 {
-	bool write = WriteFile(m_file_handle, data, size, NULL, NULL))
+	bool write = WriteFile(m_file_handle, data, size, NULL, NULL);
 	
 	CE_ASSERT(write, "Cannot read from file\n");		
 
@@ -126,7 +128,7 @@ size_t OsFile::position() const
 
 bool OsFile::eof() const
 {
-	return feof(m_file_handle) != 0;
+	return feof((FILE*)m_file_handle) != 0;
 }
 
 } // namespace crown

+ 1 - 1
src/os/win/OsFile.h

@@ -81,7 +81,7 @@ public:
 
 private:
 
-	FILE*					m_file_handle;
+	HANDLE					m_file_handle;
 	FileOpenMode			m_mode;
 };
 

+ 20 - 29
src/os/win/OsWindow.cpp

@@ -25,6 +25,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "OsWindow.h"
 #include "Assert.h"
+#include "Keyboard.h"
+#include "Log.h"
 
 namespace crown
 {
@@ -69,7 +71,7 @@ static Key translate_key(int32_t winKey)
 		case VK_RCONTROL:	return KC_RCONTROL;
 		case VK_CAPITAL:	return KC_CAPS_LOCK;
 		case VK_LMENU:		return KC_LALT;
-		case VK_@noteNU:	return KC_RALT;
+		case VK_RMENU:		return KC_RALT;
 		case VK_LWIN:		return KC_LSUPER;
 		case VK_RWIN:		return KC_RSUPER;
 		case VK_NUMPAD0:	return KC_KP_0;
@@ -108,7 +110,7 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 		if (ChangeDisplaySettings(&dm_screen_setting, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
 		{
 			fullscreen = false;
-			Log::I("Fullscreen resolution not supported, switching to windowed mode.");
+			Log::i("Fullscreen resolution not supported, switching to windowed mode.");
 		}
 	}
 
@@ -120,18 +122,15 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 	wcex.cbClsExtra = 0;
 	wcex.cbWndExtra = 0;
 	wcex.hInstance = GetModuleHandle(NULL);
-	wcex.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
+//	wcex.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
 	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
-	wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
+//	wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
 	wcex.lpszMenuName = NULL;
 	wcex.lpszClassName = m_window_name;
-	wcex.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
+//	wcex.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CROWNICON));
 
-	if (!RegisterClassEx(&wcex))
-	{
-		CE_ASSERT(false, "Unable to register a Window Class.");
-		return false;
-	}
+	bool registered = RegisterClassEx(&wcex);
+	CE_ASSERT(registered, "Unable to register a Window Class.");
 
 	if (fullscreen)
 	{
@@ -139,17 +138,13 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 	}
 	else
 	{
-		m_window_handle = CreateWindowEx(0, m_window_name, "", WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX, x, y, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
-	}
-
-	if (m_window_handle == NULL)
-	{
-		CE_ASSERT(false, "Unable to create a Window.");
-		return false;
+		m_window_handle = CreateWindowEx(0, m_window_name, "", WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);
 	}
 
+	CE_ASSERT(m_window_handle != NULL, "Unable to create a Window.");
+	
 	//Save the WGLRenderWindow pointer to the window's user data
-	SetWindowLong(m_window_handle, GWL_USERDATA, (LONG) this);
+	SetWindowLongPtr(m_window_handle, GWLP_USERDATA, (LONG) this);
 	RECT rc;
 	rc.left = rc.top = 0;
 	rc.right = width;
@@ -159,11 +154,10 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 	styleEx = GetWindowLong(m_window_handle, GWL_EXSTYLE);
 	AdjustWindowRectEx(&rc, style, false, styleEx);
 	SetWindowPos(m_window_handle, 0, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
-
 	PIXELFORMATDESCRIPTOR pfd;
 	int32_t pixel_format;
 	/* get the device context (DC) */
-	device_context = GetDC(m_window_handle);
+	HDC device_context = GetDC(m_window_handle);
 	/* set the pixel format for the DC */
 	ZeroMemory(&pfd, sizeof (pfd));
 	pfd.nSize = sizeof (pfd);
@@ -171,17 +165,14 @@ OsWindow::OsWindow(uint32_t width, uint32_t height)
 	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
 	pfd.iPixelType = PFD_TYPE_RGBA;
 	pfd.cColorBits = 24;
-	pfd.cDepthBits = depth;
+	//pfd.cDepthBits = depth;
 	pfd.iLayerType = PFD_MAIN_PLANE;
-	pixel_format = ChoosePixelFormat(device_context, &pfd);
-
 
+	pixel_format = ChoosePixelFormat(device_context, &pfd);
 	CE_ASSERT(pixel_format != 0, "Pixel format not supported.");
 	
-	if (!SetPixelFormat(device_context, pixel_format, &pfd))
-	{
-		CE_ASSERT(false, "Unable to set the pixel format, altough it seems to be supported.");
-	}
+	bool pf_set = SetPixelFormat(device_context, pixel_format, &pfd);
+	CE_ASSERT(pf_set, "Unable to set the pixel format, altough it seems to be supported.");
 }
 
 //-----------------------------------------------------------------------------
@@ -202,7 +193,7 @@ void OsWindow::show()
 //-----------------------------------------------------------------------------
 void OsWindow::hide()
 {
-	ShowWindow(m_Window_handle, SW_HIDE);
+	ShowWindow(m_window_handle, SW_HIDE);
 }
 
 //-----------------------------------------------------------------------------
@@ -371,7 +362,7 @@ void OsWindow::frame()
 			case WM_KEYDOWN:
 			case WM_KEYUP:
 			{
-				Key kc = TranslateKey(msg.wParam);
+				Key kc = translate_key(msg.wParam);
 
 				int32_t modifier_mask = 0;
 

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

@@ -36,13 +36,13 @@ namespace os
 {
 
 //-----------------------------------------------------------------------------
-Thread::Thread(os::ThreadFunction f, void* params, const char* name)
+Thread::Thread(os::ThreadFunction f, LPVOID params, const char* name)
 {
-	m_thread = CreateThread(NULL, 0, f, params, 0, NULL);
+	m_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) f, params, 0, NULL);
 
 	CE_ASSERT(m_thread != NULL, "Unable to create thread");
 
-	string::strcpy(m_name, name);
+	m_name = name;
 }
 
 //-----------------------------------------------------------------------------

+ 2 - 1
src/os/win/Thread.h

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include <windows.h>
 #include <process.h>
+#include <WinBase.h>
 #include "Types.h"
 #include "OS.h"
 
@@ -42,7 +43,7 @@ class Thread
 {
 public:
 
-					Thread(os::ThreadFunction f, void* params, const char* name);
+					Thread(os::ThreadFunction f, LPVOID params, const char* name);
 					~Thread();
 
 	void			join();

+ 28 - 27
src/os/win/WinOS.cpp

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <windows.h>
 #include <cstdio>
 #include <cstdarg>
+#include "StringUtils.h"
 
 namespace crown
 {
@@ -36,8 +37,8 @@ namespace os
 
 // FIXME: timespec does not exists in win
 // static timespec base_time;
-	LARGE_INTEGER* frequency;
-	LARGE_INTEGER* base_time;
+	LARGE_INTEGER frequency;
+	LARGE_INTEGER base_time;
 
 //-----------------------------------------------------------------------------
 void printf(const char* string, ...)
@@ -126,7 +127,7 @@ bool is_dir(const char* path)
 //-----------------------------------------------------------------------------
 bool is_reg(const char* path)
 {
-	return !IsDir(path);
+	return !is_dir(path);
 }
 
 //-----------------------------------------------------------------------------
@@ -153,7 +154,7 @@ bool mkdir(const char* path)
 }
 
 //-----------------------------------------------------------------------------
-bool OS::rmdir(const char* path)
+bool rmdir(const char* path)
 {
 	return RemoveDirectory(path) == TRUE;
 }
@@ -166,7 +167,7 @@ const char* get_cwd()
 
 	if (len == 0)
 	{
-		return Str::EMPTY;
+		return string::EMPTY;
 	}
 
 	return cwdBuf;
@@ -176,64 +177,64 @@ const char* get_cwd()
 const char* get_home()
 {
 	// TODO
-	return Str::EMPTY;
+	return string::EMPTY;
 }
 
 //-----------------------------------------------------------------------------
 const char* get_env(const char* env)
 {
-	static char evnBuf[1024];
+	static char envBuf[1024];
 	int32_t len = GetEnvironmentVariable(env, envBuf, 1024);
 
 	if (len == 0)
 	{
-		return Str::EMPTY;
+		return string::EMPTY;
 	}
 
 	return envBuf;
 }
 
 //-----------------------------------------------------------------------------
-bool ls(const char* path, List<Str>& fileList)
-{
-	// TODO
-	return false; 
-}
+// bool ls(const char* path, List<Str>& fileList)
+// {
+//	// TODO
+//	return false; 
+//}
 
 //-----------------------------------------------------------------------------
 void init_os()
 {
-	QueryPerformanceFrequency(frequency);
+	QueryPerformanceFrequency(&frequency);
 
-	CE_ASSERT(frequency > 0, "Hardware does not support high resolution performance counter.\n");
+	CE_ASSERT(frequency.QuadPart > 0, "Hardware does not support high resolution performance counter.\n");
 	
-	QueryPerformanceCounter(base_time);
+	QueryPerformanceCounter(&base_time);
 }
 
 //-----------------------------------------------------------------------------
 uint64_t milliseconds()
 {
-	LARGE_INTEGER* current_time;
+	LARGE_INTEGER current_time;
 
-	QueryPerformanceCounter(current_time);
+	QueryPerformanceCounter(&current_time);
 
-	return (uint64_t) (*current_time - *base_time) / (*frequency / 1000);
+	return (uint64_t) (current_time.QuadPart - base_time.QuadPart) / (frequency.QuadPart / 1000);
 }
 
 //-----------------------------------------------------------------------------
 uint64_t microseconds()
 {
-	LARGE_INTEGER* current_time;
+	LARGE_INTEGER current_time;
 
-	QueryPerformanceCounter(current_time);
+	QueryPerformanceCounter(&current_time);
 
-	return (uint64_t) (*current_time - *base_time) / (*frequency / 1000000);
+	return (uint64_t) (current_time.QuadPart - base_time.QuadPart) / (frequency.QuadPart / 1000000);
 }
 
 //-----------------------------------------------------------------------------
 void* open_library(const char* path)
 {
-	HMODULE library = LoadLibrary(_T(path));
+	HMODULE library = LoadLibrary(path);
 
 	CE_ASSERT(library  != NULL, "Unable to load library '%s' with error: %s\n", path, GetLastError());
 
@@ -243,7 +244,7 @@ void* open_library(const char* path)
 //-----------------------------------------------------------------------------
 void close_library(void* library)
 {
-	BOOL freed = FreeLibrary(library);
+	BOOL freed = FreeLibrary((HMODULE)library);
 
 	CE_ASSERT(freed,  "Failed to close library\n");
 }
@@ -251,10 +252,10 @@ void close_library(void* library)
 //-----------------------------------------------------------------------------
 void* lookup_symbol(void* library, const char* name)
 {
-	FARPROC symbol = GetProcAddress(library, name);
+	FARPROC symbol = GetProcAddress((HMODULE)library, name);
 
 	return symbol;
 }
 
-} // namespace crown
-
+} // namespace os
+} // namespace crown

+ 1 - 1
src/renderers/gl/wgl/GLContext.cpp

@@ -47,7 +47,7 @@ GLContext::GLContext() :
 //-----------------------------------------------------------------------------
 void GLContext::create_context()
 {
-	wglMakeCurrent(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.");