VCMI: this is dementing
This commit is contained in:
@@ -65,11 +65,12 @@ $(OBJS_SERVER) $(OBJS_LIB) $(OBJS_LIB_FILESYSTEM) $(OBJS_LIB_LOGGING) $(OBJS_LIB
|
||||
$(OBJS_BATTLEAI) $(OBJS_STUPIDAI) $(OBJS_FUZZYLITE) $(OBJS_VCAI) $(OBJS_CLIENT) $(OBJS_ERM): out/%.o: %.cpp
|
||||
env GCCVER=$(GCC_VERSION) ../setEnvironment-armeabi-v7a.sh sh -c \
|
||||
"$(GCC_PREFIX)-g++ \
|
||||
-c \$$CXXFLAGS -O1 -Ivcmi -std=c++11 -Ivcmi/lib \
|
||||
-c \$$CXXFLAGS -O1 -Ivcmi -std=c++0x -Ivcmi/lib \
|
||||
-DM_DATA_DIR=\\\".\\\" \
|
||||
-DM_BIN_DIR=\\\"/data/data/eu.vcmi/files\\\" \
|
||||
-DM_LIB_DIR=\\\"/data/data/eu.vcmi/files\\\" \
|
||||
-Wstrict-aliasing -Wcast-align -Wpointer-arith -Waddress -D__SOURCE_FILE__=\\\"$<\\\" \
|
||||
-Wstrict-aliasing -Wcast-align -Wpointer-arith -Waddress \
|
||||
-D__SOURCE_FILE__=\\\"$<\\\" \
|
||||
$< -o $@"
|
||||
# -Werror=strict-aliasing -Werror=cast-align -Werror=pointer-arith -Werror=address
|
||||
|
||||
|
||||
876
project/jni/application/vcmi/vcmi-android-WIP-crap-shit.diff
Normal file
876
project/jni/application/vcmi/vcmi-android-WIP-crap-shit.diff
Normal file
@@ -0,0 +1,876 @@
|
||||
Index: lib/JsonNode.cpp
|
||||
===================================================================
|
||||
--- lib/JsonNode.cpp (revision 3494)
|
||||
+++ lib/JsonNode.cpp (working copy)
|
||||
@@ -43,7 +43,7 @@
|
||||
{
|
||||
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
||||
|
||||
- JsonParser parser(reinterpret_cast<char*>(file.first.get()), file.second);
|
||||
+ JsonParser parser(file.data(), file.size());
|
||||
*this = parser.parse(fileURI.getName());
|
||||
}
|
||||
|
||||
@@ -1574,7 +1574,7 @@
|
||||
//reserve place and *move* remaining data from source to dest
|
||||
source.Vector().reserve(source.Vector().size() + dest.Vector().size());
|
||||
|
||||
- std::move(source.Vector().begin() + total, source.Vector().end(),
|
||||
+ std::copy(source.Vector().begin() + total, source.Vector().end(),
|
||||
std::back_inserter(dest.Vector()));
|
||||
}
|
||||
break;
|
||||
Index: lib/CGameState.h
|
||||
===================================================================
|
||||
--- lib/CGameState.h (revision 3494)
|
||||
+++ lib/CGameState.h (working copy)
|
||||
@@ -363,7 +363,7 @@
|
||||
PlayerColor currentPlayer; //ID of player currently having turn
|
||||
ConstTransitivePtr<BattleInfo> curB; //current battle
|
||||
ui32 day; //total number of days in game
|
||||
- ConstTransitivePtr<CMap> map;
|
||||
+ shared_ptr<CMap> map;
|
||||
bmap<PlayerColor, PlayerState> players;
|
||||
bmap<TeamID, TeamState> 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 <typename T>
|
||||
void saveSerializable(const unique_ptr<T> &data)
|
||||
{
|
||||
T *internalPtr = data.get();
|
||||
*this << internalPtr;
|
||||
}
|
||||
+ */
|
||||
template <typename T>
|
||||
void saveSerializable(const std::vector<T> &data)
|
||||
{
|
||||
@@ -1098,6 +1100,7 @@
|
||||
else
|
||||
data.reset();
|
||||
}
|
||||
+ /*
|
||||
template <typename T>
|
||||
void loadSerializable(unique_ptr<T> &data)
|
||||
{
|
||||
@@ -1105,6 +1108,7 @@
|
||||
*this >> internalPtr;
|
||||
data.reset(internalPtr);
|
||||
}
|
||||
+ */
|
||||
template <typename T>
|
||||
void loadSerializable(std::vector<T> &data)
|
||||
{
|
||||
Index: lib/mapping/CMapInfo.cpp
|
||||
===================================================================
|
||||
--- lib/mapping/CMapInfo.cpp (revision 3494)
|
||||
+++ lib/mapping/CMapInfo.cpp (working copy)
|
||||
@@ -35,9 +35,9 @@
|
||||
|
||||
}
|
||||
|
||||
-#define STEAL(x) x = std::move(tmp.x)
|
||||
+#define STEAL(x) x = /*std::move*/(tmp.x)
|
||||
|
||||
-CMapInfo::CMapInfo(CMapInfo && tmp)
|
||||
+CMapInfo::CMapInfo(const CMapInfo & tmp)
|
||||
{
|
||||
STEAL(mapHeader);
|
||||
STEAL(campaignHeader);
|
||||
@@ -54,16 +54,16 @@
|
||||
void CMapInfo::mapInit(const std::string & fname)
|
||||
{
|
||||
fileURI = fname;
|
||||
- mapHeader = CMapService::loadMapHeader(fname);
|
||||
+ mapHeader = std::make_shared<CMapHeader>(*CMapService::loadMapHeader(fname));
|
||||
countPlayers();
|
||||
}
|
||||
|
||||
void CMapInfo::campaignInit()
|
||||
{
|
||||
- campaignHeader = std::unique_ptr<CCampaignHeader>(new CCampaignHeader(CCampaignHandler::getHeader(fileURI)));
|
||||
+ campaignHeader = std::make_shared<CCampaignHeader>(CCampaignHandler::getHeader(fileURI));
|
||||
}
|
||||
|
||||
-CMapInfo & CMapInfo::operator=(CMapInfo &&tmp)
|
||||
+CMapInfo & CMapInfo::operator=(const CMapInfo &tmp)
|
||||
{
|
||||
STEAL(mapHeader);
|
||||
STEAL(campaignHeader);
|
||||
Index: lib/mapping/MapFormatH3M.cpp
|
||||
===================================================================
|
||||
--- lib/mapping/MapFormatH3M.cpp (revision 3494)
|
||||
+++ lib/mapping/MapFormatH3M.cpp (working copy)
|
||||
@@ -44,7 +44,7 @@
|
||||
mapHeader = std::unique_ptr<CMapHeader>(dynamic_cast<CMapHeader *>(map));
|
||||
init();
|
||||
|
||||
- return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.release()));;
|
||||
+ return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.get()));
|
||||
}
|
||||
|
||||
std::unique_ptr<CMapHeader> CMapLoaderH3M::loadMapHeader()
|
||||
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<CMapHeader> mapHeader; //may be nullptr if campaign
|
||||
- unique_ptr<CCampaignHeader> campaignHeader; //may be nullptr if scenario
|
||||
+ shared_ptr<CMapHeader> mapHeader; //may be nullptr if campaign
|
||||
+ shared_ptr<CCampaignHeader> 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;
|
||||
@@ -31,9 +31,9 @@
|
||||
bool isRandomMap; // true if the map will be created randomly, false if not
|
||||
|
||||
CMapInfo();
|
||||
- CMapInfo(CMapInfo && tmp);
|
||||
+ CMapInfo(const CMapInfo & tmp);
|
||||
|
||||
- CMapInfo &operator=(CMapInfo &&other);
|
||||
+ CMapInfo &operator=(const CMapInfo &other);
|
||||
|
||||
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<CLoadFile> CLoadIntegrityValidator::decay()
|
||||
+std::unique_ptr<CLoadFile> 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<char[]> data;
|
||||
+ std::vector<char> data;
|
||||
char * curr;
|
||||
char * end;
|
||||
|
||||
Index: lib/CGameState.cpp
|
||||
===================================================================
|
||||
--- lib/CGameState.cpp (revision 3494)
|
||||
+++ lib/CGameState.cpp (working copy)
|
||||
@@ -757,7 +757,7 @@
|
||||
CGameState::~CGameState()
|
||||
{
|
||||
//delete mx;//TODO: crash on Linux (mutex must be unlocked before destruction)
|
||||
- map.dellNull();
|
||||
+ map.reset();
|
||||
curB.dellNull();
|
||||
//delete scenarioOps; //TODO: fix for loading ind delete
|
||||
//delete initialOpts;
|
||||
@@ -868,7 +868,7 @@
|
||||
|
||||
// Gen map
|
||||
CMapGenerator mapGen(*(scenarioOps->mapGenOptions), scenarioOps->seedToBeUsed);
|
||||
- map = mapGen.generate().release();
|
||||
+ map = mapGen.generate();
|
||||
|
||||
// Update starting options
|
||||
for(int i = 0; i < map->players.size(); ++i)
|
||||
@@ -897,7 +897,7 @@
|
||||
else
|
||||
{
|
||||
logGlobal->infoStream() << "Open map file: " << scenarioOps->mapname;
|
||||
- map = CMapService::loadMap(scenarioOps->mapname).release();
|
||||
+ map = CMapService::loadMap(scenarioOps->mapname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -909,7 +909,7 @@
|
||||
|
||||
std::string & mapContent = campaign->camp->mapPieces[scenarioOps->campState->currentMap];
|
||||
auto buffer = reinterpret_cast<const ui8 *>(mapContent.data());
|
||||
- map = CMapService::loadMap(buffer, mapContent.size()).release();
|
||||
+ map = CMapService::loadMap(buffer, mapContent.size());
|
||||
}
|
||||
break;
|
||||
case StartInfo::DUEL:
|
||||
Index: lib/CGeneralTextHandler.cpp
|
||||
===================================================================
|
||||
--- lib/CGeneralTextHandler.cpp (revision 3494)
|
||||
+++ lib/CGeneralTextHandler.cpp (working copy)
|
||||
@@ -40,10 +40,10 @@
|
||||
|
||||
void CLegacyConfigParser::init(const std::unique_ptr<CInputStream> & input)
|
||||
{
|
||||
- data.reset(new char[input->getSize()]);
|
||||
- input->read((ui8*)data.get(), input->getSize());
|
||||
+ data.resize(input->getSize());
|
||||
+ input->read((ui8*)data.data(), input->getSize());
|
||||
|
||||
- curr = data.get();
|
||||
+ curr = data.data();
|
||||
end = curr + input->getSize();
|
||||
}
|
||||
|
||||
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("/.");
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
if (filename)
|
||||
{
|
||||
auto configData = initialLoader->load(ResourceID(URI, EResType::TEXT))->readAll();
|
||||
- const JsonNode config((char*)configData.first.get(), configData.second);
|
||||
+ const JsonNode config((char*)configData.data(), configData.size());
|
||||
resourceLoader->addLoader(new CMappedFileLoader(mountPoint, config), false);
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@
|
||||
{
|
||||
auto fsConfigData = initialLoader->load(ResourceID(fsConfigURI, EResType::TEXT))->readAll();
|
||||
|
||||
- const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second);
|
||||
+ const JsonNode fsConfig((char*)fsConfigData.data(), fsConfigData.size());
|
||||
|
||||
loadModFileSystem("", fsConfig["filesystem"]);
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
{
|
||||
ResourceID modConfFile("mods/" + modName + "/mod", EResType::TEXT);
|
||||
auto fsConfigData = initialLoader->load(modConfFile)->readAll();
|
||||
- const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second);
|
||||
+ const JsonNode fsConfig((char*)fsConfigData.data(), fsConfigData.size());
|
||||
|
||||
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<std::unique_ptr<ui8[]>, size_t> readAll()
|
||||
+ std::vector<ui8> readAll()
|
||||
{
|
||||
- std::unique_ptr<ui8[]> data(new ui8[getSize()]);
|
||||
+ std::vector<ui8> 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)
|
||||
+++ lib/filesystem/CFileInfo.cpp (working copy)
|
||||
@@ -7,7 +7,7 @@
|
||||
}
|
||||
|
||||
CFileInfo::CFileInfo(std::string name)
|
||||
- : name(std::move(name))
|
||||
+ : name(/*std::move*/(name))
|
||||
{
|
||||
|
||||
}
|
||||
Index: client/CPreGame.h
|
||||
===================================================================
|
||||
--- client/CPreGame.h (revision 3494)
|
||||
+++ client/CPreGame.h (working copy)
|
||||
@@ -307,7 +307,7 @@
|
||||
* compOnlyTeamsCntGroup, * waterContentGroup, * monsterStrengthGroup;
|
||||
CAdventureMapButton * showRandMaps;
|
||||
CMapGenOptions mapGenOptions;
|
||||
- unique_ptr<CMapInfo> mapInfo;
|
||||
+ shared_ptr<CMapInfo> mapInfo;
|
||||
CFunctionList<void(const CMapInfo *)> 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();
|
||||
|
||||
// try to determine video format using magic number from header (3 bytes, SMK or BIK)
|
||||
- std::string magic(reinterpret_cast<char*>(data.first.get()), 3);
|
||||
+ std::string magic(reinterpret_cast<char*>(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<soundBase::soundID, Mix_Chunk *>(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 "<<musicURI;
|
||||
|
||||
auto data = CResourceHandler::get()->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/Graphics.cpp
|
||||
===================================================================
|
||||
--- client/Graphics.cpp (revision 3494)
|
||||
+++ client/Graphics.cpp (working copy)
|
||||
@@ -48,7 +48,7 @@
|
||||
void Graphics::loadPaletteAndColors()
|
||||
{
|
||||
auto textFile = CResourceHandler::get()->load(ResourceID("DATA/PLAYERS.PAL"))->readAll();
|
||||
- std::string pals((char*)textFile.first.get(), textFile.second);
|
||||
+ std::string pals((char*)textFile.data(), textFile.size());
|
||||
|
||||
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<std::unique_ptr<ui8[]>, ui64> CTrueTypeFont::loadData(const JsonNode & config)
|
||||
+std::vector<ui8> 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<std::unique_ptr<ui8[]>, ui64> data;
|
||||
+ std::vector<ui8> data;
|
||||
|
||||
const std::unique_ptr<TTF_Font, void (*)(TTF_Font*)> font;
|
||||
const bool blended;
|
||||
|
||||
- std::pair<std::unique_ptr<ui8[]>, ui64> loadData(const JsonNode & config);
|
||||
+ std::vector<ui8> 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<ResourceID> &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<ResourceID> &files, bool multi)
|
||||
@@ -1141,7 +1145,7 @@
|
||||
|
||||
// Create the map info object
|
||||
CMapInfo mapInfo;
|
||||
- mapInfo.mapHeader = make_unique<CMapHeader>();
|
||||
+ mapInfo.mapHeader = std::make_shared<CMapHeader>(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<CMapInfo>();
|
||||
+ mapInfo = make_shared<CMapInfo>();
|
||||
mapInfo->isRandomMap = true;
|
||||
- mapInfo->mapHeader = make_unique<CMapHeader>();
|
||||
+ mapInfo->mapHeader = std::make_shared<CMapHeader>(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<spriteHeight; i++)
|
||||
{
|
||||
//NOTE: if this loop will be optimized to skip empty lines - recheck this read access
|
||||
- ui8 * lineData = pixelData.get() + baseOffset + reader.readUInt32();
|
||||
+ ui8 * lineData = pixelData.data() + baseOffset + reader.readUInt32();
|
||||
|
||||
size_t destX = pos.x;
|
||||
if (rotate)
|
||||
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<ui8[]> pixelData;
|
||||
- size_t pixelDataSize;
|
||||
+ std::vector<ui8> pixelData;
|
||||
|
||||
// speed of animation, measure in frames per second
|
||||
float speed;
|
||||
Index: client/CMT.cpp
|
||||
===================================================================
|
||||
--- client/CMT.cpp (revision 3494)
|
||||
+++ client/CMT.cpp (working copy)
|
||||
@@ -194,7 +194,7 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
int wmain(int argc, wchar_t* argv[])
|
||||
-#elif defined(__APPLE__)
|
||||
+#elif defined(__APPLE__) || defined(ANDROID)
|
||||
int SDL_main(int argc, char *argv[])
|
||||
#else
|
||||
int main(int argc, char** argv)
|
||||
@@ -217,6 +217,13 @@
|
||||
}
|
||||
fclose(check);
|
||||
#endif
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "%s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
+
|
||||
+ // Fix crashing locale shit in Boost
|
||||
+ setenv( "LANG", "C", 1 );
|
||||
+ setenv( "LANGUAGE", "C", 1 );
|
||||
+ setenv( "LC_ALL", "C", 1 );
|
||||
+
|
||||
std::cout << "Starting... " << std::endl;
|
||||
po::options_description opts("Allowed options");
|
||||
opts.add_options()
|
||||
@@ -289,6 +296,7 @@
|
||||
|
||||
// Initialize logging based on settings
|
||||
logConfig.configure();
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
|
||||
// Some basic data validation to produce better error messages in cases of incorrect install
|
||||
auto testFile = [](std::string filename, std::string message) -> bool
|
||||
@@ -300,22 +308,31 @@
|
||||
return false;
|
||||
};
|
||||
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
if (!testFile("DATA/HELP.TXT", "Heroes III data") ||
|
||||
!testFile("MODS/VCMI/MOD.JSON", "VCMI mod") ||
|
||||
- !testFile("DATA/StackQueueBgBig.PCX", "VCMI data"))
|
||||
+ !testFile("DATA/StackQueueBgBig.PCX", "VCMI data"))
|
||||
+ {
|
||||
+ __android_log_print(ANDROID_LOG_ERROR, "VCMI", "Cannot find data files!");
|
||||
exit(1); // These are unrecoverable errors
|
||||
+ }
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
|
||||
// these two are optional + some installs have them on CD and not in data directory
|
||||
testFile("VIDEO/GOOD1A.SMK", "campaign movies");
|
||||
testFile("SOUNDS/G1A.WAV", "campaign music"); //technically not a music but voiced intro sounds
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
conf.init();
|
||||
logGlobal->infoStream() <<"Loading settings: "<<pomtime.getDiff();
|
||||
logGlobal->infoStream() << NAME;
|
||||
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
srand ( time(nullptr) );
|
||||
|
||||
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
const JsonNode& video = settings["video"];
|
||||
const JsonNode& res = video["screenRes"];
|
||||
|
||||
@@ -330,6 +347,7 @@
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
+ __android_log_print(ANDROID_LOG_DEBUG, "VCMI", "Trace: %s:%s:%d", __FUNCTION__, __FILE__, __LINE__);
|
||||
if(!gNoGUI)
|
||||
{
|
||||
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
|
||||
@@ -360,7 +378,8 @@
|
||||
|
||||
|
||||
//we can properly play intro only in the main thread, so we have to move loading to the separate thread
|
||||
- boost::thread loading(init);
|
||||
+ //boost::thread loading(init);
|
||||
+ init(); // boost::thread crashes when destroyed
|
||||
|
||||
if(!gNoGUI )
|
||||
{
|
||||
@@ -370,8 +389,8 @@
|
||||
}
|
||||
|
||||
CSDL_Ext::update(screen);
|
||||
- loading.join();
|
||||
- logGlobal->infoStream()<<"Initialization of VCMI (together): "<<total.getDiff();
|
||||
+ //loading.join();
|
||||
+ logGlobal->infoStream()<<"Initialization of VCMI (together): "<<total.getDiff();
|
||||
|
||||
if(!vm.count("battle"))
|
||||
{
|
||||
@@ -550,7 +569,7 @@
|
||||
std::ofstream file(outName + ".TXT");
|
||||
auto text = CResourceHandler::get()->load(filename)->readAll();
|
||||
|
||||
- file.write((char*)text.first.get(), text.second);
|
||||
+ file.write((char*)text.data(), text.size());
|
||||
}
|
||||
|
||||
std::cout << "\rExtracting done :)\n";
|
||||
@@ -689,7 +708,7 @@
|
||||
|
||||
boost::filesystem::create_directories(fullPath.substr(0, fullPath.find_last_of("/")));
|
||||
std::ofstream outFile(outPath + outName);
|
||||
- outFile.write((char*)data.first.get(), data.second);
|
||||
+ outFile.write((char*)data.data(), data.size());
|
||||
}
|
||||
else
|
||||
logGlobal->errorStream() << "File not found!";
|
||||
Index: client/CDefHandler.cpp
|
||||
===================================================================
|
||||
--- client/CDefHandler.cpp (revision 3494)
|
||||
+++ client/CDefHandler.cpp (working copy)
|
||||
@@ -364,11 +364,11 @@
|
||||
{
|
||||
ResourceID resID(std::string("SPRITES/") + defName, EResType::ANIMATION);
|
||||
|
||||
- auto data = CResourceHandler::get()->load(resID)->readAll().first;
|
||||
- if(!data)
|
||||
+ auto data = CResourceHandler::get()->load(resID)->readAll();
|
||||
+ if(!data.size())
|
||||
throw std::runtime_error("bad def name!");
|
||||
auto nh = new CDefHandler();
|
||||
- nh->openFromMemory(data.get(), defName);
|
||||
+ nh->openFromMemory(data.data(), defName);
|
||||
return nh;
|
||||
}
|
||||
CDefEssential * CDefHandler::giveDefEss(const std::string & defName)
|
||||
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();
|
||||
}
|
||||
Index: Global.h
|
||||
===================================================================
|
||||
--- Global.h (revision 3494)
|
||||
+++ Global.h (working copy)
|
||||
@@ -62,7 +62,35 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdio.h>
|
||||
-
|
||||
+#ifdef ANDROID
|
||||
+/*
|
||||
+#define move disable_move // It crashes with NDK r9 and GCC 4.8
|
||||
+#include <algorithm>
|
||||
+#undef move
|
||||
+namespace std
|
||||
+{
|
||||
+ template<typename _Tp>
|
||||
+ _Tp move(_Tp __t)
|
||||
+ {
|
||||
+ return __t; // Unoptimized version that does not crash
|
||||
+ }
|
||||
+
|
||||
+ template<class InputIt, class OutputIt>
|
||||
+ OutputIt move(InputIt first, InputIt last, OutputIt d_first)
|
||||
+ {
|
||||
+ while (first != last)
|
||||
+ {
|
||||
+ *d_first++ = *first++;
|
||||
+ }
|
||||
+ return d_first;
|
||||
+ }
|
||||
+}
|
||||
+*/
|
||||
+/*
|
||||
+#include <memory>
|
||||
+#define unique_ptr shared_ptr
|
||||
+*/
|
||||
+#endif
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
@@ -129,6 +157,8 @@
|
||||
using std::make_shared;
|
||||
//using namespace std::placeholders;
|
||||
namespace range = boost::range;
|
||||
+#define unique_ptr shared_ptr
|
||||
+#define make_unique make_shared
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
Reference in New Issue
Block a user