Scene.cpp 21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
// $Id: R_RavenScene.cpp 2732 2012-06-26 13:38:17Z stienen $

#include <ITASimulationScheduler/Raven/R_RavenScene.h>

#include <cassert>
#include <sstream>

#include <ITAConfigUtils.h>
#include <ITAException.h>
#include <ITAFileSystemUtils.h>
#include <ITAStringUtils.h>

13
namespace ITASimulationScheduler
14
{
15
	namespace RAVEN
16
	{
17

18
		// --= Raven States =--
19

Pascal Palenda's avatar
Pascal Palenda committed
20
		int CReceiverState::Compare(const CReceiverState& oState) const
21
22
23
24
25
26
27
28
29
30
31
32
33
		{
			int iDifferenceFlags = 0;
			if (vPos != oState.vPos)
				iDifferenceFlags += POS;
			if ((vView != oState.vView) || (vUp != oState.vUp))
				iDifferenceFlags += ORIENT;
			if (sHRIRFilename != oState.sHRIRFilename)
				iDifferenceFlags += HRIR;
			if (bInsideRoom != oState.bInsideRoom)
				iDifferenceFlags += INROOM;

			return iDifferenceFlags;
		}
34

Pascal Palenda's avatar
Pascal Palenda committed
35
		int CSourceState::Compare(const CSourceState& oState) const
36
37
38
39
40
41
42
43
44
45
46
47
48
		{
			int iDifferenceFlags = 0;
			if (vPos != oState.vPos)
				iDifferenceFlags += POS;
			if ((vView != oState.vView) || (vUp != oState.vUp))
				iDifferenceFlags += ORIENT;
			if (sDirectivityFilename != oState.sDirectivityFilename)
				iDifferenceFlags += DIR;
			if (bInsideRoom != oState.bInsideRoom)
				iDifferenceFlags += INROOM;

			return iDifferenceFlags;
		}
49

Pascal Palenda's avatar
Pascal Palenda committed
50
		int CPortalState::Compare(const CPortalState& oState) const
51
52
53
54
55
56
		{
			int iDifferenceFlags = 0;
			if (vPos != oState.vPos)
				iDifferenceFlags += POS;
			if (dState != oState.dState)
				iDifferenceFlags += STATE;
57

58
59
			return iDifferenceFlags;
		}
60

Pascal Palenda's avatar
Pascal Palenda committed
61
		bool CSceneDiff::EntitiesChanged() const
62
63
64
65
66
67
68
69
70
71
		{
			if (viNewReceivers.size() > 0) return true;
			if (viDelReceivers.size() > 0) return true;
			if (viNewSources.size() > 0) return true;
			if (viDelSources.size() > 0) return true;
			if (viNewPortals.size() > 0) return true;
			if (viDelPortals.size() > 0) return true;

			return false;
		}
72
73


74
		// --= Raven Scene = --
75

Pascal Palenda's avatar
Pascal Palenda committed
76
		CScene::CScene()
77
78
79
		{
			assert(true);
		}
80

Pascal Palenda's avatar
Pascal Palenda committed
81
		CScene::~CScene()
82
83
84
		{
			Reset();
		}
85

Pascal Palenda's avatar
Pascal Palenda committed
86
		void CScene::Reset()
87
88
89
90
91
		{
			m_mSources.clear();
			m_mReceivers.clear();
			m_mPortals.clear();
		}
92

Pascal Palenda's avatar
Pascal Palenda committed
93
		void CScene::AddSource(int iSoundSourceID)
94
95
96
		{
			// Sicherstellen das die ID noch nicht vergeben ist
			assert(m_mSources.find(iSoundSourceID) == m_mSources.end());
97

Pascal Palenda's avatar
Pascal Palenda committed
98
			CSourceState& oState = m_mSources[iSoundSourceID];
99
		}
100

Pascal Palenda's avatar
Pascal Palenda committed
101
		void CScene::RemoveSource(int iSoundSourceID)
102
103
104
105
106
107
		{
			SourceMapIt it = m_mSources.find(iSoundSourceID);
			// Sicherstellen das die ID vorhanden ist
			assert(it != m_mSources.end());
			m_mSources.erase(it);
		}
108

Pascal Palenda's avatar
Pascal Palenda committed
109
		const CSourceState& CScene::GetSourceState(int iID) const
110
111
112
113
114
115
		{
			SourceMapCit cit = m_mSources.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(cit != m_mSources.end());
			return cit->second;
		}
116

Pascal Palenda's avatar
Pascal Palenda committed
117
		void CScene::SetSourceState(int iID, const CSourceState& oState)
118
119
120
121
122
123
		{
			SourceMapIt it = m_mSources.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(it != m_mSources.end());
			it->second = oState;
		}
124
125


Pascal Palenda's avatar
Pascal Palenda committed
126
		void CScene::AddReceiver(int iID)
127
128
129
		{
			// Sicherstellen das die ID noch nicht vergeben ist
			assert(m_mReceivers.find(iID) == m_mReceivers.end());
130

Pascal Palenda's avatar
Pascal Palenda committed
131
			CReceiverState& oState = m_mReceivers[iID];
132
		}
133

Pascal Palenda's avatar
Pascal Palenda committed
134
		void CScene::RemoveReceiver(int iID)
135
136
137
138
139
140
		{
			ReceiverMapIt it = m_mReceivers.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(it != m_mReceivers.end());
			m_mReceivers.erase(it);
		}
141

Pascal Palenda's avatar
Pascal Palenda committed
142
		const CReceiverState& CScene::GetReceiverState(int iID) const
143
144
145
146
147
148
		{
			ReceiverMapCit cit = m_mReceivers.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(cit != m_mReceivers.end());
			return cit->second;
		}
149

Pascal Palenda's avatar
Pascal Palenda committed
150
		void CScene::SetReceiverState(int iID, const CReceiverState& oState)
151
152
153
154
155
156
		{
			ReceiverMapIt it = m_mReceivers.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(it != m_mReceivers.end());
			it->second = oState;
		}
157

Pascal Palenda's avatar
Pascal Palenda committed
158
		void CScene::AddPortal(int iID)
159
160
161
		{
			// Sicherstellen das die ID noch nicht vergeben ist
			assert(m_mPortals.find(iID) == m_mPortals.end());
162

Pascal Palenda's avatar
Pascal Palenda committed
163
			CPortalState& oState = m_mPortals[iID];
164
		}
165

Pascal Palenda's avatar
Pascal Palenda committed
166
		void CScene::RemovePortal(int iID)
167
168
169
170
171
172
		{
			PortalMapIt it = m_mPortals.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(it != m_mPortals.end());
			m_mPortals.erase(it);
		}
173

Pascal Palenda's avatar
Pascal Palenda committed
174
		const CPortalState& CScene::GetPortalState(int iID) const
175
		{
176
177
178
179
			PortalMapCit cit = m_mPortals.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(cit != m_mPortals.end());
			return cit->second;
180
		}
181

Pascal Palenda's avatar
Pascal Palenda committed
182
		void CScene::SetPortalState(int iID, const CPortalState& oState)
183
		{
184
185
186
187
			PortalMapIt it = m_mPortals.find(iID);
			// Sicherstellen das die ID vorhanden ist
			assert(it != m_mPortals.end());
			it->second = oState;
188
		}
189

Pascal Palenda's avatar
Pascal Palenda committed
190
		void CScene::Diff(const CScene& oScene, CSceneDiff& oDiff) const
191
192
193
194
195
		{
			Diff(m_mReceivers, oScene.m_mReceivers, oDiff.viNewReceivers, oDiff.viModReceivers, oDiff.viDelReceivers);
			Diff(m_mSources, oScene.m_mSources, oDiff.viNewSources, oDiff.viModSources, oDiff.viDelSources);
			Diff(m_mPortals, oScene.m_mPortals, oDiff.viNewPortals, oDiff.viModPortals, oDiff.viDelPortals);
		}
196

Pascal Palenda's avatar
Pascal Palenda committed
197
		void CScene::Diff(const ReceiverMap& mOld, const ReceiverMap& mNew, std::vector< int >& viNewElems, std::vector< int >& viComElems, std::vector< int >& viDelElems) const
198
		{
199
200
201
202
			// Clear container
			viNewElems.clear();
			viComElems.clear();
			viDelElems.clear();
203

204
			// Sanity check: ordered lists
205

206
207
208
209
210
211
212
213
214
215
			ReceiverMapCit cit = mOld.begin();
			int iPreviousID = -1;
			while (cit != mOld.end())
			{
				int iNextID = cit->first;
				if (iNextID > iPreviousID)
					cit++;
				else
					ITA_EXCEPT1(INVALID_PARAMETER, "Old receiver map corrupted, order invalid (prev>=next): " + IntToString(iPreviousID) + " >= " + IntToString(iNextID));
				iPreviousID = iNextID;
216
			}
217
218
219
220

			cit = mNew.begin();
			iPreviousID = -1;
			while (cit != mNew.end())
221
			{
222
223
224
225
226
227
228
				int iNextID = cit->first;
				if (iNextID > iPreviousID)
					cit++;
				else
					ITA_EXCEPT1(INVALID_PARAMETER, "New receiver map corrupted, order invalid (prev>=next): " + IntToString(iPreviousID) + " >= " + IntToString(iNextID));
				iPreviousID = iNextID;
			}
229

230
231
			// Preparations for assertions
			int iTotalNumEntities = int(mOld.size() + mNew.size());
232

233
234
235
236
237
238
239
			// Intersection test
			ReceiverMapCit oldit = mOld.begin();
			ReceiverMapCit newit = mNew.begin();
			while (true)
			{
				// End condition: no further elements in old list or new list or both
				if (oldit == mOld.end() && newit != mNew.end())
240
				{
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
					// All elements of new list are new
					while (newit != mNew.end())
					{
						viNewElems.push_back(newit->first);
						newit++;
					}

					break;
				}
				else if (newit == mNew.end() && oldit != mOld.end())
				{
					// All elements of old list have been removed
					while (oldit != mOld.end())
					{
						viDelElems.push_back(oldit->first);
						oldit++;
					}

					break;
260
				}
261
				else if (oldit != mOld.end() && newit != mNew.end())
262
263
				{

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
					int iOldID = oldit->first;
					int iNewID = newit->first;

					if (iOldID < iNewID)
					{
						// Old id missing in new list -> removed
						viDelElems.push_back(iOldID);

						// Continue to reach equivalent new id
						oldit++;
					}
					else if (iOldID > iNewID)
					{
						// New id missing in old list 
						viNewElems.push_back(iNewID);

						// Continue to reach equivalent new id
						newit++;
					}
					else
					{
						// Old and new id are equivalent
						assert(iOldID == iNewID);
						viComElems.push_back(iOldID);

						// Continue on both maps
						oldit++;
						newit++;
					}
293
294
295
				}
				else
				{
296
297
					// Both lists brought to end
					break;
298
				}
299
300
301
			}


302
303
			// Assert correct number of entities after comparison
			assert(iTotalNumEntities == int(viNewElems.size() + viDelElems.size() + 2 * viComElems.size()));
304

305
			return;
306
307
		}

Pascal Palenda's avatar
Pascal Palenda committed
308
		void CScene::Diff(const SourceMap& mOld, const SourceMap& mNew, std::vector<int>& viNewElems, std::vector<int>& viComElems, std::vector<int>& viDelElems) const
309
		{
310
311
312
313
			// Clear container
			viNewElems.clear();
			viComElems.clear();
			viDelElems.clear();
314

315
			// Sanity check: ordered lists
316

317
318
319
			SourceMapCit cit = mOld.begin();
			int iPreviousID = -1;
			while (cit != mOld.end())
320
			{
321
322
323
324
325
326
				int iNextID = cit->first;
				if (iNextID > iPreviousID)
					cit++;
				else
					ITA_EXCEPT1(INVALID_PARAMETER, "Old source map corrupted, order invalid (prev>=next): " + IntToString(iPreviousID) + " >= " + IntToString(iNextID));
				iPreviousID = iNextID;
327
328
			}

329
330
331
			cit = mNew.begin();
			iPreviousID = -1;
			while (cit != mNew.end())
332
			{
333
334
335
336
337
338
339
				int iNextID = cit->first;
				if (iNextID > iPreviousID)
					cit++;
				else
					ITA_EXCEPT1(INVALID_PARAMETER, "New source map corrupted, order invalid (prev>=next): " + IntToString(iPreviousID) + " >= " + IntToString(iNextID));
				iPreviousID = iNextID;
			}
340

341
342
			// Preparations for assertions
			int iTotalNumEntities = int(mOld.size() + mNew.size());
343

344
345
346
347
348
349
350
			// Intersection test
			SourceMapCit oldit = mOld.begin();
			SourceMapCit newit = mNew.begin();
			while (true)
			{
				// End condition: no further elements in old list or new list or both
				if (oldit == mOld.end() && newit != mNew.end())
351
				{
352
353
354
355
356
357
358
359
					// All elements of new list are new
					while (newit != mNew.end())
					{
						viNewElems.push_back(newit->first);
						newit++;
					}

					break;
360
				}
361
362
363
364
365
366
367
368
369
370
371
372
				else if (newit == mNew.end() && oldit != mOld.end())
				{
					// All elements of old list have been removed
					while (oldit != mOld.end())
					{
						viDelElems.push_back(oldit->first);
						oldit++;
					}

					break;
				}
				else if (oldit != mOld.end() && newit != mNew.end())
373
374
				{

375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
					int iOldID = oldit->first;
					int iNewID = newit->first;

					if (iOldID < iNewID)
					{
						// Old id missing in new list -> removed
						viDelElems.push_back(iOldID);

						// Continue to reach equivalent new id
						oldit++;
					}
					else if (iOldID > iNewID)
					{
						// New id missing in old list 
						viNewElems.push_back(iNewID);

						// Continue to reach equivalent new id
						newit++;
					}
					else
					{
						// Old and new id are equivalent
						assert(iOldID == iNewID);
						viComElems.push_back(iOldID);

						// Continue on both maps
						oldit++;
						newit++;
					}
404
405
406
				}
				else
				{
407
408
					// Both lists brought to end
					break;
409
				}
410
411
412
			}


413
414
			// Assert correct number of entities after comparison
			assert(iTotalNumEntities == int(viNewElems.size() + viDelElems.size() + 2 * viComElems.size()));
415

416
			return;
417
418
		}

Pascal Palenda's avatar
Pascal Palenda committed
419
		void CScene::Diff(const PortalMap& mOld, const PortalMap& mNew, std::vector<int>& viNewElems, std::vector<int>& viComElems, std::vector<int>& viDelElems) const
420
		{
421
422
423
424
			// Clear container
			viNewElems.clear();
			viComElems.clear();
			viDelElems.clear();
425

426
			// Sanity check: ordered lists
427

428
429
430
			PortalMapCit cit = mOld.begin();
			int iPreviousID = -1;
			while (cit != mOld.end())
431
			{
432
433
434
435
436
437
				int iNextID = cit->first;
				if (iNextID > iPreviousID)
					cit++;
				else
					ITA_EXCEPT1(INVALID_PARAMETER, "Old portal map corrupted, order invalid (prev>=next): " + IntToString(iPreviousID) + " >= " + IntToString(iNextID));
				iPreviousID = iNextID;
438
439
			}

440
441
442
			cit = mNew.begin();
			iPreviousID = -1;
			while (cit != mNew.end())
443
			{
444
445
446
447
448
449
450
				int iNextID = cit->first;
				if (iNextID > iPreviousID)
					cit++;
				else
					ITA_EXCEPT1(INVALID_PARAMETER, "New portal map corrupted, order invalid (prev>=next): " + IntToString(iPreviousID) + " >= " + IntToString(iNextID));
				iPreviousID = iNextID;
			}
451

452
453
			// Preparations for assertions
			int iTotalNumEntities = int(mOld.size() + mNew.size());
454

455
456
457
458
459
460
461
			// Intersection test
			PortalMapCit oldit = mOld.begin();
			PortalMapCit newit = mNew.begin();
			while (true)
			{
				// End condition: no further elements in old list or new list or both
				if (oldit == mOld.end() && newit != mNew.end())
462
				{
463
464
465
466
467
468
469
470
					// All elements of new list are new
					while (newit != mNew.end())
					{
						viNewElems.push_back(newit->first);
						newit++;
					}

					break;
471
				}
472
473
474
475
476
477
478
479
480
481
482
483
				else if (newit == mNew.end() && oldit != mOld.end())
				{
					// All elements of old list have been removed
					while (oldit != mOld.end())
					{
						viDelElems.push_back(oldit->first);
						oldit++;
					}

					break;
				}
				else if (oldit != mOld.end() && newit != mNew.end())
484
485
				{

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
					int iOldID = oldit->first;
					int iNewID = newit->first;

					if (iOldID < iNewID)
					{
						// Old id missing in new list -> removed
						viDelElems.push_back(iOldID);

						// Continue to reach equivalent new id
						oldit++;
					}
					else if (iOldID > iNewID)
					{
						// New id missing in old list 
						viNewElems.push_back(iNewID);

						// Continue to reach equivalent new id
						newit++;
					}
					else
					{
						// Old and new id are equivalent
						assert(iOldID == iNewID);
						viComElems.push_back(iOldID);

						// Continue on both maps
						oldit++;
						newit++;
					}
515
516
517
				}
				else
				{
518
519
					// Both lists brought to end
					break;
520
				}
521
522
523
			}


524
525
			// Assert correct number of entities after comparison
			assert(iTotalNumEntities == int(viNewElems.size() + viDelElems.size() + 2 * viComElems.size()));
526

527
			return;
528
		}
529

Pascal Palenda's avatar
Pascal Palenda committed
530
		std::string CScene::ToString() const
531
		{
532
			std::ostringstream  ss;
533

534
			ss << "Number of sources: " << m_mSources.size() << std::endl;
535

536
537
538
539
540
541
			SourceMapCit cits = m_mSources.begin();
			while (cits != m_mSources.end())
			{
				ss << " + Source " << cits->first << " has state (pos: " << cits->second.vPos.x << ", " << cits->second.vPos.y << ", " << cits->second.vPos.z << "; dir: " << cits->second.sDirectivityFilename << ")" << std::endl;
				cits++;
			}
542

543
544
545
546
547
548
549
			ss << "Number of receivers: " << m_mReceivers.size() << std::endl;
			ReceiverMapCit citr = m_mReceivers.begin();
			while (citr != m_mReceivers.end())
			{
				ss << " + Receiver " << citr->first << " has state (pos: " << citr->second.vPos.x << ", " << citr->second.vPos.y << ", " << citr->second.vPos.z << "; dir: " << citr->second.sHRIRFilename << ")" << std::endl;
				citr++;
			}
550

551
552
553
554
555
556
557
			ss << "Number of portals: " << m_mPortals.size() << std::endl;
			PortalMapCit citp = m_mPortals.begin();
			while (citp != m_mPortals.end())
			{
				ss << " + Portal " << citp->first << " has state (posx=" << citp->second.vPos.x << ", state=" << citp->second.dState << ")" << std::endl;
				citp++;
			}
558

559
			return ss.str();
560
561
		}

Pascal Palenda's avatar
Pascal Palenda committed
562
		void CScene::Store(const std::string& sPath, int iFloatingPointPrecision) const
563
		{
564
			INIFileUseFile(sPath);
565

566
567
568
569
			SourceMapCit cits = m_mSources.begin();
			while (cits != m_mSources.end())
			{
				int iID = cits->first;
Pascal Palenda's avatar
Pascal Palenda committed
570
				const CSourceState& oState = cits->second;
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
				std::string sKey = "Source" + IntToString(iID);
				std::vector< std::string > vsSource;
				vsSource.push_back(FloatToString(oState.vPos.x, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vPos.y, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vPos.z, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vView.x, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vView.y, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vView.z, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vUp.x, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vUp.y, iFloatingPointPrecision));
				vsSource.push_back(FloatToString(oState.vUp.z, iFloatingPointPrecision));
				vsSource.push_back(oState.sDirectivityFilename);
				INIFileWriteStringList(sPath, "SCENE", sKey, vsSource);
				cits++;
			}
586

587
588
			ReceiverMapCit citr = m_mReceivers.begin();
			while (citr != m_mReceivers.end())
589
			{
590
				int iID = citr->first;
Pascal Palenda's avatar
Pascal Palenda committed
591
				const CReceiverState& oState = citr->second;
592
593
594
595
596
597
598
599
600
601
602
603
604
605
				std::string sKey = "Receiver" + IntToString(iID);
				std::vector< std::string > vsReceiver;
				vsReceiver.push_back(FloatToString(oState.vPos.x, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vPos.y, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vPos.z, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vView.x, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vView.y, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vView.z, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vUp.x, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vUp.y, iFloatingPointPrecision));
				vsReceiver.push_back(FloatToString(oState.vUp.z, iFloatingPointPrecision));
				vsReceiver.push_back(oState.sHRIRFilename);
				INIFileWriteStringList(sPath, "SCENE", sKey, vsReceiver);
				citr++;
606
			}
607

608
609
			PortalMapCit citp = m_mPortals.begin();
			while (citp != m_mPortals.end())
610
			{
611
				int iID = citp->first;
Pascal Palenda's avatar
Pascal Palenda committed
612
				const CPortalState& oState = citp->second;
613
614
615
616
617
618
619
620
				std::string sKey = "Portal" + IntToString(iID);
				std::vector< std::string > vsPortal;
				vsPortal.push_back(FloatToString(oState.vPos.x, iFloatingPointPrecision));
				vsPortal.push_back(FloatToString(oState.vPos.y, iFloatingPointPrecision));
				vsPortal.push_back(FloatToString(oState.vPos.z, iFloatingPointPrecision));
				vsPortal.push_back(DoubleToString(oState.dState));
				INIFileWriteStringList(sPath, "SCENE", sKey, vsPortal);
				citp++;
621
			}
622
623
		}

Pascal Palenda's avatar
Pascal Palenda committed
624
		void CScene::Load(const std::string& sPath)
625
626
		{
			Reset();
627

628
629
			INIFileUseFile(sPath);
			INIFileUseSection("Scene");
630

631
632
633
			std::vector< std::string > vsKeys(INIFileGetKeys("Scene"));

			for (int i = 0; i < (int)vsKeys.size(); i++)
634
			{
635
				std::string sKey(toLowercase(vsKeys[i]));
636

637
638
639
640
641
642
643
644
645
646
647
648
649
				std::string sPrefix = "source";
				std::size_t iFound = sKey.find(sPrefix);
				if (iFound != std::string::npos)
				{
					std::string sID(&(sKey[iFound + sPrefix.size()]));
					int iID = StringToInt(sID);

					std::vector< std::string > vsSource(INIFileReadStringList(sKey));

					int iNumParams = 3 + 3 + 3 + 1;
					if (vsSource.size() != iNumParams)
						ITA_EXCEPT1(INVALID_PARAMETER, "Invalid source '" + sKey + "' in '" + sPath + "', list must have " + IntToString(iNumParams) + " elements");

Pascal Palenda's avatar
Pascal Palenda committed
650
					CSourceState oState;
651
652
653
654
655
656
657
658
659
660
661
662
663
664
					oState.vPos.x = (float)StringToDouble(vsSource[0]);
					oState.vPos.y = (float)StringToDouble(vsSource[1]);
					oState.vPos.z = (float)StringToDouble(vsSource[2]);
					oState.vView.x = (float)StringToDouble(vsSource[3]);
					oState.vView.y = (float)StringToDouble(vsSource[4]);
					oState.vView.z = (float)StringToDouble(vsSource[5]);
					oState.vUp.x = (float)StringToDouble(vsSource[6]);
					oState.vUp.y = (float)StringToDouble(vsSource[7]);
					oState.vUp.z = (float)StringToDouble(vsSource[8]);
					oState.sDirectivityFilename = vsSource[9];

					AddSource(iID);
					SetSourceState(iID, oState);
				}
665

666
667
668
669
670
671
672
673
674
675
676
677
678
				sPrefix = "receiver";
				iFound = sKey.find(sPrefix);
				if (iFound != std::string::npos)
				{
					std::string sID(&(sKey[iFound + sPrefix.size()]));
					int iID = StringToInt(sID);

					std::vector< std::string > vsReceiver(INIFileReadStringList(sKey));

					int iNumParams = 3 + 3 + 3 + 1;
					if (vsReceiver.size() != iNumParams)
						ITA_EXCEPT1(INVALID_PARAMETER, "Invalid receiver '" + sKey + "' in '" + sPath + "', list must have " + IntToString(iNumParams) + " elements");

Pascal Palenda's avatar
Pascal Palenda committed
679
					CReceiverState oState;
680
681
682
683
684
685
686
687
688
689
690
691
692
693
					oState.vPos.x = (float)StringToDouble(vsReceiver[0]);
					oState.vPos.y = (float)StringToDouble(vsReceiver[1]);
					oState.vPos.z = (float)StringToDouble(vsReceiver[2]);
					oState.vView.x = (float)StringToDouble(vsReceiver[3]);
					oState.vView.y = (float)StringToDouble(vsReceiver[4]);
					oState.vView.z = (float)StringToDouble(vsReceiver[5]);
					oState.vUp.x = (float)StringToDouble(vsReceiver[6]);
					oState.vUp.y = (float)StringToDouble(vsReceiver[7]);
					oState.vUp.z = (float)StringToDouble(vsReceiver[8]);
					oState.sHRIRFilename = vsReceiver[9];

					AddReceiver(iID);
					SetReceiverState(iID, oState);
				}
694
695


696
697
698
699
700
701
				sPrefix = "portal";
				iFound = sKey.find(sPrefix);
				if (iFound != std::string::npos)
				{
					std::string sID(&(sKey[iFound + sPrefix.size()]));
					int iID = StringToInt(sID);
702

703
					std::vector< std::string > vsPortal(INIFileReadStringList(sKey));
704

705
706
707
708
					int iNumParams = 3 + 1;
					if (vsPortal.size() != iNumParams)
						ITA_EXCEPT1(INVALID_PARAMETER, "Invalid portal '" + sKey + "' in '" + sPath + "', list must have " + IntToString(iNumParams) + " elements");

Pascal Palenda's avatar
Pascal Palenda committed
709
					CPortalState oState;
710
711
712
713
714
715
716
717
718
					oState.vPos.x = (float)StringToDouble(vsPortal[0]);
					oState.vPos.y = (float)StringToDouble(vsPortal[1]);
					oState.vPos.z = (float)StringToDouble(vsPortal[2]);
					oState.dState = StringToDouble(vsPortal[3]);

					AddPortal(iID);
					SetPortalState(iID, oState);
				}
			}
719
720
		}

Pascal Palenda's avatar
Pascal Palenda committed
721
		bool CScene::Compare(const CScene& oScene) const
722
		{
Pascal Palenda's avatar
Pascal Palenda committed
723
			CSceneDiff oDiff;
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
			Diff(oScene, oDiff);

			for (int i = 0; i < (int)oDiff.viModSources.size(); i++)
			{
				int iID = oDiff.viModSources[i];
				if (GetSourceState(iID).Compare(oScene.GetSourceState(iID)) > 0)
					return true;
			}

			for (int i = 0; i < (int)oDiff.viModReceivers.size(); i++)
			{
				int iID = oDiff.viModReceivers[i];
				if (GetReceiverState(iID).Compare(oScene.GetReceiverState(iID)) > 0)
					return true;
			}

			for (int i = 0; i < (int)oDiff.viModPortals.size(); i++)
			{
				int iID = oDiff.viModPortals[i];
				if (GetPortalState(iID).Compare(oScene.GetPortalState(iID)) > 0)
					return true;
			}

			return false;
748
749
		}

Pascal Palenda's avatar
Pascal Palenda committed
750
		void CScene::Set(const CScene& oSrc)
751
		{
752
753
754
			m_mPortals = oSrc.m_mPortals;
			m_mReceivers = oSrc.m_mReceivers;
			m_mSources = oSrc.m_mSources;
755
756
		}

757
	}
758
}