| 1 |
#include "stdafx.h" |
| 2 |
#include "CRailPlugin.h" |
| 3 |
#include "CLinePlugin.h" |
| 4 |
#include "CPolePlugin.h" |
| 5 |
#include "CLineSelectMode.h" |
| 6 |
#include "CRailBuildMode.h" |
| 7 |
|
| 8 |
// 外部定数 |
| 9 |
extern const float RAIL_PREV_LEN; |
| 10 |
|
| 11 |
/* |
| 12 |
* [static] |
| 13 |
* プレビュー |
| 14 |
*/ |
| 15 |
void CLinePlugin::RenderPreview(){ |
| 16 |
if(!ms_PreviewState || (!g_Line && !g_Pole)) return; |
| 17 |
VEC3 op1(0.0f, 0.0f, -RAIL_PREV_LEN), op2(0.0f, 0.0f, RAIL_PREV_LEN); |
| 18 |
VEC3 r1 = V3RIGHT, u1 = V3UP, d1 = V3DIR; |
| 19 |
VEC3 r2 = V3RIGHT, u2 = V3UP, d2 = V3DIR; |
| 20 |
if(g_Line){ |
| 21 |
bool multi = CRailwayMode::IsMultiTrack(); |
| 22 |
int tnum = multi ? CRailwayMode::GetTrackNum() : 1; |
| 23 |
float tint = multi ? CRailwayMode::GetTrackInterval() : 0.0f; |
| 24 |
if(g_Pole && g_Pole->IsMultiTrack()){ |
| 25 |
if(tnum>g_Pole->GetTrackNum()) tnum = g_Pole->GetTrackNum(); |
| 26 |
tint = g_Pole->GetTrackInterval(); |
| 27 |
} |
| 28 |
int j; |
| 29 |
for(j = 0; j<=tnum; j++){ |
| 30 |
float x = (j-(tnum-1)*0.5f)*tint; |
| 31 |
if(j==tnum){ |
| 32 |
if(g_Pole && !g_Pole->IsMultiTrack()) break; |
| 33 |
x = 0.0f; |
| 34 |
} |
| 35 |
g_Line->ResetMapTemp(); |
| 36 |
bool p_flag = g_Pole && (g_Pole->IsMultiTrack() ? j==tnum : j<tnum); |
| 37 |
VEC3 p1, ip1, p2, ip2; |
| 38 |
float tmp = -RAIL_PREV_LEN; |
| 39 |
do{ |
| 40 |
ip1 = p1 = VEC3(x, 0.0f, tmp)+g_Line->m_TrolleyAlt*u1; |
| 41 |
ip2 = p2 = p1+g_Line->m_MaxInterval*V3DIR; |
| 42 |
devSetLighting(TRUE); |
| 43 |
if(p_flag) g_Pole->Preview(p1+g_Line->m_Height*u1); |
| 44 |
devResetMatrix(); |
| 45 |
if(j<tnum) g_Line->Dump(p1, r1, u1, ip1, r1, u1, |
| 46 |
p2, r2, u2, ip2, r2, u2, g_Line->m_MaxInterval, 7); |
| 47 |
p1 = ip1; p2 = ip2; |
| 48 |
g_Line->Render(p1, r1, u1, d1, ip1, r1, u1, |
| 49 |
p2, r2, u2, d2, ip2, r2, u2, 3, g_Line->m_MaxInterval); |
| 50 |
tmp += g_Line->m_MaxInterval; |
| 51 |
} while(tmp<RAIL_PREV_LEN); |
| 52 |
if(p_flag) g_Pole->Preview(tmp*d1+(g_Line->m_TrolleyAlt+g_Line->m_Height)*u1); |
| 53 |
} |
| 54 |
}else if(g_Pole){ |
| 55 |
g_Pole->Preview(V3ZERO); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
/* |
| 60 |
* ロード |
| 61 |
*/ |
| 62 |
bool CLinePlugin::Load(){ |
| 63 |
char *str = m_Script, *tmp, *eee; |
| 64 |
if(!ChDir() || !m_Script) return false; |
| 65 |
try{ |
| 66 |
if(!(str = BeginBlock(eee = str, "LineInfo"))) throw CSynErr(eee); |
| 67 |
if(!(str = AsgnFloat(eee = str, "TrolleyAlt", &m_TrolleyAlt))) throw CSynErr(eee); |
| 68 |
if(!(str = AsgnFloat(eee = str, "Height", &m_Height))) throw CSynErr(eee); |
| 69 |
if(!(str = AsgnFloat(eee = str, "MaxInterval", &m_MaxInterval))) throw CSynErr(eee); |
| 70 |
if(tmp = AsgnFloat(str, "Offset", &m_Offset)) str = tmp; |
| 71 |
else m_Offset = 0.0f; |
| 72 |
if(!(str = AsgnFloat(eee = str, "MaxDeflection", &m_MaxDeflection))) throw CSynErr(eee); |
| 73 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 74 |
|
| 75 |
if(!(str = ReadProfile(eee = str))) throw CSynErr(eee); |
| 76 |
|
| 77 |
if(*(eee = str)) throw CSynErr(eee); |
| 78 |
} |
| 79 |
catch(CSynErr err){ |
| 80 |
HandleError(&err); |
| 81 |
return false; |
| 82 |
} |
| 83 |
LoadData(); |
| 84 |
DELETE_A(m_Buffer); |
| 85 |
return true; |
| 86 |
} |
| 87 |
|
| 88 |
/* |
| 89 |
* プレビュー設定 |
| 90 |
*/ |
| 91 |
void CLinePlugin::SetPreview(){ |
| 92 |
ms_PreviewState = true; |
| 93 |
g_Line = this; |
| 94 |
string desc = g_Line->GetBasicInfo(); |
| 95 |
desc += "\n"+g_Line->GetDescription(); |
| 96 |
g_LineSelectMode->SetProperty((char *)desc.c_str()); |
| 97 |
} |
| 98 |
|
| 99 |
/* |
| 100 |
* 架線柱距離加算 |
| 101 |
*/ |
| 102 |
void CLinePlugin::AddPolePos( |
| 103 |
float len // 距離 |
| 104 |
){ |
| 105 |
m_PolePos -= len; |
| 106 |
while(m_PolePos<=0.0f) m_PolePos += m_MaxInterval; |
| 107 |
} |