From e227bbaff02ebeb64f37301816c0965ae260a306 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Wed, 21 Apr 2021 18:40:37 +0200 Subject: [PATCH] Cleanup: remove the old FIO slot functions (cherry picked from commit fa6abe16463de8f252bac2322c9f84b6d02c9abc) --- src/fileio.cpp | 124 --------------------------------- src/fileio_func.h | 13 ---- src/fios.h | 16 ----- src/network/core/udp.cpp | 2 +- src/network/network_client.cpp | 2 +- src/newgrf.cpp | 13 +++- src/newgrf_config.h | 2 + src/newgrf_gui.cpp | 2 +- src/openttd.cpp | 3 - 9 files changed, 17 insertions(+), 160 deletions(-) diff --git a/src/fileio.cpp b/src/fileio.cpp index 47e7ff47fe..72f1809244 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -30,136 +30,12 @@ #include "safeguards.h" -static SpriteFile *_fio_current_file; ///< current file handle for the Fio functions -static std::array _fio_files; ///< array of random access files we can have open - /** Whether the working directory should be scanned. */ static bool _do_scan_working_directory = true; extern std::string _config_file; extern std::string _highscore_file; -/** - * Transition helper to get the SpriteFile associated with a given slot. - */ -SpriteFile *FioGetSpriteFile(int slot) -{ - return _fio_files[slot]; -} - -/** - * Get position in the current file. - * @return Position in the file. - */ -size_t FioGetPos() -{ - return _fio_current_file->GetPos(); -} - -/** - * Get the filename associated with a slot. - * @param slot Index of queried file. - * @return Name of the file. - */ -const char *FioGetFilename(uint slot) -{ - return _fio_current_file->GetSimplifiedFilename().c_str(); -} - -/** - * Seek in the current file. - * @param pos New position. - * @param mode Type of seek (\c SEEK_CUR means \a pos is relative to current position, \c SEEK_SET means \a pos is absolute). - */ -void FioSeekTo(size_t pos, int mode) -{ - _fio_current_file->SeekTo(pos, mode); -} - -/** - * Switch to a different file and seek to a position. - * @param slot Slot number of the new file. - * @param pos New absolute position in the new file. - */ -void FioSeekToFile(uint slot, size_t pos) -{ - SpriteFile *file = _fio_files[slot]; - assert(file != nullptr); - _fio_current_file = file; - _fio_current_file->SeekTo(pos, SEEK_SET); -} - -/** - * Read a byte from the file. - * @return Read byte. - */ -byte FioReadByte() -{ - return _fio_current_file->ReadByte(); -} - -/** - * Skip \a n bytes ahead in the file. - * @param n Number of bytes to skip reading. - */ -void FioSkipBytes(int n) -{ - return _fio_current_file->SkipBytes(n); -} - -/** - * Read a word (16 bits) from the file (in low endian format). - * @return Read word. - */ -uint16 FioReadWord() -{ - return _fio_current_file->ReadWord(); -} - -/** - * Read a double word (32 bits) from the file (in low endian format). - * @return Read word. - */ -uint32 FioReadDword() -{ - return _fio_current_file->ReadDword(); -} - -/** - * Read a block. - * @param ptr Destination buffer. - * @param size Number of bytes to read. - */ -void FioReadBlock(void *ptr, size_t size) -{ - _fio_current_file->ReadBlock(ptr, size); -} - -/** Close all slotted open files. */ -void FioCloseAll() -{ - for (int i = 0; i != lengthof(_fio_files); i++) { - delete _fio_files[i]; - _fio_files[i] = nullptr; - } -} - -/** - * Open a slotted file. - * @param slot Index to assign. - * @param filename Name of the file at the disk. - * @param subdir The sub directory to search this file in. - * @param palette_remap Whether palette remapping needs to take place. - */ -SpriteFile &FioOpenFile(int slot, const std::string &filename, Subdirectory subdir, bool palette_remap) -{ - SpriteFile *file = new SpriteFile(filename, subdir, palette_remap); - delete _fio_files[slot]; - _fio_files[slot] = file; - _fio_current_file = file; - return *file; -} - static const char * const _subdirs[] = { "", "save" PATHSEP, diff --git a/src/fileio_func.h b/src/fileio_func.h index f35543249b..f84acd3a46 100644 --- a/src/fileio_func.h +++ b/src/fileio_func.h @@ -15,19 +15,6 @@ #include #include -void FioSeekTo(size_t pos, int mode); -void FioSeekToFile(uint slot, size_t pos); -size_t FioGetPos(); -const char *FioGetFilename(uint slot); -byte FioReadByte(); -uint16 FioReadWord(); -uint32 FioReadDword(); -void FioCloseAll(); -class SpriteFile &FioOpenFile(int slot, const std::string &filename, Subdirectory subdir, bool palette_remap = false); -void FioReadBlock(void *ptr, size_t size); -void FioSkipBytes(int n); -class SpriteFile *FioGetSpriteFile(int slot); - void FioFCloseFile(FILE *f); FILE *FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr, std::string *output_filename = nullptr); bool FioCheckFileExists(const std::string &filename, Subdirectory subdir); diff --git a/src/fios.h b/src/fios.h index 525fddb990..46d6660823 100644 --- a/src/fios.h +++ b/src/fios.h @@ -88,22 +88,6 @@ struct LoadCheckData { extern LoadCheckData _load_check_data; - -enum FileSlots { - /** - * Slot used for the GRF scanning and such. - * This slot is used for all temporary accesses to files when scanning/testing files, - * and thus cannot be used for files, which are continuously accessed during a game. - */ - CONFIG_SLOT = 0, - /** First slot usable for (New)GRFs used during the game. */ - FIRST_GRF_SLOT = 2, - /** Maximum number of GRFs in single-player */ - MAX_NEWGRFS = 256, - /** Maximum number of slots. */ - MAX_FILE_SLOTS = 300, -}; - /** Deals with finding savegames */ struct FiosItem { FiosType type; diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp index 69631a3ada..ccb69538ba 100644 --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -422,7 +422,7 @@ void NetworkUDPSocketHandler::ReceiveNetworkGameInfoExtended(Packet *p, NetworkG uint num_grfs = p->Recv_uint32(); /* Broken/bad data. It cannot have that many NewGRFs. */ - if (num_grfs > MAX_NEWGRFS) return; + if (num_grfs > MAX_NON_STATIC_GRF_COUNT) return; for (i = 0; i < num_grfs; i++) { GRFConfig *c = new GRFConfig(); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 481e59ffb1..5fc12703dc 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -841,7 +841,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(P if (this->status != STATUS_JOIN) return NETWORK_RECV_STATUS_MALFORMED_PACKET; uint grf_count = p->Recv_uint32(); - if (grf_count > MAX_NEWGRFS) return NETWORK_RECV_STATUS_MALFORMED_PACKET; + if (grf_count > MAX_NON_STATIC_GRF_COUNT) return NETWORK_RECV_STATUS_MALFORMED_PACKET; NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY; /* Check all GRFs */ diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 882372ff4a..60ad30d474 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -81,7 +81,7 @@ static uint32 _ttdpatch_flags[8]; GRFLoadedFeatures _loaded_newgrf_features; static const uint MAX_SPRITEGROUP = UINT8_MAX; ///< Maximum GRF-local ID for a spritegroup. -static const uint MAX_GRF_COUNT = 256; ///< Maximum number of NewGRF files that could be loaded. +static const uint MAX_GRF_COUNT = 300; ///< Maximum number of NewGRF files that could be loaded. /** Base GRF ID for OpenTTD's base graphics GRFs. */ static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400); @@ -10378,6 +10378,7 @@ void LoadNewGRF(uint load_index, uint num_baseset) } uint num_grfs = 0; + uint num_non_static = 0; _cur.stage = stage; for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) { @@ -10393,6 +10394,16 @@ void LoadNewGRF(uint load_index, uint num_baseset) if (stage == GLS_LABELSCAN) InitNewGRFFile(c); + if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) { + if (num_non_static == MAX_NON_STATIC_GRF_COUNT) { + DEBUG(grf, 0, "'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->filename); + c->status = GCS_DISABLED; + c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED); + continue; + } + num_non_static++; + } + if (num_grfs >= MAX_GRF_COUNT) { DEBUG(grf, 0, "'%s' is not loaded as the maximum number of file slots has been reached", c->filename); c->status = GCS_DISABLED; diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 98d3a2f44b..63784b5dd5 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -18,6 +18,8 @@ #include "textfile_type.h" #include "newgrf_text.h" +static const uint MAX_NON_STATIC_GRF_COUNT = 256; + /** GRF config bit flags */ enum GCF_Flags { GCF_SYSTEM, ///< GRF file is an openttd-internal system grf diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 3ccc470de9..1aef047de5 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1516,7 +1516,7 @@ private: if (!HasBit((*list)->flags, GCF_STATIC)) count++; } if (entry == nullptr) entry = list; - if (count >= MAX_NEWGRFS) { + if (count >= MAX_NON_STATIC_GRF_COUNT) { ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO); return false; } diff --git a/src/openttd.cpp b/src/openttd.cpp index 6593e3ca5f..bdc8d26f9d 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -445,9 +445,6 @@ static void ShutdownGame() /* No NewGRFs were loaded when it was still bootstrapping. */ if (_game_mode != GM_BOOTSTRAP) ResetNewGRFData(); - /* Close all and any open filehandles */ - FioCloseAll(); - UninitFreeType(); ViewportMapClearTunnelCache();