1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Code style fixes.

This commit is contained in:
SFENCE 2024-09-04 19:15:39 +02:00 committed by sfence
parent 24e9db07ec
commit af3f696423
43 changed files with 493 additions and 484 deletions

View file

@ -34,7 +34,16 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# Line endings are already ensured by .gitattributes # Line endings are already ensured by .gitattributes
- name: Check trailing whitespaces - name: Check trailing whitespaces
run: if git ls-files | grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' | xargs grep -n '\s$'; then echo -e "\033[0;31mFound trailing whitespace"; (exit 1); else (exit 0); fi run: |
if git ls-files |\
grep -E '\.txt$|\.md$|\.[ch]$|\.cpp$|\.hpp$|\.sh$|\.cmake$|\.glsl$' |\
xargs grep -n '\s$';\
then\
echo -e "\033[0;31mFound trailing whitespace";\
(exit 1);\
else\
(exit 0);\
fi
indent_spaces: indent_spaces:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -46,21 +55,51 @@ jobs:
# So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error # So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error
- name: Check for unsupported multiline comments - name: Check for unsupported multiline comments
run: | run: |
if git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' | xargs grep -n '\*/.*/\*'; then echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line."; (exit 1); else (exit 0); fi if git ls-files |\
if git ls-files | grep -E '\.lua$' | xargs grep -n -e '\]\].*--\[\['; then echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line."; (exit 1); else (exit 0); fi grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
xargs grep -n '\*/.*/\*';\
then
echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
(exit 1);\
else\
(exit 0);\
fi
if git ls-files |\
grep -E '\.lua$' |\
xargs grep -n -e '\]\].*--\[\[';\
then
echo -e "\033[0;31mUnsupported combination of multiline comments. New multiline comment should begin on new line.";\
(exit 1);\
else\
(exit 0);\
fi
# This prepare files for final check # This prepare files for final check
# See python script ./util/ci/indent_tab_preprocess.py for details. # See python script ./util/ci/indent_tab_preprocess.py for details.
- name: Preprocess files - name: Preprocess files
run: | run: |
git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "/*" "*/" git ls-files |\
git ls-files | grep -E '\.lua$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]" grep -E '^src/.*\.cpp$|^src/.*\.[ch]$' |\
xargs -L 1 -P $(($(nproc) + 1)) \
python3 ./util/ci/indent_tab_preprocess.py "/*" "*/"
git ls-files |\
grep -E '\.lua$' |\
xargs -L 1 -P $(($(nproc) + 1)) \
python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]"
# Check for bad indent. # Check for bad indent.
# This runs over preprocessed files. # This runs over preprocessed files.
# If there is any remaining space on line beginning or after tab, # If there is any remaining space on line beginning or after tab,
# error is generated # error is generated
- name: Check indent spaces - name: Check indent spaces
run: | run: |
if git ls-files | grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' | xargs grep -n -P '^\t*[ ]'; then echo -e "\033[0;31mFound incorrect indent whitespaces"; (exit 1); else (exit 0); fi if git ls-files |\
grep -E '^src/.*\.cpp$|^src/.*\.[ch]$|\.lua' |\
xargs grep -n -P '^\t*[ ]';\
then\
echo -e "\033[0;31mFound incorrect indent whitespaces";\
(exit 1);\
else\
(exit 0);\
fi
tabs_lua_api_files: tabs_lua_api_files:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -68,6 +107,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# Some files should not contain tabs # Some files should not contain tabs
- name: Check tabs in Lua API files - name: Check tabs in Lua API files
run: if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md; then echo -e "\033[0;31mFound tab in markdown file"; (exit 1); else (exit 0); fi run: |
if grep -n $'\t' doc/lua_api.md doc/client_lua_api.md;\
then\
echo -e "\033[0;31mFound tab in markdown file";\
(exit 1);\
else\
(exit 0);\
fi

View file

@ -389,7 +389,7 @@ function vector.random_direction()
local x, y, z, l2 local x, y, z, l2
repeat -- expected less than two attempts on average (volume sphere vs. cube) repeat -- expected less than two attempts on average (volume sphere vs. cube)
x, y, z = math.random() * 2 - 1, math.random() * 2 - 1, math.random() * 2 - 1 x, y, z = math.random() * 2 - 1, math.random() * 2 - 1, math.random() * 2 - 1
l2 = x*x + y*y + z*z l2 = x*x + y*y + z*z
until l2 <= 1 and l2 >= 1e-6 until l2 <= 1 and l2 >= 1e-6
-- normalize -- normalize
local l = math.sqrt(l2) local l = math.sqrt(l2)

View file

@ -38,7 +38,7 @@ local function buttonbar_formspec(self)
-- `BASE_SPACING` is used as the minimum spacing, like `gap` in CSS Flexbox. -- `BASE_SPACING` is used as the minimum spacing, like `gap` in CSS Flexbox.
-- The number of buttons per page is always calculated as if the scroll -- The number of buttons per page is always calculated as if the scroll
-- buttons were visible. -- buttons were visible.
local avail_space = self.size.x - 2*BASE_SPACING - 2*get_scroll_btn_width() local avail_space = self.size.x - 2*BASE_SPACING - 2*get_scroll_btn_width()
local btns_per_page = math.floor((avail_space - BASE_SPACING) / (btn_size + BASE_SPACING)) local btns_per_page = math.floor((avail_space - BASE_SPACING) / (btn_size + BASE_SPACING))

View file

@ -78,7 +78,7 @@ core.register_entity(":__builtin:falling_node", {
self.floats = core.get_item_group(node.name, "float") ~= 0 self.floats = core.get_item_group(node.name, "float") ~= 0
-- Save liquidtype for falling water -- Save liquidtype for falling water
self.liquidtype = def.liquidtype self.liquidtype = def.liquidtype
-- Set entity visuals -- Set entity visuals
if def.drawtype == "torchlike" or def.drawtype == "signlike" then if def.drawtype == "torchlike" or def.drawtype == "signlike" then

View file

@ -36,7 +36,7 @@ end
function core.setting_get_pos(name) function core.setting_get_pos(name)
return core.settings:get_pos(name) return core.settings:get_pos(name)
end end

View file

@ -32,7 +32,7 @@ end
local function clients_list_buttonhandler(this, fields) local function clients_list_buttonhandler(this, fields)
if fields.quit then if fields.quit then
this:delete() this:delete()
return true return true
end end
return false return false

View file

@ -76,7 +76,7 @@ end
local function buttonhandler(this, fields) local function buttonhandler(this, fields)
if fields.quit then if fields.quit then
this:delete() this:delete()
return true return true
end end

View file

@ -4,14 +4,14 @@ local drive_distance = 30
core.register_entity("soundstuff:racecar", { core.register_entity("soundstuff:racecar", {
initial_properties = { initial_properties = {
physical = false, physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "upright_sprite", visual = "upright_sprite",
visual_size = {x = 1, y = 1, z = 1}, visual_size = {x = 1, y = 1, z = 1},
textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"}, textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"},
static_save = false, static_save = false,
}, },
on_activate = function(self, _staticdata, _dtime_s) on_activate = function(self, _staticdata, _dtime_s)
self.min_x = self.object:get_pos().x - drive_distance * 0.5 self.min_x = self.object:get_pos().x - drive_distance * 0.5

View file

@ -68,7 +68,7 @@ core.register_globalstep(function()
hud_ids[pname] = hud_id or player:hud_add({ hud_ids[pname] = hud_id or player:hud_add({
type = "text", -- See HUD element types type = "text", -- See HUD element types
position = {x=0.5, y=0.5}, position = {x=0.5, y=0.5},
text = "X", text = "X",
number = 0xFF0000, number = 0xFF0000,
alignment = {x=0, y=0}, alignment = {x=0, y=0},
}) })

View file

@ -110,15 +110,15 @@ core.register_craftitem("testitems:telescope_stick", {
-- Tree spawners -- Tree spawners
local tree_def={ local tree_def={
axiom="Af", axiom="Af",
rules_a="TT[&GB][&+GB][&++GB][&+++GB]A", rules_a="TT[&GB][&+GB][&++GB][&+++GB]A",
rules_b="[+GB]fB", rules_b="[+GB]fB",
trunk="basenodes:tree", trunk="basenodes:tree",
leaves="basenodes:leaves", leaves="basenodes:leaves",
angle=90, angle=90,
iterations=4, iterations=4,
trunk_type="single", trunk_type="single",
thin_branches=true, thin_branches=true,
} }
core.register_craftitem("testitems:tree_spawner", { core.register_craftitem("testitems:tree_spawner", {

View file

@ -2,37 +2,38 @@ local align_help = "Texture spans over a space of 8×8 nodes"
local align_help_n = "Tiles looks the same for every node" local align_help_n = "Tiles looks the same for every node"
core.register_node("tiled:tiled", { core.register_node("tiled:tiled", {
description = "Tiled Node (world-aligned)".."\n"..align_help, description = "Tiled Node (world-aligned)".."\n"..align_help,
tiles = {{ tiles = {{
name = "tiled_tiled.png", name = "tiled_tiled.png",
align_style = "world", align_style = "world",
scale = 8, scale = 8,
}}, }},
groups = {cracky=3}, groups = {cracky=3},
}) })
core.register_node("tiled:tiled_rooted", { core.register_node("tiled:tiled_rooted", {
description = "Tiled 'plantlike_rooted' Node (world-aligned)".."\n".. description =
"Base node texture spans over a space of 8×8 nodes".."\n".. "Tiled 'plantlike_rooted' Node (world-aligned)".."\n"..
"A plantlike thing grows on top", "Base node texture spans over a space of 8×8 nodes".."\n"..
paramtype = "light", "A plantlike thing grows on top",
drawtype = "plantlike_rooted", paramtype = "light",
tiles = {{ drawtype = "plantlike_rooted",
name = "tiled_tiled.png", tiles = {{
align_style = "world", name = "tiled_tiled.png",
scale = 8, align_style = "world",
}}, scale = 8,
special_tiles = {"tiled_tiled_node.png"}, }},
groups = {cracky=3}, special_tiles = {"tiled_tiled_node.png"},
groups = {cracky=3},
}) })
core.register_node("tiled:tiled_n", { core.register_node("tiled:tiled_n", {
description = "Tiled Node (node-aligned)".."\n"..align_help_n, description = "Tiled Node (node-aligned)".."\n"..align_help_n,
tiles = {{ tiles = {{
name = "tiled_tiled_node.png", name = "tiled_tiled_node.png",
align_style = "node", align_style = "node",
}}, }},
groups = {cracky=3}, groups = {cracky=3},
}) })
stairs.register_stair_and_slab("tiled_n", "tiled:tiled_n", stairs.register_stair_and_slab("tiled_n", "tiled:tiled_n",

View file

@ -1,17 +1,17 @@
local function assert_colors_equal(c1, c2) local function assert_colors_equal(c1, c2)
if type(c1) == "table" and type(c2) == "table" then if type(c1) == "table" and type(c2) == "table" then
assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a) assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
else else
assert(c1 == c2) assert(c1 == c2)
end end
end end
local function test_color_conversion() local function test_color_conversion()
assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255}) assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255}) assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0}) assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255}) assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
assert_colors_equal(core.colorspec_to_table("gren"), nil) assert_colors_equal(core.colorspec_to_table("gren"), nil)
end end
unittests.register("test_color_conversion", test_color_conversion) unittests.register("test_color_conversion", test_color_conversion)

View file

@ -1,16 +1,16 @@
unittests.register("test_get_version", function() unittests.register("test_get_version", function()
local version = core.get_version() local version = core.get_version()
assert(type(version) == "table") assert(type(version) == "table")
assert(type(version.project) == "string") assert(type(version.project) == "string")
assert(type(version.string) == "string") assert(type(version.string) == "string")
assert(type(version.proto_min) == "number") assert(type(version.proto_min) == "number")
assert(type(version.proto_max) == "number") assert(type(version.proto_max) == "number")
assert(version.proto_max >= version.proto_min) assert(version.proto_max >= version.proto_min)
assert(type(version.is_dev) == "boolean") assert(type(version.is_dev) == "boolean")
if version.is_dev then if version.is_dev then
assert(type(version.hash) == "string") assert(type(version.hash) == "string")
else else
assert(version.hash == nil) assert(version.hash == nil)
end end
end) end)

View file

@ -1,36 +1,36 @@
local function raycast_with_pointabilities(start_pos, end_pos, pointabilities) local function raycast_with_pointabilities(start_pos, end_pos, pointabilities)
local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities) local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities)
for hit in ray do for hit in ray do
if hit.type == "node" then if hit.type == "node" then
return hit.under return hit.under
end end
end end
return nil return nil
end end
local function test_raycast_pointabilities(player, pos1) local function test_raycast_pointabilities(player, pos1)
local pos2 = pos1:offset(0, 0, 1) local pos2 = pos1:offset(0, 0, 1)
local pos3 = pos1:offset(0, 0, 2) local pos3 = pos1:offset(0, 0, 2)
local oldnode1 = core.get_node(pos1) local oldnode1 = core.get_node(pos1)
local oldnode2 = core.get_node(pos2) local oldnode2 = core.get_node(pos2)
local oldnode3 = core.get_node(pos3) local oldnode3 = core.get_node(pos3)
core.swap_node(pos1, {name = "air"}) core.swap_node(pos1, {name = "air"})
core.swap_node(pos2, {name = "testnodes:not_pointable"}) core.swap_node(pos2, {name = "testnodes:not_pointable"})
core.swap_node(pos3, {name = "testnodes:pointable"}) core.swap_node(pos3, {name = "testnodes:pointable"})
local p = nil local p = nil
assert(raycast_with_pointabilities(pos1, pos3, p) == pos3) assert(raycast_with_pointabilities(pos1, pos3, p) == pos3)
p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities
assert(raycast_with_pointabilities(pos1, pos3, p) == nil) assert(raycast_with_pointabilities(pos1, pos3, p) == nil)
p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities
assert(raycast_with_pointabilities(pos1, pos3, p) == pos2) assert(raycast_with_pointabilities(pos1, pos3, p) == pos2)
core.swap_node(pos1, oldnode1) core.swap_node(pos1, oldnode1)
core.swap_node(pos2, oldnode2) core.swap_node(pos2, oldnode2)
core.swap_node(pos3, oldnode3) core.swap_node(pos3, oldnode3)
end end
unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true}) unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true})

View file

@ -234,10 +234,10 @@ core.register_chatcommand("dump_wear_bar", {
}) })
core.register_chatcommand("set_saturation", { core.register_chatcommand("set_saturation", {
params = "<saturation>", params = "<saturation>",
description = "Set the saturation for current player.", description = "Set the saturation for current player.",
func = function(player_name, param) func = function(player_name, param)
local saturation = tonumber(param) local saturation = tonumber(param)
core.get_player_by_name(player_name):set_lighting({saturation = saturation }) core.get_player_by_name(player_name):set_lighting({saturation = saturation })
end end
}) })

View file

@ -39,7 +39,7 @@ public:
MapNode n = env->getMap().getNode(floatToInt(pos, BS), &pos_ok); MapNode n = env->getMap().getNode(floatToInt(pos, BS), &pos_ok);
light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(), light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
env->getGameDef()->ndef()->getLightingFlags(n))) env->getGameDef()->ndef()->getLightingFlags(n)))
: 64; : 64;
video::SColor color(255,light,light,light); video::SColor color(255,light,light,light);
m_spritenode->setColor(color); m_spritenode->setColor(color);
} }

View file

@ -3793,8 +3793,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
float old_brightness = sky->getBrightness(); float old_brightness = sky->getBrightness();
direct_brightness = client->getEnv().getClientMap() direct_brightness = client->getEnv().getClientMap()
.getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS), .getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS),
daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen) daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen)
/ 255.0; / 255.0;
} }
float time_of_day_smooth = runData.time_of_day_smooth; float time_of_day_smooth = runData.time_of_day_smooth;

View file

@ -13,32 +13,32 @@
ClientDynamicInfo ClientDynamicInfo::getCurrent() ClientDynamicInfo ClientDynamicInfo::getCurrent()
{ {
v2u32 screen_size = RenderingEngine::getWindowSize(); v2u32 screen_size = RenderingEngine::getWindowSize();
f32 density = RenderingEngine::getDisplayDensity(); f32 density = RenderingEngine::getDisplayDensity();
f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f); f32 gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 20.0f);
f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f); f32 hud_scaling = g_settings->getFloat("hud_scaling", 0.5f, 20.0f);
f32 real_gui_scaling = gui_scaling * density; f32 real_gui_scaling = gui_scaling * density;
f32 real_hud_scaling = hud_scaling * density; f32 real_hud_scaling = hud_scaling * density;
bool touch_controls = g_touchcontrols; bool touch_controls = g_touchcontrols;
return { return {
screen_size, real_gui_scaling, real_hud_scaling, screen_size, real_gui_scaling, real_hud_scaling,
ClientDynamicInfo::calculateMaxFSSize(screen_size, density, gui_scaling), ClientDynamicInfo::calculateMaxFSSize(screen_size, density, gui_scaling),
touch_controls touch_controls
}; };
} }
v2f32 ClientDynamicInfo::calculateMaxFSSize(v2u32 render_target_size, f32 density, f32 gui_scaling) v2f32 ClientDynamicInfo::calculateMaxFSSize(v2u32 render_target_size, f32 density, f32 gui_scaling)
{ {
// must stay in sync with GUIFormSpecMenu::calculateImgsize // must stay in sync with GUIFormSpecMenu::calculateImgsize
const double screen_dpi = density * 96; const double screen_dpi = density * 96;
// assume padding[0,0] since max_formspec_size is used for fullscreen formspecs // assume padding[0,0] since max_formspec_size is used for fullscreen formspecs
double prefer_imgsize = GUIFormSpecMenu::getImgsize(render_target_size, double prefer_imgsize = GUIFormSpecMenu::getImgsize(render_target_size,
screen_dpi, gui_scaling); screen_dpi, gui_scaling);
return v2f32(render_target_size.X / prefer_imgsize, return v2f32(render_target_size.X / prefer_imgsize,
render_target_size.Y / prefer_imgsize); render_target_size.Y / prefer_imgsize);
} }
#endif #endif

View file

@ -104,7 +104,7 @@ std::vector<DirListNode> GetDirListing(const std::string &pathstring)
<< " Error is " << dwError << std::endl; << " Error is " << dwError << std::endl;
listing.clear(); listing.clear();
return listing; return listing;
} }
} }
return listing; return listing;
} }
@ -715,7 +715,7 @@ bool PathStartsWith(const std::string &path, const std::string &prefix)
if(prefixpos == prefixsize) if(prefixpos == prefixsize)
return true; return true;
// Return false if path has ended (at delimiter/EOS) // Return false if path has ended (at delimiter/EOS)
// while prefix did not. // while prefix did not.
if(pathpos == pathsize) if(pathpos == pathsize)
return false; return false;
} }

View file

@ -3892,7 +3892,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode)
fields[name] = "CHG:" + itos(e->getPos()); fields[name] = "CHG:" + itos(e->getPos());
else else
fields[name] = "VAL:" + itos(e->getPos()); fields[name] = "VAL:" + itos(e->getPos());
} }
} else if (s.ftype == f_AnimatedImage) { } else if (s.ftype == f_AnimatedImage) {
// No dynamic cast possible due to some distributions shipped // No dynamic cast possible due to some distributions shipped
// without rtti support in Irrlicht // without rtti support in Irrlicht
@ -5056,7 +5056,7 @@ double GUIFormSpecMenu::calculateImgsize(const parserData &data)
{ {
// must stay in sync with ClientDynamicInfo::calculateMaxFSSize // must stay in sync with ClientDynamicInfo::calculateMaxFSSize
const double screen_dpi = RenderingEngine::getDisplayDensity() * 96; const double screen_dpi = RenderingEngine::getDisplayDensity() * 96;
const double gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 42.0f); const double gui_scaling = g_settings->getFloat("gui_scaling", 0.5f, 42.0f);
// Fixed-size mode // Fixed-size mode

View file

@ -777,7 +777,7 @@ void TextDrawer::place(const core::rect<s32> &dest_rect)
std::max(f.margin, p.margin); std::max(f.margin, p.margin);
} else if (f.rect.UpperLeftCorner.X - f.margin <= left && } else if (f.rect.UpperLeftCorner.X - f.margin <= left &&
f.rect.LowerRightCorner.X + f.margin >= right) { f.rect.LowerRightCorner.X + f.margin >= right) {
// float taking all space // float taking all space
left = right; left = right;
} }

View file

@ -475,7 +475,7 @@ void TouchControls::translateEvent(const SEvent &event)
toggleOverflowMenu(); toggleOverflowMenu();
// refresh since visibility of buttons has changed // refresh since visibility of buttons has changed
element = m_guienv->getRootGUIElement()->getElementFromPoint(touch_pos); element = m_guienv->getRootGUIElement()->getElementFromPoint(touch_pos);
// continue processing, but avoid accidentally placing a node // continue processing, but avoid accidentally placing a node
// when closing the overflow menu // when closing the overflow menu
prevent_short_tap = true; prevent_short_tap = true;

View file

@ -21,8 +21,8 @@ class GUITouchscreenLayout : public GUIModalMenu
{ {
public: public:
GUITouchscreenLayout(gui::IGUIEnvironment* env, GUITouchscreenLayout(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id, gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, ISimpleTextureSource *tsrc); IMenuManager *menumgr, ISimpleTextureSource *tsrc);
~GUITouchscreenLayout(); ~GUITouchscreenLayout();
void regenerateGui(v2u32 screensize); void regenerateGui(v2u32 screensize);

View file

@ -344,7 +344,7 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
Buffer<u8> buf; Buffer<u8> buf;
const u8 content_width = 2; const u8 content_width = 2;
const u8 params_width = 2; const u8 params_width = 2;
if(disk) if(disk)
{ {
MapNode *tmp_nodes = new MapNode[nodecount]; MapNode *tmp_nodes = new MapNode[nodecount];
memcpy(tmp_nodes, data, nodecount * sizeof(MapNode)); memcpy(tmp_nodes, data, nodecount * sizeof(MapNode));

View file

@ -763,7 +763,7 @@ void MapgenBasic::generateBiomes()
// If no stone surface detected in mapchunk column and a water surface // If no stone surface detected in mapchunk column and a water surface
// biome fallback exists, add it to the biomemap. This avoids water // biome fallback exists, add it to the biomemap. This avoids water
// surface decorations failing in deep water. // surface decorations failing in deep water.
if (biomemap[index] == BIOME_NONE && water_biome_index != 0) if (biomemap[index] == BIOME_NONE && water_biome_index != 0)
biomemap[index] = water_biome_index; biomemap[index] = water_biome_index;
} }
} }

View file

@ -172,7 +172,7 @@ int MapgenFlat::getSpawnLevelAtPoint(v2s16 p)
stone_level = ground_level - depress; stone_level = ground_level - depress;
} else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) {
s16 rise = (n_terrain - hill_threshold) * hill_steepness; s16 rise = (n_terrain - hill_threshold) * hill_steepness;
stone_level = ground_level + rise; stone_level = ground_level + rise;
} }
if (ground_level < water_level) if (ground_level < water_level)
@ -296,7 +296,7 @@ s16 MapgenFlat::generateTerrain()
stone_level = ground_level - depress; stone_level = ground_level - depress;
} else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) {
s16 rise = (n_terrain - hill_threshold) * hill_steepness; s16 rise = (n_terrain - hill_threshold) * hill_steepness;
stone_level = ground_level + rise; stone_level = ground_level + rise;
} }
u32 vi = vm->m_area.index(x, node_min.Y - 1, z); u32 vi = vm->m_area.index(x, node_min.Y - 1, z);

View file

@ -104,15 +104,15 @@ void MapgenFractalParams::readParams(const Settings *settings)
settings->getU16NoEx("mgfractal_fractal", fractal); settings->getU16NoEx("mgfractal_fractal", fractal);
settings->getU16NoEx("mgfractal_iterations", iterations); settings->getU16NoEx("mgfractal_iterations", iterations);
std::optional<v3f> mgfractal_scale; std::optional<v3f> mgfractal_scale;
if (settings->getV3FNoEx("mgfractal_scale", mgfractal_scale) && mgfractal_scale.has_value()) { if (settings->getV3FNoEx("mgfractal_scale", mgfractal_scale) && mgfractal_scale.has_value()) {
scale = *mgfractal_scale; scale = *mgfractal_scale;
} }
std::optional<v3f> mgfractal_offset; std::optional<v3f> mgfractal_offset;
if (settings->getV3FNoEx("mgfractal_offset", mgfractal_offset) && mgfractal_offset.has_value()) { if (settings->getV3FNoEx("mgfractal_offset", mgfractal_offset) && mgfractal_offset.has_value()) {
offset = *mgfractal_offset; offset = *mgfractal_offset;
} }
settings->getFloatNoEx("mgfractal_slice_w", slice_w); settings->getFloatNoEx("mgfractal_slice_w", slice_w);
settings->getFloatNoEx("mgfractal_julia_x", julia_x); settings->getFloatNoEx("mgfractal_julia_x", julia_x);

View file

@ -276,29 +276,29 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
Key for Special L-System Symbols used in Axioms Key for Special L-System Symbols used in Axioms
G - move forward one unit with the pen up G - move forward one unit with the pen up
F - move forward one unit with the pen down drawing trunks and branches F - move forward one unit with the pen down drawing trunks and branches
f - move forward one unit with the pen down drawing leaves (100% chance) f - move forward one unit with the pen down drawing leaves (100% chance)
T - move forward one unit with the pen down drawing trunks only T - move forward one unit with the pen down drawing trunks only
R - move forward one unit with the pen down placing fruit R - move forward one unit with the pen down placing fruit
A - replace with rules set A A - replace with rules set A
B - replace with rules set B B - replace with rules set B
C - replace with rules set C C - replace with rules set C
D - replace with rules set D D - replace with rules set D
a - replace with rules set A, chance 90% a - replace with rules set A, chance 90%
b - replace with rules set B, chance 80% b - replace with rules set B, chance 80%
c - replace with rules set C, chance 70% c - replace with rules set C, chance 70%
d - replace with rules set D, chance 60% d - replace with rules set D, chance 60%
+ - yaw the turtle right by angle degrees + - yaw the turtle right by angle degrees
- - yaw the turtle left by angle degrees - - yaw the turtle left by angle degrees
& - pitch the turtle down by angle degrees & - pitch the turtle down by angle degrees
^ - pitch the turtle up by angle degrees ^ - pitch the turtle up by angle degrees
/ - roll the turtle to the right by angle degrees / - roll the turtle to the right by angle degrees
* - roll the turtle to the left by angle degrees * - roll the turtle to the left by angle degrees
[ - save in stack current state info [ - save in stack current state info
] - recover from stack state info ] - recover from stack state info
*/ */
s16 x,y,z; s16 x,y,z;
for (s16 i = 0; i < (s16)axiom.size(); i++) { for (s16 i = 0; i < (s16)axiom.size(); i++) {

View file

@ -160,8 +160,8 @@ void PcgRandom::getState(u64 state[2]) const
void PcgRandom::setState(const u64 state[2]) void PcgRandom::setState(const u64 state[2])
{ {
m_state = state[0]; m_state = state[0];
m_inc = state[1]; m_inc = state[1];
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View file

@ -67,9 +67,9 @@
#ifndef _WIN32 // POSIX #ifndef _WIN32 // POSIX
#include <sys/time.h> #include <sys/time.h>
#include <ctime> #include <ctime>
#if defined(__MACH__) && defined(__APPLE__) #if defined(__MACH__) && defined(__APPLE__)
#include <TargetConditionals.h> #include <TargetConditionals.h>
#endif #endif
#endif #endif
namespace porting namespace porting

View file

@ -902,7 +902,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
lua_getfield(L, index, "selection_box"); lua_getfield(L, index, "selection_box");
if(lua_istable(L, -1)) if(lua_istable(L, -1))
f.selection_box = read_nodebox(L, -1); f.selection_box = read_nodebox(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
lua_getfield(L, index, "collision_box"); lua_getfield(L, index, "collision_box");
if(lua_istable(L, -1)) if(lua_istable(L, -1))

View file

@ -62,130 +62,98 @@ extern struct EnumString es_TileAnimationType[];
extern const std::array<const char *, 33> object_property_keys; extern const std::array<const char *, 33> object_property_keys;
void read_content_features (lua_State *L, ContentFeatures &f, void read_content_features(lua_State *L, ContentFeatures &f, int index);
int index); void push_content_features(lua_State *L, const ContentFeatures &c);
void push_content_features (lua_State *L,
const ContentFeatures &c);
void push_nodebox (lua_State *L, void push_nodebox(lua_State *L, const NodeBox &box);
const NodeBox &box); void push_palette(lua_State *L, const std::vector<video::SColor> *palette);
void push_palette (lua_State *L,
const std::vector<video::SColor> *palette);
TileDef read_tiledef (lua_State *L, int index, TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special);
u8 drawtype, bool special);
void read_simplesoundspec (lua_State *L, int index, void read_simplesoundspec(lua_State *L, int index, SoundSpec &spec);
SoundSpec &spec); NodeBox read_nodebox(lua_State *L, int index);
NodeBox read_nodebox (lua_State *L, int index);
void read_server_sound_params (lua_State *L, int index, void read_server_sound_params(lua_State *L, int index,
ServerPlayingSound &params); ServerPlayingSound &params);
void push_dig_params (lua_State *L, void push_dig_params(lua_State *L, const DigParams &params);
const DigParams &params); void push_hit_params(lua_State *L, const HitParams &params);
void push_hit_params (lua_State *L,
const HitParams &params);
ItemStack read_item (lua_State *L, int index, IItemDefManager *idef); ItemStack read_item(lua_State *L, int index, IItemDefManager *idef);
struct TileAnimationParams read_animation_definition(lua_State *L, int index); struct TileAnimationParams read_animation_definition(lua_State *L, int index);
PointabilityType read_pointability_type (lua_State *L, int index); PointabilityType read_pointability_type(lua_State *L, int index);
Pointabilities read_pointabilities (lua_State *L, int index); Pointabilities read_pointabilities(lua_State *L, int index);
void push_pointability_type (lua_State *L, PointabilityType pointable); void push_pointability_type(lua_State *L, PointabilityType pointable);
void push_pointabilities (lua_State *L, const Pointabilities &pointabilities); void push_pointabilities(lua_State *L, const Pointabilities &pointabilities);
ToolCapabilities read_tool_capabilities (lua_State *L, int table); ToolCapabilities read_tool_capabilities(lua_State *L, int table);
void push_tool_capabilities (lua_State *L, void push_tool_capabilities(lua_State *L, const ToolCapabilities &prop);
const ToolCapabilities &prop); WearBarParams read_wear_bar_params(lua_State *L, int table);
WearBarParams read_wear_bar_params (lua_State *L, int table); void push_wear_bar_params(lua_State *L, const WearBarParams &prop);
void push_wear_bar_params (lua_State *L,
const WearBarParams &prop);
void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def, void read_item_definition(lua_State *L, int index,
ItemDefinition &def); const ItemDefinition &default_def, ItemDefinition &def);
void push_item_definition (lua_State *L, void push_item_definition(lua_State *L, const ItemDefinition &i);
const ItemDefinition &i); void push_item_definition_full(lua_State *L, const ItemDefinition &i);
void push_item_definition_full (lua_State *L,
const ItemDefinition &i);
void read_object_properties (lua_State *L, int index, void read_object_properties(lua_State *L, int index,
ServerActiveObject *sao, ServerActiveObject *sao,
ObjectProperties *prop, ObjectProperties *prop,
IItemDefManager *idef); IItemDefManager *idef);
void push_object_properties (lua_State *L, void push_object_properties(lua_State *L, const ObjectProperties *prop);
const ObjectProperties *prop);
void push_inventory_list (lua_State *L, void push_inventory_list(lua_State *L, const InventoryList &invlist);
const InventoryList &invlist); void push_inventory_lists(lua_State *L, const Inventory &inv);
void push_inventory_lists (lua_State *L, void read_inventory_list(lua_State *L, int tableindex,
const Inventory &inv); Inventory *inv, const char *name,
void read_inventory_list (lua_State *L, int tableindex, IGameDef *gdef, int forcesize=-1);
Inventory *inv, const char *name,
IGameDef *gdef, int forcesize=-1);
MapNode readnode (lua_State *L, int index); MapNode readnode(lua_State *L, int index);
void pushnode (lua_State *L, const MapNode &n); void pushnode(lua_State *L, const MapNode &n);
void read_groups (lua_State *L, int index, void read_groups(lua_State *L, int index, ItemGroupList &result);
ItemGroupList &result);
void push_groups (lua_State *L, void push_groups(lua_State *L, const ItemGroupList &groups);
const ItemGroupList &groups);
//TODO rename to "read_enum_field" //TODO rename to "read_enum_field"
int getenumfield (lua_State *L, int table, int getenumfield(lua_State *L, int table, const char *fieldname,
const char *fieldname, const EnumString *spec, int default_);
const EnumString *spec,
int default_);
bool getflagsfield (lua_State *L, int table, bool getflagsfield(lua_State *L, int table, const char *fieldname,
const char *fieldname, FlagDesc *flagdesc, u32 *flags, u32 *flagmask);
FlagDesc *flagdesc,
u32 *flags, u32 *flagmask);
bool read_flags (lua_State *L, int index, bool read_flags(lua_State *L, int index, FlagDesc *flagdesc,
FlagDesc *flagdesc, u32 *flags, u32 *flagmask);
u32 *flags, u32 *flagmask);
void push_flags_string (lua_State *L, FlagDesc *flagdesc, void push_flags_string(lua_State *L, FlagDesc *flagdesc,
u32 flags, u32 flagmask); u32 flags, u32 flagmask);
u32 read_flags_table (lua_State *L, int table, u32 read_flags_table(lua_State *L, int table,
FlagDesc *flagdesc, u32 *flagmask); FlagDesc *flagdesc, u32 *flagmask);
void push_items (lua_State *L, void push_items(lua_State *L, const std::vector<ItemStack> &items);
const std::vector<ItemStack> &items);
std::vector<ItemStack> read_items (lua_State *L, std::vector<ItemStack> read_items(lua_State *L, int index, IGameDef* gdef);
int index,
IGameDef* gdef);
void push_simplesoundspec (lua_State *L, void push_simplesoundspec(lua_State *L, const SoundSpec &spec);
const SoundSpec &spec);
bool string_to_enum (const EnumString *spec, bool string_to_enum(const EnumString *spec,
int &result, int &result, const std::string &str);
const std::string &str);
bool read_noiseparams (lua_State *L, int index, bool read_noiseparams(lua_State *L, int index, NoiseParams *np);
NoiseParams *np); void push_noiseparams(lua_State *L, NoiseParams *np);
void push_noiseparams (lua_State *L, NoiseParams *np);
bool read_tree_def (lua_State *L, int idx, bool read_tree_def(lua_State *L, int idx,
const NodeDefManager *ndef, const NodeDefManager *ndef, treegen::TreeDef &tree_def);
treegen::TreeDef &tree_def);
void luaentity_get (lua_State *L,u16 id); void luaentity_get(lua_State *L,u16 id);
bool push_json_value (lua_State *L, bool push_json_value(lua_State *L, const Json::Value &value, int nullindex);
const Json::Value &value, void read_json_value(lua_State *L, Json::Value &root, int index, u16 max_depth);
int nullindex);
void read_json_value (lua_State *L, Json::Value &root,
int index, u16 max_depth);
/*! /*!
* Pushes a Lua `pointed_thing` to the given Lua stack. * Pushes a Lua `pointed_thing` to the given Lua stack.
@ -195,13 +163,13 @@ void read_json_value (lua_State *L, Json::Value &root,
void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm = void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm =
false, bool hitpoint = false); false, bool hitpoint = false);
void push_objectRef (lua_State *L, const u16 id); void push_objectRef(lua_State *L, const u16 id);
void read_hud_element (lua_State *L, HudElement *elem); void read_hud_element(lua_State *L, HudElement *elem);
void push_hud_element (lua_State *L, HudElement *elem); void push_hud_element(lua_State *L, HudElement *elem);
bool read_hud_change (lua_State *L, HudElementStat &stat, HudElement *elem, void **value); bool read_hud_change(lua_State *L, HudElementStat &stat, HudElement *elem, void **value);
void push_collision_move_result(lua_State *L, const collisionMoveResult &res); void push_collision_move_result(lua_State *L, const collisionMoveResult &res);

View file

@ -21,20 +21,19 @@ extern "C" {
#include <lua.h> #include <lua.h>
} }
std::string getstringfield_default(lua_State *L, int table, std::string getstringfield_default(lua_State *L, int table,
const char *fieldname, const std::string &default_); const char *fieldname, const std::string &default_);
bool getboolfield_default(lua_State *L, int table, bool getboolfield_default(lua_State *L, int table,
const char *fieldname, bool default_); const char *fieldname, bool default_);
float getfloatfield_default(lua_State *L, int table, float getfloatfield_default(lua_State *L, int table,
const char *fieldname, float default_); const char *fieldname, float default_);
int getintfield_default(lua_State *L, int table, int getintfield_default(lua_State *L, int table,
const char *fieldname, int default_); const char *fieldname, int default_);
bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname); bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname);
template<typename T> template<typename T>
bool getintfield(lua_State *L, int table, bool getintfield(lua_State *L, int table, const char *fieldname, T &result)
const char *fieldname, T &result)
{ {
lua_getfield(L, table, fieldname); lua_getfield(L, table, fieldname);
bool got = false; bool got = false;
@ -47,43 +46,41 @@ bool getintfield(lua_State *L, int table,
} }
// Retrieve an v3s16 where all components are optional (falls back to default) // Retrieve an v3s16 where all components are optional (falls back to default)
v3s16 getv3s16field_default(lua_State *L, int table, v3s16 getv3s16field_default(lua_State *L, int table,
const char *fieldname, v3s16 default_); const char *fieldname, v3s16 default_);
bool getstringfield(lua_State *L, int table, bool getstringfield(lua_State *L, int table,
const char *fieldname, std::string &result); const char *fieldname, std::string &result);
bool getstringfield(lua_State *L, int table, bool getstringfield(lua_State *L, int table,
const char *fieldname, std::string_view &result); const char *fieldname, std::string_view &result);
size_t getstringlistfield(lua_State *L, int table, size_t getstringlistfield(lua_State *L, int table,
const char *fieldname, const char *fieldname, std::vector<std::string> *result);
std::vector<std::string> *result); bool getboolfield(lua_State *L, int table,
bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result);
const char *fieldname, bool &result); bool getfloatfield(lua_State *L, int table,
bool getfloatfield(lua_State *L, int table, const char *fieldname, float &result);
const char *fieldname, float &result);
void setstringfield(lua_State *L, int table, void setstringfield(lua_State *L, int table,
const char *fieldname, const std::string &value); const char *fieldname, const std::string &value);
void setintfield(lua_State *L, int table, void setintfield(lua_State *L, int table,
const char *fieldname, int value); const char *fieldname, int value);
void setfloatfield(lua_State *L, int table, void setfloatfield(lua_State *L, int table,
const char *fieldname, float value); const char *fieldname, float value);
void setboolfield(lua_State *L, int table, void setboolfield(lua_State *L, int table,
const char *fieldname, bool value); const char *fieldname, bool value);
v3f checkFloatPos (lua_State *L, int index); v3f checkFloatPos(lua_State *L, int index);
v2f check_v2f (lua_State *L, int index); v2f check_v2f(lua_State *L, int index);
v3f check_v3f (lua_State *L, int index); v3f check_v3f(lua_State *L, int index);
v3s16 check_v3s16 (lua_State *L, int index); v3s16 check_v3s16(lua_State *L, int index);
v3f read_v3f (lua_State *L, int index); v3f read_v3f(lua_State *L, int index);
v2f read_v2f (lua_State *L, int index); v2f read_v2f(lua_State *L, int index);
v2s16 read_v2s16 (lua_State *L, int index); v2s16 read_v2s16(lua_State *L, int index);
v2s32 read_v2s32 (lua_State *L, int index); v2s32 read_v2s32(lua_State *L, int index);
video::SColor read_ARGB8 (lua_State *L, int index); video::SColor read_ARGB8(lua_State *L, int index);
bool read_color (lua_State *L, int index, bool read_color(lua_State *L, int index, video::SColor *color);
video::SColor *color); bool is_color_table (lua_State *L, int index);
bool is_color_table (lua_State *L, int index);
/** /**
* Read a floating-point axis-aligned box from Lua. * Read a floating-point axis-aligned box from Lua.
@ -96,32 +93,30 @@ bool is_color_table (lua_State *L, int index);
* *
* @return the box corresponding to lua table * @return the box corresponding to lua table
*/ */
aabb3f read_aabb3f (lua_State *L, int index, f32 scale); aabb3f read_aabb3f(lua_State *L, int index, f32 scale);
v3s16 read_v3s16 (lua_State *L, int index); v3s16 read_v3s16(lua_State *L, int index);
std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale); std::vector<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale);
size_t read_stringlist (lua_State *L, int index, size_t read_stringlist(lua_State *L, int index,
std::vector<std::string> *result); std::vector<std::string> *result);
void push_v2s16 (lua_State *L, v2s16 p); void push_v2s16(lua_State *L, v2s16 p);
void push_v2s32 (lua_State *L, v2s32 p); void push_v2s32(lua_State *L, v2s32 p);
void push_v2u32 (lua_State *L, v2u32 p); void push_v2u32(lua_State *L, v2u32 p);
void push_v3s16 (lua_State *L, v3s16 p); void push_v3s16(lua_State *L, v3s16 p);
void push_aabb3f (lua_State *L, aabb3f box, f32 divisor = 1.0f); void push_aabb3f(lua_State *L, aabb3f box, f32 divisor = 1.0f);
void push_ARGB8 (lua_State *L, video::SColor color); void push_ARGB8(lua_State *L, video::SColor color);
void pushFloatPos (lua_State *L, v3f p); void pushFloatPos(lua_State *L, v3f p);
void push_v3f (lua_State *L, v3f p); void push_v3f(lua_State *L, v3f p);
void push_v2f (lua_State *L, v2f p); void push_v2f(lua_State *L, v2f p);
void push_aabb3f_vector (lua_State *L, const std::vector<aabb3f> &boxes, void push_aabb3f_vector(lua_State *L, const std::vector<aabb3f> &boxes,
f32 divisor = 1.0f); f32 divisor = 1.0f);
void warn_if_field_exists(lua_State *L, int table, void warn_if_field_exists(lua_State *L, int table, const char *fieldname,
const char *fieldname, std::string_view name, std::string_view message);
std::string_view name,
std::string_view message);
size_t write_array_slice_float(lua_State *L, int table_index, float *data, size_t write_array_slice_float(lua_State *L, int table_index, float *data,
v3u16 data_size, v3u16 slice_offset, v3u16 slice_size); v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);
// This must match the implementation in builtin/game/misc_s.lua // This must match the implementation in builtin/game/misc_s.lua
// Note that this returns a floating point result as Lua integers are 32-bit // Note that this returns a floating point result as Lua integers are 32-bit

View file

@ -445,13 +445,13 @@ int LuaItemStack::l_equals(lua_State *L)
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
LuaItemStack *o1 = checkObject<LuaItemStack>(L, 1); LuaItemStack *o1 = checkObject<LuaItemStack>(L, 1);
// checks for non-userdata argument // checks for non-userdata argument
if (!lua_isuserdata(L, 2)) { if (!lua_isuserdata(L, 2)) {
lua_pushboolean(L, false); lua_pushboolean(L, false);
return 1; return 1;
} }
// check that the argument is an ItemStack // check that the argument is an ItemStack
if (!lua_getmetatable(L, 2)) { if (!lua_getmetatable(L, 2)) {
lua_pushboolean(L, false); lua_pushboolean(L, false);
return 1; return 1;

View file

@ -182,16 +182,16 @@ int LuaSettings::l_get_flags(lua_State *L)
// get_pos(self, key) -> vector or nil // get_pos(self, key) -> vector or nil
int LuaSettings::l_get_pos(lua_State *L) int LuaSettings::l_get_pos(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
LuaSettings *o = checkObject<LuaSettings>(L, 1); LuaSettings *o = checkObject<LuaSettings>(L, 1);
std::string key = luaL_checkstring(L, 2); std::string key = luaL_checkstring(L, 2);
std::optional<v3f> pos; std::optional<v3f> pos;
if (o->m_settings->getV3FNoEx(key, pos) && pos.has_value()) if (o->m_settings->getV3FNoEx(key, pos) && pos.has_value())
push_v3f(L, *pos); push_v3f(L, *pos);
else else
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
} }
// set(self, key, value) // set(self, key, value)
@ -247,17 +247,17 @@ int LuaSettings::l_set_np_group(lua_State *L)
// set_pos(self, key, value) // set_pos(self, key, value)
int LuaSettings::l_set_pos(lua_State *L) int LuaSettings::l_set_pos(lua_State *L)
{ {
NO_MAP_LOCK_REQUIRED; NO_MAP_LOCK_REQUIRED;
LuaSettings *o = checkObject<LuaSettings>(L, 1); LuaSettings *o = checkObject<LuaSettings>(L, 1);
std::string key = luaL_checkstring(L, 2); std::string key = luaL_checkstring(L, 2);
v3f value = check_v3f(L, 3); v3f value = check_v3f(L, 3);
CHECK_SETTING_SECURITY(L, key); CHECK_SETTING_SECURITY(L, key);
o->m_settings->setV3F(key, value); o->m_settings->setV3F(key, value);
return 0; return 0;
} }
// remove(self, key) -> success // remove(self, key) -> success
@ -389,11 +389,11 @@ const luaL_Reg LuaSettings::methods[] = {
luamethod(LuaSettings, get_bool), luamethod(LuaSettings, get_bool),
luamethod(LuaSettings, get_np_group), luamethod(LuaSettings, get_np_group),
luamethod(LuaSettings, get_flags), luamethod(LuaSettings, get_flags),
luamethod(LuaSettings, get_pos), luamethod(LuaSettings, get_pos),
luamethod(LuaSettings, set), luamethod(LuaSettings, set),
luamethod(LuaSettings, set_bool), luamethod(LuaSettings, set_bool),
luamethod(LuaSettings, set_np_group), luamethod(LuaSettings, set_np_group),
luamethod(LuaSettings, set_pos), luamethod(LuaSettings, set_pos),
luamethod(LuaSettings, remove), luamethod(LuaSettings, remove),
luamethod(LuaSettings, get_names), luamethod(LuaSettings, get_names),
luamethod(LuaSettings, has), luamethod(LuaSettings, has),

View file

@ -29,8 +29,8 @@ private:
// get_flags(self, key) -> key/value table // get_flags(self, key) -> key/value table
static int l_get_flags(lua_State *L); static int l_get_flags(lua_State *L);
// get_pos(self, key) -> vector or nil // get_pos(self, key) -> vector or nil
static int l_get_pos(lua_State *L); static int l_get_pos(lua_State *L);
// set(self, key, value) // set(self, key, value)
static int l_set(lua_State *L); static int l_set(lua_State *L);
@ -41,8 +41,8 @@ private:
// set_np_group(self, key, value) // set_np_group(self, key, value)
static int l_set_np_group(lua_State *L); static int l_set_np_group(lua_State *L);
// set_pos(self, key, value) // set_pos(self, key, value)
static int l_set_pos(lua_State *L); static int l_set_pos(lua_State *L);
// remove(self, key) -> success // remove(self, key) -> success
static int l_remove(lua_State *L); static int l_remove(lua_State *L);

View file

@ -2626,9 +2626,9 @@ void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_co
std::string lang_suffixes[3]; std::string lang_suffixes[3];
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
lang_suffixes[i].append(".").append(lang_code).append(translation_formats[i]); lang_suffixes[i].append(".").append(lang_code).append(translation_formats[i]);
} }
auto include = [&] (const std::string &name, const MediaInfo &info) -> bool { auto include = [&] (const std::string &name, const MediaInfo &info) -> bool {
if (info.no_announce) if (info.no_announce)
return false; return false;
for (size_t j = 0; j < 3; j++) { for (size_t j = 0; j < 3; j++) {
@ -3890,13 +3890,13 @@ v3f Server::findSpawnPos()
{ {
ServerMap &map = m_env->getServerMap(); ServerMap &map = m_env->getServerMap();
std::optional<v3f> staticSpawnPoint; std::optional<v3f> staticSpawnPoint;
if (g_settings->getV3FNoEx("static_spawnpoint", staticSpawnPoint) && staticSpawnPoint.has_value()) if (g_settings->getV3FNoEx("static_spawnpoint", staticSpawnPoint) && staticSpawnPoint.has_value())
{ {
return *staticSpawnPoint * BS; return *staticSpawnPoint * BS;
} }
v3f nodeposf; v3f nodeposf;
bool is_good = false; bool is_good = false;
// Limit spawn range to mapgen edges (determined by 'mapgen_limit') // Limit spawn range to mapgen edges (determined by 'mapgen_limit')

View file

@ -627,9 +627,9 @@ bool Settings::getNoiseParamsFromGroup(const std::string &name,
group->getFloatNoEx("offset", np.offset); group->getFloatNoEx("offset", np.offset);
group->getFloatNoEx("scale", np.scale); group->getFloatNoEx("scale", np.scale);
std::optional<v3f> spread; std::optional<v3f> spread;
if (group->getV3FNoEx("spread", spread) && spread.has_value()) if (group->getV3FNoEx("spread", spread) && spread.has_value())
np.spread = *spread; np.spread = *spread;
group->getS32NoEx("seed", np.seed); group->getS32NoEx("seed", np.seed);
group->getU16NoEx("octaves", np.octaves); group->getU16NoEx("octaves", np.octaves);

View file

@ -9,7 +9,7 @@
using matrix4 = core::matrix4; using matrix4 = core::matrix4;
static bool matrix_equals(const matrix4 &a, const matrix4 &b) { static bool matrix_equals(const matrix4 &a, const matrix4 &b) {
return a.equals(b, 0.00001f); return a.equals(b, 0.00001f);
} }
constexpr v3f x{1, 0, 0}; constexpr v3f x{1, 0, 0};
@ -19,68 +19,68 @@ constexpr v3f z{0, 0, 1};
TEST_CASE("matrix4") { TEST_CASE("matrix4") {
SECTION("setRotationRadians") { SECTION("setRotationRadians") {
SECTION("rotation order is ZYX (matrix notation)") { SECTION("rotation order is ZYX (matrix notation)") {
v3f rot{1, 2, 3}; v3f rot{1, 2, 3};
matrix4 X, Y, Z, ZYX; matrix4 X, Y, Z, ZYX;
X.setRotationRadians({rot.X, 0, 0}); X.setRotationRadians({rot.X, 0, 0});
Y.setRotationRadians({0, rot.Y, 0}); Y.setRotationRadians({0, rot.Y, 0});
Z.setRotationRadians({0, 0, rot.Z}); Z.setRotationRadians({0, 0, rot.Z});
ZYX.setRotationRadians(rot); ZYX.setRotationRadians(rot);
CHECK(!matrix_equals(X * Y * Z, ZYX)); CHECK(!matrix_equals(X * Y * Z, ZYX));
CHECK(!matrix_equals(X * Z * Y, ZYX)); CHECK(!matrix_equals(X * Z * Y, ZYX));
CHECK(!matrix_equals(Y * X * Z, ZYX)); CHECK(!matrix_equals(Y * X * Z, ZYX));
CHECK(!matrix_equals(Y * Z * X, ZYX)); CHECK(!matrix_equals(Y * Z * X, ZYX));
CHECK(!matrix_equals(Z * X * Y, ZYX)); CHECK(!matrix_equals(Z * X * Y, ZYX));
CHECK(matrix_equals(Z * Y * X, ZYX)); CHECK(matrix_equals(Z * Y * X, ZYX));
} }
const f32 quarter_turn = core::PI / 2; const f32 quarter_turn = core::PI / 2;
// See https://en.wikipedia.org/wiki/Right-hand_rule#/media/File:Cartesian_coordinate_system_handedness.svg // See https://en.wikipedia.org/wiki/Right-hand_rule#/media/File:Cartesian_coordinate_system_handedness.svg
// for a visualization of what handedness means for rotations // for a visualization of what handedness means for rotations
SECTION("rotation is right-handed") { SECTION("rotation is right-handed") {
SECTION("rotation around the X-axis is Z-up, counter-clockwise") { SECTION("rotation around the X-axis is Z-up, counter-clockwise") {
matrix4 X; matrix4 X;
X.setRotationRadians({quarter_turn, 0, 0}); X.setRotationRadians({quarter_turn, 0, 0});
CHECK(X.transformVect(x).equals(x)); CHECK(X.transformVect(x).equals(x));
CHECK(X.transformVect(y).equals(z)); CHECK(X.transformVect(y).equals(z));
CHECK(X.transformVect(z).equals(-y)); CHECK(X.transformVect(z).equals(-y));
} }
SECTION("rotation around the Y-axis is Z-up, clockwise") { SECTION("rotation around the Y-axis is Z-up, clockwise") {
matrix4 Y; matrix4 Y;
Y.setRotationRadians({0, quarter_turn, 0}); Y.setRotationRadians({0, quarter_turn, 0});
CHECK(Y.transformVect(y).equals(y)); CHECK(Y.transformVect(y).equals(y));
CHECK(Y.transformVect(x).equals(-z)); CHECK(Y.transformVect(x).equals(-z));
CHECK(Y.transformVect(z).equals(x)); CHECK(Y.transformVect(z).equals(x));
} }
SECTION("rotation around the Z-axis is Y-up, counter-clockwise") { SECTION("rotation around the Z-axis is Y-up, counter-clockwise") {
matrix4 Z; matrix4 Z;
Z.setRotationRadians({0, 0, quarter_turn}); Z.setRotationRadians({0, 0, quarter_turn});
CHECK(Z.transformVect(z).equals(z)); CHECK(Z.transformVect(z).equals(z));
CHECK(Z.transformVect(x).equals(y)); CHECK(Z.transformVect(x).equals(y));
CHECK(Z.transformVect(y).equals(-x)); CHECK(Z.transformVect(y).equals(-x));
} }
} }
} }
SECTION("getScale") { SECTION("getScale") {
SECTION("correctly gets the length of each row of the 3x3 submatrix") { SECTION("correctly gets the length of each row of the 3x3 submatrix") {
matrix4 A( matrix4 A(
1, 2, 3, 0, 1, 2, 3, 0,
4, 5, 6, 0, 4, 5, 6, 0,
7, 8, 9, 0, 7, 8, 9, 0,
0, 0, 0, 1 0, 0, 0, 1
); );
v3f scale = A.getScale(); v3f scale = A.getScale();
CHECK(scale.equals(v3f( CHECK(scale.equals(v3f(
v3f(1, 2, 3).getLength(), v3f(1, 2, 3).getLength(),
v3f(4, 5, 6).getLength(), v3f(4, 5, 6).getLength(),
v3f(7, 8, 9).getLength() v3f(7, 8, 9).getLength()
))); )));
} }
} }
} }

View file

@ -42,14 +42,14 @@ const char *TestSettings::config_text_before =
"floaty_thing = 1.1\n" "floaty_thing = 1.1\n"
"stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n" "stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n"
"coord = (1, 2, 4.5)\n" "coord = (1, 2, 4.5)\n"
"coord_invalid = (1,2,3\n" "coord_invalid = (1,2,3\n"
"coord_invalid_2 = 1, 2, 3 test\n" "coord_invalid_2 = 1, 2, 3 test\n"
"coord_invalid_3 = (test, something, stupid)\n" "coord_invalid_3 = (test, something, stupid)\n"
"coord_invalid_4 = (1, test, 3)\n" "coord_invalid_4 = (1, test, 3)\n"
"coord_invalid_5 = ()\n" "coord_invalid_5 = ()\n"
"coord_invalid_6 = (1, 2)\n" "coord_invalid_6 = (1, 2)\n"
"coord_invalid_7 = (1)\n" "coord_invalid_7 = (1)\n"
"coord_no_parenthesis = 1,2,3\n" "coord_no_parenthesis = 1,2,3\n"
" # this is just a comment\n" " # this is just a comment\n"
"this is an invalid line\n" "this is an invalid line\n"
"asdf = {\n" "asdf = {\n"
@ -103,14 +103,14 @@ const char *TestSettings::config_text_after =
"}\n" "}\n"
"zoop = true\n" "zoop = true\n"
"coord2 = (1,2,3.25)\n" "coord2 = (1,2,3.25)\n"
"coord_invalid = (1,2,3\n" "coord_invalid = (1,2,3\n"
"coord_invalid_2 = 1, 2, 3 test\n" "coord_invalid_2 = 1, 2, 3 test\n"
"coord_invalid_3 = (test, something, stupid)\n" "coord_invalid_3 = (test, something, stupid)\n"
"coord_invalid_4 = (1, test, 3)\n" "coord_invalid_4 = (1, test, 3)\n"
"coord_invalid_5 = ()\n" "coord_invalid_5 = ()\n"
"coord_invalid_6 = (1, 2)\n" "coord_invalid_6 = (1, 2)\n"
"coord_invalid_7 = (1)\n" "coord_invalid_7 = (1)\n"
"coord_no_parenthesis = 1,2,3\n" "coord_no_parenthesis = 1,2,3\n"
"floaty_thing_2 = 1.25\n" "floaty_thing_2 = 1.25\n"
"groupy_thing = {\n" "groupy_thing = {\n"
" animals = cute\n" " animals = cute\n"
@ -169,20 +169,20 @@ void TestSettings::testAllSettings()
UASSERT(s.getV3F("coord2").value().Y == 2.0); UASSERT(s.getV3F("coord2").value().Y == 2.0);
UASSERT(s.getV3F("coord2").value().Z == 3.25); UASSERT(s.getV3F("coord2").value().Z == 3.25);
std::optional<v3f> testNotExist; std::optional<v3f> testNotExist;
UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist)); UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist));
EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist")); EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist"));
UASSERT(!s.getV3F("coord_invalid").has_value()); UASSERT(!s.getV3F("coord_invalid").has_value());
UASSERT(!s.getV3F("coord_invalid_2").has_value()); UASSERT(!s.getV3F("coord_invalid_2").has_value());
UASSERT(!s.getV3F("coord_invalid_3").has_value()); UASSERT(!s.getV3F("coord_invalid_3").has_value());
UASSERT(!s.getV3F("coord_invalid_4").has_value()); UASSERT(!s.getV3F("coord_invalid_4").has_value());
UASSERT(!s.getV3F("coord_invalid_5").has_value()); UASSERT(!s.getV3F("coord_invalid_5").has_value());
UASSERT(!s.getV3F("coord_invalid_6").has_value()); UASSERT(!s.getV3F("coord_invalid_6").has_value());
UASSERT(!s.getV3F("coord_invalid_7").has_value()); UASSERT(!s.getV3F("coord_invalid_7").has_value());
std::optional<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis"); std::optional<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis");
UASSERT(testNoParenthesis.value() == v3f(1, 2, 3)); UASSERT(testNoParenthesis.value() == v3f(1, 2, 3));
// Test settings groups // Test settings groups
Settings *group = s.getGroup("asdf"); Settings *group = s.getGroup("asdf");

View file

@ -405,9 +405,9 @@ inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxi
inline float cycle_shift(float value, float by = 0, float max = 1) inline float cycle_shift(float value, float by = 0, float max = 1)
{ {
if (value + by < 0) return value + by + max; if (value + by < 0) return value + by + max;
if (value + by > max) return value + by - max; if (value + by > max) return value + by - max;
return value + by; return value + by;
} }
inline bool is_power_of_two(u32 n) inline bool is_power_of_two(u32 n)

View file

@ -1070,39 +1070,39 @@ void safe_print_string(std::ostream &os, std::string_view str)
std::optional<v3f> str_to_v3f(std::string_view str) std::optional<v3f> str_to_v3f(std::string_view str)
{ {
str = trim(str); str = trim(str);
if (str.empty()) if (str.empty())
return std::nullopt; return std::nullopt;
// Strip parentheses if they exist // Strip parentheses if they exist
if (str.front() == '(' && str.back() == ')') { if (str.front() == '(' && str.back() == ')') {
str.remove_prefix(1); str.remove_prefix(1);
str.remove_suffix(1); str.remove_suffix(1);
str = trim(str); str = trim(str);
} }
std::istringstream iss((std::string(str))); std::istringstream iss((std::string(str)));
const auto expect_delimiter = [&]() { const auto expect_delimiter = [&]() {
const auto c = iss.get(); const auto c = iss.get();
return c == ' ' || c == ','; return c == ' ' || c == ',';
}; };
v3f value; v3f value;
if (!(iss >> value.X)) if (!(iss >> value.X))
return std::nullopt; return std::nullopt;
if (!expect_delimiter()) if (!expect_delimiter())
return std::nullopt; return std::nullopt;
if (!(iss >> value.Y)) if (!(iss >> value.Y))
return std::nullopt; return std::nullopt;
if (!expect_delimiter()) if (!expect_delimiter())
return std::nullopt; return std::nullopt;
if (!(iss >> value.Z)) if (!(iss >> value.Z))
return std::nullopt; return std::nullopt;
if (!iss.eof()) if (!iss.eof())
return std::nullopt; return std::nullopt;
return value; return value;
} }

View file

@ -753,9 +753,9 @@ inline std::string stringw_to_utf8(const irr::core::stringw &input)
return wide_to_utf8(sv); return wide_to_utf8(sv);
} }
/** /**
* Create an irr::core:stringw from a UTF8 std::string. * Create an irr::core:stringw from a UTF8 std::string.
*/ */
inline irr::core::stringw utf8_to_stringw(std::string_view input) inline irr::core::stringw utf8_to_stringw(std::string_view input)
{ {
std::wstring str = utf8_to_wide(input); std::wstring str = utf8_to_wide(input);