summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-11-07 16:32:18 +0300
committerAndrei Karas <akaras@inbox.ru>2013-11-07 18:56:07 +0300
commit64535f9763c432bbb46be2769560bfd6a2202d72 (patch)
tree08221a911005ad417cbdc339b02a416b757122a5 /src
parentcf77bdc4baa273d8750175411cb59af3ca3c07ac (diff)
downloadmanaplus-64535f9763c432bbb46be2769560bfd6a2202d72.tar.gz
manaplus-64535f9763c432bbb46be2769560bfd6a2202d72.tar.bz2
manaplus-64535f9763c432bbb46be2769560bfd6a2202d72.tar.xz
manaplus-64535f9763c432bbb46be2769560bfd6a2202d72.zip
add progress bar while loading in SDL2 in Android.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp35
-rw-r--r--src/utils/files.cpp19
-rw-r--r--src/utils/files.h4
3 files changed, 56 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 461ce03c8..bcaba2a40 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -152,6 +152,12 @@
#define _nacl_dir std::string("/persistent/manaplus")
#endif
+#ifdef ANDROID
+#ifdef USE_SDL2
+int loadingProgressCounter = 1;
+#endif
+#endif
+
std::string errorMessage;
ErrorListener errorListener;
LoginData loginData;
@@ -309,7 +315,6 @@ void Client::gameInit()
"Exiting.", mLocalDataDir.c_str()));
}
- extractDataDir();
initLang();
chatLogger = new ChatLogger;
@@ -348,6 +353,8 @@ void Client::gameInit()
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+ initGraphics();
+ extractDataDir();
mountDataDir();
if (mOptions.dataPath.empty()
@@ -373,7 +380,6 @@ void Client::gameInit()
resman->addToSearchPath(mLocalDataDir, false);
TranslationManager::loadCurrentLang();
- initGraphics();
initTitle();
Theme::selectSkin();
@@ -580,10 +586,33 @@ void Client::initTitle()
setIcon();
}
+#ifdef ANDROID
+#ifdef USE_SDL2
+static void updateProgress(int cnt)
+{
+ const int progress = cnt + loadingProgressCounter;
+ const int h = mainGraphics->mHeight;
+ mainGraphics->setColor(gcn::Color(255, 255, 255));
+ const int maxSize = mainGraphics->mWidth - 100;
+ const int width = maxSize * progress / 450;
+ mainGraphics->fillRectangle(gcn::Rectangle(50, h - 100, width, 50));
+ mainGraphics->updateScreen();
+}
+
+static void setProgress(const int val)
+{
+ loadingProgressCounter = val;
+ updateProgress(loadingProgressCounter);
+}
+#endif
+#endif
+
void Client::extractDataDir()
{
#ifdef ANDROID
#ifdef USE_SDL2
+ Files::setCopyCallBack(&updateProgress);
+ setProgress(0);
extractAssets();
const std::string zipName = std::string(getenv(
@@ -2965,6 +2994,7 @@ void Client::extractAssets()
logger->log("asset size: %d", size2);
fwrite(buf, 1, size2, file);
SDL_RWclose(rw);
+ setProgress(loadingProgressCounter + 1);
}
else
{
@@ -2983,6 +3013,7 @@ void Client::extractAssets()
int size2 = SDL_RWread(rw, buf, 1, size);
fwrite(buf, 1, size2, file2);
SDL_RWclose(rw);
+ setProgress(loadingProgressCounter + 1);
}
fclose(file2);
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index 6f57d3062..bfaed472a 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -63,6 +63,18 @@ void Files::extractLocale()
#endif // ANDROID
#if defined(ANDROID) || defined(__native_client__)
+
+namespace
+{
+ int mFilesCount = 0;
+ Files::CopyFileCallbackPtr mCallbackPtr = nullptr;
+} // namespace
+
+void Files::setCopyCallBack(Files::CopyFileCallbackPtr callback)
+{
+ mCallbackPtr = callback;
+}
+
void Files::copyPhysFsFile(const std::string &inFile,
const std::string &outFile)
{
@@ -72,6 +84,13 @@ void Files::copyPhysFsFile(const std::string &inFile,
fwrite(buf, 1, size, file);
fclose(file);
free(buf);
+#ifdef ANDROID
+ if (mCallbackPtr)
+ {
+ mCallbackPtr(mFilesCount);
+ mFilesCount ++;
+ }
+#endif
}
void Files::copyPhysFsDir(const std::string &inDir, const std::string &outDir)
diff --git a/src/utils/files.h b/src/utils/files.h
index 735812563..f356d7688 100644
--- a/src/utils/files.h
+++ b/src/utils/files.h
@@ -30,6 +30,10 @@ namespace Files
#endif
#if defined(ANDROID) || defined(__native_client__)
+ typedef void (*CopyFileCallbackPtr) (int cnt);
+
+ void setCopyCallBack(CopyFileCallbackPtr callback);
+
void copyPhysFsFile(const std::string &inFile, const std::string &outFile);
void copyPhysFsDir(const std::string &inDir, const std::string &outDir);