Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions GeneralsMD/Code/GameEngine/Include/GameClient/MapUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ class MapMetaData
AsciiString m_nameLookupTag;
Region3D m_extent;
Int m_numPlayers;
Bool m_isMultiplayer;

Bool m_isMultiplayer;
Bool m_isOfficial;
Bool m_doesExist; ///< Flag to indicate whether the map physically exists. Should be true.
UnsignedInt m_filesize;
UnsignedInt m_CRC;

Expand All @@ -89,10 +90,20 @@ class MapMetaData
AsciiString m_fileName;
};

// TheSuperHackers @performance xezon 02/11/2025 Simplifies and improves the implementation of MapCache
// to prevent expensive reoccurring redundant map cache reads.

class MapCache : public std::map<AsciiString, MapMetaData>
{
typedef std::set<AsciiString> MapNameSet;

public:
MapCache() {}
MapCache()
: m_hasTriedCreatingStandardMapCacheINI(FALSE)
, m_hasLoadedStandardMapCacheINI(FALSE)
, m_hasLoadedUserMapCacheINI(FALSE)
{}

void updateCache( void );

AsciiString getMapDir() const;
Expand All @@ -105,22 +116,27 @@ class MapCache : public std::map<AsciiString, MapMetaData>
void addShippingMap(AsciiString mapName) { mapName.toLower(); m_allowedMaps.insert(mapName); }

private:
Bool clearUnseenMaps( AsciiString dirName );
void loadStandardMaps(void);
Bool loadUserMaps(void); // returns true if we needed to (re)parse a map
// Bool addMap( AsciiString dirName, AsciiString fname, WinTimeStamp timestamp,
// UnsignedInt filesize, Bool isOfficial ); ///< returns true if it had to (re)parse the map
Bool addMap( AsciiString dirName, AsciiString fname, FileInfo *fileInfo, Bool isOfficial); ///< returns true if it had to (re)parse the map
void writeCacheINI( Bool userDir );

static const char * m_mapCacheName;
std::map<AsciiString, Bool> m_seen;

std::set<AsciiString> m_allowedMaps;
void prepareUnseenMaps(const AsciiString &mapDir);
Bool clearUnseenMaps(const AsciiString &mapDir);
void loadMapsFromMapCacheINI(const AsciiString &mapDir);
Bool loadMapsFromDisk(const AsciiString &mapDir, Bool isOfficial, Bool filterByAllowedMaps = FALSE); // returns true if we needed to (re)parse a map
Bool addMap(const AsciiString &mapDir, const AsciiString &fname, const AsciiString &lowerFname, FileInfo &fileInfo, Bool isOfficial); ///< returns true if it had to (re)parse the map
void writeCacheINI(const AsciiString &mapDir);

static const char *const m_mapCacheName;

MapNameSet m_allowedMaps;
Bool m_hasTriedCreatingStandardMapCacheINI;
Bool m_hasLoadedStandardMapCacheINI;
Bool m_hasLoadedUserMapCacheINI;
};

extern MapCache *TheMapCache;
extern TechAndSupplyImages TheSupplyAndTechImageLocations;

// TheSuperHackers @refactor xezon 28/11/2025 Refactors the map list population implementation
// by breaking it into smaller pieces to make it more maintainable.

Int populateMapListbox( GameWindow *listbox, Bool useSystemMaps, Bool isMultiplayer, AsciiString mapToSelect = AsciiString::TheEmptyString ); /// Read a list of maps from the run directory and fill in the listbox. Return the selected index
Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isMultiplayer, AsciiString mapToSelect = AsciiString::TheEmptyString ); /// Read a list of maps from the run directory and fill in the listbox. Return the selected index
Bool isValidMap( AsciiString mapName, Bool isMultiplayer ); /// Validate a map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void INI::parseMapCacheDefinition( INI* ini )

md.m_extent = mdr.m_extent;
md.m_isOfficial = mdr.m_isOfficial != 0;
md.m_doesExist = TRUE;
md.m_isMultiplayer = mdr.m_isMultiplayer != 0;
md.m_numPlayers = mdr.m_numPlayers;
md.m_filesize = mdr.m_filesize;
Expand Down
Loading
Loading