mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r1852) Start cleaning up sprite handling:
- Complement the sprite header struct with a variable sized array for the sprite data and rename it to Sprite. - Use the correct type Sprite* instead of casting all the time (this causes some "assignment from incompatible pointer type" warnings, nothing serious, will be resolved soon)
This commit is contained in:
parent
297223cc21
commit
092e72d60d
26
gfx.c
26
gfx.c
@ -5,7 +5,7 @@
|
|||||||
#include "table/palettes.h"
|
#include "table/palettes.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
|
||||||
static void GfxMainBlitter(byte *sprite, int x, int y, int mode);
|
static void GfxMainBlitter(Sprite *sprite, int x, int y, int mode);
|
||||||
|
|
||||||
static int _stringwidth_out;
|
static int _stringwidth_out;
|
||||||
static byte _cursor_backup[64*64];
|
static byte _cursor_backup[64*64];
|
||||||
@ -1312,7 +1312,7 @@ static void GfxBlitZoomOutUncomp(BlitterParams *bp)
|
|||||||
|
|
||||||
typedef void (*BlitZoomFunc)(BlitterParams *bp);
|
typedef void (*BlitZoomFunc)(BlitterParams *bp);
|
||||||
|
|
||||||
static void GfxMainBlitter(byte *sprite, int x, int y, int mode)
|
static void GfxMainBlitter(Sprite *sprite, int x, int y, int mode)
|
||||||
{
|
{
|
||||||
DrawPixelInfo *dpi = _cur_dpi;
|
DrawPixelInfo *dpi = _cur_dpi;
|
||||||
int start_x, start_y;
|
int start_x, start_y;
|
||||||
@ -1334,13 +1334,13 @@ static void GfxMainBlitter(byte *sprite, int x, int y, int mode)
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* decode sprite header */
|
/* decode sprite header */
|
||||||
x += (int16)READ_LE_UINT16(&((SpriteHdr*)sprite)->x_offs);
|
x += (int16)TO_LE16(sprite->x_offs);
|
||||||
y += (int16)READ_LE_UINT16(&((SpriteHdr*)sprite)->y_offs);
|
y += (int16)TO_LE16(sprite->y_offs);
|
||||||
bp.width_org = bp.width = READ_LE_UINT16(&((SpriteHdr*)sprite)->width);
|
bp.width_org = bp.width = TO_LE16(sprite->width);
|
||||||
bp.height_org = bp.height = ((SpriteHdr*)sprite)->height;
|
bp.height_org = bp.height = sprite->height;
|
||||||
info = ((SpriteHdr*)sprite)->info;
|
info = sprite->info;
|
||||||
bp.info = info;
|
bp.info = info;
|
||||||
bp.sprite_org = bp.sprite = sprite + sizeof(SpriteHdr);
|
bp.sprite_org = bp.sprite = sprite->data;
|
||||||
bp.dst = dpi->dst_ptr;
|
bp.dst = dpi->dst_ptr;
|
||||||
bp.mode = mode;
|
bp.mode = mode;
|
||||||
bp.pitch = dpi->pitch;
|
bp.pitch = dpi->pitch;
|
||||||
@ -1905,17 +1905,17 @@ bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, in
|
|||||||
static void SetCursorSprite(uint cursor)
|
static void SetCursorSprite(uint cursor)
|
||||||
{
|
{
|
||||||
CursorVars *cv = &_cursor;
|
CursorVars *cv = &_cursor;
|
||||||
byte *p;
|
const Sprite *p;
|
||||||
|
|
||||||
if (cv->sprite == cursor)
|
if (cv->sprite == cursor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p = GetSpritePtr(cursor & 0x3FFF);
|
p = GetSpritePtr(cursor & 0x3FFF);
|
||||||
cv->sprite = cursor;
|
cv->sprite = cursor;
|
||||||
cv->size.y = *(byte*)(p+1);
|
cv->size.y = p->height;
|
||||||
cv->size.x = READ_LE_UINT16(p+2);
|
cv->size.x = TO_LE16(p->width);
|
||||||
cv->offs.x = (int16)READ_LE_UINT16(p+4);
|
cv->offs.x = (int16)TO_LE16(p->x_offs);
|
||||||
cv->offs.y = (int16)READ_LE_UINT16(p+6);
|
cv->offs.y = (int16)TO_LE16(p->y_offs);
|
||||||
|
|
||||||
cv->dirty = true;
|
cv->dirty = true;
|
||||||
}
|
}
|
||||||
|
12
gfx.h
12
gfx.h
@ -17,13 +17,15 @@ struct DrawPixelInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef struct SpriteHdr {
|
typedef struct Sprite {
|
||||||
byte info;
|
byte info;
|
||||||
byte height;
|
byte height;
|
||||||
uint16 width;
|
uint16 width; // LE!
|
||||||
int16 x_offs, y_offs;
|
int16 x_offs; // LE!
|
||||||
} SpriteHdr;
|
int16 y_offs; // LE!
|
||||||
assert_compile(sizeof(SpriteHdr) == 8);
|
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;
|
||||||
|
@ -26,7 +26,7 @@ static const char *_cur_grffile;
|
|||||||
static int _loading_stage;
|
static int _loading_stage;
|
||||||
static int _skip_specials;
|
static int _skip_specials;
|
||||||
uint16 _custom_sprites_base;
|
uint16 _custom_sprites_base;
|
||||||
static SpriteHdr _cur_sprite;
|
static Sprite _cur_sprite;
|
||||||
|
|
||||||
|
|
||||||
static byte *_sprite_ptr[NUM_SPRITES];
|
static byte *_sprite_ptr[NUM_SPRITES];
|
||||||
@ -982,7 +982,7 @@ const SpriteDimension *GetSpriteDimension(uint sprite)
|
|||||||
SpriteDimension *sd;
|
SpriteDimension *sd;
|
||||||
|
|
||||||
#ifndef WANT_SPRITESIZES
|
#ifndef WANT_SPRITESIZES
|
||||||
byte *p;
|
const Sprite* p;
|
||||||
|
|
||||||
p = _sprite_ptr[sprite];
|
p = _sprite_ptr[sprite];
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
@ -990,10 +990,10 @@ const SpriteDimension *GetSpriteDimension(uint sprite)
|
|||||||
|
|
||||||
/* decode sprite header */
|
/* decode sprite header */
|
||||||
sd = &sd_static;
|
sd = &sd_static;
|
||||||
sd->xoffs = (int16)READ_LE_UINT16(&((SpriteHdr*)p)->x_offs);
|
sd->xoffs = (int16)TO_LE16(p->x_offs);
|
||||||
sd->yoffs = (int16)READ_LE_UINT16(&((SpriteHdr*)p)->y_offs);
|
sd->yoffs = (int16)TO_LE16(p->y_offs);
|
||||||
sd->xsize = READ_LE_UINT16(&((SpriteHdr*)p)->width);
|
sd->xsize = TO_LE16(p->width);
|
||||||
sd->ysize = ((SpriteHdr*)p)->height;
|
sd->ysize = p->height;
|
||||||
#else
|
#else
|
||||||
sd = &sd_static;
|
sd = &sd_static;
|
||||||
sd->xoffs = _sprite_xoffs[sprite];
|
sd->xoffs = _sprite_xoffs[sprite];
|
||||||
|
Loading…
Reference in New Issue
Block a user