From 45fc7dfe871e25c913deb56063ca930dafe8b9ae Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 21 Sep 2013 21:46:17 +0300 Subject: fix compilation and partial running with SDL2 on Android. --- src/actionmanager.cpp | 6 ++++++ src/client.cpp | 21 ++++++++++++++++----- src/game.cpp | 4 ++++ src/graphicsmanager.cpp | 4 ++++ src/gui/gui.cpp | 2 ++ src/gui/sdlinput.cpp | 14 ++++++++++++++ src/input/inputmanager.cpp | 4 ++++ src/localconsts.h | 2 +- src/main.cpp | 4 +++- src/utils/mkdir.cpp | 6 ++++++ src/utils/paths.cpp | 13 +++++++++++++ src/utils/paths.h | 4 ++++ src/utils/process.cpp | 6 ++++++ 13 files changed, 83 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 3e675429e..3bbc30ffc 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -68,8 +68,10 @@ #include "utils/gettext.h" #ifdef ANDROID +#ifndef USE_SDL2 #include #endif +#endif #include "debug.h" @@ -1108,7 +1110,11 @@ impHandler0(stopSit) impHandler0(showKeyboard) { #ifdef ANDROID +#ifdef USE_SDL2 +// +++ need add support +#else SDL_ANDROID_ToggleScreenKeyboardTextInput(nullptr); +#endif return true; #else return false; diff --git a/src/client.cpp b/src/client.cpp index fcfb6db7f..aad9f0561 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -128,8 +128,10 @@ #endif #ifdef ANDROID +#ifndef USE_SDL2 #include #endif +#endif #include @@ -138,6 +140,8 @@ #include "mumblemanager.h" +#include + #include "debug.h" /** @@ -701,8 +705,10 @@ void Client::gameInit() PlayerInfo::init(); #ifdef ANDROID +#ifndef USE_SDL2 updateScreenKeyboard(SDL_GetScreenKeyboardHeight(nullptr)); #endif +#endif } Client::~Client() @@ -989,6 +995,9 @@ int Client::gameExec() break; #ifdef ANDROID +#ifdef USE_SDL2 + // +++ need add support +#else case SDL_ACTIVEEVENT: if ((event.active.state & SDL_APPACTIVE) && !event.active.gain) @@ -1004,6 +1013,7 @@ int Client::gameExec() case SDL_ACCELEROMETER: break; +#endif #endif default: @@ -1972,7 +1982,7 @@ void Client::initLocalDataDir() mLocalDataDir = std::string(PhysFs::getUserDir()); mLocalDataDir.append("/Mana"); #elif defined __ANDROID__ - mLocalDataDir = getenv("DATADIR2") + branding.getValue( + mLocalDataDir = getSdStoragePath() + branding.getValue( "appShort", "ManaPlus") + "/local"; #else mLocalDataDir = std::string(PhysFs::getUserDir()) + @@ -2029,7 +2039,7 @@ void Client::initConfigDir() "appShort", "mana")); } #elif defined __ANDROID__ - mConfigDir = getenv("DATADIR2") + branding.getValue( + mConfigDir = getSdStoragePath() + branding.getValue( "appShort", "ManaPlus").append("/config"); #else mConfigDir = std::string(PhysFs::getUserDir()).append( @@ -2275,7 +2285,7 @@ void Client::initScreenshotDir() else if (mScreenshotDir.empty()) { #ifdef __ANDROID__ - mScreenshotDir = getenv("DATADIR2") + std::string("/images"); + mScreenshotDir = getSdStoragePath() + std::string("/images"); if (mkdir_r(mScreenshotDir.c_str())) { @@ -2886,8 +2896,7 @@ void Client::logVars() { #ifdef ANDROID logger->log("APPDIR: %s", getenv("APPDIR")); - logger->log("DATADIR: %s", getenv("DATADIR")); - logger->log("DATADIR2: %s", getenv("DATADIR2")); + logger->log("DATADIR2: %s", getSdStoragePath().c_str()); #endif } @@ -3017,9 +3026,11 @@ void Client::logEvent(const SDL_Event &event) logger->log("event: SDL_USEREVENT"); break; #ifdef ANDROID +#ifndef USE_SDL2 case SDL_ACCELEROMETER: logger->log("event: SDL_ACCELEROMETER"); break; +#endif #endif default: logger->log("event: other: %d", event.type); diff --git a/src/game.cpp b/src/game.cpp index 671a8d578..debc28515 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1053,9 +1053,13 @@ void Game::handleInput() client->setState(STATE_EXIT); break; #ifdef ANDROID +#ifdef USE_SDL2 + // +++ probably need add support +#else case SDL_KEYBOARDSHOW: client->updateScreenKeyboard(event.user.code); break; +#endif #endif default: break; diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index d226e35e0..7ce307e99 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -1090,8 +1090,12 @@ void GraphicsManager::detectPixelSize() #endif } #if defined ANDROID +#ifdef USE_SDL2 + // +++ need add support +#else SDL_ANDROID_GetMetrics(&mMaxWidth, &mMaxHeight, &mWidthMM, &mHeightMM, &mDensity); +#endif #endif logger->log("screen size in pixels: %dx%d", mMaxWidth, mMaxHeight); logger->log("screen size in millimeters: %dx%d", mWidthMM, mHeightMM); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2733f75fa..694010f8b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -769,8 +769,10 @@ void Gui::handleMouseInput() if (touchManager.processEvent(mouseInput)) { #ifdef ANDROID +#ifndef USE_SDL2 SDL_WarpMouse(mLastMouseX, mLastMouseY, mLastMouseRealX, mLastMouseRealY); +#endif #endif mMouseInactivityTimer = 0; continue; diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 59f9c8e19..a942d6909 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -185,8 +185,10 @@ void SDLInput::pushInput(const SDL_Event &event) #endif #ifdef ANDROID +#ifndef USE_SDL2 case SDL_ACCELEROMETER: break; +#endif #endif case SDL_MOUSEBUTTONDOWN: @@ -194,7 +196,11 @@ void SDLInput::pushInput(const SDL_Event &event) mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); #ifdef ANDROID +#ifdef USE_SDL2 + mouseInput.setReal(event.button.x, event.button.y); +#else mouseInput.setReal(event.button.realx, event.button.realy); +#endif #endif mouseInput.setButton(convertMouseButton(event.button.button)); @@ -215,7 +221,11 @@ void SDLInput::pushInput(const SDL_Event &event) mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); #ifdef ANDROID +#ifdef USE_SDL2 + mouseInput.setReal(event.button.x, event.button.y); +#else mouseInput.setReal(event.button.realx, event.button.realy); +#endif #endif mouseInput.setButton(convertMouseButton(event.button.button)); mouseInput.setType(gcn::MouseInput::RELEASED); @@ -227,7 +237,11 @@ void SDLInput::pushInput(const SDL_Event &event) mouseInput.setX(event.motion.x); mouseInput.setY(event.motion.y); #ifdef ANDROID +#ifdef USE_SDL2 + mouseInput.setReal(event.motion.x, event.motion.y); +#else mouseInput.setReal(event.motion.realx, event.motion.realy); +#endif #endif mouseInput.setButton(gcn::MouseInput::EMPTY); mouseInput.setType(gcn::MouseInput::MOVED); diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 12831560a..0f250dae6 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -563,10 +563,12 @@ bool InputManager::handleEvent(const SDL_Event &event) break; } #ifdef ANDROID +#ifndef USE_SDL2 case SDL_ACCELEROMETER: { break; } +#endif #endif default: break; @@ -604,10 +606,12 @@ bool InputManager::handleEvent(const SDL_Event &event) } break; #ifdef ANDROID +#ifndef USE_SDL2 case SDL_ACCELEROMETER: { break; } +#endif #endif default: break; diff --git a/src/localconsts.h b/src/localconsts.h index 4187cefd2..d46c83ef4 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -88,7 +88,7 @@ // #define DEBUG_SDLFONT 1 // Android logging -// #define ANDROID_LOG 1 +#define ANDROID_LOG 1 // profiler // #define USE_PROFILER 1 diff --git a/src/main.cpp b/src/main.cpp index 68d81eda0..0f7e41b65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include "debug.h" char *selfName = nullptr; @@ -278,7 +280,7 @@ int main(int argc, char *argv[]) // Initialize PhysicsFS #ifdef ANDROID - mkdir_r(getenv("DATADIR2")); + mkdir_r(getSdStoragePath().c_str()); if (!PHYSFS_init((getRealPath(".").append("/fakebinary")).c_str())) #else diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp index d61fae919..d4005f4ab 100644 --- a/src/utils/mkdir.cpp +++ b/src/utils/mkdir.cpp @@ -40,6 +40,9 @@ #if defined WIN32 int mkdir_r(const char *const pathname) { + if (!pathname) + return -1; + char tmp[PATH_MAX]; char tmp2[PATH_MAX]; char *p; @@ -111,6 +114,9 @@ int mkdir_r(const char *const pathname) /// Create a directory, making leading components first if necessary int mkdir_r(const char *const pathname) { + if (!pathname) + return -1; + const size_t len = static_cast(strlen(pathname)); char *tmp = new char[len + 2]; char *p; diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index dd045cb5a..dbbdf6b31 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -39,6 +39,12 @@ #include #endif +#ifdef ANDROID +#ifdef USE_SDL2 +#include +#endif +#endif + #include "debug.h" std::string getRealPath(const std::string &str) @@ -175,3 +181,10 @@ std::string getDesktopDir() return std::string(PhysFs::getUserDir()).append("Desktop"); #endif } + +#ifdef ANDROID +std::string getSdStoragePath() +{ + return getenv("DATADIR2"); +} +#endif diff --git a/src/utils/paths.h b/src/utils/paths.h index 0c36b2f66..6e2d17808 100644 --- a/src/utils/paths.h +++ b/src/utils/paths.h @@ -39,4 +39,8 @@ std::string getSelfName() A_WARN_UNUSED; std::string getDesktopDir() A_WARN_UNUSED; +#ifdef ANDROID +std::string getSdStoragePath() A_WARN_UNUSED; +#endif + #endif // UTILS_PATHS_H diff --git a/src/utils/process.cpp b/src/utils/process.cpp index 1859b1c2f..efd799987 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -238,10 +238,16 @@ bool openBrowser(std::string url) } #elif defined ANDROID #include "utils/stringutils.h" +#ifndef USE_SDL2 #include +#endif bool openBrowser(std::string url) { +#ifdef USE_SDL2 + // +++ need add support +#else SDL_ANDROID_OpenBrowser(replaceAll(url, " ", "").c_str()); +#endif return true; } #elif defined __APPLE__ -- cgit v1.2.3-60-g2f50