mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-17 01:12:39 +01:00
Codechange: Store loaded GRFFiles in vector directly. (#13940)
Removes pointer management.
This commit is contained in:
@@ -1215,7 +1215,7 @@ DEF_CONSOLE_CMD(ConReturn)
|
||||
* default console commands
|
||||
******************************/
|
||||
extern bool CloseConsoleLogIfActive();
|
||||
extern const std::vector<GRFFile *> &GetAllGRFFiles();
|
||||
extern std::span<const GRFFile> GetAllGRFFiles();
|
||||
extern void ConPrintFramerate(); // framerate_gui.cpp
|
||||
extern void ShowFramerateWindow();
|
||||
|
||||
@@ -2447,19 +2447,19 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<GRFFile *> &files = GetAllGRFFiles();
|
||||
std::span<const GRFFile> files = GetAllGRFFiles();
|
||||
|
||||
/* "list" sub-command */
|
||||
if (argc == 1 || StrStartsWithIgnoreCase(argv[1], "lis")) {
|
||||
IConsolePrint(CC_INFO, "Loaded GRF files:");
|
||||
int i = 1;
|
||||
for (GRFFile *grf : files) {
|
||||
auto profiler = std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile);
|
||||
for (const auto &grf : files) {
|
||||
auto profiler = std::ranges::find(_newgrf_profilers, &grf, &NewGRFProfiler::grffile);
|
||||
bool selected = profiler != _newgrf_profilers.end();
|
||||
bool active = selected && profiler->active;
|
||||
TextColour tc = active ? TC_LIGHT_BLUE : selected ? TC_GREEN : CC_INFO;
|
||||
const char *statustext = active ? " (active)" : selected ? " (selected)" : "";
|
||||
IConsolePrint(tc, "{}: [{:08X}] {}{}", i, std::byteswap(grf->grfid), grf->filename, statustext);
|
||||
IConsolePrint(tc, "{}: [{:08X}] {}{}", i, std::byteswap(grf.grfid), grf.filename, statustext);
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
@@ -2473,7 +2473,7 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
|
||||
IConsolePrint(CC_WARNING, "GRF number {} out of range, not added.", grfnum);
|
||||
continue;
|
||||
}
|
||||
GRFFile *grf = files[grfnum - 1];
|
||||
const GRFFile *grf = &files[grfnum - 1];
|
||||
if (std::any_of(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; })) {
|
||||
IConsolePrint(CC_WARNING, "GRF number {} [{:08X}] is already selected for profiling.", grfnum, std::byteswap(grf->grfid));
|
||||
continue;
|
||||
@@ -2495,7 +2495,7 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
|
||||
IConsolePrint(CC_WARNING, "GRF number {} out of range, not removing.", grfnum);
|
||||
continue;
|
||||
}
|
||||
GRFFile *grf = files[grfnum - 1];
|
||||
const GRFFile *grf = &files[grfnum - 1];
|
||||
_newgrf_profilers.erase(std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile));
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user