17 #define MOUSE_TIMEOUT 1200
23 int fb_width = FB_WIDTH;
24 int fb_height = FB_HEIGHT;
27 uint16_t *fb_pixels, *vmem;
28 unsigned long time_msec;
30 unsigned int mouse_bmask;
32 float sball_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
34 static unsigned long last_mouse_move;
35 static int prev_mx, prev_my, mouse_dx, mouse_dy;
36 static unsigned int bmask_diff, prev_bmask;
38 static unsigned long nframes;
39 static int con_active;
41 extern uint16_t loading_pixels[]; /* data.asm */
44 int demo_init(int argc, char **argv)
49 if(load_config("demo.cfg") == -1) {
52 if((env = getenv("START_SCR"))) {
55 if(parse_args(argc, argv) == -1) {
59 /* reuse the loading image as our back buffer.
60 * adjust fb_pixels to leave 4 pixels guard band top/bottom. We have enough
61 * space since the loading image is 8 pixels taller.
63 fb_pixels = loading_pixels + 320 * 4;
68 if(g3d_init() == -1) {
71 g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
74 if(music_open("data/test.mod") == -1) {
79 if(scr_init() == -1) {
83 scr = scr_lookup(opt.start_scr);
88 if(!scr || scr_change(scr, 4000) == -1) {
89 fprintf(stderr, "screen %s not found\n", opt.start_scr ? opt.start_scr : "0");
93 /* clear the framebuffer at least once */
94 memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * FB_BPP / CHAR_BIT);
102 void demo_cleanup(void)
111 float fps = (float)nframes / ((float)time_msec / 1000.0f);
112 printf("average framerate: %.1f\n", fps);
119 mouse_dx = mouse_x - prev_mx;
120 mouse_dy = mouse_y - prev_my;
123 bmask_diff = mouse_bmask ^ prev_bmask;
124 prev_bmask = mouse_bmask;
125 if(mouse_dx | mouse_dy) {
126 last_mouse_move = time_msec;
139 /* called by swap_buffers just before the actual swap */
140 void demo_post_draw(void *pixels)
145 if(dbg_curscr_name) {
146 cs_dputs(pixels, dbg_curscr_name_pos, 240 - 16, dbg_curscr_name);
154 if(opt.mouse && time_msec - last_mouse_move < MOUSE_TIMEOUT) {
155 cs_mouseptr(pixels, mouse_x, mouse_y);
159 void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str)
164 if(c > ' ' && c < 128) {
165 csfont(fb, x, y, c - ' ');
171 void change_screen(int idx)
173 printf("change screen %d\n", idx);
174 scr_change(scr_screen(idx), 4000);
177 void demo_keyboard(int key, int press)
197 con_active = !con_active;
208 con_active = con_input('/');
214 con_active = con_input(key);
218 if(key >= '1' && key <= '9' && key <= '1' + scr_num_screens()) {
219 change_screen(key - '1');
221 } else if(key == '0' && scr_num_screens() >= 10) {
232 void mouse_orbit_update(float *theta, float *phi, float *dist)
235 if(bmask_diff == 0) {
237 if(mouse_dx | mouse_dy) {
238 if(mouse_bmask & MOUSE_BN_LEFT) {
240 *theta += mouse_dx * 1.0;
247 if(mouse_bmask & MOUSE_BN_RIGHT) {
248 *dist += mouse_dy * 0.5;
250 if(*dist < 0) *dist = 0;