X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgamescr.c;h=bad3bec97eac09df3e4b00b2e6fda2e165742dbf;hb=79c636931d1f9bf844196e91be171b17bbe9c04f;hp=3b15a4a50f0f508658088c1ffceec8af8c25baae;hpb=41765ea063cbab26ae05e7259ffc8a7c85db2f5d;p=gbajam22 diff --git a/src/gamescr.c b/src/gamescr.c index 3b15a4a..bad3bec 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -6,105 +6,124 @@ #include "util.h" #include "intr.h" #include "input.h" +#include "player.h" +#include "gba.h" #include "sprite.h" #include "debug.h" #include "level.h" #include "xgl.h" #include "polyfill.h" +static int gamescr_start(void); +static void gamescr_stop(void); +static void gamescr_frame(void); +static void gamescr_vblank(void); + static void update(void); static void draw(void); -static void vblank(void); + +static struct screen gamescr = { + "game", + gamescr_start, + gamescr_stop, + gamescr_frame, + gamescr_vblank +}; static int nframes, num_vbl, backbuf; -static uint16_t *vram[] = { (uint16_t*)VRAM_LFB_FB0_ADDR, (uint16_t*)VRAM_LFB_FB1_ADDR }; +static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 }; static const char *testlvl = - "########\n" - "### s#\n" - "### ####\n" - "### #\n" - "## #\n" - "## #\n" - "## #\n" - "## ### #\n" - "## ### #\n" - "## #\n" - "#### ###\n" - "########\n"; - -static struct xvertex cube[] __attribute__((section(".rodata"))) = { - /* front */ - {-0x10000, -0x10000, -0x10000, 0, 0, -0x10000, 255}, - {0x10000, -0x10000, -0x10000, 0, 0, -0x10000, 255}, - {0x10000, 0x10000, -0x10000, 0, 0, -0x10000, 255}, - {-0x10000, 0x10000, -0x10000, 0, 0, -0x10000, 255}, - /* right */ - {0x10000, -0x10000, -0x10000, 0x10000, 0, 0, 128}, - {0x10000, -0x10000, 0x10000, 0x10000, 0, 0, 128}, - {0x10000, 0x10000, 0x10000, 0x10000, 0, 0, 128}, - {0x10000, 0x10000, -0x10000, 0x10000, 0, 0, 128}, - /* back */ - {0x10000, -0x10000, 0x10000, 0, 0, 0x10000, 200}, - {-0x10000, -0x10000, 0x10000, 0, 0, 0x10000, 200}, - {-0x10000, 0x10000, 0x10000, 0, 0, 0x10000, 200}, - {0x10000, 0x10000, 0x10000, 0, 0, 0x10000, 200}, - /* left */ - {-0x10000, -0x10000, 0x10000, -0x10000, 0, 0, 192}, - {-0x10000, -0x10000, -0x10000, -0x10000, 0, 0, 192}, - {-0x10000, 0x10000, -0x10000, -0x10000, 0, 0, 192}, - {-0x10000, 0x10000, 0x10000, -0x10000, 0, 0, 192}, - /* top */ - {-0x10000, 0x10000, -0x10000, 0, 0x10000, 0, 150}, - {0x10000, 0x10000, -0x10000, 0, 0x10000, 0, 150}, - {0x10000, 0x10000, 0x10000, 0, 0x10000, 0, 150}, - {-0x10000, 0x10000, 0x10000, 0, 0x10000, 0, 150}, - /* bottom */ - {0x10000, -0x10000, -0x10000, 0, -0x10000, 0, 210}, - {-0x10000, -0x10000, -0x10000, 0, -0x10000, 0, 210}, - {-0x10000, -0x10000, 0x10000, 0, -0x10000, 0, 210}, - {0x10000, -0x10000, 0x10000, 0, -0x10000, 0, 210} + "################\n" + "################\n" + "################\n" + "################\n" + "################\n" + "####### s#####\n" + "####### ########\n" + "####### #####\n" + "###### #####\n" + "###### #####\n" + "###### #####\n" + "###### ### #####\n" + "###### ### #####\n" + "###### #####\n" + "######## #######\n" + "################\n" + "################\n" + "################\n" + "################\n" + "################\n"; + +static struct xvertex tm_floor[] __attribute__((section(".rodata"))) = { + {0x10000, -0x10000, 0x10000, 0, 0x10000, 0, 210}, + {-0x10000, -0x10000, 0x10000, 0, 0x10000, 0, 210}, + {-0x10000, -0x10000, -0x10000, 0, 0x10000, 0, 210}, + {0x10000, -0x10000, -0x10000, 0, 0x10000, 0, 210} }; static struct level *lvl; -static int32_t cam_theta, cam_phi; +static struct player player; + -void gamescr(void) +struct screen *init_game_screen(void) { - unsigned char *fb; + return &gamescr; +} + +static int gamescr_start(void) +{ + int i; + uint16_t *cmap; - REG_DISPCNT = 4 | DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1; + gba_setmode(4, DISPCNT_BG2 | DISPCNT_OBJ | DISPCNT_FB1); - vblperf_setcolor(0xff); + vblperf_setcolor(1); lvl = init_level(testlvl); xgl_init(); - select_input(BN_DPAD); + init_player(&player, lvl); + player.phi = 0x100; + + cmap = gba_bgpal; + *cmap++ = 0; + for(i=1; i<255; i++) { + *cmap++ = rand(); + } + *cmap = 0xffff; + - mask(INTR_VBLANK); - screen_vblank = vblank; - unmask(INTR_VBLANK); + select_input(BN_DPAD | BN_A | BN_B); nframes = 0; - for(;;) { - backbuf = ++nframes & 1; - fb = (unsigned char*)vram[backbuf]; + return 0; +} + +static void gamescr_stop(void) +{ +} - polyfill_framebuffer(fb, 240, 160); - fillblock_16byte(fb, 0, 240 * 160 / 16); +static void gamescr_frame(void) +{ + unsigned char *fb; - update(); - draw(); + backbuf = ++nframes & 1; + fb = (unsigned char*)vram[backbuf]; - vblperf_end(); - wait_vblank(); - present(backbuf); - vblperf_begin(); - } + polyfill_framebuffer(fb, 240, 160); + fillblock_16byte(fb, 0, 240 * 160 / 16); + + update(); + draw(); + + vblperf_end(); + wait_vblank(); + present(backbuf); + vblperf_begin(); } static void update(void) @@ -113,37 +132,42 @@ static void update(void) bnstate = get_input(); - if(bnstate & KEY_UP) { - cam_phi += 0x2000; - if(cam_phi > X_HPI) cam_phi = X_HPI; - } - if(bnstate & KEY_DOWN) { - cam_phi -= 0x2000; - if(cam_phi < -X_HPI) cam_phi = -X_HPI; - } - if(bnstate & KEY_LEFT) { - cam_theta += 0x2000; - if(cam_theta > X_2PI) cam_theta -= X_2PI; - } - if(bnstate & KEY_RIGHT) { - cam_theta -= 0x2000; - if(cam_theta < X_2PI) cam_theta += X_2PI; - } + player_input(&player, bnstate); + + upd_vis(lvl, &player); } static void draw(void) { - xgl_load_identity(); - //xgl_translate(0, -0x50000, 0); - xgl_translate(0, 0, 0x80000); - xgl_rotate_x(cam_phi); - xgl_rotate_y(cam_theta); + int i, x, y; + struct cell *cell; - xgl_draw(XGL_QUADS, cube, sizeof cube / sizeof *cube); + xgl_load_identity(); +#ifndef BUILD_GBA + xgl_translate(0, 0, view_zoom); +#endif + xgl_rotate_x(player.phi); + xgl_rotate_y(player.theta); + xgl_translate(player.x, 0, player.y); + + for(i=0; inumvis; i++) { + cell = lvl->vis[i]; + + x = (int32_t)(cell->x - player.cx) << 17; + y = -(int32_t)(cell->y - player.cy) << 17; + + xgl_push_matrix(); + xgl_translate(x, 0, y); + xgl_index(i + 1); + xgl_draw(XGL_QUADS, tm_floor, sizeof tm_floor / sizeof *tm_floor); + xgl_pop_matrix(); + } } +#ifdef BUILD_GBA __attribute__((noinline, target("arm"), section(".iwram"))) -static void vblank(void) +#endif +static void gamescr_vblank(void) { num_vbl++; }