1207
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /*
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 viewer.cc を、xmlファイルのsurface nameをわざわざ書き出さなくても
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 良いように改良しました。
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 ただxmlファイル内のsurface name行をプログラム内で抜き出せるようにしただけ
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 使い方:
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 ./viewer_2 -sg (読み込みたいxmlファイル名)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 */
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 #include <math.h>
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 #include <stdlib.h>
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 #include "SceneGraphRoot.h"
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 #include "MainLoop.h"
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 #include "viewer.h"
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 // prototype
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 static void object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 static void object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 static void object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 /*
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 getStrFromFile関数
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 指定したテキストファイル内から,
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 ある文字列(searchStartStr)とある文字列(searchEndStr)の間の文字列を抜き出す.
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 抜き出した文字列の数を返す.
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 char **date に抜き出した文字列を二次元配列のポインタを渡す.
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 中でmallocしてるから、使い終わったら free(date)しないとダメかも
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 reallocとかでfree()しなくて良い方法も教えて下さい.
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 */
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 static int getStrFromFile( char **date, const char *fname, const char *searchStartStr, const char *searchEndStr );
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 int light_sysswitch = 1;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 int light_num = 4;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 void LightSysSwitch(Viewer *sgroot) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 if (light_sysswitch == 1) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 sgroot->OnLightSysSwitch();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 } else if (light_sysswitch == 0) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 sgroot->OffLightSysSwitch();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 static void
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 Pad *pad = sgroot->getController();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 if (pad->circle.isPush()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 node->set_move_collision(object_move_translation, object_collision);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 if (pad->left.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 node->angle[1] += 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 } else if (pad->right.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 node->angle[1] -= 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 if (pad->up.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 node->angle[0] += 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 } else if (pad->down.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 node->angle[0] -= 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 static void
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 Pad *pad = sgroot->getController();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 if (pad->circle.isPush()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 node->set_move_collision(object_move_rotation, object_collision);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 if (pad->left.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 node->xyz[0] -= 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } else if (pad->right.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 node->xyz[0] += 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 if (pad->up.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 node->xyz[1] -= 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 } else if (pad->down.isHold()) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 node->xyz[1] += 10;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 static void
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w,
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 int screen_h, SceneGraphPtr tree)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 // if (node->xyz[1] > screen_h - object_radius) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 // node->xyz[1] = screen_h - object_radius;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 // vy *= e;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 // if (vy > -g && vy < 0) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 // vy = 0.0;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 // node->set_move_collision(object_move_idle, object_collision_idle);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 // }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 // }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 char *xmlfile;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 #define MAX_ROOT 100
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 char *parts[MAX_ROOT ];
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 int parts_cnt;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 MainLoopPtr
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 viewer::init(Viewer *sgroot, int screen_w, int screen_h)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 LightSysSwitch(sgroot);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 SceneGraphPtr object;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 for (int i = 0; i < light_num; i++) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 SceneGraphPtr light = sgroot->getLight(i);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 sgroot->OnLightSwitch(i);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 light->xyz[0] = screen_w / 2;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 light->xyz[1] = screen_h / 2;
|
1292
|
120 light->xyz[2] = 100;
|
1207
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 // 固定した値で srandom すると、毎回同じ、random() 列が生成される
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 // random な値が欲しいなら、man random に方法が書いてあります。
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 srandom(100);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 object = sgroot->createSceneGraph();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 object->set_move_collision(object_move_rotation, object_collision);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 object->xyz[0] = screen_w/2;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 object->xyz[1] = screen_h/2;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 object->xyz[2] = 30.0f;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 // [128]ってのは取得する文字列の十分な大きさ。
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 char *getStrDate[128];
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 char *fn = xmlfile; // 読み込みたいテキストファイル
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 const char *sStr = "surface name=\""; // この文字列の直後の文字列を取得する
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 const char *eStr = "\" size="; // この文字列の直前までの文字列を抜き取る
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 sgroot->createFromXMLfile(fn);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143
|
1218
|
144 if (parts_cnt>0) {
|
|
145 for( int i = 0; i < parts_cnt; i ++ ){
|
|
146 object->addChild( sgroot->createSceneGraph( parts[i] ) );
|
|
147 }
|
|
148 sgroot->setSceneData(object);
|
|
149 } else {
|
|
150 int num = getStrFromFile( getStrDate, fn, sStr, eStr );
|
1207
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151
|
1218
|
152 for( int i = 0; i < num; i ++ ){
|
|
153 object->addChild( sgroot->createSceneGraph( getStrDate[i] ) );
|
|
154 }
|
|
155 sgroot->setSceneData(object);
|
|
156
|
|
157 for( int i = 0; i < num; i ++ ){
|
|
158 free( getStrDate[i] );
|
|
159 }
|
|
160
|
1207
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 return sgroot;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 extern Application *
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 application() {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 return new viewer();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 extern int init(TaskManager *manager, int argc, char *argv[]);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 extern void task_initialize();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 static void TMend(TaskManager *manager);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 int
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 TMmain(TaskManager *manager, int argc, char *argv[])
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 task_initialize();
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 manager->set_TMend(TMend);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 for(int i=0;i<argc;i++) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 xmlfile = argv[i+1];
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 parts[parts_cnt++] = argv[i+1];
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 if (strcmp(argv[i],"on") == 0) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 light_sysswitch = 1;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 } else if (strcmp(argv[i],"off") == 0) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 light_sysswitch = 0;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 } else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 light_num = atoi(argv[i+1]);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 return init(manager, argc, argv);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 void
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 TMend(TaskManager *manager)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 printf("test_nogl end\n");
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 int getStrFromFile( char **getStrDate, const char *fname, const char *searchStartStr, const char *searchEndStr )
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 {
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 const int BUFSIZE = 256;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 // [100]ってのは取得する文字列の十分な大きさ。
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218 // ここも動的に確保したいケド、良い方法がわからん。
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 // char *getStrDate[100];
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 int num = 0;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 FILE *fp;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 // const char *fname = "xml_file/car/kart_cp.xml"; // 読み込みたいファイル名
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 char buf[BUFSIZE]; // 一行読み込み
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 //const char *searchStartStr = "surface name=\""; // この文字列の直後の文字列を取得する
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 //const char *searchEndStr = "\" size="; // この文字列の直前までの文字列を抜き取る
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 fp = fopen( fname, "r" );
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 if ( fp ==NULL ){
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 printf("fileNameError\n");
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 return 0;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 // ファイルの終端まで一行読み込みをループする
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 while( feof(fp) == 0 ){
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 fgets( buf, BUFSIZE, fp );
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 char *p1 = strstr( buf, searchStartStr ); // 文字列検索。
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 // 見つけた位置のポインタを返す
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 // 見つけれなかったらNULLを返す
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
244 if( p1 != NULL ){
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 int p1Len = strlen(p1);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246 char *p2 = strstr( p1, searchEndStr );
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
247 int p2Len = strlen(p2); //
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249 // 余分なsearchEndStr以降の文字列を切り捨てるため空白文字(改行文字だっけ?'\0'ってなんだっけ)
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 p1[p1Len - p2Len] = '\0';
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 int searchStartStrLen = strlen(searchStartStr);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254 // +searchStartStrLenで最初の余分な文字列をカウントしないようにする
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 int lenNum = strlen(p1 + searchStartStrLen);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 // 動的にメモリ確保したい。なんかオカしいってのはわかるケド、良い方法が思いつかん
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 getStrDate[num] = (char*)malloc(sizeof(char)*lenNum);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 strcpy(getStrDate[num], p1+searchStartStrLen);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 num ++;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 fclose( fp );
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 // 確認:抜き出した文字列の数
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 printf("num = %d\n",num);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 // 確認:抜き出した文字列
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 for( int i = 0; i < num; i ++ ){
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 printf("getStrDate[%d] = %s\n", i, getStrDate[i]);
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 return num;
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 }
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278
|
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 /* end */
|