mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 06:32:23 +01:00
Settings: semi-automatic callback cleanup
This commit is contained in:
parent
9f43018df2
commit
e3813cf027
@ -71,9 +71,8 @@ static void dump_start_data(const GameStartData &data)
|
||||
ClientLauncher::~ClientLauncher()
|
||||
{
|
||||
delete input;
|
||||
g_settings->deregisterChangedCallback("dpi_change_notifier", setting_changed_callback, this);
|
||||
g_settings->deregisterChangedCallback("display_density_factor", setting_changed_callback, this);
|
||||
g_settings->deregisterChangedCallback("gui_scaling", setting_changed_callback, this);
|
||||
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
|
||||
delete g_fontengine;
|
||||
g_fontengine = nullptr;
|
||||
|
@ -140,8 +140,7 @@ void ClientMap::onSettingChanged(std::string_view name, bool all)
|
||||
|
||||
ClientMap::~ClientMap()
|
||||
{
|
||||
for (const auto &name : ClientMap_settings)
|
||||
g_settings->deregisterChangedCallback(name, on_settings_changed, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
}
|
||||
|
||||
void ClientMap::updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color)
|
||||
|
@ -76,10 +76,7 @@ Clouds::Clouds(scene::ISceneManager* mgr, IShaderSource *ssrc,
|
||||
|
||||
Clouds::~Clouds()
|
||||
{
|
||||
g_settings->deregisterChangedCallback("enable_3d_clouds",
|
||||
&cloud_3d_setting_changed, this);
|
||||
g_settings->deregisterChangedCallback("soft_clouds",
|
||||
&cloud_3d_setting_changed, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
}
|
||||
|
||||
void Clouds::OnRegisterSceneNode()
|
||||
|
@ -68,8 +68,7 @@ FontEngine::FontEngine(gui::IGUIEnvironment* env) :
|
||||
/******************************************************************************/
|
||||
FontEngine::~FontEngine()
|
||||
{
|
||||
for (auto name : settings)
|
||||
g_settings->deregisterChangedCallback(name, font_setting_changed, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
|
||||
cleanCache();
|
||||
}
|
||||
|
@ -451,8 +451,7 @@ public:
|
||||
|
||||
~GameGlobalShaderConstantSetter()
|
||||
{
|
||||
for (auto &name : SETTING_CALLBACKS)
|
||||
g_settings->deregisterChangedCallback(name, settingsCallback, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
}
|
||||
|
||||
void onSetConstants(video::IMaterialRendererServices *services) override
|
||||
@ -1046,48 +1045,8 @@ Game::~Game()
|
||||
|
||||
clearTextureNameCache();
|
||||
|
||||
g_settings->deregisterChangedCallback("chat_log_level",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("disable_escape_sequences",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("doubletap_jump",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("enable_clouds",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("enable_joysticks",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("enable_particles",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("enable_fog",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("mouse_sensitivity",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("joystick_frustum_sensitivity",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("repeat_place_time",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("repeat_dig_time",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("noclip",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("free_move",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("fog_start",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("cinematic",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("cinematic_camera_smoothing",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("camera_smoothing",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("invert_mouse",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("enable_hotbar_mouse_wheel",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("invert_hotbar_mouse_wheel",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("pause_on_lost_focus",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
|
||||
if (m_rendering_engine)
|
||||
m_rendering_engine->finalize();
|
||||
}
|
||||
|
@ -170,9 +170,7 @@ void Hud::readScalingSetting()
|
||||
|
||||
Hud::~Hud()
|
||||
{
|
||||
g_settings->deregisterChangedCallback("dpi_change_notifier", setting_changed_callback, this);
|
||||
g_settings->deregisterChangedCallback("display_density_factor", setting_changed_callback, this);
|
||||
g_settings->deregisterChangedCallback("hud_scaling", setting_changed_callback, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
|
||||
if (m_selection_mesh)
|
||||
m_selection_mesh->drop();
|
||||
|
@ -60,10 +60,7 @@ void PlayerSettings::registerSettingsCallback()
|
||||
|
||||
void PlayerSettings::deregisterSettingsCallback()
|
||||
{
|
||||
for (auto &name : PlayerSettings_names) {
|
||||
g_settings->deregisterChangedCallback(name,
|
||||
&PlayerSettings::settingsChangedCallback, this);
|
||||
}
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
}
|
||||
|
||||
void PlayerSettings::settingsChangedCallback(const std::string &name, void *data)
|
||||
|
@ -238,8 +238,7 @@ RenderingEngine::~RenderingEngine()
|
||||
{
|
||||
sanity_check(s_singleton == this);
|
||||
|
||||
g_settings->deregisterChangedCallback("fullscreen", settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("window_maximized", settingChangedCallback, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
|
||||
core.reset();
|
||||
m_device->closeDevice();
|
||||
|
@ -404,7 +404,7 @@ void GUIEngine::run()
|
||||
/******************************************************************************/
|
||||
GUIEngine::~GUIEngine()
|
||||
{
|
||||
g_settings->deregisterChangedCallback("fullscreen", fullscreenChangedCallback, this);
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
|
||||
// deinitialize script first. gc destructors might depend on other stuff
|
||||
infostream << "GUIEngine: Deinitializing scripting" << std::endl;
|
||||
|
@ -1048,21 +1048,22 @@ void Settings::registerChangedCallback(const std::string &name,
|
||||
m_callbacks[name].emplace_back(cbf, userdata);
|
||||
}
|
||||
|
||||
void Settings::deregisterChangedCallback(const std::string &name,
|
||||
SettingsChangedCallback cbf, void *userdata)
|
||||
size_t Settings::deregisterAllChangedCallbacks(const void *userdata)
|
||||
{
|
||||
MutexAutoLock lock(m_callback_mutex);
|
||||
SettingsCallbackMap::iterator it_cbks = m_callbacks.find(name);
|
||||
|
||||
if (it_cbks != m_callbacks.end()) {
|
||||
SettingsCallbackList &cbks = it_cbks->second;
|
||||
|
||||
SettingsCallbackList::iterator position =
|
||||
std::find(cbks.begin(), cbks.end(), std::make_pair(cbf, userdata));
|
||||
|
||||
if (position != cbks.end())
|
||||
cbks.erase(position);
|
||||
size_t n_removed = 0;
|
||||
for (auto &settings : m_callbacks) {
|
||||
for (auto cb = settings.second.begin(); cb != settings.second.end();) {
|
||||
if (cb->second == userdata) {
|
||||
cb = settings.second.erase(cb);
|
||||
n_removed++;
|
||||
} else {
|
||||
++cb;
|
||||
}
|
||||
}
|
||||
}
|
||||
return n_removed;
|
||||
}
|
||||
|
||||
void Settings::removeSecureSettings()
|
||||
|
@ -238,8 +238,7 @@ public:
|
||||
|
||||
void registerChangedCallback(const std::string &name,
|
||||
SettingsChangedCallback cbf, void *userdata = NULL);
|
||||
void deregisterChangedCallback(const std::string &name,
|
||||
SettingsChangedCallback cbf, void *userdata = NULL);
|
||||
size_t deregisterAllChangedCallbacks(const void *userdata);
|
||||
|
||||
void removeSecureSettings();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user