TPT: Use an array instead of ctype to cache tron colour 6101c04ff9

This commit is contained in:
Simon Robertshaw 2012-06-12 16:20:35 +01:00
parent 74d7fb59c3
commit ad677189cb

View File

@ -44,6 +44,8 @@ Element_TRON::Element_TRON()
Update = &Element_TRON::update; Update = &Element_TRON::update;
Graphics = &Element_TRON::graphics; Graphics = &Element_TRON::graphics;
Element_TRON::init_graphics();
} }
#define TRON_HEAD 1 #define TRON_HEAD 1
@ -53,19 +55,24 @@ Element_TRON::Element_TRON()
#define TRON_DEATH 16 //Crashed, now dying #define TRON_DEATH 16 //Crashed, now dying
int tron_rx[4] = {-1, 0, 1, 0}; int tron_rx[4] = {-1, 0, 1, 0};
int tron_ry[4] = { 0,-1, 0, 1}; int tron_ry[4] = { 0,-1, 0, 1};
unsigned int tron_colours[32];
//#TPT-Directive ElementHeader Element_TRON static void init_graphics()
void Element_TRON::init_graphics()
{
int i;
int r, g, b;
for (i=0; i<32; i++)
{
HSV_to_RGB(i<<4,255,255,&r,&g,&b);
tron_colours[i] = r<<16 | g<<8 | b;
}
}
//#TPT-Directive ElementHeader Element_TRON static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_TRON static int update(UPDATE_FUNC_ARGS)
int Element_TRON::update(UPDATE_FUNC_ARGS) int Element_TRON::update(UPDATE_FUNC_ARGS)
{ {
int r, rx, ry, np; int r, rx, ry, np;
if(!parts[i].ctype)
{
int r, g, b;
int hue = (parts[i].tmp&0xF800)>>7;
HSV_to_RGB(hue,255,255,&r,&g,&b);
parts[i].ctype = r<<16 | g<<8 | b;
//Use photon-like wavelength?
}
if (parts[i].tmp&TRON_WAIT) if (parts[i].tmp&TRON_WAIT)
{ {
parts[i].tmp &= ~TRON_WAIT; parts[i].tmp &= ~TRON_WAIT;
@ -134,20 +141,12 @@ int Element_TRON::update(UPDATE_FUNC_ARGS)
//#TPT-Directive ElementHeader Element_TRON static int graphics(GRAPHICS_FUNC_ARGS) //#TPT-Directive ElementHeader Element_TRON static int graphics(GRAPHICS_FUNC_ARGS)
int Element_TRON::graphics(GRAPHICS_FUNC_ARGS) int Element_TRON::graphics(GRAPHICS_FUNC_ARGS)
{ {
unsigned int col = tron_colours[(cpart->tmp&0xF800)>>11];
if(cpart->tmp & TRON_HEAD) if(cpart->tmp & TRON_HEAD)
*pixel_mode |= PMODE_GLOW; *pixel_mode |= PMODE_GLOW;
if(cpart->ctype) *colr = (col & 0xFF0000)>>16;
{ *colg = (col & 0x00FF00)>>8;
*colr = (cpart->ctype & 0xFF0000)>>16; *colb = (col & 0x0000FF);
*colg = (cpart->ctype & 0x00FF00)>>8;
*colb = (cpart->ctype & 0x0000FF);
}
else
{
*colr = 255;
*colg = 255;
*colb = 255;
}
if(cpart->tmp & TRON_DEATH) if(cpart->tmp & TRON_DEATH)
{ {
*pixel_mode |= FIRE_ADD | PMODE_FLARE; *pixel_mode |= FIRE_ADD | PMODE_FLARE;