Skip to content

Commit

Permalink
Fix for reservedSpace (mod size metadata)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeridianOXC committed Jan 9, 2017
1 parent 89a7e90 commit 258581e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Engine/ModInfo.cpp
Expand Up @@ -83,6 +83,10 @@ const std::string &ModInfo::getId() const { return _id; }
const std::string &ModInfo::getMaster() const { return _master; }
bool ModInfo::isMaster() const { return _isMaster; }
int ModInfo::getReservedSpace() const { return _reservedSpace; }
void ModInfo::setReservedSpace(int reservedSpace)
{
_reservedSpace = reservedSpace;
}

const std::vector<std::string> &ModInfo::getExternalResourceDirs() const { return _externalResourceDirs; }
}
2 changes: 2 additions & 0 deletions src/Engine/ModInfo.h
Expand Up @@ -60,6 +60,8 @@ class ModInfo
bool isMaster() const;
/// Gets size of mod, bigger mod reserve more values in common colections/surfacesets.
int getReservedSpace() const;
/// Sets mod size (DO NOT use this method outside Options::updateReservedSpace()).
void setReservedSpace(int reservedSpace);
/// Gets the list of external resource dirs to load for this mod.
const std::vector<std::string> &getExternalResourceDirs() const;
};
Expand Down
46 changes: 46 additions & 0 deletions src/Engine/Options.cpp
Expand Up @@ -671,6 +671,7 @@ void updateMods()
}
}

updateReservedSpace();
mapResources();
userSplitMasters();
}
Expand Down Expand Up @@ -744,6 +745,51 @@ static void _loadMod(const ModInfo &modInfo, std::set<std::string> circDepCheck)
}
}

void updateReservedSpace()
{
Log(LOG_VERBOSE) << "Updating reservedSpace for master mods if necessary...";

std::string curMaster = getActiveMaster();
Log(LOG_VERBOSE) << "curMaster = " << curMaster;

int maxSize = 1;
for (std::vector< std::pair<std::string, bool> >::reverse_iterator i = mods.rbegin(); i != mods.rend(); ++i)
{
if (!i->second)
{
Log(LOG_VERBOSE) << "skipping inactive mod: " << i->first;
continue;
}

const ModInfo &modInfo = _modInfos.find(i->first)->second;
if (!modInfo.isMaster() && !modInfo.getMaster().empty() && modInfo.getMaster() != curMaster)
{
Log(LOG_VERBOSE) << "skipping mod for non-current master: " << i->first << "(" << modInfo.getMaster() << " != " << curMaster << ")";
continue;
}

if (modInfo.getReservedSpace() > maxSize)
{
maxSize = modInfo.getReservedSpace();
}
}

if (maxSize > 1)
{
// Small hack: update ALL masters, not only active master!
// this is because, there can be a hierarchy of multiple masters (e.g. xcom1 master > piratez master > some piratez mod)
// and the one that needs to be updated is actually the "root", i.e. xcom1 master
for (std::map<std::string, ModInfo>::iterator i = _modInfos.begin(); i != _modInfos.end(); ++i)
{
if (i->second.isMaster())
{
i->second.setReservedSpace(maxSize);
Log(LOG_INFO) << "reservedSpace for: " << i->first << " updated to: " << i->second.getReservedSpace();
}
}
}
}

void mapResources()
{
Log(LOG_INFO) << "Mapping resource files...";
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/Options.h
Expand Up @@ -101,6 +101,8 @@ namespace Options
void switchDisplay();
/// returns the id of the active master mod
std::string getActiveMaster();
/// Updates the reservedSpace for master mods if necessary
void updateReservedSpace();
/// Maps resources in active mods to the virtual file system
void mapResources();
/// Gets the map of mod ids to mod infos
Expand Down

0 comments on commit 258581e

Please sign in to comment.