Skip to content

Commit ecd7eb7

Browse files
committed
Apply review, bug fix.
1 parent 2c95df9 commit ecd7eb7

File tree

7 files changed

+74
-73
lines changed

7 files changed

+74
-73
lines changed

doc/lua_api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5280,7 +5280,7 @@ Utilities
52805280
physics_overrides_v2 = true,
52815281
-- In HUD definitions the field `type` is used and `hud_elem_type` is deprecated (5.9.0)
52825282
hud_def_type_field = true,
5283-
-- set_lighting support lightIntensity table (5.9.0)
5283+
-- set_lighting support light_intensity table (5.9.0)
52845284
light_intensity = true,
52855285
}
52865286
```
@@ -8047,15 +8047,15 @@ child will follow movement and rotation of that bone.
80478047
* `volumetric_light`: is a table that controls volumetric light (a.k.a. "godrays")
80488048
* `strength`: sets the strength of the volumetric light effect from 0 (off, default) to 1 (strongest)
80498049
* This value has no effect on clients who have the "Volumetric Lighting" or "Bloom" shaders disabled.
8050-
* `lightIntensity` is a table that controls calculation of night and day sun light color.
8051-
`sun_color = colorOffset + colorRatioCoef*daynight_ratio` where `daynight_ratio` is not linear to day time
8050+
* `light_intensity` is a table that controls calculation of sun light color.
8051+
`sun_color = color_offset + color_ratio_coef*daynight_ratio` where `daynight_ratio` is not linear to day time
80528052
Result color lesser or equal to 0.0 means no color in light.
80538053
Result color greater or equal to 1.0 means full color in light.
8054-
* `colorOffset` is a table that controls red, green and blue color offsets.
8054+
* `color_offset` is a table that controls red, green and blue color offsets.
80558055
* `r` (default: `-0.04`)
80568056
* `g` (default: `-0.04`)
80578057
* `b` (default: `0.078`)
8058-
* `colorRatioCoef` is table that controls red, green and blue color ration coefficients.
8058+
* `color_ratio_coef` is table that controls red, green and blue color ration coefficients.
80598059
* `r` (default: `0.001`)
80608060
* `g` (default: `0.001`)
80618061
* `b` (default: `0.00098`)

games/devtest/mods/lighting/set_lightIntensity.lua

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
local lightIntensity_sections = {
3-
{n = "colorOffset", d = "Color offset",
2+
local light_intensity_sections = {
3+
{n = "color_offset", d = "Color offset",
44
entries = {
55
{n = "r", d = "Red color offset", min = -1, max = 2},
66
{n = "g", d = "Green color offset", min = -1, max = 2},
77
{n = "b", d = "Blue color offset", min = -1, max = 2},
88
}
99
},
10-
{n = "colorRatioCoef", d = "Color day-night ratio coefficient",
10+
{n = "color_ratio_coef", d = "Color day-night ratio coefficient",
1111
entries = {
1212
{n = "r", d = "Red color day-night ratio coefficient", min = -1e-3, max = 2e-3},
1313
{n = "g", d = "Green color day-night ratio coefficient", min = -1e-3, max = 2e-3},
@@ -16,14 +16,14 @@ local lightIntensity_sections = {
1616
}
1717
}
1818

19-
local function dump_lightIntensity(lightIntensity)
19+
local function dump_light_intensity(light_intensity)
2020
local result = "{\n"
2121
local section_count = 0
22-
for _,section in ipairs(lightIntensity_sections) do
22+
for _,section in ipairs(light_intensity_sections) do
2323
section_count = section_count + 1
2424

2525
local parameters = section.entries or {}
26-
local state = lightIntensity[section.n] or {}
26+
local state = light_intensity[section.n] or {}
2727

2828
result = result.." "..section.n.." = {\n"
2929

@@ -39,7 +39,7 @@ local function dump_lightIntensity(lightIntensity)
3939

4040
result = result.." }"
4141

42-
if section_count < #lightIntensity_sections then
42+
if section_count < #light_intensity_sections then
4343
result = result..","
4444
end
4545
result = result.."\n"
@@ -48,15 +48,15 @@ local function dump_lightIntensity(lightIntensity)
4848
return result
4949
end
5050

51-
minetest.register_chatcommand("set_lightIntensity", {
51+
minetest.register_chatcommand("set_light_intensity", {
5252
params = "",
53-
description = "Tune lighting lightIntensity parameters",
53+
description = "Tune lighting light_intensity parameters",
5454
func = function(player_name, param)
5555
local player = minetest.get_player_by_name(player_name)
5656
if not player then return end
5757

5858
local lighting = player:get_lighting()
59-
local lightIntensity = lighting.lightIntensity
59+
local light_intensity = lighting.light_intensity
6060

6161
local form = {
6262
"formspec_version[2]",
@@ -68,9 +68,9 @@ minetest.register_chatcommand("set_lightIntensity", {
6868
};
6969

7070
local line = 1
71-
for _,section in ipairs(lightIntensity_sections) do
71+
for _,section in ipairs(light_intensity_sections) do
7272
local parameters = section.entries or {}
73-
local state = lightIntensity[section.n] or {}
73+
local state = light_intensity[section.n] or {}
7474

7575
table.insert(form, "label[1,"..line..";"..section.d.."]")
7676
line = line + 1
@@ -90,33 +90,33 @@ minetest.register_chatcommand("set_lightIntensity", {
9090
line = line + 1
9191
end
9292

93-
minetest.show_formspec(player_name, "lightIntensity", table.concat(form))
94-
local debug_value = dump_lightIntensity(lightIntensity)
93+
minetest.show_formspec(player_name, "light_intensity", table.concat(form))
94+
local debug_value = dump_light_intensity(light_intensity)
9595
local debug_ui = player:hud_add({type="text", position={x=0.1, y=0.3}, scale={x=1,y=1}, alignment = {x=1, y=1}, text=debug_value, number=0xFFFFFF})
96-
player:get_meta():set_int("lightIntensity_hud", debug_ui)
96+
player:get_meta():set_int("light_intensity_hud", debug_ui)
9797
end
9898
})
9999

100100
minetest.register_on_player_receive_fields(function(player, formname, fields)
101-
if formname ~= "lightIntensity" then return end
101+
if formname ~= "light_intensity" then return end
102102

103103
if not player then return end
104104

105-
local hud_id = player:get_meta():get_int("lightIntensity_hud")
105+
local hud_id = player:get_meta():get_int("light_intensity_hud")
106106

107107
if fields.quit then
108108
player:hud_remove(hud_id)
109-
player:get_meta():set_int("lightIntensity_hud", -1)
109+
player:get_meta():set_int("light_intensity_hud", -1)
110110
return
111111
end
112112

113113
local lighting = player:get_lighting()
114-
local lightIntensity = lighting.lightIntensity
115-
for _,section in ipairs(lightIntensity_sections) do
114+
local light_intensity = lighting.light_intensity
115+
for _,section in ipairs(light_intensity_sections) do
116116
local parameters = section.entries or {}
117117

118-
local state = (lightIntensity[section.n] or {})
119-
lightIntensity[section.n] = state
118+
local state = (light_intensity[section.n] or {})
119+
light_intensity[section.n] = state
120120

121121
for _,v in ipairs(parameters) do
122122

@@ -133,7 +133,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
133133
end
134134
end
135135

136-
local debug_value = dump_lightIntensity(lightIntensity)
136+
local debug_value = dump_light_intensity(light_intensity)
137137
player:hud_change(hud_id, "text", debug_value)
138138

139139
player:set_lighting(lighting)

src/client/mapblock_mesh.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData
283283
}
284284

285285
void get_sunlight_color(video::SColorf *sunlight, u32 daynight_ratio, const LightIntensity &lightIntensity){
286-
sunlight->r = lightIntensity.colorOffset_rgb[0]+lightIntensity.colorRatioCoef_rgb[0]*daynight_ratio;
287-
sunlight->g = lightIntensity.colorOffset_rgb[1]+lightIntensity.colorRatioCoef_rgb[1]*daynight_ratio;
288-
sunlight->b = lightIntensity.colorOffset_rgb[2]+lightIntensity.colorRatioCoef_rgb[2]*daynight_ratio;
286+
sunlight->r = lightIntensity.colorOffset_rgb.X+lightIntensity.colorRatioCoef_rgb.X*daynight_ratio;
287+
sunlight->g = lightIntensity.colorOffset_rgb.Y+lightIntensity.colorRatioCoef_rgb.Y*daynight_ratio;
288+
sunlight->b = lightIntensity.colorOffset_rgb.Z+lightIntensity.colorRatioCoef_rgb.Z*daynight_ratio;
289289
}
290290

291291
void final_color_blend(video::SColor *result,

src/lighting.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#pragma once
2121

22+
#include "irr_v3d.h"
2223

2324
/**
2425
* Parameters for automatic exposure compensation
@@ -52,17 +53,17 @@ struct AutoExposure
5253
* Light color is calculated in function get_sunlight_color.
5354
* Variable daynight_ration can be from 0 to 1000.
5455
*
55-
* sunlight->r = colorOffset_rgb[0]+colorRatioCoef_rgb[0]*daynight_ratio;
56-
* sunlight->g = colorOffset_rgb[1]+colorRatioCoef_rgb[1]*daynight_ratio;
57-
* sunlight->b = colorOffset_rgb[2]+colorRatioCoef_rgb[2]*daynight_ratio;
56+
* sunlight->r = colorOffset_rgb.X+colorRatioCoef_rgb.X*daynight_ratio;
57+
* sunlight->g = colorOffset_rgb.Y+colorRatioCoef_rgb.Y*daynight_ratio;
58+
* sunlight->b = colorOffset_rgb.Z+colorRatioCoef_rgb.Z*daynight_ratio;
5859
*
5960
*/
6061
struct LightIntensity
6162
{
6263
/// @brief Sunlight color offset
63-
float colorOffset_rgb[3];
64+
v3f colorOffset_rgb;
6465
/// @brief Sunlight color dayratio effect
65-
float colorRatioCoef_rgb[3];
66+
v3f colorRatioCoef_rgb;
6667

6768
LightIntensity();
6869
};

src/network/clientpackethandler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,11 +1818,11 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
18181818
if (pkt->getRemainingBytes() >= 4)
18191819
*pkt >> lighting.volumetric_light_strength;
18201820
if (pkt->getRemainingBytes() >= 24) {
1821-
*pkt >> lighting.lightIntensity.colorOffset_rgb[0]
1822-
>> lighting.lightIntensity.colorOffset_rgb[1]
1823-
>> lighting.lightIntensity.colorOffset_rgb[2]
1824-
>> lighting.lightIntensity.colorRatioCoef_rgb[0]
1825-
>> lighting.lightIntensity.colorRatioCoef_rgb[1]
1826-
>> lighting.lightIntensity.colorRatioCoef_rgb[2];
1821+
*pkt >> lighting.lightIntensity.colorOffset_rgb.X
1822+
>> lighting.lightIntensity.colorOffset_rgb.Y
1823+
>> lighting.lightIntensity.colorOffset_rgb.Z
1824+
>> lighting.lightIntensity.colorRatioCoef_rgb.X
1825+
>> lighting.lightIntensity.colorRatioCoef_rgb.Y
1826+
>> lighting.lightIntensity.colorRatioCoef_rgb.Z;
18271827
}
18281828
}

src/script/lua_api/l_object.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,24 +2518,24 @@ int ObjectRef::l_set_lighting(lua_State *L)
25182518
}
25192519
lua_pop(L, 1); // volumetric_light
25202520

2521-
lua_getfield(L, 2, "lightIntensity");
2521+
lua_getfield(L, 2, "light_intensity");
25222522
if (lua_istable(L, -1)) {
2523-
lua_getfield(L, 3, "colorOffset");
2523+
lua_getfield(L, 3, "color_offset");
25242524
if (lua_istable(L, -1)) {
2525-
lighting.lightIntensity.colorOffset_rgb[0] = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorOffset_rgb[0]);
2526-
lighting.lightIntensity.colorOffset_rgb[1] = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorOffset_rgb[1]);
2527-
lighting.lightIntensity.colorOffset_rgb[2] = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorOffset_rgb[2]);
2525+
lighting.lightIntensity.colorOffset_rgb.X = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorOffset_rgb.X);
2526+
lighting.lightIntensity.colorOffset_rgb.Y = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorOffset_rgb.Y);
2527+
lighting.lightIntensity.colorOffset_rgb.Z = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorOffset_rgb.Z);
25282528
}
2529-
lua_pop(L, 1); // colorOffset
2530-
lua_getfield(L, 3, "colorRatioCoef");
2529+
lua_pop(L, 1); // color_offset
2530+
lua_getfield(L, 3, "color_ratio_coef");
25312531
if (lua_istable(L, -1)) {
2532-
lighting.lightIntensity.colorRatioCoef_rgb[0] = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorRatioCoef_rgb[0]);
2533-
lighting.lightIntensity.colorRatioCoef_rgb[1] = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorRatioCoef_rgb[1]);
2534-
lighting.lightIntensity.colorRatioCoef_rgb[2] = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorRatioCoef_rgb[2]);
2532+
lighting.lightIntensity.colorRatioCoef_rgb.X = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorRatioCoef_rgb.X);
2533+
lighting.lightIntensity.colorRatioCoef_rgb.Y = getfloatfield_default(L, -1, "g", lighting.lightIntensity.colorRatioCoef_rgb.Y);
2534+
lighting.lightIntensity.colorRatioCoef_rgb.Z = getfloatfield_default(L, -1, "b", lighting.lightIntensity.colorRatioCoef_rgb.Z);
25352535
}
2536-
lua_pop(L, 1); // colorRatioCoef
2536+
lua_pop(L, 1); // color_ratio_coef
25372537
}
2538-
lua_pop(L, 1); // lightIntensity
2538+
lua_pop(L, 1); // light_intensity
25392539
}
25402540

25412541
getServer(L)->setLighting(player, lighting);
@@ -2578,24 +2578,24 @@ int ObjectRef::l_get_lighting(lua_State *L)
25782578
lua_pushnumber(L, lighting.volumetric_light_strength);
25792579
lua_setfield(L, -2, "strength");
25802580
lua_setfield(L, -2, "volumetric_light");
2581-
lua_newtable(L); // "lightIntensity"
2582-
lua_newtable(L); // "colorOffset"
2583-
lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb[0]);
2581+
lua_newtable(L); // "light_intensity"
2582+
lua_newtable(L); // "color_offset"
2583+
lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb.X);
25842584
lua_setfield(L, -2, "r");
2585-
lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb[1]);
2585+
lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb.Y);
25862586
lua_setfield(L, -2, "g");
2587-
lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb[2]);
2587+
lua_pushnumber(L, lighting.lightIntensity.colorOffset_rgb.Z);
25882588
lua_setfield(L, -2, "b");
2589-
lua_setfield(L, -2, "colorOffset");
2590-
lua_newtable(L); // "colorRatioCoef"
2591-
lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb[0]);
2589+
lua_setfield(L, -2, "color_offset");
2590+
lua_newtable(L); // "color_ratio_coef"
2591+
lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb.X);
25922592
lua_setfield(L, -2, "r");
2593-
lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb[1]);
2593+
lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb.Y);
25942594
lua_setfield(L, -2, "g");
2595-
lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb[2]);
2595+
lua_pushnumber(L, lighting.lightIntensity.colorRatioCoef_rgb.Z);
25962596
lua_setfield(L, -2, "b");
2597-
lua_setfield(L, -2, "colorRatioCoef");
2598-
lua_setfield(L, -2, "lightIntensity");
2597+
lua_setfield(L, -2, "color_ratio_coef");
2598+
lua_setfield(L, -2, "light_intensity");
25992599
return 1;
26002600
}
26012601

src/server.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,15 +1910,15 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting)
19101910
<< lighting.exposure.speed_bright_dark
19111911
<< lighting.exposure.center_weight_power;
19121912

1913-
pkt << lighting.lightIntensity.colorOffset_rgb[0]
1914-
<< lighting.lightIntensity.colorOffset_rgb[1]
1915-
<< lighting.lightIntensity.colorOffset_rgb[2]
1916-
<< lighting.lightIntensity.colorRatioCoef_rgb[0]
1917-
<< lighting.lightIntensity.colorRatioCoef_rgb[1]
1918-
<< lighting.lightIntensity.colorRatioCoef_rgb[2];
1919-
19201913
pkt << lighting.volumetric_light_strength;
19211914

1915+
pkt << lighting.lightIntensity.colorOffset_rgb.X
1916+
<< lighting.lightIntensity.colorOffset_rgb.Y
1917+
<< lighting.lightIntensity.colorOffset_rgb.Z
1918+
<< lighting.lightIntensity.colorRatioCoef_rgb.X
1919+
<< lighting.lightIntensity.colorRatioCoef_rgb.Y
1920+
<< lighting.lightIntensity.colorRatioCoef_rgb.Z;
1921+
19221922
Send(&pkt);
19231923
}
19241924

0 commit comments

Comments
 (0)