1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-20 16:35:25 +01:00

Some random code cleanups

This commit is contained in:
sfan5
2025-11-14 16:06:07 +01:00
parent 08ba866992
commit aff1abd05d
21 changed files with 103 additions and 91 deletions

View File

@@ -100,7 +100,6 @@ endif()
if(TRUE) if(TRUE)
message(STATUS "Using imported IrrlichtMt at subdirectory 'irr'")
if(BUILD_CLIENT) if(BUILD_CLIENT)
add_subdirectory(irr EXCLUDE_FROM_ALL) add_subdirectory(irr EXCLUDE_FROM_ALL)

View File

@@ -55,6 +55,9 @@ enum EGUI_ELEMENT_TYPE
//! A tool bar (IGUIToolBar) //! A tool bar (IGUIToolBar)
EGUIET_TOOL_BAR, EGUIET_TOOL_BAR,
// (static_text.cpp in Luanti source)
EGUIET_ENRICHED_STATIC_TEXT,
//! Unknown type. //! Unknown type.
EGUIET_ELEMENT, EGUIET_ELEMENT,

View File

@@ -10,7 +10,7 @@
#include "util/numeric.h" #include "util/numeric.h"
#include <plane3d.h> #include <plane3d.h>
#include <array> #include <array>
#include <list> #include <vector>
#include <optional> #include <optional>
class LocalPlayer; class LocalPlayer;
@@ -255,7 +255,7 @@ private:
f32 m_cache_view_bobbing_amount; f32 m_cache_view_bobbing_amount;
bool m_arm_inertia; bool m_arm_inertia;
std::list<Nametag *> m_nametags; std::vector<Nametag*> m_nametags;
bool m_show_nametag_backgrounds; bool m_show_nametag_backgrounds;
// Last known light color of the player // Last known light color of the player

View File

@@ -16,7 +16,7 @@
class Map; class Map;
class MapBlock; class MapBlock;
class MapBlockMesh; class MapBlockMesh;
class MeshMakeData; struct MeshMakeData;
class Client; class Client;
struct QueuedMeshUpdate struct QueuedMeshUpdate

View File

@@ -534,10 +534,10 @@ v3f Minimap::getYawVec()
return v3f( return v3f(
std::cos(m_angle * core::DEGTORAD), std::cos(m_angle * core::DEGTORAD),
std::sin(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<scene::SMeshBuffer> Minimap::createMinimapMeshBuffer() irr_ptr<scene::SMeshBuffer> Minimap::createMinimapMeshBuffer()
@@ -651,18 +651,16 @@ void Minimap::drawMinimap(core::rect<s32> rect)
static const video::SColor c[4] = {col, col, col, col}; static const video::SColor c[4] = {col, col, col, col};
f32 sin_angle = std::sin(m_angle * core::DEGTORAD); f32 sin_angle = std::sin(m_angle * core::DEGTORAD);
f32 cos_angle = std::cos(m_angle * core::DEGTORAD); f32 cos_angle = std::cos(m_angle * core::DEGTORAD);
s32 marker_size2 = 0.025 * (float)rect.getWidth();; s32 marker_size2 = 0.025f * (float)rect.getWidth();
for (auto i = m_active_markers.begin(); for (v2f posf : m_active_markers) {
i != m_active_markers.end(); ++i) {
v2f posf = *i;
if (data->minimap_shape_round) { if (data->minimap_shape_round) {
f32 t1 = posf.X * cos_angle - posf.Y * sin_angle; f32 t1 = posf.X * cos_angle - posf.Y * sin_angle;
f32 t2 = posf.X * sin_angle + posf.Y * cos_angle; f32 t2 = posf.X * sin_angle + posf.Y * cos_angle;
posf.X = t1; posf.X = t1;
posf.Y = t2; posf.Y = t2;
} }
posf.X = (posf.X + 0.5) * (float)rect.getWidth(); posf.X = (posf.X + 0.5f) * (float)rect.getWidth();
posf.Y = (posf.Y + 0.5) * (float)rect.getHeight(); posf.Y = (posf.Y + 0.5f) * (float)rect.getHeight();
core::rect<s32> dest_rect( core::rect<s32> dest_rect(
s_pos.X + posf.X - marker_size2, s_pos.X + posf.X - marker_size2,
s_pos.Y + posf.Y - 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) void Minimap::removeMarker(MinimapMarker **m)
{ {
m_markers.remove_if([ptr = *m](const auto &up) { return up.get() == ptr; }); MinimapMarker *ptr = *m;
*m = nullptr; *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() void Minimap::updateActiveMarkers()

View File

@@ -53,10 +53,11 @@ struct MinimapModeDef {
struct MinimapMarker { struct MinimapMarker {
MinimapMarker(scene::ISceneNode *parent_node): MinimapMarker(scene::ISceneNode *parent_node):
parent_node(parent_node) parent_node(parent_node)
{ {}
}
scene::ISceneNode *parent_node; scene::ISceneNode *parent_node;
}; };
struct MinimapPixel { struct MinimapPixel {
//! The topmost node that the minimap displays. //! The topmost node that the minimap displays.
MapNode n; MapNode n;
@@ -158,21 +159,22 @@ public:
void updateActiveMarkers(); void updateActiveMarkers();
void drawMinimap(core::rect<s32> rect); void drawMinimap(core::rect<s32> rect);
video::IVideoDriver *driver; video::IVideoDriver *driver = nullptr;
Client* client; Client *client = nullptr;
std::unique_ptr<MinimapData> data; std::unique_ptr<MinimapData> data;
private: private:
ITextureSource *m_tsrc; ITextureSource *m_tsrc = nullptr;
IShaderSource *m_shdrsrc; IShaderSource *m_shdrsrc = nullptr;
const NodeDefManager *m_ndef; const NodeDefManager *m_ndef = nullptr;
std::unique_ptr<MinimapUpdateThread> m_minimap_update_thread; std::unique_ptr<MinimapUpdateThread> m_minimap_update_thread;
irr_ptr<scene::SMeshBuffer> m_meshbuffer; irr_ptr<scene::SMeshBuffer> m_meshbuffer;
std::vector<MinimapModeDef> m_modes; std::vector<MinimapModeDef> m_modes;
size_t m_current_mode_index; size_t m_current_mode_index;
u16 m_surface_mode_scan_height; u16 m_surface_mode_scan_height;
f32 m_angle; f32 m_angle;
std::mutex m_mutex; std::mutex m_mutex;
std::list<std::unique_ptr<MinimapMarker>> m_markers; std::vector<std::unique_ptr<MinimapMarker>> m_markers;
std::list<v2f> m_active_markers; std::vector<v2f> m_active_markers;
}; };

View File

@@ -43,8 +43,6 @@ void GUIEditBoxWithScrollBar::draw()
if (!skin) if (!skin)
return; return;
video::SColor default_bg_color;
if (m_bg_color_used) { if (m_bg_color_used) {
OverrideBgColor = m_bg_color; OverrideBgColor = m_bg_color;
} else if (IsWritable) { } else if (IsWritable) {

View File

@@ -21,7 +21,7 @@ class ISimpleTextureSource;
using namespace gui; using namespace gui;
class GUIScrollBar : public IGUIScrollBar class GUIScrollBar final : public IGUIScrollBar
{ {
public: public:
GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id, GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s32 id,

View File

@@ -242,7 +242,7 @@ namespace gui
}; };
//! Class representing a TrueType font. //! Class representing a TrueType font.
class CGUITTFont : public IGUIFont class CGUITTFont final : public IGUIFont
{ {
public: public:
//! Creates a new TrueType font and returns a pointer to it. The pointer must be drop()'ed when finished. //! Creates a new TrueType font and returns a pointer to it. The pointer must be drop()'ed when finished.

View File

@@ -16,10 +16,7 @@
namespace gui namespace gui
{ {
class StaticText final : public IGUIStaticText
const EGUI_ELEMENT_TYPE EGUIET_ENRICHED_STATIC_TEXT = (EGUI_ELEMENT_TYPE)(0x1000);
class StaticText : public IGUIStaticText
{ {
public: public:
@@ -155,10 +152,6 @@ namespace gui
return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); 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); void setText(const EnrichedString &text);
private: private:

View File

@@ -178,7 +178,7 @@ void ItemDefinition::reset()
wield_overlay.reset(); wield_overlay.reset();
palette_image.clear(); palette_image.clear();
color = video::SColor(0xFFFFFFFF); color = video::SColor(0xFFFFFFFF);
wield_scale = v3f(1.0, 1.0, 1.0); wield_scale = v3f(1.0f);
stack_max = 99; stack_max = 99;
usable = false; usable = false;
liquids_pointable = false; liquids_pointable = false;
@@ -369,7 +369,7 @@ void ItemDefinition::deSerialize(std::istream &is, u16 protocol_version)
// SUGG: Support chains of aliases? // SUGG: Support chains of aliases?
class CItemDefManager: public IWritableItemDefManager class CItemDefManager final : public IWritableItemDefManager
{ {
public: public:
@@ -385,10 +385,10 @@ public:
} }
m_item_definitions.clear(); 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 const std::string &name = getAlias(name_);
std::string name = getAlias(name_);
// Get the definition // Get the definition
auto i = m_item_definitions.find(name); auto i = m_item_definitions.find(name);
if (i == m_item_definitions.cend()) if (i == m_item_definitions.cend())
@@ -396,6 +396,7 @@ public:
assert(i != m_item_definitions.cend()); assert(i != m_item_definitions.cend());
return *(i->second); return *(i->second);
} }
virtual const std::string &getAlias(const std::string &name) const virtual const std::string &getAlias(const std::string &name) const
{ {
auto it = m_aliases.find(name); auto it = m_aliases.find(name);
@@ -403,6 +404,7 @@ public:
return it->second; return it->second;
return name; return name;
} }
virtual void getAll(std::set<std::string> &result) const virtual void getAll(std::set<std::string> &result) const
{ {
result.clear(); result.clear();
@@ -414,16 +416,18 @@ public:
result.insert(alias.first); result.insert(alias.first);
} }
} }
virtual bool isKnown(const std::string &name_) const virtual bool isKnown(const std::string &name_) const
{ {
// Convert name according to possible alias const std::string &name = getAlias(name_);
std::string name = getAlias(name_);
// Get the definition
return m_item_definitions.find(name) != m_item_definitions.cend(); return m_item_definitions.find(name) != m_item_definitions.cend();
} }
void applyTextureOverrides(const std::vector<TextureOverride> &overrides) void applyTextureOverrides(const std::vector<TextureOverride> &overrides)
{ {
if (overrides.empty())
return;
infostream << "ItemDefManager::applyTextureOverrides(): Applying " infostream << "ItemDefManager::applyTextureOverrides(): Applying "
"overrides to textures" << std::endl; "overrides to textures" << std::endl;
@@ -441,6 +445,7 @@ public:
itemdef->wield_image = texture_override.texture; itemdef->wield_image = texture_override.texture;
} }
} }
void clear() void clear()
{ {
for (auto &i : m_item_definitions) for (auto &i : m_item_definitions)
@@ -478,6 +483,7 @@ public:
ignore_def->name = "ignore"; ignore_def->name = "ignore";
m_item_definitions.insert(std::make_pair("ignore", ignore_def)); m_item_definitions.insert(std::make_pair("ignore", ignore_def));
} }
virtual void registerItem(const ItemDefinition &def) virtual void registerItem(const ItemDefinition &def)
{ {
TRACESTREAM(<< "ItemDefManager: registering " << def.name << std::endl); TRACESTREAM(<< "ItemDefManager: registering " << def.name << std::endl);
@@ -496,6 +502,7 @@ public:
infostream<<"ItemDefManager: erased alias "<<def.name infostream<<"ItemDefManager: erased alias "<<def.name
<<" because item was defined"<<std::endl; <<" because item was defined"<<std::endl;
} }
virtual void unregisterItem(const std::string &name) virtual void unregisterItem(const std::string &name)
{ {
verbosestream<<"ItemDefManager: unregistering \""<<name<<"\""<<std::endl; verbosestream<<"ItemDefManager: unregistering \""<<name<<"\""<<std::endl;
@@ -503,6 +510,7 @@ public:
delete m_item_definitions[name]; delete m_item_definitions[name];
m_item_definitions.erase(name); m_item_definitions.erase(name);
} }
virtual void registerAlias(const std::string &name, virtual void registerAlias(const std::string &name,
const std::string &convert_to) const std::string &convert_to)
{ {
@@ -512,6 +520,7 @@ public:
m_aliases[name] = convert_to; m_aliases[name] = convert_to;
} }
} }
void serialize(std::ostream &os, u16 protocol_version) void serialize(std::ostream &os, u16 protocol_version)
{ {
writeU8(os, 0); // version writeU8(os, 0); // version
@@ -533,6 +542,7 @@ public:
os << serializeString16(it.second); os << serializeString16(it.second);
} }
} }
void deSerialize(std::istream &is, u16 protocol_version) void deSerialize(std::istream &is, u16 protocol_version)
{ {
// Clear everything // Clear everything

View File

@@ -70,8 +70,8 @@ struct DungeonParams {
class DungeonGen { class DungeonGen {
public: public:
MMVManip *vm = nullptr; MMVManip *vm = nullptr;
const NodeDefManager *ndef; const NodeDefManager *ndef = nullptr;
GenerateNotifier *gennotify; GenerateNotifier *gennotify = nullptr;
u32 blockseed; u32 blockseed;
PseudoRandom random; PseudoRandom random;

View File

@@ -86,7 +86,7 @@ private:
u32 m_notify_on = 0; u32 m_notify_on = 0;
const std::set<u32> *m_notify_on_deco_ids = nullptr; const std::set<u32> *m_notify_on_deco_ids = nullptr;
const std::set<std::string> *m_notify_on_custom = nullptr; const std::set<std::string> *m_notify_on_custom = nullptr;
std::list<GenNotifyEvent> m_notify_events; std::vector<GenNotifyEvent> m_notify_events;
StringMap m_notify_custom; StringMap m_notify_custom;
inline bool shouldNotifyOn(GenNotifyType type) const { inline bool shouldNotifyOn(GenNotifyType type) const {
@@ -285,9 +285,9 @@ public:
virtual void generateDungeons(s16 max_stone_y); virtual void generateDungeons(s16 max_stone_y);
protected: protected:
BiomeManager *m_bmgr; BiomeManager *m_bmgr = nullptr;
Noise *noise_filler_depth; Noise *noise_filler_depth = nullptr;
v3s16 node_min; v3s16 node_min;
v3s16 node_max; v3s16 node_max;

View File

@@ -77,18 +77,18 @@ private:
float river_depth; float river_depth;
float valley_width; float valley_width;
Noise *noise_height1; Noise *noise_height1 = nullptr;
Noise *noise_height2; Noise *noise_height2 = nullptr;
Noise *noise_height3; Noise *noise_height3 = nullptr;
Noise *noise_height4; Noise *noise_height4 = nullptr;
Noise *noise_hills_terrain; Noise *noise_hills_terrain = nullptr;
Noise *noise_ridge_terrain; Noise *noise_ridge_terrain = nullptr;
Noise *noise_step_terrain; Noise *noise_step_terrain = nullptr;
Noise *noise_hills; Noise *noise_hills = nullptr;
Noise *noise_ridge_mnt; Noise *noise_ridge_mnt = nullptr;
Noise *noise_step_mnt; Noise *noise_step_mnt = nullptr;
Noise *noise_rivers = nullptr; Noise *noise_rivers = nullptr;
Noise *noise_mnt_var; Noise *noise_mnt_var = nullptr;
s32 grad_wl; s32 grad_wl;

View File

@@ -70,5 +70,5 @@ private:
float hill_threshold; float hill_threshold;
float hill_steepness; float hill_steepness;
Noise *noise_terrain; Noise *noise_terrain = nullptr;
}; };

View File

@@ -58,7 +58,7 @@ public:
int generateBaseTerrain(); int generateBaseTerrain();
private: private:
Noise *noise_factor; Noise *noise_factor = nullptr;
Noise *noise_height; Noise *noise_height = nullptr;
Noise *noise_ground; Noise *noise_ground = nullptr;
}; };

View File

@@ -78,18 +78,18 @@ public:
v3s16 full_node_max; v3s16 full_node_max;
v3s16 central_area_size; v3s16 central_area_size;
Noise *noise_terrain_base; Noise *noise_terrain_base = nullptr;
Noise *noise_terrain_higher; Noise *noise_terrain_higher = nullptr;
Noise *noise_steepness; Noise *noise_steepness = nullptr;
Noise *noise_height_select; Noise *noise_height_select = nullptr;
Noise *noise_mud; Noise *noise_mud = nullptr;
Noise *noise_beach; Noise *noise_beach = nullptr;
Noise *noise_biome; Noise *noise_biome = nullptr;
Noise *noise_humidity; Noise *noise_humidity = nullptr;
NoiseParams *np_cave; NoiseParams *np_cave = nullptr;
NoiseParams *np_humidity; NoiseParams *np_humidity = nullptr;
NoiseParams *np_trees; NoiseParams *np_trees = nullptr;
NoiseParams *np_apple_trees; NoiseParams *np_apple_trees = nullptr;
NoiseParams np_dungeons; NoiseParams np_dungeons;

View File

@@ -94,13 +94,13 @@ private:
float *float_offset_cache = nullptr; float *float_offset_cache = nullptr;
Noise *noise_terrain_base; Noise *noise_terrain_base = nullptr;
Noise *noise_terrain_alt; Noise *noise_terrain_alt = nullptr;
Noise *noise_terrain_persist; Noise *noise_terrain_persist = nullptr;
Noise *noise_height_select; Noise *noise_height_select = nullptr;
Noise *noise_mount_height; Noise *noise_mount_height = nullptr;
Noise *noise_ridge_uwater; Noise *noise_ridge_uwater = nullptr;
Noise *noise_mountain; Noise *noise_mountain = nullptr;
Noise *noise_ridge; Noise *noise_ridge = nullptr;
Noise *noise_floatland; Noise *noise_floatland = nullptr;
}; };

View File

@@ -79,18 +79,18 @@ public:
int getSpawnLevelAtPoint(v2s16 p); int getSpawnLevelAtPoint(v2s16 p);
private: private:
BiomeGenOriginal *m_bgen; BiomeGenOriginal *m_bgen = nullptr;
float altitude_chill; float altitude_chill;
float river_depth_bed; float river_depth_bed;
float river_size_factor; float river_size_factor;
Noise *noise_inter_valley_fill; Noise *noise_inter_valley_fill = nullptr;
Noise *noise_inter_valley_slope; Noise *noise_inter_valley_slope = nullptr;
Noise *noise_rivers; Noise *noise_rivers = nullptr;
Noise *noise_terrain_height; Noise *noise_terrain_height = nullptr;
Noise *noise_valley_depth; Noise *noise_valley_depth = nullptr;
Noise *noise_valley_profile; Noise *noise_valley_profile = nullptr;
virtual int generateTerrain(); virtual int generateTerrain();
}; };

View File

@@ -1037,6 +1037,9 @@ void NodeDefManager::updateAliases(IItemDefManager *idef)
void NodeDefManager::applyTextureOverrides(const std::vector<TextureOverride> &overrides) void NodeDefManager::applyTextureOverrides(const std::vector<TextureOverride> &overrides)
{ {
if (overrides.empty())
return;
infostream << "NodeDefManager::applyTextureOverrides(): Applying " infostream << "NodeDefManager::applyTextureOverrides(): Applying "
"overrides to textures" << std::endl; "overrides to textures" << std::endl;

View File

@@ -81,7 +81,7 @@ public:
} }
Key key; Key key;
std::list<caller_info_type> callers; std::vector<caller_info_type> callers;
}; };
/** /**