summaryrefslogtreecommitdiff
path: root/src/fileio.cpp
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-06-13 16:21:11 +0000
committertruelight <truelight@openttd.org>2007-06-13 16:21:11 +0000
commitb7443d800bddcdc7f3e5feaa0130df2445af4160 (patch)
tree214b44d6a6b5ee20d5f7eb13ed8d04475c94bd5f /src/fileio.cpp
parent4185c4afcdd58d49c33e64c6d53a7eb71d44bd1e (diff)
downloadopenttd-b7443d800bddcdc7f3e5feaa0130df2445af4160.tar.xz
(svn r10143) -Add: store the filename of the grfs opened and allow easy access to the name
-Codechange: store the SpriteID in the spritecache too -Add: add a PNG loader for graphical files -Documentation: added a document to explain the PNG format
Diffstat (limited to 'src/fileio.cpp')
-rw-r--r--src/fileio.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 171f6bfcd..f8173ab86 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -28,11 +28,12 @@ struct Fio {
byte *buffer, *buffer_end; ///< position pointer in local buffer and last valid byte of buffer
uint32 pos; ///< current (system) position in file
FILE *cur_fh; ///< current file handle
+ const char *filename; ///< current filename
FILE *handles[MAX_HANDLES]; ///< array of file handles we can have open
byte buffer_start[FIO_BUFFER_SIZE]; ///< local buffer when read from file
+ const char *filenames[MAX_HANDLES]; ///< array of filenames we (should) have open
#if defined(LIMITED_FDS)
uint open_handles; ///< current amount of open handles
- const char *filename[MAX_HANDLES]; ///< array of filenames we (should) have open
uint usage_count[MAX_HANDLES]; ///< count how many times this file has been opened
#endif /* LIMITED_FDS */
};
@@ -45,6 +46,11 @@ uint32 FioGetPos()
return _fio.pos + (_fio.buffer - _fio.buffer_start) - FIO_BUFFER_SIZE;
}
+const char *FioGetFilename()
+{
+ return _fio.filename;
+}
+
void FioSeekTo(uint32 pos, int mode)
{
if (mode == SEEK_CUR) pos += FioGetPos();
@@ -76,6 +82,7 @@ void FioSeekToFile(uint32 pos)
f = _fio.handles[pos >> 24];
assert(f != NULL);
_fio.cur_fh = f;
+ _fio.filename = _fio.filenames[pos >> 24];
FioSeekTo(GB(pos, 0, 24), SEEK_SET);
}
@@ -174,8 +181,8 @@ void FioOpenFile(int slot, const char *filename)
FioCloseFile(slot); // if file was opened before, close it
_fio.handles[slot] = f;
+ _fio.filenames[slot] = filename;
#if defined(LIMITED_FDS)
- _fio.filename[slot] = filename;
_fio.usage_count[slot] = 0;
_fio.open_handles++;
#endif /* LIMITED_FDS */