diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-21 21:18:02 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-24 21:08:15 +0300 |
commit | a3082da9c7296bb18b7a6bc0424eb2a19d485ff6 (patch) | |
tree | cd07d091f69f5a3000aaddcbc8911d472b9137e7 /src | |
parent | 84189722a64c0794fbd918b4e6412908be2b7394 (diff) | |
download | manaplus-a3082da9c7296bb18b7a6bc0424eb2a19d485ff6.tar.gz manaplus-a3082da9c7296bb18b7a6bc0424eb2a19d485ff6.tar.bz2 manaplus-a3082da9c7296bb18b7a6bc0424eb2a19d485ff6.tar.xz manaplus-a3082da9c7296bb18b7a6bc0424eb2a19d485ff6.zip |
second part with compilation fixes for SDL2.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 80 | ||||
-rw-r--r-- | src/game.cpp | 20 | ||||
-rw-r--r-- | src/graphicsmanager.cpp | 10 | ||||
-rw-r--r-- | src/gui/sdlinput.cpp | 16 | ||||
-rw-r--r-- | src/sdlshared.h | 18 | ||||
-rw-r--r-- | src/utils/physfsrwops.cpp | 26 |
6 files changed, 149 insertions, 21 deletions
diff --git a/src/client.cpp b/src/client.cpp index 38fc440f9..29d81ad64 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -483,7 +483,11 @@ void Client::gameInit() SMALL_VERSION); } +#ifdef USE_SDL2 + // +++ need use SDL_SetWindowTitle +#else SDL_WM_SetCaption(mCaption.c_str(), nullptr); +#endif const ResourceManager *const resman = ResourceManager::getInstance(); @@ -589,7 +593,11 @@ void Client::gameInit() #else SDL_SetAlpha(mIcon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); #endif +#ifdef USE_SDL2 + // +++ need use SDL_SetWindowIcon +#else SDL_WM_SetIcon(mIcon, nullptr); +#endif } #endif @@ -1026,9 +1034,26 @@ int Client::gameExec() // logger->log("unknown event: %d", event.type); break; +#ifdef USE_SDL2 + case SDL_WINDOWEVENT: + { + switch (event.window.event) + { + // +++ need add other window events + case SDL_WINDOWEVENT_RESIZED: + resizeVideo(event.window.data1, + event.window.data2, false); + break; + default: + break; + } + break; + } +#else case SDL_VIDEORESIZE: resizeVideo(event.resize.w, event.resize.h, false); break; +#endif } guiInput->pushInput(event); @@ -1076,6 +1101,9 @@ int Client::gameExec() // This is done because at some point tick_time will wrap. lastTickTime = tick_time; +#ifdef USE_SDL2 + mainGraphics->updateScreen(); +#else // Update the screen when application is active, delay otherwise. if (SDL_GetAppState() & SDL_APPACTIVE) { @@ -1083,13 +1111,12 @@ int Client::gameExec() if (gui) gui->draw(); mainGraphics->updateScreen(); -// logger->log("active"); } else { -// logger->log("inactive"); SDL_Delay(100); } +#endif BLOCK_START("~Client::SDL_framerateDelay") if (mLimitFps) @@ -2865,8 +2892,12 @@ void Client::resizeVideo(int width, int height, const bool always) void Client::applyGrabMode() { +#ifdef USE_SDL2 + // +++ need use SDL_SetWindowGrab +#else SDL_WM_GrabInput(config.getBoolValue("grabinput") ? SDL_GRAB_ON : SDL_GRAB_OFF); +#endif } void Client::applyGamma() @@ -2874,15 +2905,21 @@ void Client::applyGamma() if (config.getFloatValue("enableGamma")) { const float val = config.getFloatValue("gamma"); +#ifdef USE_SDL2 + // +++ need use SDL_SetWindowBrightness +#else SDL_SetGamma(val, val, val); +#endif } } void Client::applyVSync() { +#ifndef USE_SDL2 const int val = config.getIntValue("vsync"); if (val > 0 && val < 2) SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, val); +#endif } void Client::applyKeyRepeat() @@ -2903,7 +2940,11 @@ void Client::setIsMinimized(const bool n) if (!n && client->mNewMessageFlag) { client->mNewMessageFlag = false; +#ifdef USE_SDL2 + // +++ need use SDL_SetWindowTitle +#else SDL_WM_SetCaption(client->mCaption.c_str(), nullptr); +#endif } } @@ -2916,7 +2957,11 @@ void Client::newChatMessage() if (!client->mNewMessageFlag && client->mIsMinimized) { // show * on window caption +#ifdef USE_SDL2 + // +++ need use SDL_SetWindowTitle +#else SDL_WM_SetCaption(("*" + client->mCaption).c_str(), nullptr); +#endif client->mNewMessageFlag = true; } } @@ -2938,6 +2983,16 @@ void Client::logEvent(const SDL_Event &event) logger->log("event: SDL_MOUSEMOTION: %d,%d,%d", event.motion.state, event.motion.x, event.motion.y); break; +#ifdef USE_SDL2 + case SDL_KEYDOWN: + logger->log("event: SDL_KEYDOWN: %d,%d", event.key.state, + event.key.keysym.scancode); + break; + case SDL_KEYUP: + logger->log("event: SDL_KEYUP: %d,%d", event.key.state, + event.key.keysym.scancode); + break; +#else case SDL_KEYDOWN: logger->log("event: SDL_KEYDOWN: %d,%d,%d", event.key.state, event.key.keysym.scancode, event.key.keysym.unicode); @@ -2946,6 +3001,17 @@ void Client::logEvent(const SDL_Event &event) logger->log("event: SDL_KEYUP: %d,%d,%d", event.key.state, event.key.keysym.scancode, event.key.keysym.unicode); break; + case SDL_VIDEORESIZE: + logger->log("event: SDL_VIDEORESIZE"); + break; + case SDL_VIDEOEXPOSE: + logger->log("event: SDL_VIDEOEXPOSE"); + break; + case SDL_ACTIVEEVENT: + logger->log("event: SDL_ACTIVEEVENT: %d %d", + event.active.state, event.active.gain); + break; +#endif case SDL_MOUSEBUTTONDOWN: logger->log("event: SDL_MOUSEBUTTONDOWN: %d,%d,%d,%d", event.button.button, event.button.state, @@ -2985,19 +3051,9 @@ void Client::logEvent(const SDL_Event &event) case SDL_SYSWMEVENT: logger->log("event: SDL_SYSWMEVENT"); break; - case SDL_VIDEORESIZE: - logger->log("event: SDL_VIDEORESIZE"); - break; - case SDL_VIDEOEXPOSE: - logger->log("event: SDL_VIDEOEXPOSE"); - break; case SDL_USEREVENT: logger->log("event: SDL_USEREVENT"); break; - case SDL_ACTIVEEVENT: - logger->log("event: SDL_ACTIVEEVENT: %d %d", - event.active.state, event.active.gain); - break; #ifdef ANDROID case SDL_ACCELEROMETER: logger->log("event: SDL_ACCELEROMETER"); diff --git a/src/game.cpp b/src/game.cpp index 8c7fbf868..f4dc97ed6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -880,6 +880,8 @@ void Game::handleActive(const SDL_Event &event) // logger->log("state: %d", (int)event.active.state); // logger->log("gain: %d", (int)event.active.gain); + // +++ need use window events +#ifndef USE_SDL2 int fpsLimit = 0; if (event.active.state & SDL_APPACTIVE) { @@ -935,6 +937,7 @@ void Game::handleActive(const SDL_Event &event) } Client::setFramerate(fpsLimit); mNextAdjustTime = cur_time + adjustDelay; +#endif } /** @@ -966,6 +969,22 @@ void Game::handleInput() switch (event.type) { +#ifdef USE_SDL2 + case SDL_WINDOWEVENT: + { + switch (event.window.event) + { + // +++ need add other window events + case SDL_WINDOWEVENT_RESIZED: + Client::resize(event.window.data1, + event.window.data2, false); + break; + default: + break; + } + break; + } +#else case SDL_VIDEORESIZE: // Let the client deal with this one (it'll // pass down from there) @@ -975,6 +994,7 @@ void Game::handleInput() case SDL_ACTIVEEVENT: handleActive(event); break; +#endif // Quit event case SDL_QUIT: Client::setState(STATE_EXIT); diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 23e105e5f..c0ea92ba6 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -413,7 +413,12 @@ void GraphicsManager::updatePlanformExtensions() { SDL_SysWMinfo info; SDL_VERSION(&info.version); +#ifdef USE_SDL2 + // +++ need use SDL_GetWindowWMInfo + if (false) +#else if (SDL_GetWMInfo(&info)) +#endif { #ifdef WIN32 if (!mwglGetExtensionsString) @@ -996,7 +1001,12 @@ void GraphicsManager::detectPixelSize() { SDL_SysWMinfo info; SDL_VERSION(&info.version); +#ifdef USE_SDL2 + // +++ need use SDL_GetWindowWMInfo + if (false) +#else if (SDL_GetWMInfo(&info)) +#endif { #ifdef WIN32 HDC hdc = GetDC(info.window); diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index bb0ded46f..fd72cb962 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -61,6 +61,9 @@ #include "inputmanager.h" #include "keydata.h" #include "mouseinput.h" +#include "sdlshared.h" + +#include <SDL_keyboard.h> #include <guichan/exception.hpp> @@ -176,11 +179,13 @@ void SDLInput::pushInput(const SDL_Event &event) #endif mouseInput.setButton(convertMouseButton(event.button.button)); +#ifndef USE_SDL2 if (event.button.button == SDL_BUTTON_WHEELDOWN) mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_DOWN); else if (event.button.button == SDL_BUTTON_WHEELUP) mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_UP); else +#endif mouseInput.setType(gcn::MouseInput::PRESSED); mouseInput.setTimeStamp(SDL_GetTicks()); mMouseInputQueue.push(mouseInput); @@ -211,6 +216,7 @@ void SDLInput::pushInput(const SDL_Event &event) mMouseInputQueue.push(mouseInput); break; +#ifndef USE_SDL2 case SDL_ACTIVEEVENT: /* * This occurs when the mouse leaves the window and the Gui-chan @@ -237,7 +243,7 @@ void SDLInput::pushInput(const SDL_Event &event) mMouseInWindow = true; } break; - +#endif default: break; } // end switch @@ -262,7 +268,11 @@ int SDLInput::convertMouseButton(const int button) int SDLInput::convertKeyCharacter(const SDL_Event &event) { const SDL_keysym keysym = event.key.keysym; +#ifdef USE_SDL2 + int value = keysym.scancode; +#else int value = keysym.unicode; +#endif switch (keysym.sym) { @@ -298,7 +308,9 @@ int SDLInput::convertKeyCharacter(const SDL_Event &event) // with the keysym.sym SDLK_SPACE which // without this check would be lost. The check // is only valid on key down events in SDL. +#ifndef USE_SDL2 if (event.type == SDL_KEYUP || keysym.unicode == ' ') +#endif { value = Key::SPACE; } @@ -387,12 +399,14 @@ int SDLInput::convertKeyCharacter(const SDL_Event &event) case SDLK_LMETA: value = Key::LEFT_META; break; +#ifndef USE_SDL2 case SDLK_LSUPER: value = Key::LEFT_SUPER; break; case SDLK_RSUPER: value = Key::RIGHT_SUPER; break; +#endif case SDLK_MODE: value = Key::ALT_GR; break; diff --git a/src/sdlshared.h b/src/sdlshared.h index 2c872b404..70798d441 100644 --- a/src/sdlshared.h +++ b/src/sdlshared.h @@ -26,6 +26,24 @@ #define SDLKey SDL_Keycode #define SDL_GetKeyState SDL_GetKeyboardState #define SDL_HWSURFACE 0 +#define SDL_keysym SDL_Keysym + +#define KMOD_META KMOD_GUI +#define SDLK_RMETA SDLK_RGUI +#define SDLK_LMETA SDLK_LGUI +#define SDLK_KP0 SDLK_KP_0 +#define SDLK_KP1 SDLK_KP_1 +#define SDLK_KP2 SDLK_KP_2 +#define SDLK_KP3 SDLK_KP_3 +#define SDLK_KP4 SDLK_KP_4 +#define SDLK_KP5 SDLK_KP_5 +#define SDLK_KP6 SDLK_KP_6 +#define SDLK_KP7 SDLK_KP_7 +#define SDLK_KP8 SDLK_KP_8 +#define SDLK_KP9 SDLK_KP_9 +#define SDLK_PRINT SDLK_PRINTSCREEN +#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR +#define SDLK_SCROLLOCK SDLK_SCROLLLOCK #else diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp index ae334bfe4..62330f33a 100644 --- a/src/utils/physfsrwops.cpp +++ b/src/utils/physfsrwops.cpp @@ -28,12 +28,20 @@ #include "debug.h" -static int physfsrwops_seek(SDL_RWops *const rw, const int offset, - const int whence) +#ifdef USE_SDL2 +#define PHYSFSINT int64_t +#define PHYSFSSIZE size_t +#else +#define PHYSFSINT int32_t +#define PHYSFSSIZE int +#endif + +static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw, const PHYSFSINT offset, + const int whence) { PHYSFS_file *const handle = static_cast<PHYSFS_file *const>( rw->hidden.unknown.data1); - int pos = 0; + PHYSFSINT pos = 0; if (whence == SEEK_SET) { @@ -70,7 +78,7 @@ static int physfsrwops_seek(SDL_RWops *const rw, const int offset, return -1; } /* if */ - pos = static_cast<int>(len); + pos = static_cast<PHYSFSINT>(len); if (static_cast<PHYSFS_sint64>(pos) != len) { SDL_SetError("Can't fit end-of-file position in an int!"); @@ -100,8 +108,9 @@ static int physfsrwops_seek(SDL_RWops *const rw, const int offset, return pos; } /* physfsrwops_seek */ -static int physfsrwops_read(SDL_RWops *const rw, void *ptr, - const int size, const int maxnum) +static PHYSFSSIZE physfsrwops_read(SDL_RWops *const rw, void *ptr, + const PHYSFSSIZE size, + const PHYSFSSIZE maxnum) { PHYSFS_file *const handle = static_cast<PHYSFS_file *const>( rw->hidden.unknown.data1); @@ -115,8 +124,9 @@ static int physfsrwops_read(SDL_RWops *const rw, void *ptr, return static_cast<int>(rc); } /* physfsrwops_read */ -static int physfsrwops_write(SDL_RWops *const rw, const void *ptr, - const int size, const int num) +static PHYSFSSIZE physfsrwops_write(SDL_RWops *const rw, const void *ptr, + const PHYSFSSIZE size, + const PHYSFSSIZE num) { PHYSFS_file *const handle = static_cast<PHYSFS_file *const>( rw->hidden.unknown.data1); |