diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-03 22:13:28 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-03 22:13:28 +0300 |
commit | 527d9d1aea2b840e98dd0976f7bd3426703a886a (patch) | |
tree | b08af3a0162083b5208ada49e98b2d4a81e93230 /src | |
parent | 8f7f5129c39107aca1e5166be91940cdc073bb8e (diff) | |
download | manaverse-527d9d1aea2b840e98dd0976f7bd3426703a886a.tar.gz manaverse-527d9d1aea2b840e98dd0976f7bd3426703a886a.tar.bz2 manaverse-527d9d1aea2b840e98dd0976f7bd3426703a886a.tar.xz manaverse-527d9d1aea2b840e98dd0976f7bd3426703a886a.zip |
Fix compilation for Android with SDL2.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 33 | ||||
-rw-r--r-- | src/client.h | 6 | ||||
-rw-r--r-- | src/dirs.cpp | 87 | ||||
-rw-r--r-- | src/dirs.h | 6 |
4 files changed, 96 insertions, 36 deletions
diff --git a/src/client.cpp b/src/client.cpp index f433746e0..198fadc1d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -161,12 +161,6 @@ #include "debug.h" -#ifdef ANDROID -#ifdef USE_SDL2 -int loadingProgressCounter = 1; -#endif -#endif - std::string errorMessage; LoginData loginData; @@ -556,27 +550,6 @@ void Client::initGraphics() mainGraphics->beginDraw(); } -#ifdef ANDROID -#ifdef USE_SDL2 -static void updateProgress(int cnt) -{ - const int progress = cnt + loadingProgressCounter; - const int h = mainGraphics->mHeight; - mainGraphics->setColor(Color(255, 255, 255)); - const int maxSize = mainGraphics->mWidth - 100; - const int width = maxSize * progress / 450; - mainGraphics->fillRectangle(Rect(50, h - 100, width, 50)); - mainGraphics->updateScreen(); -} - -static void setProgress(const int val) -{ - loadingProgressCounter = val; - updateProgress(loadingProgressCounter); -} -#endif -#endif - void Client::setEnv(const char *const name, const char *const value) { if (!name || !value) @@ -1813,6 +1786,7 @@ void Client::logVars() #ifdef ANDROID #ifdef USE_SDL2 +/* void Client::extractAssets() { if (!getenv("APPDIR")) @@ -1840,7 +1814,7 @@ void Client::extractAssets() logger->log("asset size: %d", size2); fwrite(buf, 1, size2, file); SDL_RWclose(rw); - setProgress(loadingProgressCounter + 1); + Dirs::setProgress(); } else { @@ -1859,11 +1833,12 @@ void Client::extractAssets() int size2 = SDL_RWread(rw, buf, 1, size); fwrite(buf, 1, size2, file2); SDL_RWclose(rw); - setProgress(loadingProgressCounter + 1); + setProgress(); } fclose(file2); delete [] buf; } +*/ #endif #endif diff --git a/src/client.h b/src/client.h index 29dca9ad7..06c261eb2 100644 --- a/src/client.h +++ b/src/client.h @@ -120,12 +120,6 @@ class Client final : public ConfigListener, static void logVars(); -#ifdef ANDROID -#ifdef USE_SDL2 - static void extractAssets(); -#endif -#endif - ServerInfo mCurrentServer; Game *mGame; diff --git a/src/dirs.cpp b/src/dirs.cpp index 5f68bb449..94067420b 100644 --- a/src/dirs.cpp +++ b/src/dirs.cpp @@ -55,6 +55,91 @@ #define _nacl_dir std::string("/persistent/manaplus") #endif +#ifdef ANDROID +#ifdef USE_SDL2 +#include "render/graphics.h" + +int loadingProgressCounter = 1; + +static void updateProgress(int cnt) +{ + const int progress = cnt + loadingProgressCounter; + const int h = mainGraphics->mHeight; + mainGraphics->setColor(Color(255, 255, 255)); + const int maxSize = mainGraphics->mWidth - 100; + const int width = maxSize * progress / 450; + mainGraphics->fillRectangle(Rect(50, h - 100, width, 50)); + mainGraphics->updateScreen(); +} + +void Dirs::setProgress() +{ + loadingProgressCounter++; + updateProgress(loadingProgressCounter); +} + +static void resetProgress() +{ + loadingProgressCounter = 0; + updateProgress(loadingProgressCounter); +} + +void extractAssets() +{ + if (!getenv("APPDIR")) + { + logger->log("error: APPDIR is not set!"); + return; + } + const std::string fileName = std::string(getenv( + "APPDIR")).append("/data.zip"); + logger->log("Extracting asset into: " + fileName); + uint8_t *buf = new uint8_t[1000000]; + + FILE *const file = fopen(fileName.c_str(), "w"); + for (int f = 0; f < 100; f ++) + { + std::string part = strprintf("manaplus-data.zip%u%u", + static_cast<unsigned int>(f / 10), + static_cast<unsigned int>(f % 10)); + logger->log("testing asset: " + part); + SDL_RWops *const rw = SDL_RWFromFile(part.c_str(), "r"); + if (rw) + { + const int size = SDL_RWsize(rw); + int size2 = SDL_RWread(rw, buf, 1, size); + logger->log("asset size: %d", size2); + fwrite(buf, 1, size2, file); + SDL_RWclose(rw); + Dirs::setProgress(); + } + else + { + break; + } + } + fclose(file); + + const std::string fileName2 = std::string(getenv( + "APPDIR")).append("/locale.zip"); + FILE *const file2 = fopen(fileName2.c_str(), "w"); + SDL_RWops *const rw = SDL_RWFromFile("manaplus-locale.zip", "r"); + if (rw) + { + const int size = SDL_RWsize(rw); + int size2 = SDL_RWread(rw, buf, 1, size); + fwrite(buf, 1, size2, file2); + SDL_RWclose(rw); + Dirs::setProgress(); + } + fclose(file2); + + delete [] buf; +} + +#endif +#endif + void Dirs::updateDataPath() { if (settings.options.dataPath.empty() @@ -78,7 +163,7 @@ void Dirs::extractDataDir() #ifdef ANDROID #ifdef USE_SDL2 Files::setCopyCallBack(&updateProgress); - setProgress(0); + resetProgress(); extractAssets(); const std::string zipName = std::string(getenv( diff --git a/src/dirs.h b/src/dirs.h index 25c1beb89..95a5fd9e7 100644 --- a/src/dirs.h +++ b/src/dirs.h @@ -49,6 +49,12 @@ class Dirs final static void initUpdatesDir(); static void initScreenshotDir(); + +#ifdef ANDROID +#ifdef USE_SDL2 + static void setProgress(); +#endif +#endif }; #endif // DIRS_H |