summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-21 21:46:17 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-22 02:56:50 +0300
commit45fc7dfe871e25c913deb56063ca930dafe8b9ae (patch)
tree0ef15c4d3d36b02e41f8bfa765f5fadee779af24 /src
parent6e6d42af899c7dcc05b20b07130d0b1a5932f9bf (diff)
downloadmanaverse-45fc7dfe871e25c913deb56063ca930dafe8b9ae.tar.gz
manaverse-45fc7dfe871e25c913deb56063ca930dafe8b9ae.tar.bz2
manaverse-45fc7dfe871e25c913deb56063ca930dafe8b9ae.tar.xz
manaverse-45fc7dfe871e25c913deb56063ca930dafe8b9ae.zip
fix compilation and partial running with SDL2 on Android.
Diffstat (limited to 'src')
-rw-r--r--src/actionmanager.cpp6
-rw-r--r--src/client.cpp21
-rw-r--r--src/game.cpp4
-rw-r--r--src/graphicsmanager.cpp4
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/sdlinput.cpp14
-rw-r--r--src/input/inputmanager.cpp4
-rw-r--r--src/localconsts.h2
-rw-r--r--src/main.cpp4
-rw-r--r--src/utils/mkdir.cpp6
-rw-r--r--src/utils/paths.cpp13
-rw-r--r--src/utils/paths.h4
-rw-r--r--src/utils/process.cpp6
13 files changed, 83 insertions, 7 deletions
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 <SDL_screenkeyboard.h>
#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 <SDL_screenkeyboard.h>
#endif
+#endif
#include <sys/stat.h>
@@ -138,6 +140,8 @@
#include "mumblemanager.h"
+#include <android/log.h>
+
#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)
@@ -1005,6 +1014,7 @@ int Client::gameExec()
case SDL_ACCELEROMETER:
break;
#endif
+#endif
default:
// logger->log("unknown event: %d", event.type);
@@ -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,10 +3026,12 @@ 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);
break;
diff --git a/src/game.cpp b/src/game.cpp
index 671a8d578..debc28515 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1053,10 +1053,14 @@ 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,9 +1090,13 @@ 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);
logger->log("actual screen density: " + getDensityString());
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,9 +769,11 @@ 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,17 +185,23 @@ void SDLInput::pushInput(const SDL_Event &event)
#endif
#ifdef ANDROID
+#ifndef USE_SDL2
case SDL_ACCELEROMETER:
break;
#endif
+#endif
case SDL_MOUSEBUTTONDOWN:
mMouseDown = true;
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));
#ifndef USE_SDL2
@@ -215,8 +221,12 @@ 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);
mouseInput.setTimeStamp(SDL_GetTicks());
@@ -227,8 +237,12 @@ 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);
mouseInput.setTimeStamp(SDL_GetTicks());
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,11 +563,13 @@ bool InputManager::handleEvent(const SDL_Event &event)
break;
}
#ifdef ANDROID
+#ifndef USE_SDL2
case SDL_ACCELEROMETER:
{
break;
}
#endif
+#endif
default:
break;
}
@@ -604,11 +606,13 @@ 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 <SDL_image.h>
#include <SDL_mixer.h>
+#include <android/log.h>
+
#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<size_t>(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 <limits.h>
#endif
+#ifdef ANDROID
+#ifdef USE_SDL2
+#include <SDL_system.h>
+#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 <SDL_screenkeyboard.h>
+#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__