Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CModelSwitch.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download) (as text)
Tue Nov 23 14:34:03 2010 UTC (13 years, 5 months ago) by okadu
File MIME type: text/x-c++src
File size: 14807 byte(s)
[okadu] Version 2.13
1 #include "stdafx.h"
2 #include "CListView.h"
3 #include "CExpression.h"
4 #include "CModelPlugin.h"
5
6 // 外部グローバル
7 extern float g_FovRatio;
8
9 // 内部グローバル
10 CModelSwitch g_SystemSwitch[SYSTEM_SWITCH_NUM];
11
12 vector<CStaticSwitchID> g_StaticSwitchTable;
13
14 int CurrentEnabledEffectorTypes(){
15 return g_PreSimulationFlag ? EFCT_PARTICLEAPPLIER|EFCT_RAILCONNECTOR : EFCT_MISCELLANEOUS;
16 }
17
18 /*
19 * コンストラクタ
20 */
21 CModelSwitch::CModelSwitch(){
22 m_ListElement = NULL;
23 }
24
25 /*
26 * コンストラクタ
27 */
28 CModelSwitch::CModelSwitch(
29 int id // 番号
30 ){
31 m_ID = id;
32 m_Value = 0;
33 m_ListElement = NULL;
34 }
35
36 /*
37 * 初期化
38 */
39 void CModelSwitch::Init(
40 int id, // 番号
41 char *name // スイッチ名
42 ){
43 m_ID = id;
44 m_SwitchName = name;
45 }
46
47 /*
48 * 読込
49 */
50 char *CModelSwitch::Read(
51 char *str, // 対象文字列
52 CModelPlugin *mpi // モデルプラグイン
53 ){
54 char *tmp, *eee;
55 if(!(str = BeginNamedBlock(eee = str, "DefineSwitch", &m_SwitchName))) return NULL;
56
57 int i;
58 for(i = 0; i<SYSTEM_SWITCH_NUM; i++) if(g_SystemSwitch[i].Check(m_SwitchName))
59 throw CSynErr(eee, "%s: \"%s\"", lang(ReservedSwitchName), m_SwitchName.c_str());
60 if(mpi->FindModelSwitch(m_SwitchName))
61 throw CSynErr(eee, "%s: \"%s\"", lang(OverlappedSwitchName), m_SwitchName.c_str());
62
63 if(tmp = AsgnString(str, "GroupCommon", &m_GroupCommon)) str = tmp;
64 else m_GroupCommon = "";
65
66 string entry;
67 m_Entry.clear();
68 while(true){
69 if(tmp = AsgnString(str, "Entry", &entry)){
70 str = tmp;
71 m_Entry.push_back(entry);
72 }else{
73 break;
74 }
75 }
76
77 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
78 return str;
79 }
80
81 /*
82 * 現在の設定を取得
83 */
84 char *CModelSwitch::GetCurrentOptionName(){
85 int i = 0;
86 Istring is = m_Entry.begin();
87 for(; is!=m_Entry.end(); is++, i++) if(i==m_Value) return (char *)is->c_str();
88 return "";
89 }
90
91 /*
92 * エントリリスト作成
93 */
94 void CModelSwitch::ListEntry(
95 CListView *olv // リストビュー
96 ){
97 olv->DeleteAllItems();
98 int i = 0;
99 Istring is = m_Entry.begin();
100 for(; is!=m_Entry.end(); is++, i++){
101 CListElement *ole = olv->InsertItem(-1, (char *)is->c_str());
102 ole->SetData(i);
103 }
104 olv->SetSelectionMark(m_Value, 0);
105 }
106
107 /*
108 * スイッチリスト作成
109 */
110 void CModelSwitch::EditSwitch(
111 CListView *olv, // オプションリストビュー
112 int *link, // リンク変数
113 int switch_id // スイッチ ID
114 ){
115 if(!m_Entry.size()) return;
116 CListElement *ole = olv->GetFocusItem();
117 bool force_reset = false;
118 if(g_NetworkInitialized && switch_id>=0){
119 if(g_StaticSwitchTable[switch_id].net_sync){
120 force_reset = true;
121 g_StaticSwitchTable[switch_id].tmp_opt = m_Value;
122 g_StaticSwitchTable[switch_id].net_sync = false;
123 }else{
124 link = &g_StaticSwitchTable[switch_id].tmp_opt;
125 }
126 }
127 if(ole && ole->IsSelected() && !force_reset){
128 int opt = ole->GetData();
129 if(opt!=m_Value){
130 m_Value = opt;
131 bool async = false;
132 if(link && *link!=m_Value){
133 async = true;
134 *link = m_Value;
135 }
136 m_ListElement->SetString(1, GetCurrentOptionName());
137 if(switch_id>=0 && g_NetworkInitialized && async){
138 //Dialog("set switch [%d] <= %d", switch_id, m_Value);
139 void EnqueueSwitchControl(int, int);
140 EnqueueSwitchControl(switch_id, m_Value);
141 }
142 }
143 }else{
144 olv->SetSelectionMark(m_Value, 0);
145 }
146 }
147
148 ////////////////////////////////////////////////////////////////////////////////
149 ////////////////////////////////////////////////////////////////////////////////
150
151 /*
152 * 読込
153 */
154 char *CSwitchEntry::Read(
155 char *str, // 対象文字列
156 CModelPlugin *mpi, // モデルプラグイン
157 int condtype // 条件タイプ
158 ){
159 char *tmp, *eee;
160 int value;
161 m_TypeFlag = 0;
162 m_ConditionType = condtype;
163 m_Value.clear();
164 if(!m_ConditionType){
165 if(!(str = Identifier2(str, "Case"))) return NULL;
166 if(!(str = ConstInteger(eee = str, &value))) throw CSynErr(eee);
167 m_Value.push_back(value);
168 while(tmp = Character2(str, ',')){
169 str = tmp;
170 if(!(str = ConstInteger(eee = str, &value))) throw CSynErr(eee);
171 m_Value.push_back(value);
172 }
173 if(!(str = Character2(eee = str, ':'))) throw CSynErr(eee);
174 }
175 if(!(str = Read2(eee = str, mpi))) throw CSynErr(eee);
176 return str;
177 }
178
179 /*
180 * スイッチ値チェック
181 */
182 bool CSwitchEntry::CheckValue(
183 int value, // 判定値
184 bool def // デフォルト
185 ){
186 switch(m_ConditionType){
187 case 0: {
188 int i, vn = m_Value.size();
189 if(!vn) return true;
190 for(i = 0; i<vn; i++) if(m_Value[i]==value) return true;
191 return false; }
192 case 1:
193 return true;
194 case 2:
195 return !!value;
196 case 3:
197 return !value;
198 case 4:
199 return def;
200 }
201 return false;
202 }
203
204 ////////////////////////////////////////////////////////////////////////////////
205 ////////////////////////////////////////////////////////////////////////////////
206
207 /*
208 * コンストラクタ
209 */
210 CSwitchApplier::CSwitchApplier(
211 const CSwitchApplier *src // コピー元
212 ){
213 m_TypeFlag = src->m_TypeFlag;
214 m_Expression = src->m_Expression->Duplicate();
215 }
216
217 /*
218 * デストラクタ
219 */
220 CSwitchApplier::~CSwitchApplier(){
221 DELETE_V(m_Expression);
222 }
223
224 /*
225 * 読込
226 */
227 char *CSwitchApplier::Read(
228 char *str, // 対象文字列
229 CModelPlugin *mpi // モデルプラグイン
230 ){
231 char *eee, *tmp;
232 m_TypeFlag = 0;
233 if(tmp = Identifier2(eee = str, "ApplySwitch")){
234 str = tmp;
235 g_SwitchOwner = mpi;
236 if(!(str = Expression(eee = str, &m_Expression))) throw CSynErr(eee, lang(InvalidExpression));
237 g_SwitchOwner = NULL;
238 if(!(str = Character2(eee = str, '{'))) return NULL;
239 while(true){
240 if(!(tmp = Read2(eee = str, mpi, 0))) throw CSynErr(eee);
241 if(tmp==str) break;
242 str = tmp;
243 }
244 if(tmp = Identifier2(str, "Default")){
245 str = tmp;
246 if(!(str = Character2(eee = str, ':'))) throw CSynErr(eee);
247 if(!(str = Read2(eee = str, mpi, 4))) throw CSynErr(eee);
248 }
249 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
250 return str;
251 }else if(tmp = Identifier2(eee = str, "If")){
252 str = tmp;
253 g_SwitchOwner = mpi;
254 if(!(str = Expression(eee = str, &m_Expression))) throw CSynErr(eee, lang(InvalidExpression));
255 g_SwitchOwner = NULL;
256 if(!(str = Character2(eee = str, '{'))) return NULL;
257 if(!(str = Read2(eee = str, mpi, 2))) throw CSynErr(eee);
258 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
259 if(tmp = BeginBlock(str, "Else")){
260 str = tmp;
261 if(!(str = Read2(eee = str, mpi, 3))) throw CSynErr(eee);
262 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
263 }
264 return str;
265 }else{
266 return NULL;
267 }
268 }
269
270 /*
271 * 数式計算
272 */
273 int CSwitchApplier::GetSwitchValue(){
274 return m_Expression->CalcInt();
275 }
276
277 ////////////////////////////////////////////////////////////////////////////////
278 ////////////////////////////////////////////////////////////////////////////////
279
280 /*
281 * 読込
282 */
283 char *CCustomizerSwitchEntry::Read2(
284 char *str, // 対象文字列
285 CModelPlugin *mpi // モデルプラグイン
286 ){
287 char *tmp;
288 m_Customizer.clear();
289 CCustomizerContainer cont;
290 while(tmp = cont.Read(str, mpi)){
291 str = tmp;
292 m_Customizer.push_back(cont);
293 m_TypeFlag |= cont.GetTypeFlag();
294 }
295 return str;
296 }
297
298 /*
299 * データ読込
300 */
301 void CCustomizerSwitchEntry::LoadData(
302 CModelPlugin *mpi // 呼び出し元
303 ){
304 ICustomizerContainer icc = m_Customizer.begin();
305 for(; icc!=m_Customizer.end(); icc++) icc->LoadData(mpi);
306 }
307
308 /*
309 * 常時適用リスト作成
310 */
311 void CCustomizerSwitchEntry::SetOffList(
312 CNamedObject *nobj // 呼び出し元
313 ){
314 ICustomizerContainer icc = m_Customizer.begin();
315 for(; icc!=m_Customizer.end(); icc++) icc->SetOffList(nobj);
316 }
317
318 /*
319 * 代替モデル取得
320 */
321 CMesh *CCustomizerSwitchEntry::GetMesh(
322 float *asc // スケール格納先
323 ){
324 if(!(m_TypeFlag&CSTM_MODELCHANGER)) return NULL;
325 ICustomizerContainer icc = m_Customizer.begin();
326 for(; icc!=m_Customizer.end(); icc++){
327 CMesh *tm = icc->GetMesh(asc);
328 if(*asc>=0.0f) return tm;
329 }
330 return NULL;
331 }
332
333 /*
334 * 姿勢適用
335 */
336 void CCustomizerSwitchEntry::SetPosture(
337 CObject *obj // オブジェクト
338 ){
339 if(!(m_TypeFlag&CSTM_MODELMOVER)) return;
340 ICustomizerContainer icc = m_Customizer.begin();
341 for(; icc!=m_Customizer.end(); icc++) icc->SetPosture(obj);
342 }
343
344 /*
345 * 変更子適用
346 */
347 void CCustomizerSwitchEntry::Apply(
348 CMesh *mesh // メッシュ
349 ){
350 if(!(m_TypeFlag&CSTM_MISCELLANEOUS)) return;
351 ICustomizerContainer icc = m_Customizer.begin();
352 for(; icc!=m_Customizer.end(); icc++) icc->Apply(mesh);
353 }
354
355 ////////////////////////////////////////////////////////////////////////////////
356 ////////////////////////////////////////////////////////////////////////////////
357
358 /*
359 * 読込
360 */
361 char *CCustomizerSwitchApplier::Read2(
362 char *str, // 対象文字列
363 CModelPlugin *mpi, // モデルプラグイン
364 int condtype // 条件タイプ
365 ){
366 char *tmp;
367 CCustomizerSwitchEntry swent;
368 if(tmp = swent.Read(str, mpi, condtype)){
369 str = tmp;
370 m_Entry.push_back(swent);
371 m_TypeFlag |= swent.GetTypeFlag();
372 }
373 return str;
374 }
375
376 /*
377 * データ読込
378 */
379 void CCustomizerSwitchApplier::LoadDataCustomizer(
380 CModelPlugin *mpi // 呼び出し元
381 ){
382 ICustomizerSwitchEntry ise = m_Entry.begin();
383 for(; ise!=m_Entry.end(); ise++) ise->LoadData(mpi);
384 }
385
386 /*
387 * 常時適用リスト作成
388 */
389 void CCustomizerSwitchApplier::SetOffListCustomizer(
390 CNamedObject *nobj // 呼び出し元
391 ){
392 ICustomizerSwitchEntry ise = m_Entry.begin();
393 for(; ise!=m_Entry.end(); ise++) ise->SetOffList(nobj);
394 }
395
396 /*
397 * 代替モデル取得
398 */
399 CMesh *CCustomizerSwitchApplier::GetMeshCustomizer(
400 float *asc // スケール格納先
401 ){
402 if(!(m_TypeFlag&CSTM_MODELCHANGER)) return NULL;
403 ICustomizerSwitchEntry ise = m_Entry.begin();
404 int eval = GetSwitchValue();
405 bool def = true;
406 for(; ise!=m_Entry.end(); ise++){
407 if(ise->CheckValue(eval, def)){
408 def = false;
409 CMesh *tm = ise->GetMesh(asc);
410 if(*asc>=0.0f) return tm;
411 }
412 }
413 return NULL;
414 }
415
416 /*
417 * 姿勢適用
418 */
419 void CCustomizerSwitchApplier::SetPostureCustomizer(
420 CObject *obj // オブジェクト
421 ){
422 if(!(m_TypeFlag&CSTM_MODELMOVER)) return;
423 ICustomizerSwitchEntry ise = m_Entry.begin();
424 int eval = GetSwitchValue();
425 bool def = true;
426 for(; ise!=m_Entry.end(); ise++){
427 if(ise->CheckValue(eval, def)){
428 def = false;
429 ise->SetPosture(obj);
430 }
431 }
432 }
433
434 /*
435 * 変更子適用
436 */
437 void CCustomizerSwitchApplier::ApplyCustomizer(
438 CMesh *mesh // メッシュ
439 ){
440 if(!(m_TypeFlag&CSTM_MISCELLANEOUS)) return;
441 ICustomizerSwitchEntry ise = m_Entry.begin();
442 int eval = GetSwitchValue();
443 bool def = true;
444 for(; ise!=m_Entry.end(); ise++){
445 if(ise->CheckValue(eval, def)){
446 def = false;
447 ise->Apply(mesh);
448 }
449 }
450 }
451
452 ////////////////////////////////////////////////////////////////////////////////
453 ////////////////////////////////////////////////////////////////////////////////
454
455 /*
456 * 読込
457 */
458 char *CEffectorSwitchEntry::Read2(
459 char *str, // 対象文字列
460 CModelPlugin *mpi // モデルプラグイン
461 ){
462 char *tmp;
463 m_Effector.clear();
464 CEffectorContainer cont;
465 while(tmp = cont.Read(str, mpi)){
466 str = tmp;
467 m_Effector.push_back(cont);
468 m_TypeFlag |= cont.GetTypeFlag();
469 }
470 return str;
471 }
472
473 /*
474 * データ読込
475 */
476 void CEffectorSwitchEntry::LoadData(
477 CModelPlugin *mpi // 呼び出し元
478 ){
479 IEffectorContainer icc = m_Effector.begin();
480 for(; icc!=m_Effector.end(); icc++) icc->LoadData(mpi);
481 }
482
483 /*
484 * 変更子適用
485 */
486 void CEffectorSwitchEntry::Apply(
487 CScene *scene // シーン
488 ){
489 if(!(m_TypeFlag&CurrentEnabledEffectorTypes())) return;
490 IEffectorContainer icc = m_Effector.begin();
491 for(; icc!=m_Effector.end(); icc++) icc->Apply(scene);
492 }
493
494 ////////////////////////////////////////////////////////////////////////////////
495 ////////////////////////////////////////////////////////////////////////////////
496
497 /*
498 * 読込
499 */
500 char *CEffectorSwitchApplier::Read2(
501 char *str, // 対象文字列
502 CModelPlugin *mpi, // モデルプラグイン
503 int condtype // 条件タイプ
504 ){
505 char *tmp;
506 CEffectorSwitchEntry swent;
507 if(tmp = swent.Read(str, mpi, condtype)){
508 str = tmp;
509 m_Entry.push_back(swent);
510 m_TypeFlag |= swent.GetTypeFlag();
511 }
512 return str;
513 }
514
515 /*
516 * データ読込
517 */
518 void CEffectorSwitchApplier::LoadDataEffector(
519 CModelPlugin *mpi // 呼び出し元
520 ){
521 IEffectorSwitchEntry ise = m_Entry.begin();
522 for(; ise!=m_Entry.end(); ise++) ise->LoadData(mpi);
523 }
524
525 /*
526 * 変更子適用
527 */
528 void CEffectorSwitchApplier::ApplyEffector(
529 CScene *scene // シーン
530 ){
531 if(!(m_TypeFlag&CurrentEnabledEffectorTypes())) return;
532 IEffectorSwitchEntry ise = m_Entry.begin();
533 int eval = GetSwitchValue();
534 bool def = true;
535 for(; ise!=m_Entry.end(); ise++){
536 if(ise->CheckValue(eval, def)){
537 def = false;
538 ise->Apply(scene);
539 }
540 }
541 }
542
543 ////////////////////////////////////////////////////////////////////////////////
544 ////////////////////////////////////////////////////////////////////////////////
545
546 /*
547 * システムスイッチ初期化
548 */
549 void InitSystemSwitch(){
550 g_SystemSwitch[SYS_SW_FRONT].Init(-SYS_SW_FRONT-1, "_FRONT");
551 g_SystemSwitch[SYS_SW_CONNECT1].Init(-SYS_SW_CONNECT1-1, "_CONNECT1");
552 g_SystemSwitch[SYS_SW_CONNECT2].Init(-SYS_SW_CONNECT2-1, "_CONNECT2");
553 g_SystemSwitch[SYS_SW_DOOR1].Init(-SYS_SW_DOOR1-1, "_DOOR1");
554 g_SystemSwitch[SYS_SW_DOOR2].Init(-SYS_SW_DOOR2-1, "_DOOR2");
555 g_SystemSwitch[SYS_SW_SERIAL].Init(-SYS_SW_SERIAL-1, "_SERIAL");
556 g_SystemSwitch[SYS_SW_CAMDIST].Init(-SYS_SW_CAMDIST-1, "_CAMDIST");
557 g_SystemSwitch[SYS_SW_VELOCITY].Init(-SYS_SW_VELOCITY-1, "_VELOCITY");
558 g_SystemSwitch[SYS_SW_ACCEL].Init(-SYS_SW_ACCEL-1, "_ACCEL");
559 g_SystemSwitch[SYS_SW_CABINVIEW].Init(-SYS_SW_CABINVIEW-1, "_CABINVIEW");
560 g_SystemSwitch[SYS_SW_APPROACH1].Init(-SYS_SW_APPROACH1-1, "_APPROACH1");
561 g_SystemSwitch[SYS_SW_APPROACH2].Init(-SYS_SW_APPROACH2-1, "_APPROACH2");
562 g_SystemSwitch[SYS_SW_STOPPING].Init(-SYS_SW_STOPPING-1, "_STOPPING");
563
564 g_SystemSwitch[SYS_SW_NIGHT].Init(-SYS_SW_NIGHT-1, "_NIGHT");
565 g_SystemSwitch[SYS_SW_WEATHER].Init(-SYS_SW_WEATHER-1, "_WEATHER");
566 g_SystemSwitch[SYS_SW_SEASON].Init(-SYS_SW_WEATHER-1, "_SEASON");
567 g_SystemSwitch[SYS_SW_SHADOW].Init(-SYS_SW_SHADOW-1, "_SHADOW");
568 g_SystemSwitch[SYS_SW_ENVMAP].Init(-SYS_SW_ENVMAP-1, "_ENVMAP");
569 g_SystemSwitch[SYS_SW_YEAR].Init(-SYS_SW_YEAR-1, "_YEAR");
570 g_SystemSwitch[SYS_SW_MONTH].Init(-SYS_SW_MONTH-1, "_MONTH");
571 g_SystemSwitch[SYS_SW_DAY].Init(-SYS_SW_DAY-1, "_DAY");
572 g_SystemSwitch[SYS_SW_DAYOFWEEK].Init(-SYS_SW_DAYOFWEEK-1, "_DAYOFWEEK");
573 g_SystemSwitch[SYS_SW_HOUR].Init(-SYS_SW_HOUR-1, "_HOUR");
574 g_SystemSwitch[SYS_SW_MINUTE].Init(-SYS_SW_MINUTE-1, "_MINUTE");
575 g_SystemSwitch[SYS_SW_SECOND].Init(-SYS_SW_SECOND-1, "_SECOND");
576 }
577
578 /*
579 * カメラ距離スイッチ設定
580 */
581 void SetCamDistSwitch(
582 VEC3 pos // 視点座標
583 ){
584 g_SystemSwitch[SYS_SW_CAMDIST].SetValue(Round(g_FovRatio*V3Len(&(pos-GetVPos()))));
585 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26