diff --git a/project/jni/application/vcmi/vcmi-android-WIP-crap-shit.diff b/project/jni/application/vcmi/vcmi-android-WIP-crap-shit.diff index 5db5f37b5..59ed7978e 100644 --- a/project/jni/application/vcmi/vcmi-android-WIP-crap-shit.diff +++ b/project/jni/application/vcmi/vcmi-android-WIP-crap-shit.diff @@ -1,3 +1,76 @@ +Index: lib/CGeneralTextHandler.h +=================================================================== +--- lib/CGeneralTextHandler.h (revision 3494) ++++ lib/CGeneralTextHandler.h (working copy) +@@ -15,7 +15,7 @@ + /// Parser for any text files from H3 + class CLegacyConfigParser + { +- std::unique_ptr data; ++ std::vector data; + char * curr; + char * end; + +Index: lib/IGameCallback.cpp +=================================================================== +--- lib/IGameCallback.cpp (revision 3494) ++++ lib/IGameCallback.cpp (working copy) +@@ -661,7 +661,7 @@ + + const CMapHeader * CGameInfoCallback::getMapHeader() const + { +- return gs->map; ++ return gs->map.get(); + } + + bool CGameInfoCallback::hasAccess(boost::optional playerId) const +Index: lib/Connection.cpp +=================================================================== +--- lib/Connection.cpp (revision 3494) ++++ lib/Connection.cpp (working copy) +@@ -526,10 +526,10 @@ + return ret; + } + +-unique_ptr CLoadIntegrityValidator::decay() ++std::unique_ptr CLoadIntegrityValidator::decay() + { + primaryFile->loadedPointers = this->loadedPointers; +- return std::move(primaryFile); ++ return /*std::move*/(primaryFile); + } + + void CLoadIntegrityValidator::checkMagicBytes( const std::string &text ) +Index: lib/CDefObjInfoHandler.cpp +=================================================================== +--- lib/CDefObjInfoHandler.cpp (revision 3494) ++++ lib/CDefObjInfoHandler.cpp (working copy) +@@ -37,12 +37,12 @@ + + auto msk = CResourceHandler::get()->load(ResourceID(std::string("SPRITES/") + name, EResType::MASK))->readAll(); + +- width = msk.first.get()[0]; +- height = msk.first.get()[1]; ++ width = msk[0]; ++ height = msk[1]; + for(int i=0; i<6; ++i) + { +- coverageMap[i] = msk.first.get()[i+2]; +- shadowCoverage[i] = msk.first.get()[i+8]; ++ coverageMap[i] = msk[i+2]; ++ shadowCoverage[i] = msk[i+8]; + } + } + +@@ -51,7 +51,7 @@ + VLC->dobjinfo = this; + + auto textFile = CResourceHandler::get()->load(ResourceID("DATA/OBJECTS.TXT"))->readAll(); +- std::istringstream inp(std::string((char*)textFile.first.get(), textFile.second)); ++ std::istringstream inp(std::string((char*)textFile.data(), textFile.size())); + int objNumber; + inp>>objNumber; + std::string mapStr; Index: lib/JsonNode.cpp =================================================================== --- lib/JsonNode.cpp (revision 3494) @@ -7,7 +80,7 @@ Index: lib/JsonNode.cpp auto file = CResourceHandler::get()->load(fileURI)->readAll(); - JsonParser parser(reinterpret_cast(file.first.get()), file.second); -+ JsonParser parser(file.data(), file.size()); ++ JsonParser parser((const char *)file.data(), file.size()); *this = parser.parse(fileURI.getName()); } @@ -20,6 +93,20 @@ Index: lib/JsonNode.cpp std::back_inserter(dest.Vector())); } break; +@@ -1615,10 +1615,10 @@ + { + // FIXME: some way to make this code more readable + auto stream = loader->load(resID); +- std::unique_ptr textData(new ui8[stream->getSize()]); +- stream->read(textData.get(), stream->getSize()); ++ std::vector textData(stream->getSize()); ++ stream->read(textData.data(), stream->getSize()); + +- JsonNode section((char*)textData.get(), stream->getSize()); ++ JsonNode section((char*)textData.data(), stream->getSize()); + merge(result, section); + } + return result; Index: lib/CGameState.h =================================================================== --- lib/CGameState.h (revision 3494) @@ -33,54 +120,6 @@ Index: lib/CGameState.h bmap players; bmap teams; CBonusSystemNode globalEffects; -Index: lib/vcmi_endian.h -=================================================================== ---- lib/vcmi_endian.h (revision 3494) -+++ lib/vcmi_endian.h (working copy) -@@ -19,7 +19,7 @@ - * memory. On big endian machines, the value will be byteswapped. - */ - --#if defined(linux) && (defined(sparc) || defined(__arm__)) -+#if defined(ANDROID) || defined(linux) && (defined(sparc) || defined(__arm__)) - /* SPARC does not support unaligned memory access. Let gcc know when - * to emit the right code. */ - struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; -Index: lib/Connection.h -=================================================================== ---- lib/Connection.h (revision 3494) -+++ lib/Connection.h (working copy) -@@ -709,12 +709,14 @@ - T *internalPtr = data.get(); - *this << internalPtr; - } -+ /* - template - void saveSerializable(const unique_ptr &data) - { - T *internalPtr = data.get(); - *this << internalPtr; - } -+ */ - template - void saveSerializable(const std::vector &data) - { -@@ -1098,6 +1100,7 @@ - else - data.reset(); - } -+ /* - template - void loadSerializable(unique_ptr &data) - { -@@ -1105,6 +1108,7 @@ - *this >> internalPtr; - data.reset(internalPtr); - } -+ */ - template - void loadSerializable(std::vector &data) - { Index: lib/mapping/CMapInfo.cpp =================================================================== --- lib/mapping/CMapInfo.cpp (revision 3494) @@ -157,128 +196,6 @@ Index: lib/mapping/CMapInfo.h void mapInit(const std::string & fname); void campaignInit(); -Index: lib/VCMIDirs.cpp -=================================================================== ---- lib/VCMIDirs.cpp (revision 3494) -+++ lib/VCMIDirs.cpp (working copy) -@@ -15,11 +15,16 @@ - - VCMIDirs::VCMIDirs() - { -+ char buf[1024] = ""; -+ getcwd(buf, sizeof(buf)); -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d: mkdir '%s' '%s' '%s' '%s' curdir '%s'", __FUNCTION__, __FILE__, __LINE__, -+ userDataPath().c_str(), userCachePath().c_str(), userConfigPath().c_str(), userSavePath().c_str(), buf); - // initialize local directory and create folders to which VCMI needs write access - boost::filesystem::create_directory(userDataPath()); - boost::filesystem::create_directory(userCachePath()); - boost::filesystem::create_directory(userConfigPath()); - boost::filesystem::create_directory(userSavePath()); -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); - } - - VCMIDirs & VCMIDirs::get() -@@ -115,8 +120,10 @@ - - std::string VCMIDirs::userDataPath() const - { -+#ifndef ANDROID - if (getenv("HOME") != nullptr ) - return std::string(getenv("HOME")) + "/.vcmi"; -+#endif - return "."; - } - -Index: lib/Connection.cpp -=================================================================== ---- lib/Connection.cpp (revision 3494) -+++ lib/Connection.cpp (working copy) -@@ -526,10 +526,10 @@ - return ret; - } - --unique_ptr CLoadIntegrityValidator::decay() -+std::unique_ptr CLoadIntegrityValidator::decay() - { - primaryFile->loadedPointers = this->loadedPointers; -- return std::move(primaryFile); -+ return /*std::move*/(primaryFile); - } - - void CLoadIntegrityValidator::checkMagicBytes( const std::string &text ) -Index: lib/logging/CLogger.h -=================================================================== ---- lib/logging/CLogger.h (revision 3494) -+++ lib/logging/CLogger.h (working copy) -@@ -289,3 +289,11 @@ - CLogFormatter formatter; - mutable boost::mutex mx; - }; -+ -+#ifdef ANDROID -+static bool AndroidStaticInitLog() -+{ -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Static init: %s", __SOURCE_FILE__); -+} -+static bool AndroidStaticInitLogFlag = AndroidStaticInitLog(); -+#endif -Index: lib/logging/CLogger.cpp -=================================================================== ---- lib/logging/CLogger.cpp (revision 3494) -+++ lib/logging/CLogger.cpp (working copy) -@@ -387,6 +387,9 @@ - if(threshold > record.level) return; - - std::string message = formatter.format(record); -+#ifdef ANDROID -+ __android_log_print(ANDROID_LOG_INFO, "VCMI", "%s", message.c_str()); -+#endif - bool printToStdErr = record.level >= ELogLevel::WARN; - if(console) - { -Index: lib/CDefObjInfoHandler.cpp -=================================================================== ---- lib/CDefObjInfoHandler.cpp (revision 3494) -+++ lib/CDefObjInfoHandler.cpp (working copy) -@@ -37,12 +37,12 @@ - - auto msk = CResourceHandler::get()->load(ResourceID(std::string("SPRITES/") + name, EResType::MASK))->readAll(); - -- width = msk.first.get()[0]; -- height = msk.first.get()[1]; -+ width = msk[0]; -+ height = msk[1]; - for(int i=0; i<6; ++i) - { -- coverageMap[i] = msk.first.get()[i+2]; -- shadowCoverage[i] = msk.first.get()[i+8]; -+ coverageMap[i] = msk[i+2]; -+ shadowCoverage[i] = msk[i+8]; - } - } - -@@ -51,7 +51,7 @@ - VLC->dobjinfo = this; - - auto textFile = CResourceHandler::get()->load(ResourceID("DATA/OBJECTS.TXT"))->readAll(); -- std::istringstream inp(std::string((char*)textFile.first.get(), textFile.second)); -+ std::istringstream inp(std::string((char*)textFile.data(), textFile.size())); - int objNumber; - inp>>objNumber; - std::string mapStr; -Index: lib/CGeneralTextHandler.h -=================================================================== ---- lib/CGeneralTextHandler.h (revision 3494) -+++ lib/CGeneralTextHandler.h (working copy) -@@ -15,7 +15,7 @@ - /// Parser for any text files from H3 - class CLegacyConfigParser - { -- std::unique_ptr data; -+ std::vector data; - char * curr; - char * end; - Index: lib/CGameState.cpp =================================================================== --- lib/CGameState.cpp (revision 3494) @@ -319,6 +236,116 @@ Index: lib/CGameState.cpp } break; case StartInfo::DUEL: +Index: lib/logging/CLogger.h +=================================================================== +--- lib/logging/CLogger.h (revision 3494) ++++ lib/logging/CLogger.h (working copy) +@@ -289,3 +289,11 @@ + CLogFormatter formatter; + mutable boost::mutex mx; + }; ++ ++#ifdef ANDROID ++static bool AndroidStaticInitLog() ++{ ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Static init: %s", __SOURCE_FILE__); ++} ++static bool AndroidStaticInitLogFlag = AndroidStaticInitLog(); ++#endif +Index: lib/logging/CLogger.cpp +=================================================================== +--- lib/logging/CLogger.cpp (revision 3494) ++++ lib/logging/CLogger.cpp (working copy) +@@ -387,6 +387,9 @@ + if(threshold > record.level) return; + + std::string message = formatter.format(record); ++#ifdef ANDROID ++ __android_log_print(ANDROID_LOG_INFO, "VCMI", "%s", message.c_str()); ++#endif + bool printToStdErr = record.level >= ELogLevel::WARN; + if(console) + { +Index: lib/Connection.h +=================================================================== +--- lib/Connection.h (revision 3494) ++++ lib/Connection.h (working copy) +@@ -709,12 +709,14 @@ + T *internalPtr = data.get(); + *this << internalPtr; + } ++ /* + template + void saveSerializable(const unique_ptr &data) + { + T *internalPtr = data.get(); + *this << internalPtr; + } ++ */ + template + void saveSerializable(const std::vector &data) + { +@@ -1098,6 +1100,7 @@ + else + data.reset(); + } ++ /* + template + void loadSerializable(unique_ptr &data) + { +@@ -1105,6 +1108,7 @@ + *this >> internalPtr; + data.reset(internalPtr); + } ++ */ + template + void loadSerializable(std::vector &data) + { +Index: lib/VCMIDirs.cpp +=================================================================== +--- lib/VCMIDirs.cpp (revision 3494) ++++ lib/VCMIDirs.cpp (working copy) +@@ -15,11 +15,16 @@ + + VCMIDirs::VCMIDirs() + { ++ char buf[1024] = ""; ++ getcwd(buf, sizeof(buf)); ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d: mkdir '%s' '%s' '%s' '%s' curdir '%s'", __FUNCTION__, __FILE__, __LINE__, ++ userDataPath().c_str(), userCachePath().c_str(), userConfigPath().c_str(), userSavePath().c_str(), buf); + // initialize local directory and create folders to which VCMI needs write access + boost::filesystem::create_directory(userDataPath()); + boost::filesystem::create_directory(userCachePath()); + boost::filesystem::create_directory(userConfigPath()); + boost::filesystem::create_directory(userSavePath()); ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); + } + + VCMIDirs & VCMIDirs::get() +@@ -115,8 +120,10 @@ + + std::string VCMIDirs::userDataPath() const + { ++#ifndef ANDROID + if (getenv("HOME") != nullptr ) + return std::string(getenv("HOME")) + "/.vcmi"; ++#endif + return "."; + } + +Index: lib/vcmi_endian.h +=================================================================== +--- lib/vcmi_endian.h (revision 3494) ++++ lib/vcmi_endian.h (working copy) +@@ -19,7 +19,7 @@ + * memory. On big endian machines, the value will be byteswapped. + */ + +-#if defined(linux) && (defined(sparc) || defined(__arm__)) ++#if defined(ANDROID) || defined(linux) && (defined(sparc) || defined(__arm__)) + /* SPARC does not support unaligned memory access. Let gcc know when + * to emit the right code. */ + struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; Index: lib/CGeneralTextHandler.cpp =================================================================== --- lib/CGeneralTextHandler.cpp (revision 3494) @@ -337,6 +364,28 @@ Index: lib/CGeneralTextHandler.cpp end = curr + input->getSize(); } +Index: lib/filesystem/CInputStream.h +=================================================================== +--- lib/filesystem/CInputStream.h (revision 3494) ++++ lib/filesystem/CInputStream.h (working copy) +@@ -65,13 +65,13 @@ + * + * @return pair, first = raw data, second = size of data + */ +- std::pair, size_t> readAll() ++ std::vector readAll() + { +- std::unique_ptr data(new ui8[getSize()]); ++ std::vector data(getSize()); + +- size_t readSize = read(data.get(), getSize()); ++ size_t readSize = read(data.data(), getSize()); + assert(readSize == getSize()); + +- return std::make_pair(std::move(data), getSize()); ++ return data; + } + }; Index: lib/filesystem/Filesystem.cpp =================================================================== --- lib/filesystem/Filesystem.cpp (revision 3494) @@ -394,28 +443,6 @@ Index: lib/filesystem/Filesystem.cpp if (!fsConfig["filesystem"].isNull()) loadModFileSystem("mods/" + modName, fsConfig["filesystem"]); -Index: lib/filesystem/CInputStream.h -=================================================================== ---- lib/filesystem/CInputStream.h (revision 3494) -+++ lib/filesystem/CInputStream.h (working copy) -@@ -65,13 +65,13 @@ - * - * @return pair, first = raw data, second = size of data - */ -- std::pair, size_t> readAll() -+ std::vector readAll() - { -- std::unique_ptr data(new ui8[getSize()]); -+ std::vector data(getSize()); - -- size_t readSize = read(data.get(), getSize()); -+ size_t readSize = read(data.data(), getSize()); - assert(readSize == getSize()); - -- return std::make_pair(std::move(data), getSize()); -+ return data; - } - }; Index: lib/filesystem/CFileInfo.cpp =================================================================== --- lib/filesystem/CFileInfo.cpp (revision 3494) @@ -429,6 +456,31 @@ Index: lib/filesystem/CFileInfo.cpp { } +Index: client/CAnimation.cpp +=================================================================== +--- client/CAnimation.cpp (revision 3494) ++++ client/CAnimation.cpp (working copy) +@@ -109,8 +109,9 @@ + + auto data = CResourceHandler::get()->load(rid)->readAll(); + cache.back().name = ResourceID(rid); +- cache.back().size = data.second; +- cache.back().data = data.first.release(); ++ cache.back().size = data.size(); ++ cache.back().data = new ui8[data.size()]; ++ memcpy(cache.back().data, data.data(), data.size()); + + return cache.back().getCopy(); + } +@@ -1037,7 +1038,7 @@ + for(auto & loader : configList) + { + auto stream = loader->load(resID); +- std::unique_ptr textData(new ui8[stream->getSize()]); ++ std::unique_ptr textData(new ui8[stream->getSize()]); + stream->read(textData.get(), stream->getSize()); + + const JsonNode config((char*)textData.get(), stream->getSize()); Index: client/CPreGame.h =================================================================== --- client/CPreGame.h (revision 3494) @@ -442,56 +494,15 @@ Index: client/CPreGame.h CFunctionList mapInfoChanged; }; -Index: client/CVideoHandler.cpp -=================================================================== ---- client/CVideoHandler.cpp (revision 3494) -+++ client/CVideoHandler.cpp (working copy) -@@ -415,7 +415,7 @@ - auto data = CResourceHandler::get()->load(videoID)->readAll(); +@@ -495,7 +495,7 @@ - // try to determine video format using magic number from header (3 bytes, SMK or BIK) -- std::string magic(reinterpret_cast(data.first.get()), 3); -+ std::string magic(reinterpret_cast(data.data()), 3); - if (magic == "BIK") - current = &bikPlayer; - else if (magic == "SMK") -Index: client/CMusicHandler.cpp -=================================================================== ---- client/CMusicHandler.cpp (revision 3494) -+++ client/CMusicHandler.cpp (working copy) -@@ -141,7 +141,9 @@ - { - auto data = CResourceHandler::get()->load(ResourceID(std::string("SOUNDS/") + fname, EResType::SOUND))->readAll(); - -- SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second); -+ char *buf = new char[data.size()]; // Never release it -+ memcpy(buf, data.data(), data.size()); -+ SDL_RWops *ops = SDL_RWFromMem(buf, data.size()); - Mix_Chunk *chunk; - chunk = Mix_LoadWAV_RW(ops, 1); // will free ops - soundChunks.insert(std::pair(soundID, chunk)); -@@ -164,7 +166,9 @@ - { - auto data = CResourceHandler::get()->load(ResourceID(std::string("SOUNDS/") + sound, EResType::SOUND))->readAll(); - -- SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second); -+ char *buf = new char[data.size()]; // Never release it -+ memcpy(buf, data.data(), data.size()); -+ SDL_RWops *ops = SDL_RWFromMem(buf, data.size()); - Mix_Chunk *chunk; - chunk = Mix_LoadWAV_RW(ops, 1); // will free ops - return chunk; -@@ -496,7 +500,9 @@ - logGlobal->traceStream()<<"Loading music file "<load(ResourceID(musicURI, EResType::MUSIC))->readAll(); -- musicFile = SDL_RWFromConstMem(data.first.release(), data.second); -+ char *buf = new char[data.size()]; // Never release it -+ memcpy(buf, data.data(), data.size()); -+ musicFile = SDL_RWFromConstMem(buf, data.size()); - music = Mix_LoadMUS_RW(musicFile); - - if(!music) + void loadPositionsOfGraphics(); + shared_ptr ourCampaign; +- CMapHeader *ourHeader; ++ std::shared_ptr ourHeader; + CDefHandler *sizes; //icons of map sizes + SDL_Surface* diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this) + CAdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty Index: client/Graphics.cpp =================================================================== --- client/Graphics.cpp (revision 3494) @@ -505,176 +516,6 @@ Index: client/Graphics.cpp playerColorPalette = new SDL_Color[256]; neutralColor = new SDL_Color; -Index: client/gui/Fonts.cpp -=================================================================== ---- client/gui/Fonts.cpp (revision 3494) -+++ client/gui/Fonts.cpp (working copy) -@@ -97,7 +97,7 @@ - CBitmapFont::CBitmapFont(const std::string & filename): - data(CResourceHandler::get()->load(ResourceID("data/" + filename, EResType::BMP_FONT))->readAll()), - chars(loadChars()), -- height(data.first.get()[5]) -+ height(data.data()[5]) - {} - - size_t CBitmapFont::getLineHeight() const -@@ -195,7 +195,7 @@ - SDL_UnlockSurface(surface); - } - --std::pair, ui64> CTrueTypeFont::loadData(const JsonNode & config) -+std::vector CTrueTypeFont::loadData(const JsonNode & config) - { - std::string filename = "Data/" + config["file"].String(); - return CResourceHandler::get()->load(ResourceID(filename, EResType::TTF_FONT))->readAll(); -Index: client/gui/Fonts.h -=================================================================== ---- client/gui/Fonts.h (revision 3494) -+++ client/gui/Fonts.h (working copy) -@@ -88,12 +88,12 @@ - - class CTrueTypeFont : public IFont - { -- const std::pair, ui64> data; -+ std::vector data; - - const std::unique_ptr font; - const bool blended; - -- std::pair, ui64> loadData(const JsonNode & config); -+ std::vector loadData(const JsonNode & config); - TTF_Font * loadFont(const JsonNode & config); - int getFontStyle(const JsonNode & config); - -Index: client/CBitmapHandler.cpp -=================================================================== ---- client/CBitmapHandler.cpp (revision 3494) -+++ client/CBitmapHandler.cpp (working copy) -@@ -114,9 +114,9 @@ - - auto readFile = CResourceHandler::get()->load(ResourceID(path + fname, EResType::IMAGE))->readAll(); - -- if (isPCX(readFile.first.get())) -+ if (isPCX(readFile.data())) - {//H3-style PCX -- ret = loadH3PCX(readFile.first.get(), readFile.second); -+ ret = loadH3PCX(readFile.data(), readFile.size()); - if (ret) - { - if(ret->format->BytesPerPixel == 1 && setKey) -Index: client/CPreGame.cpp -=================================================================== ---- client/CPreGame.cpp (revision 3494) -+++ client/CPreGame.cpp (working copy) -@@ -404,7 +404,7 @@ - pos.w = CGP->menu->pos.w; - pos.h = CGP->menu->pos.h; - auto textFile = CResourceHandler::get()->load(ResourceID("DATA/CREDITS.TXT"))->readAll(); -- std::string text((char*)textFile.first.get(), textFile.second); -+ std::string text((char*)textFile.data(), textFile.size()); - size_t firstQuote = text.find('\"')+1; - text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote ); - credits = new CTextBox(text, Rect(pos.w - 350, 600, 350, 32000), 0, FONT_CREDITS, CENTER, Colors::WHITE); -@@ -1105,9 +1105,11 @@ - - void SelectionTab::parseMaps(const std::unordered_set &files) - { -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); - allItems.clear(); - for(auto & file : files) - { -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "checking file %s", file.getName().c_str()); - try - { - CMapInfo mapInfo; -@@ -1115,13 +1117,15 @@ - - // ignore unsupported map versions (e.g. WoG maps without WoG - if (mapInfo.mapHeader->version <= CGI->modh->settings.data["textData"]["mapVersion"].Float()) -- allItems.push_back(std::move(mapInfo)); -+ allItems.push_back(/*std::move*/(mapInfo)); - } - catch(std::exception & e) - { -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Error loading file %s", file.getName().c_str()); - logGlobal->errorStream() << "Map " << file.getName() << " is invalid. Message: " << e.what(); - } - } -+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); - } - - void SelectionTab::parseGames(const std::unordered_set &files, bool multi) -@@ -1141,7 +1145,7 @@ - - // Create the map info object - CMapInfo mapInfo; -- mapInfo.mapHeader = make_unique(); -+ mapInfo.mapHeader = std::make_shared(CMapHeader()); - mapInfo.scenarioOpts = new StartInfo; - lf >> *(mapInfo.mapHeader.get()) >> mapInfo.scenarioOpts; - mapInfo.fileURI = file.getName(); -@@ -1834,9 +1838,9 @@ - void CRandomMapTab::updateMapInfo() - { - // Generate header info -- mapInfo = make_unique(); -+ mapInfo = make_shared(); - mapInfo->isRandomMap = true; -- mapInfo->mapHeader = make_unique(); -+ mapInfo->mapHeader = std::make_shared(CMapHeader()); - mapInfo->mapHeader->version = EMapFormat::SOD; - mapInfo->mapHeader->name = CGI->generaltexth->allTexts[740]; - mapInfo->mapHeader->description = CGI->generaltexth->allTexts[741]; -Index: client/battle/CCreatureAnimation.cpp -=================================================================== ---- client/battle/CCreatureAnimation.cpp (revision 3494) -+++ client/battle/CCreatureAnimation.cpp (working copy) -@@ -159,11 +159,10 @@ - - auto data = CResourceHandler::get()->load(resID)->readAll(); - -- pixelData = std::move(data.first); -- pixelDataSize = data.second; -+ pixelData = data; - } - -- CBinaryReader reader(new CMemoryStream(pixelData.get(), pixelDataSize)); -+ CBinaryReader reader(new CMemoryStream(pixelData.data(), pixelData.size())); - - reader.readInt32(); // def type, unused - -@@ -307,7 +306,7 @@ - - ui32 offset = dataOffsets.at(type).at(floor(currentFrame)); - -- CBinaryReader reader(new CMemoryStream(pixelData.get(), pixelDataSize)); -+ CBinaryReader reader(new CMemoryStream(pixelData.data(), pixelData.size())); - - reader.getStream()->seek(offset); - -@@ -332,7 +331,7 @@ - for (ui32 i=0; i pixelData; -- size_t pixelDataSize; -+ std::vector pixelData; - - // speed of animation, measure in frames per second - float speed; Index: client/CMT.cpp =================================================================== --- client/CMT.cpp (revision 3494) @@ -808,22 +649,356 @@ Index: client/CDefHandler.cpp return nh; } CDefEssential * CDefHandler::giveDefEss(const std::string & defName) -Index: client/CAnimation.cpp +Index: client/CBitmapHandler.cpp =================================================================== ---- client/CAnimation.cpp (revision 3494) -+++ client/CAnimation.cpp (working copy) -@@ -109,8 +109,9 @@ +--- client/CBitmapHandler.cpp (revision 3494) ++++ client/CBitmapHandler.cpp (working copy) +@@ -114,9 +114,9 @@ - auto data = CResourceHandler::get()->load(rid)->readAll(); - cache.back().name = ResourceID(rid); -- cache.back().size = data.second; -- cache.back().data = data.first.release(); -+ cache.back().size = data.size(); -+ cache.back().data = new ui8[data.size()]; -+ memcpy(cache.back().data, data.data(), data.size()); + auto readFile = CResourceHandler::get()->load(ResourceID(path + fname, EResType::IMAGE))->readAll(); - return cache.back().getCopy(); +- if (isPCX(readFile.first.get())) ++ if (isPCX(readFile.data())) + {//H3-style PCX +- ret = loadH3PCX(readFile.first.get(), readFile.second); ++ ret = loadH3PCX(readFile.data(), readFile.size()); + if (ret) + { + if(ret->format->BytesPerPixel == 1 && setKey) +@@ -132,7 +132,7 @@ + { //loading via SDL_Image + ret = IMG_Load_RW( + //create SDL_RW with our data (will be deleted by SDL) +- SDL_RWFromConstMem((void*)readFile.first.get(), readFile.second), ++ SDL_RWFromConstMem((void*)readFile.data(), readFile.size()), + 1); // mark it for auto-deleting + if (ret) + { +Index: client/CPreGame.cpp +=================================================================== +--- client/CPreGame.cpp (revision 3494) ++++ client/CPreGame.cpp (working copy) +@@ -404,7 +404,7 @@ + pos.w = CGP->menu->pos.w; + pos.h = CGP->menu->pos.h; + auto textFile = CResourceHandler::get()->load(ResourceID("DATA/CREDITS.TXT"))->readAll(); +- std::string text((char*)textFile.first.get(), textFile.second); ++ std::string text((char*)textFile.data(), textFile.size()); + size_t firstQuote = text.find('\"')+1; + text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote ); + credits = new CTextBox(text, Rect(pos.w - 350, 600, 350, 32000), 0, FONT_CREDITS, CENTER, Colors::WHITE); +@@ -1105,9 +1105,11 @@ + + void SelectionTab::parseMaps(const std::unordered_set &files) + { ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); + allItems.clear(); + for(auto & file : files) + { ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "checking file %s", file.getName().c_str()); + try + { + CMapInfo mapInfo; +@@ -1115,13 +1117,15 @@ + + // ignore unsupported map versions (e.g. WoG maps without WoG + if (mapInfo.mapHeader->version <= CGI->modh->settings.data["textData"]["mapVersion"].Float()) +- allItems.push_back(std::move(mapInfo)); ++ allItems.push_back(/*std::move*/(mapInfo)); + } + catch(std::exception & e) + { ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Error loading file %s", file.getName().c_str()); + logGlobal->errorStream() << "Map " << file.getName() << " is invalid. Message: " << e.what(); + } } ++ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__); + } + + void SelectionTab::parseGames(const std::unordered_set &files, bool multi) +@@ -1141,7 +1145,7 @@ + + // Create the map info object + CMapInfo mapInfo; +- mapInfo.mapHeader = make_unique(); ++ mapInfo.mapHeader = std::make_shared(CMapHeader()); + mapInfo.scenarioOpts = new StartInfo; + lf >> *(mapInfo.mapHeader.get()) >> mapInfo.scenarioOpts; + mapInfo.fileURI = file.getName(); +@@ -1834,9 +1838,9 @@ + void CRandomMapTab::updateMapInfo() + { + // Generate header info +- mapInfo = make_unique(); ++ mapInfo = make_shared(); + mapInfo->isRandomMap = true; +- mapInfo->mapHeader = make_unique(); ++ mapInfo->mapHeader = std::make_shared(CMapHeader()); + mapInfo->mapHeader->version = EMapFormat::SOD; + mapInfo->mapHeader->name = CGI->generaltexth->allTexts[740]; + mapInfo->mapHeader->description = CGI->generaltexth->allTexts[741]; +@@ -3256,7 +3260,7 @@ + { + SDL_FreeSurface(background); + delete sizes; +- delete ourHeader; ++ ourHeader.reset(); + delete sFlags; + for (auto & elem : diffPics) + { +@@ -3320,14 +3324,14 @@ + ourCampaign->currentMap = whichOne; + + //get header +- delete ourHeader; ++ //delete ourHeader; + std::string & headerStr = ourCampaign->camp->mapPieces.find(whichOne)->second; + auto buffer = reinterpret_cast(headerStr.data()); +- ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()).release(); ++ ourHeader = CMapService::loadMapHeader(buffer, headerStr.size()); + + std::map names; + names[1] = settings["general"]["playerName"].String(); +- updateStartInfo(ourCampaign->camp->header.filename, sInfo, ourHeader, names); ++ updateStartInfo(ourCampaign->camp->header.filename, sInfo, ourHeader.get(), names); + sInfo.turnTime = 0; + sInfo.difficulty = ourCampaign->camp->scenarios[whichOne].difficulty; + +Index: client/Client.cpp +=================================================================== +--- client/Client.cpp (revision 3494) ++++ client/Client.cpp (working copy) +@@ -252,7 +252,7 @@ + } + logNetwork->infoStream() << "Loaded common part of save " << tmh.getDiff(); + const_cast(CGI)->mh = new CMapHandler(); +- const_cast(CGI)->mh->map = gs->map; ++ const_cast(CGI)->mh->map = gs->map.get(); + pathInfo = make_unique(getMapSize()); + CGI->mh->init(); + logNetwork->infoStream() <<"Initing maphandler: "<map) + { + const_cast(CGI)->mh = new CMapHandler(); +- CGI->mh->map = gs->map; ++ CGI->mh->map = gs->map.get(); + logNetwork->infoStream() <<"Creating mapHandler: "<mh->init(); + pathInfo = make_unique(getMapSize()); +Index: client/CVideoHandler.cpp +=================================================================== +--- client/CVideoHandler.cpp (revision 3494) ++++ client/CVideoHandler.cpp (working copy) +@@ -415,7 +415,7 @@ + auto data = CResourceHandler::get()->load(videoID)->readAll(); + + // try to determine video format using magic number from header (3 bytes, SMK or BIK) +- std::string magic(reinterpret_cast(data.first.get()), 3); ++ std::string magic(reinterpret_cast(data.data()), 3); + if (magic == "BIK") + current = &bikPlayer; + else if (magic == "SMK") +Index: client/CMusicHandler.cpp +=================================================================== +--- client/CMusicHandler.cpp (revision 3494) ++++ client/CMusicHandler.cpp (working copy) +@@ -141,7 +141,9 @@ + { + auto data = CResourceHandler::get()->load(ResourceID(std::string("SOUNDS/") + fname, EResType::SOUND))->readAll(); + +- SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second); ++ char *buf = new char[data.size()]; // Never release it ++ memcpy(buf, data.data(), data.size()); ++ SDL_RWops *ops = SDL_RWFromMem(buf, data.size()); + Mix_Chunk *chunk; + chunk = Mix_LoadWAV_RW(ops, 1); // will free ops + soundChunks.insert(std::pair(soundID, chunk)); +@@ -164,7 +166,9 @@ + { + auto data = CResourceHandler::get()->load(ResourceID(std::string("SOUNDS/") + sound, EResType::SOUND))->readAll(); + +- SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second); ++ char *buf = new char[data.size()]; // Never release it ++ memcpy(buf, data.data(), data.size()); ++ SDL_RWops *ops = SDL_RWFromMem(buf, data.size()); + Mix_Chunk *chunk; + chunk = Mix_LoadWAV_RW(ops, 1); // will free ops + return chunk; +@@ -400,11 +404,11 @@ + + boost::mutex::scoped_lock guard(musicMutex); + +- next = std::move(queued); ++ next = /*std::move*/(queued); + + if (current.get() == nullptr || !current->stop(1000)) + { +- current.reset(next.release()); ++ current = next; + current->play(); + } + } +@@ -457,7 +461,7 @@ + + if (current.get() == nullptr && next.get() != nullptr) + { +- current.reset(next.release()); ++ current = next; + current->play(); + } + } +@@ -496,7 +500,9 @@ + logGlobal->traceStream()<<"Loading music file "<load(ResourceID(musicURI, EResType::MUSIC))->readAll(); +- musicFile = SDL_RWFromConstMem(data.first.release(), data.second); ++ char *buf = new char[data.size()]; // Never release it ++ memcpy(buf, data.data(), data.size()); ++ musicFile = SDL_RWFromConstMem(buf, data.size()); + music = Mix_LoadMUS_RW(musicFile); + + if(!music) +Index: client/battle/CCreatureAnimation.h +=================================================================== +--- client/battle/CCreatureAnimation.h (revision 3494) ++++ client/battle/CCreatureAnimation.h (working copy) +@@ -66,8 +66,7 @@ + + //animation raw data + //TODO: use vector instead? +- unique_ptr pixelData; +- size_t pixelDataSize; ++ std::vector pixelData; + + // speed of animation, measure in frames per second + float speed; +Index: client/battle/CCreatureAnimation.cpp +=================================================================== +--- client/battle/CCreatureAnimation.cpp (revision 3494) ++++ client/battle/CCreatureAnimation.cpp (working copy) +@@ -159,11 +159,10 @@ + + auto data = CResourceHandler::get()->load(resID)->readAll(); + +- pixelData = std::move(data.first); +- pixelDataSize = data.second; ++ pixelData = data; + } + +- CBinaryReader reader(new CMemoryStream(pixelData.get(), pixelDataSize)); ++ CBinaryReader reader(new CMemoryStream(pixelData.data(), pixelData.size())); + + reader.readInt32(); // def type, unused + +@@ -307,7 +306,7 @@ + + ui32 offset = dataOffsets.at(type).at(floor(currentFrame)); + +- CBinaryReader reader(new CMemoryStream(pixelData.get(), pixelDataSize)); ++ CBinaryReader reader(new CMemoryStream(pixelData.data(), pixelData.size())); + + reader.getStream()->seek(offset); + +@@ -332,7 +331,7 @@ + for (ui32 i=0; iload(ResourceID("data/" + filename, EResType::BMP_FONT))->readAll()), + chars(loadChars()), +- height(data.first.get()[5]) ++ height(data.data()[5]) + {} + + size_t CBitmapFont::getLineHeight() const +@@ -195,7 +195,7 @@ + SDL_UnlockSurface(surface); + } + +-std::pair, ui64> CTrueTypeFont::loadData(const JsonNode & config) ++std::vector CTrueTypeFont::loadData(const JsonNode & config) + { + std::string filename = "Data/" + config["file"].String(); + return CResourceHandler::get()->load(ResourceID(filename, EResType::TTF_FONT))->readAll(); +@@ -208,7 +208,7 @@ + if(!TTF_WasInit() && TTF_Init()==-1) + throw std::runtime_error(std::string("Failed to initialize true type support: ") + TTF_GetError() + "\n"); + +- return TTF_OpenFontRW(SDL_RWFromConstMem(data.first.get(), data.second), 1, pointSize); ++ return TTF_OpenFontRW(SDL_RWFromConstMem(data.data(), data.size()), 1, pointSize); + } + + int CTrueTypeFont::getFontStyle(const JsonNode &config) +@@ -227,7 +227,7 @@ + + CTrueTypeFont::CTrueTypeFont(const JsonNode & fontConfig): + data(loadData(fontConfig)), +- font(loadFont(fontConfig), TTF_CloseFont), ++ font(loadFont(fontConfig), &TTF_CloseFont), + blended(fontConfig["blend"].Bool()) + { + assert(font); +Index: client/gui/Fonts.h +=================================================================== +--- client/gui/Fonts.h (revision 3494) ++++ client/gui/Fonts.h (working copy) +@@ -68,7 +68,7 @@ + ui8 *pixels; // pixels of this character, part of BitmapFont::data + }; + +- const std::pair, ui64> data; ++ std::vector data; + + const std::array chars; + const ui8 height; +@@ -88,12 +88,12 @@ + + class CTrueTypeFont : public IFont + { +- const std::pair, ui64> data; ++ std::vector data; + +- const std::unique_ptr font; ++ const std::unique_ptr font; + const bool blended; + +- std::pair, ui64> loadData(const JsonNode & config); ++ std::vector loadData(const JsonNode & config); + TTF_Font * loadFont(const JsonNode & config); + int getFontStyle(const JsonNode & config); + Index: Global.h =================================================================== --- Global.h (revision 3494) diff --git a/project/jni/application/vcmi/vcmi-android.diff b/project/jni/application/vcmi/vcmi-android.diff index 0d444b113..8bb6b64b2 100644 --- a/project/jni/application/vcmi/vcmi-android.diff +++ b/project/jni/application/vcmi/vcmi-android.diff @@ -1,25 +1,3 @@ -Index: client/CPreGame.cpp -=================================================================== ---- client/CPreGame.cpp (revision 3494) -+++ client/CPreGame.cpp (working copy) -@@ -1141,7 +1141,7 @@ - - // Create the map info object - CMapInfo mapInfo; -- mapInfo.mapHeader = make_unique(); -+ mapInfo.mapHeader = std::make_shared(CMapHeader()); - mapInfo.scenarioOpts = new StartInfo; - lf >> *(mapInfo.mapHeader.get()) >> mapInfo.scenarioOpts; - mapInfo.fileURI = file.getName(); -@@ -1836,7 +1836,7 @@ - // Generate header info - mapInfo = make_unique(); - mapInfo->isRandomMap = true; -- mapInfo->mapHeader = make_unique(); -+ mapInfo->mapHeader = std::make_shared(CMapHeader()); - mapInfo->mapHeader->version = EMapFormat::SOD; - mapInfo->mapHeader->name = CGI->generaltexth->allTexts[740]; - mapInfo->mapHeader->description = CGI->generaltexth->allTexts[741]; Index: client/CMT.cpp =================================================================== --- client/CMT.cpp (revision 3494) @@ -106,144 +84,15 @@ Index: client/CMT.cpp if(!gNoGUI ) { -@@ -370,8 +389,8 @@ +@@ -370,7 +389,7 @@ } CSDL_Ext::update(screen); - loading.join(); -- logGlobal->infoStream()<<"Initialization of VCMI (together): "<infoStream()<<"Initialization of VCMI (together): "<infoStream()<<"Initialization of VCMI (together): "< - #include -- -+#ifdef ANDROID -+/* -+#define move disable_move // It crashes with NDK r9 and GCC 4.8 -+#include -+#undef move -+namespace std -+{ -+ template -+ _Tp move(_Tp __t) -+ { -+ return __t; // Unoptimized version that does not crash -+ } -+ -+ template -+ OutputIt move(InputIt first, InputIt last, OutputIt d_first) -+ { -+ while (first != last) -+ { -+ *d_first++ = *first++; -+ } -+ return d_first; -+ } -+} -+*/ -+/* -+#include -+#define unique_ptr shared_ptr -+*/ -+#endif - #include - #include - #include -Index: lib/filesystem/Filesystem.cpp -=================================================================== ---- lib/filesystem/Filesystem.cpp (revision 3494) -+++ lib/filesystem/Filesystem.cpp (working copy) -@@ -24,14 +24,14 @@ - - ResourceID::ResourceID(std::string name) - { -- CFileInfo info(std::move(name)); -+ CFileInfo info(/*std::move*/(name)); - setName(info.getStem()); - setType(info.getType()); - } - - ResourceID::ResourceID(std::string name, EResType::Type type) - { -- setName(std::move(name)); -+ setName(/*std::move*/(name)); - setType(type); - } - -@@ -47,7 +47,7 @@ - - void ResourceID::setName(std::string name) - { -- this->name = std::move(name); -+ this->name = /*std::move*/(name); - - size_t dotPos = this->name.find_last_of("/."); - -Index: lib/filesystem/CFileInfo.cpp -=================================================================== ---- lib/filesystem/CFileInfo.cpp (revision 3494) -+++ lib/filesystem/CFileInfo.cpp (working copy) -@@ -7,7 +7,7 @@ - } - - CFileInfo::CFileInfo(std::string name) -- : name(std::move(name)) -+ : name(/*std::move*/(name)) - { - - } -Index: lib/mapping/CMapInfo.cpp -=================================================================== ---- lib/mapping/CMapInfo.cpp (revision 3494) -+++ lib/mapping/CMapInfo.cpp (working copy) -@@ -35,7 +35,7 @@ - - } - --#define STEAL(x) x = std::move(tmp.x) -+#define STEAL(x) x = /*std::move*/(tmp.x) - - CMapInfo::CMapInfo(CMapInfo && tmp) - { -@@ -54,13 +54,13 @@ - void CMapInfo::mapInit(const std::string & fname) - { - fileURI = fname; -- mapHeader = CMapService::loadMapHeader(fname); -+ mapHeader = std::make_shared(*CMapService::loadMapHeader(fname)); - countPlayers(); - } - - void CMapInfo::campaignInit() - { -- campaignHeader = std::unique_ptr(new CCampaignHeader(CCampaignHandler::getHeader(fileURI))); -+ campaignHeader = std::make_shared(CCampaignHandler::getHeader(fileURI)); - } - - CMapInfo & CMapInfo::operator=(CMapInfo &&tmp) -Index: lib/mapping/CMapInfo.h -=================================================================== ---- lib/mapping/CMapInfo.h (revision 3494) -+++ lib/mapping/CMapInfo.h (working copy) -@@ -20,8 +20,8 @@ - class DLL_LINKAGE CMapInfo - { - public: -- unique_ptr mapHeader; //may be nullptr if campaign -- unique_ptr campaignHeader; //may be nullptr if scenario -+ shared_ptr mapHeader; //may be nullptr if campaign -+ shared_ptr campaignHeader; //may be nullptr if scenario - StartInfo * scenarioOpts; //options with which scenario has been started (used only with saved games) - std::string fileURI; - std::string date; Index: lib/logging/CLogger.cpp =================================================================== --- lib/logging/CLogger.cpp (revision 3494) @@ -287,19 +136,49 @@ Index: lib/JsonNode.cpp std::back_inserter(dest.Vector())); } break; -Index: lib/vcmi_endian.h +Index: lib/filesystem/Filesystem.cpp =================================================================== ---- lib/vcmi_endian.h (revision 3494) -+++ lib/vcmi_endian.h (working copy) -@@ -19,7 +19,7 @@ - * memory. On big endian machines, the value will be byteswapped. - */ - --#if defined(linux) && (defined(sparc) || defined(__arm__)) -+#if defined(ANDROID) || defined(linux) && (defined(sparc) || defined(__arm__)) - /* SPARC does not support unaligned memory access. Let gcc know when - * to emit the right code. */ - struct unaligned_Uint16 { ui16 val __attribute__(( packed )); }; +--- lib/filesystem/Filesystem.cpp (revision 3494) ++++ lib/filesystem/Filesystem.cpp (working copy) +@@ -24,14 +24,14 @@ + + ResourceID::ResourceID(std::string name) + { +- CFileInfo info(std::move(name)); ++ CFileInfo info(/*std::move*/(name)); + setName(info.getStem()); + setType(info.getType()); + } + + ResourceID::ResourceID(std::string name, EResType::Type type) + { +- setName(std::move(name)); ++ setName(/*std::move*/(name)); + setType(type); + } + +@@ -47,7 +47,7 @@ + + void ResourceID::setName(std::string name) + { +- this->name = std::move(name); ++ this->name = /*std::move*/(name); + + size_t dotPos = this->name.find_last_of("/."); + +Index: lib/filesystem/CFileInfo.cpp +=================================================================== +--- lib/filesystem/CFileInfo.cpp (revision 3494) ++++ lib/filesystem/CFileInfo.cpp (working copy) +@@ -7,7 +7,7 @@ + } + + CFileInfo::CFileInfo(std::string name) +- : name(std::move(name)) ++ : name(/*std::move*/(name)) + { + + } Index: lib/VCMIDirs.cpp =================================================================== --- lib/VCMIDirs.cpp (revision 3494) @@ -332,3 +211,16 @@ Index: lib/VCMIDirs.cpp return "."; } +Index: lib/vcmi_endian.h +=================================================================== +--- lib/vcmi_endian.h (revision 3494) ++++ lib/vcmi_endian.h (working copy) +@@ -19,7 +19,7 @@ + * memory. On big endian machines, the value will be byteswapped. + */ + +-#if defined(linux) && (defined(sparc) || defined(__arm__)) ++#if defined(ANDROID) || defined(linux) && (defined(sparc) || defined(__arm__)) + /* SPARC does not support unaligned memory access. Let gcc know when + * to emit the right code. */ + struct unaligned_Uint16 { ui16 val __attribute__(( packed )); };