1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-06 18:25:21 +01:00

Default-initialize SColor

This commit is contained in:
sfan5
2025-11-02 10:02:01 +01:00
parent 329e210326
commit 8350fb734a
8 changed files with 14 additions and 45 deletions

View File

@@ -205,50 +205,19 @@ inline u16 A1R5G5B5toR5G6B5(u16 color)
return (((color & 0x7FE0) << 1) | (color & 0x1F)); 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. //! Class representing a 32 bit ARGB color.
/** The color values for alpha, red, green, and blue are /** 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. 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). Alpha in Irrlicht is non-premultiplied.
This class is used by most parts of the Irrlicht Engine This class is used by most parts of the engine, another way is using the SColorf,
to specify a color. Another way is using the class SColorf, which which stores the color values in 4 floats.
stores the color values in 4 floats.
This class must consist of only one u32 and must not use virtual functions. This class must consist of only one u32 and must not use virtual functions.
*/ */
class SColor class SColor
{ {
public: public:
//! Constructor of the Color. Does nothing. //! Default constructor
/** The color value is not initialized to save time. */ constexpr SColor() : color(0) {}
SColor() {}
//! Constructs the color from 4 values representing the alpha, red, green and blue component. //! Constructs the color from 4 values representing the alpha, red, green and blue component.
/** Must be values between 0 and 255. */ /** Must be values between 0 and 255. */

View File

@@ -406,7 +406,7 @@ void Clouds::render()
const float cloud_full_radius = cloud_size * m_cloud_radius_i; const float cloud_full_radius = cloud_size * m_cloud_radius_i;
// Get fog parameters for setting them back later // 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; video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR;
f32 fog_start = 0; f32 fog_start = 0;
f32 fog_end = 0; f32 fog_end = 0;

View File

@@ -79,7 +79,7 @@ public:
auto *driver = services->getVideoDriver(); auto *driver = services->getVideoDriver();
assert(driver); assert(driver);
video::SColor fog_color(0); video::SColor fog_color;
video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR; video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR;
f32 fog_start = 0; f32 fog_start = 0;
f32 fog_end = 0; f32 fog_end = 0;

View File

@@ -9,7 +9,7 @@ ShadowScreenQuad::ShadowScreenQuad()
{ {
Material.Wireframe = false; Material.Wireframe = false;
video::SColor color(0x0); video::SColor color;
Vertices[0] = video::S3DVertex( Vertices[0] = video::S3DVertex(
-1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f); -1.0f, -1.0f, 0.0f, 0, 0, 1, color, 0.0f, 1.0f);
Vertices[1] = video::S3DVertex( Vertices[1] = video::S3DVertex(

View File

@@ -161,7 +161,7 @@ struct TileLayer
* The color of the tile, or if the tile does not own * The color of the tile, or if the tile does not own
* a color then the color of the node owning this tile. * 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. //! If true, the tile has its own color.
bool has_color = false; bool has_color = false;

View File

@@ -69,5 +69,5 @@ private:
bool m_inf_rot = false; bool m_inf_rot = false;
bool m_initial_rotation = true; bool m_initial_rotation = true;
video::SColor m_bgcolor = 0; video::SColor m_bgcolor;
}; };

View File

@@ -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() // 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); CHECK_TYPE(index, "ARGB color", LUA_TTABLE);
lua_getfield(L, index, "a"); lua_getfield(L, index, "a");
color.setAlpha(lua_isnumber(L, -1) ? clamp_col(lua_tonumber(L, -1)) : 0xFF); color.setAlpha(lua_isnumber(L, -1) ? clamp_col(lua_tonumber(L, -1)) : 0xFF);

View File

@@ -579,7 +579,7 @@ int ModApiUtil::l_colorspec_to_colorstring(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
video::SColor color(0); video::SColor color;
if (read_color(L, 1, &color)) { if (read_color(L, 1, &color)) {
char colorstring[10]; char colorstring[10];
snprintf(colorstring, 10, "#%02X%02X%02X%02X", snprintf(colorstring, 10, "#%02X%02X%02X%02X",
@@ -596,7 +596,7 @@ int ModApiUtil::l_colorspec_to_bytes(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
video::SColor color(0); video::SColor color;
if (read_color(L, 1, &color)) { if (read_color(L, 1, &color)) {
u8 colorbytes[4] = { u8 colorbytes[4] = {
(u8) color.getRed(), (u8) color.getRed(),
@@ -616,7 +616,7 @@ int ModApiUtil::l_colorspec_to_table(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
video::SColor color(0); video::SColor color;
if (read_color(L, 1, &color)) { if (read_color(L, 1, &color)) {
push_ARGB8(L, color); push_ARGB8(L, color);
return 1; return 1;