diff options
author | truelight <truelight@openttd.org> | 2007-09-13 18:22:34 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2007-09-13 18:22:34 +0000 |
commit | 8cd9ab9b7eb684737321cb09a875e41b1632a609 (patch) | |
tree | 0593f8ece7aec74da5da2ff346539cd1698e6ec4 | |
parent | 1970e657a353cb5a86a4d1f101595039eadf6f29 (diff) | |
download | openttd-8cd9ab9b7eb684737321cb09a875e41b1632a609.tar.xz |
(svn r11095) -Codechange: don't abuse 'file_pos' by storing the file_slot in it too, but use a nice seperate variable for it
-Note: on a side-note, this allows files bigger than 16+ MiB, needed for tar-support
-rw-r--r-- | src/fileio.cpp | 13 | ||||
-rw-r--r-- | src/fileio.h | 2 | ||||
-rw-r--r-- | src/newgrf.cpp | 6 | ||||
-rw-r--r-- | src/sound.cpp | 9 | ||||
-rw-r--r-- | src/sound.h | 1 | ||||
-rw-r--r-- | src/spritecache.cpp | 17 | ||||
-rw-r--r-- | src/spriteloader/grf.cpp | 4 | ||||
-rw-r--r-- | src/spriteloader/grf.hpp | 2 | ||||
-rw-r--r-- | src/spriteloader/png.cpp | 2 | ||||
-rw-r--r-- | src/spriteloader/png.hpp | 2 | ||||
-rw-r--r-- | src/spriteloader/spriteloader.hpp | 2 |
11 files changed, 35 insertions, 25 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp index a8cf964a0..ad278e15f 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -74,18 +74,18 @@ static void FioRestoreFile(int slot) #endif /* LIMITED_FDS */ /* Seek to a file and a position */ -void FioSeekToFile(uint32 pos) +void FioSeekToFile(uint8 slot, uint32 pos) { FILE *f; #if defined(LIMITED_FDS) /* Make sure we have this file open */ - FioRestoreFile(pos >> 24); + FioRestoreFile(slot); #endif /* LIMITED_FDS */ - f = _fio.handles[pos >> 24]; + f = _fio.handles[slot]; assert(f != NULL); _fio.cur_fh = f; - _fio.filename = _fio.filenames[pos >> 24]; - FioSeekTo(GB(pos, 0, 24), SEEK_SET); + _fio.filename = _fio.filenames[slot]; + FioSeekTo(pos, SEEK_SET); } byte FioReadByte() @@ -180,6 +180,7 @@ void FioOpenFile(int slot, const char *filename) #endif /* LIMITED_FDS */ f = FioFOpenFile(filename); if (f == NULL) error("Cannot open file '%s'", filename); + uint32 pos = ftell(f); FioCloseFile(slot); // if file was opened before, close it _fio.handles[slot] = f; @@ -188,7 +189,7 @@ void FioOpenFile(int slot, const char *filename) _fio.usage_count[slot] = 0; _fio.open_handles++; #endif /* LIMITED_FDS */ - FioSeekToFile(slot << 24); + FioSeekToFile(slot, pos); } const char *_subdirs[NUM_SUBDIRS] = { diff --git a/src/fileio.h b/src/fileio.h index 8596dc123..a12c01e65 100644 --- a/src/fileio.h +++ b/src/fileio.h @@ -8,7 +8,7 @@ #include "helpers.hpp" void FioSeekTo(uint32 pos, int mode); -void FioSeekToFile(uint32 pos); +void FioSeekToFile(uint8 slot, uint32 pos); uint32 FioGetPos(); const char *FioGetFilename(); byte FioReadByte(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index bb7dbe3ac..25066d2f3 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4506,9 +4506,9 @@ static void LoadGRFSound(byte *buf, int len) break; case 'atad': // 'data' - se->file_size = size; - se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1; - se->file_offset |= _file_index << 24; + se->file_size = size; + se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1; + se->file_slot = _file_index; /* Set default volume and priority */ se->volume = 0x80; diff --git a/src/sound.cpp b/src/sound.cpp index 249ff73e3..a63e9564f 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -45,6 +45,7 @@ static void OpenBankFile(const char *filename) FioSeekTo(0, SEEK_SET); for (i = 0; i != count; i++) { + fe[i].file_slot = SOUND_SLOT; fe[i].file_offset = FioReadDword(); fe[i].file_size = FioReadDword(); } @@ -75,7 +76,8 @@ static void OpenBankFile(const char *filename) FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR); } else if (tag == 'atad') { fe->file_size = size; - fe->file_offset = FioGetPos() | (SOUND_SLOT << 24); + fe->file_slot = SOUND_SLOT; + fe->file_offset = FioGetPos(); break; } else { fe->file_size = 0; @@ -91,7 +93,8 @@ static void OpenBankFile(const char *filename) fe->channels = 1; fe->rate = 11025; fe->bits_per_sample = 8; - fe->file_offset = FioGetPos() | (SOUND_SLOT << 24); + fe->file_slot = SOUND_SLOT; + fe->file_offset = FioGetPos(); } } } @@ -114,7 +117,7 @@ static bool SetBankSource(MixerChannel *mc, uint bank) int8 *mem = MallocT<int8>(fe->file_size); if (mem == NULL) return false; - FioSeekToFile(fe->file_offset); + FioSeekToFile(fe->file_slot, fe->file_offset); FioReadBlock(mem, fe->file_size); for (i = 0; i != fe->file_size; i++) diff --git a/src/sound.h b/src/sound.h index ff5c130d9..2b3355a9e 100644 --- a/src/sound.h +++ b/src/sound.h @@ -21,6 +21,7 @@ struct MusicFileSettings { VARDEF MusicFileSettings msf; struct FileEntry { + uint8 file_slot; uint32 file_offset; uint32 file_size; uint16 rate; diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 710bca443..fb8e684d3 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -25,6 +25,7 @@ uint _sprite_cache_size = 4; struct SpriteCache { void *ptr; + uint8 file_slot; uint32 file_pos; int16 lru; uint32 id; @@ -127,6 +128,7 @@ void* AllocSprite(size_t); static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) { + uint8 file_slot = sc->file_slot; uint32 file_pos = sc->file_pos; DEBUG(sprite, 9, "Load sprite %d", id); @@ -136,7 +138,8 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) /* SPR_IMG_QUERY is a BIG FAT RED ? */ id = SPR_IMG_QUERY; - file_pos = GetSpriteCache(SPR_IMG_QUERY)->file_pos; + file_slot = GetSpriteCache(SPR_IMG_QUERY)->file_slot; + file_pos = GetSpriteCache(SPR_IMG_QUERY)->file_pos; } if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) { @@ -145,7 +148,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) SpriteLoaderPNG sprite_loader; SpriteLoader::Sprite sprite; - if (sprite_loader.LoadSprite(&sprite, sc->grf_name, sc->id)) { + if (sprite_loader.LoadSprite(&sprite, sc->grf_name, 0, sc->id)) { sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite); free(sprite.data); @@ -161,7 +164,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) #endif /* WITH_PNG */ } - FioSeekToFile(file_pos); + FioSeekToFile(file_slot, file_pos); /* Read the size and type */ int num = FioReadWord(); @@ -232,7 +235,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) SpriteLoaderGrf sprite_loader; SpriteLoader::Sprite sprite; - if (!sprite_loader.LoadSprite(&sprite, sc->grf_name, file_pos)) return NULL; + if (!sprite_loader.LoadSprite(&sprite, sc->grf_name, file_slot, file_pos)) return NULL; if (id == 142) sprite.height = 10; // Compensate for a TTD bug sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite); free(sprite.data); @@ -241,10 +244,10 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) } -bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id) +bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id) { SpriteCache *sc; - uint32 file_pos = FioGetPos() | (file_index << 24); + uint32 file_pos = FioGetPos(); if (!ReadSpriteHeaderSkipData()) return false; @@ -253,6 +256,7 @@ bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id) } sc = AllocateSpriteCache(load_index); + sc->file_slot = file_slot; sc->file_pos = file_pos; sc->ptr = NULL; sc->lru = 0; @@ -280,6 +284,7 @@ void DupSprite(SpriteID old_spr, SpriteID new_spr) SpriteCache *scold = GetSpriteCache(old_spr); SpriteCache *scnew = AllocateSpriteCache(new_spr); + scnew->file_slot = scold->file_slot; scnew->file_pos = scold->file_pos; scnew->ptr = NULL; scnew->id = scold->id; diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index 79095e4db..e41732b50 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -8,10 +8,10 @@ #include "../debug.h" #include "grf.hpp" -bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint32 file_pos) +bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos) { /* Open the right file and go to the correct position */ - FioSeekToFile(file_pos); + FioSeekToFile(file_slot, file_pos); /* Read the size and type */ int num = FioReadWord(); diff --git a/src/spriteloader/grf.hpp b/src/spriteloader/grf.hpp index e6e67be15..fe9405339 100644 --- a/src/spriteloader/grf.hpp +++ b/src/spriteloader/grf.hpp @@ -12,7 +12,7 @@ public: /** * Load a sprite from the disk and return a sprite struct which is the same for all loaders. */ - bool LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint32 file_pos); + bool LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos); }; #endif /* SPRITELOADER_GRF_HPP */ diff --git a/src/spriteloader/png.cpp b/src/spriteloader/png.cpp index 6048c6fdd..2bb7227d5 100644 --- a/src/spriteloader/png.cpp +++ b/src/spriteloader/png.cpp @@ -180,7 +180,7 @@ static bool LoadPNG(SpriteLoader::Sprite *sprite, const char *filename, uint32 i return true; } -bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint32 file_pos) +bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos) { if (!LoadPNG(sprite, filename, file_pos, false)) return false; if (!LoadPNG(sprite, filename, file_pos, true)) return false; diff --git a/src/spriteloader/png.hpp b/src/spriteloader/png.hpp index 737501268..eb3719180 100644 --- a/src/spriteloader/png.hpp +++ b/src/spriteloader/png.hpp @@ -12,7 +12,7 @@ public: /** * Load a sprite from the disk and return a sprite struct which is the same for all loaders. */ - bool LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint32 file_pos); + bool LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos); }; #endif /* SPRITELOADER_PNG_HPP */ diff --git a/src/spriteloader/spriteloader.hpp b/src/spriteloader/spriteloader.hpp index fe0e6ab8e..47d1b7d40 100644 --- a/src/spriteloader/spriteloader.hpp +++ b/src/spriteloader/spriteloader.hpp @@ -26,7 +26,7 @@ public: /** * Load a sprite from the disk and return a sprite struct which is the same for all loaders. */ - virtual bool LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint32 file_pos) = 0; + virtual bool LoadSprite(SpriteLoader::Sprite *sprite, const char *filename, uint8 file_slot, uint32 file_pos) = 0; virtual ~SpriteLoader() { } }; |