17 #define MOUSE_TIMEOUT 1200
22 int fb_width, fb_height, fb_bpp, fb_scan_size;
24 long fb_size, fb_buf_size;
25 uint16_t *fb_pixels, *vmem;
28 unsigned long time_msec;
30 unsigned int mouse_bmask;
32 static struct au_module *mod;
34 float sball_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
36 static unsigned long last_mouse_move;
37 static int prev_mx, prev_my, mouse_dx, mouse_dy;
38 static unsigned int bmask_diff, prev_bmask;
40 static unsigned long nframes;
41 static int con_active;
43 extern uint16_t loading_pixels[]; /* data.asm */
45 int demo_init(int argc, char **argv)
47 if(demo_init1(argc, argv) == -1) {
50 if(demo_init2() == -1) {
56 static struct screen *scr;
58 int demo_init1(int argc, char **argv)
62 if(load_config("demo.cfg") == -1) {
65 if((env = getenv("START_SCR"))) {
68 if(parse_args(argc, argv) == -1) {
79 if(g3d_init() == -1) {
82 g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels);
85 if(!(mod = au_load_module("data/test.mod"))) {
90 if(scr_init() == -1) {
95 scr = scr_lookup(opt.start_scr);
100 if(!scr || scr_change(scr, 4000) == -1) {
101 fprintf(stderr, "screen %s not found\n", opt.start_scr ? opt.start_scr : "0");
105 /* clear the framebuffer at least once */
106 memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * FB_BPP / CHAR_BIT);
114 void demo_cleanup(void)
123 float fps = (float)nframes / ((float)time_msec / 1000.0f);
124 printf("average framerate: %.1f\n", fps);
128 int demo_resizefb(int width, int height, int bpp)
130 int newsz, new_scansz;
132 if(!width || !height || !bpp) {
134 fb_buf = fb_pixels = 0;
135 fb_size = fb_buf_size = fb_scan_size = 0;
136 fb_width = fb_height = fb_bpp = 0;
140 new_scansz = ((width + GUARD_XPAD * 2) * bpp + 7) / 8;
141 newsz = (height + GUARD_YPAD * 2) * new_scansz;
143 if(!fb_buf || newsz > fb_buf_size) {
144 void *tmp = malloc(newsz);
152 fb_scan_size = new_scansz;
153 fb_pixels = (uint16_t*)((char*)fb_buf + GUARD_YPAD * fb_scan_size + (GUARD_XPAD * bpp + 7) / 8);
157 fb_size = fb_scan_size * fb_height;
159 fb_aspect = (float)fb_width / (float)fb_height;
168 mouse_dx = mouse_x - prev_mx;
169 mouse_dy = mouse_y - prev_my;
172 bmask_diff = mouse_bmask ^ prev_bmask;
173 prev_bmask = mouse_bmask;
174 if(mouse_dx | mouse_dy) {
175 last_mouse_move = time_msec;
188 /* called by swap_buffers just before the actual swap */
189 void demo_post_draw(void *pixels)
194 if(dbg_curscr_name) {
195 cs_dputs(pixels, dbg_curscr_name_pos, 240 - 16, dbg_curscr_name);
203 if(opt.mouse && time_msec - last_mouse_move < MOUSE_TIMEOUT) {
204 cs_mouseptr(pixels, mouse_x, mouse_y);
208 void cs_puts_font(cs_font_func csfont, int sz, void *fb, int x, int y, const char *str)
213 if(c > ' ' && c < 128) {
214 csfont(fb, x, y, c - ' ');
220 void change_screen(int idx)
222 printf("change screen %d\n", idx);
223 scr_change(scr_screen(idx), 4000);
226 void demo_keyboard(int key, int press)
246 con_active = !con_active;
257 con_active = con_input('/');
263 con_active = con_input(key);
267 if(key >= '1' && key <= '9' && key <= '1' + scr_num_screens()) {
268 change_screen(key - '1');
270 } else if(key == '0' && scr_num_screens() >= 10) {
281 void mouse_orbit_update(float *theta, float *phi, float *dist)
284 if(bmask_diff == 0) {
286 if(mouse_dx | mouse_dy) {
287 if(mouse_bmask & MOUSE_BN_LEFT) {
289 *theta += mouse_dx * 1.0;
296 if(mouse_bmask & MOUSE_BN_RIGHT) {
297 *dist += mouse_dy * 0.5;
299 if(*dist < 0) *dist = 0;