Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CStruct.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations) (download) (as text)
Sat Oct 26 14:53:53 2013 UTC (10 years, 6 months ago) by okadu
File MIME type: text/x-c++src
File size: 4941 byte(s)
[okadu] Version 2.15
橋脚・架線柱手動設置機能
車輌プラグイン以外でクランク等使用可能に
エンジン模型プラグイン追加

1 #include "stdafx.h"
2 #include "CListView.h"
3 #include "CSimpleDialog.h"
4 #include "CScene.h"
5 #include "CStructPlugin.h"
6 #include "CSkinPlugin.h"
7 #include "CStructEditMode.h"
8
9 // 外部グローバル
10 extern MAT8 *g_AltMaterial;
11 extern MAT8 g_MatSelect[];
12
13 // static メンバ
14 CStruct **CStruct::ms_Root = NULL;
15
16 /*
17 * コンストラクタ (読込用)
18 */
19 CStruct::CStruct(){
20 m_StructPlugin = NULL;
21 FixPosture(V3ZERO, V3DIR, V3UP);
22 m_Scene = g_Scene;
23 m_Next = NULL;
24 }
25
26 /*
27 * コンストラクタ (地形用)
28 */
29 CStruct::CStruct(
30 CStructPlugin *bpi // 施設プラグイン
31 ):
32 CModelInst(bpi) // 基本クラス
33 {
34 m_StructPlugin = bpi;
35 FixPosture(V3ZERO, V3DIR, V3UP);
36 m_Scene = NULL;
37 m_Next = NULL;
38 }
39
40 /*
41 * コンストラクタ
42 */
43 CStruct::CStruct(
44 CStructPlugin *bpi, // 施設プラグイン
45 VEC3 pos, // 位置
46 VEC3 dir, // dir
47 VEC3 up, // up
48 bool link // リスト連結フラグ
49 ):
50 CModelInst(bpi) // 基本クラス
51 {
52 m_StructPlugin = bpi;
53 FixPosture(pos, dir, up);
54 bpi->SetSwitch(this);
55 bpi->SetPartsInst(this);
56 bpi->SetMoverState(this);
57 bpi->SetPosture();
58 m_Scene = g_Scene;
59 if(link){
60 m_Next = *ms_Root;
61 *ms_Root = this;
62 }else{
63 m_Next = NULL;
64 }
65 }
66
67 /*
68 * デストラクタ
69 */
70 CStruct::~CStruct(){
71 DELETE_V(m_Next);
72 }
73
74 /*
75 * プラグイン選択モード取得
76 */
77 bool CStruct::IsSelectVisible(){
78 return g_StructEditMode->IsModeActive();
79 }
80
81 /*
82 * プラグイン選択モード取得
83 */
84 CPartsInst *CStruct::FindParts(CNamedObject *nobj){
85 list<CFreeObjectContainer>::iterator n_itr = m_StructPlugin->m_FreeObject.begin();
86 list<CPartsInst>::iterator p_itr = m_PartsInst.begin();
87 while(true){
88 if(n_itr==m_StructPlugin->m_FreeObject.end()) break;
89 if(p_itr==m_PartsInst.end()) break;
90 int i;
91 for(i = 0; i<n_itr->GetNamedObjectNum(); ++i){
92 if(n_itr->GetNamedObject(i)==nobj) return &*p_itr;
93 ++p_itr;
94 }
95 ++n_itr;
96 }
97 return NULL;
98 }
99
100 /*
101 * 撤去
102 */
103 void CStruct::Remove(){
104 m_Scene->DeleteStruct(this);
105 }
106
107 /*
108 * リストから削除
109 */
110 void CStruct::Delete(){
111 m_Next = NULL;
112 delete this;
113 }
114
115 /*
116 * 速度情報表示
117 */
118 void CStruct::PrintInfo(){
119 }
120
121 /*
122 * 操作
123 */
124 CModelInst *CStruct::Control(){
125 if(CEditBox::IsActive()) return this;
126 if(GetKey(DIK_DELETE)==S_PUSH){
127 class CStructDeleter: public CMenuCommand{
128 private:
129 CStruct *m_Struct; // 施設
130 public:
131 CStructDeleter(CStruct *s){ m_Struct = s; }
132 void Exec(){
133 void PushUndoStack();
134 PushUndoStack();
135 m_Struct->Remove();
136 }
137 };
138 CYesNoDialog *dlg = new CYesNoDialog(
139 lang(DeleteStructCfmMessage), lang(Confirmation), false);
140 dlg->SetYesCommand(new CStructDeleter(this));
141 EnqueueCommonDialog(dlg);
142 }
143 return this;
144 }
145
146 /*
147 * 入力チェック
148 */
149 void CStruct::ScanInput(
150 int mode, // モード (0: link)
151 VEC3 &rect1, // 領域始点
152 VEC3 &rect2 // 領域終点
153 ){
154 ms_CurrentInst = this;
155 ms_DetectTemp = 0;
156 SetSwitchStruct();
157 m_StructPlugin->SetSwitch(this);
158 m_StructPlugin->SetPartsInst(this);
159 m_StructPlugin->ScanInput(this);
160 switch(mode){
161 case 2:
162 if(ms_DetectTemp) m_Selected |= 1; else m_Selected &= 2;
163 break;
164 case 3:
165 if(CheckCtrl()){
166 m_Selected &= ~m_Selected<<1;
167 }else{
168 if(CheckShift()) m_Selected |= m_Selected<<1;
169 else m_Selected = m_Selected<<1;
170 }
171 m_Selected &= 2;
172 break;
173 case 4:
174 m_Selected &= 2;
175 break;
176 case 5:
177 m_Selected = 0;
178 break;
179 case 6:
180 m_Selected = m_Selected<<1;
181 m_Selected &= 2;
182 break;
183 }
184 }
185
186 /*
187 * レンダリング
188 */
189 void CStruct::Render(){
190 if(m_Selected && IsSelectVisible()) g_AltMaterial = &g_MatSelect[m_Selected];
191 SetSwitchStruct();
192 m_StructPlugin->SetSwitch(this);
193 m_StructPlugin->SetPartsInst(this);
194 m_StructPlugin->Render(this);
195 g_AltMaterial = NULL;
196 }
197
198 /*
199 * シミュレート進行
200 */
201 void CStruct::SimulateModelInst(){
202 SetSwitchStruct();
203 m_StructPlugin->SetSwitch(this);
204 m_StructPlugin->SetPartsInst(this);
205 m_StructPlugin->Simulate(this);
206 SimulateStruct();
207 }
208
209 /*
210 * 読込
211 */
212 char *CStruct::Read(
213 char *str // 対象文字列
214 ){
215 char *eee;
216 if(!(str = BeginBlock(str, "Struct"))){
217 delete this;
218 return NULL;
219 }
220 void *oldadr;
221 if(!(str = AsgnPointer(eee = str, "Address", &oldadr))) throw CSynErr(eee);
222 g_AddressMap[oldadr] = this;
223 string pid;
224 if(!(str = AsgnString(eee = str, "StructPlugin", &pid))) throw CSynErr(eee);
225 m_ModelPlugin = m_StructPlugin = g_StructPluginList->FindPlugin(pid.c_str(), true);
226 if(!(str = ReadModelInst(eee = str, true))) throw CSynErr(eee);
227 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
228 *ms_Root = this;
229 ms_Root = &m_Next;
230 return str;
231 }
232
233 /*
234 * 保存
235 */
236 void CStruct::Save(
237 FILE *df // ファイル
238 ){
239 fprintf(df, "\t\t\tStruct{\n");
240 fprintf(df, "\t\t\t\tAddress = %p;\n", this);
241 fprintf(df, "\t\t\t\tStructPlugin = \"%s\";\n", CheckPluginID(m_StructPlugin));
242 SaveModelInst(df, "\t\t\t\t", true);
243 fprintf(df, "\t\t\t}\n");
244 }

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