1
0
Fork 0

(svn r590) -newgrf: Instead of a bunch of statinfo arrays, use station-array of struct StationSpec-s (pasky).

release/0.4.5
darkvater 2004-11-14 13:59:11 +00:00
parent 770eb4c8c3
commit 5663926aaf
1 changed files with 39 additions and 26 deletions

View File

@ -21,6 +21,12 @@ extern int _skip_sprites;
extern int _replace_sprites_count[16]; extern int _replace_sprites_count[16];
extern int _replace_sprites_offset[16]; extern int _replace_sprites_offset[16];
struct StationSpec {
uint32 classid;
byte tiles;
DrawTileSprites renderdata[8];
};
struct GRFFile { struct GRFFile {
char *filename; char *filename;
uint32 grfid; uint32 grfid;
@ -47,9 +53,7 @@ struct GRFFile {
int spritegroups_count; int spritegroups_count;
struct SpriteGroup *spritegroups; struct SpriteGroup *spritegroups;
uint32 statinfo_classid[256]; struct StationSpec stations[256];
byte statinfo_tiles[256];
DrawTileSprites statinfo_renderdata[256][8];
}; };
static struct GRFFile *_cur_grffile, *_first_grffile; static struct GRFFile *_cur_grffile, *_first_grffile;
@ -709,21 +713,25 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x08: case 0x08:
{ /* Class ID */ { /* Class ID */
FOR_EACH_ENGINE { FOR_EACH_ENGINE {
struct StationSpec *stat = &_cur_grffile->stations[stid + i];
/* classid, for a change, is always little-endian */ /* classid, for a change, is always little-endian */
_cur_grffile->statinfo_classid[stid+i] = *(buf++) << 24; stat->classid = *(buf++) << 24;
_cur_grffile->statinfo_classid[stid+i] |= *(buf++) << 16; stat->classid |= *(buf++) << 16;
_cur_grffile->statinfo_classid[stid+i] |= *(buf++) << 8; stat->classid |= *(buf++) << 8;
_cur_grffile->statinfo_classid[stid+i] |= *(buf++); stat->classid |= *(buf++);
} }
break; break;
} }
case 0x09: case 0x09:
{ /* Define sprite layout */ { /* Define sprite layout */
FOR_EACH_ENGINE { FOR_EACH_ENGINE {
struct StationSpec *stat = &_cur_grffile->stations[stid + i];
int t; int t;
_cur_grffile->statinfo_tiles[stid+i] = grf_load_byte(&buf);
for (t = 0; t < _cur_grffile->statinfo_tiles[stid+i]; t++) { stat->tiles = grf_load_byte(&buf);
DrawTileSprites *dts = &_cur_grffile->statinfo_renderdata[stid+i][t]; for (t = 0; t < stat->tiles; t++) {
DrawTileSprites *dts = &stat->renderdata[t];
int seq_count = 0; int seq_count = 0;
if (t >= 8) { if (t >= 8) {
@ -763,12 +771,15 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x0a: case 0x0a:
{ /* Copy sprite layout */ { /* Copy sprite layout */
FOR_EACH_ENGINE { FOR_EACH_ENGINE {
byte src = grf_load_byte(&buf); struct StationSpec *stat = &_cur_grffile->stations[stid + i];
byte srcid = grf_load_byte(&buf);
struct StationSpec *srcstat = &_cur_grffile->stations[srcid];
int t; int t;
_cur_grffile->statinfo_tiles[stid+i] = _cur_grffile->statinfo_tiles[src];
for (t = 0; t < _cur_grffile->statinfo_tiles[stid+i]; t++) { stat->tiles = srcstat->tiles;
DrawTileSprites *dts = &_cur_grffile->statinfo_renderdata[stid+i][t]; for (t = 0; t < stat->tiles; t++) {
DrawTileSprites *sdts = &_cur_grffile->statinfo_renderdata[src][t]; DrawTileSprites *dts = &stat->renderdata[t];
DrawTileSprites *sdts = &srcstat->renderdata[t];
DrawTileSeqStruct const *sdtss = sdts->seq; DrawTileSeqStruct const *sdtss = sdts->seq;
int seq_count = 0; int seq_count = 0;
@ -1063,8 +1074,8 @@ static void NewSpriteGroup(byte *buf, int len)
/* XXX: This just goes for the default superset for now, /* XXX: This just goes for the default superset for now,
* straight and safe. --pasky */ * straight and safe. --pasky */
uint8 var = buf[4]; uint8 var = buf[4];
uint8 shiftnum = buf[5]; //uint8 shiftnum = buf[5];
uint8 andmask = buf[6]; //uint8 andmask = buf[6];
uint8 nvar = buf[7]; uint8 nvar = buf[7];
//uint32 val; //uint32 val;
uint16 def; uint16 def;
@ -1194,6 +1205,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
uint16 groupid = grf_load_word(&bp); uint16 groupid = grf_load_word(&bp);
for (i = 0; i < idcount; i++) { for (i = 0; i < idcount; i++) {
struct StationSpec *stat;
uint8 stid = buf[3 + i]; uint8 stid = buf[3 + i];
int j; int j;
@ -1203,19 +1215,21 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
return; return;
} }
stat = &_cur_grffile->stations[stid];
// relocate sprite indexes based on spriteset locations // relocate sprite indexes based on spriteset locations
for (j = 0; j < _cur_grffile->statinfo_tiles[stid]; j++) { for (j = 0; j < stat->tiles; j++) {
DrawTileSeqStruct *seq; DrawTileSeqStruct *seq;
foreach_draw_tile_seq(seq, (DrawTileSeqStruct*) _cur_grffile->statinfo_renderdata[stid][j].seq) { foreach_draw_tile_seq(seq, (DrawTileSeqStruct*) stat->renderdata[j].seq) {
seq->image += _cur_grffile->spritegroups[groupid].loading[0]; seq->image += _cur_grffile->spritegroups[groupid].loading[0];
} }
} }
/* FIXME: This means several GRF files defining new stations /* FIXME: This means several GRF files defining new stations
* will override each other, but the stid should be GRF-specific * will override each other, but the stid should be GRF-specific
* instead! --pasky */ * instead! --pasky */
SetCustomStation(_cur_grffile->statinfo_classid[stid], stid, _cur_grffile->statinfo_renderdata[stid], _cur_grffile->statinfo_tiles[stid]); SetCustomStation(stat->classid, stid, stat->renderdata, stat->tiles);
_cur_grffile->statinfo_classid[stid] = 0; stat->classid = 0;
} }
return; return;
} }
@ -1251,7 +1265,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
DEBUG(grf, 6) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.", DEBUG(grf, 6) ("VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons.",
last_engines_count, idcount); last_engines_count, idcount);
} }
for (i = 0; i < idcount; i++) { for (i = 0; i < idcount; i++) {
uint8 engine_id = buf[3 + i]; uint8 engine_id = buf[3 + i];
@ -1565,7 +1579,7 @@ static void SpriteReplace(byte *buf, int len)
if (num_sets > 16) { if (num_sets > 16) {
grfmsg(GMS_ERROR, "SpriteReplace: Too many sets (%d), taking only the first 16!", num_sets); grfmsg(GMS_ERROR, "SpriteReplace: Too many sets (%d), taking only the first 16!", num_sets);
} }
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
if (i < num_sets) { if (i < num_sets) {
uint8 num_sprites = grf_load_byte(&buf); uint8 num_sprites = grf_load_byte(&buf);
@ -1666,7 +1680,7 @@ static void ParamSet(byte *buf, int len)
if (len >= 8) if (len >= 8)
data = grf_load_dword(&buf); data = grf_load_dword(&buf);
/* You can add 80 to the operation to make it apply only if the target /* You can add 80 to the operation to make it apply only if the target
* is not defined yet. In this respect, a parameter is taken to be * is not defined yet. In this respect, a parameter is taken to be
* defined if any of the following applies: * defined if any of the following applies:
@ -1750,11 +1764,10 @@ static void GRFInhibit(byte *buf, int len)
* *
* B num Number of GRFIDs that follow * B num Number of GRFIDs that follow
* D grfids GRFIDs of the files to deactivate */ * D grfids GRFIDs of the files to deactivate */
/* XXX: Should we handle forward deactivations? */
byte num; byte num;
int i; int i;
check_length(len, 1, "GRFInhibit"); check_length(len, 1, "GRFInhibit");
num = grf_load_byte(&buf); len--; num = grf_load_byte(&buf); len--;
check_length(len, 4 * num, "GRFInhibit"); check_length(len, 4 * num, "GRFInhibit");