Mercurial > hg > openttd
changeset 7570:afe1137d97d8 draft
(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
author | truelight <truelight@openttd.org> |
---|---|
date | Thu, 13 Sep 2007 18:22:34 +0000 |
parents | 326049261489 |
children | b20b488ca748 |
files | src/fileio.cpp src/fileio.h src/newgrf.cpp src/sound.cpp src/sound.h src/spritecache.cpp src/spriteloader/grf.cpp src/spriteloader/grf.hpp src/spriteloader/png.cpp src/spriteloader/png.hpp src/spriteloader/spriteloader.hpp |
diffstat | 11 files changed, 35 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -74,18 +74,18 @@ #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 @@ #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 @@ _fio.usage_count[slot] = 0; _fio.open_handles++; #endif /* LIMITED_FDS */ - FioSeekToFile(slot << 24); + FioSeekToFile(slot, pos); } const char *_subdirs[NUM_SUBDIRS] = {
--- 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();
--- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4506,9 +4506,9 @@ 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;
--- a/src/sound.cpp +++ b/src/sound.cpp @@ -45,6 +45,7 @@ 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 @@ 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 @@ 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 @@ 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++)
--- a/src/sound.h +++ b/src/sound.h @@ -21,6 +21,7 @@ VARDEF MusicFileSettings msf; struct FileEntry { + uint8 file_slot; uint32 file_offset; uint32 file_size; uint16 rate;
--- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -25,6 +25,7 @@ struct SpriteCache { void *ptr; + uint8 file_slot; uint32 file_pos; int16 lru; uint32 id; @@ -127,6 +128,7 @@ 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 @@ /* 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 @@ 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 @@ #endif /* WITH_PNG */ } - FioSeekToFile(file_pos); + FioSeekToFile(file_slot, file_pos); /* Read the size and type */ int num = FioReadWord(); @@ -232,7 +235,7 @@ 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 @@ } -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 @@ } sc = AllocateSpriteCache(load_index); + sc->file_slot = file_slot; sc->file_pos = file_pos; sc->ptr = NULL; sc->lru = 0; @@ -280,6 +284,7 @@ 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;
--- 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();
--- a/src/spriteloader/grf.hpp +++ b/src/spriteloader/grf.hpp @@ -12,7 +12,7 @@ /** * 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 */
--- a/src/spriteloader/png.cpp +++ b/src/spriteloader/png.cpp @@ -180,7 +180,7 @@ 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;
--- a/src/spriteloader/png.hpp +++ b/src/spriteloader/png.hpp @@ -12,7 +12,7 @@ /** * 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 */
--- a/src/spriteloader/spriteloader.hpp +++ b/src/spriteloader/spriteloader.hpp @@ -26,7 +26,7 @@ /** * 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() { } };