NewGRF: Use per-GRF text ID map in GetGRFStringID

This commit is contained in:
Jonathan G Rennison
2022-06-06 19:34:22 +01:00
parent 7a61b5d820
commit c342b4219b
2 changed files with 10 additions and 6 deletions

View File

@@ -12461,9 +12461,6 @@ void LoadNewGRF(uint load_index, uint num_baseset)
/* Pseudo sprite processing is finished; free temporary stuff */
_cur.ClearDataForNextFile();
for (GRFFile * const file : _grf_files) {
file->string_map.clear();
}
_callback_result_cache.clear();
/* Call any functions that should be run after GRFs have been loaded. */

View File

@@ -614,11 +614,18 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
*/
StringID GetGRFStringID(uint32 grfid, StringID stringid)
{
extern GRFFile *GetFileByGRFIDExpectCurrent(uint32 grfid);
GRFFile *grf = GetFileByGRFIDExpectCurrent(grfid);
if (unlikely(grf == nullptr)) {
for (uint id = 0; id < _num_grf_texts; id++) {
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
return MakeStringID(TEXT_TAB_NEWGRF_START, id);
}
}
} else {
auto iter = grf->string_map.find(stringid);
if (iter != grf->string_map.end()) return MakeStringID(TEXT_TAB_NEWGRF_START, iter->second);
}
return STR_UNDEFINED;
}