foo
[andemo] / src / demosys.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "demosys.h"
4
5 static struct demoscreen *act_tail;
6
7 void regscr_testa(void);
8 void regscr_testb(void);
9
10 int dsys_init(const char *fname)
11 {
12         int i;
13
14         regscr_testa();
15         regscr_testb();
16
17         for(i=0; i<dsys_num_screens; i++) {
18                 if(dsys_screens[i]->init() == -1) {
19                         fprintf(stderr, "failed to initialize demo screen: %s\n", dsys_screens[i]->name);
20                         return -1;
21                 }
22         }
23
24         return 0;
25 }
26
27 void dsys_destroy(void)
28 {
29         int i;
30
31         for(i=0; i<dsys_num_screens; i++) {
32                 if(dsys_screens[i]->destroy) {
33                         dsys_screens[i]->destroy();
34                 }
35         }
36         dsys_num_screens = 0;
37 }
38
39 struct demoscreen *dsys_find_screen(const char *name)
40 {
41         int i;
42
43         for(i=0; i<dsys_num_screens; i++) {
44                 if(strcmp(dsys_screens[i]->name, name) == 0) {
45                         return dsys_screens[i];
46                 }
47         }
48         return 0;
49 }
50
51 void dsys_run_screen(struct demoscreen *scr)
52 {
53         struct demoscreen *act;
54
55         if(!scr) return;
56         if(dsys_act_scr == scr && act_tail == scr) return;
57
58         act = dsys_act_scr;
59         while(act) {
60                 if(act->stop) act->stop();
61                 act = act->next;
62         }
63         dsys_act_scr = act_tail = scr;
64         if(scr->start) scr->start();
65 }
66
67 void dsys_run(void)
68 {
69 }
70
71 void dsys_stop(void)
72 {
73 }
74
75 void dsys_seek_abs(long tm)
76 {
77 }
78
79 void dsys_seek_rel(long dt)
80 {
81 }
82
83 void dsys_seek_norm(float t)
84 {
85 }
86
87 int dsys_add_screen(struct demoscreen *scr)
88 {
89         if(!scr->name || !scr->init || !scr->draw) {
90                 fprintf(stderr, "dsys_add_screen: invalid screen\n");
91                 return -1;
92         }
93         dsys_screens[dsys_num_screens++] = scr;
94         return 0;
95 }