diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-10 19:42:55 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-10 19:42:55 (GMT) |
| commit | 948fd376b4aae29b961822005cd503d9eb0fbf41 (patch) | |
| tree | 4f6a3e62c993bc7a79bcad452ad501143906e493 /src | |
| parent | 9c9f6b2287b028f7d0367308c7669e0ba8960a36 (diff) | |
| download | powder-948fd376b4aae29b961822005cd503d9eb0fbf41.zip powder-948fd376b4aae29b961822005cd503d9eb0fbf41.tar.gz | |
Starting on jumptable/function pointers for graphics, only FIRE is implemented
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics.c | 66 | ||||
| -rw-r--r-- | src/main.c | 4 |
2 files changed, 67 insertions, 3 deletions
diff --git a/src/graphics.c b/src/graphics.c index c038f10..dd70e28 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -16,6 +16,7 @@ #include <air.h> #include <powder.h> #include <graphics.h> +#include <powdergraphics.h> #define INCLUDE_FONTDATA #include <font.h> #include <misc.h> @@ -1724,7 +1725,67 @@ void xor_rect(pixel *vid, int x, int y, int w, int h) } } -//the main function for drawing the particles +//New function for drawing particles +void render_parts(pixel *vid) +{ + //TODO: Replace cmode with a set of flags + int colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, i, t, nx, ny; + for(i = 0; i<=parts_lastActiveIndex; i++) { + if (parts[i].type) { + t = parts[i].type; + + nx = (int)(parts[i].x+0.5f); + ny = (int)(parts[i].y+0.5f); + + if(photons[ny][nx]&0xFF && !(ptypes[t].properties & TYPE_ENERGY)) + continue; + + //Defaults + pixel_mode = 0 | PMODE_FLAT; + colr = PIXR(ptypes[t].pcolors); + colg = PIXG(ptypes[t].pcolors); + colb = PIXB(ptypes[t].pcolors); + firea = 0; + + if (ptypes[t].graphics_func) + { + if ((*(ptypes[t].graphics_func))(i, nx, ny, &pixel_mode, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better + { + //Data can be cached! + } + } + + if(firea && (pixel_mode & FIRE_BLEND) && cmode==CM_FIRE) + { + fire_r[ny/CELL][nx/CELL] = (firea*firer + (255-firea)*fire_r[ny/CELL][nx/CELL]) >> 8; + fire_g[ny/CELL][nx/CELL] = (firea*fireg + (255-firea)*fire_g[ny/CELL][nx/CELL]) >> 8; + fire_b[ny/CELL][nx/CELL] = (firea*fireb + (255-firea)*fire_b[ny/CELL][nx/CELL]) >> 8; + } + if(firea && (pixel_mode & FIRE_ADD) && cmode==CM_FIRE) + { + firer = ((firea*firer) >> 8) + fire_r[ny/CELL][nx/CELL]; + fireg = ((firea*fireg) >> 8) + fire_g[ny/CELL][nx/CELL]; + fireb = ((firea*fireb) >> 8) + fire_b[ny/CELL][nx/CELL]; + + if(firer>255) + firer = 255; + if(fireg>255) + fireg = 255; + if(fireb>255) + fireb = 255; + + fire_r[ny/CELL][nx/CELL] = firer; + fire_g[ny/CELL][nx/CELL] = fireg; + fire_b[ny/CELL][nx/CELL] = fireb; + } + //Put part on video + if(pixel_mode & PMODE_FLAT) + vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(colr,colg,colb); + } + } +} + +//the old function for drawing the particles void draw_parts(pixel *vid) { int i, x, y, t, nx, ny, r, s; @@ -1808,6 +1869,9 @@ void draw_parts(pixel *vid) if(photons[ny][nx]&0xFF && !(ptypes[t].properties & TYPE_ENERGY)) continue; + + + if (t==PT_SOAP) { if ((parts[i].ctype&7) == 7) @@ -1508,7 +1508,7 @@ int main(int argc, char *argv[]) memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); draw_walls(vid_buf); update_particles(vid_buf); - draw_parts(vid_buf); + render_parts(vid_buf); render_fire(vid_buf); } @@ -1814,7 +1814,7 @@ int main(int argc, char *argv[]) draw_grav(vid_buf); draw_walls(part_vbuf); update_particles(part_vbuf); //update everything - draw_parts(part_vbuf); //draw particles + render_parts(part_vbuf); //draw particles if(sl == WL_GRAV+100 || sr == WL_GRAV+100) draw_grav_zones(part_vbuf); |
