annotate old/simple_pack/main.cpp @ 656:66810c71442b draft

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