rev |
line source |
nuclear@6
|
1 #include "config.h"
|
nuclear@5
|
2 #include "game.h"
|
nuclear@5
|
3 #include "gbasys.h"
|
nuclear@8
|
4 #include "x3d.h"
|
nuclear@8
|
5 #include "sincos.h"
|
nuclear@8
|
6 #include "fixed.h"
|
nuclear@9
|
7 #include "palman.h"
|
nuclear@13
|
8 #include "ggen.h"
|
nuclear@9
|
9
|
nuclear@9
|
10 static void draw_rect(int x, int y, int w, int h, uint16_t color);
|
nuclear@5
|
11
|
nuclear@5
|
12 #define X16INT(x) ((x) << 16)
|
nuclear@12
|
13 #define X16FLT(x) ((int32_t)((x) * 65536.0))
|
nuclear@5
|
14
|
nuclear@8
|
15 static const int32_t poly[] = {
|
nuclear@13
|
16 X16INT(-1), X16INT(-1), 0,
|
nuclear@13
|
17 X16INT(-1), X16INT(1), 0,
|
nuclear@13
|
18 X16INT(1), X16INT(1), 0,
|
nuclear@13
|
19 X16INT(1), X16INT(-1), 0,
|
nuclear@13
|
20 X16INT(1), X16INT(-1), 0,
|
nuclear@13
|
21 X16INT(1), X16INT(1), 0,
|
nuclear@13
|
22 X16INT(-1), X16INT(1), 0,
|
nuclear@13
|
23 X16INT(-1), X16INT(-1), 0
|
nuclear@13
|
24 };
|
nuclear@13
|
25 static const int32_t colors[] = {
|
nuclear@13
|
26 65535, 0, 0, 65535, 0, 0, 65535, 0, 0, 65535, 0, 0,
|
nuclear@13
|
27 65536, 65535, 0, 65536, 65535, 0, 65536, 65535, 0, 65536, 65535, 0
|
nuclear@5
|
28 };
|
nuclear@8
|
29 static const short vcount = sizeof poly / sizeof *poly / 3;
|
nuclear@8
|
30
|
nuclear@13
|
31 static struct mesh box;
|
nuclear@13
|
32
|
nuclear@13
|
33
|
nuclear@8
|
34 int game_init(void)
|
nuclear@8
|
35 {
|
nuclear@8
|
36 sincos_init();
|
nuclear@9
|
37 #ifdef PALMODE
|
nuclear@9
|
38 palman_init();
|
nuclear@9
|
39 #endif
|
nuclear@8
|
40
|
nuclear@12
|
41 x3d_projection(45.0, (WIDTH << 16) / HEIGHT, 65536 / 2, 65536 * 500);
|
nuclear@12
|
42
|
nuclear@13
|
43 init_mesh(&box);
|
nuclear@13
|
44 gen_box(&box);
|
nuclear@13
|
45
|
nuclear@8
|
46 return 0;
|
nuclear@8
|
47 }
|
nuclear@5
|
48
|
nuclear@13
|
49 static int32_t cam_theta, cam_phi = 25 << 16;
|
nuclear@9
|
50 static short keyrot;
|
nuclear@9
|
51 static int autorot = 1;
|
nuclear@9
|
52
|
nuclear@5
|
53 void game_draw(void)
|
nuclear@5
|
54 {
|
nuclear@8
|
55 unsigned long msec = get_millisec();
|
nuclear@8
|
56
|
nuclear@5
|
57 clear_buffer(back_buffer, 0);
|
nuclear@5
|
58
|
nuclear@8
|
59 x3d_load_identity();
|
nuclear@12
|
60 /*x3d_translate(-itox16(WIDTH / 2), -itox16(HEIGHT / 2), 0);
|
nuclear@9
|
61 if(autorot) {
|
nuclear@9
|
62 x3d_rotate((msec / 64) << 16, 0, 0, 65536);
|
nuclear@9
|
63 } else {
|
nuclear@9
|
64 x3d_rotate(keyrot << 16, 0, 0, 65536);
|
nuclear@9
|
65 }
|
nuclear@12
|
66 x3d_translate(itox16(WIDTH / 2), itox16(HEIGHT / 2), 0);*/
|
nuclear@12
|
67
|
nuclear@13
|
68 x3d_rotate(cam_phi, 65536, 0, 0);
|
nuclear@13
|
69 x3d_rotate(keyrot << 16, 0, 65536, 0);
|
nuclear@13
|
70 x3d_translate(0, 0, X16INT(6));
|
nuclear@6
|
71
|
nuclear@9
|
72 #ifdef PALMODE
|
nuclear@9
|
73 x3d_color_index(255);
|
nuclear@9
|
74 #else
|
nuclear@8
|
75 x3d_color(65536, 65536, 65536);
|
nuclear@9
|
76 #endif
|
nuclear@13
|
77
|
nuclear@13
|
78 draw_mesh(&box);
|
nuclear@13
|
79
|
nuclear@13
|
80 /*
|
nuclear@13
|
81 x3d_vertex_array(vcount, poly);
|
nuclear@13
|
82 x3d_color_array(vcount, colors);
|
nuclear@13
|
83 x3d_draw(X3D_QUADS, vcount);
|
nuclear@13
|
84 x3d_color_array(0, 0);
|
nuclear@8
|
85
|
nuclear@9
|
86 #ifdef PALMODE
|
nuclear@9
|
87 x3d_color_index(RGBPAL(0, 255, 0));
|
nuclear@9
|
88 #else
|
nuclear@8
|
89 x3d_color(0, 65536, 0);
|
nuclear@9
|
90 #endif
|
nuclear@13
|
91
|
nuclear@12
|
92 x3d_draw(X3D_POINTS, vcount);
|
nuclear@9
|
93 x3d_vertex_array(0, 0);
|
nuclear@13
|
94 */
|
nuclear@6
|
95
|
nuclear@5
|
96 flip();
|
nuclear@5
|
97 }
|
nuclear@5
|
98
|
nuclear@5
|
99 void game_keyb(int key, int pressed)
|
nuclear@5
|
100 {
|
nuclear@9
|
101 if(!pressed) return;
|
nuclear@9
|
102
|
nuclear@9
|
103 switch(key) {
|
nuclear@9
|
104 case KEY_LEFT:
|
nuclear@9
|
105 keyrot--;
|
nuclear@9
|
106 break;
|
nuclear@9
|
107
|
nuclear@9
|
108 case KEY_RIGHT:
|
nuclear@9
|
109 keyrot++;
|
nuclear@9
|
110 break;
|
nuclear@9
|
111
|
nuclear@9
|
112 case KEY_A:
|
nuclear@9
|
113 autorot = !autorot;
|
nuclear@9
|
114 break;
|
nuclear@9
|
115
|
nuclear@9
|
116 default:
|
nuclear@9
|
117 break;
|
nuclear@9
|
118 }
|
nuclear@5
|
119 }
|
nuclear@9
|
120
|
nuclear@9
|
121 #ifdef PALMODE
|
nuclear@9
|
122 #define ROWADV (WIDTH / 2)
|
nuclear@9
|
123 #else
|
nuclear@9
|
124 #define ROWADV WIDTH
|
nuclear@9
|
125 #endif
|
nuclear@9
|
126
|
nuclear@9
|
127 static void draw_rect(int x, int y, int w, int h, uint16_t color)
|
nuclear@9
|
128 {
|
nuclear@9
|
129 int i, xsz = w, ysz = h;
|
nuclear@9
|
130 uint16_t *pixels = back_buffer->pixels;
|
nuclear@9
|
131 uint16_t *topleft, *topright, *botleft;
|
nuclear@9
|
132
|
nuclear@9
|
133 #ifdef PALMODE
|
nuclear@9
|
134 pixels += (y * WIDTH + x) / 2;
|
nuclear@9
|
135 topleft = pixels;
|
nuclear@9
|
136 topright = (uint16_t*)back_buffer->pixels + (y * WIDTH + x + w - 1) / 2;
|
nuclear@9
|
137
|
nuclear@9
|
138 color |= color << 8;
|
nuclear@9
|
139 xsz /= 2;
|
nuclear@9
|
140 #else
|
nuclear@9
|
141 pixels += y * WIDTH + x;
|
nuclear@9
|
142 topleft = pixels;
|
nuclear@9
|
143 topright = topleft + w - 1;
|
nuclear@9
|
144 #endif
|
nuclear@9
|
145 botleft = topleft + (ysz - 1) * ROWADV;
|
nuclear@9
|
146
|
nuclear@9
|
147 #ifdef PALMODE
|
nuclear@9
|
148 if(x & 1) {
|
nuclear@9
|
149 *topleft = (*topleft & 0xff) | (color & 0xff00);
|
nuclear@9
|
150 *botleft = (*topleft & 0xff) | (color & 0xff00);
|
nuclear@9
|
151 ++topleft;
|
nuclear@9
|
152 ++botleft;
|
nuclear@9
|
153 xsz -= 1;
|
nuclear@9
|
154 }
|
nuclear@9
|
155 #endif
|
nuclear@9
|
156 for(i=0; i<xsz; i++) {
|
nuclear@9
|
157 *topleft++ = color;
|
nuclear@9
|
158 *botleft++ = color;
|
nuclear@9
|
159 }
|
nuclear@9
|
160
|
nuclear@9
|
161 topleft = pixels;
|
nuclear@9
|
162 for(i=0; i<ysz; i++) {
|
nuclear@9
|
163 #ifdef PALMODE
|
nuclear@9
|
164 if(x & 1) {
|
nuclear@9
|
165 *topleft = (*topleft & 0xff) | (color & 0xff00);
|
nuclear@9
|
166 } else {
|
nuclear@9
|
167 *topleft = (*topleft & 0xff00) | (color & 0xff);
|
nuclear@9
|
168 }
|
nuclear@9
|
169
|
nuclear@9
|
170 if((x + w - 1) & 1) {
|
nuclear@9
|
171 *topright = (*topright & 0xff) | (color & 0xff00);
|
nuclear@9
|
172 } else {
|
nuclear@9
|
173 *topright = (*topright & 0xff00) | (color & 0xff);
|
nuclear@9
|
174 }
|
nuclear@9
|
175 #else
|
nuclear@9
|
176 *topleft = color;
|
nuclear@9
|
177 *topright = color;
|
nuclear@9
|
178 #endif
|
nuclear@9
|
179
|
nuclear@9
|
180 topleft += ROWADV;
|
nuclear@9
|
181 topright += ROWADV;
|
nuclear@9
|
182 }
|
nuclear@9
|
183 }
|