Cleanup: remove the old FIO slot functions
(cherry picked from commit fa6abe1646
)
This commit is contained in:

committed by
Jonathan G Rennison

parent
eecf7c8525
commit
e227bbaff0
124
src/fileio.cpp
124
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<SpriteFile *, MAX_FILE_SLOTS> _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,
|
||||
|
@@ -15,19 +15,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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);
|
||||
|
16
src/fios.h
16
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;
|
||||
|
@@ -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();
|
||||
|
@@ -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 */
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user