From e8b26db00c934d141f16652cb8dcbeae23b17e48 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 24 Dec 2019 22:02:40 +0200 Subject: [PATCH] minor performance improvements, optional mouse, mouse cursor now drawn with compiled sprites --- Makefile | 15 ++++++-- libs/anim/Makefile | 2 +- libs/imago/Makefile | 2 +- src/3dgfx.c | 73 +++++++++++++++++++++++++++++-------- src/3dgfx.h | 2 + src/cfgopt.c | 12 +++++- src/cfgopt.h | 2 +- src/demo.c | 101 +++++++++++++++------------------------------------ src/demo.h | 11 ++++-- src/dos/main.c | 25 +++++++------ src/gfxutil.c | 6 +-- src/scr/bump.c | 44 +++++++++++----------- src/scr/fract.c | 14 +++---- src/scr/greets.c | 16 ++++---- src/scr/grise.c | 22 +++++------ src/scr/hairball.c | 2 +- src/scr/infcubes.c | 2 +- src/scr/metaball.c | 4 +- src/scr/plasma.c | 4 +- src/scr/polytest.c | 27 ++++++++------ src/scr/tunnel.c | 10 ++--- src/sdl/main.c | 18 ++++----- src/tinyfps.c | 8 ++-- src/util.h | 19 ++++++++++ 24 files changed, 245 insertions(+), 196 deletions(-) diff --git a/Makefile b/Makefile index 54e4148..e249553 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,15 @@ endif inc = -Isrc -Isrc/scr -Isrc/dos -Ilibs -Ilibs/imago/src -Ilibs/anim/src opt = -O3 -ffast-math -fno-strict-aliasing -dbg = -g -#prof = -pg warn = -pedantic -Wall -Wno-unused-function -Wno-unused-variable -def = -DNO_MUSIC + +ifdef RELEASE + dbg = -g + def = -DNDEBUG -DNO_MUSIC +else + def = -DNO_MUSIC +endif +#prof = -pg CC = $(TOOLPREFIX)gcc AR = $(TOOLPREFIX)ar @@ -86,3 +91,7 @@ cleandep: data: @tools/procdata endif + +.PHONY: strip +strip: $(bin) + $(TOOLPREFIX)strip $(bin) diff --git a/libs/anim/Makefile b/libs/anim/Makefile index fd3b651..d0e6d59 100644 --- a/libs/anim/Makefile +++ b/libs/anim/Makefile @@ -11,7 +11,7 @@ endif CC = $(TOOLPREFIX)gcc AR = $(TOOLPREFIX)ar -CFLAGS = -Wno-main -march=pentium -g -O3 -ffast-math -I.. -I../../src +CFLAGS = -Wno-main -march=pentium -O3 -ffast-math -I.. -I../../src $(alib): $(obj) $(AR) rcs $@ $(obj) diff --git a/libs/imago/Makefile b/libs/imago/Makefile index 3e11a8d..b8b014f 100644 --- a/libs/imago/Makefile +++ b/libs/imago/Makefile @@ -14,7 +14,7 @@ endif CC = $(TOOLPREFIX)gcc AR = $(TOOLPREFIX)ar -CFLAGS = -Wno-main -march=pentium -g -O3 -ffast-math -Izlib -Ilibpng -Ijpeglib +CFLAGS = -Wno-main -march=pentium -O3 -ffast-math -Izlib -Ilibpng -Ijpeglib $(alib): $(obj) $(AR) rcs $@ $(obj) diff --git a/src/3dgfx.c b/src/3dgfx.c index e58ac89..b1dea9f 100644 --- a/src/3dgfx.c +++ b/src/3dgfx.c @@ -23,7 +23,20 @@ typedef float g3d_matrix[16]; #define IMM_VBUF_SIZE 256 +#define NORMALIZE(v) \ + do { \ + float len = sqrt((v)[0] * (v)[0] + (v)[1] * (v)[1] + (v)[2] * (v)[2]); \ + if(len != 0.0) { \ + float s = 1.0 / len; \ + (v)[0] *= s; \ + (v)[1] *= s; \ + (v)[2] *= s; \ + } \ + } while(0) + +enum {LT_POS, LT_DIR}; struct light { + int type; float x, y, z; float r, g, b; }; @@ -336,6 +349,7 @@ void g3d_light_pos(int idx, float x, float y, float z) { int mvtop = st->mtop[G3D_MODELVIEW]; + st->lt[idx].type = LT_POS; st->lt[idx].x = x; st->lt[idx].y = y; st->lt[idx].z = z; @@ -343,6 +357,24 @@ void g3d_light_pos(int idx, float x, float y, float z) xform4_vec3(st->mat[G3D_MODELVIEW][mvtop], &st->lt[idx].x); } +void g3d_light_dir(int idx, float x, float y, float z) +{ + int mvtop = st->mtop[G3D_MODELVIEW]; + + st->lt[idx].type = LT_DIR; + st->lt[idx].x = x; + st->lt[idx].y = y; + st->lt[idx].z = z; + + /* calc the normal matrix */ + memcpy(st->norm_mat, st->mat[G3D_MODELVIEW][mvtop], 16 * sizeof(float)); + st->norm_mat[12] = st->norm_mat[13] = st->norm_mat[14] = 0.0f; + + xform4_vec3(st->norm_mat, &st->lt[idx].x); + + NORMALIZE(&st->lt[idx].x); +} + void g3d_light_color(int idx, float r, float g, float b) { st->lt[idx].r = r; @@ -653,17 +685,6 @@ static __inline void xform3_vec3(const float *mat, float *vec) vec[0] = x; } -#define NORMALIZE(v) \ - do { \ - float len = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); \ - if(len != 0.0) { \ - float s = 1.0 / len; \ - v[0] *= s; \ - v[1] *= s; \ - v[2] *= s; \ - } \ - } while(0) - static void shade(struct g3d_vertex *v) { int i, r, g, b; @@ -681,10 +702,16 @@ static void shade(struct g3d_vertex *v) continue; } - ldir[0] = st->lt[i].x - v->x; - ldir[1] = st->lt[i].y - v->y; - ldir[2] = st->lt[i].z - v->z; - NORMALIZE(ldir); + ldir[0] = st->lt[i].x; + ldir[1] = st->lt[i].y; + ldir[2] = st->lt[i].z; + + if(st->lt[i].type != LT_DIR) { + ldir[0] -= v->x; + ldir[1] -= v->y; + ldir[2] -= v->z; + NORMALIZE(ldir); + } if((ndotl = v->nx * ldir[0] + v->ny * ldir[1] + v->nz * ldir[2]) < 0.0f) { ndotl = 0.0f; @@ -693,6 +720,22 @@ static void shade(struct g3d_vertex *v) color[0] += st->mtl.kd[0] * st->lt[i].r * ndotl; color[1] += st->mtl.kd[1] * st->lt[i].g * ndotl; color[2] += st->mtl.kd[2] * st->lt[i].b * ndotl; + + /* + if(st->opt & G3D_SPECULAR) { + float ndoth; + ldir[2] += 1.0f; + NORMALIZE(ldir); + if((ndoth = v->nx * ldir[0] + v->ny * ldir[1] + v->nz * ldir[2]) < 0.0f) { + ndoth = 0.0f; + } + ndoth = pow(ndoth, st->mtl.shin); + + color[0] += st->mtl.ks[0] * st->lt[i].r * ndoth; + color[1] += st->mtl.ks[1] * st->lt[i].g * ndoth; + color[2] += st->mtl.ks[2] * st->lt[i].b * ndoth; + } + */ } r = cround64(color[0] * 255.0); diff --git a/src/3dgfx.h b/src/3dgfx.h index 5c30e9c..f6250d5 100644 --- a/src/3dgfx.h +++ b/src/3dgfx.h @@ -54,6 +54,7 @@ enum { G3D_CLIP_PLANE3 = 0x008000, G3D_TEXTURE_MAT = 0x010000, + G3D_SPECULAR = 0x020000, G3D_ALL = 0x7fffffff }; @@ -112,6 +113,7 @@ void g3d_perspective(float vfov, float aspect, float znear, float zfar); const float *g3d_get_matrix(int which, float *m); void g3d_light_pos(int idx, float x, float y, float z); +void g3d_light_dir(int idx, float x, float y, float z); void g3d_light_color(int idx, float r, float g, float b); void g3d_light_ambient(float r, float g, float b); diff --git a/src/cfgopt.c b/src/cfgopt.c index 8f3759b..2592930 100644 --- a/src/cfgopt.c +++ b/src/cfgopt.c @@ -9,8 +9,9 @@ struct options opt = { 0, /* start_scr */ 1, /* music */ + 0, /* mouse */ 0, /* sball */ - 1, /* vsync */ + 0, /* vsync */ 0 /* dbginfo */ }; #else @@ -18,8 +19,9 @@ struct options opt = { struct options opt = { 0, /* start_scr */ 0, /* music */ + 1, /* mouse */ 0, /* sball */ - 1, /* vsync */ + 0, /* vsync */ 1 /* dbginfo */ }; #endif @@ -37,6 +39,10 @@ int parse_args(int argc, char **argv) opt.music = 0; } else if(strcmp(argv[i], "-scr") == 0 || strcmp(argv[i], "-screen") == 0) { scrname = argv[++i]; + } else if(strcmp(argv[i], "-mouse") == 0) { + opt.mouse = 1; + } else if(strcmp(argv[i], "-nomouse") == 0) { + opt.mouse = 0; } else if(strcmp(argv[i], "-sball") == 0) { opt.sball = !opt.sball; } else if(strcmp(argv[i], "-vsync") == 0) { @@ -129,6 +135,8 @@ int load_config(const char *fname) opt.music = bool_value(value); } else if(strcmp(line, "screen") == 0) { opt.start_scr = strdup(value); + } else if(strcmp(line, "mouse") == 0) { + opt.mouse = bool_value(value); } else if(strcmp(line, "sball") == 0) { opt.sball = bool_value(value); } else if(strcmp(line, "vsync") == 0) { diff --git a/src/cfgopt.h b/src/cfgopt.h index 0c302a6..5172d20 100644 --- a/src/cfgopt.h +++ b/src/cfgopt.h @@ -4,7 +4,7 @@ struct options { const char *start_scr; int music; - int sball; + int mouse, sball; int vsync; int dbginfo; }; diff --git a/src/demo.c b/src/demo.c index 77c3e80..7067ccd 100644 --- a/src/demo.c +++ b/src/demo.c @@ -14,12 +14,16 @@ #include "tinyfps.h" #include "util.h" +#define MOUSE_TIMEOUT 1200 + +/* #define FB_WIDTH 320 #define FB_HEIGHT 240 int fb_width = FB_WIDTH; int fb_height = FB_HEIGHT; int fb_bpp = 16; +*/ uint16_t *fb_pixels, *vmem; unsigned long time_msec; int mouse_x, mouse_y; @@ -27,6 +31,10 @@ unsigned int mouse_bmask; float sball_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; +static unsigned long last_mouse_move; +static int prev_mx, prev_my, mouse_dx, mouse_dy; +static unsigned int bmask_diff, prev_bmask; + static unsigned long nframes; static int con_active; @@ -60,7 +68,7 @@ int demo_init(int argc, char **argv) if(g3d_init() == -1) { return -1; } - g3d_framebuffer(fb_width, fb_height, fb_pixels); + g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels); if(opt.music) { if(music_open("data/test.mod") == -1) { @@ -83,7 +91,7 @@ int demo_init(int argc, char **argv) } /* clear the framebuffer at least once */ - memset(fb_pixels, 0, fb_width * fb_height * fb_bpp / CHAR_BIT); + memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * FB_BPP / CHAR_BIT); if(opt.music) { music_play(); @@ -107,6 +115,18 @@ void demo_cleanup(void) void demo_draw(void) { + if(opt.mouse) { + mouse_dx = mouse_x - prev_mx; + mouse_dy = mouse_y - prev_my; + prev_mx = mouse_x; + prev_my = mouse_y; + bmask_diff = mouse_bmask ^ prev_bmask; + prev_bmask = mouse_bmask; + if(mouse_dx | mouse_dy) { + last_mouse_move = time_msec; + } + } + if(opt.music) { music_update(); } @@ -119,6 +139,7 @@ void demo_draw(void) /* called by swap_buffers just before the actual swap */ void demo_post_draw(void *pixels) { + char buf[32]; if(opt.dbginfo) { drawFps(pixels); if(dbg_curscr_name) { @@ -130,61 +151,8 @@ void demo_post_draw(void *pixels) con_draw(pixels); } - draw_mouse_pointer(pixels); -} - -#define DEST(x, y) dest[(y) * FB_WIDTH + (x)] -void draw_mouse_pointer(uint16_t *fb) -{ - uint16_t *dest = fb + mouse_y * FB_WIDTH + mouse_x; - int ylines = FB_HEIGHT - mouse_y; - - switch(ylines) { - default: - case 10: - DEST(0, 9) = 0xffff; - case 9: - DEST(0, 8) = 0xffff; - DEST(1, 8) = 0xffff; - case 8: - DEST(0, 7) = 0xffff; - DEST(2, 7) = 0xffff; - DEST(1, 7) = 0; - case 7: - DEST(6, 6) = 0xffff; - DEST(0, 6) = 0xffff; - DEST(3, 6) = 0xffff; - DEST(4, 6) = 0xffff; - DEST(5, 6) = 0xffff; - DEST(1, 6) = 0; - DEST(2, 6) = 0; - case 6: - DEST(5, 5) = 0xffff; - DEST(0, 5) = 0xffff; - DEST(1, 5) = 0; - DEST(2, 5) = 0; - DEST(3, 5) = 0; - DEST(4, 5) = 0; - case 5: - DEST(4, 4) = 0xffff; - DEST(0, 4) = 0xffff; - DEST(1, 4) = 0; - DEST(2, 4) = 0; - DEST(3, 4) = 0; - case 4: - DEST(3, 3) = 0xffff; - DEST(0, 3) = 0xffff; - DEST(1, 3) = 0; - DEST(2, 3) = 0; - case 3: - DEST(2, 2) = 0xffff; - DEST(0, 2) = 0xffff; - DEST(1, 2) = 0; - case 2: - DEST(1, 1) = 0xffff; - DEST(0, 1) = 0xffff; - case 1: - DEST(0, 0) = 0xffff; + if(opt.mouse && time_msec - last_mouse_move < MOUSE_TIMEOUT) { + cs_mouseptr(pixels, mouse_x, mouse_y); } } @@ -263,34 +231,25 @@ void demo_keyboard(int key, int press) void mouse_orbit_update(float *theta, float *phi, float *dist) { - static int prev_mx, prev_my; - static unsigned int prev_bmask; - if(mouse_bmask) { - if((mouse_bmask ^ prev_bmask) == 0) { - int dx = mouse_x - prev_mx; - int dy = mouse_y - prev_my; + if(bmask_diff == 0) { - if(dx || dy) { + if(mouse_dx | mouse_dy) { if(mouse_bmask & MOUSE_BN_LEFT) { float p = *phi; - *theta += dx * 1.0; - p += dy * 1.0; + *theta += mouse_dx * 1.0; + p += mouse_dy * 1.0; if(p < -90) p = -90; if(p > 90) p = 90; *phi = p; } if(mouse_bmask & MOUSE_BN_RIGHT) { - *dist += dy * 0.5; + *dist += mouse_dy * 0.5; if(*dist < 0) *dist = 0; } } } } - - prev_mx = mouse_x; - prev_my = mouse_y; - prev_bmask = mouse_bmask; } diff --git a/src/demo.h b/src/demo.h index ff58caa..349cc53 100644 --- a/src/demo.h +++ b/src/demo.h @@ -3,7 +3,10 @@ #include "inttypes.h" -extern int fb_width, fb_height, fb_bpp; +/*extern int fb_width, fb_height, fb_bpp;*/ +#define FB_WIDTH 320 +#define FB_HEIGHT 240 +#define FB_BPP 16 extern uint16_t *fb_pixels; /* system-RAM pixel buffer: use swap_buffers(fb_pixels) */ extern uint16_t *vmem; /* visible video memory pointer */ @@ -70,7 +73,9 @@ void cs_confont(void *fb, int x, int y, int idx); /* helper to print text with cs_font */ void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str); -#define cs_dputs(fb, x, y, idx) cs_puts_font(cs_dbgfont, 9, fb, x, y, idx) -#define cs_cputs(fb, x, y, idx) cs_puts_font(cs_confont, 6, fb, x, y, idx) +#define cs_dputs(fb, x, y, str) cs_puts_font(cs_dbgfont, 9, fb, x, y, str) +#define cs_cputs(fb, x, y, str) cs_puts_font(cs_confont, 6, fb, x, y, str) + +#define cs_mouseptr(fb, x, y) cs_dbgfont(fb, x, y, 127 - ' ') #endif /* DEMO_H_ */ diff --git a/src/dos/main.c b/src/dos/main.c index 4d2f7fa..5d840b1 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -23,7 +23,6 @@ static int handle_sball_event(sball_event *ev); static void recalc_sball_matrix(float *xform); static int quit; -static int use_mouse; static long fbsize; static int use_sball; @@ -36,7 +35,7 @@ int main(int argc, char **argv) __djgpp_nearptr_enable(); #endif - fbsize = fb_width * fb_height * fb_bpp / 8; + fbsize = FB_WIDTH * FB_HEIGHT * FB_BPP / 8; init_logger("demo.log"); @@ -45,28 +44,30 @@ int main(int argc, char **argv) kb_init(32); #endif - if((use_mouse = have_mouse())) { - printf("initializing mouse input\n"); - set_mouse_limits(0, 0, fb_width, fb_height); - set_mouse(fb_width / 2, fb_height / 2); - } - /* now start_loadscr sets up fb_pixels to the space used by the loading image, * so no need to allocate another framebuffer */ #if 0 /* allocate a couple extra rows as a guard band, until we fucking fix the rasterizer */ - if(!(fb_pixels = malloc(fbsize + (fb_width * fb_bpp / 8) * 2))) { + if(!(fb_pixels = malloc(fbsize + (FB_WIDTH * FB_BPP / 8) * 2))) { fprintf(stderr, "failed to allocate backbuffer\n"); return 1; } - fb_pixels += fb_width; + fb_pixels += FB_WIDTH; #endif - if(!(vmem = set_video_mode(fb_width, fb_height, fb_bpp, 1))) { + if(!(vmem = set_video_mode(FB_WIDTH, FB_HEIGHT, FB_BPP, 1))) { return 1; } + if(opt.mouse) { + if((opt.mouse = have_mouse())) { + printf("initializing mouse input\n"); + set_mouse_limits(0, 0, FB_WIDTH - 1, FB_HEIGHT - 1); + set_mouse(FB_WIDTH / 2, FB_HEIGHT / 2); + } + } + if(demo_init(argc, argv) == -1) { set_text_mode(); return 1; @@ -91,7 +92,7 @@ int main(int argc, char **argv) #endif if(quit) goto break_evloop; - if(use_mouse) { + if(opt.mouse) { mouse_bmask = read_mouse(&mouse_x, &mouse_y); } if(use_sball && sball_pending()) { diff --git a/src/gfxutil.c b/src/gfxutil.c index a8d7edc..259b56d 100644 --- a/src/gfxutil.c +++ b/src/gfxutil.c @@ -101,7 +101,7 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color) int i, dx, dy, x_inc, y_inc, error; unsigned short *fb = fb_pixels; - fb += y0 * fb_width + x0; + fb += y0 * FB_WIDTH + x0; dx = x1 - x0; dy = y1 - y0; @@ -113,9 +113,9 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color) dx = -dx; } if(dy >= 0) { - y_inc = fb_width; + y_inc = FB_WIDTH; } else { - y_inc = -fb_width; + y_inc = -FB_WIDTH; dy = -dy; } diff --git a/src/scr/bump.c b/src/scr/bump.c index a595ba6..2761c7d 100644 --- a/src/scr/bump.c +++ b/src/scr/bump.c @@ -62,7 +62,7 @@ static int init(void) const int bigLightSize = BIG_LIGHT_WIDTH * BIG_LIGHT_HEIGHT; const int particleLightSize = PARTICLE_LIGHT_WIDTH * PARTICLE_LIGHT_HEIGHT; - const int fb_size = fb_width * fb_height; + const int fb_size = FB_WIDTH * FB_HEIGHT; /* Just some parameters to temporary test the colors of 3 lights * if every light uses it's own channel bits, it's better @@ -91,29 +91,29 @@ static int init(void) /* Blur to smooth */ for (j = 0; j < numBlurs; j++) for (i = 0; i < fb_size; i++) - heightmap[i] = (heightmap[abs((i - 1) % fb_size)] + heightmap[abs((i + 1) % fb_size)] + heightmap[abs((i - fb_width) % fb_size)] + heightmap[abs((i + fb_width) % fb_size)]) >> 2; + heightmap[i] = (heightmap[abs((i - 1) % fb_size)] + heightmap[abs((i + 1) % fb_size)] + heightmap[abs((i - FB_WIDTH) % fb_size)] + heightmap[abs((i + FB_WIDTH) % fb_size)]) >> 2; /* Inclination precalculation */ i = 0; - for (y = 0; y < fb_height; y++) + for (y = 0; y < FB_HEIGHT; y++) { - for (x = 0; x < fb_width; x++) + for (x = 0; x < FB_WIDTH; x++) { const float offsetPower = 0.75f; int dx, dy, xp, yp; dx = i < fb_size - 1 ? (int)((heightmap[i] - heightmap[i + 1]) * offsetPower) : 0; - dy = i < fb_size - fb_width ? (int)((heightmap[i] - heightmap[i + fb_width]) * offsetPower) : 0; + dy = i < fb_size - FB_WIDTH ? (int)((heightmap[i] - heightmap[i + FB_WIDTH]) * offsetPower) : 0; xp = x + dx; if (xp < 0) xp = 0; - if (xp > fb_width - 1) xp = fb_width - 1; + if (xp > FB_WIDTH - 1) xp = FB_WIDTH - 1; yp = y + dy; if (yp < 0) yp = 0; - if (yp > fb_height - 1) yp = fb_height - 1; + if (yp > FB_HEIGHT - 1) yp = FB_HEIGHT - 1; - bumpOffset[i++] = yp * fb_width + xp; + bumpOffset[i++] = yp * FB_WIDTH + xp; } } @@ -182,12 +182,12 @@ static void eraseArea(struct point *p, int width, int height) if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; - if (x1 > fb_width) x1 = fb_width; - if (y1 > fb_height) y1 = fb_height; + if (x1 > FB_WIDTH) x1 = FB_WIDTH; + if (y1 > FB_HEIGHT) y1 = FB_HEIGHT; dx = x1 - x0; - dst = lightmap + y0 * fb_width + x0; + dst = lightmap + y0 * FB_WIDTH + x0; for (y = y0; y < y1; y++) { @@ -195,7 +195,7 @@ static void eraseArea(struct point *p, int width, int height) { *dst++ = 0; } - dst += fb_width - dx; + dst += FB_WIDTH - dx; } } @@ -225,12 +225,12 @@ static void renderLight(struct point *p, int width, int height, unsigned short * y0 = 0; } - if (x1 > fb_width) x1 = fb_width; - if (y1 > fb_height) y1 = fb_height; + if (x1 > FB_WIDTH) x1 = FB_WIDTH; + if (y1 > FB_HEIGHT) y1 = FB_HEIGHT; dx = x1 - x0; - dst = lightmap + y0 * fb_width + x0; + dst = lightmap + y0 * FB_WIDTH + x0; src = light + yl * width + xl; for (y = y0; y < y1; y++) @@ -239,7 +239,7 @@ static void renderLight(struct point *p, int width, int height, unsigned short * { *dst++ |= *src++; } - dst += fb_width - dx; + dst += FB_WIDTH - dx; src += width - dx; } } @@ -272,8 +272,8 @@ static void animateLights() float tt = 1.0f - sin(dt); float disperse = tt * 64.0f; - center.x = (fb_width >> 1) - (BIG_LIGHT_WIDTH / 2); - center.y = (fb_height >> 1) - (BIG_LIGHT_HEIGHT / 2); + center.x = (FB_WIDTH >> 1) - (BIG_LIGHT_WIDTH / 2); + center.y = (FB_HEIGHT >> 1) - (BIG_LIGHT_HEIGHT / 2); bigLightPoint[0].x = center.x + sin(1.2f * dt) * (144.0f + disperse); bigLightPoint[0].y = center.y + sin(0.8f * dt) * (148.0f + disperse); @@ -288,7 +288,7 @@ static void animateLights() static void renderBump(unsigned short *vram) { int i; - for (i = 0; i < fb_width * fb_height; i++) + for (i = 0; i < FB_WIDTH * FB_HEIGHT; i++) { unsigned short c = lightmap[bumpOffset[i]]; *vram++ = c; @@ -302,8 +302,8 @@ static void animateParticles() float dt = (float)(time_msec - startingTime) / 2000.0f; float tt = sin(dt); - center.x = (fb_width >> 1) - (PARTICLE_LIGHT_WIDTH / 2); - center.y = (fb_height >> 1) - (PARTICLE_LIGHT_HEIGHT / 2); + center.x = (FB_WIDTH >> 1) - (PARTICLE_LIGHT_WIDTH / 2); + center.y = (FB_HEIGHT >> 1) - (PARTICLE_LIGHT_HEIGHT / 2); for (i = 0; i < NUM_PARTICLES; i++) { @@ -314,7 +314,7 @@ static void animateParticles() static void draw(void) { - memset(lightmap, 0, fb_width * fb_height * sizeof(*lightmap)); + memset(lightmap, 0, FB_WIDTH * FB_HEIGHT * sizeof(*lightmap)); /*eraseLights();*/ animateLights(); diff --git a/src/scr/fract.c b/src/scr/fract.c index 6eeb678..09e3bfb 100644 --- a/src/scr/fract.c +++ b/src/scr/fract.c @@ -51,15 +51,15 @@ static void draw(void) cx = mouse_x; cy = mouse_y; - for(i=0; i> 3) | ((pidx >> 2) << 5) | ((pidx >> 3) << 11); } } pixels = fb_pixels; - pixels[mouse_y * fb_width + mouse_x] = 0xffe; + pixels[mouse_y * FB_WIDTH + mouse_x] = 0xffe; swap_buffers(0); } @@ -74,10 +74,10 @@ static int julia(long x, long y, long cx, long cy, int max_iter) int i; /* convert to fixed point roughly [-1, 1] */ - x = (normalize_coord(x, fb_width) >> 8) * xscale_24x8; - y = (normalize_coord(y, fb_height) >> 8) * yscale_24x8; - cx = (normalize_coord(cx, fb_width) >> 8) * xscale_24x8; - cy = (normalize_coord(cy, fb_height) >> 8) * yscale_24x8; + x = (normalize_coord(x, FB_WIDTH) >> 8) * xscale_24x8; + y = (normalize_coord(y, FB_HEIGHT) >> 8) * yscale_24x8; + cx = (normalize_coord(cx, FB_WIDTH) >> 8) * xscale_24x8; + cy = (normalize_coord(cy, FB_HEIGHT) >> 8) * yscale_24x8; for(i=0; i> 1); + unsigned int *pixels = (unsigned int*)pix + starty * (FB_WIDTH >> 1); for(i=0; i>1); j++) { diff --git a/src/sdl/main.c b/src/sdl/main.c index 08bddf8..f2487cf 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -41,23 +41,23 @@ int main(int argc, char **argv) printf("Framebuffer scaling x%d\n", fbscale); } - xsz = fb_width * fbscale; - ysz = fb_height * fbscale; + xsz = FB_WIDTH * fbscale; + ysz = FB_HEIGHT * fbscale; /* now start_loadscr sets up fb_pixels to the space used by the loading image, * so no need to allocate another framebuffer */ #if 0 /* allocate 1 extra row as a guard band, until we fucking fix the rasterizer */ - if(!(fb_pixels = malloc(fb_width * (fb_height + 1) * fb_bpp / CHAR_BIT))) { + if(!(fb_pixels = malloc(FB_WIDTH * (FB_HEIGHT + 1) * FB_BPP / CHAR_BIT))) { fprintf(stderr, "failed to allocate virtual framebuffer\n"); return 1; } #endif SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); - if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, fb_bpp, sdl_flags))) { - fprintf(stderr, "failed to set video mode %dx%d %dbpp\n", fb_width, fb_height, fb_bpp); + if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, FB_BPP, sdl_flags))) { + fprintf(stderr, "failed to set video mode %dx%d %dbpp\n", FB_WIDTH, FB_HEIGHT, FB_BPP); /*free(fb_pixels);*/ SDL_Quit(); return 1; @@ -134,8 +134,8 @@ void swap_buffers(void *pixels) sptr = fb_pixels; dptr = (unsigned short*)fbsurf->pixels + (fbsurf->w - xsz) / 2; - for(i=0; iw - fb_width) * fbscale; + dptr += (fbsurf->w - FB_WIDTH) * fbscale; } if(SDL_MUSTLOCK(fbsurf)) { @@ -215,7 +215,7 @@ static void toggle_fullscreen(void) SDL_Surface *newsurf; unsigned int newflags = sdl_flags ^ SDL_FULLSCREEN; - if(!(newsurf = SDL_SetVideoMode(xsz, ysz, fb_bpp, newflags))) { + if(!(newsurf = SDL_SetVideoMode(xsz, ysz, FB_BPP, newflags))) { fprintf(stderr, "failed to go %s\n", newflags & SDL_FULLSCREEN ? "fullscreen" : "windowed"); return; } diff --git a/src/tinyfps.c b/src/tinyfps.c index d7d1f80..41102e6 100644 --- a/src/tinyfps.c +++ b/src/tinyfps.c @@ -71,7 +71,7 @@ static void drawFont(unsigned char decimal, int posX, int posY, unsigned char zo unsigned short *fontData = (unsigned short*)&miniDecimalFonts[decimal * FPS_FONT_WIDTH * FPS_FONT_HEIGHT]; - vram += posY * fb_width + posX; + vram += posY * FB_WIDTH + posX; if (zoom < 1) zoom = 1; if (zoom > 4) zoom = 4; @@ -88,13 +88,13 @@ static void drawFont(unsigned char decimal, int posX, int posY, unsigned char zo { for (k=0; k