Skip to content

Commit

Permalink
🎮 Remove dopplerfactor console command
Browse files Browse the repository at this point in the history
The console command was largely redundant to working with the audio_doppler_factor CVar. Instead of the previous way of triggering updates of the doppler factor via the message queue, the doppler factor is now updated each frame from the audio_doppler_factor CVar.
  • Loading branch information
Hiradur committed Nov 24, 2024
1 parent 135303f commit f9e26fc
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 98 deletions.
2 changes: 0 additions & 2 deletions doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,6 @@ enum MsgType
MSG_EDI_RELOAD_BUNDLE_REQUESTED, //!< This deletes all actors using that bundle (= ZIP or directory)! Params: 'cache_entry' (CacheEntryClass@)
MSG_EDI_UNLOAD_BUNDLE_REQUESTED, //!< This deletes all actors using that bundle (= ZIP or directory)! Params: 'cache_entry' (CacheEntryClass@)
MSG_EDI_CREATE_PROJECT_REQUESTED, //!< Creates a subdir under 'projects/', pre-populates it and adds to modcache. Params: 'name' (string), 'ext' (string, optional), 'source_entry' (CacheEntryClass@)
// Audio
MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED //!< Request change of doppler factor. Params: 'doppler_factor' (float). doppler_factor must not be negative.NAL
};

} // namespace Script2Game
Expand Down
2 changes: 0 additions & 2 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,6 @@ const char* MsgTypeToString(MsgType type)
case MSG_EDI_MODIFY_PROJECT_REQUESTED : return "MSG_EDI_MODIFY_PROJECT_REQUESTED";
case MSG_EDI_DELETE_PROJECT_REQUESTED : return "MSG_EDI_DELETE_PROJECT_REQUESTED";

case MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED : return "MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED";

default: return "";
}
}
Expand Down
2 changes: 0 additions & 2 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ enum MsgType
MSG_EDI_CREATE_PROJECT_REQUESTED, //!< Payload = RoR::CreateProjectRequest* (owner)
MSG_EDI_MODIFY_PROJECT_REQUESTED, //!< Payload = RoR::UpdateProjectRequest* (owner)
MSG_EDI_DELETE_PROJECT_REQUESTED, //!< Payload = RoR::CacheEntryPtr* (owner)
// Audio
MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED, //!< Payload = float*
};

const char* MsgTypeToString(MsgType type);
Expand Down
2 changes: 2 additions & 0 deletions source/main/audio/SoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ void SoundManager::Update(const float dt_sec)
if (!audio_device)
return;

this->SetDopplerFactor(App::audio_doppler_factor->getFloat());

recomputeAllSources();
UpdateAlListener();

Expand Down
7 changes: 0 additions & 7 deletions source/main/audio/SoundScriptManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,6 @@ const EFXEAXREVERBPROPERTIES* SoundScriptManager::GetReverbPresetAt(const Ogre::
}
}

void SoundScriptManager::SetDopplerFactor(float doppler_factor)
{
if (disabled)
return;
sound_manager->SetDopplerFactor(doppler_factor);
}

const StringVector& SoundScriptManager::getScriptPatterns(void) const
{
return script_patterns;
Expand Down
1 change: 0 additions & 1 deletion source/main/audio/SoundScriptManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ class SoundScriptManager : public Ogre::ScriptLoader

void setEnabled(bool state);

void SetDopplerFactor(float doppler_factor);
void SetListener(Ogre::Vector3 position, Ogre::Vector3 direction, Ogre::Vector3 up, Ogre::Vector3 velocity);
void setLoadingBaseSounds(bool value) { loading_base = value; };

Expand Down
10 changes: 0 additions & 10 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,16 +1582,6 @@ int main(int argc, char *argv[])
break;
}

// -- Audio events --
case MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED:
{
float* doppler_factor_ptr = static_cast<float*>(m.payload);
LOG(fmt::format("Changing doppler factor to '{}' (from message bus)", *doppler_factor_ptr));
App::GetSoundScriptManager()->getSoundManager()->SetDopplerFactor(*doppler_factor_ptr);
delete doppler_factor_ptr;
break;
}

default:;
}

Expand Down
18 changes: 1 addition & 17 deletions source/main/scripting/GameScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,23 +1704,7 @@ bool GameScript::pushMessage(MsgType type, AngelScript::CScriptDictionary* dict)
}
break;
}
// Audio
case MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED:
{
float* doppler_factor_ptr = new float();
if (GetValueFromScriptDict(log_msg, dict, /*required:*/true, "doppler_factor", "float", doppler_factor_ptr) &&
!(*doppler_factor_ptr < 0.0f))
{
m.payload = static_cast<void*>(doppler_factor_ptr);
}
else
{
delete doppler_factor_ptr;
return false;
}
break;
}


default:;
}

Expand Down
2 changes: 0 additions & 2 deletions source/main/scripting/bindings/MsgQueueAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ void RoR::RegisterMessageQueue(asIScriptEngine* engine)
result = engine->RegisterEnumValue("MsgType", "MSG_EDI_RELOAD_BUNDLE_REQUESTED", MSG_EDI_RELOAD_BUNDLE_REQUESTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_EDI_UNLOAD_BUNDLE_REQUESTED", MSG_EDI_UNLOAD_BUNDLE_REQUESTED); ROR_ASSERT(result >= 0);
result = engine->RegisterEnumValue("MsgType", "MSG_EDI_CREATE_PROJECT_REQUESTED", MSG_EDI_CREATE_PROJECT_REQUESTED); ROR_ASSERT(result >= 0);
// Audio
result = engine->RegisterEnumValue("MsgType", "MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED", MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED); ROR_ASSERT(result >= 0);

// enum FreeForceType
result = engine->RegisterEnum("FreeForceType"); ROR_ASSERT(result>=0);
Expand Down
55 changes: 0 additions & 55 deletions source/main/system/ConsoleCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,60 +383,6 @@ class SpeedOfSoundCmd: public ConsoleCmd
}
};

class DopplerFactorCmd: public ConsoleCmd
{
public:
DopplerFactorCmd(): ConsoleCmd("dopplerfactor", "[<number>]", _L("Get or set doppler factor (1.0 for realistic effect, 0 for disabling).")) {}

void Run(Ogre::StringVector const& args) override
{
if (!this->CheckAppState(AppState::SIMULATION))
return;

Str<200> reply;
Console::MessageType reply_type;
reply << m_name << ": ";

if (!(args.size() >= 1 && args.size() <= 2))
{
reply_type = Console::CONSOLE_HELP;
reply <<_L("usage: dopplerfactor [doppler factor (float)]");
}
else
{
SoundManager* sound_manager = App::GetSoundScriptManager()->getSoundManager();
if (sound_manager == nullptr)
{
reply << _L("unable to get sound manager");
}
else
{
if(args.size() == 2)
{
float doppler_factor = std::stof(args[1]);
if (doppler_factor < 0.0f)
{
reply << _L("doppler factor must not be negative");
}
else
{
Message m(MSG_AUD_MODIFY_DOPPLER_FACTOR_REQUESTED);
float* doppler_factor_ptr = new float(doppler_factor);
m.payload = static_cast<void*>(doppler_factor_ptr);
App::GetGameContext()->PushMessage(m);
reply << _L("Queued update of doppler factor to: ") << doppler_factor;
}
}
else
{
reply << _L("Doppler Factor is configured as: ") << "CVar (change requires restart): " << App::audio_doppler_factor->getFloat() << ", currently used by OpenAL: " << sound_manager->GetDopplerFactor();
}
}
}
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, reply_type, reply.ToCStr());
}
};

class QuitCmd: public ConsoleCmd
{
public:
Expand Down Expand Up @@ -749,7 +695,6 @@ void Console::regBuiltinCommands()
cmd = new ClearCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
cmd = new LoadScriptCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
cmd = new SpeedOfSoundCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
cmd = new DopplerFactorCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
// CVars
cmd = new SetCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
cmd = new SetstringCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
Expand Down

0 comments on commit f9e26fc

Please sign in to comment.