/* Sprite routines */ #include #include #include "sprite.h" /* Choose between static and dynamic allocation */ /* #define SPRITE_DYN /* Use malloc() to reserve sprite store */ /* Sprite stores */ static int max; static int no; static GsSPRITE *curr; static int *curr_pri; static char *curr_fast; static int frame; typedef struct {int r,g,b; } Color; #ifdef SPRITE_DYN static GsSPRITE *spr; static int *pri; static char *fast; static Color *orig_col; #else static GsSPRITE spr[1000]; static int pri[1000]; static char fast[1000]; static Color orig_col[1000]; #endif static int cl_x; static int cl_y; static int tp; static GsOT *ot[2]; static int lcx,lcy; void InitSprite(int cx, int cy, int maxsprite, GsOT *frame0_ot, GsOT *frame1_ot, int texture_page, int clut_x, int clut_y) { lcx=cx; lcy=cy; max=maxsprite; tp=texture_page; cl_x=clut_x; cl_y=clut_y; ot[0]=frame0_ot; ot[1]=frame1_ot; #ifdef SPRITE_DYN spr=(GsSPRITE *)malloc(sizeof(GsSPRITE)*max); assert(spr); pri=(int *)malloc(sizeof(int)*max); assert(pri); fast=(char *)malloc(sizeof(char)*max); assert(fast); fast=(Colour *)malloc(sizeof(Colour)*max); assert(fast); #else assert(max<1000); #endif curr=spr; curr_pri=pri; curr_fast=fast; no=0; } void SpriteNewFrame(int frame_index) { frame=frame_index; curr=spr; curr_pri=pri; curr_fast=fast; no=0; } void SpriteRedraw(int frame_index, int r, int g, int b, int fade_pri) { int f; frame=frame_index; for(f=0;ffade_pri) { if (orig_col[f].r>r) spr[f].r=r; else spr[f].r=orig_col[f].r; if (orig_col[f].g>g) spr[f].g=g; else spr[f].g=orig_col[f].g; if (orig_col[f].b>b) spr[f].b=b; else spr[f].b=orig_col[f].b; } if (fast[f]) GsSortFastSprite(spr+f,ot[frame],pri[f]); else GsSortSprite(spr+f,ot[frame],pri[f]); } } void FastSprite(int x, int y, int w, int h, int tp_x, int tp_y, int transparent, int trans_mode, int priority, int r, int g, int b) { if (no==max) return; curr->attribute=transparent<<30|trans_mode<<28|1<<27; curr->x=x-lcx; curr->y=y-lcy; curr->tpage=tp; curr->u=tp_x; curr->v=tp_y; curr->w=w; curr->h=h; curr->r=r; curr->g=g; curr->b=b; curr->cx=cl_x; curr->cy=cl_y; orig_col[no].r=r; orig_col[no].g=g; orig_col[no].b=b; *curr_fast++=1; *curr_pri++=priority; GsSortFastSprite(curr,ot[frame],priority); curr++; no++; } void Sprite(int x, int y, int w, int h, int centre_x, int centre_y, int tp_x, int tp_y, long rot, short scale_x, short scale_y, int transparent, int trans_mode, int priority, int r, int g, int b) { if (no==max) return; curr->attribute=transparent<<30|trans_mode<<28; curr->x=x-lcx; curr->y=y-lcy; curr->tpage=tp; curr->u=tp_x; curr->v=tp_y; curr->w=w; curr->h=h; curr->r=r; curr->g=g; curr->b=b; curr->cx=cl_x; curr->cy=cl_y; curr->mx=centre_x; curr->my=centre_y; curr->scalex=scale_x; curr->scaley=scale_y; curr->rotate=rot; orig_col[no].r=r; orig_col[no].g=g; orig_col[no].b=b; *curr_fast++=0; *curr_pri++=priority; GsSortSprite(curr,ot[frame],priority); curr++; no++; } /* END OF FILE */