forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAudioEventRTS.cpp
More file actions
851 lines (742 loc) · 25.3 KB
/
AudioEventRTS.cpp
File metadata and controls
851 lines (742 loc) · 25.3 KB
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
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: AudioEventRTS.cpp
/*---------------------------------------------------------------------------*/
/* EA Pacific */
/* Confidential Information */
/* Copyright (C) 2001 - All Rights Reserved */
/* DO NOT DISTRIBUTE */
/*---------------------------------------------------------------------------*/
/* Project: RTS3 */
/* File name: AudioEventRTS.cpp */
/* Created: John K. McDonald, Jr., 3/21/2002 */
/* Desc: AudioEventRTS constructors and assignment operator, etc. */
/* Revision History: */
/* 3/21/2002 : Initial creation */
/*---------------------------------------------------------------------------*/
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/AudioEventRTS.h"
#include "Common/AudioEventInfo.h"
#include "Common/AudioRandomValue.h"
#include "Common/AudioSettings.h"
#include "Common/file.h"
#include "Common/FileSystem.h"
#include "Common/GameSounds.h"
#include "Common/GlobalData.h"
#include "Common/Player.h"
#include "Common/Registry.h"
#include "GameLogic/GameLogic.h" // For getObjectByID
#include "GameLogic/LogicRandomValue.h"
#include "GameLogic/Object.h"
#include "GameClient/Drawable.h" // For getPosition
#include "GameClient/GameClient.h" // For getDrawableByID
#include "Common/ScopedMutex.h" // For ScopedMutex
//-------------------------------------------------------------------------------------------------
AudioEventRTS::AudioEventRTS()
: m_eventName(AsciiString::TheEmptyString),
m_priority(AP_NORMAL),
m_volume(-1.0),
m_timeOfDay(TIME_OF_DAY_AFTERNOON),
m_ownerType(OT_INVALID),
m_shouldFade(false),
m_isLogicalAudio(false),
m_filenameToLoad(AsciiString::TheEmptyString),
m_eventInfo(nullptr),
m_playingHandle(0),
m_killThisHandle(0),
m_pitchShift(1.0),
m_volumeShift(0.0),
m_loopCount(1),
m_playingAudioIndex(-1),
m_allCount(0),
m_playerIndex(-1),
m_delay(0.0f),
m_uninterruptible(FALSE)
{
m_attackName.clear();
m_decayName.clear();
m_positionOfAudio.zero();
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS::AudioEventRTS( const AsciiString& eventName )
: m_eventName(eventName),
m_priority(AP_NORMAL),
m_volume(-1.0),
m_timeOfDay(TIME_OF_DAY_AFTERNOON),
m_ownerType(OT_INVALID),
m_shouldFade(false),
m_isLogicalAudio(false),
m_filenameToLoad(AsciiString::TheEmptyString),
m_eventInfo(nullptr),
m_playingHandle(0),
m_killThisHandle(0),
m_pitchShift(1.0),
m_volumeShift(0.0),
m_loopCount(1),
m_playingAudioIndex(-1),
m_allCount(0),
m_playerIndex(-1),
m_delay(0.0f),
m_uninterruptible(FALSE)
{
m_attackName.clear();
m_decayName.clear();
m_positionOfAudio.zero();
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS::AudioEventRTS( const AsciiString& eventName, ObjectID ownerID )
: m_eventName(eventName),
m_priority(AP_NORMAL),
m_volume(-1.0),
m_timeOfDay(TIME_OF_DAY_AFTERNOON),
m_objectID(ownerID),
m_ownerType(OT_INVALID),
m_shouldFade(false),
m_isLogicalAudio(false),
m_filenameToLoad(AsciiString::TheEmptyString),
m_eventInfo(nullptr),
m_playingHandle(0),
m_killThisHandle(0),
m_pitchShift(1.0),
m_volumeShift(0.0),
m_loopCount(1),
m_playingAudioIndex(-1),
m_allCount(0),
m_playerIndex(-1),
m_delay(0.0f),
m_uninterruptible(FALSE)
{
m_attackName.clear();
m_decayName.clear();
if( m_objectID )
{
m_ownerType = OT_Object;
}
else
{
m_objectID = INVALID_ID;
}
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS::AudioEventRTS( const AsciiString& eventName, DrawableID drawableID )
: m_eventName(eventName),
m_priority(AP_NORMAL),
m_volume(-1.0),
m_timeOfDay(TIME_OF_DAY_AFTERNOON),
m_drawableID(drawableID),
m_ownerType(OT_INVALID),
m_shouldFade(false),
m_isLogicalAudio(false),
m_filenameToLoad(AsciiString::TheEmptyString),
m_eventInfo(nullptr),
m_playingHandle(0),
m_killThisHandle(0),
m_pitchShift(1.0),
m_volumeShift(0.0),
m_loopCount(1),
m_playingAudioIndex(-1),
m_allCount(0),
m_playerIndex(-1),
m_delay(0.0f),
m_uninterruptible(FALSE)
{
m_attackName.clear();
m_decayName.clear();
if( m_drawableID )
{
m_ownerType = OT_Drawable;
}
else
{
m_drawableID = INVALID_DRAWABLE_ID;
}
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS::AudioEventRTS( const AsciiString& eventName, const Coord3D *positionOfAudio )
: m_eventName(eventName),
m_priority(AP_NORMAL),
m_volume(-1.0),
m_timeOfDay(TIME_OF_DAY_AFTERNOON),
m_ownerType(OT_Positional),
m_shouldFade(false),
m_isLogicalAudio(false),
m_filenameToLoad(AsciiString::TheEmptyString),
m_eventInfo(nullptr),
m_playingHandle(0),
m_killThisHandle(0),
m_pitchShift(1.0),
m_volumeShift(0.0),
m_loopCount(1),
m_playingAudioIndex(-1),
m_allCount(0),
m_playerIndex(-1),
m_delay(0.0f),
m_uninterruptible(FALSE)
{
m_positionOfAudio.set( positionOfAudio );
m_attackName.clear();
m_decayName.clear();
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS::AudioEventRTS( const AudioEventRTS& right )
{
m_filenameToLoad = right.m_filenameToLoad;
m_eventInfo = right.m_eventInfo;
m_playingHandle = right.m_playingHandle;
m_killThisHandle = right.m_killThisHandle;
m_eventName = right.m_eventName;
m_priority = right.m_priority;
m_volume = right.m_volume;
m_timeOfDay = right.m_timeOfDay;
m_ownerType = right.m_ownerType;
m_shouldFade = right.m_shouldFade;
m_isLogicalAudio = right.m_isLogicalAudio;
m_pitchShift = right.m_pitchShift;
m_volumeShift = right.m_volumeShift;
m_loopCount = right.m_loopCount;
m_playingAudioIndex = right.m_playingAudioIndex;
m_allCount = right.m_allCount;
m_playerIndex = right.m_playerIndex;
m_delay = right.m_delay;
m_attackName = right.m_attackName;
m_decayName = right.m_decayName;
m_portionToPlayNext = right.m_portionToPlayNext;
m_uninterruptible = right.m_uninterruptible;
if( m_ownerType == OT_Positional || m_ownerType == OT_Dead )
{
m_positionOfAudio.set( &right.m_positionOfAudio );
}
else if( m_ownerType == OT_Drawable )
{
m_drawableID = right.m_drawableID;
}
else if( m_ownerType == OT_Object )
{
m_objectID = right.m_objectID;
}
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS& AudioEventRTS::operator=( const AudioEventRTS& right )
{
m_filenameToLoad = right.m_filenameToLoad;
m_eventInfo = right.m_eventInfo;
m_playingHandle = right.m_playingHandle;
m_killThisHandle = right.m_killThisHandle;
m_eventName = right.m_eventName;
m_priority = right.m_priority;
m_volume = right.m_volume;
m_timeOfDay = right.m_timeOfDay;
m_ownerType = right.m_ownerType;
m_shouldFade = right.m_shouldFade;
m_isLogicalAudio = right.m_isLogicalAudio;
m_pitchShift = right.m_pitchShift;
m_volumeShift = right.m_volumeShift;
m_loopCount = right.m_loopCount;
m_playingAudioIndex = right.m_playingAudioIndex;
m_allCount = right.m_allCount;
m_playerIndex = right.m_playerIndex;
m_delay = right.m_delay;
m_attackName = right.m_attackName;
m_decayName = right.m_decayName;
m_portionToPlayNext = right.m_portionToPlayNext;
m_uninterruptible = right.m_uninterruptible;
if( m_ownerType == OT_Positional || m_ownerType == OT_Dead )
{
m_positionOfAudio.set( &right.m_positionOfAudio );
}
else if( m_ownerType == OT_Drawable )
{
m_drawableID = right.m_drawableID;
}
else if( m_ownerType == OT_Object )
{
m_objectID = right.m_objectID;
}
return *this;
}
//-------------------------------------------------------------------------------------------------
AudioEventRTS::~AudioEventRTS()
{
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setEventName( AsciiString name )
{
if ((name != m_eventName) && m_eventInfo != nullptr) {
// Clear out the audio event info, cause its not valid for the new event.
m_eventInfo = nullptr;
}
m_eventName = name;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::generateFilename()
{
// A Logic Random Value is used because we may ask "How long will it take to play this sound?"
// In that case, we need the same answer across all pcs.
if (!m_eventInfo) {
return;
}
m_filenameToLoad = generateFilenamePrefix(m_eventInfo->m_soundType, false);
Int which = 0;
if (m_eventInfo->m_soundType == AT_Music || m_eventInfo->m_soundType == AT_Streaming) {
m_filenameToLoad.concat(m_eventInfo->m_filename);
adjustForLocalization(m_filenameToLoad);
return;
} else {
if (m_eventInfo->m_sounds.empty()) {
m_filenameToLoad = AsciiString::TheEmptyString;
return;
}
if (BitIsSet(m_eventInfo->m_control, AC_RANDOM))
{
if (m_isLogicalAudio)
{
which = GameLogicRandomValueUnchanged(0, m_eventInfo->m_sounds.size() - 1);
}
else
{
which = GameAudioRandomValue(0, m_eventInfo->m_sounds.size() - 1);
}
if (which == m_playingAudioIndex && m_eventInfo->m_sounds.size() > 2)
which = ( which + 1 ) % m_eventInfo->m_sounds.size();
m_playingAudioIndex = which;//caching random choice to compare next call
}
else
which = (++m_playingAudioIndex) % m_eventInfo->m_sounds.size();
}
m_filenameToLoad.concat(m_eventInfo->m_sounds[which]);
m_filenameToLoad.concat(generateFilenameExtension(m_eventInfo->m_soundType));
adjustForLocalization(m_filenameToLoad);
// Note: Also generate Delay when generating a filename, cause
// we want delay to apply between every loop of a sound.
m_delay = GameAudioRandomValueReal(m_eventInfo->m_delayMin, m_eventInfo->m_delayMax);
}
//-------------------------------------------------------------------------------------------------
AsciiString AudioEventRTS::getFilename()
{
return m_filenameToLoad;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::generatePlayInfo()
{
m_pitchShift = GameAudioRandomValueReal(m_eventInfo->m_pitchShiftMin, m_eventInfo->m_pitchShiftMax);
m_volumeShift = GameAudioRandomValueReal(1.0f + m_eventInfo->m_volumeShift, 1.0f); // volume shifts are between 0 and 1
m_loopCount = m_eventInfo->m_loopCount;
m_portionToPlayNext = PP_Attack;
Int attackSize = m_eventInfo->m_attackSounds.size();
if (attackSize > 0) {
m_attackName = generateFilenamePrefix(m_eventInfo->m_soundType, false);
// needs to be logic because it needs to be the same on all systems.
Int attackToPlay;
if (m_isLogicalAudio) {
attackToPlay = GameLogicRandomValueUnchanged(0, attackSize - 1);
} else {
attackToPlay = GameAudioRandomValue(0, attackSize - 1);
}
m_attackName.concat(m_eventInfo->m_attackSounds[attackToPlay]);
m_attackName.concat(generateFilenameExtension(m_eventInfo->m_soundType));
adjustForLocalization(m_attackName);
} else {
m_portionToPlayNext = PP_Sound;
}
Int decaySize = m_eventInfo->m_decaySounds.size();
if (decaySize > 0) {
m_decayName = generateFilenamePrefix(m_eventInfo->m_soundType, false);
// needs to be logic because it needs to be the same on all systems.
Int decayToPlay;
if (m_isLogicalAudio) {
decayToPlay = GameLogicRandomValueUnchanged(0, decaySize - 1);
} else {
decayToPlay = GameAudioRandomValue(0, decaySize - 1);
}
m_decayName.concat(m_eventInfo->m_decaySounds[decayToPlay]);
m_decayName.concat(generateFilenameExtension(m_eventInfo->m_soundType));
adjustForLocalization(m_decayName);
}
m_isLogicalAudio = FALSE;
}
//-------------------------------------------------------------------------------------------------
Real AudioEventRTS::getPitchShift() const
{
return m_pitchShift;
}
//-------------------------------------------------------------------------------------------------
Real AudioEventRTS::getVolumeShift() const
{
return m_volumeShift;
}
//-------------------------------------------------------------------------------------------------
AsciiString AudioEventRTS::getAttackFilename() const
{
return m_attackName;
}
//-------------------------------------------------------------------------------------------------
AsciiString AudioEventRTS::getDecayFilename() const
{
return m_decayName;
}
//-------------------------------------------------------------------------------------------------
Real AudioEventRTS::getDelay() const
{
return m_delay;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::decrementDelay( Real timeToDecrement )
{
m_delay -= timeToDecrement;
}
//-------------------------------------------------------------------------------------------------
PortionToPlay AudioEventRTS::getNextPlayPortion() const
{
return m_portionToPlayNext;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::advanceNextPlayPortion()
{
switch (m_portionToPlayNext)
{
case PP_Attack:
m_portionToPlayNext = PP_Sound;
break;
case PP_Sound:
if (m_eventInfo && BitIsSet(m_eventInfo->m_control, AC_ALL))
{
if (m_allCount == m_eventInfo->m_sounds.size()) {
m_portionToPlayNext = PP_Decay;
}
// Advance the all count so that we move to the next sound.
++m_allCount;
}
if (!m_decayName.isEmpty()) {
m_portionToPlayNext = PP_Decay;
} else {
m_portionToPlayNext = PP_Done;
}
break;
case PP_Decay:
m_portionToPlayNext = PP_Done;
break;
}
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setNextPlayPortion( PortionToPlay ptp )
{
m_portionToPlayNext = ptp;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::decreaseLoopCount()
{
if (m_loopCount == 1) {
m_loopCount = -1;
} else if (m_loopCount > 1) {
--m_loopCount;
}
}
//-------------------------------------------------------------------------------------------------
Bool AudioEventRTS::hasMoreLoops() const
{
return (m_loopCount >= 0);
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setAudioEventInfo( const AudioEventInfo *eventInfo ) const
{
m_eventInfo = eventInfo;
}
//-------------------------------------------------------------------------------------------------
const AudioEventInfo *AudioEventRTS::getAudioEventInfo() const
{
if (m_eventInfo) {
if (m_eventInfo->m_audioName == m_eventName) {
return m_eventInfo;
} else {
m_eventInfo = nullptr;
}
}
return m_eventInfo;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setPlayingHandle( AudioHandle handle )
{
m_playingHandle = handle;
}
//-------------------------------------------------------------------------------------------------
AudioHandle AudioEventRTS::getPlayingHandle()
{
return m_playingHandle;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setPosition( const Coord3D *pos )
{
if (!pos) {
return;
}
if (!(m_ownerType == OT_Positional || m_ownerType == OT_INVALID)) {
return;
}
m_positionOfAudio = *pos;
m_ownerType = OT_Positional;
}
//-------------------------------------------------------------------------------------------------
const Coord3D* AudioEventRTS::getPosition()
{
if( m_ownerType != OT_INVALID )
{
return &m_positionOfAudio;
}
return nullptr;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setObjectID( ObjectID objID )
{
if (!(m_ownerType == OT_Object || m_ownerType == OT_INVALID)) {
return;
}
m_objectID = objID;
m_ownerType = OT_Object;
}
//-------------------------------------------------------------------------------------------------
ObjectID AudioEventRTS::getObjectID()
{
if (m_ownerType == OT_Object) {
return m_objectID;
}
return INVALID_ID;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setDrawableID( DrawableID drawID )
{
if (!(m_ownerType == OT_Drawable || m_ownerType == OT_INVALID)) {
return;
}
m_drawableID = drawID;
m_ownerType = OT_Drawable;
}
//-------------------------------------------------------------------------------------------------
DrawableID AudioEventRTS::getDrawableID()
{
if (m_ownerType == OT_Drawable) {
return m_drawableID;
}
return INVALID_DRAWABLE_ID;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setTimeOfDay( TimeOfDay tod )
{
m_timeOfDay = tod;
}
//-------------------------------------------------------------------------------------------------
TimeOfDay AudioEventRTS::getTimeOfDay() const
{
return m_timeOfDay;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setHandleToKill( AudioHandle handleToKill )
{
m_killThisHandle = handleToKill;
}
//-------------------------------------------------------------------------------------------------
AudioHandle AudioEventRTS::getHandleToKill() const
{
return m_killThisHandle;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setShouldFade( Bool shouldFade )
{
m_shouldFade = shouldFade;
}
//-------------------------------------------------------------------------------------------------
Bool AudioEventRTS::getShouldFade() const
{
return m_shouldFade;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setIsLogicalAudio( Bool isLogicalAudio )
{
m_isLogicalAudio = isLogicalAudio;
}
//-------------------------------------------------------------------------------------------------
Bool AudioEventRTS::getIsLogicalAudio() const
{
return m_isLogicalAudio;
}
//-------------------------------------------------------------------------------------------------
Bool AudioEventRTS::isPositionalAudio() const
{
if( m_eventInfo )
{
if( !BitIsSet( m_eventInfo->m_type, ST_WORLD ) )
{
return FALSE;
}
}
if( m_ownerType != OT_INVALID )
{
if( m_drawableID != INVALID_DRAWABLE_ID || m_objectID != INVALID_ID || m_ownerType == OT_Positional )
{
return TRUE;
}
}
return FALSE;
}
//-------------------------------------------------------------------------------------------------
Bool AudioEventRTS::isCurrentlyPlaying() const
{
return TheAudio->isCurrentlyPlaying(m_playingHandle);
}
//-------------------------------------------------------------------------------------------------
AudioPriority AudioEventRTS::getAudioPriority() const
{
return m_priority;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setAudioPriority( AudioPriority newPriority )
{
m_priority = newPriority;
}
//-------------------------------------------------------------------------------------------------
Real AudioEventRTS::getVolume() const
{
if (m_volume == -1.0f) {
if (m_eventInfo) {
return m_eventInfo->m_volume;
}
return 0.5;
}
return m_volume;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setVolume( Real vol )
{
m_volume = vol;
}
//-------------------------------------------------------------------------------------------------
const Coord3D *AudioEventRTS::getCurrentPosition()
{
switch (m_ownerType)
{
case OT_Positional:
return &m_positionOfAudio;
case OT_Object:
if (Object *obj = TheGameLogic->findObjectByID(m_objectID))
{
m_positionOfAudio.set( obj->getPosition() );
}
else
{
m_ownerType = OT_Dead;
}
return &m_positionOfAudio;
case OT_Drawable:
{
// Hold the drawable lookup mutex for the duration of the find-and-read to prevent
// the main thread from destroying the drawable (and freeing its memory) between
// findDrawableByID() returning a non-null pointer and getPosition() being called.
// This function can be invoked from the Miles audio background thread via
// notifyOfAudioCompletion(), so the mutex is needed to close this race window.
ScopedMutex mut(TheGameClient->getDrawableLookupMutex());
if (Drawable *draw = TheGameClient->findDrawableByID(m_drawableID))
{
m_positionOfAudio.set( draw->getPosition() );
}
else
{
m_ownerType = OT_Dead;
}
}
return &m_positionOfAudio;
case OT_Dead:
return &m_positionOfAudio;
}
return nullptr;
}
//-------------------------------------------------------------------------------------------------
AsciiString AudioEventRTS::generateFilenamePrefix( AudioType audioTypeToPlay, Bool localized )
{
AsciiString retStr;
retStr = TheAudio->getAudioSettings()->m_audioRoot;
retStr.concat("\\");
if (audioTypeToPlay == AT_Music) {
retStr.concat(TheAudio->getAudioSettings()->m_musicFolder);
} else if (audioTypeToPlay == AT_Streaming) {
retStr.concat(TheAudio->getAudioSettings()->m_streamingFolder);
} else {
retStr.concat(TheAudio->getAudioSettings()->m_soundsFolder);
}
retStr.concat("\\");
if (localized) {
retStr.concat(GetRegistryLanguage());
retStr.concat("\\");
}
return retStr;
}
//-------------------------------------------------------------------------------------------------
AsciiString AudioEventRTS::generateFilenameExtension( AudioType audioTypeToPlay )
{
AsciiString retStr = AsciiString::TheEmptyString;
if (audioTypeToPlay != AT_Music) {
retStr = ".";
retStr.concat(TheAudio->getAudioSettings()->m_soundsExtension);
}
return retStr;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::adjustForLocalization(AsciiString &strToAdjust)
{
const char *filename = strToAdjust.reverseFind('\\');
if (filename) {
filename += 1;
} else {
filename = strToAdjust.str();
}
// try the localized version first so that we're guaranteed to get it
// even if the generic data directory holds a version of the file
AsciiString localizedFilePath = generateFilenamePrefix(m_eventInfo->m_soundType, TRUE);
localizedFilePath.concat(filename);
if (TheFileSystem->doesFileExist(localizedFilePath.str())) {
strToAdjust = localizedFilePath;
}
// else there was no localized version, so leave the path we received unchanged
}
//-------------------------------------------------------------------------------------------------
Int AudioEventRTS::getPlayerIndex() const
{
if (m_ownerType == OT_Object) {
Object *obj = TheGameLogic->findObjectByID(m_objectID);
if (obj) {
return obj->getControllingPlayer()->getPlayerIndex();
}
} else if (m_ownerType == OT_Drawable) {
Drawable *draw = TheGameClient->findDrawableByID(m_drawableID);
if (draw) {
Object *obj = draw->getObject();
if (obj) {
return obj->getControllingPlayer()->getPlayerIndex();
}
}
}
return m_playerIndex;
}
//-------------------------------------------------------------------------------------------------
void AudioEventRTS::setPlayerIndex( Int playerNdx )
{
m_playerIndex = playerNdx;
}