From 6101c04ff9ee55e2be9a100a76a65ed1559ca24a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 27 Apr 2012 17:59:24 +0100 Subject: [PATCH] Use an array instead of ctype to cache tron colour --- includes/powder.h | 2 ++ src/elements/tron.c | 38 +++++++++++++++++--------------------- src/main.c | 2 ++ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index c471aa70f..48a06642f 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -329,6 +329,8 @@ int graphics_DCEL(GRAPHICS_FUNC_ARGS); int graphics_GEL(GRAPHICS_FUNC_ARGS); int graphics_TRON(GRAPHICS_FUNC_ARGS); +void TRON_init_graphics(); + #define UPDATE_FUNC_ARGS int i, int x, int y, int surround_space, int nt // to call another update function with same arguments: #define UPDATE_FUNC_SUBCALL_ARGS i, x, y, surround_space, nt diff --git a/src/elements/tron.c b/src/elements/tron.c index df8fbe370..00d2e9e91 100644 --- a/src/elements/tron.c +++ b/src/elements/tron.c @@ -24,6 +24,7 @@ #define TRON_DEATH 16 //Crashed, now dying int tron_rx[4] = {-1, 0, 1, 0}; int tron_ry[4] = { 0,-1, 0, 1}; +unsigned int tron_colours[32]; int new_tronhead(int x, int y, int i, int direction) { int np = create_part(-1, x , y ,PT_TRON); @@ -90,14 +91,6 @@ int trymovetron(int x, int y, int dir, int i, int len) } int update_TRON(UPDATE_FUNC_ARGS) { 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) { parts[i].tmp &= ~TRON_WAIT; @@ -162,20 +155,12 @@ int update_TRON(UPDATE_FUNC_ARGS) { } int graphics_TRON(GRAPHICS_FUNC_ARGS) { + unsigned int col = tron_colours[(cpart->tmp&0xF800)>>11]; if(cpart->tmp & TRON_HEAD) *pixel_mode |= PMODE_GLOW; - if(cpart->ctype) - { - *colr = (cpart->ctype & 0xFF0000)>>16; - *colg = (cpart->ctype & 0x00FF00)>>8; - *colb = (cpart->ctype & 0x0000FF); - } - else - { - *colr = 255; - *colg = 255; - *colb = 255; - } + *colr = (col & 0xFF0000)>>16; + *colg = (col & 0x00FF00)>>8; + *colb = (col & 0x0000FF); if(cpart->tmp & TRON_DEATH) { *pixel_mode |= FIRE_ADD | PMODE_FLARE; @@ -191,4 +176,15 @@ int graphics_TRON(GRAPHICS_FUNC_ARGS) { *cola = (int)((((float)cpart->life)/((float)cpart->tmp2))*255.0f); } return 0; -} \ No newline at end of file +} + +void 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; + } +} diff --git a/src/main.c b/src/main.c index f6e741c5a..4e60674b6 100644 --- a/src/main.c +++ b/src/main.c @@ -657,6 +657,7 @@ int main(int argc, char *argv[]) colour_mode = COLOUR_DEFAULT; init_display_modes(); + TRON_init_graphics(); sys_pause = 1; parts = calloc(sizeof(particle), NPART); @@ -806,6 +807,7 @@ int main(int argc, char *argv[]) colour_mode = COLOUR_DEFAULT; init_display_modes(); + TRON_init_graphics(); //fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP);