From aff1abd05da1e9f7e754d353beec248fa76fcc21 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 14 Nov 2025 16:06:07 +0100 Subject: [PATCH] Some random code cleanups --- CMakeLists.txt | 1 - irr/include/EGUIElementTypes.h | 3 +++ src/client/camera.h | 4 ++-- src/client/mesh_generator_thread.h | 2 +- src/client/minimap.cpp | 22 +++++++++++++--------- src/client/minimap.h | 20 +++++++++++--------- src/gui/guiEditBoxWithScrollbar.cpp | 2 -- src/gui/guiScrollBar.h | 2 +- src/irrlicht_changes/CGUITTFont.h | 2 +- src/irrlicht_changes/static_text.h | 9 +-------- src/itemdef.cpp | 26 ++++++++++++++++++-------- src/mapgen/dungeongen.h | 4 ++-- src/mapgen/mapgen.h | 6 +++--- src/mapgen/mapgen_carpathian.h | 22 +++++++++++----------- src/mapgen/mapgen_flat.h | 2 +- src/mapgen/mapgen_v5.h | 6 +++--- src/mapgen/mapgen_v6.h | 24 ++++++++++++------------ src/mapgen/mapgen_v7.h | 18 +++++++++--------- src/mapgen/mapgen_valleys.h | 14 +++++++------- src/nodedef.cpp | 3 +++ src/util/thread.h | 2 +- 21 files changed, 103 insertions(+), 91 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29d81b094..041084a49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,6 @@ endif() if(TRUE) - message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'") if(BUILD_CLIENT) add_subdirectory(irr EXCLUDE_FROM_ALL) diff --git a/irr/include/EGUIElementTypes.h b/irr/include/EGUIElementTypes.h index 8353b7927..34f6ab13c 100644 --- a/irr/include/EGUIElementTypes.h +++ b/irr/include/EGUIElementTypes.h @@ -55,6 +55,9 @@ enum EGUI_ELEMENT_TYPE //! A tool bar (IGUIToolBar) EGUIET_TOOL_BAR, + // (static_text.cpp in Luanti source) + EGUIET_ENRICHED_STATIC_TEXT, + //! Unknown type. EGUIET_ELEMENT, diff --git a/src/client/camera.h b/src/client/camera.h index 1aaa39c6e..64c9fab92 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -10,7 +10,7 @@ #include "util/numeric.h" #include #include -#include +#include #include class LocalPlayer; @@ -255,7 +255,7 @@ private: f32 m_cache_view_bobbing_amount; bool m_arm_inertia; - std::list m_nametags; + std::vector m_nametags; bool m_show_nametag_backgrounds; // Last known light color of the player diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index 87e77610b..3ade5fb91 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -16,7 +16,7 @@ class Map; class MapBlock; class MapBlockMesh; -class MeshMakeData; +struct MeshMakeData; class Client; struct QueuedMeshUpdate diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index ead088bba..5cd7dc520 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -534,10 +534,10 @@ v3f Minimap::getYawVec() return v3f( std::cos(m_angle * core::DEGTORAD), std::sin(m_angle * core::DEGTORAD), - 1.0); + 1.0f); } - return v3f(1.0, 0.0, 1.0); + return v3f(1.0f, 0.0, 1.0f); } irr_ptr Minimap::createMinimapMeshBuffer() @@ -651,18 +651,16 @@ void Minimap::drawMinimap(core::rect rect) static const video::SColor c[4] = {col, col, col, col}; f32 sin_angle = std::sin(m_angle * core::DEGTORAD); f32 cos_angle = std::cos(m_angle * core::DEGTORAD); - s32 marker_size2 = 0.025 * (float)rect.getWidth();; - for (auto i = m_active_markers.begin(); - i != m_active_markers.end(); ++i) { - v2f posf = *i; + s32 marker_size2 = 0.025f * (float)rect.getWidth(); + for (v2f posf : m_active_markers) { if (data->minimap_shape_round) { f32 t1 = posf.X * cos_angle - posf.Y * sin_angle; f32 t2 = posf.X * sin_angle + posf.Y * cos_angle; posf.X = t1; posf.Y = t2; } - posf.X = (posf.X + 0.5) * (float)rect.getWidth(); - posf.Y = (posf.Y + 0.5) * (float)rect.getHeight(); + posf.X = (posf.X + 0.5f) * (float)rect.getWidth(); + posf.Y = (posf.Y + 0.5f) * (float)rect.getHeight(); core::rect dest_rect( s_pos.X + posf.X - marker_size2, s_pos.Y + posf.Y - marker_size2, @@ -683,8 +681,14 @@ MinimapMarker *Minimap::addMarker(scene::ISceneNode *parent_node) void Minimap::removeMarker(MinimapMarker **m) { - m_markers.remove_if([ptr = *m](const auto &up) { return up.get() == ptr; }); + MinimapMarker *ptr = *m; *m = nullptr; + + auto it = std::find_if(m_markers.begin(), m_markers.end(), [&] (const auto &it) { + return it.get() == ptr; + }); + assert(it != m_markers.end()); + m_markers.erase(it); } void Minimap::updateActiveMarkers() diff --git a/src/client/minimap.h b/src/client/minimap.h index 58326e2a7..e7ba63e4f 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -53,10 +53,11 @@ struct MinimapModeDef { struct MinimapMarker { MinimapMarker(scene::ISceneNode *parent_node): parent_node(parent_node) - { - } + {} + scene::ISceneNode *parent_node; }; + struct MinimapPixel { //! The topmost node that the minimap displays. MapNode n; @@ -158,21 +159,22 @@ public: void updateActiveMarkers(); void drawMinimap(core::rect rect); - video::IVideoDriver *driver; - Client* client; + video::IVideoDriver *driver = nullptr; + Client *client = nullptr; std::unique_ptr data; private: - ITextureSource *m_tsrc; - IShaderSource *m_shdrsrc; - const NodeDefManager *m_ndef; + ITextureSource *m_tsrc = nullptr; + IShaderSource *m_shdrsrc = nullptr; + const NodeDefManager *m_ndef = nullptr; std::unique_ptr m_minimap_update_thread; irr_ptr m_meshbuffer; std::vector m_modes; size_t m_current_mode_index; u16 m_surface_mode_scan_height; f32 m_angle; + std::mutex m_mutex; - std::list> m_markers; - std::list m_active_markers; + std::vector> m_markers; + std::vector m_active_markers; }; diff --git a/src/gui/guiEditBoxWithScrollbar.cpp b/src/gui/guiEditBoxWithScrollbar.cpp index 6e277a682..58be9c8af 100644 --- a/src/gui/guiEditBoxWithScrollbar.cpp +++ b/src/gui/guiEditBoxWithScrollbar.cpp @@ -43,8 +43,6 @@ void GUIEditBoxWithScrollBar::draw() if (!skin) return; - video::SColor default_bg_color; - if (m_bg_color_used) { OverrideBgColor = m_bg_color; } else if (IsWritable) { diff --git a/src/gui/guiScrollBar.h b/src/gui/guiScrollBar.h index ea68c9fe3..e7ef0e83b 100644 --- a/src/gui/guiScrollBar.h +++ b/src/gui/guiScrollBar.h @@ -21,7 +21,7 @@ class ISimpleTextureSource; using namespace gui; -class GUIScrollBar : public IGUIScrollBar +class GUIScrollBar final : public IGUIScrollBar { public: GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id, diff --git a/src/irrlicht_changes/CGUITTFont.h b/src/irrlicht_changes/CGUITTFont.h index 00e621ee3..a84f7161d 100644 --- a/src/irrlicht_changes/CGUITTFont.h +++ b/src/irrlicht_changes/CGUITTFont.h @@ -242,7 +242,7 @@ namespace gui }; //! Class representing a TrueType font. - class CGUITTFont : public IGUIFont + class CGUITTFont final : public IGUIFont { public: //! Creates a new TrueType font and returns a pointer to it. The pointer must be drop()'ed when finished. diff --git a/src/irrlicht_changes/static_text.h b/src/irrlicht_changes/static_text.h index b60e33aac..b9ac34683 100644 --- a/src/irrlicht_changes/static_text.h +++ b/src/irrlicht_changes/static_text.h @@ -16,10 +16,7 @@ namespace gui { - - const EGUI_ELEMENT_TYPE EGUIET_ENRICHED_STATIC_TEXT = (EGUI_ELEMENT_TYPE)(0x1000); - - class StaticText : public IGUIStaticText + class StaticText final : public IGUIStaticText { public: @@ -155,10 +152,6 @@ namespace gui return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); }; - virtual bool hasType(EGUI_ELEMENT_TYPE t) { - return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); - }; - void setText(const EnrichedString &text); private: diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 663469053..9d5a8a325 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -178,7 +178,7 @@ void ItemDefinition::reset() wield_overlay.reset(); palette_image.clear(); color = video::SColor(0xFFFFFFFF); - wield_scale = v3f(1.0, 1.0, 1.0); + wield_scale = v3f(1.0f); stack_max = 99; usable = false; liquids_pointable = false; @@ -369,7 +369,7 @@ void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version) // SUGG: Support chains of aliases? -class CItemDefManager: public IWritableItemDefManager +class CItemDefManager final : public IWritableItemDefManager { public: @@ -385,10 +385,10 @@ public: } m_item_definitions.clear(); } - virtual const ItemDefinition& get(const std::string &name_) const + + virtual const ItemDefinition &get(const std::string &name_) const { - // Convert name according to possible alias - std::string name = getAlias(name_); + const std::string &name = getAlias(name_); // Get the definition auto i = m_item_definitions.find(name); if (i == m_item_definitions.cend()) @@ -396,6 +396,7 @@ public: assert(i != m_item_definitions.cend()); return *(i->second); } + virtual const std::string &getAlias(const std::string &name) const { auto it = m_aliases.find(name); @@ -403,6 +404,7 @@ public: return it->second; return name; } + virtual void getAll(std::set &result) const { result.clear(); @@ -414,16 +416,18 @@ public: result.insert(alias.first); } } + virtual bool isKnown(const std::string &name_) const { - // Convert name according to possible alias - std::string name = getAlias(name_); - // Get the definition + const std::string &name = getAlias(name_); return m_item_definitions.find(name) != m_item_definitions.cend(); } void applyTextureOverrides(const std::vector &overrides) { + if (overrides.empty()) + return; + infostream << "ItemDefManager::applyTextureOverrides(): Applying " "overrides to textures" << std::endl; @@ -441,6 +445,7 @@ public: itemdef->wield_image = texture_override.texture; } } + void clear() { for (auto &i : m_item_definitions) @@ -478,6 +483,7 @@ public: ignore_def->name = "ignore"; m_item_definitions.insert(std::make_pair("ignore", ignore_def)); } + virtual void registerItem(const ItemDefinition &def) { TRACESTREAM(<< "ItemDefManager: registering " << def.name << std::endl); @@ -496,6 +502,7 @@ public: infostream<<"ItemDefManager: erased alias "< *m_notify_on_deco_ids = nullptr; const std::set *m_notify_on_custom = nullptr; - std::list m_notify_events; + std::vector m_notify_events; StringMap m_notify_custom; inline bool shouldNotifyOn(GenNotifyType type) const { @@ -285,9 +285,9 @@ public: virtual void generateDungeons(s16 max_stone_y); protected: - BiomeManager *m_bmgr; + BiomeManager *m_bmgr = nullptr; - Noise *noise_filler_depth; + Noise *noise_filler_depth = nullptr; v3s16 node_min; v3s16 node_max; diff --git a/src/mapgen/mapgen_carpathian.h b/src/mapgen/mapgen_carpathian.h index 175994be9..7bcb12b8c 100644 --- a/src/mapgen/mapgen_carpathian.h +++ b/src/mapgen/mapgen_carpathian.h @@ -77,18 +77,18 @@ private: float river_depth; float valley_width; - Noise *noise_height1; - Noise *noise_height2; - Noise *noise_height3; - Noise *noise_height4; - Noise *noise_hills_terrain; - Noise *noise_ridge_terrain; - Noise *noise_step_terrain; - Noise *noise_hills; - Noise *noise_ridge_mnt; - Noise *noise_step_mnt; + Noise *noise_height1 = nullptr; + Noise *noise_height2 = nullptr; + Noise *noise_height3 = nullptr; + Noise *noise_height4 = nullptr; + Noise *noise_hills_terrain = nullptr; + Noise *noise_ridge_terrain = nullptr; + Noise *noise_step_terrain = nullptr; + Noise *noise_hills = nullptr; + Noise *noise_ridge_mnt = nullptr; + Noise *noise_step_mnt = nullptr; Noise *noise_rivers = nullptr; - Noise *noise_mnt_var; + Noise *noise_mnt_var = nullptr; s32 grad_wl; diff --git a/src/mapgen/mapgen_flat.h b/src/mapgen/mapgen_flat.h index 9071edb9e..77bbeb35e 100644 --- a/src/mapgen/mapgen_flat.h +++ b/src/mapgen/mapgen_flat.h @@ -70,5 +70,5 @@ private: float hill_threshold; float hill_steepness; - Noise *noise_terrain; + Noise *noise_terrain = nullptr; }; diff --git a/src/mapgen/mapgen_v5.h b/src/mapgen/mapgen_v5.h index ef60cfa68..41becfe46 100644 --- a/src/mapgen/mapgen_v5.h +++ b/src/mapgen/mapgen_v5.h @@ -58,7 +58,7 @@ public: int generateBaseTerrain(); private: - Noise *noise_factor; - Noise *noise_height; - Noise *noise_ground; + Noise *noise_factor = nullptr; + Noise *noise_height = nullptr; + Noise *noise_ground = nullptr; }; diff --git a/src/mapgen/mapgen_v6.h b/src/mapgen/mapgen_v6.h index 820577187..691da9028 100644 --- a/src/mapgen/mapgen_v6.h +++ b/src/mapgen/mapgen_v6.h @@ -78,18 +78,18 @@ public: v3s16 full_node_max; v3s16 central_area_size; - Noise *noise_terrain_base; - Noise *noise_terrain_higher; - Noise *noise_steepness; - Noise *noise_height_select; - Noise *noise_mud; - Noise *noise_beach; - Noise *noise_biome; - Noise *noise_humidity; - NoiseParams *np_cave; - NoiseParams *np_humidity; - NoiseParams *np_trees; - NoiseParams *np_apple_trees; + Noise *noise_terrain_base = nullptr; + Noise *noise_terrain_higher = nullptr; + Noise *noise_steepness = nullptr; + Noise *noise_height_select = nullptr; + Noise *noise_mud = nullptr; + Noise *noise_beach = nullptr; + Noise *noise_biome = nullptr; + Noise *noise_humidity = nullptr; + NoiseParams *np_cave = nullptr; + NoiseParams *np_humidity = nullptr; + NoiseParams *np_trees = nullptr; + NoiseParams *np_apple_trees = nullptr; NoiseParams np_dungeons; diff --git a/src/mapgen/mapgen_v7.h b/src/mapgen/mapgen_v7.h index 6c1c509d2..40bbe347e 100644 --- a/src/mapgen/mapgen_v7.h +++ b/src/mapgen/mapgen_v7.h @@ -94,13 +94,13 @@ private: float *float_offset_cache = nullptr; - Noise *noise_terrain_base; - Noise *noise_terrain_alt; - Noise *noise_terrain_persist; - Noise *noise_height_select; - Noise *noise_mount_height; - Noise *noise_ridge_uwater; - Noise *noise_mountain; - Noise *noise_ridge; - Noise *noise_floatland; + Noise *noise_terrain_base = nullptr; + Noise *noise_terrain_alt = nullptr; + Noise *noise_terrain_persist = nullptr; + Noise *noise_height_select = nullptr; + Noise *noise_mount_height = nullptr; + Noise *noise_ridge_uwater = nullptr; + Noise *noise_mountain = nullptr; + Noise *noise_ridge = nullptr; + Noise *noise_floatland = nullptr; }; diff --git a/src/mapgen/mapgen_valleys.h b/src/mapgen/mapgen_valleys.h index a36ade208..d7bd0bb8a 100644 --- a/src/mapgen/mapgen_valleys.h +++ b/src/mapgen/mapgen_valleys.h @@ -79,18 +79,18 @@ public: int getSpawnLevelAtPoint(v2s16 p); private: - BiomeGenOriginal *m_bgen; + BiomeGenOriginal *m_bgen = nullptr; float altitude_chill; float river_depth_bed; float river_size_factor; - Noise *noise_inter_valley_fill; - Noise *noise_inter_valley_slope; - Noise *noise_rivers; - Noise *noise_terrain_height; - Noise *noise_valley_depth; - Noise *noise_valley_profile; + Noise *noise_inter_valley_fill = nullptr; + Noise *noise_inter_valley_slope = nullptr; + Noise *noise_rivers = nullptr; + Noise *noise_terrain_height = nullptr; + Noise *noise_valley_depth = nullptr; + Noise *noise_valley_profile = nullptr; virtual int generateTerrain(); }; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 8a22036c2..bb9a2c351 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1037,6 +1037,9 @@ void NodeDefManager::updateAliases(IItemDefManager *idef) void NodeDefManager::applyTextureOverrides(const std::vector &overrides) { + if (overrides.empty()) + return; + infostream << "NodeDefManager::applyTextureOverrides(): Applying " "overrides to textures" << std::endl; diff --git a/src/util/thread.h b/src/util/thread.h index 778649d8d..9bcf9885b 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -81,7 +81,7 @@ public: } Key key; - std::list callers; + std::vector callers; }; /**