From 8350fb734abf9ead60517fb2ed7fb0da8d923de7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 2 Nov 2025 10:02:01 +0100 Subject: [PATCH] Default-initialize SColor --- irr/include/SColor.h | 41 +++--------------------- src/client/clouds.cpp | 2 +- src/client/renderingengine.cpp | 2 +- src/client/shadows/shadowsScreenQuad.cpp | 2 +- src/client/tile.h | 2 +- src/gui/guiScene.h | 2 +- src/script/common/c_converter.cpp | 2 +- src/script/lua_api/l_util.cpp | 6 ++-- 8 files changed, 14 insertions(+), 45 deletions(-) diff --git a/irr/include/SColor.h b/irr/include/SColor.h index 48af09c713..829d4b43e6 100644 --- a/irr/include/SColor.h +++ b/irr/include/SColor.h @@ -205,50 +205,19 @@ inline u16 A1R5G5B5toR5G6B5(u16 color) return (((color & 0x7FE0) << 1) | (color & 0x1F)); } -//! Returns the alpha component from A1R5G5B5 color -/** In Irrlicht, alpha refers to opacity. -\return The alpha value of the color. 0 is transparent, 1 is opaque. */ -inline u32 getAlpha(u16 color) -{ - return ((color >> 15) & 0x1); -} - -//! Returns the red component from A1R5G5B5 color. -/** Shift left by 3 to get 8 bit value. */ -inline u32 getRed(u16 color) -{ - return ((color >> 10) & 0x1F); -} - -//! Returns the green component from A1R5G5B5 color -/** Shift left by 3 to get 8 bit value. */ -inline u32 getGreen(u16 color) -{ - return ((color >> 5) & 0x1F); -} - -//! Returns the blue component from A1R5G5B5 color -/** Shift left by 3 to get 8 bit value. */ -inline u32 getBlue(u16 color) -{ - return (color & 0x1F); -} - //! Class representing a 32 bit ARGB color. /** The color values for alpha, red, green, and blue are stored in a single u32. So all four values may be between 0 and 255. -Alpha in Irrlicht is opacity, so 0 is fully transparent, 255 is fully opaque (solid). -This class is used by most parts of the Irrlicht Engine -to specify a color. Another way is using the class SColorf, which -stores the color values in 4 floats. +Alpha in Irrlicht is non-premultiplied. +This class is used by most parts of the engine, another way is using the SColorf, +which stores the color values in 4 floats. This class must consist of only one u32 and must not use virtual functions. */ class SColor { public: - //! Constructor of the Color. Does nothing. - /** The color value is not initialized to save time. */ - SColor() {} + //! Default constructor + constexpr SColor() : color(0) {} //! Constructs the color from 4 values representing the alpha, red, green and blue component. /** Must be values between 0 and 255. */ diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index b7f6a9a643..de319f83ef 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -406,7 +406,7 @@ void Clouds::render() const float cloud_full_radius = cloud_size * m_cloud_radius_i; // Get fog parameters for setting them back later - video::SColor fog_color(0,0,0,0); + video::SColor fog_color; video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; f32 fog_start = 0; f32 fog_end = 0; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index f87e58df38..3d58bab37f 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -79,7 +79,7 @@ public: auto *driver = services->getVideoDriver(); assert(driver); - video::SColor fog_color(0); + video::SColor fog_color; video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; f32 fog_start = 0; f32 fog_end = 0; diff --git a/src/client/shadows/shadowsScreenQuad.cpp b/src/client/shadows/shadowsScreenQuad.cpp index 18d18835a3..6c2a06928e 100644 --- a/src/client/shadows/shadowsScreenQuad.cpp +++ b/src/client/shadows/shadowsScreenQuad.cpp @@ -9,7 +9,7 @@ ShadowScreenQuad::ShadowScreenQuad() { Material.Wireframe = false; - video::SColor color(0x0); + video::SColor color; Vertices[0] = video::S3DVertex( -1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f); Vertices[1] = video::S3DVertex( diff --git a/src/client/tile.h b/src/client/tile.h index bb37e8f6bd..5ec61c3c72 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -161,7 +161,7 @@ struct TileLayer * The color of the tile, or if the tile does not own * a color then the color of the node owning this tile. */ - video::SColor color = video::SColor(0, 0, 0, 0); + video::SColor color; //! If true, the tile has its own color. bool has_color = false; diff --git a/src/gui/guiScene.h b/src/gui/guiScene.h index eae1e5e5d7..1151d49069 100644 --- a/src/gui/guiScene.h +++ b/src/gui/guiScene.h @@ -69,5 +69,5 @@ private: bool m_inf_rot = false; bool m_initial_rotation = true; - video::SColor m_bgcolor = 0; + video::SColor m_bgcolor; }; diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 2b711bfda6..12d8c59192 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -282,7 +282,7 @@ video::SColor read_ARGB8(lua_State *L, int index) // FIXME: maybe we should have strict type checks here. compare to is_color_table() - video::SColor color(0); + video::SColor color; CHECK_TYPE(index, "ARGB color", LUA_TTABLE); lua_getfield(L, index, "a"); color.setAlpha(lua_isnumber(L, -1) ? clamp_col(lua_tonumber(L, -1)) : 0xFF); diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index f91f4ca6fa..49f177a9c2 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -579,7 +579,7 @@ int ModApiUtil::l_colorspec_to_colorstring(lua_State *L) { NO_MAP_LOCK_REQUIRED; - video::SColor color(0); + video::SColor color; if (read_color(L, 1, &color)) { char colorstring[10]; snprintf(colorstring, 10, "#%02X%02X%02X%02X", @@ -596,7 +596,7 @@ int ModApiUtil::l_colorspec_to_bytes(lua_State *L) { NO_MAP_LOCK_REQUIRED; - video::SColor color(0); + video::SColor color; if (read_color(L, 1, &color)) { u8 colorbytes[4] = { (u8) color.getRed(), @@ -616,7 +616,7 @@ int ModApiUtil::l_colorspec_to_table(lua_State *L) { NO_MAP_LOCK_REQUIRED; - video::SColor color(0); + video::SColor color; if (read_color(L, 1, &color)) { push_ARGB8(L, color); return 1;