1
0
Fork 0

(svn r1859) Miscellaneous style changes

release/0.4.5
tron 2005-02-11 14:33:43 +00:00
parent 5c946cdbd8
commit f03b8859ed
1 changed files with 91 additions and 98 deletions

View File

@ -94,7 +94,6 @@ static void CompactSpriteCache(void);
static void ReadSpriteHeaderSkipData(int num, int load_index) static void ReadSpriteHeaderSkipData(int num, int load_index)
{ {
byte type; byte type;
int8 i;
int deaf = 0; int deaf = 0;
if (_skip_sprites) { if (_skip_sprites) {
@ -133,11 +132,9 @@ static void ReadSpriteHeaderSkipData(int num, int load_index)
if (type & 2) { if (type & 2) {
FioSkipBytes(num); FioSkipBytes(num);
return; } else {
} while (num > 0) {
int8 i = FioReadByte();
while (num) {
i = FioReadByte();
if (i >= 0) { if (i >= 0) {
num -= i; num -= i;
FioSkipBytes(i); FioSkipBytes(i);
@ -148,14 +145,12 @@ static void ReadSpriteHeaderSkipData(int num, int load_index)
} }
} }
} }
}
static void ReadSprite(SpriteID id, byte *dest) static void ReadSprite(SpriteID id, byte *dest)
{ {
uint num = _sprite_size[id]; uint num = _sprite_size[id];
byte type; byte type;
byte *rel;
int8 i;
int dist;
FioSeekToFile(_sprite_file_pos[id]); FioSeekToFile(_sprite_file_pos[id]);
@ -175,28 +170,28 @@ static void ReadSprite(SpriteID id, byte *dest)
} }
if (type & 2) { if (type & 2) {
while (num--) for (; num > 0; --num)
*dest++ = FioReadByte();
return;
}
while (num) {
i = FioReadByte();
if (i>=0) {
num -= i;
while (i--)
*dest++ = FioReadByte(); *dest++ = FioReadByte();
} else { } else {
dist = -(((i&7)<<8)|FioReadByte()); while (num > 0) {
int8 i = FioReadByte();
if (i >= 0) {
num -= i;
for (; i > 0; --i)
*dest++ = FioReadByte();
} else {
const byte* rel = dest - (((i & 7) << 8) | FioReadByte());
i = -(i >> 3); i = -(i >> 3);
num -= i; num -= i;
rel = &dest[dist]; for (; i > 0; --i)
while (i--)
*dest++ = *rel++; *dest++ = *rel++;
} }
} }
} }
}
static bool LoadNextSprite(int load_index, byte file_index) static bool LoadNextSprite(int load_index, byte file_index)
@ -204,14 +199,15 @@ static bool LoadNextSprite(int load_index, byte file_index)
uint16 size; uint16 size;
uint32 file_pos; uint32 file_pos;
if ((size = FioReadWord()) == 0) size = FioReadWord();
if (size == 0)
return false; return false;
file_pos = FioGetPos() | (file_index << 24); file_pos = FioGetPos() | (file_index << 24);
ReadSpriteHeaderSkipData(size, load_index); ReadSpriteHeaderSkipData(size, load_index);
if ((_replace_sprites_count[0] > 0) && (_cur_sprite.info != 0xFF)) { if (_replace_sprites_count[0] > 0 && _cur_sprite.info != 0xFF) {
int count = _replace_sprites_count[0]; int count = _replace_sprites_count[0];
int offset = _replace_sprites_offset[0]; int offset = _replace_sprites_offset[0];
@ -265,16 +261,16 @@ static bool LoadNextSprite(int load_index, byte file_index)
return true; return true;
} }
static void SkipSprites(int count) static void SkipSprites(uint count)
{ {
while(count>0) for (; count > 0; --count)
{ {
uint16 size; uint16 size = FioReadWord();
if ( (size = FioReadWord()) == 0)
if (size == 0)
return; return;
ReadSpriteHeaderSkipData(size, NUM_SPRITES - 1); ReadSpriteHeaderSkipData(size, NUM_SPRITES - 1);
count--;
} }
} }
@ -323,7 +319,7 @@ static int LoadNewGrfFile(const char *filename, int load_index, int file_index)
length = FioReadWord(); length = FioReadWord();
type = FioReadByte(); type = FioReadByte();
if ((length == 4) && (type == 0xFF)) { if (length == 4 && type == 0xFF) {
FioReadDword(); FioReadDword();
} else { } else {
error("Custom .grf has invalid format."); error("Custom .grf has invalid format.");
@ -540,10 +536,9 @@ static void DeleteEntryFromSpriteCache(void)
if (_sprite_ptr[i] != 0 && if (_sprite_ptr[i] != 0 &&
_sprite_lru_new[i] < cur_lru _sprite_lru_new[i] < cur_lru
#if defined(WANT_LOCKED) #if defined(WANT_LOCKED)
&& !_sprite_locked[i]) { && !_sprite_locked[i]
#else
) {
#endif #endif
) {
cur_lru = _sprite_lru_new[i]; cur_lru = _sprite_lru_new[i];
best = i; best = i;
} }
@ -595,7 +590,7 @@ static void DeleteEntryFromSpriteCache(void)
} }
} }
static byte *LoadSpriteToMem(int sprite) static byte *LoadSpriteToMem(SpriteID sprite)
{ {
size_t mem_req; size_t mem_req;
@ -781,7 +776,7 @@ static bool FileMD5(const MD5File file, bool warn)
if (f == NULL) { if (f == NULL) {
char *s; char *s;
// make lower case and check again // make lower case and check again
for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++) for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++)
*s = tolower(*s); *s = tolower(*s);
f = fopen(buf, "rb"); f = fopen(buf, "rb");
} }
@ -789,7 +784,7 @@ static bool FileMD5(const MD5File file, bool warn)
if (f != NULL) { if (f != NULL) {
md5_init(&filemd5state); md5_init(&filemd5state);
while ( (len = fread (buffer, 1, 1024, f)) ) while ((len = fread(buffer, 1, 1024, f)) != 0)
md5_append(&filemd5state, buffer, len); md5_append(&filemd5state, buffer, len);
if (ferror(f)) if (ferror(f))
@ -810,8 +805,10 @@ static bool FileMD5(const MD5File file, bool warn)
* (Note: Also checks sample.cat for corruption) */ * (Note: Also checks sample.cat for corruption) */
void CheckExternalFiles(void) void CheckExternalFiles(void)
{ {
int i; uint i;
int dos=0, win=0; // count of files from this version // count of files from this version
uint dos = 0;
uint win = 0;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if (FileMD5(files_dos.basic[i], true)) if (FileMD5(files_dos.basic[i], true))
@ -841,8 +838,9 @@ void CheckExternalFiles(void)
static void LoadSpriteTables(void) static void LoadSpriteTables(void)
{ {
int i,j; uint i;
FileList *files; // list of grf files to be loaded. Either Windows files or DOS files uint j;
const FileList *files; // list of grf files to be loaded. Either Windows files or DOS files
_loading_stage = 1; _loading_stage = 1;
@ -857,7 +855,7 @@ static void LoadSpriteTables(void)
* invest that further. --octo * invest that further. --octo
*/ */
files = _use_dos_palette?(&files_dos):(&files_win); files = _use_dos_palette? &files_dos : &files_win;
// Try to load the sprites from cache // Try to load the sprites from cache
if (!HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], true)) { if (!HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], true)) {
@ -873,7 +871,11 @@ static void LoadSpriteTables(void)
LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++); LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++);
if (_sprite_page_to_load != 0) if (_sprite_page_to_load != 0)
LoadGrfIndexed(files->landscape[_sprite_page_to_load-1].filename, _landscape_spriteindexes[_sprite_page_to_load-1], i++); LoadGrfIndexed(
files->landscape[_sprite_page_to_load - 1].filename,
_landscape_spriteindexes[_sprite_page_to_load - 1],
i++
);
LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++); LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++);
@ -886,8 +888,9 @@ static void LoadSpriteTables(void)
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1; load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1;
/* Load newgrf sprites */ /* Load newgrf sprites
// in each loading stage, (try to) open each file specified in the config and load information from it. * in each loading stage, (try to) open each file specified in the config
* and load information from it. */
_custom_sprites_base = load_index; _custom_sprites_base = load_index;
for (_loading_stage = 0; _loading_stage < 2; _loading_stage++) { for (_loading_stage = 0; _loading_stage < 2; _loading_stage++) {
load_index = _custom_sprites_base; load_index = _custom_sprites_base;
@ -927,7 +930,7 @@ static void LoadSpriteTables(void)
// invalid. We should have some kind of check for this. // invalid. We should have some kind of check for this.
// The best solution for this is to delete the cached-sprites.. but how // The best solution for this is to delete the cached-sprites.. but how
// do we detect it? // do we detect it?
for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++) for (j = 0; j != lengthof(_newgrf_files) && _newgrf_files[j] != NULL; j++)
FioOpenFile(i++, _newgrf_files[j]); FioOpenFile(i++, _newgrf_files[j]);
} }
@ -972,33 +975,23 @@ void GfxLoadSprites(void)
const SpriteDimension *GetSpriteDimension(SpriteID sprite) const SpriteDimension *GetSpriteDimension(SpriteID sprite)
{ {
static SpriteDimension sd_static; static SpriteDimension sd_static;
SpriteDimension *sd; SpriteDimension *sd = &sd_static;
#ifndef WANT_SPRITESIZES #ifdef WANT_SPRITESIZES
const Sprite* p;
p = _sprite_ptr[sprite];
if (p == NULL)
p = GetSprite(sprite);
/* decode sprite header */
sd = &sd_static;
sd->xoffs = p->x_offs;
sd->yoffs = p->y_offs;
sd->xsize = p->width;
sd->ysize = p->height;
#else
sd = &sd_static;
sd->xoffs = _sprite_xoffs[sprite]; sd->xoffs = _sprite_xoffs[sprite];
sd->yoffs = _sprite_yoffs[sprite]; sd->yoffs = _sprite_yoffs[sprite];
sd->xsize = _sprite_xsize[sprite]; sd->xsize = _sprite_xsize[sprite];
sd->ysize = _sprite_ysize[sprite]; sd->ysize = _sprite_ysize[sprite];
#else
const Sprite* p = GetSprite(sprite);
/* decode sprite header */
sd->xoffs = p->x_offs;
sd->yoffs = p->y_offs;
sd->xsize = p->width;
sd->ysize = p->height;
#endif #endif
/* sd->xoffs = _sprite_xoffs[sprite];
sd->yoffs = _sprite_yoffs[sprite];
sd->xsize = _sprite_xsize[sprite];
sd->ysize = _sprite_ysize[sprite];
*/
return sd; return sd;
} }