| 1 |
#include "stdafx.h" |
| 2 |
#include "CJobTimer.h" |
| 3 |
#include "CRailDetectCurve.h" |
| 4 |
#include "CRailConnector.h" |
| 5 |
#include "CPier.h" |
| 6 |
#include "CLine.h" |
| 7 |
#include "CStation.h" |
| 8 |
#include "CScene.h" |
| 9 |
#include "CSaveFile.h" |
| 10 |
#include "CRailPlugin.h" |
| 11 |
#include "CTiePlugin.h" |
| 12 |
#include "CGirderPlugin.h" |
| 13 |
#include "CPierPlugin.h" |
| 14 |
#include "CLinePlugin.h" |
| 15 |
#include "CPolePlugin.h" |
| 16 |
#include "CStructPlugin.h" |
| 17 |
#include "CSurfacePlugin.h" |
| 18 |
#include "CRailBuildMode.h" |
| 19 |
#include "CSceneEditMode.h" |
| 20 |
#include "CEnvPlugin.h" |
| 21 |
#include "CSimulationMode.h" |
| 22 |
#include "CConfigMode.h" |
| 23 |
|
| 24 |
// 内部定数 |
| 25 |
const float SURFACE_PICK_OFFSET = 10.0f; // 地形ピックオフセット |
| 26 |
|
| 27 |
// 外部グローバル |
| 28 |
extern CLineDumpN *g_LineDumpN; |
| 29 |
extern COffScreen g_HidefCapture; |
| 30 |
extern bool g_HidefCaptureFlag; |
| 31 |
extern bool g_SelectMultiTrackDummy; |
| 32 |
|
| 33 |
// 内部グローバル |
| 34 |
CSurfacePlugin *g_Surface; // カレントサーフェイス |
| 35 |
CEnvPlugin *g_Env; // カレント環境 |
| 36 |
|
| 37 |
/* |
| 38 |
* コンストラクタ (読込用) |
| 39 |
*/ |
| 40 |
CScene::CScene(){ |
| 41 |
m_ArrowPos = V3ZERO; |
| 42 |
m_ListElement = NULL; |
| 43 |
m_Camera.Init(200.0f, 2.0f, 5000.0f, true); |
| 44 |
m_RailConnector = NULL; |
| 45 |
m_RailWay = NULL; |
| 46 |
m_Pier = NULL; |
| 47 |
m_Line = NULL; |
| 48 |
m_Pole = NULL; |
| 49 |
m_Station = NULL; |
| 50 |
m_Struct = NULL; |
| 51 |
m_SurfacePlugin = NULL; |
| 52 |
m_EnvPlugin = NULL; |
| 53 |
m_IsDumpReady = false; |
| 54 |
m_Next = NULL; |
| 55 |
} |
| 56 |
|
| 57 |
/* |
| 58 |
* コンストラクタ |
| 59 |
*/ |
| 60 |
CScene::CScene( |
| 61 |
CSurfacePlugin *spi, // 地形プラグイン |
| 62 |
CEnvPlugin *epi, // 環境プラグイン |
| 63 |
char *name // 名称 |
| 64 |
): |
| 65 |
CStruct(spi) // 基本クラス |
| 66 |
{ |
| 67 |
m_Name = name; |
| 68 |
m_ArrowPos = V3ZERO; |
| 69 |
m_ListElement = NULL; |
| 70 |
m_Camera.Init(200.0f, 2.0f, 5000.0f, true); |
| 71 |
m_RailConnector = NULL; |
| 72 |
m_RailWay = NULL; |
| 73 |
m_Pier = NULL; |
| 74 |
m_Line = NULL; |
| 75 |
m_Pole = NULL; |
| 76 |
m_Station = NULL; |
| 77 |
m_Struct = NULL; |
| 78 |
m_SurfacePlugin = spi; |
| 79 |
m_EnvPlugin = epi; |
| 80 |
m_Next = NULL; |
| 81 |
m_SurfacePlugin->SetSwitch(this); |
| 82 |
m_SurfacePlugin->SetPartsInst(this); |
| 83 |
m_SurfacePlugin->SetMoverState(this); |
| 84 |
SetLocalAxis(); |
| 85 |
SetCamDistSwitch(V3ZERO); |
| 86 |
m_SurfacePlugin->SetPosture(); |
| 87 |
if(PickScene(100.0f*V3UP, -V3UP, &m_ArrowPos)) |
| 88 |
m_Camera.SetFocus(m_ArrowPos); |
| 89 |
// else Dialog("not hit"); |
| 90 |
} |
| 91 |
|
| 92 |
/* |
| 93 |
* デストラクタ |
| 94 |
*/ |
| 95 |
CScene::~CScene(){ |
| 96 |
DELETE_V(m_RailConnector); |
| 97 |
DELETE_V(m_RailWay); |
| 98 |
DELETE_V(m_Pier); |
| 99 |
DELETE_V(m_Line); |
| 100 |
DELETE_V(m_Pole); |
| 101 |
DELETE_V(m_Station); |
| 102 |
DELETE_V(m_Struct); |
| 103 |
DELETE_V(m_Next); |
| 104 |
} |
| 105 |
|
| 106 |
/* |
| 107 |
* 番号付きシーン名取得 |
| 108 |
*/ |
| 109 |
char *CScene::GetNumberedName(){ |
| 110 |
return FlashIn("(%d/%d) %s", m_Serial+1, g_SaveFile->GetSceneNum(), m_Name.c_str()); |
| 111 |
} |
| 112 |
|
| 113 |
/* |
| 114 |
* 季節設定 |
| 115 |
*/ |
| 116 |
void CScene::SetSeason(){ |
| 117 |
static int season[12] = {3, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3}; |
| 118 |
int frev = g_SimulationMode->GetEarthRevolution(); |
| 119 |
g_SystemSwitch[SYS_SW_SEASON].SetValue(frev ? frev-1 |
| 120 |
: season[((m_EnvPlugin->GetHemisphere() ? 6 : 0)+g_SaveFile->GetMonth())%12]); |
| 121 |
} |
| 122 |
|
| 123 |
/* |
| 124 |
* シーン適用 |
| 125 |
*/ |
| 126 |
void CScene::Enter( |
| 127 |
bool selectcamera // カメラ選択フラグ |
| 128 |
){ |
| 129 |
g_Scene = this; |
| 130 |
g_Surface = m_SurfacePlugin; |
| 131 |
g_Env = m_EnvPlugin; |
| 132 |
CSoundEffector::InitPlayList(); |
| 133 |
CRailConnector::SetRoot(&m_RailConnector); |
| 134 |
CRailWay::SetRoot(&m_RailWay); |
| 135 |
CPier::SetRoot(&m_Pier); |
| 136 |
CLine::SetRoot(&m_Line); |
| 137 |
CPole::SetRoot(&m_Pole); |
| 138 |
CStruct::SetRoot(&m_Struct); |
| 139 |
CStation::SetRoot(&m_Station); |
| 140 |
m_Camera.SetFocusInfo(R2L(CDetectInfo())); |
| 141 |
if(selectcamera) m_Camera.Select(); |
| 142 |
m_ArrowPos = m_Camera.GetFocus(); |
| 143 |
if(!m_IsDumpReady) Dump(); |
| 144 |
if(g_RailBuildMode) g_RailBuildMode->ResetBuilder(); |
| 145 |
} |
| 146 |
|
| 147 |
/* |
| 148 |
* システム座標系設定 |
| 149 |
*/ |
| 150 |
void CScene::SetGlobalAxis(){ |
| 151 |
VEC3 ldir, lup = V3UP; |
| 152 |
V3Norm(&ldir, (VEC3*)&svl.dir.Direction); |
| 153 |
if(ldir.x==0.0f && ldir.y==0.0f) ldir.z = 1.0f; |
| 154 |
g_SystemObject[SYS_OBJ_CAMERA].SetPreviewPosture(GetVPos(), GetVDir(), GetVUp()); |
| 155 |
g_SystemObject[SYS_OBJ_LIGHT].SetPreviewPosture(-ldir*1.0e8f, ldir, lup); |
| 156 |
} |
| 157 |
|
| 158 |
/* |
| 159 |
* レールリストルート再設定 |
| 160 |
*/ |
| 161 |
void CScene::ResetRailWayRoot(){ |
| 162 |
CRailWay::SetRoot(&m_RailWay); |
| 163 |
} |
| 164 |
|
| 165 |
/* |
| 166 |
* レールリストルート再設定 |
| 167 |
*/ |
| 168 |
void CScene::ResetRailConnectorRoot(){ |
| 169 |
CRailConnector::SetRoot(&m_RailConnector); |
| 170 |
} |
| 171 |
|
| 172 |
/* |
| 173 |
* シーン削除処理 |
| 174 |
*/ |
| 175 |
void CScene::Delete(){ |
| 176 |
while(m_Station) DeleteStation(m_Station); |
| 177 |
CRailConnector *con = m_RailConnector; |
| 178 |
while(con){ |
| 179 |
con->RemoveGroup(); |
| 180 |
con = con->Next(); |
| 181 |
} |
| 182 |
CRailWay *way = m_RailWay; |
| 183 |
while(way){ |
| 184 |
way->RemoveGroup(); |
| 185 |
way = way->Next(); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
/* |
| 190 |
* 編成の削除 |
| 191 |
*/ |
| 192 |
void CScene::DeleteGroup( |
| 193 |
CTrainGroup *group // 編成 |
| 194 |
){ |
| 195 |
CRailConnector *con = m_RailConnector; |
| 196 |
while(con){ |
| 197 |
con->DeleteGroup(group); |
| 198 |
con = con->Next(); |
| 199 |
} |
| 200 |
CStation *sta = m_Station; |
| 201 |
while(sta){ |
| 202 |
sta->DeleteGroup(group); |
| 203 |
sta = sta->Next(); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
/* |
| 208 |
* 橋脚リンクの削除 |
| 209 |
*/ |
| 210 |
void CScene::DeletePierLink( |
| 211 |
CPier *pier // 橋脚 |
| 212 |
){ |
| 213 |
CRailWay *ptr = m_RailWay; |
| 214 |
while(ptr){ |
| 215 |
ptr->DeletePier(pier); |
| 216 |
ptr = ptr->Next(); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
/* |
| 221 |
* 架線リンクの削除 |
| 222 |
*/ |
| 223 |
void CScene::DeletePoleLink( |
| 224 |
CPole *pole // 架線柱 |
| 225 |
){ |
| 226 |
CRailWay *ptr = m_RailWay; |
| 227 |
while(ptr){ |
| 228 |
ptr->DeletePole(pole); |
| 229 |
ptr = ptr->Next(); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
/* |
| 234 |
* 未使用コネクタ撤去 |
| 235 |
*/ |
| 236 |
bool CScene::DeleteRailConnector(){ |
| 237 |
bool deleted = false; |
| 238 |
CRailConnector *ptr, **adr = &m_RailConnector; |
| 239 |
while(ptr = *adr){ |
| 240 |
*adr = ptr->Delete(); |
| 241 |
if(ptr==*adr) adr = ptr->NextAdr(); |
| 242 |
else deleted = true; |
| 243 |
} |
| 244 |
return deleted; |
| 245 |
} |
| 246 |
|
| 247 |
/* |
| 248 |
* レール撤去 |
| 249 |
*/ |
| 250 |
bool CScene::DeleteRailWay(){ |
| 251 |
bool deleted = false; |
| 252 |
CRailWay *ptr = m_RailWay; |
| 253 |
while(ptr){ |
| 254 |
ptr->SplitSelect(); |
| 255 |
ptr = ptr->Next(); |
| 256 |
} |
| 257 |
CRailWay **adr = &m_RailWay; |
| 258 |
while(ptr = *adr){ |
| 259 |
*adr = ptr->Delete(); |
| 260 |
if(ptr==*adr) adr = ptr->NextAdr(); |
| 261 |
else deleted = true; |
| 262 |
} |
| 263 |
DeleteRailConnector(); |
| 264 |
g_SaveFile->DeleteWarp(); |
| 265 |
return deleted; |
| 266 |
} |
| 267 |
|
| 268 |
/* |
| 269 |
* 閉塞区間設定 |
| 270 |
*/ |
| 271 |
bool CScene::SetRailBlock(char *rb){ |
| 272 |
bool changed = false; |
| 273 |
CRailWay *ptr = m_RailWay; |
| 274 |
while(ptr){ |
| 275 |
ptr->SplitSelect(); |
| 276 |
ptr = ptr->Next(); |
| 277 |
} |
| 278 |
ptr = m_RailWay; |
| 279 |
while(ptr){ |
| 280 |
changed |= ptr->SetRailBlock(rb); |
| 281 |
ptr = ptr->Next(); |
| 282 |
} |
| 283 |
return changed; |
| 284 |
} |
| 285 |
|
| 286 |
/* |
| 287 |
* 制限速度設定 |
| 288 |
*/ |
| 289 |
bool CScene::SetSpeedLimit(int sl){ |
| 290 |
bool changed = false; |
| 291 |
CRailWay *ptr = m_RailWay; |
| 292 |
while(ptr){ |
| 293 |
ptr->SplitSelect(); |
| 294 |
ptr = ptr->Next(); |
| 295 |
} |
| 296 |
ptr = m_RailWay; |
| 297 |
while(ptr){ |
| 298 |
changed |= ptr->SetSpeedLimit(sl); |
| 299 |
ptr = ptr->Next(); |
| 300 |
} |
| 301 |
return changed; |
| 302 |
} |
| 303 |
|
| 304 |
/* |
| 305 |
* 橋脚撤去 |
| 306 |
*/ |
| 307 |
bool CScene::DeletePier( |
| 308 |
CPier *pier // 橋脚 |
| 309 |
){ |
| 310 |
bool deleted = false; |
| 311 |
CPier **adr = &m_Pier; |
| 312 |
while(*adr){ |
| 313 |
CPier *ptr = *adr; |
| 314 |
if(pier ? ptr==pier : ptr->GetSelectFlag()&2){ |
| 315 |
*adr = ptr->Next(); |
| 316 |
ptr->Delete(); |
| 317 |
deleted = true; |
| 318 |
continue; |
| 319 |
} |
| 320 |
adr = ptr->NextAdr(); |
| 321 |
} |
| 322 |
return deleted; |
| 323 |
} |
| 324 |
|
| 325 |
/* |
| 326 |
* 架線撤去 |
| 327 |
*/ |
| 328 |
bool CScene::DeleteLine( |
| 329 |
CLine *line // 架線 |
| 330 |
){ |
| 331 |
bool deleted = false; |
| 332 |
CLine **adr = &m_Line; |
| 333 |
while(*adr){ |
| 334 |
CLine *ptr = *adr; |
| 335 |
if(line ? ptr==line : ptr->GetSelectFlag()&2){ |
| 336 |
*adr = ptr->Next(); |
| 337 |
ptr->Delete(); |
| 338 |
deleted = true; |
| 339 |
continue; |
| 340 |
} |
| 341 |
adr = ptr->NextAdr(); |
| 342 |
} |
| 343 |
return deleted; |
| 344 |
} |
| 345 |
|
| 346 |
/* |
| 347 |
* 架線柱撤去 |
| 348 |
*/ |
| 349 |
bool CScene::DeletePole( |
| 350 |
CPole *pole // 架線柱 |
| 351 |
){ |
| 352 |
bool deleted = false; |
| 353 |
CPole **adr = &m_Pole; |
| 354 |
while(*adr){ |
| 355 |
CPole *ptr = *adr; |
| 356 |
if(pole ? ptr==pole : ptr->GetSelectFlag()&2){ |
| 357 |
*adr = ptr->Next(); |
| 358 |
ptr->Delete(this); |
| 359 |
deleted = true; |
| 360 |
continue; |
| 361 |
} |
| 362 |
adr = ptr->NextAdr(); |
| 363 |
} |
| 364 |
return deleted; |
| 365 |
} |
| 366 |
|
| 367 |
/* |
| 368 |
* 駅舎撤去 |
| 369 |
*/ |
| 370 |
bool CScene::DeleteStation( |
| 371 |
CStation *station // 駅舎 |
| 372 |
){ |
| 373 |
bool deleted = false; |
| 374 |
CStation **adr = &m_Station; |
| 375 |
while(*adr){ |
| 376 |
CStation *ptr = *adr; |
| 377 |
if(station ? ptr==station : ptr->GetSelectFlag()&2){ |
| 378 |
*adr = ptr->Next(); |
| 379 |
ptr->Delete(); |
| 380 |
deleted = true; |
| 381 |
continue; |
| 382 |
} |
| 383 |
adr = ptr->NextAdr(); |
| 384 |
} |
| 385 |
if(deleted) Dump(); |
| 386 |
return deleted; |
| 387 |
} |
| 388 |
|
| 389 |
/* |
| 390 |
* 施設撤去 |
| 391 |
*/ |
| 392 |
bool CScene::DeleteStruct( |
| 393 |
CStruct *strct // 施設 |
| 394 |
){ |
| 395 |
bool deleted = false; |
| 396 |
CStruct **adr = &m_Struct; |
| 397 |
while(*adr){ |
| 398 |
CStruct *ptr = *adr; |
| 399 |
if(strct ? ptr==strct : ptr->GetSelectFlag()&2){ |
| 400 |
*adr = ptr->Next(); |
| 401 |
ptr->Delete(); |
| 402 |
deleted = true; |
| 403 |
continue; |
| 404 |
} |
| 405 |
adr = ptr->NextAdr(); |
| 406 |
} |
| 407 |
return deleted; |
| 408 |
} |
| 409 |
|
| 410 |
/* |
| 411 |
* レール入力チェック |
| 412 |
*/ |
| 413 |
void CScene::ScanInputRailWay( |
| 414 |
int mode, // モード (0: link) |
| 415 |
VEC3 rect1, // 領域始点 |
| 416 |
VEC3 rect2, // 領域終点 |
| 417 |
bool mtd // 複線ダミー選択フラグ |
| 418 |
){ |
| 419 |
g_SelectMultiTrackDummy = mtd; |
| 420 |
if(mode==2) V3MinMax(rect1, rect2, &rect1, &rect2); |
| 421 |
CRailDetectCurve3D::ResetDetect(); |
| 422 |
CRailDetectCurve2D::ResetDetect(); |
| 423 |
CRailWay *way = m_RailWay; |
| 424 |
while(way){ |
| 425 |
way->ScanInput(mode, rect1, rect2); |
| 426 |
way = way->Next(); |
| 427 |
} |
| 428 |
g_SelectMultiTrackDummy = true; |
| 429 |
} |
| 430 |
|
| 431 |
/* |
| 432 |
* コネクタ入力チェック |
| 433 |
*/ |
| 434 |
void CScene::ScanInputRailConnector( |
| 435 |
int mode, // モード (0: link) |
| 436 |
VEC3 rect1, // 領域始点 |
| 437 |
VEC3 rect2 // 領域終点 |
| 438 |
){ |
| 439 |
if(mode==2) V3MinMax(rect1, rect2, &rect1, &rect2); |
| 440 |
CRailConnector::ResetDetect(); |
| 441 |
CRailConnector *con = m_RailConnector; |
| 442 |
while(con){ |
| 443 |
con->ScanInput(mode, rect1, rect2); |
| 444 |
con = con->Next(); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
/* |
| 449 |
* 橋脚入力チェック |
| 450 |
*/ |
| 451 |
void CScene::ScanInputPier( |
| 452 |
int mode, // モード |
| 453 |
VEC3 rect1, // 領域始点 |
| 454 |
VEC3 rect2 // 領域終点 |
| 455 |
){ |
| 456 |
if(mode==2) V3MinMax(rect1, rect2, &rect1, &rect2); |
| 457 |
CPier::ResetDetect(); |
| 458 |
CPier *pier = m_Pier; |
| 459 |
while(pier){ |
| 460 |
pier->ScanInput(mode, rect1, rect2); |
| 461 |
pier = pier->Next(); |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
/* |
| 466 |
* 架線入力チェック |
| 467 |
*/ |
| 468 |
void CScene::ScanInputLine( |
| 469 |
int mode, // モード |
| 470 |
VEC3 rect1, // 領域始点 |
| 471 |
VEC3 rect2 // 領域終点 |
| 472 |
){ |
| 473 |
if(mode==2) V3MinMax(rect1, rect2, &rect1, &rect2); |
| 474 |
CLine::ResetDetect(); |
| 475 |
CLine *line = m_Line; |
| 476 |
while(line){ |
| 477 |
line->ScanInput(mode, rect1, rect2); |
| 478 |
line = line->Next(); |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
/* |
| 483 |
* 架線柱入力チェック |
| 484 |
*/ |
| 485 |
void CScene::ScanInputPole( |
| 486 |
int mode, // モード |
| 487 |
VEC3 rect1, // 領域始点 |
| 488 |
VEC3 rect2 // 領域終点 |
| 489 |
){ |
| 490 |
if(mode==2) V3MinMax(rect1, rect2, &rect1, &rect2); |
| 491 |
CPole::ResetDetect(); |
| 492 |
CPole *pole = m_Pole; |
| 493 |
while(pole){ |
| 494 |
pole->ScanInput(mode, rect1, rect2); |
| 495 |
pole = pole->Next(); |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
/* |
| 500 |
* 駅舎入力チェック |
| 501 |
*/ |
| 502 |
void CScene::ScanInputStation( |
| 503 |
int mode, // モード |
| 504 |
VEC3 rect1, // 領域始点 |
| 505 |
VEC3 rect2, // 領域終点 |
| 506 |
bool init // 初期化フラグ |
| 507 |
){ |
| 508 |
if(init) CModelInst::ResetDetect(mode, rect1, rect2); |
| 509 |
CStation *station = m_Station; |
| 510 |
while(station){ |
| 511 |
station->ScanInput(mode, rect1, rect2); |
| 512 |
station = station->Next(); |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
/* |
| 517 |
* 施設入力チェック |
| 518 |
*/ |
| 519 |
void CScene::ScanInputStruct( |
| 520 |
int mode, // モード |
| 521 |
VEC3 rect1, // 領域始点 |
| 522 |
VEC3 rect2, // 領域終点 |
| 523 |
bool init // 初期化フラグ |
| 524 |
){ |
| 525 |
if(init) CModelInst::ResetDetect(mode, rect1, rect2); |
| 526 |
CStruct *strct = m_Struct; |
| 527 |
while(strct){ |
| 528 |
strct->ScanInput(mode, rect1, rect2); |
| 529 |
strct = strct->Next(); |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
/* |
| 534 |
* 架線検索 |
| 535 |
*/ |
| 536 |
CLine *CScene::FindLine( |
| 537 |
CPoleLink *from, // 接続元 |
| 538 |
CPoleLink *to // 接続先 |
| 539 |
){ |
| 540 |
CLine *line = m_Line; |
| 541 |
while(line){ |
| 542 |
CPoleLink p1 = line->GetLink(0); |
| 543 |
CPoleLink p2 = line->GetLink(1); |
| 544 |
if(from->m_Link==p1.m_Link && from->m_Track==p1.m_Track |
| 545 |
&& to->m_Link==p2.m_Link && to->m_Track==p2.m_Track |
| 546 |
|| from->m_Link==p2.m_Link && from->m_Track==p2.m_Track |
| 547 |
&& to->m_Link==p1.m_Link && to->m_Track==p1.m_Track) return line; |
| 548 |
line = line->Next(); |
| 549 |
} |
| 550 |
return NULL; |
| 551 |
} |
| 552 |
|
| 553 |
/* |
| 554 |
* 橋脚・架線設置 |
| 555 |
*/ |
| 556 |
void CScene::BuildLine( |
| 557 |
CPierPlugin *ipi, // 橋脚プラグイン |
| 558 |
CLinePlugin *lpi, // 架線プラグイン |
| 559 |
CPolePlugin *ppi // 架線柱プラグイン |
| 560 |
){ |
| 561 |
CRailConnector *con = m_RailConnector; |
| 562 |
while(con){ |
| 563 |
if(!con->Dump()) break; |
| 564 |
con = con->Next(); |
| 565 |
} |
| 566 |
m_RailWay->BuildLine(ipi, lpi, ppi); |
| 567 |
if(lpi && g_MultiTrackDummy==(ppi ? ppi->IsMultiTrack() : false)){ |
| 568 |
int i; |
| 569 |
for(i = 0; i<g_LastPole.size(); i++) |
| 570 |
if(g_LastPole[i].IsValid() && g_FinishPole[i].IsValid()) |
| 571 |
new CLine(g_LastPole[i], g_FinishPole[i], lpi); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
/* |
| 576 |
* 地形ピック |
| 577 |
*/ |
| 578 |
bool CScene::PickScene( |
| 579 |
VEC3 pos, // 座標 |
| 580 |
VEC3 dir, // 方向 |
| 581 |
VEC3 *hit, // ヒット座標格納先 |
| 582 |
VEC3 *tri, // 三角形頂点格納先 |
| 583 |
int inv // 裏面フラグ |
| 584 |
){ |
| 585 |
m_SurfacePlugin->SetSwitch(this); |
| 586 |
m_SurfacePlugin->SetPartsInst(this); |
| 587 |
m_SurfacePlugin->SetMoverState(this); |
| 588 |
return m_SurfacePlugin->PickSurface(pos, dir, hit, tri, inv); |
| 589 |
} |
| 590 |
|
| 591 |
/* |
| 592 |
* 地形ピック・高度制限 |
| 593 |
*/ |
| 594 |
bool CScene::ClipAlt( |
| 595 |
VEC3 *pos, // 座標 |
| 596 |
VEC3 *hit, // ヒット座標格納先 |
| 597 |
VEC3 *norm, // 法線格納先 |
| 598 |
int clip // クリップモード (1: 地下, 2: 高架) |
| 599 |
){ |
| 600 |
VEC3 opos = *pos, tmp, tri[3]; |
| 601 |
bool ret = false, ugpick = false; |
| 602 |
if(PickScene(opos+SURFACE_PICK_OFFSET*V3UP, -V3UP, &tmp, tri, 1)){ |
| 603 |
ret = true; |
| 604 |
if((clip&2) && opos.y+SURFACE_PICK_OFFSET>tmp.y |
| 605 |
&& ((clip&1) || pos->y>tmp.y)){ |
| 606 |
ugpick = true; |
| 607 |
pos->y = tmp.y; |
| 608 |
} |
| 609 |
if(hit) *hit = tmp; |
| 610 |
if(norm) *norm = CalcPlaneNormal(tri[0], tri[1], tri[2]); |
| 611 |
} |
| 612 |
if(PickScene(opos-SURFACE_PICK_OFFSET*V3UP, V3UP, &tmp, tri, 2)){ |
| 613 |
ret = true; |
| 614 |
if((clip&1) && opos.y-SURFACE_PICK_OFFSET<tmp.y |
| 615 |
&& ((clip&2) || pos->y<tmp.y) && (!ugpick || pos->y<tmp.y)) pos->y = tmp.y; |
| 616 |
if(hit) *hit = tmp; |
| 617 |
if(norm) *norm = CalcPlaneNormal(tri[0], tri[1], tri[2]); |
| 618 |
} |
| 619 |
return ret; |
| 620 |
} |
| 621 |
|
| 622 |
/* |
| 623 |
* 各種インスタンスをダンプ |
| 624 |
*/ |
| 625 |
void CScene::Dump(){ |
| 626 |
g_RailPluginList->ClearDump(); |
| 627 |
g_TiePluginList->ClearDump(); |
| 628 |
g_GirderPluginList->ClearDump(); |
| 629 |
g_PierPluginList->ClearDump(); |
| 630 |
g_LinePluginList->ClearDump(); |
| 631 |
CRailWay *way = m_RailWay; |
| 632 |
while(way){ |
| 633 |
way->Dump(); |
| 634 |
way = way->Next(); |
| 635 |
} |
| 636 |
CPier *pier = m_Pier; |
| 637 |
while(pier){ |
| 638 |
pier->Dump(); |
| 639 |
pier = pier->Next(); |
| 640 |
} |
| 641 |
CLine *line = m_Line; |
| 642 |
while(line){ |
| 643 |
line->Dump(); |
| 644 |
line = line->Next(); |
| 645 |
} |
| 646 |
g_RailPluginList->PrepareVertex(); |
| 647 |
g_TiePluginList->PrepareVertex(); |
| 648 |
g_GirderPluginList->PrepareVertex(); |
| 649 |
g_PierPluginList->PrepareVertex(); |
| 650 |
g_LinePluginList->PrepareVertex(); |
| 651 |
m_IsDumpReady = true; |
| 652 |
} |
| 653 |
|
| 654 |
/* |
| 655 |
* レンダリング |
| 656 |
*/ |
| 657 |
void CScene::RenderScene(){ |
| 658 |
TIMER_RAII("CScene::RenderScene()"); |
| 659 |
SetSeason(); |
| 660 |
SetGlobalAxis(); |
| 661 |
g_SystemSwitch[SYS_SW_SERIAL].SetValue(m_Serial); |
| 662 |
if(m_EnvPlugin){ |
| 663 |
m_EnvPlugin->Render(); |
| 664 |
}else{ |
| 665 |
devSetZRead(TRUE); |
| 666 |
devSetZWrite(TRUE); |
| 667 |
devSetLighting(TRUE); |
| 668 |
SetDirLight(VEC3(-1.0f, -2.0f, -1.0f), MAKE_CV(1.0f, 1.0f, 1.0f, 1.0f)); |
| 669 |
if(g_HidefCaptureFlag) g_HidefCapture.Begin(); |
| 670 |
else BeginScene(); |
| 671 |
} |
| 672 |
Render(); |
| 673 |
devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); |
| 674 |
devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); |
| 675 |
{ |
| 676 |
TIMER_RAII("profile RenderAll()"); |
| 677 |
g_RailPluginList->RenderAll(); |
| 678 |
g_TiePluginList->RenderAll(); |
| 679 |
g_GirderPluginList->RenderAll(); |
| 680 |
g_PierPluginList->RenderAll(); |
| 681 |
g_LinePluginList->RenderAll(); |
| 682 |
} |
| 683 |
devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); |
| 684 |
devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); |
| 685 |
devSetLighting(TRUE); |
| 686 |
{ |
| 687 |
TIMER_RAII("railway"); |
| 688 |
CRailWay *way = m_RailWay; |
| 689 |
while(way){ |
| 690 |
way->Render(); |
| 691 |
way = way->Next(); |
| 692 |
} |
| 693 |
} |
| 694 |
{ |
| 695 |
TIMER_RAII("pier"); |
| 696 |
CPier *pier = m_Pier; |
| 697 |
while(pier){ |
| 698 |
pier->Render(); |
| 699 |
pier = pier->Next(); |
| 700 |
} |
| 701 |
} |
| 702 |
{ |
| 703 |
TIMER_RAII("line"); |
| 704 |
CLine *line = m_Line; |
| 705 |
while(line){ |
| 706 |
line->Render(); |
| 707 |
line = line->Next(); |
| 708 |
} |
| 709 |
} |
| 710 |
{ |
| 711 |
TIMER_RAII("pole"); |
| 712 |
CPole *pole = m_Pole; |
| 713 |
while(pole){ |
| 714 |
pole->Render(); |
| 715 |
pole = pole->Next(); |
| 716 |
} |
| 717 |
} |
| 718 |
{ |
| 719 |
TIMER_RAII("station"); |
| 720 |
CStation *station = m_Station; |
| 721 |
while(station){ |
| 722 |
station->Render(); |
| 723 |
station = station->Next(); |
| 724 |
} |
| 725 |
} |
| 726 |
{ |
| 727 |
TIMER_RAII("struct"); |
| 728 |
CStruct *strct = m_Struct; |
| 729 |
while(strct){ |
| 730 |
strct->Render(); |
| 731 |
strct = strct->Next(); |
| 732 |
} |
| 733 |
} |
| 734 |
devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); |
| 735 |
devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); |
| 736 |
} |
| 737 |
|
| 738 |
/* |
| 739 |
* レンダリング仕上げ |
| 740 |
*/ |
| 741 |
void CScene::RenderAfter(){ |
| 742 |
if(m_EnvPlugin) m_EnvPlugin->RenderAfter(); |
| 743 |
} |
| 744 |
|
| 745 |
/* |
| 746 |
* シミュレート進行 |
| 747 |
*/ |
| 748 |
void CScene::SimulateScene(){ |
| 749 |
SetSeason(); |
| 750 |
SetGlobalAxis(); |
| 751 |
g_SystemSwitch[SYS_SW_SERIAL].SetValue(m_Serial); |
| 752 |
CStation *station = m_Station; |
| 753 |
while(station){ |
| 754 |
station->Simulate(); |
| 755 |
station = station->Next(); |
| 756 |
} |
| 757 |
CStruct *strct = m_Struct; |
| 758 |
while(strct){ |
| 759 |
strct->Simulate(); |
| 760 |
strct = strct->Next(); |
| 761 |
} |
| 762 |
Simulate(); |
| 763 |
} |
| 764 |
|
| 765 |
/* |
| 766 |
* アドレス復元 |
| 767 |
*/ |
| 768 |
void CScene::RestoreAddress(){ |
| 769 |
CRailConnector *con = m_RailConnector; |
| 770 |
while(con){ |
| 771 |
con->RestoreAddress(); |
| 772 |
con = con->Next(); |
| 773 |
} |
| 774 |
CRailWay *way = m_RailWay; |
| 775 |
while(way){ |
| 776 |
way->RestoreAddress(); |
| 777 |
way = way->Next(); |
| 778 |
} |
| 779 |
// CPier *pier = m_Pier; |
| 780 |
// while(pier){ |
| 781 |
// pier->RestoreAddress(); |
| 782 |
// pier = pier->Next(); |
| 783 |
// } |
| 784 |
CLine *line = m_Line; |
| 785 |
while(line){ |
| 786 |
line->RestoreAddress(); |
| 787 |
line = line->Next(); |
| 788 |
} |
| 789 |
CPole *pole = m_Pole; |
| 790 |
while(pole){ |
| 791 |
pole->RestoreAddress(); |
| 792 |
pole = pole->Next(); |
| 793 |
} |
| 794 |
CStation *station = m_Station; |
| 795 |
while(station){ |
| 796 |
station->RestoreAddress(); |
| 797 |
station = station->Next(); |
| 798 |
} |
| 799 |
// CStruct *strct = m_Struct; |
| 800 |
// while(strct){ |
| 801 |
// strct->RestoreAddress(); |
| 802 |
// strct = strct->Next(); |
| 803 |
// } |
| 804 |
} |
| 805 |
|
| 806 |
/* |
| 807 |
* 読込 |
| 808 |
*/ |
| 809 |
char *CScene::Read( |
| 810 |
char *str, // 対象文字列 |
| 811 |
CScene ***root // 格納先 |
| 812 |
){ |
| 813 |
char *eee, *tmp; |
| 814 |
if(!(str = BeginBlock(str, "Scene"))){ |
| 815 |
delete this; |
| 816 |
return NULL; |
| 817 |
} |
| 818 |
m_Scene = NULL; |
| 819 |
void *oldadr; |
| 820 |
if(!(str = AsgnPointer(eee = str, "Address", &oldadr))) throw CSynErr(eee); |
| 821 |
g_AddressMap[oldadr] = this; |
| 822 |
string pid; |
| 823 |
if(!(str = AsgnString(eee = str, "Name", &m_Name))) throw CSynErr(eee); |
| 824 |
m_Name = RestoreDoubleQuote(m_Name); |
| 825 |
if(!(str = AsgnString(eee = str, "SurfacePlugin", &pid))) throw CSynErr(eee); |
| 826 |
m_ModelPlugin = m_StructPlugin = |
| 827 |
m_SurfacePlugin = g_SurfacePluginList->FindPlugin(pid.c_str(), true); |
| 828 |
if(!(str = AsgnString(eee = str, "EnvPlugin", &pid))) throw CSynErr(eee); |
| 829 |
m_EnvPlugin = g_EnvPluginList->FindPlugin(pid.c_str(), true); |
| 830 |
if(!(str = ReadModelInst(eee = str, false))) throw CSynErr(eee); |
| 831 |
if(!(str = m_Camera.Read(eee = str))) throw CSynErr(eee); |
| 832 |
|
| 833 |
if(!(str = BeginBlock(str, "RailConnectorList"))) throw CSynErr(eee); |
| 834 |
CRailConnector::SetRoot(&m_RailConnector); |
| 835 |
while(true){ |
| 836 |
if(tmp = (new CRailConnector)->Read(str)) str = tmp; |
| 837 |
else break; |
| 838 |
} |
| 839 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 840 |
|
| 841 |
if(!(str = BeginBlock(str, "RailWayList"))) throw CSynErr(eee); |
| 842 |
CRailWay::SetRoot(&m_RailWay); |
| 843 |
while(true){ |
| 844 |
if(tmp = (new CRailWay)->Read(str)) str = tmp; |
| 845 |
else break; |
| 846 |
} |
| 847 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 848 |
|
| 849 |
if(!(str = BeginBlock(str, "PierList"))) throw CSynErr(eee); |
| 850 |
CPier::SetRoot(&m_Pier); |
| 851 |
while(true){ |
| 852 |
if(tmp = (new CPier)->Read(str)) str = tmp; |
| 853 |
else break; |
| 854 |
} |
| 855 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 856 |
|
| 857 |
if(!(str = BeginBlock(str, "LineList"))) throw CSynErr(eee); |
| 858 |
CLine::SetRoot(&m_Line); |
| 859 |
while(true){ |
| 860 |
if(tmp = (new CLine)->Read(str)) str = tmp; |
| 861 |
else break; |
| 862 |
} |
| 863 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 864 |
|
| 865 |
if(!(str = BeginBlock(str, "PoleList"))) throw CSynErr(eee); |
| 866 |
CPole::SetRoot(&m_Pole); |
| 867 |
while(true){ |
| 868 |
if(tmp = (new CPole)->Read(str)) str = tmp; |
| 869 |
else break; |
| 870 |
} |
| 871 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 872 |
|
| 873 |
if(!(str = BeginBlock(str, "StationList"))) throw CSynErr(eee); |
| 874 |
CStation::SetRoot(&m_Station); |
| 875 |
while(true){ |
| 876 |
if(tmp = (new CStation)->Read(str)) str = tmp; |
| 877 |
else break; |
| 878 |
} |
| 879 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 880 |
|
| 881 |
if(!(str = BeginBlock(str, "StructList"))) throw CSynErr(eee); |
| 882 |
CStruct::SetRoot(&m_Struct); |
| 883 |
while(true){ |
| 884 |
if(tmp = (new CStruct)->Read(str)) str = tmp; |
| 885 |
else break; |
| 886 |
} |
| 887 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 888 |
|
| 889 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 890 |
**root = this; |
| 891 |
*root = &m_Next; |
| 892 |
return str; |
| 893 |
} |
| 894 |
|
| 895 |
/* |
| 896 |
* 保存 |
| 897 |
*/ |
| 898 |
void CScene::Save( |
| 899 |
FILE *df // ファイル |
| 900 |
){ |
| 901 |
fprintf(df, "\tScene{\n"); |
| 902 |
fprintf(df, "\t\tAddress = %p;\n", this); |
| 903 |
fprintf(df, "\t\tName = \"%s\";\n", ExpandDoubleQuote(m_Name).c_str()); |
| 904 |
fprintf(df, "\t\tSurfacePlugin = \"%s\";\n", CheckPluginID(m_SurfacePlugin)); |
| 905 |
fprintf(df, "\t\tEnvPlugin = \"%s\";\n", CheckPluginID(m_EnvPlugin)); |
| 906 |
SaveModelInst(df, "\t\t", false); |
| 907 |
fprintf(df, "\n"); |
| 908 |
m_Camera.Save(df); |
| 909 |
fprintf(df, "\n"); |
| 910 |
|
| 911 |
fprintf(df, "\t\tRailConnectorList{\n"); |
| 912 |
CRailConnector *con = m_RailConnector; |
| 913 |
while(con){ |
| 914 |
con->Save(df); |
| 915 |
con = con->Next(); |
| 916 |
} |
| 917 |
fprintf(df, "\t\t}\n\n"); |
| 918 |
|
| 919 |
fprintf(df, "\t\tRailWayList{\n"); |
| 920 |
CRailWay *way = m_RailWay; |
| 921 |
while(way){ |
| 922 |
way->Save(df); |
| 923 |
way = way->Next(); |
| 924 |
} |
| 925 |
fprintf(df, "\t\t}\n\n"); |
| 926 |
|
| 927 |
fprintf(df, "\t\tPierList{\n"); |
| 928 |
CPier *pier = m_Pier; |
| 929 |
while(pier){ |
| 930 |
pier->Save(df); |
| 931 |
pier = pier->Next(); |
| 932 |
} |
| 933 |
fprintf(df, "\t\t}\n\n"); |
| 934 |
|
| 935 |
fprintf(df, "\t\tLineList{\n"); |
| 936 |
CLine *line = m_Line; |
| 937 |
while(line){ |
| 938 |
line->Save(df); |
| 939 |
line = line->Next(); |
| 940 |
} |
| 941 |
fprintf(df, "\t\t}\n\n"); |
| 942 |
|
| 943 |
fprintf(df, "\t\tPoleList{\n"); |
| 944 |
CPole *pole = m_Pole; |
| 945 |
while(pole){ |
| 946 |
pole->Save(df); |
| 947 |
pole = pole->Next(); |
| 948 |
} |
| 949 |
fprintf(df, "\t\t}\n\n"); |
| 950 |
|
| 951 |
fprintf(df, "\t\tStationList{\n"); |
| 952 |
CStation *station = m_Station; |
| 953 |
while(station){ |
| 954 |
station->Save(df); |
| 955 |
station = station->Next(); |
| 956 |
} |
| 957 |
fprintf(df, "\t\t}\n\n"); |
| 958 |
|
| 959 |
fprintf(df, "\t\tStructList{\n"); |
| 960 |
CStruct *strct = m_Struct; |
| 961 |
while(strct){ |
| 962 |
strct->Save(df); |
| 963 |
strct = strct->Next(); |
| 964 |
} |
| 965 |
fprintf(df, "\t\t}\n"); |
| 966 |
|
| 967 |
fprintf(df, "\t}\n"); |
| 968 |
} |