Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CModelPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Sun Aug 15 01:53:13 2010 UTC (13 years, 9 months ago) by okadu
File MIME type: text/x-c++src
File size: 8942 byte(s)


1 #include "stdafx.h"
2 #include "CListView.h"
3 #include "CModelInst.h"
4 #include "CTrainGroup.h"
5 #include "CEnvPlugin.h"
6 #include "CConfigMode.h"
7
8 // 外部グローバル
9 extern CHeadlight g_TempHeadlight;
10 extern CParticle g_TempParticle;
11 extern CSoundEffector g_TempSoundEffector;
12
13 /*
14 * コンストラクタ
15 */
16 CModelPlugin::CModelPlugin(
17 char *id // プラグイン ID
18 ):
19 CPlugin(id) // 基本クラス
20 {
21 m_SelectSwitchID = 0;
22 m_PartsNum = 0;
23 }
24
25 /*
26 * スイッチ読込
27 */
28 char *CModelPlugin::ReadModelSwitch(
29 char *str // 対象文字列
30 ){
31 char *tmp;
32 while(true){
33 CModelSwitch msw(m_ModelSwitch.size());
34 CTextureAnimation anim;
35 if(tmp = msw.Read(str, this)){
36 str = tmp;
37 m_ModelSwitch.push_back(msw);
38 }else if(tmp = anim.Read(str, this)){
39 str = tmp;
40 m_Animation.push_back(anim);
41 }else{
42 break;
43 }
44 }
45 if(m_ModelSwitch.size()){
46 m_TempSwitch.resize(m_ModelSwitch.size());
47 int i;
48 for(i = 0; i<m_TempSwitch.size(); i++) m_TempSwitch[i] = 0;
49 }
50 return str;
51 }
52
53 /*
54 * エフェクト読込
55 */
56 char *CModelPlugin::ReadEffect(
57 char *str // 対象文字列
58 ){
59 g_TempHeadlight = CHeadlight();
60 g_TempParticle = CParticle();
61 char *tmp;
62 if(tmp = m_Effector.Read(str, this, 1)) str = tmp;
63 return str;
64 }
65
66 /*
67 * データ読み込み
68 */
69 void CModelPlugin::LoadData(){
70 ChDir();
71 ITextureAnimation ia = m_Animation.begin();
72 for(; ia!=m_Animation.end(); ia++) ia->LoadData();
73 m_Effector.LoadData(this);
74 }
75
76 /*
77 * スイッチ検索
78 */
79 CModelSwitch *CModelPlugin::FindModelSwitch(
80 const string &name // スイッチ名
81 ){
82 CModelSwitch *ret;
83 IModelSwitch is = m_ModelSwitch.begin();
84 for(; is!=m_ModelSwitch.end(); is++) if(ret = is->Check(name)) return ret;
85 return NULL;
86 }
87
88 /*
89 * スイッチ取得
90 */
91 CModelSwitch *CModelPlugin::GetModelSwitch(
92 int index // 番号
93 ){
94 int i = 0;
95 IModelSwitch is = m_ModelSwitch.begin();
96 for(; is!=m_ModelSwitch.end(); is++) if(i++==index) return &*is;
97 return NULL;
98 }
99
100 /*
101 * アニメーション検索
102 */
103 CTextureAnimation *CModelPlugin::FindAnimation(
104 const string &name // アニメーション名
105 ){
106 CTextureAnimation *ret;
107 ITextureAnimation ia = m_Animation.begin();
108 for(; ia!=m_Animation.end(); ia++) if(ret = ia->Check(name)) return ret;
109 return NULL;
110 }
111
112 /*
113 * スイッチリスト作成
114 */
115 void CModelPlugin::ListSwitch(
116 CListView *slv, // スイッチリストビュー
117 CListView *olv, // オプションリストビュー
118 CModelInst *minst // リンクインスタンス
119 ){
120 slv->DeleteAllItems();
121 olv->DeleteAllItems();
122 m_LinkInst = minst;
123 if(!m_ModelSwitch.size()) return;
124 IModelSwitch im = m_ModelSwitch.begin();
125 for(; im!=m_ModelSwitch.end(); im++){
126 CListElement *sle = slv->InsertItem(-1, (char *)im->m_SwitchName.c_str());
127 sle->SetString(1, im->GetCurrentOptionName());
128 sle->SetData((DWORD)&*im);
129 im->SetListElement(sle);
130 }
131 slv->SetSelectionMark(m_SelectSwitchID, 0);
132 slv->EnsureVisible(m_SelectSwitchID);
133 m_SelectSwitch = NULL;
134 }
135
136 /*
137 * スイッチ編集
138 */
139 void CModelPlugin::EditSwitch(
140 CListView *slv, // スイッチリストビュー
141 CListView *olv // オプションリストビュー
142 ){
143 if(!m_ModelSwitch.size()) return;
144 if(m_LinkInst){
145 SetSwitch(m_LinkInst);
146 CNamedObjectAfterRenderer::SetCurrentInst(NULL);
147 }
148 CListElement *sle = slv->GetFocusItem();
149 if(sle && sle->IsSelected()){
150 m_SelectSwitchID = slv->GetSelectionMark();
151 CModelSwitch *sw = (CModelSwitch *)sle->GetData();
152 if(sw!=m_SelectSwitch){
153 m_SelectSwitch = sw;
154 sw->ListEntry(olv);
155 }
156 }else if(m_SelectSwitch){
157 m_SelectSwitch = NULL;
158 olv->DeleteAllItems();
159 }
160 if(m_SelectSwitch){
161 if(m_LinkInst){
162 int *pval = &m_LinkInst->m_SwitchOption[m_SelectSwitch->m_ID], before = *pval;
163 int switch_id = m_SelectSwitch->m_ID<m_LinkInst->m_StaticSwitchID.size()
164 ? m_LinkInst->m_StaticSwitchID[m_SelectSwitch->m_ID] : -1;
165 m_SelectSwitch->EditSwitch(olv, pval, switch_id);
166 if(m_SelectSwitch->IsGroupCommon()){
167 CTrainGroup *group = m_LinkInst->GetTrainGroup();
168 if(group && before!=*pval) group->SetGroupCommonSwitch(m_SelectSwitch, *pval);
169 }
170 }else{
171 m_SelectSwitch->EditSwitch(olv, NULL, -1);
172 }
173 }
174 }
175
176 /*
177 * スイッチ設定セット
178 */
179 bool CModelPlugin::SetSwitch(
180 vector<int> &sopt // スイッチ設定値
181 ){
182 LoadAndGet();
183 IModelSwitch im = m_ModelSwitch.begin();
184 int i = 0;
185 for(; im!=m_ModelSwitch.end() && i<sopt.size(); im++, i++) im->m_Value = sopt[i];
186 for(; im!=m_ModelSwitch.end(); im++) im->m_Value = 0;
187 return sopt.size()==m_ModelSwitch.size();
188 }
189
190 /*
191 * スイッチ設定セット
192 */
193 void CModelPlugin::SetSwitch(
194 CModelInst *minst // インスタンス
195 ){
196 LoadAndGet();
197 CNamedObjectAfterRenderer::SetCurrentInst(minst);
198 CNamedObjectAfterRenderer::SetCurrentPlugin(this);
199 IModelSwitch im = m_ModelSwitch.begin();
200 if(minst->m_SwitchOption.size()!=m_ModelSwitch.size()) minst->AttachPlugin(this);
201 vector<int>::iterator ptr = minst->m_SwitchOption.begin();
202 for(; im!=m_ModelSwitch.end(); im++, ptr++) im->m_Value = *ptr;
203 }
204
205 /*
206 * スイッチ設定コピー
207 */
208 void CModelPlugin::CopySwitch(
209 vector<int> &sopt // スイッチ設定値
210 ){
211 sopt.resize(m_ModelSwitch.size());
212 vector<int>::iterator ptr = sopt.begin();
213 IModelSwitch im = m_ModelSwitch.begin();
214 for(; im!=m_ModelSwitch.end(); im++, ptr++) *ptr = im->m_Value;
215 }
216
217 /*
218 * 編成共通スイッチのチェック
219 */
220 void CModelPlugin::CheckGroupCommonSwitch(
221 CModelInst *minst, // インスタンス (変更側)
222 CModelSwitch *sw, // 対象スイッチ (固定側)
223 int val // 対象値 (固定側)
224 ){
225 vector<int>::iterator ptr = minst->m_SwitchOption.begin();
226 IModelSwitch im = m_ModelSwitch.begin();
227 for(; im!=m_ModelSwitch.end(); im++, ptr++) if(im->CheckGroupCommon(sw)) *ptr = val;
228 }
229
230 /*
231 * 編成共通スイッチのチェック
232 */
233 void CModelPlugin::CheckGroupCommonSwitchAll(
234 CModelInst *minst1, // インスタンス (変更側)
235 CModelInst *minst2 // インスタンス (固定側)
236 ){
237 CModelPlugin *mpi = minst2->GetModelPlugin();
238 vector<int>::iterator ptr = minst2->m_SwitchOption.begin();
239 IModelSwitch im = mpi->m_ModelSwitch.begin();
240 for(; im!=mpi->m_ModelSwitch.end(); im++, ptr++)
241 if(im->IsGroupCommon()) CheckGroupCommonSwitch(minst1, &*im, *ptr);
242 }
243
244 /*
245 * パーツインスタンスセット
246 */
247 void CModelPlugin::SetPartsInst(
248 CModelInst *minst // インスタンス
249 ){
250 if(minst){
251 if(minst->m_PartsInst.size()!=GetPartsNum()) minst->AttachPlugin(this);
252 CNamedObject::SetPartsInst(&minst->m_PartsInst);
253 }else{
254 CNamedObject::SetPartsInst(NULL);
255 }
256 }
257
258 /*
259 * アニメーション状態セット
260 */
261 void CModelPlugin::SetAnimation(
262 CModelInst *minst // インスタンス
263 ){
264 ITextureAnimation ia = m_Animation.begin();
265 if(minst){
266 if(minst->m_AnimationState.size()!=m_Animation.size()) minst->AttachPlugin(this);
267 ITexAnimState itas = minst->m_AnimationState.begin();
268 for(; ia!=m_Animation.end(); ia++, itas++) ia->SetState(&*itas);;
269 }else{
270 for(; ia!=m_Animation.end(); ia++) ia->SetState(NULL);
271 }
272 }
273
274 /*
275 * ムーバー状態セット
276 */
277 void CModelPlugin::SetMoverState(
278 CModelInst *minst // インスタンス
279 ){
280 IPMoverState ipms = m_MoverState.begin();
281 if(minst){
282 if(minst->m_MoverState.size()!=m_MoverState.size()) minst->AttachPlugin(this);
283 IMoverState ims = minst->m_MoverState.begin();
284 for(; ipms!=m_MoverState.end(); ipms++, ims++) *ipms = &*ims;
285 }else{
286 for(; ipms!=m_MoverState.end(); ipms++) *ipms = NULL;
287 }
288 }
289
290 /*
291 * サウンドのロード
292 */
293 void CModelPlugin::LoadSoundWave(
294 CModelInst *minst // インスタンス
295 ){
296 ChDir();
297 if(minst){
298 minst->m_SoundState.clear();
299 minst->m_SoundState.insert(minst->m_SoundState.begin(), GetSoundNum(), CSoundState());
300 ISoundEffector is = m_SoundEffector.begin();
301 ISoundState iss = minst->m_SoundState.begin();
302 for(; is!=m_SoundEffector.end(); is++, iss++) is->LoadData(&*iss);
303 }
304 }
305
306 /*
307 * エフェクト描画
308 */
309 void CModelPlugin::SimulateEffect(
310 CModelInst *minst // インスタンス
311 ){
312 if(minst){
313 if(minst->IsWarping()) return;
314 if(g_PreSimulationFlag){
315 if(minst->m_ParticleState.size()!=m_Particle.size()) minst->AttachPlugin(this);
316 IParticle ip = m_Particle.begin();
317 IParticleState ips = minst->m_ParticleState.begin();
318 for(; ip!=m_Particle.end(); ip++, ips++) ip->Link(&*ips);
319 }else{
320 if(minst->m_SoundState.size()!=m_SoundEffector.size()) minst->AttachPlugin(this);
321 ISoundEffector is = m_SoundEffector.begin();
322 ISoundState iss = minst->m_SoundState.begin();
323 for(; is!=m_SoundEffector.end(); is++, iss++) is->Link(&*iss);
324 }
325 }
326 m_Effector.Apply(minst ? minst->GetScene() : NULL);
327 if(minst){
328 if(g_PreSimulationFlag){
329 IParticleState ips = minst->m_ParticleState.begin();
330 for(; ips!=minst->m_ParticleState.end(); ips++) ips->Confirm();
331 }else{
332 ISoundEffector is = m_SoundEffector.begin();
333 ISoundState iss = minst->m_SoundState.begin();
334 for(; is!=m_SoundEffector.end(); is++, iss++)
335 iss->Confirm(&*is, IsSoundEnabled());
336 }
337 }
338 }

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