17 #include "dos/gfx.h" /* for wait_vsync assembly macro */
19 void wait_vsync(void);
25 static int init(void);
26 static void destroy(void);
27 static void start(long trans_time);
28 static void draw(void);
31 static struct screen scr = {
39 static long start_time;
41 static struct smktxt *stx;
43 static uint16_t *cur_smokebuf, *prev_smokebuf;
44 static int smokebuf_size;
45 #define smokebuf_start (cur_smokebuf < prev_smokebuf ? cur_smokebuf : prev_smokebuf)
46 #define swap_smoke_buffers() \
48 uint16_t *tmp = cur_smokebuf; \
49 cur_smokebuf = prev_smokebuf; \
50 prev_smokebuf = tmp; \
53 static float cam_theta, cam_phi = 25;
54 static float cam_dist = 3;
56 struct screen *greets_screen(void)
64 if(!(stx = create_smktxt("data/greets1.png", "data/vfield1"))) {
68 smokebuf_size = FB_WIDTH * FB_HEIGHT * sizeof *cur_smokebuf;
69 if(!(cur_smokebuf = malloc(smokebuf_size * 2))) {
70 perror("failed to allocate smoke framebuffer");
73 prev_smokebuf = cur_smokebuf + FB_WIDTH * FB_HEIGHT;
78 static void destroy(void)
84 static void start(long trans_time)
86 g3d_matrix_mode(G3D_PROJECTION);
88 g3d_perspective(50.0, 1.3333333, 0.5, 100.0);
90 memset(smokebuf_start, 0, smokebuf_size * 2);
92 start_time = time_msec;
95 static void update(void)
97 static long prev_msec;
98 static int prev_mx, prev_my;
99 static unsigned int prev_bmask;
101 long msec = time_msec - start_time;
102 float dt = (msec - prev_msec) / 1000.0f;
106 if((mouse_bmask ^ prev_bmask) == 0) {
107 int dx = mouse_x - prev_mx;
108 int dy = mouse_y - prev_my;
111 if(mouse_bmask & 1) {
112 cam_theta += dx * 1.0;
115 if(cam_phi < -90) cam_phi = -90;
116 if(cam_phi > 90) cam_phi = 90;
118 if(mouse_bmask & 4) {
119 cam_dist += dy * 0.5;
121 if(cam_dist < 0) cam_dist = 0;
128 prev_bmask = mouse_bmask;
130 update_smktxt(stx, dt);
133 static void draw(void)
136 uint16_t *dest, *src;
138 static unsigned long last_swap;
142 g3d_matrix_mode(G3D_MODELVIEW);
144 g3d_translate(0, 0, -cam_dist);
145 g3d_rotate(cam_phi, 1, 0, 0);
146 g3d_rotate(cam_theta, 0, 1, 0);
148 g3d_mult_matrix(sball_matrix);
151 memcpy(cur_smokebuf, prev_smokebuf, smokebuf_size);
153 g3d_framebuffer(FB_WIDTH, FB_HEIGHT, cur_smokebuf);
155 g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
157 memcpy(fb_pixels, cur_smokebuf, smokebuf_size);
160 blur_horiz(prev_smokebuf, cur_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
163 printf("blur perf: %lu\n", (unsigned long)perf_interval_count);
165 blur_vert(cur_smokebuf, prev_smokebuf, FB_WIDTH, FB_HEIGHT, BLUR_RAD, 240);
166 swap_smoke_buffers();
169 if(msec - last_swap < 16) {
175 swap_buffers(fb_pixels);
176 last_swap = get_msec();