1
0
Fork 0

(svn r1854) Split GetSpritePtr() into GetSprite() for regular sprites (returning a Sprite*) and GetNonSprite() for "sprites" of type 0xFF (returning byte*)

release/0.4.5
tron 2005-02-10 12:14:38 +00:00
parent 2a151d9354
commit 94c75f33bb
7 changed files with 33 additions and 27 deletions

22
gfx.c
View File

@ -144,7 +144,7 @@ void GfxFillRect(int left, int top, int right, int bottom, int color) {
} while (--bottom); } while (--bottom);
} else { } else {
/* use colortable mode */ /* use colortable mode */
ctab = GetSpritePtr(color & 0x3FFF) + 1; ctab = GetNonSprite(color & 0x3FFF) + 1;
do { do {
int i; int i;
for(i=0; i!=right;i++) for(i=0; i!=right;i++)
@ -528,7 +528,7 @@ skip_cont:;
if (c >= ASCII_LETTERSTART) { if (c >= ASCII_LETTERSTART) {
if (x >= dpi->left + dpi->width) goto skip_char; if (x >= dpi->left + dpi->width) goto skip_char;
if (x + 26 >= dpi->left) { if (x + 26 >= dpi->left) {
GfxMainBlitter(GetSpritePtr(base + 2 + c - ASCII_LETTERSTART), x, y, 1); GfxMainBlitter(GetSprite(base + 2 + c - ASCII_LETTERSTART), x, y, 1);
} }
x += _stringwidth_table[base + c - ' ']; x += _stringwidth_table[base + c - ' '];
} else if (c == ASCII_NL) { // newline = {} } else if (c == ASCII_NL) { // newline = {}
@ -560,13 +560,13 @@ skip_cont:;
void DrawSprite(uint32 img, int x, int y) { void DrawSprite(uint32 img, int x, int y) {
if (img & 0x8000) { if (img & 0x8000) {
_color_remap_ptr = GetSpritePtr(img >> 16) + 1; _color_remap_ptr = GetNonSprite(img >> 16) + 1;
GfxMainBlitter(GetSpritePtr(img & 0x3FFF), x, y, 1); GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 1);
} else if (img & 0x4000) { } else if (img & 0x4000) {
_color_remap_ptr = GetSpritePtr(img >> 16) + 1; _color_remap_ptr = GetNonSprite(img >> 16) + 1;
GfxMainBlitter(GetSpritePtr(img & 0x3FFF), x, y, 2); GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 2);
} else { } else {
GfxMainBlitter(GetSpritePtr(img & 0x3FFF), x, y, 0); GfxMainBlitter(GetSprite(img & 0x3FFF), x, y, 0);
} }
} }
@ -1628,15 +1628,15 @@ void LoadStringWidthTable(void)
// 2 equals space. // 2 equals space.
for(i=2; i != 0xE2; i++) { for(i=2; i != 0xE2; i++) {
*b++ = (byte)((i < 93 || i >= 129 || i == 98) ? GetSpritePtr(i)[2] : 0); *b++ = (byte)((i < 93 || i >= 129 || i == 98) ? TO_LE16(GetSprite(i)->width) : 0);
} }
for(i=0xE2; i != 0x1C2; i++) { for(i=0xE2; i != 0x1C2; i++) {
*b++ = (byte)((i < 317 || i >= 353) ? GetSpritePtr(i)[2]+1 : 0); *b++ = (byte)((i < 317 || i >= 353) ? TO_LE16(GetSprite(i)->width) + 1 : 0);
} }
for(i=0x1C2; i != 0x2A2; i++) { for(i=0x1C2; i != 0x2A2; i++) {
*b++ = (byte)((i < 541 || i >= 577) ? GetSpritePtr(i)[2]+1 : 0); *b++ = (byte)((i < 541 || i >= 577) ? TO_LE16(GetSprite(i)->width) + 1 : 0);
} }
} }
@ -1911,7 +1911,7 @@ static void SetCursorSprite(uint cursor)
if (cv->sprite == cursor) if (cv->sprite == cursor)
return; return;
p = GetSpritePtr(cursor & 0x3FFF); p = GetSprite(cursor & 0x3FFF);
cv->sprite = cursor; cv->sprite = cursor;
cv->size.y = p->height; cv->size.y = p->height;
cv->size.x = TO_LE16(p->width); cv->size.x = TO_LE16(p->width);

10
gfx.h
View File

@ -17,16 +17,6 @@ struct DrawPixelInfo {
}; };
typedef struct Sprite {
byte info;
byte height;
uint16 width; // LE!
int16 x_offs; // LE!
int16 y_offs; // LE!
byte data[VARARRAY_SIZE];
} Sprite;
assert_compile(sizeof(Sprite) == 8);
typedef struct CursorVars { typedef struct CursorVars {
Point pos, size, offs, delta; Point pos, size, offs, delta;
Point draw_pos, draw_size; Point draw_pos, draw_size;

View File

@ -476,7 +476,7 @@ static void GenerateTerrain(int type, int flag)
byte direction; byte direction;
r = Random(); r = Random();
p = GetSpritePtr((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845); p = GetNonSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
x = r & MapMaxX(); x = r & MapMaxX();
y = (r >> MapLogX()) & MapMaxY(); y = (r >> MapLogX()) & MapMaxY();

View File

@ -2378,7 +2378,7 @@ void SetupColorsAndInitialWindow(void)
int width,height; int width,height;
for(i=0; i!=16; i++) { for(i=0; i!=16; i++) {
b = GetSpritePtr(0x307 + i); b = GetNonSprite(0x307 + i);
assert(b); assert(b);
_color_list[i] = *(ColorList*)(b + 0xC6); _color_list[i] = *(ColorList*)(b + 0xC6);
} }

View File

@ -618,7 +618,7 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
FOR_ALL_PLAYERS(p) { FOR_ALL_PLAYERS(p) {
if (p->is_active) if (p->is_active)
_owner_colors[p->index] = _owner_colors[p->index] =
dup_byte32(GetSpritePtr(0x307 + p->player_color)[0xCB]); dup_byte32(GetNonSprite(0x307 + p->player_color)[0xCB]);
} }
} }

View File

@ -698,7 +698,12 @@ static uint RotateSprite(uint s)
} }
#endif #endif
byte *GetSpritePtr(SpriteID sprite) Sprite *GetSprite(SpriteID sprite)
{
return GetNonSprite(sprite);
}
byte *GetNonSprite(SpriteID sprite)
{ {
byte *p; byte *p;
@ -987,7 +992,7 @@ const SpriteDimension *GetSpriteDimension(SpriteID sprite)
p = _sprite_ptr[sprite]; p = _sprite_ptr[sprite];
if (p == NULL) if (p == NULL)
p = GetSpritePtr(sprite); p = GetSprite(sprite);
/* decode sprite header */ /* decode sprite header */
sd = &sd_static; sd = &sd_static;

View File

@ -1,13 +1,24 @@
#ifndef SPRITECACHE_H #ifndef SPRITECACHE_H
#define SPRITECACHE_H #define SPRITECACHE_H
typedef struct Sprite {
byte info;
byte height;
uint16 width; // LE!
int16 x_offs; // LE!
int16 y_offs; // LE!
byte data[VARARRAY_SIZE];
} Sprite;
assert_compile(sizeof(Sprite) == 8);
typedef struct { typedef struct {
int xoffs, yoffs; int xoffs, yoffs;
int xsize, ysize; int xsize, ysize;
} SpriteDimension; } SpriteDimension;
const SpriteDimension *GetSpriteDimension(SpriteID sprite); const SpriteDimension *GetSpriteDimension(SpriteID sprite);
byte *GetSpritePtr(SpriteID sprite); Sprite *GetSprite(SpriteID sprite);
byte *GetNonSprite(SpriteID sprite);
void GfxInitSpriteMem(byte *ptr, uint32 size); void GfxInitSpriteMem(byte *ptr, uint32 size);
void GfxLoadSprites(void); void GfxLoadSprites(void);