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
data:
@tools/procdata
endif
+
+.PHONY: strip
+strip: $(bin)
+ $(TOOLPREFIX)strip $(bin)
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)
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)
#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;
};
{
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;
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;
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;
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;
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);
G3D_CLIP_PLANE3 = 0x008000,
G3D_TEXTURE_MAT = 0x010000,
+ G3D_SPECULAR = 0x020000,
G3D_ALL = 0x7fffffff
};
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);
struct options opt = {
0, /* start_scr */
1, /* music */
+ 0, /* mouse */
0, /* sball */
- 1, /* vsync */
+ 0, /* vsync */
0 /* dbginfo */
};
#else
struct options opt = {
0, /* start_scr */
0, /* music */
+ 1, /* mouse */
0, /* sball */
- 1, /* vsync */
+ 0, /* vsync */
1 /* dbginfo */
};
#endif
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) {
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) {
struct options {
const char *start_scr;
int music;
- int sball;
+ int mouse, sball;
int vsync;
int dbginfo;
};
#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;
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;
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) {
}
/* 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();
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();
}
/* 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) {
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);
}
}
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;
}
#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 */
/* 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_ */
static void recalc_sball_matrix(float *xform);
static int quit;
-static int use_mouse;
static long fbsize;
static int use_sball;
__djgpp_nearptr_enable();
#endif
- fbsize = fb_width * fb_height * fb_bpp / 8;
+ fbsize = FB_WIDTH * FB_HEIGHT * FB_BPP / 8;
init_logger("demo.log");
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;
#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()) {
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;
dx = -dx;
}
if(dy >= 0) {
- y_inc = fb_width;
+ y_inc = FB_WIDTH;
} else {
- y_inc = -fb_width;
+ y_inc = -FB_WIDTH;
dy = -dy;
}
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
/* 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;
}
}
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++)
{
{
*dst++ = 0;
}
- dst += fb_width - dx;
+ dst += FB_WIDTH - dx;
}
}
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++)
{
*dst++ |= *src++;
}
- dst += fb_width - dx;
+ dst += FB_WIDTH - dx;
src += width - dx;
}
}
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);
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;
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++)
{
static void draw(void)
{
- memset(lightmap, 0, fb_width * fb_height * sizeof(*lightmap));
+ memset(lightmap, 0, FB_WIDTH * FB_HEIGHT * sizeof(*lightmap));
/*eraseLights();*/
animateLights();
cx = mouse_x;
cy = mouse_y;
- for(i=0; i<fb_height; i++) {
- for(j=0; j<fb_width; j++) {
+ for(i=0; i<FB_HEIGHT; i++) {
+ for(j=0; j<FB_WIDTH; j++) {
unsigned char pidx = julia(j, i, cx, cy, max_iter) & 0xff;
*pixels++ = (pidx >> 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);
}
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<max_iter; i++) {
/* z_n = z_{n-1}**2 + c */
return -1;
}
- smokebuf_size = fb_width * fb_height * sizeof *cur_smokebuf;
+ smokebuf_size = FB_WIDTH * FB_HEIGHT * sizeof *cur_smokebuf;
if(!(cur_smokebuf = malloc(smokebuf_size * 2))) {
perror("failed to allocate smoke framebuffer");
return -1;
}
- prev_smokebuf = cur_smokebuf + fb_width * fb_height;
+ prev_smokebuf = cur_smokebuf + FB_WIDTH * FB_HEIGHT;
return 0;
}
memcpy(cur_smokebuf, prev_smokebuf, smokebuf_size);
- g3d_framebuffer(fb_width, fb_height, cur_smokebuf);
+ g3d_framebuffer(FB_WIDTH, FB_HEIGHT, cur_smokebuf);
draw_smktxt(stx);
- g3d_framebuffer(fb_width, fb_height, fb_pixels);
+ g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
dest = fb_pixels;
src = cur_smokebuf;
- for(i=0; i<fb_height; i++) {
- for(j=0; j<fb_width; j++) {
+ for(i=0; i<FB_HEIGHT; i++) {
+ for(j=0; j<FB_WIDTH; j++) {
unsigned int alpha = *src++;
*dest++ = PACK_RGB16(alpha, alpha, alpha);
}
}
/*perf_start();*/
- blur_grey_horiz(prev_smokebuf, cur_smokebuf, fb_width, fb_height, BLUR_RAD, 240);
+ blur_grey_horiz(prev_smokebuf, cur_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
/*
perf_end();
printf("blur perf: %lu\n", (unsigned long)perf_interval_count);
*/
- blur_grey_vert(cur_smokebuf, prev_smokebuf, fb_width, fb_height, BLUR_RAD, 240);
+ blur_grey_vert(cur_smokebuf, prev_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
swap_smoke_buffers();
msec = get_msec();
#define MAX_DISPLACEMENT 16
#define MIN_SCROLL PIXEL_PADDING
-#define MAX_SCROLL (backgroundW - fb_width - MIN_SCROLL)
+#define MAX_SCROLL (backgroundW - FB_WIDTH - MIN_SCROLL)
#define FAR_SCROLL_SPEED 15.0f
#define NEAR_SCROLL_SPEED 120.0f
static void draw(void)
{
- int scroll = MIN_SCROLL + (MAX_SCROLL - MIN_SCROLL) * mouse_x / fb_width;
+ int scroll = MIN_SCROLL + (MAX_SCROLL - MIN_SCROLL) * mouse_x / FB_WIDTH;
unsigned short *dst = backBuffer + PIXEL_PADDING;
unsigned short *src = background + scroll;
int scanline = 0;
/* First, render the horizon */
for (scanline = 0; scanline < HORIZON_HEIGHT; scanline++) {
- memcpy(dst, src, fb_width * 2);
+ memcpy(dst, src, FB_WIDTH * 2);
src += backgroundW;
dst += BB_SIZE;
}
src -= PIXEL_PADDING; /* We want to also fill the PADDING pixels here */
dst = backBuffer + (HORIZON_HEIGHT + 1) * BB_SIZE;
for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) {
- memcpy(dst, src, (fb_width + PIXEL_PADDING) * 2);
+ memcpy(dst, src, (FB_WIDTH + PIXEL_PADDING) * 2);
src += backgroundW;
dst += BB_SIZE;
}
/* Blit reflections first, to be displaced */
- for (i = 0; i < 5; i++) rleBlitScaleInv(backBuffer + PIXEL_PADDING, fb_width, fb_height, BB_SIZE, rlePropeller, 134 + (i-3) * 60, 200, 1.0f, 1.8f);
+ for (i = 0; i < 5; i++) rleBlitScaleInv(backBuffer + PIXEL_PADDING, FB_WIDTH, FB_HEIGHT, BB_SIZE, rlePropeller, 134 + (i-3) * 60, 200, 1.0f, 1.8f);
/* Perform displacement */
dst = backBuffer + HORIZON_HEIGHT * BB_SIZE + PIXEL_PADDING;
sc = scrollTableRounded[scanline];
accum = 0;
- for (i = 0; i < fb_width; i++) {
+ for (i = 0; i < FB_WIDTH; i++) {
/* Try to immitate modulo without the division */
if (i == md) accum += md;
scrolledIndex = i - accum + sc;
*dst++ = src[i + d];
}
src += backgroundW;
- dst += BB_SIZE - fb_width;
+ dst += BB_SIZE - FB_WIDTH;
dispScanline += backgroundW;
}
/* Then after displacement, blit the objects */
- for (i = 0; i < 5; i++) rleBlit(backBuffer + PIXEL_PADDING, fb_width, fb_height, BB_SIZE, rlePropeller, 134 + (i-3) * 60, 100);
+ for (i = 0; i < 5; i++) rleBlit(backBuffer + PIXEL_PADDING, FB_WIDTH, FB_HEIGHT, BB_SIZE, rlePropeller, 134 + (i-3) * 60, 100);
/* Blit effect to framebuffer */
src = backBuffer + PIXEL_PADDING;
dst = fb_pixels;
- for (scanline = 0; scanline < fb_height; scanline++) {
- memcpy(dst, src, fb_width * 2);
+ for (scanline = 0; scanline < FB_HEIGHT; scanline++) {
+ memcpy(dst, src, FB_WIDTH * 2);
src += BB_SIZE;
- dst += fb_width;
+ dst += FB_WIDTH;
}
swap_buffers(0);
update();
- memset(fb_pixels, 0, fb_width * fb_height * 2);
+ memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2);
g3d_matrix_mode(G3D_MODELVIEW);
g3d_load_identity();
g3d_mult_matrix(sball_matrix);
}
- /*memset(fb_pixels, 0, fb_width * fb_height * 2);*/
+ /*memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2);*/
g3d_polygon_mode(G3D_FLAT);
g3d_enable(G3D_TEXTURE_2D);
update();
- memset(fb_pixels, 0, fb_width * fb_height * 2);
+ memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2);
for(i=0; i<120; i++) {
for(j=0; j<160; j++) {
draw_mesh(&mmesh);
- g3d_viewport(0, 0, fb_width, fb_height);
+ g3d_viewport(0, 0, FB_WIDTH, FB_HEIGHT);
swap_buffers(fb_pixels);
}
unsigned int *vram32 = (unsigned int*)fb_pixels;
unsigned int p0, p1;
- for (y = 0; y < fb_height; y++)
+ for (y = 0; y < FB_HEIGHT; y++)
{
s1 = psin2[y + t2];
s2 = psin3[y + t1];
- for (x = 0; x < fb_width; x+=2)
+ for (x = 0; x < FB_WIDTH; x+=2)
{
c = psin1[x + t1] + s1 + psin3[x + y + t3] + psin1[psin2[x + t2] + s2 + t3];
p0 = plasmaPal[c];
#include "cfgopt.h"
#include "mesh.h"
#include "bsptree.h"
+#include "util.h"
static int init(void);
static void destroy(void);
}
*/
- gen_texture(&tex, 128, 128);
+ gen_texture(&tex, 64, 64);
#ifdef DEBUG_POLYFILL
- lowres_width = fb_width / LOWRES_SCALE;
- lowres_height = fb_height / LOWRES_SCALE;
+ lowres_width = FB_WIDTH / LOWRES_SCALE;
+ lowres_height = FB_HEIGHT / LOWRES_SCALE;
lowres_pixels = malloc(lowres_width * lowres_height * 2);
scr.draw = draw_debug;
#endif
update();
- memset(fb_pixels, 0, fb_width * fb_height * 2);
+ memset16(fb_pixels, PACK_RGB16(20, 30, 50), FB_WIDTH * FB_HEIGHT);
g3d_matrix_mode(G3D_MODELVIEW);
g3d_load_identity();
g3d_rotate(cam_theta, 0, 1, 0);
}
- g3d_light_pos(0, -10, 10, 20);
-
- g3d_mtl_diffuse(0.4, 0.7, 1.0);
+ g3d_light_dir(0, -10, 10, 10);
+ g3d_mtl_diffuse(1.0, 1.0, 1.0);
g3d_set_texture(tex.width, tex.height, tex.pixels);
if(use_bsp) {
draw_lowres_raster();
- g3d_framebuffer(fb_width, fb_height, fb_pixels);
+ g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
g3d_polygon_mode(G3D_WIRE);
draw_mesh(&cube);
for(i=0; i<lowres_height; i++) {
for(j=0; j<lowres_width; j++) {
- draw_huge_pixel(dptr, fb_width, *sptr++);
+ draw_huge_pixel(dptr, FB_WIDTH, *sptr++);
dptr += LOWRES_SCALE;
}
- dptr += fb_width * LOWRES_SCALE - fb_width;
+ dptr += FB_WIDTH * LOWRES_SCALE - FB_WIDTH;
}
}
for(i=0; i<ysz; i++) {
for(j=0; j<xsz; j++) {
- int val = i ^ j;
+ int val = (i << 2) ^ (j << 2);
+ uint16_t r = val;
+ uint16_t g = val << 1;
+ uint16_t b = val << 2;
- *pix++ = PACK_RGB16(val, val, val);
+ *pix++ = PACK_RGB16(r, g, b);
}
}
int i, j, n;
unsigned int *tmap;
unsigned char *fog;
- float aspect = (float)fb_width / (float)fb_height;
+ float aspect = (float)FB_WIDTH / (float)FB_HEIGHT;
- xsz = fb_width;
- ysz = fb_height;
+ xsz = FB_WIDTH;
+ ysz = FB_HEIGHT;
vxsz = xsz * VSCALE;
vysz = ysz * VSCALE;
int rest_lines = num_lines - draw_lines;
draw_tunnel_range(fb_pixels, xoffs, yoffs, starty, draw_lines, time_msec);
if(rest_lines) {
- memset(fb_pixels + resty * fb_width, 0, rest_lines * fb_width * 2);
+ memset(fb_pixels + resty * FB_WIDTH, 0, rest_lines * FB_WIDTH * 2);
}
}
unsigned char *fog = tunnel_fog + (starty + yoffs) * vxsz + xoffs;
long toffs = tm / 8;
- unsigned int *pixels = (unsigned int*)pix + starty * (fb_width >> 1);
+ unsigned int *pixels = (unsigned int*)pix + starty * (FB_WIDTH >> 1);
for(i=0; i<num_lines; i++) {
for(j=0; j<(xsz>>1); j++) {
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;
sptr = fb_pixels;
dptr = (unsigned short*)fbsurf->pixels + (fbsurf->w - xsz) / 2;
- for(i=0; i<fb_height; i++) {
- for(j=0; j<fb_width; j++) {
+ for(i=0; i<FB_HEIGHT; i++) {
+ for(j=0; j<FB_WIDTH; j++) {
int x, y;
unsigned short pixel = *sptr++;
}
dptr += fbscale;
}
- dptr += (fbsurf->w - fb_width) * fbscale;
+ dptr += (fbsurf->w - FB_WIDTH) * fbscale;
}
if(SDL_MUSTLOCK(fbsurf)) {
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;
}
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;
{
for (k=0; k<zoom; k++)
{
- *(vram + j * fb_width + k) ^= c;
+ *(vram + j * FB_WIDTH + k) ^= c;
}
}
}
vram += zoom;
}
- vram += (-FPS_FONT_WIDTH * zoom + fb_width * zoom);
+ vram += (-FPS_FONT_WIDTH * zoom + FB_WIDTH * zoom);
}
}
}
/*drawDecimal(fps, 4, 4, 2, vram);*/
/* Moving this on the lower left side of screen for now, since the lack of double buffering generates flickering for this atm */
- drawDecimal(fps, 4, fb_height - 12, 2, vram);
+ drawDecimal(fps, 4, FB_HEIGHT - 12, 2, vram);
}
void halt(void);
#pragma aux halt = "hlt";
+
+void memset16(void *ptr, int val, int count);
+#pragma aux memset16 = \
+ "rep stosw" \
+ parm[edi][eax][ecx];
#endif
#ifdef __GNUC__
#define halt() \
asm volatile("hlt")
+
+#define memset16(ptr, val, count) asm volatile ( \
+ "rep stosw\n\t" \
+ :: "D"(ptr), "a"(val), "c"(count))
#endif
#ifdef _MSC_VER
do { \
__asm { int 3 } \
} while(0)
+
+#define memset16(ptr, val, count) \
+ do { \
+ __asm { \
+ mov edi, ptr \
+ mov ecx, count \
+ mov eax, val \
+ rep stosw \
+ } \
+ } while(0)
#endif
#endif /* UTIL_H_ */