1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

Use unique_ptr for trivial ownership (#16300)

This commit is contained in:
Lucas OH 2025-07-03 17:32:46 +02:00 committed by GitHub
parent 08bc036311
commit 5b37614d23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 44 additions and 59 deletions

View file

@ -118,7 +118,7 @@ Client::Client(
m_last_chat_message_sent(time(NULL)),
m_password(password),
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
m_media_downloader(new ClientMediaDownloader()),
m_media_downloader(std::make_unique<ClientMediaDownloader>()),
m_state(LC_Created),
m_modchannel_mgr(new ModChannelMgr())
{
@ -131,7 +131,7 @@ Client::Client(
m_mod_storage_database->beginSave();
if (g_settings->getBool("enable_minimap")) {
m_minimap = new Minimap(this);
m_minimap = std::make_unique<Minimap>(this);
}
m_cache_save_interval = g_settings->getU16("server_map_save_interval");
@ -212,6 +212,9 @@ void Client::loadMods()
// complain about mods with unsatisfied dependencies
if (!modconf.isConsistent()) {
errorstream << modconf.getUnsatisfiedModsError() << std::endl;
delete m_script;
m_script = nullptr;
m_env.setScript(nullptr);
return;
}
@ -243,7 +246,7 @@ void Client::loadMods()
if (m_camera)
m_script->on_camera_ready(m_camera);
if (m_minimap)
m_script->on_minimap_ready(m_minimap);
m_script->on_minimap_ready(m_minimap.get());
}
void Client::scanModSubfolder(const std::string &mod_name, const std::string &mod_path,
@ -309,6 +312,7 @@ void Client::Stop()
if (m_localdb) {
infostream << "Local map saving ended." << std::endl;
m_localdb->endSave();
m_localdb.reset();
}
if (m_mods_loaded)
@ -339,8 +343,6 @@ Client::~Client()
delete r.mesh;
}
delete m_inventory_from_server;
// Delete detached inventories
for (auto &m_detached_inventorie : m_detached_inventories) {
delete m_detached_inventorie.second;
@ -353,10 +355,8 @@ Client::~Client()
guiScalingCacheClear();
delete m_minimap;
m_minimap = nullptr;
delete m_media_downloader;
m_minimap.reset();
m_media_downloader.reset();
// Write the changes and delete
if (m_mod_storage_database)
@ -672,8 +672,7 @@ void Client::step(float dtime)
if (m_media_downloader && m_media_downloader->isStarted()) {
m_media_downloader->step(this);
if (m_media_downloader->isDone()) {
delete m_media_downloader;
m_media_downloader = NULL;
m_media_downloader.reset();
}
}
{
@ -921,7 +920,7 @@ void Client::initLocalMapSaving(const Address &address, const std::string &hostn
return;
}
if (m_localdb) {
infostream << "Local map saving already running" << std::endl;
infostream << "Local map saving already initialized" << std::endl;
return;
}
@ -941,7 +940,7 @@ void Client::initLocalMapSaving(const Address &address, const std::string &hostn
#undef set_world_path
fs::CreateAllDirs(world_path);
m_localdb = new MapDatabaseSQLite3(world_path);
m_localdb = std::make_unique<MapDatabaseSQLite3>(world_path);
m_localdb->beginSave();
actionstream << "Local map saving started, map will be saved at '" << world_path << "'" << std::endl;
}

View file

@ -363,7 +363,7 @@ public:
return getProtoVersion() != 0; // (set in TOCLIENT_HELLO)
}
Minimap* getMinimap() { return m_minimap; }
Minimap* getMinimap() { return m_minimap.get(); }
void setCamera(Camera* camera) { m_camera = camera; }
Camera* getCamera () { return m_camera; }
@ -494,7 +494,7 @@ private:
std::string m_address_name;
ELoginRegister m_allow_login_or_register = ELoginRegister::Any;
Camera *m_camera = nullptr;
Minimap *m_minimap = nullptr;
std::unique_ptr<Minimap> m_minimap;
// Server serialization version
u8 m_server_ser_ver;
@ -504,7 +504,7 @@ private:
u16 m_proto_ver = 0;
bool m_update_wielded_item = false;
Inventory *m_inventory_from_server = nullptr;
std::unique_ptr<Inventory> m_inventory_from_server;
float m_inventory_from_server_age = 0.0f;
s32 m_mapblock_limit_logged = 0;
PacketCounter m_packetcounter;
@ -543,7 +543,7 @@ private:
std::vector<std::string> m_remote_media_servers;
// Media downloader, only exists during init
ClientMediaDownloader *m_media_downloader;
std::unique_ptr<ClientMediaDownloader> m_media_downloader;
// Pending downloads of dynamic media (key: token)
std::vector<std::pair<u32, std::shared_ptr<SingleMediaDownloader>>> m_pending_media_downloads;
@ -574,7 +574,7 @@ private:
LocalClientState m_state;
// Used for saving server map to disk client-side
MapDatabase *m_localdb = nullptr;
std::unique_ptr<MapDatabase> m_localdb;
IntervalLimiter m_localdb_save_interval;
u16 m_cache_save_interval;