gba-trycatch

diff src/game.c @ 8:fb0a0d6a8b52

sortof works
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 19 Jun 2014 05:53:46 +0300
parents 73b5f2e5d18a
children b0ed38f13261
line diff
     1.1 --- a/src/game.c	Wed Jun 18 06:20:07 2014 +0300
     1.2 +++ b/src/game.c	Thu Jun 19 05:53:46 2014 +0300
     1.3 @@ -1,29 +1,46 @@
     1.4  #include "config.h"
     1.5  #include "game.h"
     1.6  #include "gbasys.h"
     1.7 -#include "polyfill.h"
     1.8 +#include "x3d.h"
     1.9 +#include "sincos.h"
    1.10 +#include "fixed.h"
    1.11  
    1.12  #define X16INT(x)	((x) << 16)
    1.13  
    1.14 -static const pvec3 poly[] = {
    1.15 -	{X16INT(80), X16INT(10), 0},
    1.16 -	{X16INT(140), X16INT(100), 0},
    1.17 -	{X16INT(40), X16INT(80), 0}
    1.18 +static const int32_t poly[] = {
    1.19 +	X16INT(80), X16INT(10), 0,
    1.20 +	X16INT(140), X16INT(100), 0,
    1.21 +	X16INT(40), X16INT(80), 0
    1.22  };
    1.23 +static const short vcount = sizeof poly / sizeof *poly / 3;
    1.24 +
    1.25 +int game_init(void)
    1.26 +{
    1.27 +	sincos_init();
    1.28 +
    1.29 +	return 0;
    1.30 +}
    1.31  
    1.32  void game_draw(void)
    1.33  {
    1.34 -	int i;
    1.35 +	unsigned long msec = get_millisec();
    1.36 +
    1.37  	clear_buffer(back_buffer, 0);
    1.38  
    1.39 -	draw_poly(3, poly, 0xffff);
    1.40 +	x3d_load_identity();
    1.41 +	x3d_translate(-itox16(WIDTH / 2), -itox16(HEIGHT / 2), 0);
    1.42 +	x3d_rotate((msec / 64) << 16, 0, 0, 65536);
    1.43 +	x3d_translate(itox16(WIDTH / 2), itox16(HEIGHT / 2), 0);
    1.44  
    1.45 -	for(i=0; i<sizeof poly / sizeof *poly; i++) {
    1.46 -		int x = poly[i].x >> 16;
    1.47 -		int y = poly[i].y >> 16;
    1.48 +	x3d_vertex_array(vcount, poly);
    1.49  
    1.50 -		((uint16_t*)back_buffer->pixels)[y * WIDTH + x] = RGB(0, 255, 0);
    1.51 -	}
    1.52 +	x3d_color(65536, 65536, 65536);
    1.53 +	x3d_draw_arrays(X3D_TRIANGLES, vcount);
    1.54 +
    1.55 +	x3d_color(0, 65536, 0);
    1.56 +	x3d_draw_arrays(X3D_POINTS, vcount);
    1.57 +
    1.58 +	x3d_vertex_array(0, 0);
    1.59  
    1.60  	flip();
    1.61  }