nuclear@6: #include "config.h" nuclear@5: #include "game.h" nuclear@5: #include "gbasys.h" nuclear@8: #include "x3d.h" nuclear@8: #include "sincos.h" nuclear@8: #include "fixed.h" nuclear@9: #include "palman.h" nuclear@13: #include "ggen.h" nuclear@9: nuclear@14: extern int dbg_fill_dump; nuclear@14: nuclear@9: static void draw_rect(int x, int y, int w, int h, uint16_t color); nuclear@5: nuclear@5: #define X16INT(x) ((x) << 16) nuclear@12: #define X16FLT(x) ((int32_t)((x) * 65536.0)) nuclear@5: nuclear@8: static const int32_t poly[] = { nuclear@13: X16INT(-1), X16INT(-1), 0, nuclear@13: X16INT(-1), X16INT(1), 0, nuclear@13: X16INT(1), X16INT(1), 0, nuclear@13: X16INT(1), X16INT(-1), 0, nuclear@13: X16INT(1), X16INT(-1), 0, nuclear@13: X16INT(1), X16INT(1), 0, nuclear@13: X16INT(-1), X16INT(1), 0, nuclear@13: X16INT(-1), X16INT(-1), 0 nuclear@13: }; nuclear@13: static const int32_t colors[] = { nuclear@13: 65535, 0, 0, 65535, 0, 0, 65535, 0, 0, 65535, 0, 0, nuclear@13: 65536, 65535, 0, 65536, 65535, 0, 65536, 65535, 0, 65536, 65535, 0 nuclear@5: }; nuclear@8: static const short vcount = sizeof poly / sizeof *poly / 3; nuclear@8: nuclear@13: static struct mesh box; nuclear@13: nuclear@13: nuclear@8: int game_init(void) nuclear@8: { nuclear@8: sincos_init(); nuclear@9: #ifdef PALMODE nuclear@9: palman_init(); nuclear@9: #endif nuclear@8: nuclear@12: x3d_projection(45.0, (WIDTH << 16) / HEIGHT, 65536 / 2, 65536 * 500); nuclear@12: nuclear@13: init_mesh(&box); nuclear@13: gen_box(&box); nuclear@13: nuclear@8: return 0; nuclear@8: } nuclear@5: nuclear@13: static int32_t cam_theta, cam_phi = 25 << 16; nuclear@9: static short keyrot; nuclear@9: static int autorot = 1; nuclear@9: nuclear@5: void game_draw(void) nuclear@5: { nuclear@8: unsigned long msec = get_millisec(); nuclear@8: nuclear@5: clear_buffer(back_buffer, 0); nuclear@5: nuclear@8: x3d_load_identity(); nuclear@12: /*x3d_translate(-itox16(WIDTH / 2), -itox16(HEIGHT / 2), 0); nuclear@9: if(autorot) { nuclear@9: x3d_rotate((msec / 64) << 16, 0, 0, 65536); nuclear@9: } else { nuclear@9: x3d_rotate(keyrot << 16, 0, 0, 65536); nuclear@9: } nuclear@12: x3d_translate(itox16(WIDTH / 2), itox16(HEIGHT / 2), 0);*/ nuclear@12: nuclear@14: x3d_translate(0, 0, X16INT(6)); nuclear@13: x3d_rotate(cam_phi, 65536, 0, 0); nuclear@14: if(autorot) { nuclear@14: x3d_rotate((msec / 64) << 16, 0, 65536, 0); nuclear@14: } else { nuclear@14: x3d_rotate(cam_theta, 0, 65536, 0); nuclear@14: } nuclear@6: nuclear@9: #ifdef PALMODE nuclear@9: x3d_color_index(255); nuclear@9: #else nuclear@8: x3d_color(65536, 65536, 65536); nuclear@9: #endif nuclear@13: nuclear@13: draw_mesh(&box); nuclear@13: nuclear@13: /* nuclear@13: x3d_vertex_array(vcount, poly); nuclear@13: x3d_color_array(vcount, colors); nuclear@13: x3d_draw(X3D_QUADS, vcount); nuclear@13: x3d_color_array(0, 0); nuclear@8: nuclear@9: #ifdef PALMODE nuclear@9: x3d_color_index(RGBPAL(0, 255, 0)); nuclear@9: #else nuclear@8: x3d_color(0, 65536, 0); nuclear@9: #endif nuclear@13: nuclear@12: x3d_draw(X3D_POINTS, vcount); nuclear@9: x3d_vertex_array(0, 0); nuclear@13: */ nuclear@6: nuclear@5: flip(); nuclear@5: } nuclear@5: nuclear@5: void game_keyb(int key, int pressed) nuclear@5: { nuclear@9: if(!pressed) return; nuclear@9: nuclear@9: switch(key) { nuclear@9: case KEY_LEFT: nuclear@14: cam_theta += 65536; nuclear@9: break; nuclear@9: nuclear@9: case KEY_RIGHT: nuclear@14: cam_theta -= 65536; nuclear@14: break; nuclear@14: nuclear@14: case KEY_UP: nuclear@14: cam_phi += 65536; nuclear@14: break; nuclear@14: nuclear@14: case KEY_DOWN: nuclear@14: cam_phi -= 65536; nuclear@9: break; nuclear@9: nuclear@9: case KEY_A: nuclear@9: autorot = !autorot; nuclear@9: break; nuclear@9: nuclear@14: case KEY_SELECT: nuclear@14: dbg_fill_dump = 1; nuclear@14: break; nuclear@14: nuclear@9: default: nuclear@9: break; nuclear@9: } nuclear@5: } nuclear@9: nuclear@9: #ifdef PALMODE nuclear@9: #define ROWADV (WIDTH / 2) nuclear@9: #else nuclear@9: #define ROWADV WIDTH nuclear@9: #endif nuclear@9: nuclear@9: static void draw_rect(int x, int y, int w, int h, uint16_t color) nuclear@9: { nuclear@9: int i, xsz = w, ysz = h; nuclear@9: uint16_t *pixels = back_buffer->pixels; nuclear@9: uint16_t *topleft, *topright, *botleft; nuclear@9: nuclear@9: #ifdef PALMODE nuclear@9: pixels += (y * WIDTH + x) / 2; nuclear@9: topleft = pixels; nuclear@9: topright = (uint16_t*)back_buffer->pixels + (y * WIDTH + x + w - 1) / 2; nuclear@9: nuclear@9: color |= color << 8; nuclear@9: xsz /= 2; nuclear@9: #else nuclear@9: pixels += y * WIDTH + x; nuclear@9: topleft = pixels; nuclear@9: topright = topleft + w - 1; nuclear@9: #endif nuclear@9: botleft = topleft + (ysz - 1) * ROWADV; nuclear@9: nuclear@9: #ifdef PALMODE nuclear@9: if(x & 1) { nuclear@9: *topleft = (*topleft & 0xff) | (color & 0xff00); nuclear@9: *botleft = (*topleft & 0xff) | (color & 0xff00); nuclear@9: ++topleft; nuclear@9: ++botleft; nuclear@9: xsz -= 1; nuclear@9: } nuclear@9: #endif nuclear@9: for(i=0; i