53
|
1 #include <iostream>
|
|
2 #include "viewer.h"
|
|
3 #include "polygon.h"
|
|
4 #include "demonstration.h"
|
|
5 #include "pad.h"
|
|
6 #include "TaskManager.h"
|
|
7 using namespace std;
|
|
8
|
68
|
9 #include "error.h"
|
|
10
|
53
|
11 int init(void*, void*);
|
|
12 int sdl_init(void*, void*);
|
|
13 int zrow_init(void*, void*);
|
|
14 int run(void*, void*);
|
|
15 int finish(void*, void*);
|
|
16
|
|
17 extern void task_initialize();
|
|
18
|
|
19 TaskManager *manager;
|
|
20 Viewer *screen;
|
|
21
|
|
22 struct init_arg {
|
|
23 int bpp;
|
|
24 int w;
|
|
25 int h;
|
|
26 };
|
|
27
|
68
|
28 struct init_arg *initArg;
|
|
29
|
|
30 int init(void *r, void *w)
|
53
|
31 {
|
|
32 int fd_sdl_init, fd_zrow_init, fd_run;
|
|
33 HTaskPtr task_sdl_init, task_zrow_init, task_run;
|
|
34
|
68
|
35 __debug("[%s]\n", __FUNCTION__);
|
53
|
36
|
68
|
37 screen = new Viewer(initArg->bpp, initArg->w, initArg->h);
|
53
|
38
|
|
39 fd_sdl_init = manager->open("sdl_init");
|
|
40 fd_zrow_init = manager->open("zRow_init");
|
|
41 fd_run = manager->open("run");
|
|
42
|
|
43 task_sdl_init = manager->create_task(fd_sdl_init, 0, 0, 0, NULL);
|
|
44 task_zrow_init = manager->create_task(fd_zrow_init, 0, 0, 0, NULL);
|
|
45 task_run = manager->create_task(fd_run, 0, 0, 0, NULL);
|
|
46
|
|
47 manager->set_task_depend(task_sdl_init, task_run);
|
|
48 manager->set_task_depend(task_zrow_init, task_run);
|
|
49
|
|
50 //task_sdl_init->set_depend(..);
|
|
51 //task_sdl_init->spawn();
|
|
52
|
|
53 manager->spawn_task(task_sdl_init);
|
|
54 manager->spawn_task(task_zrow_init);
|
|
55 manager->spawn_task(task_run);
|
|
56
|
68
|
57 free(initArg);
|
53
|
58 return 0;
|
|
59 }
|
|
60
|
|
61
|
321
|
62 // クラス関数は単純にポインタで扱えないので
|
|
63 // 現状は間接的に呼ぶことに
|
53
|
64 int sdl_init(void *r, void *w)
|
|
65 {
|
68
|
66 __debug("[%s]\n", __FUNCTION__);
|
53
|
67 screen->sdl_init();
|
|
68 return 0;
|
|
69 }
|
|
70
|
|
71 int zRow_init(void *r, void *w)
|
|
72 {
|
68
|
73 __debug("[%s]\n", __FUNCTION__);
|
53
|
74 screen->zRow_init();
|
|
75 return 0;
|
|
76 }
|
|
77
|
|
78 int run(void *r, void *w)
|
|
79 {
|
68
|
80 __debug("[%s]\n", __FUNCTION__);
|
53
|
81 screen->run_init();
|
|
82 return 0;
|
|
83 }
|
|
84
|
|
85 int run_loop(void *r, void *w)
|
|
86 {
|
68
|
87 __debug("[%s]\n", __FUNCTION__);
|
53
|
88 screen->run_loop();
|
|
89 return 0;
|
|
90 }
|
|
91
|
|
92 int run_draw(void *r, void *w)
|
|
93 {
|
68
|
94 __debug("[%s]\n", __FUNCTION__);
|
53
|
95 screen->run_draw();
|
|
96 return 0;
|
|
97 }
|
|
98
|
|
99 int run_finish(void *r, void *w)
|
|
100 {
|
68
|
101 __debug("[%s]\n", __FUNCTION__);
|
53
|
102 screen->run_finish();
|
|
103 return 0;
|
|
104 }
|
|
105
|
|
106 int finish(void *w, void *r)
|
|
107 {
|
68
|
108 __debug("[%s]\n", __FUNCTION__);
|
53
|
109 delete screen;
|
68
|
110 delete manager;
|
53
|
111 return 0;
|
|
112 }
|
|
113
|
68
|
114 int
|
|
115 main(int argc, char *argv[])
|
53
|
116 {
|
|
117 manager = new TaskManager(1);
|
|
118 manager->init();
|
|
119
|
|
120 task_initialize();
|
|
121
|
321
|
122 // 本当は、dlsym みたいなものを使いたいんだけど
|
|
123 // 静的なやつはできないん?
|
53
|
124 manager->set_symbol("init", (void*)init);
|
|
125 manager->set_symbol("sdl_init", (void*)sdl_init);
|
|
126 manager->set_symbol("zRow_init", (void*)zRow_init);
|
|
127 manager->set_symbol("run", (void*)run);
|
|
128 manager->set_symbol("finish", (void*)finish);
|
|
129 manager->set_symbol("ViewerRunLoop", (void*)run_loop);
|
|
130 manager->set_symbol("ViewerRunDraw", (void*)run_draw);
|
|
131 manager->set_symbol("ViewerRunFinish", (void*)run_finish);
|
|
132
|
|
133 int bpp = 0;
|
|
134 int width = 640;
|
|
135 int height = 480;
|
|
136
|
|
137 for(int i = 1; argv[i]; ++i)
|
|
138 {
|
|
139 if (strcmp(argv[i], "-bpp") == 0)
|
|
140 {
|
|
141 bpp = atoi(argv[++i]);
|
|
142 }
|
|
143 if (strcmp(argv[i], "-width") == 0)
|
|
144 {
|
|
145 width = atoi(argv[++i]);
|
|
146 }
|
|
147 if (strcmp(argv[i], "-height") == 0)
|
|
148 {
|
|
149 height = atoi(argv[++i]);
|
|
150 }
|
|
151 }
|
|
152
|
321
|
153 // 一番最初に行われる init 専用の task_run があってもいいけど。。
|
|
154 // その場合は引数とか固定か。まあ引数は argc, argv を持つ
|
|
155 // 構造体で固定しても問題はない・・・か?
|
53
|
156 HTaskPtr task_init;
|
|
157 int fd_init;
|
68
|
158 initArg = new struct init_arg;
|
|
159 initArg->bpp = bpp;
|
|
160 initArg->w = width;
|
|
161 initArg->h = height;
|
53
|
162
|
|
163 fd_init = manager->open("init");
|
68
|
164 task_init = manager->create_task(fd_init, 0, 0, 0, NULL);
|
53
|
165 manager->spawn_task(task_init);
|
68
|
166
|
53
|
167 manager->run();
|
|
168
|
|
169 finish(NULL, NULL);
|
|
170 return 0;
|
|
171 }
|