Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

perf(gameclient): read each MapCache.ini once instead of once per menu

Olcay Seygan3a037132ea2f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6c0f1edb2..22f56a3aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -404,6 +404,12 @@ position wrapped around to a negative number: the view snapped somewhere it shou
scrolling back up stopped responding. Any long list in the game -- replays, maps, a busy chat room
-- now scrolls the whole way, however many entries it holds.
+Opening one of those lists was its own wait. Every menu that shows maps rebuilt the entire map
+catalogue from scratch each time it appeared, and again every time you switched between the
+shipped maps and your own -- re-reading the catalogue of hundreds of maps out of the game's
+archives over and over. It is read once now, and again only when one of your own maps actually changed on
+disk. The map, skirmish and replay menus open without the pause.
+
## Placing a building, then changing your mind
Right-clicking to cancel a building you were about to place used to also deselect the builder, so
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/MapUtil.h b/GeneralsMD/Code/GameEngine/Include/GameClient/MapUtil.h
index 0561d84f7..28f7740a3 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/MapUtil.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/MapUtil.h
@@ -95,7 +95,10 @@ public:
class MapCache : public std::map<AsciiString, MapMetaData>
{
public:
- MapCache() {}
+ MapCache()
+ : m_doLoadStandardMapCacheINI(TRUE)
+ , m_doLoadUserMapCacheINI(TRUE)
+ {}
void updateCache( void );
AsciiString getMapDir() const;
@@ -117,6 +120,9 @@ private:
void writeCacheINI( Bool userDir );
static const char * m_mapCacheName;
+ // both MapCache.ini files only need reading once a run - see updateCache
+ Bool m_doLoadStandardMapCacheINI;
+ Bool m_doLoadUserMapCacheINI;
std::map<AsciiString, Bool> m_seen;
std::set<AsciiString> m_allowedMaps;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp
index 57ca8d33c..6f68f0020 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp
@@ -466,11 +466,22 @@ void MapCache::updateCache( void )
TheFileSystem->createDirectory(getUserMapDir());
- if (loadUserMaps())
+ // this runs again every time a map list is populated: every menu that shows maps calls it on
+ // open, and again on each toggle between the shipped and the user map directory. Re-parsing
+ // the shipped MapCache.ini out of the archive on each of those is what made those menus hitch.
+ const Bool userMapsChanged = loadUserMaps();
+ if (userMapsChanged)
{
writeCacheINI( TRUE );
}
- loadStandardMaps(); // we shall overwrite info from matching user maps to prevent munkees from getting rowdy :)
+ // we shall overwrite info from matching user maps to prevent munkees from getting rowdy :)
+ // the shipped cache cannot change while the game runs, so read it once - and again whenever a
+ // user map was (re)parsed, since that pass is what could have overwritten an official entry.
+ if (m_doLoadStandardMapCacheINI || userMapsChanged)
+ {
+ loadStandardMaps();
+ m_doLoadStandardMapCacheINI = FALSE;
+ }
#if defined(_DEBUG) || defined(_INTERNAL)
if (TheLocalFileSystem->doesFileExist(getMapDir().str()))
{
@@ -535,16 +546,23 @@ Bool MapCache::loadUserMaps()
{
mapDir = getUserMapDir();
- INI ini;
- AsciiString fname;
- fname.format("%s\\%s", mapDir.str(), m_mapCacheName);
- File *fp = TheFileSystem->openFile(fname.str(), File::READ);
- if (fp)
+ // once this has been read, what is in memory is a superset of it: writeCacheINI writes the
+ // file back out of memory, and every later pass re-parses whatever changed on disk anyway.
+ if (m_doLoadUserMapCacheINI)
{
- fp->close();
- ini.load( fname, INI_LOAD_OVERWRITE, NULL );
- }
+ m_doLoadUserMapCacheINI = FALSE;
+ INI ini;
+ AsciiString fname;
+ fname.format("%s\\%s", mapDir.str(), m_mapCacheName);
+ File *fp = TheFileSystem->openFile(fname.str(), File::READ);
+ if (fp)
+ {
+ fp->close();
+ ini.load( fname, INI_LOAD_OVERWRITE, NULL );
+ }
+
+ }
}
// mark all as unseen