/* Sprite printing routines */ #include #include #include "sprint.h" /* Choose between static and dynamic allocation */ /* #define SPRINT_DYN /* Use malloc() to reserve sprite store */ /* Sprite stores */ static int max; static int no; static GsSPRITE *curr; static int *curr_pri; static int frame; typedef struct {int r,g,b; } Color; #ifdef SPRINT_DYN static GsSPRITE *spr; static int *pri; static Color *orig_col; #else static GsSPRITE spr[1000]; static int pri[1000]; static Color orig_col[1000]; #endif static int cl8_x; static int cl8_y; static int cl16_x; static int cl16_y; static int tp8; static int tp16; static GsOT *ot[2]; static short defw8[256],defw16[256],*w8,*w16; static int lcx,lcy; void InitSPrint(int cx, int cy, int maxchars, GsOT *frame0_ot, GsOT *frame1_ot, int font8x8_texture_page, int font16x16_texture_page, int clut8_x, int clut8_y, int clut16_x, int clut16_y, short *width8, short *width16) { int f; lcx=cx; lcy=cy; max=maxchars; tp8=font8x8_texture_page; tp16=font16x16_texture_page; cl8_x=clut8_x; cl8_y=clut8_y; cl16_x=clut16_x; cl16_y=clut16_y; ot[0]=frame0_ot; ot[1]=frame1_ot; #ifdef SPRINT_DYN spr=(GsSPRITE *)malloc(sizeof(GsSPRITE)*max); assert(spr); pri=(int *)malloc(sizeof(int)*max); assert(pri); orig_col=(Color *)malloc(sizeof(Color)*max); assert(pri); #else assert(max<1000); #endif if (width8) w8=width8; else { for(f=0;f<256;f++) defw8[f]=8; w8=defw8; } if (width16) w16=width16; else { for(f=0;f<256;f++) defw16[f]=16; w16=defw16; } curr=spr; curr_pri=pri; no=0; } void SPrintNewFrame(int frame_index) { frame=frame_index; curr=spr; curr_pri=pri; no=0; } void SPrintRedraw(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; } GsSortFastSprite(spr+f,ot[frame],pri[f]); } } static void DoChar(int x, int y, int transparent, int trans_mode, int priority, int r, int g, int b, int tp, int u, int v, int w, int h, int cl_x, int cl_y) { 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=u; curr->v=v; 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_pri++=priority; GsSortFastSprite(curr,ot[frame],priority); curr++; no++; } void SPrint8(char *str, int x, int y, int transparent, int trans_mode, int priority, int r, int g, int b) { int u,v; char *p; p=str; while(*p) { u=((*p)%32)*8; v=(*p)/32*8; DoChar(x,y,transparent,trans_mode,priority, r,g,b,tp8,u,v,w8[*p],8,cl8_x,cl8_y); x+=w8[*p]; p++; } } void SPrint16(char *str, int x, int y, int transparent, int trans_mode, int priority, int r, int g, int b) { int u,v; char *p; p=str; while(*p) { u=((*p)%16)*16; v=(*p)/16*16; DoChar(x,y,transparent,trans_mode,priority, r,g,b,tp16,u,v,w16[*p],16,cl16_x,cl16_y); x+=w16[*p]; p++; } } void SPutCh8(char ch, int x, int y, int transparent, int trans_mode, int priority, int r, int g, int b) { int u,v; u=(ch%32)*8; v=ch/32*8; DoChar(x,y,transparent,trans_mode,priority, r,g,b,tp8,u,v,w8[ch],8,cl8_x,cl8_y); } void SPutCh16(char ch, int x, int y, int transparent, int trans_mode, int priority, int r, int g, int b) { int u,v; u=(ch%16)*16; v=ch/16*16; DoChar(x,y,transparent,trans_mode,priority, r,g,b,tp16,u,v,w16[ch],16,cl16_x,cl16_y); } int SLength8(char *str) { int l; l=0; while(*str) l+=w8[*str++]; return(l); } int SLength16(char *str) { int l; l=0; while(*str) l+=w16[*str++]; return(l); } /* END OF FILE */