From 4c5d1d0ca5eb84b76a27c5f4d202337bf299b1b4 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 30 Oct 2011 18:11:43 -0200 Subject: [PATCH] make work on Windows again --- CMakeLists.txt | 5 +- src/framework/graphics/texture.cpp | 1 + src/framework/platform/platform.h | 1 - src/framework/platform/win32platform.cpp | 148 +++++++++++++---------- src/framework/platform/x11platform.cpp | 63 +++++----- 5 files changed, 118 insertions(+), 100 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 060b725b..b8268dfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE}) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch") - SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}") + SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline") SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -rdynamic") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-inline") @@ -170,4 +170,5 @@ ENDIF(USE_PCH) # installation SET(DATA_INSTALL_DIR share/otclient) INSTALL(TARGETS otclient RUNTIME DESTINATION bin) -INSTALL(DIRECTORY modules DESTINATION ${DATA_INSTALL_DIR}) +INSTALL(DIRECTORY modules DESTINATION ${DATA_INSTALL_DIR} + PATTERN ".git" EXCLUDE) diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 9a9af1cc..0bc5d038 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -24,6 +24,7 @@ #include "graphics.h" #include +#include Texture::Texture() { diff --git a/src/framework/platform/platform.h b/src/framework/platform/platform.h index e5cde12f..153cf5fb 100644 --- a/src/framework/platform/platform.h +++ b/src/framework/platform/platform.h @@ -84,7 +84,6 @@ public: std::string generateBacktrace(int maxLevel = 100); private: - PlatformListener* m_listener; int m_lastTicks; }; diff --git a/src/framework/platform/win32platform.cpp b/src/framework/platform/win32platform.cpp index b6e89ec6..d379f154 100644 --- a/src/framework/platform/win32platform.cpp +++ b/src/framework/platform/win32platform.cpp @@ -20,9 +20,8 @@ * THE SOFTWARE. */ -#include -#include -#include +#include "platform.h" +#include "platformlistener.h" #include #include @@ -36,23 +35,26 @@ struct Win32PlatformPrivate { HINSTANCE instance; HDC hdc; HGLRC hrc; - std::string appName; int x, y; int width, height; int minWidth, minHeight; bool focused, visible, maximized; - - std::map keyMap; + std::map keyMap; + PlatformListener* listener; + PlatformEvent platformEvent; } win32; -void Platform::init(const char *appName) +Platform g_platform; + +void Platform::init(PlatformListener* platformListener, const char *appName) { // seend random numbers std::srand(std::time(NULL)); win32.appName = appName; win32.instance = GetModuleHandle(NULL); + win32.listener = platformListener; win32.keyMap[VK_ESCAPE] = Fw::KeyEscape; win32.keyMap[VK_TAB] = Fw::KeyTab; @@ -188,30 +190,30 @@ void Platform::init(const char *appName) win32.keyMap[VK_NUMPAD8] = Fw::KeyNumpad8; win32.keyMap[VK_NUMPAD9] = Fw::KeyNumpad9; - win32.keyMap[VK_OEM_1] = KeySemicolon; - win32.keyMap[VK_OEM_2] = KeySlash; - win32.keyMap[VK_OEM_3] = KeyGrave; - win32.keyMap[VK_OEM_4] = KeyLeftBracket; - win32.keyMap[VK_OEM_5] = KeyBackslash; - win32.keyMap[VK_OEM_6] = KeyRightBracket; - win32.keyMap[VK_OEM_7] = KeyApostrophe; - win32.keyMap[VK_OEM_MINUS] = KeyMinus; - win32.keyMap[VK_OEM_PLUS] = KeyPlus; - win32.keyMap[VK_OEM_COMMA] = KeyComma; - win32.keyMap[VK_OEM_PERIOD] = KeyPeriod; + win32.keyMap[VK_OEM_1] = Fw::KeySemicolon; + win32.keyMap[VK_OEM_2] = Fw::KeySlash; + win32.keyMap[VK_OEM_3] = Fw::KeyGrave; + win32.keyMap[VK_OEM_4] = Fw::KeyLeftBracket; + win32.keyMap[VK_OEM_5] = Fw::KeyBackslash; + win32.keyMap[VK_OEM_6] = Fw::KeyRightBracket; + win32.keyMap[VK_OEM_7] = Fw::KeyApostrophe; + win32.keyMap[VK_OEM_MINUS] = Fw::KeyMinus; + win32.keyMap[VK_OEM_PLUS] = Fw::KeyPlus; + win32.keyMap[VK_OEM_COMMA] = Fw::KeyComma; + win32.keyMap[VK_OEM_PERIOD] = Fw::KeyPeriod; - win32.keyMap[VK_F1] = KeyF1; - win32.keyMap[VK_F2] = KeyF2; - win32.keyMap[VK_F3] = KeyF3; - win32.keyMap[VK_F4] = KeyF4; - win32.keyMap[VK_F5] = KeyF5; - win32.keyMap[VK_F6] = KeyF6; - win32.keyMap[VK_F7] = KeyF7; - win32.keyMap[VK_F8] = KeyF8; - win32.keyMap[VK_F9] = KeyF9; - win32.keyMap[VK_F10] = KeyF10; - win32.keyMap[VK_F11] = KeyF11; - win32.keyMap[VK_F12] = KeyF12; + win32.keyMap[VK_F1] = Fw::KeyF1; + win32.keyMap[VK_F2] = Fw::KeyF2; + win32.keyMap[VK_F3] = Fw::KeyF3; + win32.keyMap[VK_F4] = Fw::KeyF4; + win32.keyMap[VK_F5] = Fw::KeyF5; + win32.keyMap[VK_F6] = Fw::KeyF6; + win32.keyMap[VK_F7] = Fw::KeyF7; + win32.keyMap[VK_F8] = Fw::KeyF8; + win32.keyMap[VK_F9] = Fw::KeyF9; + win32.keyMap[VK_F10] = Fw::KeyF10; + win32.keyMap[VK_F11] = Fw::KeyF11; + win32.keyMap[VK_F12] = Fw::KeyF12; // win class WNDCLASSA wc; @@ -230,7 +232,7 @@ void Platform::init(const char *appName) logFatal("FATAL ERROR: Failed to register the window class."); // force first tick - Platform::getTicks(); + updateTicks(); } void Platform::terminate() @@ -257,13 +259,13 @@ void Platform::poll() } } -int Platform::getTicks() +void Platform::updateTicks() { static ulong firstTick = 0; if(!firstTick) firstTick = GetTickCount(); - return (uint32_t)(GetTickCount() - firstTick); + m_lastTicks = (uint32_t)(GetTickCount() - firstTick); } void Platform::sleep(ulong miliseconds) @@ -306,7 +308,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i return false; } - GLuint pixelFormat; + uint pixelFormat; static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor @@ -397,6 +399,11 @@ void Platform::showWindow() ShowWindow(win32.window, SW_SHOW); } +void Platform::hideWindow() +{ + ShowWindow(win32.window, SW_HIDE); +} + void Platform::setWindowTitle(const char *title) { SetWindowTextA(win32.window, title); @@ -451,9 +458,14 @@ void Platform::showMouseCursor() ShowCursor(true); } +Point Platform::getMouseCursorPos() +{ + return win32.platformEvent.mousePos; +} + void Platform::setVerticalSync(bool enable /*= true*/) { - typedef GLint (*glSwapIntervalProc)(GLint); + typedef int (*glSwapIntervalProc)(int); glSwapIntervalProc glSwapInterval = NULL; if(isExtensionSupported("WGL_EXT_swap_control")) @@ -525,7 +537,7 @@ std::string Platform::getAppUserDir() LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static int lastX, lastY; - static InputEvent inputEvent; + PlatformEvent& platformEvent = win32.platformEvent; switch(uMsg) { @@ -537,16 +549,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_CHAR: { if(wParam >= 32 && wParam <= 255) { - inputEvent.type = EV_TEXT_ENTER; - inputEvent.keychar = wParam; - inputEvent.keycode = KeyUNKNOWN; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventKeyDown; + platformEvent.ctrl = HIWORD(GetKeyState(VK_CONTROL)) == 0 ? false : true; + platformEvent.alt = HIWORD(GetKeyState(VK_MENU)) == 0 ? false : true; + platformEvent.shift = HIWORD(GetKeyState(VK_SHIFT)) == 0 ? false : true; + platformEvent.keychar = wParam; + platformEvent.keycode = Fw::KeyUnknown; + win32.listener->onPlatformEvent(platformEvent); } break; } case WM_CLOSE: { - g_engine.onClose(); + win32.listener->onClose(); break; } case WM_GETMINMAXINFO: @@ -560,64 +575,65 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_KEYUP: { if(win32.keyMap.find(wParam) != win32.keyMap.end()) { - inputEvent.type = uMsg == WM_KEYDOWN ? EV_KEY_DOWN : EV_KEY_UP; - inputEvent.ctrl = HIWORD(GetKeyState(VK_CONTROL)) == 0 ? false : true; - inputEvent.alt = HIWORD(GetKeyState(VK_MENU)) == 0 ? false : true; - inputEvent.shift = HIWORD(GetKeyState(VK_SHIFT)) == 0 ? false : true; - inputEvent.keycode = win32.keyMap[wParam]; + platformEvent.type = uMsg == WM_KEYDOWN ? EventKeyDown : EventKeyUp; + platformEvent.ctrl = HIWORD(GetKeyState(VK_CONTROL)) == 0 ? false : true; + platformEvent.alt = HIWORD(GetKeyState(VK_MENU)) == 0 ? false : true; + platformEvent.shift = HIWORD(GetKeyState(VK_SHIFT)) == 0 ? false : true; + platformEvent.keycode = win32.keyMap[wParam]; + platformEvent.keychar = 0; } - g_engine.onInputEvent(inputEvent); + win32.listener->onPlatformEvent(platformEvent); break; } case WM_LBUTTONDOWN: { - inputEvent.type = EV_MOUSE_LDOWN; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventMouseLeftButtonDown; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_LBUTTONUP: { - inputEvent.type = EV_MOUSE_LUP; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventMouseLeftButtonUp; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_MBUTTONDOWN: { - inputEvent.type = EV_MOUSE_MDOWN; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventMouseMiddleButtonDown; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_MBUTTONUP: { - inputEvent.type = EV_MOUSE_MUP; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventMouseMiddleButtonUp; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_RBUTTONDOWN: { - inputEvent.type = EV_MOUSE_RDOWN; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventMouseRightButtonDown; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_RBUTTONUP: { - inputEvent.type = EV_MOUSE_RUP; - g_engine.onInputEvent(inputEvent); + platformEvent.type = EventMouseRightButtonUp; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_MOUSEMOVE: { - inputEvent.type = EV_MOUSE_MOVE; + platformEvent.type = EventMouseMove; Point newMousePos(LOWORD(lParam), HIWORD(lParam)); - inputEvent.mouseMoved = newMousePos - inputEvent.mousePos; - inputEvent.mousePos = newMousePos; - g_engine.onInputEvent(inputEvent); + platformEvent.mouseMoved = newMousePos - platformEvent.mousePos; + platformEvent.mousePos = newMousePos; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_MOUSEWHEEL: { - inputEvent.type = HIWORD(wParam) > 0 ? EV_MOUSE_WHEEL_UP : EV_MOUSE_WHEEL_DOWN; - g_engine.onInputEvent(inputEvent); + platformEvent.type = HIWORD(wParam) > 0 ? EventMouseWheelUp : EventMouseWheelDown; + win32.listener->onPlatformEvent(platformEvent); break; } case WM_MOVE: @@ -649,7 +665,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) win32.height = HIWORD(lParam); } - g_engine.onResize(Size(LOWORD(lParam), HIWORD(lParam))); + win32.listener->onResize(Size(LOWORD(lParam), HIWORD(lParam))); break; } default: diff --git a/src/framework/platform/x11platform.cpp b/src/framework/platform/x11platform.cpp index d15b2dd8..c5dbbcf8 100644 --- a/src/framework/platform/x11platform.cpp +++ b/src/framework/platform/x11platform.cpp @@ -64,7 +64,8 @@ struct X11PlatformPrivate { int lastTicks; std::string clipboardText; std::map keyMap; - PlatformEvent inputEvent; + PlatformListener* listener; + PlatformEvent platformEvent; } x11; Platform g_platform; @@ -88,7 +89,7 @@ void Platform::init(PlatformListener* platformListener, const char *appName) x11.width = 0; x11.height = 0; x11.maximizeOnFirstShow = false; - m_listener = platformListener; + x11.listener = platformListener; x11.keyMap[XK_Escape] = Fw::KeyEscape; x11.keyMap[XK_Tab] = Fw::KeyTab; @@ -294,7 +295,7 @@ void Platform::terminate() void Platform::poll() { XEvent event, peekevent; - PlatformEvent& inputEvent = x11.inputEvent; + PlatformEvent& platformEvent = x11.platformEvent; while(XPending(x11.display) > 0) { XNextEvent(x11.display, &event); @@ -317,7 +318,7 @@ void Platform::poll() static int oldWidth = -1; static int oldHeight = -1; if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) { - m_listener->onResize(Size(event.xconfigure.width, event.xconfigure.height)); + x11.listener->onResize(Size(event.xconfigure.width, event.xconfigure.height)); oldWidth = event.xconfigure.width; oldHeight = event.xconfigure.height; } @@ -343,13 +344,13 @@ void Platform::poll() char buf[32]; int len; - inputEvent.ctrl = (event.xkey.state & ControlMask); - inputEvent.shift = (event.xkey.state & ShiftMask); - inputEvent.alt = (event.xkey.state & Mod1Mask); - inputEvent.keychar = 0; + platformEvent.ctrl = (event.xkey.state & ControlMask); + platformEvent.shift = (event.xkey.state & ShiftMask); + platformEvent.alt = (event.xkey.state & Mod1Mask); + platformEvent.keychar = 0; // fire enter text event - if(event.type == KeyPress && !inputEvent.ctrl && !inputEvent.alt) { + if(event.type == KeyPress && !platformEvent.ctrl && !platformEvent.alt) { if(x11.xic) { // with xim we can get latin1 input correctly Status status; len = XmbLookupString(x11.xic, &event.xkey, buf, sizeof(buf), &keysym, &status); @@ -367,57 +368,57 @@ void Platform::poll() (uchar)(buf[0]) >= 32 ) { //logDebug("char: ", buf[0], " code: ", (uint)buf[0]); - inputEvent.keychar = buf[0]; + platformEvent.keychar = buf[0]; } } else { //event.xkey.state &= ~(ShiftMask | LockMask); len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0); - if(len > 0 && (uchar)inputEvent.keychar >= 32) - inputEvent.keychar = (len > 0) ? buf[0] : 0; + if(len > 0 && (uchar)platformEvent.keychar >= 32) + platformEvent.keychar = (len > 0) ? buf[0] : 0; } if(x11.keyMap.find(keysym) != x11.keyMap.end()) - inputEvent.keycode = x11.keyMap[keysym]; + platformEvent.keycode = x11.keyMap[keysym]; else - inputEvent.keycode = Fw::KeyUnknown; + platformEvent.keycode = Fw::KeyUnknown; - inputEvent.keycode = x11.keyMap[keysym]; - inputEvent.type = (event.type == KeyPress) ? EventKeyDown : EventKeyUp; + platformEvent.keycode = x11.keyMap[keysym]; + platformEvent.type = (event.type == KeyPress) ? EventKeyDown : EventKeyUp; - if(inputEvent.keycode != Fw::KeyUnknown || inputEvent.keychar != 0) - m_listener->onPlatformEvent(inputEvent); + if(platformEvent.keycode != Fw::KeyUnknown || platformEvent.keychar != 0) + x11.listener->onPlatformEvent(platformEvent); break; } case ButtonPress: case ButtonRelease: switch(event.xbutton.button) { case Button1: - inputEvent.type = (event.type == ButtonPress) ? EventMouseLeftButtonDown : EventMouseLeftButtonUp; + platformEvent.type = (event.type == ButtonPress) ? EventMouseLeftButtonDown : EventMouseLeftButtonUp; break; case Button3: - inputEvent.type = (event.type == ButtonPress) ? EventMouseRightButtonDown : EventMouseRightButtonUp; + platformEvent.type = (event.type == ButtonPress) ? EventMouseRightButtonDown : EventMouseRightButtonUp; break; case Button2: - inputEvent.type = (event.type == ButtonPress) ? EventMouseMiddleButtonDown : EventMouseMiddleButtonUp; + platformEvent.type = (event.type == ButtonPress) ? EventMouseMiddleButtonDown : EventMouseMiddleButtonUp; break; case Button4: - inputEvent.type = EventMouseWheelUp; + platformEvent.type = EventMouseWheelUp; break; case Button5: - inputEvent.type = EventMouseWheelDown; + platformEvent.type = EventMouseWheelDown; break; } - m_listener->onPlatformEvent(inputEvent); + x11.listener->onPlatformEvent(platformEvent); break; case MotionNotify: { - inputEvent.type = EventMouseMove; + platformEvent.type = EventMouseMove; Point newMousePos(event.xbutton.x, event.xbutton.y); - inputEvent.mouseMoved = newMousePos - inputEvent.mousePos; - inputEvent.mousePos = newMousePos; - m_listener->onPlatformEvent(inputEvent); + platformEvent.mouseMoved = newMousePos - platformEvent.mousePos; + platformEvent.mousePos = newMousePos; + x11.listener->onPlatformEvent(platformEvent); break; } @@ -477,7 +478,7 @@ void Platform::poll() case ClientMessage: { if((Atom)event.xclient.data.l[0] == x11.atomDeleteWindow) - m_listener->onClose(); + x11.listener->onClose(); break; } } @@ -595,7 +596,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i x11.maximizeOnFirstShow = maximized; // call first onResize - m_listener->onResize(Size(width, height)); + x11.listener->onResize(Size(width, height)); return true; } @@ -768,7 +769,7 @@ void Platform::showMouseCursor() Point Platform::getMouseCursorPos() { - return x11.inputEvent.mousePos; + return x11.platformEvent.mousePos; } void Platform::setVerticalSync(bool enable)