@@ -136,7 +136,7 @@ namespace RTE {
136
136
if (!m_AudioEnabled) {
137
137
return ;
138
138
}
139
- if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_GLOBAL_PITCH, nullptr , nullptr , Vector (), 0 , 0 . 0F , pitch ); }
139
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_GLOBAL_PITCH, nullptr ); }
140
140
141
141
m_GlobalPitch = std::clamp (pitch, 0 .125F , 8 .0F );
142
142
if (includeMusic) { m_MusicChannelGroup->setPitch (m_GlobalPitch); }
@@ -350,7 +350,7 @@ namespace RTE {
350
350
if (!m_AudioEnabled || !soundContainer) {
351
351
return false ;
352
352
}
353
- if (m_IsInMultiplayerMode) { RegisterSoundEvent (player, SOUND_STOP, soundContainer-> GetPlayingChannels () ); }
353
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (player, SOUND_STOP, soundContainer); }
354
354
355
355
FMOD_RESULT result;
356
356
FMOD::Channel *soundChannel;
@@ -374,7 +374,7 @@ namespace RTE {
374
374
if (!m_AudioEnabled || !soundContainer || !soundContainer->IsBeingPlayed ()) {
375
375
return ;
376
376
}
377
- if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_FADE_OUT, soundContainer-> GetPlayingChannels (), &soundContainer-> GetSelectedSoundHashes (), Vector (), 0 , 0 , 0 , false , 0 , false , fadeOutTime); }
377
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_FADE_OUT, soundContainer, fadeOutTime); }
378
378
379
379
int sampleRate;
380
380
m_AudioSystem->getSoftwareFormat (&sampleRate, nullptr , nullptr );
@@ -413,13 +413,13 @@ namespace RTE {
413
413
414
414
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
415
415
416
- void AudioMan::RegisterMusicEvent (int player, NetworkMusicState state, const char *filepath, int loops , float position, float pitch) {
416
+ void AudioMan::RegisterMusicEvent (int player, NetworkMusicState state, const char *filepath, int loopsOrSilence , float position, float pitch) {
417
417
if (player == -1 ) {
418
- for (int i = 0 ; i < c_MaxClients; i++) { RegisterMusicEvent (i, state, filepath, loops , position, pitch); }
418
+ for (int i = 0 ; i < c_MaxClients; i++) { RegisterMusicEvent (i, state, filepath, loopsOrSilence , position, pitch); }
419
419
} else {
420
420
NetworkMusicData musicData;
421
421
musicData.State = state;
422
- musicData.Loops = loops ;
422
+ musicData.LoopsOrSilence = loopsOrSilence ;
423
423
musicData.Pitch = pitch;
424
424
musicData.Position = position;
425
425
if (filepath) {
@@ -440,43 +440,65 @@ namespace RTE {
440
440
return ;
441
441
}
442
442
list.clear ();
443
- g_SoundEventsListMutex[player].lock ();
444
443
445
- for (const NetworkSoundData &soundEvent : m_SoundEvents[player]) { list.push_back (soundEvent); }
446
- m_SoundEvents[player].clear ();
444
+ g_SoundEventsListMutex[player].lock ();
445
+ const NetworkSoundData *lastSetGlobalPitchEvent = nullptr ;
446
+ for (const NetworkSoundData &soundEvent : m_SoundEvents[player]) {
447
+ if (soundEvent.State == SOUND_SET_GLOBAL_PITCH) {
448
+ lastSetGlobalPitchEvent = &soundEvent;
449
+ } else {
450
+ list.push_back (soundEvent);
451
+ }
452
+ }
453
+ if (lastSetGlobalPitchEvent) { list.push_back (*lastSetGlobalPitchEvent); }
447
454
g_SoundEventsListMutex[player].unlock ();
448
455
}
449
456
450
457
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
451
458
452
- void AudioMan::RegisterSoundEvent (int player, NetworkSoundState state, const std::unordered_set< int > *channels, const std::vector< size_t > *soundFileHashes, const Vector &position, int loops, float volume, float pitch, bool affectedByGlobalPitch, float attenuationStartDistance, bool immobile, int fadeOutTime ) {
459
+ void AudioMan::RegisterSoundEvent (int player, NetworkSoundState state, const SoundContainer *soundContainer, int fadeoutTime ) {
453
460
if (player == -1 ) {
454
- for (int i = 0 ; i < c_MaxClients; i++) { RegisterSoundEvent (i, state, channels, soundFileHashes, position, loops, volume, pitch, affectedByGlobalPitch, attenuationStartDistance, immobile, fadeOutTime ); }
461
+ for (int i = 0 ; i < c_MaxClients; i++) { RegisterSoundEvent (i, state, soundContainer, fadeoutTime ); }
455
462
} else {
456
- if (player >= 0 && player < c_MaxClients) {
463
+ FMOD_RESULT result = FMOD_OK;
464
+ std::vector<NetworkSoundData> soundDataVector;
465
+
466
+ if (state == SOUND_SET_GLOBAL_PITCH) {
457
467
NetworkSoundData soundData;
458
468
soundData.State = state;
459
-
460
- std::fill_n (soundData.Channels , c_MaxPlayingSoundsPerContainer, c_MaxVirtualChannels + 1 );
461
- if (channels) { std::copy (channels->begin (), channels->end (), soundData.Channels ); }
462
-
463
- std::fill_n (soundData.SoundFileHashes , c_MaxPlayingSoundsPerContainer, 0 );
464
- if (soundFileHashes) { std::copy (soundFileHashes->begin (), soundFileHashes->end (), soundData.SoundFileHashes ); }
465
-
466
- soundData.Position [0 ] = position.m_X ;
467
- soundData.Position [1 ] = position.m_Y ;
468
- soundData.Loops = loops;
469
- soundData.Volume = volume;
470
- soundData.Pitch = pitch;
471
- soundData.AffectedByGlobalPitch = affectedByGlobalPitch;
472
- soundData.AttenuationStartDistance = attenuationStartDistance;
473
- soundData.Immobile = immobile;
474
- soundData.FadeOutTime = fadeOutTime;
475
-
476
- g_SoundEventsListMutex[player].lock ();
477
- m_SoundEvents[player].push_back (soundData);
478
- g_SoundEventsListMutex[player].unlock ();
469
+ soundData.Pitch = m_GlobalPitch;
470
+ soundDataVector.push_back (soundData);
471
+ } else {
472
+ for (int playingChannel : *soundContainer->GetPlayingChannels ()) {
473
+ FMOD::Channel *soundChannel;
474
+ result = m_AudioSystem->getChannel (playingChannel, &soundChannel);
475
+ FMOD::Sound *sound;
476
+ result = (result == FMOD_OK) ? soundChannel->getCurrentSound (&sound) : result;
477
+
478
+ if (result != FMOD_OK) {
479
+ continue ;
480
+ }
481
+ NetworkSoundData soundData;
482
+ soundData.State = state;
483
+ soundData.SoundFileHash = soundContainer->GetSoundDataForSound (sound)->SoundFile .GetHash ();
484
+ soundData.Channel = playingChannel;
485
+ soundData.Immobile = soundContainer->IsImmobile ();
486
+ soundData.AttenuationStartDistance = soundContainer->GetAttenuationStartDistance ();
487
+ soundData.Loops = soundContainer->GetLoopSetting ();
488
+ soundData.Priority = soundContainer->GetPriority ();
489
+ soundData.AffectedByGlobalPitch = soundContainer->IsAffectedByGlobalPitch ();
490
+ soundData.Position [0 ] = soundContainer->GetPosition ().m_X ;
491
+ soundData.Position [1 ] = soundContainer->GetPosition ().m_Y ;
492
+ soundData.Volume = soundContainer->GetVolume ();
493
+ soundData.Pitch = soundContainer->GetPitch ();
494
+ soundData.FadeOutTime = fadeoutTime;
495
+ soundDataVector.push_back (soundData);
496
+ }
479
497
}
498
+
499
+ g_SoundEventsListMutex[player].lock ();
500
+ m_SoundEvents[player].insert (m_SoundEvents[player].end (), soundDataVector.begin (), soundDataVector.end ());
501
+ g_SoundEventsListMutex[player].unlock ();
480
502
}
481
503
}
482
504
@@ -534,9 +556,7 @@ namespace RTE {
534
556
soundContainer->AddPlayingChannel (channelIndex);
535
557
}
536
558
537
- if (m_IsInMultiplayerMode) {
538
- RegisterSoundEvent (player, SOUND_PLAY, soundContainer->GetPlayingChannels (), &soundContainer->GetSelectedSoundHashes (), soundContainer->GetPosition (), soundContainer->GetLoopSetting (), soundContainer->GetVolume (), soundContainer->GetPitch (), soundContainer->IsAffectedByGlobalPitch (), soundContainer->GetAttenuationStartDistance (), soundContainer->IsImmobile ());
539
- }
559
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (player, SOUND_PLAY, soundContainer); }
540
560
return true ;
541
561
}
542
562
@@ -546,7 +566,7 @@ namespace RTE {
546
566
if (!m_AudioEnabled || !soundContainer) {
547
567
return false ;
548
568
}
549
- if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_POSITION, soundContainer-> GetPlayingChannels (), &soundContainer-> GetSelectedSoundHashes (), soundContainer-> GetPosition () ); }
569
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_POSITION, soundContainer); }
550
570
551
571
FMOD_RESULT result = FMOD_OK;
552
572
FMOD::Channel *soundChannel;
@@ -573,7 +593,7 @@ namespace RTE {
573
593
if (!m_AudioEnabled || !soundContainer || !soundContainer->IsBeingPlayed ()) {
574
594
return false ;
575
595
}
576
- if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_VOLUME, soundContainer-> GetPlayingChannels (), &soundContainer-> GetSelectedSoundHashes (), Vector (), 0 , soundContainer-> GetVolume () ); }
596
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_VOLUME, soundContainer); }
577
597
578
598
FMOD_RESULT result = FMOD_OK;
579
599
FMOD::Channel *soundChannel;
@@ -605,7 +625,7 @@ namespace RTE {
605
625
if (!m_AudioEnabled || !soundContainer || !soundContainer->IsBeingPlayed ()) {
606
626
return false ;
607
627
}
608
- if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_PITCH, soundContainer-> GetPlayingChannels (), &soundContainer-> GetSelectedSoundHashes (), Vector (), 0 , 0 . 0F , soundContainer-> GetPitch () ); }
628
+ if (m_IsInMultiplayerMode) { RegisterSoundEvent (-1 , SOUND_SET_PITCH, soundContainer); }
609
629
610
630
FMOD_RESULT result = FMOD_OK;
611
631
FMOD::Channel *soundChannel;
0 commit comments