(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
This commit is contained in:
truelight 2007-09-13 18:22:34 +00:00
parent 1970e657a3
commit 8cd9ab9b7e
11 changed files with 35 additions and 25 deletions

View File

@ -74,18 +74,18 @@ static void FioRestoreFile(int slot)
#endif /* LIMITED_FDS */ #endif /* LIMITED_FDS */
/* Seek to a file and a position */ /* Seek to a file and a position */
void FioSeekToFile(uint32 pos) void FioSeekToFile(uint8 slot, uint32 pos)
{ {
FILE *f; FILE *f;
#if defined(LIMITED_FDS) #if defined(LIMITED_FDS)
/* Make sure we have this file open */ /* Make sure we have this file open */
FioRestoreFile(pos >> 24); FioRestoreFile(slot);
#endif /* LIMITED_FDS */ #endif /* LIMITED_FDS */
f = _fio.handles[pos >> 24]; f = _fio.handles[slot];
assert(f != NULL); assert(f != NULL);
_fio.cur_fh = f; _fio.cur_fh = f;
_fio.filename = _fio.filenames[pos >> 24]; _fio.filename = _fio.filenames[slot];
FioSeekTo(GB(pos, 0, 24), SEEK_SET); FioSeekTo(pos, SEEK_SET);
} }
byte FioReadByte() byte FioReadByte()
@ -180,6 +180,7 @@ void FioOpenFile(int slot, const char *filename)
#endif /* LIMITED_FDS */ #endif /* LIMITED_FDS */
f = FioFOpenFile(filename); f = FioFOpenFile(filename);
if (f == NULL) error("Cannot open file '%s'", filename); if (f == NULL) error("Cannot open file '%s'", filename);
uint32 pos = ftell(f);
FioCloseFile(slot); // if file was opened before, close it FioCloseFile(slot); // if file was opened before, close it
_fio.handles[slot] = f; _fio.handles[slot] = f;
@ -188,7 +189,7 @@ void FioOpenFile(int slot, const char *filename)
_fio.usage_count[slot] = 0; _fio.usage_count[slot] = 0;
_fio.open_handles++; _fio.open_handles++;
#endif /* LIMITED_FDS */ #endif /* LIMITED_FDS */
FioSeekToFile(slot << 24); FioSeekToFile(slot, pos);
} }
const char *_subdirs[NUM_SUBDIRS] = { const char *_subdirs[NUM_SUBDIRS] = {

View File

@ -8,7 +8,7 @@
#include "helpers.hpp" #include "helpers.hpp"
void FioSeekTo(uint32 pos, int mode); void FioSeekTo(uint32 pos, int mode);
void FioSeekToFile(uint32 pos); void FioSeekToFile(uint8 slot, uint32 pos);
uint32 FioGetPos(); uint32 FioGetPos();
const char *FioGetFilename(); const char *FioGetFilename();
byte FioReadByte(); byte FioReadByte();

View File

@ -4506,9 +4506,9 @@ static void LoadGRFSound(byte *buf, int len)
break; break;
case 'atad': // 'data' case 'atad': // 'data'
se->file_size = size; se->file_size = size;
se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1; se->file_offset = FioGetPos() - (len - (buf - buf_start)) + 1;
se->file_offset |= _file_index << 24; se->file_slot = _file_index;
/* Set default volume and priority */ /* Set default volume and priority */
se->volume = 0x80; se->volume = 0x80;

View File

@ -45,6 +45,7 @@ static void OpenBankFile(const char *filename)
FioSeekTo(0, SEEK_SET); FioSeekTo(0, SEEK_SET);
for (i = 0; i != count; i++) { for (i = 0; i != count; i++) {
fe[i].file_slot = SOUND_SLOT;
fe[i].file_offset = FioReadDword(); fe[i].file_offset = FioReadDword();
fe[i].file_size = 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); FioSeekTo(size - (2 + 2 + 4 + 4 + 2 + 1), SEEK_CUR);
} else if (tag == 'atad') { } else if (tag == 'atad') {
fe->file_size = size; fe->file_size = size;
fe->file_offset = FioGetPos() | (SOUND_SLOT << 24); fe->file_slot = SOUND_SLOT;
fe->file_offset = FioGetPos();
break; break;
} else { } else {
fe->file_size = 0; fe->file_size = 0;
@ -91,7 +93,8 @@ static void OpenBankFile(const char *filename)
fe->channels = 1; fe->channels = 1;
fe->rate = 11025; fe->rate = 11025;
fe->bits_per_sample = 8; 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); int8 *mem = MallocT<int8>(fe->file_size);
if (mem == NULL) return false; if (mem == NULL) return false;
FioSeekToFile(fe->file_offset); FioSeekToFile(fe->file_slot, fe->file_offset);
FioReadBlock(mem, fe->file_size); FioReadBlock(mem, fe->file_size);
for (i = 0; i != fe->file_size; i++) for (i = 0; i != fe->file_size; i++)

View File

@ -21,6 +21,7 @@ struct MusicFileSettings {
VARDEF MusicFileSettings msf; VARDEF MusicFileSettings msf;
struct FileEntry { struct FileEntry {
uint8 file_slot;
uint32 file_offset; uint32 file_offset;
uint32 file_size; uint32 file_size;
uint16 rate; uint16 rate;

View File

@ -25,6 +25,7 @@ uint _sprite_cache_size = 4;
struct SpriteCache { struct SpriteCache {
void *ptr; void *ptr;
uint8 file_slot;
uint32 file_pos; uint32 file_pos;
int16 lru; int16 lru;
uint32 id; uint32 id;
@ -127,6 +128,7 @@ void* AllocSprite(size_t);
static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite) static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite)
{ {
uint8 file_slot = sc->file_slot;
uint32 file_pos = sc->file_pos; uint32 file_pos = sc->file_pos;
DEBUG(sprite, 9, "Load sprite %d", id); 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 ? */ /* SPR_IMG_QUERY is a BIG FAT RED ? */
id = SPR_IMG_QUERY; 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) { if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) {
@ -145,7 +148,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite)
SpriteLoaderPNG sprite_loader; SpriteLoaderPNG sprite_loader;
SpriteLoader::Sprite sprite; 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); sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
free(sprite.data); free(sprite.data);
@ -161,7 +164,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite)
#endif /* WITH_PNG */ #endif /* WITH_PNG */
} }
FioSeekToFile(file_pos); FioSeekToFile(file_slot, file_pos);
/* Read the size and type */ /* Read the size and type */
int num = FioReadWord(); int num = FioReadWord();
@ -232,7 +235,7 @@ static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite)
SpriteLoaderGrf sprite_loader; SpriteLoaderGrf sprite_loader;
SpriteLoader::Sprite sprite; 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 if (id == 142) sprite.height = 10; // Compensate for a TTD bug
sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite); sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
free(sprite.data); 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; SpriteCache *sc;
uint32 file_pos = FioGetPos() | (file_index << 24); uint32 file_pos = FioGetPos();
if (!ReadSpriteHeaderSkipData()) return false; 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 = AllocateSpriteCache(load_index);
sc->file_slot = file_slot;
sc->file_pos = file_pos; sc->file_pos = file_pos;
sc->ptr = NULL; sc->ptr = NULL;
sc->lru = 0; sc->lru = 0;
@ -280,6 +284,7 @@ void DupSprite(SpriteID old_spr, SpriteID new_spr)
SpriteCache *scold = GetSpriteCache(old_spr); SpriteCache *scold = GetSpriteCache(old_spr);
SpriteCache *scnew = AllocateSpriteCache(new_spr); SpriteCache *scnew = AllocateSpriteCache(new_spr);
scnew->file_slot = scold->file_slot;
scnew->file_pos = scold->file_pos; scnew->file_pos = scold->file_pos;
scnew->ptr = NULL; scnew->ptr = NULL;
scnew->id = scold->id; scnew->id = scold->id;

View File

@ -8,10 +8,10 @@
#include "../debug.h" #include "../debug.h"
#include "grf.hpp" #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 */ /* Open the right file and go to the correct position */
FioSeekToFile(file_pos); FioSeekToFile(file_slot, file_pos);
/* Read the size and type */ /* Read the size and type */
int num = FioReadWord(); int num = FioReadWord();

View File

@ -12,7 +12,7 @@ public:
/** /**
* Load a sprite from the disk and return a sprite struct which is the same for all loaders. * 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 */ #endif /* SPRITELOADER_GRF_HPP */

View File

@ -180,7 +180,7 @@ static bool LoadPNG(SpriteLoader::Sprite *sprite, const char *filename, uint32 i
return true; 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, false)) return false;
if (!LoadPNG(sprite, filename, file_pos, true)) return false; if (!LoadPNG(sprite, filename, file_pos, true)) return false;

View File

@ -12,7 +12,7 @@ public:
/** /**
* Load a sprite from the disk and return a sprite struct which is the same for all loaders. * 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 */ #endif /* SPRITELOADER_PNG_HPP */

View File

@ -26,7 +26,7 @@ public:
/** /**
* Load a sprite from the disk and return a sprite struct which is the same for all loaders. * 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() { } virtual ~SpriteLoader() { }
}; };