mirror of https://github.com/OpenTTD/OpenTTD.git
(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:
parent
1970e657a3
commit
8cd9ab9b7e
|
@ -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] = {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -21,6 +21,7 @@ struct MusicFileSettings {
|
|||
VARDEF MusicFileSettings msf;
|
||||
|
||||
struct FileEntry {
|
||||
uint8 file_slot;
|
||||
uint32 file_offset;
|
||||
uint32 file_size;
|
||||
uint16 rate;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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() { }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue