1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>background_sound_manager.cpp</h1><a href="background__sound__manager_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026
00027 <font class="preprocessor">#include "<a class="code" href="stdsound_8h.html">stdsound.h</a>"</font>
00028
00029 <font class="preprocessor">#include "<a class="code" href="file_8h.html">nel/misc/file.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="i__xml_8h.html">nel/misc/i_xml.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="path_8h.html">nel/misc/path.h</a>"</font>
00032
00033 <font class="preprocessor">#include "<a class="code" href="primitive_8h.html">nel/ligo/primitive.h</a>"</font>
00034
00035 <font class="preprocessor">#include "<a class="code" href="u__source_8h.html">nel/sound/u_source.h</a>"</font>
00036
00037 <font class="preprocessor">#include "<a class="code" href="background__sound__manager_8h.html">background_sound_manager.h</a>"</font>
00038 <font class="preprocessor">#include <algorithm></font>
00039
00040 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00041 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00042 <font class="keyword">using</font> <font class="keyword">namespace </font>NLLIGO;
00043
00044
00045 <font class="keyword">namespace </font>NLSOUND {
00046
00047 <font class="comment">// external sound are cliping after 10 meter inside the inner patate</font>
00048 <font class="keyword">const</font> <font class="keywordtype">float</font> <a class="code" href="namespaceNLSOUND.html#a17">INSIDE_FALLOF</a> = 10.0f;
00049
00050 <font class="comment">//UAudioMixer *CBackgroundSoundManager::_AudioMixer = NULL;</font>
00051
00052
<a name="l00053"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c0">00053</a> CBackgroundSoundManager::CBackgroundSoundManager()
00054 : _LastPosition(0,0,0), _Playing(false)
00055 {
00056 }
00057
<a name="l00058"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c1">00058</a> CBackgroundSoundManager::~CBackgroundSoundManager()
00059 {
00060 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a4">unload</a>();
00061 }
00062
<a name="l00063"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a11">00063</a> <font class="keyword">const</font> UAudioMixer::TBackgroundFlags &CBackgroundSoundManager::getBackgroundFlags()
00064 {
00065 <font class="keywordflow">return</font> <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o1">_BackgroundFlags</a>;
00066 }
00067
<a name="l00068"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a12">00068</a> <font class="keywordtype">void</font> CBackgroundSoundManager::setBackgroundFlags(<font class="keyword">const</font> UAudioMixer::TBackgroundFlags &backgroundFlags)
00069 {
00070 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o1">_BackgroundFlags</a> = backgroundFlags;
00071 }
00072
<a name="l00073"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c2">00073</a> <font class="keywordtype">void</font> CBackgroundSoundManager::addSound(<font class="keyword">const</font> std::string &soundName, <font class="keyword">const</font> std::vector<NLLIGO::CPrimVector> &points, <font class="keywordtype">bool</font> isPath)
00074 {
00075 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#l0">CAudioMixerUser</a> *mixer = CAudioMixerUser::instance();
00076 uint layerId = 0;
00077 uint n = 0;
00078 string name;
00079 <font class="comment">// count the number of '-' in the sgtring.</font>
00080 n = <a class="code" href="cf__gramatical_8cpp.html#a70">std::count</a>(soundName.begin(), soundName.end(), <font class="charliteral">'-'</font>);
00081
00082 <font class="keywordflow">if</font> (n == 2)
00083 {
00084 <font class="comment">// no layer spec, default to layer A</font>
00085 uint32 pos1 = soundName.find (<font class="stringliteral">"-"</font>);
00086 <font class="keywordflow">if</font>(pos1 == string::npos)
00087 {
00088 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"zone have the malformated name '%s' missing -name-"</font>, soundName.c_str());
00089 <font class="keywordflow">return</font>;
00090 }
00091 pos1++;
00092
00093 uint32 pos2 = soundName.find (<font class="stringliteral">"-"</font>, pos1);
00094 <font class="keywordflow">if</font>(pos2 == string::npos)
00095 {
00096 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"zone have the malformated name '%s' missing -name-"</font>, soundName.c_str());
00097 <font class="keywordflow">return</font>;
00098 }
00099
00100 name = soundName.substr(pos1, pos2-pos1);
00101 }
00102 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (n == 3)
00103 {
00104 <font class="comment">// layer spec !</font>
00105 uint32 pos1 = soundName.find (<font class="stringliteral">"-"</font>);
00106 uint32 pos2 = soundName.find (<font class="stringliteral">"-"</font>, pos1+1);
00107 <font class="keywordflow">if</font>(pos1 == string::npos || pos2 == string::npos)
00108 {
00109 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"zone have the malformated name '%s' missing -layerId- or -name-"</font>, soundName.c_str());
00110 <font class="keywordflow">return</font>;
00111 }
00112 pos1++;
00113
00114 uint32 pos3 = soundName.find (<font class="stringliteral">"-"</font>, pos2+1);
00115 <font class="keywordflow">if</font>(pos3 == string::npos)
00116 {
00117 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"zone have the malformated name '%s' missing -name-"</font>, soundName.c_str());
00118 <font class="keywordflow">return</font>;
00119 }
00120
00121 <font class="keywordtype">char</font> <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> = soundName[pos1];
00122
00123 <font class="comment">// check caps</font>
00124 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> < <font class="charliteral">'a'</font>)
00125 <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> = <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> + (<font class="charliteral">'a'</font> - <font class="charliteral">'A'</font>);
00126
00127 layerId = <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a> - <font class="charliteral">'a'</font>;
00128
00129 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(layerId, 0u, <a class="code" href="namespaceNLSOUND.html#a18">BACKGROUND_LAYER</a>-1);
00130 pos2++;
00131
00132 name = soundName.substr(pos2, pos3-pos2);
00133 }
00134 <font class="keywordflow">else</font>
00135 {
00136 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"zone have the malformated name '%s"</font>, soundName.c_str());
00137 <font class="keywordflow">return</font>;
00138 }
00139
00140
00141 TSoundData sd;
00142
00143 sd.SoundName = name;
00144 sd.Sound = mixer->getSoundId(sd.SoundName);
00145 sd.Source = 0;
00146
00147 <font class="comment">// Copy the points</font>
00148 sd.Points.resize (points.size ());
00149 <font class="keywordflow">for</font> (uint i=0; i<points.size (); i++)
00150 sd.Points[i] = points[i];
00151
00152 sd.Selected = <font class="keyword">false</font>;
00153 sd.IsPath = isPath;
00154
00155 <font class="keywordflow">if</font> (sd.Sound != 0)
00156 {
00157 <font class="comment">// the sound is available !</font>
00158 <font class="comment">// compute bouding box/</font>
00159 CVector vmin(FLT_MAX, FLT_MAX, 0), vmax(-FLT_MAX, -FLT_MAX, 0);
00160
00161 vector<CVector>::iterator first(sd.Points.begin()), last(sd.Points.end());
00162 <font class="keywordflow">for</font> (; first != last; ++first)
00163 {
00164 vmin.x = <a class="code" href="bit__set_8cpp.html#a0">min</a>(first->x, vmin.x);
00165 vmin.y = <a class="code" href="bit__set_8cpp.html#a0">min</a>(first->y, vmin.y);
00166 vmax.x = max(first->x, vmax.x);
00167 vmax.y = max(first->y, vmax.y);
00168 }
00169 sd.MaxBox = vmax;
00170 sd.MinBox = vmin;
00171
00172 <font class="comment">// compute the surface without the sound distance</font>
00173 sd.Surface = (vmax.x - vmin.x) * (vmax.y - vmin.y);
00174
00175 <font class="comment">// add the eard distance of the sound.</font>
00176 <font class="keywordtype">float</font> dist = sd.Sound->getMaxDistance();
00177 sd.MaxBox.x += dist;
00178 sd.MaxBox.y += dist;
00179 sd.MinBox.x -= dist;
00180 sd.MinBox.y -= dist;
00181
00182 sd.MaxDist = dist;
00183
00184 <font class="comment">// store the sound. </font>
00185 <font class="comment">// TODO : handle the three layer.</font>
00186 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[layerId].push_back(sd);
00187 }
00188 <font class="keywordflow">else</font>
00189 {
00190 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"The sound '%s' can't be loaded"</font>, sd.SoundName.c_str());
00191 }
00192 }
00193
00194
<a name="l00195"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a2">00195</a> <font class="keywordtype">void</font> CBackgroundSoundManager::loadSamplesFromRegion(<font class="keyword">const</font> <a class="code" href="classNLLIGO_1_1CPrimRegion.html">NLLIGO::CPrimRegion</a> &region)
00196 {
00197 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_0">_Banks</a>.clear();
00198
00199 <font class="keywordflow">for</font> (uint i=0; i< region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>.size(); ++i)
00200 {
00201 <font class="keywordflow">if</font> (region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>[i].VPoints.size() > 2)
00202 {
00203 TBanksData bd;
00204 uint pointCount = region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>[i].VPoints.size ();
00205 bd.Points.resize (pointCount);
00206 <font class="keywordflow">for</font> (uint j=0; j<pointCount; j++)
00207 {
00208 bd.Points[j] = region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>[i].VPoints[j];
00209 }
00210
00211 <font class="comment">// compute bouding box.</font>
00212 CVector vmin(FLT_MAX, FLT_MAX, 0), vmax(-FLT_MAX, -FLT_MAX, 0);
00213
00214 vector<CVector>::iterator first(bd.Points.begin()), last(bd.Points.end());
00215 <font class="keywordflow">for</font> (; first != last; ++first)
00216 {
00217 vmin.x = <a class="code" href="bit__set_8cpp.html#a0">min</a>(first->x, vmin.x);
00218 vmin.y = <a class="code" href="bit__set_8cpp.html#a0">min</a>(first->y, vmin.y);
00219 vmax.x = max(first->x, vmax.x);
00220 vmax.y = max(first->y, vmax.y);
00221 }
00222 bd.MaxBox = vmax;
00223 bd.MinBox = vmin;
00224
00225 <font class="comment">// parse the zone name to find the samples name.</font>
00226 std::vector<std::string> splitted = <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c3">split</a>(region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>[i].Name, <font class="charliteral">'-'</font>);
00227
00228 <font class="keywordflow">if</font> (splitted.size() > 2)
00229 {
00230 <font class="keywordflow">for</font> (uint j=1; j<splitted.size()-1; ++j)
00231 {
00232 bd.Banks.push_back(splitted[j]);
00233 }
00234
00235 <font class="comment">// ok, store it in the container.</font>
00236 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_0">_Banks</a>.push_back(bd);
00237 }
00238 <font class="keywordflow">else</font>
00239 {
00240 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"A sample bank patatoid name did'nt contains banks name '%s'"</font>, region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>[i].Name.c_str());
00241 }
00242 }
00243 <font class="keywordflow">else</font>
00244 {
00245 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"A sample bank patatoid have less than 3 points '%s'"</font>, region.<a class="code" href="classNLLIGO_1_1CPrimRegion.html#m2">VZones</a>[i].Name.c_str());
00246 }
00247 }
00248 }
00249
<a name="l00250"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a1">00250</a> <font class="keywordtype">void</font> CBackgroundSoundManager::loadEffecsFromRegion(<font class="keyword">const</font> <a class="code" href="classNLLIGO_1_1CPrimRegion.html">NLLIGO::CPrimRegion</a> &region)
00251 {
00252 }
00253
00254 <font class="keywordtype">void</font> CBackgroundSoundManager::loadSoundsFromRegion(<font class="keyword">const</font> CPrimRegion &region)
00255 {
00256 uint i;
00257 <font class="comment">// remember playing state</font>
00258 <font class="keywordtype">bool</font> oldState = <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o0">_Playing</a>;
00259 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a4">unload</a>();
00260
00261 <font class="keywordflow">for</font> (i = 0; i < region.VZones.size(); i++)
00262 {
00263 <font class="keywordflow">if</font>(region.VZones[i].VPoints.size()>2)
00264 {
00265 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c2">addSound</a>(region.VZones[i].Name, region.VZones[i].VPoints, <font class="keyword">false</font>);
00266 }
00267 <font class="keywordflow">else</font>
00268 {
00269 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"A background sound patatoid have less than 3 points '%s'"</font>, region.VZones[i].Name.c_str());
00270 }
00271 }
00272
00273 <font class="keywordflow">for</font> (i = 0; i < region.VPaths.size(); i++)
00274 {
00275 <font class="keywordflow">if</font>(region.VPaths[i].VPoints.size() > 1)
00276 {
00277 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c2">addSound</a>(region.VPaths[i].Name, region.VPaths[i].VPoints, <font class="keyword">true</font>);
00278 }
00279 <font class="keywordflow">else</font>
00280 {
00281 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"A background sound path have less than 2 points '%s'"</font>, region.VPaths[i].Name.c_str());
00282 }
00283 }
00284 <font class="keywordflow">for</font> (i = 0; i < region.VPoints.size(); i++)
00285 {
00286 std::vector<CPrimVector> points;
00287 points.push_back(region.VPoints[i].Point);
00288
00289 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#c2">addSound</a>(region.VPoints[i].Name, points, <font class="keyword">false</font>);
00290 }
00291
00292
00293 <font class="comment">// restart playing ?</font>
00294 <font class="keywordflow">if</font> (oldState)
00295 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a5">play</a>();
00296 }
00297
00298 <font class="keywordtype">void</font> CBackgroundSoundManager::load (<font class="keyword">const</font> string &continent)
00299 {
00300 <font class="comment">// load the sound.</font>
00301 {
00302 CIFile <a class="code" href="cf__lexical_8cpp.html#a95">file</a>;
00303 CPrimRegion region;
00304 string fn = continent+<font class="stringliteral">"_audio.prim"</font>;
00305
00306 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"loading '%s'"</font>, fn.c_str());
00307
00308 string path = CPath::lookup(fn, <font class="keyword">false</font>);
00309
00310 <font class="keywordflow">if</font>(!path.empty() && <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.open (path))
00311 {
00312 CIXml xml;
00313 xml.init (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>);
00314 region.serial(xml);
00315 <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.close ();
00316
00317 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Region '%s' contains %d zones for the background sounds"</font>, continent.c_str(), region.VZones.size());
00318
00319 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a0">loadSoundsFromRegion</a>(region);
00320 }
00321 }
00322 <font class="comment">// load the effect.</font>
00323 {
00324 CIFile <a class="code" href="cf__lexical_8cpp.html#a95">file</a>;
00325 CPrimRegion region;
00326 string fn = continent+<font class="stringliteral">"_effects.prim"</font>;
00327
00328 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"loading '%s'"</font>, fn.c_str());
00329
00330 string path = CPath::lookup(fn, <font class="keyword">false</font>);
00331
00332 <font class="keywordflow">if</font>(!path.empty() && <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.open (path))
00333 {
00334 CIXml xml;
00335 xml.init (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>);
00336 region.serial(xml);
00337 <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.close ();
00338
00339 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Region '%s' contains %d zones for the background effetcs"</font>, continent.c_str(), region.VZones.size());
00340
00341 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a1">loadEffecsFromRegion</a>(region);
00342 }
00343 }
00344 <font class="comment">// load the samples banks.</font>
00345 {
00346 CIFile <a class="code" href="cf__lexical_8cpp.html#a95">file</a>;
00347 CPrimRegion region;
00348 string fn = continent+<font class="stringliteral">"_samples.prim"</font>;
00349
00350 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"loading '%s'"</font>, fn.c_str());
00351
00352 string path = CPath::lookup(fn, <font class="keyword">false</font>);
00353
00354 <font class="keywordflow">if</font>(!path.empty() && <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.open (path))
00355 {
00356 CIXml xml;
00357 xml.init (<a class="code" href="cf__lexical_8cpp.html#a95">file</a>);
00358 region.serial(xml);
00359 <a class="code" href="cf__lexical_8cpp.html#a95">file</a>.close ();
00360
00361 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"Region '%s' contains %d zones for the background samples banks"</font>, continent.c_str(), region.VZones.size());
00362
00363 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a2">loadSamplesFromRegion</a>(region);
00364 }
00365 }
00366 }
00367
00368
<a name="l00369"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a5">00369</a> <font class="keywordtype">void</font> CBackgroundSoundManager::play ()
00370 {
00371 <font class="keywordflow">if</font> (_Playing)
00372 <font class="keywordflow">return</font>;
00373
00374 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o0">_Playing</a> = <font class="keyword">true</font>;
00375
00376 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a8">updateBackgroundStatus</a>();
00377 }
00378
00379
<a name="l00380"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a6">00380</a> <font class="keywordtype">void</font> CBackgroundSoundManager::stop ()
00381 {
00382 <font class="keywordflow">if</font>(!<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o0">_Playing</a>)
00383 <font class="keywordflow">return</font>;
00384 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#l0">CAudioMixerUser</a> *mixer = CAudioMixerUser::instance();
00385
00386 <font class="keywordflow">for</font> (uint i=0; i<<a class="code" href="namespaceNLSOUND.html#a18">BACKGROUND_LAYER</a>; ++i)
00387 {
00388 <font class="comment">// stop all playing source</font>
00389 std::vector<TSoundData>::iterator first(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[i].begin()), last(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[i].end());
00390 <font class="keywordflow">for</font> (; first != last; ++first)
00391 {
00392 <font class="keywordflow">if</font> (first->Source != 0 && first->Source->isPlaying())
00393 first->Source->stop();
00394 }
00395 }
00396
00397 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o0">_Playing</a> = <font class="keyword">false</font>;
00398 }
00399
<a name="l00400"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a4">00400</a> <font class="keywordtype">void</font> CBackgroundSoundManager::unload ()
00401 {
00402 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a6">stop</a>();
00403
00404 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#l0">CAudioMixerUser</a> *mixer = CAudioMixerUser::instance();
00405
00406 <font class="keywordflow">for</font> (uint i=0; i<<a class="code" href="namespaceNLSOUND.html#a18">BACKGROUND_LAYER</a>; ++i)
00407 {
00408 <font class="comment">// delete all created source</font>
00409 std::vector<TSoundData>::iterator first(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[i].begin()), last(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[i].end());
00410 <font class="keywordflow">for</font> (; first != last; ++first)
00411 {
00412 <font class="keywordflow">if</font> (first->Source)
00413 <font class="comment">// mixer->removeSource(first->Source);</font>
00414 <font class="keyword">delete</font> first->Source;
00415 }
00416
00417 <font class="comment">// and free the layer.</font>
00418 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[i].clear();
00419 }
00420 }
00421
00422 <font class="keywordtype">void</font> CBackgroundSoundManager::setListenerPosition (<font class="keyword">const</font> CVector &listenerPosition)
00423 {
00424 <font class="keywordflow">if</font> (<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o2">_LastPosition</a> == listenerPosition)
00425 {
00426 <font class="keywordflow">return</font>;
00427 }
00428 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o2">_LastPosition</a> = listenerPosition;
00429
00430 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a8">updateBackgroundStatus</a>();
00431 }
00432
<a name="l00433"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a8">00433</a> <font class="keywordtype">void</font> CBackgroundSoundManager::updateBackgroundStatus()
00434 {
00435 <font class="keywordflow">if</font> (!<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o0">_Playing</a>)
00436 <font class="keywordflow">return</font>;
00437
00438 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#l0">CAudioMixerUser</a> *mixer = CAudioMixerUser::instance();
00439
00440 <font class="comment">// it s on 2d so we don't have z</font>
00441 CVector listener = <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o2">_LastPosition</a>;
00442 listener.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a> = 0.0f;
00443
00444 <font class="comment">// compute the list of load/unload banks.</font>
00445 {
00446 <font class="comment">// set of bank that must be in ram.</font>
00447 std::set<std::string> newBanks;
00448
00449 std::vector<TBanksData>::iterator first(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_0">_Banks</a>.begin()), last(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_0">_Banks</a>.end());
00450 <font class="keywordflow">for</font> (; first != last; ++first)
00451 {
00452 <font class="keywordflow">if</font> (listener.x >= first->MinBox.x && listener.x <= first->MaxBox.x
00453 && listener.y >= first->MinBox.y && listener.y <= first->MaxBox.y
00454 )
00455 {
00456 <font class="comment">// bounding box ok, </font>
00457 <font class="keywordflow">if</font> (CPrimZone::contains(listener, first->Points))
00458 {
00459 <font class="comment">// add the banks of this zone in the n</font>
00460 newBanks.insert(first->Banks.begin(), first->Banks.end());
00461 }
00462 }
00463 }
00464 <font class="comment">// ok, now compute to set : the set of bank to load, and the set of banks to unload.</font>
00465 std::set<std::string> noChange;
00466 std::set_intersection(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_1">_LoadedBanks</a>.begin(), <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_1">_LoadedBanks</a>.end(), newBanks.begin(), newBanks.end(), std::inserter(noChange, noChange.end()));
00467
00468 std::set<std::string> loadList;
00469 std::set_difference(newBanks.begin(), newBanks.end(), noChange.begin(), noChange.end(), std::inserter(loadList, loadList.end()));
00470
00471 std::set<std::string> unloadList;
00472 std::set_difference(<a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_1">_LoadedBanks</a>.begin(), <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_1">_LoadedBanks</a>.end(), newBanks.begin(), newBanks.end(), std::inserter(unloadList, unloadList.end()));
00473
00474 <font class="comment">// and now, load and unload....</font>
00475 {
00476 std::set<std::string>::iterator first(loadList.begin()), last(loadList.end());
00477 <font class="keywordflow">for</font> (; first != last; ++first)
00478 {
00479 mixer->loadSampleBank(<font class="keyword">true</font>, *first);
00480 }
00481 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_1">_LoadedBanks</a>.insert(loadList.begin(), loadList.end());
00482 }
00483 {
00484 std::set<std::string>::iterator first(unloadList.begin()), last(unloadList.end());
00485 <font class="keywordflow">for</font> (; first != last; ++first)
00486 {
00487 <font class="keywordflow">if</font> (mixer->unloadSampleBank(*first))
00488 {
00489 <font class="comment">// ok, the bank is unloaded</font>
00490 <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z961_1">_LoadedBanks</a>.erase(*first);
00491 }
00492 }
00493 }
00494 }
00495
00496 <font class="comment">// Apply the same algo for each sound layer.</font>
00497 <font class="keywordflow">for</font> (uint i=0; i<<a class="code" href="namespaceNLSOUND.html#a18">BACKGROUND_LAYER</a>; ++i)
00498 {
00499 vector<TSoundData> &layer = <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#z962_0">_Layers</a>[i];
00500 vector<uint> selectedIndex;
00501 vector<uint> leaveIndex;
00502
00503 selectedIndex.reserve(layer.size());
00504 leaveIndex.reserve(layer.size());
00505
00506 <font class="comment">// extract the list of selected/unselected box</font>
00507 vector<TSoundData>::iterator first(layer.begin()), last(layer.end());
00508 <font class="keywordflow">for</font> (uint count = 0; first != last; ++first, ++count)
00509 {
00510 <font class="keywordflow">if</font> (listener.x >= first->MinBox.x && listener.x <= first->MaxBox.x
00511 && listener.y >= first->MinBox.y && listener.y <= first->MaxBox.y
00512 <font class="comment">// && listener.z >= first->MinBox.z && listener.z <= first->MaxBox.z</font>
00513 )
00514 {
00515 <font class="comment">// nldebug("patat %u is selected by box (%s)", count, first->SoundName.c_str());</font>
00516 selectedIndex.push_back(count);
00517 }
00518 <font class="keywordflow">else</font>
00519 {
00520 <font class="comment">// nldebug("patat %u is rejected by box (%s)", count, first->SoundName.c_str());</font>
00521 <font class="comment">// listener out of this box.</font>
00522 <font class="keywordflow">if</font> (first->Selected && first->Source != 0)
00523 {
00524 <font class="comment">// we leave this box.</font>
00525 leaveIndex.push_back(count);
00526 }
00527 }
00528 }
00529
00530 <font class="comment">// stop all the sound that are leaved.</font>
00531 {
00532 vector<uint>::iterator first(leaveIndex.begin()), last(leaveIndex.end());
00533 <font class="keywordflow">for</font> (; first != last; ++first)
00534 {
00535 TSoundData &sd = layer[*first];
00536 sd.Selected = <font class="keyword">false</font>;
00537 <font class="keywordflow">if</font> (sd.Source->isPlaying())
00538 sd.Source->stop();
00539 }
00540 }
00541 <font class="comment">// Compute new source mixing in this layer</font>
00542 {
00544 map<float, TSoundStatus> status;
00545
00546 <font class="comment">// first loop to compute selected sound gain and position and order the result by surface..</font>
00547 {
00548 vector<uint>::iterator first(selectedIndex.begin()), last(selectedIndex.end());
00549 <font class="keywordflow">for</font> (; first != last; ++first)
00550 {
00551 TSoundData &sd = layer[*first];
00552 CVector pos;
00553 <font class="keywordtype">float</font> gain;
00554 <font class="keywordtype">float</font> distance;
00555
00556 <font class="comment">// inside the patat ?</font>
00557
00558 <font class="keywordflow">if</font>(CPrimZone::contains(listener, sd.Points, distance, pos, sd.IsPath))
00559 {
00560 pos = <a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#o2">_LastPosition</a>; <font class="comment">// use the real listener position, not the 0 z centered</font>
00561 gain = 1.0f;
00562 <font class="comment">// nlinfo ("inside patate %d name '%s' ", *first, sd.SoundName.c_str());</font>
00563 }
00564 <font class="keywordflow">else</font>
00565 {
00566 <font class="keywordflow">if</font> (distance < sd.MaxDist)
00567 {
00568 <font class="comment">// compute the gain.</font>
00569 gain = (sd.MaxDist - distance) / sd.MaxDist;
00570 }
00571 <font class="keywordflow">else</font>
00572 {
00573 <font class="comment">// too far</font>
00574 gain = 0;
00575 }
00576 <font class="comment">//nlinfo ("near patate %d name '%s' from %f ", *first, sd.SoundName.c_str(), distance);</font>
00577 }
00578
00579 <font class="comment">// store the status.</font>
00580 status.insert(make_pair(sd.Surface, TSoundStatus(sd, pos, gain, distance)));
00581 }
00582 }
00583 <font class="comment">// second loop thrue the surface ordered selected sound.</font>
00584 {
00585 <font class="comment">// Sound mixing strategie :</font>
00586 <font class="comment">// The smallest zone sound mask bigger one</font>
00587
00588 <font class="keywordtype">float</font> maskFactor = 1.0f;
00589
00590 map<float, TSoundStatus>::iterator first(status.begin()), last(status.end());
00591 <font class="keywordflow">for</font> (; first != last; ++first)
00592 {
00593 TSoundStatus &ss = first->second;
00594
00595 <font class="keywordflow">if</font> (maskFactor > 0.0f && ss.Gain > 0)
00596 {
00597 <font class="keywordtype">float</font> gain = maskFactor * ss.Gain;
00598 <font class="comment">// maskFactor -= ss.Gain;</font>
00599
00600 ss.SoundData.Selected = <font class="keyword">true</font>;
00601
00602 <font class="keywordflow">if</font> (ss.Gain == 1)
00603 {
00604 <font class="comment">// inside a pattate, then decrease the mask factor will we are more inside the patate</font>
00605 maskFactor -= first->second.Distance / <a class="code" href="namespaceNLSOUND.html#a17">INSIDE_FALLOF</a>;
00606 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(maskFactor, 0.0f, 1.0f);
00607 }
00608
00609 <font class="comment">// start the soond (if needed) and update the volume.</font>
00610
00611 <font class="keywordflow">if</font> (ss.SoundData.Source == 0)
00612 {
00613 <font class="comment">// try to create the source.</font>
00614 ss.SoundData.Source = mixer->createSource(ss.SoundData.Sound, <font class="keyword">false</font>);
00615 }
00616 <font class="keywordflow">if</font> (ss.SoundData.Source != 0)
00617 {
00618 <font class="comment">// set the volume</font>
00619 ss.SoundData.Source->setRelativeGain(gain);
00620 <font class="comment">// and the position</font>
00621 ss.Position.z += 5.0f;
00622 ss.SoundData.Source->setPos(ss.Position);
00623
00624 <font class="comment">// nldebug("Setting source %s at %f", ss.SoundData.SoundName.c_str(), gain);</font>
00625 <font class="keywordflow">if</font> (!ss.SoundData.Source->isPlaying())
00626 {
00627 <font class="comment">// start the sound is needed.</font>
00628 ss.SoundData.Source->play();
00629 }
00630 }
00631 }
00632 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (ss.SoundData.Source != 0 && ss.SoundData.Source->isPlaying())
00633 {
00634 <font class="comment">// stop this too far source.</font>
00635 ss.SoundData.Source->stop();
00636 }
00637 }
00638 }
00639 } <font class="comment">// compute source mixing</font>
00640 } <font class="comment">// for each layer</font>
00641 }
00642
00643 <font class="comment">/*</font>
00644 <font class="comment">void CBackgroundSoundManager::update ()</font>
00645 <font class="comment">{</font>
00646 <font class="comment"></font>
00647 <font class="comment">}</font>
00648 <font class="comment">*/</font>
00649 <font class="comment">/*</font>
00650 <font class="comment">uint32 CBackgroundSoundManager::getZoneNumber ()</font>
00651 <font class="comment">{</font>
00652 <font class="comment">// return BackgroundSounds.size();</font>
00653 <font class="comment"> return 0;</font>
00654 <font class="comment">}</font>
00655 <font class="comment">*/</font>
00656 <font class="comment">/*</font>
00657 <font class="comment">const vector<CVector> &CBackgroundSoundManager::getZone(uint32 zone)</font>
00658 <font class="comment">{</font>
00659 <font class="comment">// nlassert (zone< BackgroundSounds.size());</font>
00660 <font class="comment">// return BackgroundSounds[zone].Points;</font>
00661 <font class="comment"> static vector<CVector> v;</font>
00662 <font class="comment"> return v;</font>
00663 <font class="comment">}</font>
00664 <font class="comment">*/</font>
<a name="l00665"></a><a class="code" href="classNLSOUND_1_1CBackgroundSoundManager.html#a10">00665</a> CVector CBackgroundSoundManager::getZoneSourcePos(uint32 zone)
00666 {
00667 <font class="comment">/* nlassert (zone< BackgroundSounds.size());</font>
00668 <font class="comment"> CVector pos;</font>
00669 <font class="comment"> if (BackgroundSounds[zone].SourceDay != NULL)</font>
00670 <font class="comment"> BackgroundSounds[zone].SourceDay->getPos(pos);</font>
00671 <font class="comment"> return pos;</font>
00672 <font class="comment">*/</font>
00673 <font class="keywordflow">return</font> CVector();
00674 }
00675
00676
00677 <font class="comment">/*</font>
00678 <font class="comment">void CBackgroundSoundManager::setDayNightRatio(float ratio)</font>
00679 <font class="comment">{</font>
00680 <font class="comment"> // 0 is day</font>
00681 <font class="comment"> // 1 is night</font>
00682 <font class="comment"></font>
00683 <font class="comment"> nlassert (ratio>=0.0f && ratio<=1.0f);</font>
00684 <font class="comment"></font>
00685 <font class="comment"> if (OldRatio == ratio)</font>
00686 <font class="comment"> return;</font>
00687 <font class="comment"> else</font>
00688 <font class="comment"> OldRatio = ratio;</font>
00689 <font class="comment"></font>
00690 <font class="comment"></font>
00691 <font class="comment"> // recompute all source volume</font>
00692 <font class="comment"></font>
00693 <font class="comment"> for (uint i = 0; i < BackgroundSounds.size(); i++)</font>
00694 <font class="comment"> {</font>
00695 <font class="comment"> if(ratio == 0.0f)</font>
00696 <font class="comment"> {</font>
00697 <font class="comment"> if(BackgroundSounds[i].SourceDay != NULL)</font>
00698 <font class="comment"> {</font>
00699 <font class="comment"> BackgroundSounds[i].SourceDay->setRelativeGain(1.0f);</font>
00700 <font class="comment"></font>
00701 <font class="comment"> if (!BackgroundSounds[i].SourceDay->isPlaying())</font>
00702 <font class="comment"> BackgroundSounds[i].SourceDay->play();</font>
00703 <font class="comment"> }</font>
00704 <font class="comment"> </font>
00705 <font class="comment"> if(BackgroundSounds[i].SourceNight != NULL)</font>
00706 <font class="comment"> {</font>
00707 <font class="comment"> if (BackgroundSounds[i].SourceNight->isPlaying())</font>
00708 <font class="comment"> BackgroundSounds[i].SourceNight->stop();</font>
00709 <font class="comment"> }</font>
00710 <font class="comment"> }</font>
00711 <font class="comment"> else if (ratio == 1.0f)</font>
00712 <font class="comment"> {</font>
00713 <font class="comment"> if(BackgroundSounds[i].SourceDay != NULL)</font>
00714 <font class="comment"> {</font>
00715 <font class="comment"> if (BackgroundSounds[i].SourceDay->isPlaying())</font>
00716 <font class="comment"> BackgroundSounds[i].SourceDay->stop();</font>
00717 <font class="comment"> }</font>
00718 <font class="comment"></font>
00719 <font class="comment"> if(BackgroundSounds[i].SourceNight != NULL)</font>
00720 <font class="comment"> {</font>
00721 <font class="comment"> BackgroundSounds[i].SourceNight->setRelativeGain(1.0f);</font>
00722 <font class="comment"></font>
00723 <font class="comment"> if (!BackgroundSounds[i].SourceNight->isPlaying())</font>
00724 <font class="comment"> BackgroundSounds[i].SourceNight->play();</font>
00725 <font class="comment"> }</font>
00726 <font class="comment"> }</font>
00727 <font class="comment"> else</font>
00728 <font class="comment"> {</font>
00729 <font class="comment"> if(BackgroundSounds[i].SourceDay != NULL)</font>
00730 <font class="comment"> {</font>
00731 <font class="comment"> BackgroundSounds[i].SourceDay->setRelativeGain((1.0f-ratio));</font>
00732 <font class="comment"></font>
00733 <font class="comment"> if (!BackgroundSounds[i].SourceDay->isPlaying())</font>
00734 <font class="comment"> BackgroundSounds[i].SourceDay->play();</font>
00735 <font class="comment"> }</font>
00736 <font class="comment"></font>
00737 <font class="comment"> if(BackgroundSounds[i].SourceNight != NULL)</font>
00738 <font class="comment"> {</font>
00739 <font class="comment"> BackgroundSounds[i].SourceNight->setRelativeGain(ratio);</font>
00740 <font class="comment"></font>
00741 <font class="comment"> if (!BackgroundSounds[i].SourceNight->isPlaying())</font>
00742 <font class="comment"> BackgroundSounds[i].SourceNight->play();</font>
00743 <font class="comment"> }</font>
00744 <font class="comment"> }</font>
00745 <font class="comment"> }</font>
00746 <font class="comment"></font>
00747 <font class="comment">}</font>
00748 <font class="comment">*/</font>
00749 } <font class="comment">// NLSOUND</font>
00750
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|