Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 5200442

Browse files
committed
Fixed copyof MOs that change the PresetName not having scripts loaded onto them.
Added sanity checking and percentage handling (i.e. >1 - 100) to volumeOverrideIfNotMuted. Also fixed some music related saftey checks I'd screwed up the boolean logic for.
1 parent a0a2a5e commit 5200442

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Entities/MovableObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ ENTITYALLOCATION(MovableObject)
307307
virtual const Entity::ClassInfo & GetClass() const { return m_sClass; }
308308

309309
/// <summary>
310-
/// Override SetPresetName so it also resets script paths and script preset name. Note that this'll screw up lua that calls SetPresetName but that probably shouldn't be lua accessible anyway.
310+
/// Override SetPresetName so it also resets script preset name and then reloads scripts to safely allow for multiple scripts.
311311
/// </summary>
312312
/// <param name="newName">A string reference with the instance name of this Entity.</param>
313-
virtual void SetPresetName(const std::string &newName) override { Entity::SetPresetName(newName); m_ScriptPresetName.clear(); }
313+
virtual void SetPresetName(const std::string &newName) override { Entity::SetPresetName(newName); m_ScriptPresetName.clear(); ReloadScripts(); }
314314

315315

316316
//////////////////////////////////////////////////////////////////////////////////////////

Managers/AudioMan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ namespace RTE {
185185
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
186186

187187
double AudioMan::GetMusicPosition() const {
188-
if (m_AudioEnabled || IsMusicPlaying()) {
188+
if (m_AudioEnabled && IsMusicPlaying()) {
189189
FMOD_RESULT result;
190190
FMOD::Channel *musicChannel;
191191
unsigned int position;
@@ -202,7 +202,7 @@ namespace RTE {
202202
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203203

204204
void AudioMan::SetMusicPosition(double position) {
205-
if (m_AudioEnabled || IsMusicPlaying()) {
205+
if (m_AudioEnabled && IsMusicPlaying()) {
206206
FMOD::Channel *musicChannel;
207207
FMOD_RESULT result = m_MusicChannelGroup->getChannel(0, &musicChannel);
208208

@@ -307,6 +307,7 @@ namespace RTE {
307307
result = musicChannel->setPriority(PRIORITY_HIGH);
308308

309309
if (volumeOverrideIfNotMuted >= 0 && m_MusicVolume > 0) {
310+
volumeOverrideIfNotMuted = Limit((volumeOverrideIfNotMuted > 1 ? volumeOverrideIfNotMuted / 100 : volumeOverrideIfNotMuted), 1, 0);
310311
result = musicChannel->setVolume(volumeOverrideIfNotMuted);
311312
if (result != FMOD_OK && (loops != 0 && loops != 1)) {
312313
g_ConsoleMan.PrintString("ERROR: Failed to set volume override for music file: " + std::string(filePath) + ". This means it will stay at " + std::to_string(m_MusicVolume) + ": " + std::string(FMOD_ErrorString(result)));
@@ -477,7 +478,6 @@ namespace RTE {
477478
}
478479
}
479480

480-
481481
// Now that the sound is playing we can register an event with the SoundContainer's channels, which can be used by clients to identify the sound being played.
482482
if (m_IsInMultiplayerMode) {
483483
RegisterSoundEvent(player, SOUND_PLAY, soundContainer->GetPlayingChannels(), &soundContainer->GetSelectedSoundHashes(), position, soundContainer->GetLoopSetting(), pitch, soundContainer->IsAffectedByGlobalPitch(), soundContainer->GetAttenuationStartDistance(), soundContainer->IsImmobile());

0 commit comments

Comments
 (0)