summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-09-22 15:56:01 +0300
committerAndrei Karas <akaras@inbox.ru>2013-09-22 16:28:10 +0300
commitfbad53d1a8cc89d07227165042cd55e7ed9c5dd2 (patch)
tree07a0105853e97088f1a091caecc3bb2fb4968c13
parent87b21ba61d7a8c322d658bd6b8d9f75b9e711263 (diff)
downloadplus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.tar.gz
plus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.tar.bz2
plus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.tar.xz
plus-fbad53d1a8cc89d07227165042cd55e7ed9c5dd2.zip
add support in ADNROID+SDL2 for loading data from assets.
-rw-r--r--src/client.cpp54
-rw-r--r--src/client.h6
-rw-r--r--src/gui/sdlfont.cpp9
3 files changed, 67 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp
index cc2a06f77..3a5a3f943 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -365,6 +365,11 @@ void Client::gameInit()
Fuzzer::init();
#endif
+#ifdef ANDROID
+#ifdef USE_SDL2
+ extractAssets();
+#endif
+#endif
initConfiguration();
paths.setDefaultValues(getPathsDefaults());
initFeatures();
@@ -518,6 +523,15 @@ void Client::gameInit()
mPackageDir = PKG_DATADIR "data";
resman->addToSearchPath("data", false);
+#ifdef ANDROID
+#ifdef USE_SDL2
+ if (getenv("APPDIR"))
+ {
+ resman->addToSearchPath(std::string(getenv("APPDIR"))
+ + "/data.zip", false);
+ }
+#endif
+#endif
// Add branding/data to PhysFS search path
if (!mOptions.brandingPath.empty())
{
@@ -3175,3 +3189,43 @@ void Client::handleActive(const SDL_Event &event)
setMouseFocused(event.active.gain);
}
#endif
+
+#ifdef ANDROID
+#ifdef USE_SDL2
+void Client::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);
+ FILE *const file = fopen(fileName.c_str(), "w");
+ uint8_t *buf = new uint8_t[1000000];
+ 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);
+ }
+ else
+ {
+ break;
+ }
+ }
+ delete [] buf;
+ fclose(file);
+}
+#endif
+#endif
diff --git a/src/client.h b/src/client.h
index fe19a7154..6c1a7bff2 100644
--- a/src/client.h
+++ b/src/client.h
@@ -391,6 +391,12 @@ private:
static void setEnv(const char *const name, const char *const value);
+#ifdef ANDROID
+#ifdef USE_SDL2
+ void extractAssets();
+#endif
+#endif
+
Options mOptions;
std::string mPackageDir;
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index eb05bea8d..07da298b2 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -35,6 +35,7 @@
#include "resources/surfaceimagehelper.h"
#include "utils/paths.h"
+#include "utils/physfsrwops.h"
#include "utils/sdlcheckutils.h"
#include <guichan/exception.hpp>
@@ -397,8 +398,12 @@ SDLFont::~SDLFont()
TTF_Font *SDLFont::openFont(const char *const name, const int size)
{
- return TTF_OpenFontIndex(ResourceManager::getInstance()->getPath(
- name).c_str(), size, 0);
+ logger->log("font to open: %s", name);
+ ResourceManager *const resman = ResourceManager::getInstance();
+ SDL_RWops *const rw = MPHYSFSRWOPS_openRead(name);
+ if (!rw)
+ return nullptr;
+ return TTF_OpenFontIndexRW(rw, 1, size, 0);
}
void SDLFont::loadFont(std::string filename,