diff --git a/.github/workflows/whitespace_checks.yml b/.github/workflows/whitespace_checks.yml index 7f6f615cc26ef..b5fcc02e52863 100644 --- a/.github/workflows/whitespace_checks.yml +++ b/.github/workflows/whitespace_checks.yml @@ -34,7 +34,16 @@ jobs: - uses: actions/checkout@v4 # Line endings are already ensured by .gitattributes - 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: runs-on: ubuntu-latest @@ -46,21 +55,51 @@ jobs: # So lines like: "/* */ /*" or "*/ a = 5; /*" will result in error - name: Check for unsupported multiline comments 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 | 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 + 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 |\ + 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 # See python script ./util/ci/indent_tab_preprocess.py for details. - name: Preprocess files 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 | grep -E '\.lua$' | xargs -L 1 -P $(($(nproc) + 1)) python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]" + 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 |\ + grep -E '\.lua$' |\ + xargs -L 1 -P $(($(nproc) + 1)) \ + python3 ./util/ci/indent_tab_preprocess.py "--[[" "]]" # Check for bad indent. # This runs over preprocessed files. # If there is any remaining space on line beginning or after tab, # error is generated - name: Check indent spaces 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: runs-on: ubuntu-latest @@ -68,6 +107,12 @@ jobs: - uses: actions/checkout@v4 # Some files should not contain tabs - 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 diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index fb1d2a7d9feb9..7a8558cbd4b0c 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -389,7 +389,7 @@ function vector.random_direction() local x, y, z, l2 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 - l2 = x*x + y*y + z*z + l2 = x*x + y*y + z*z until l2 <= 1 and l2 >= 1e-6 -- normalize local l = math.sqrt(l2) diff --git a/builtin/fstk/buttonbar.lua b/builtin/fstk/buttonbar.lua index ed478af82d4c4..577eb7c6dc1ea 100644 --- a/builtin/fstk/buttonbar.lua +++ b/builtin/fstk/buttonbar.lua @@ -38,7 +38,7 @@ local function buttonbar_formspec(self) -- `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 - -- buttons were visible. + -- buttons were visible. 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)) diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 6abd16c5890a0..c6893e2b8530c 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -78,7 +78,7 @@ core.register_entity(":__builtin:falling_node", { self.floats = core.get_item_group(node.name, "float") ~= 0 -- Save liquidtype for falling water - self.liquidtype = def.liquidtype + self.liquidtype = def.liquidtype -- Set entity visuals if def.drawtype == "torchlike" or def.drawtype == "signlike" then diff --git a/builtin/game/misc_s.lua b/builtin/game/misc_s.lua index 07ab09b3782c0..1e9b6d952fb3b 100644 --- a/builtin/game/misc_s.lua +++ b/builtin/game/misc_s.lua @@ -36,7 +36,7 @@ end function core.setting_get_pos(name) - return core.settings:get_pos(name) + return core.settings:get_pos(name) end diff --git a/builtin/mainmenu/dlg_clients_list.lua b/builtin/mainmenu/dlg_clients_list.lua index 2ea021c5e63a4..324d41efd4ffb 100644 --- a/builtin/mainmenu/dlg_clients_list.lua +++ b/builtin/mainmenu/dlg_clients_list.lua @@ -32,7 +32,7 @@ end local function clients_list_buttonhandler(this, fields) if fields.quit then - this:delete() + this:delete() return true end return false diff --git a/builtin/mainmenu/dlg_server_list_mods.lua b/builtin/mainmenu/dlg_server_list_mods.lua index ad44ac37f8ca4..fc392ae067a7c 100644 --- a/builtin/mainmenu/dlg_server_list_mods.lua +++ b/builtin/mainmenu/dlg_server_list_mods.lua @@ -76,7 +76,7 @@ end local function buttonhandler(this, fields) if fields.quit then - this:delete() + this:delete() return true end diff --git a/games/devtest/mods/soundstuff/racecar.lua b/games/devtest/mods/soundstuff/racecar.lua index 916279231e35c..92adc75090895 100644 --- a/games/devtest/mods/soundstuff/racecar.lua +++ b/games/devtest/mods/soundstuff/racecar.lua @@ -4,14 +4,14 @@ local drive_distance = 30 core.register_entity("soundstuff:racecar", { initial_properties = { - physical = false, - 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}, - visual = "upright_sprite", - visual_size = {x = 1, y = 1, z = 1}, - textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"}, - static_save = false, - }, + physical = false, + 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}, + visual = "upright_sprite", + visual_size = {x = 1, y = 1, z = 1}, + textures = {"soundstuff_racecar.png", "soundstuff_racecar.png^[transformFX"}, + static_save = false, + }, on_activate = function(self, _staticdata, _dtime_s) self.min_x = self.object:get_pos().x - drive_distance * 0.5 diff --git a/games/devtest/mods/testentities/selectionbox.lua b/games/devtest/mods/testentities/selectionbox.lua index 8885a2a95ee1b..eb8761a2bc281 100644 --- a/games/devtest/mods/testentities/selectionbox.lua +++ b/games/devtest/mods/testentities/selectionbox.lua @@ -68,7 +68,7 @@ core.register_globalstep(function() hud_ids[pname] = hud_id or player:hud_add({ type = "text", -- See HUD element types position = {x=0.5, y=0.5}, - text = "X", + text = "X", number = 0xFF0000, alignment = {x=0, y=0}, }) diff --git a/games/devtest/mods/testitems/init.lua b/games/devtest/mods/testitems/init.lua index 71a85ef6d27c0..90407109a323c 100644 --- a/games/devtest/mods/testitems/init.lua +++ b/games/devtest/mods/testitems/init.lua @@ -110,15 +110,15 @@ core.register_craftitem("testitems:telescope_stick", { -- Tree spawners local tree_def={ - axiom="Af", - rules_a="TT[&GB][&+GB][&++GB][&+++GB]A", - rules_b="[+GB]fB", - trunk="basenodes:tree", - leaves="basenodes:leaves", - angle=90, - iterations=4, - trunk_type="single", - thin_branches=true, + axiom="Af", + rules_a="TT[&GB][&+GB][&++GB][&+++GB]A", + rules_b="[+GB]fB", + trunk="basenodes:tree", + leaves="basenodes:leaves", + angle=90, + iterations=4, + trunk_type="single", + thin_branches=true, } core.register_craftitem("testitems:tree_spawner", { diff --git a/games/devtest/mods/tiled/init.lua b/games/devtest/mods/tiled/init.lua index 51e1fda21fd5b..ea34ea1b1a6ed 100644 --- a/games/devtest/mods/tiled/init.lua +++ b/games/devtest/mods/tiled/init.lua @@ -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" core.register_node("tiled:tiled", { - description = "Tiled Node (world-aligned)".."\n"..align_help, - tiles = {{ - name = "tiled_tiled.png", - align_style = "world", - scale = 8, - }}, - groups = {cracky=3}, + description = "Tiled Node (world-aligned)".."\n"..align_help, + tiles = {{ + name = "tiled_tiled.png", + align_style = "world", + scale = 8, + }}, + groups = {cracky=3}, }) core.register_node("tiled:tiled_rooted", { - description = "Tiled 'plantlike_rooted' Node (world-aligned)".."\n".. - "Base node texture spans over a space of 8×8 nodes".."\n".. - "A plantlike thing grows on top", - paramtype = "light", - drawtype = "plantlike_rooted", - tiles = {{ - name = "tiled_tiled.png", - align_style = "world", - scale = 8, - }}, - special_tiles = {"tiled_tiled_node.png"}, - groups = {cracky=3}, + description = + "Tiled 'plantlike_rooted' Node (world-aligned)".."\n".. + "Base node texture spans over a space of 8×8 nodes".."\n".. + "A plantlike thing grows on top", + paramtype = "light", + drawtype = "plantlike_rooted", + tiles = {{ + name = "tiled_tiled.png", + align_style = "world", + scale = 8, + }}, + special_tiles = {"tiled_tiled_node.png"}, + groups = {cracky=3}, }) core.register_node("tiled:tiled_n", { - description = "Tiled Node (node-aligned)".."\n"..align_help_n, - tiles = {{ - name = "tiled_tiled_node.png", - align_style = "node", - }}, - groups = {cracky=3}, + description = "Tiled Node (node-aligned)".."\n"..align_help_n, + tiles = {{ + name = "tiled_tiled_node.png", + align_style = "node", + }}, + groups = {cracky=3}, }) stairs.register_stair_and_slab("tiled_n", "tiled:tiled_n", diff --git a/games/devtest/mods/unittests/color.lua b/games/devtest/mods/unittests/color.lua index 86154445ce1c5..116417ed4e59f 100644 --- a/games/devtest/mods/unittests/color.lua +++ b/games/devtest/mods/unittests/color.lua @@ -1,17 +1,17 @@ local function assert_colors_equal(c1, c2) - 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) - else - assert(c1 == c2) - end + 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) + else + assert(c1 == c2) + end end 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(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("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("#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("#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("gren"), nil) end unittests.register("test_color_conversion", test_color_conversion) diff --git a/games/devtest/mods/unittests/get_version.lua b/games/devtest/mods/unittests/get_version.lua index 7ef78257d04eb..9903ac381bb7e 100644 --- a/games/devtest/mods/unittests/get_version.lua +++ b/games/devtest/mods/unittests/get_version.lua @@ -1,16 +1,16 @@ unittests.register("test_get_version", function() - local version = core.get_version() - assert(type(version) == "table") - assert(type(version.project) == "string") - assert(type(version.string) == "string") - assert(type(version.proto_min) == "number") - assert(type(version.proto_max) == "number") - assert(version.proto_max >= version.proto_min) - assert(type(version.is_dev) == "boolean") - if version.is_dev then - assert(type(version.hash) == "string") - else - assert(version.hash == nil) - end + local version = core.get_version() + assert(type(version) == "table") + assert(type(version.project) == "string") + assert(type(version.string) == "string") + assert(type(version.proto_min) == "number") + assert(type(version.proto_max) == "number") + assert(version.proto_max >= version.proto_min) + assert(type(version.is_dev) == "boolean") + if version.is_dev then + assert(type(version.hash) == "string") + else + assert(version.hash == nil) + end end) diff --git a/games/devtest/mods/unittests/raycast.lua b/games/devtest/mods/unittests/raycast.lua index 1dc196cc5d481..0c05845303b05 100644 --- a/games/devtest/mods/unittests/raycast.lua +++ b/games/devtest/mods/unittests/raycast.lua @@ -1,36 +1,36 @@ local function raycast_with_pointabilities(start_pos, end_pos, pointabilities) local ray = core.raycast(start_pos, end_pos, nil, nil, pointabilities) for hit in ray do - if hit.type == "node" then - return hit.under - end + if hit.type == "node" then + return hit.under + end end - return nil + return nil end local function test_raycast_pointabilities(player, pos1) - local pos2 = pos1:offset(0, 0, 1) - local pos3 = pos1:offset(0, 0, 2) + local pos2 = pos1:offset(0, 0, 1) + local pos3 = pos1:offset(0, 0, 2) - local oldnode1 = core.get_node(pos1) - local oldnode2 = core.get_node(pos2) - local oldnode3 = core.get_node(pos3) - core.swap_node(pos1, {name = "air"}) - core.swap_node(pos2, {name = "testnodes:not_pointable"}) - core.swap_node(pos3, {name = "testnodes:pointable"}) + local oldnode1 = core.get_node(pos1) + local oldnode2 = core.get_node(pos2) + local oldnode3 = core.get_node(pos3) + core.swap_node(pos1, {name = "air"}) + core.swap_node(pos2, {name = "testnodes:not_pointable"}) + core.swap_node(pos3, {name = "testnodes:pointable"}) - local p = nil - assert(raycast_with_pointabilities(pos1, pos3, p) == pos3) + local p = nil + assert(raycast_with_pointabilities(pos1, pos3, p) == pos3) - p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities - assert(raycast_with_pointabilities(pos1, pos3, p) == nil) + p = core.registered_items["testtools:blocked_pointing_staff"].pointabilities + assert(raycast_with_pointabilities(pos1, pos3, p) == nil) - p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities - assert(raycast_with_pointabilities(pos1, pos3, p) == pos2) + p = core.registered_items["testtools:ultimate_pointing_staff"].pointabilities + assert(raycast_with_pointabilities(pos1, pos3, p) == pos2) - core.swap_node(pos1, oldnode1) - core.swap_node(pos2, oldnode2) - core.swap_node(pos3, oldnode3) + core.swap_node(pos1, oldnode1) + core.swap_node(pos2, oldnode2) + core.swap_node(pos3, oldnode3) end unittests.register("test_raycast_pointabilities", test_raycast_pointabilities, {map=true}) diff --git a/games/devtest/mods/util_commands/init.lua b/games/devtest/mods/util_commands/init.lua index 8341901a82af8..a413e7fa78584 100644 --- a/games/devtest/mods/util_commands/init.lua +++ b/games/devtest/mods/util_commands/init.lua @@ -234,10 +234,10 @@ core.register_chatcommand("dump_wear_bar", { }) core.register_chatcommand("set_saturation", { - params = "", - description = "Set the saturation for current player.", - func = function(player_name, param) - local saturation = tonumber(param) - core.get_player_by_name(player_name):set_lighting({saturation = saturation }) - end + params = "", + description = "Set the saturation for current player.", + func = function(player_name, param) + local saturation = tonumber(param) + core.get_player_by_name(player_name):set_lighting({saturation = saturation }) + end }) diff --git a/src/client/content_cso.cpp b/src/client/content_cso.cpp index ac455d9eb1d7e..ce3f91527652c 100644 --- a/src/client/content_cso.cpp +++ b/src/client/content_cso.cpp @@ -39,7 +39,7 @@ class SmokePuffCSO: public ClientSimpleObject MapNode n = env->getMap().getNode(floatToInt(pos, BS), &pos_ok); light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(), env->getGameDef()->ndef()->getLightingFlags(n))) - : 64; + : 64; video::SColor color(255,light,light,light); m_spritenode->setColor(color); } diff --git a/src/client/game.cpp b/src/client/game.cpp index d2da5dda311c2..e9d6278d0f130 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3793,8 +3793,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, float old_brightness = sky->getBrightness(); direct_brightness = client->getEnv().getClientMap() .getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS), - daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen) - / 255.0; + daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen) + / 255.0; } float time_of_day_smooth = runData.time_of_day_smooth; diff --git a/src/clientdynamicinfo.cpp b/src/clientdynamicinfo.cpp index 46283b33c1b9e..717e7813f996b 100644 --- a/src/clientdynamicinfo.cpp +++ b/src/clientdynamicinfo.cpp @@ -13,32 +13,32 @@ ClientDynamicInfo ClientDynamicInfo::getCurrent() { - v2u32 screen_size = RenderingEngine::getWindowSize(); - f32 density = RenderingEngine::getDisplayDensity(); - 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 real_gui_scaling = gui_scaling * density; - f32 real_hud_scaling = hud_scaling * density; - bool touch_controls = g_touchcontrols; - - return { - screen_size, real_gui_scaling, real_hud_scaling, - ClientDynamicInfo::calculateMaxFSSize(screen_size, density, gui_scaling), - touch_controls - }; + v2u32 screen_size = RenderingEngine::getWindowSize(); + f32 density = RenderingEngine::getDisplayDensity(); + 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 real_gui_scaling = gui_scaling * density; + f32 real_hud_scaling = hud_scaling * density; + bool touch_controls = g_touchcontrols; + + return { + screen_size, real_gui_scaling, real_hud_scaling, + ClientDynamicInfo::calculateMaxFSSize(screen_size, density, gui_scaling), + touch_controls + }; } v2f32 ClientDynamicInfo::calculateMaxFSSize(v2u32 render_target_size, f32 density, f32 gui_scaling) { // 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, - screen_dpi, gui_scaling); - return v2f32(render_target_size.X / prefer_imgsize, - render_target_size.Y / prefer_imgsize); + screen_dpi, gui_scaling); + return v2f32(render_target_size.X / prefer_imgsize, + render_target_size.Y / prefer_imgsize); } #endif diff --git a/src/filesys.cpp b/src/filesys.cpp index a368bc6970f37..3597e019a8e6d 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -104,7 +104,7 @@ std::vector GetDirListing(const std::string &pathstring) << " Error is " << dwError << std::endl; listing.clear(); return listing; - } + } } return listing; } @@ -715,7 +715,7 @@ bool PathStartsWith(const std::string &path, const std::string &prefix) if(prefixpos == prefixsize) return true; // Return false if path has ended (at delimiter/EOS) - // while prefix did not. + // while prefix did not. if(pathpos == pathsize) return false; } diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 7478c389d8f88..0595832a1ff86 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3892,7 +3892,7 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode) fields[name] = "CHG:" + itos(e->getPos()); else fields[name] = "VAL:" + itos(e->getPos()); - } + } } else if (s.ftype == f_AnimatedImage) { // No dynamic cast possible due to some distributions shipped // without rtti support in Irrlicht @@ -5056,7 +5056,7 @@ double GUIFormSpecMenu::calculateImgsize(const parserData &data) { // 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); // Fixed-size mode diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 8efd81d0f0d81..5446038b0c4d1 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -777,7 +777,7 @@ void TextDrawer::place(const core::rect &dest_rect) std::max(f.margin, p.margin); } 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 left = right; } diff --git a/src/gui/touchcontrols.cpp b/src/gui/touchcontrols.cpp index 6ba3e7b9e8e16..334c664e4727c 100644 --- a/src/gui/touchcontrols.cpp +++ b/src/gui/touchcontrols.cpp @@ -475,7 +475,7 @@ void TouchControls::translateEvent(const SEvent &event) toggleOverflowMenu(); // 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 // when closing the overflow menu prevent_short_tap = true; diff --git a/src/gui/touchscreeneditor.h b/src/gui/touchscreeneditor.h index 6c70eb6936299..cedc3b42ae807 100644 --- a/src/gui/touchscreeneditor.h +++ b/src/gui/touchscreeneditor.h @@ -21,8 +21,8 @@ class GUITouchscreenLayout : public GUIModalMenu { public: GUITouchscreenLayout(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr, ISimpleTextureSource *tsrc); + gui::IGUIElement* parent, s32 id, + IMenuManager *menumgr, ISimpleTextureSource *tsrc); ~GUITouchscreenLayout(); void regenerateGui(v2u32 screensize); diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 3039ff3e1f692..47d0a4973e196 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -344,7 +344,7 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int Buffer buf; const u8 content_width = 2; const u8 params_width = 2; - if(disk) + if(disk) { MapNode *tmp_nodes = new MapNode[nodecount]; memcpy(tmp_nodes, data, nodecount * sizeof(MapNode)); diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 3778c3807aca1..1917c484c4783 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -763,7 +763,7 @@ void MapgenBasic::generateBiomes() // If no stone surface detected in mapchunk column and a water surface // biome fallback exists, add it to the biomemap. This avoids 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; } } diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index e96e4e45a9599..56346432e9026 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -172,7 +172,7 @@ int MapgenFlat::getSpawnLevelAtPoint(v2s16 p) stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { s16 rise = (n_terrain - hill_threshold) * hill_steepness; - stone_level = ground_level + rise; + stone_level = ground_level + rise; } if (ground_level < water_level) @@ -296,7 +296,7 @@ s16 MapgenFlat::generateTerrain() stone_level = ground_level - depress; } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) { 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); diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 940fe0083079e..3e28fbcac2c21 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -104,15 +104,15 @@ void MapgenFractalParams::readParams(const Settings *settings) settings->getU16NoEx("mgfractal_fractal", fractal); settings->getU16NoEx("mgfractal_iterations", iterations); - std::optional mgfractal_scale; - if (settings->getV3FNoEx("mgfractal_scale", mgfractal_scale) && mgfractal_scale.has_value()) { - scale = *mgfractal_scale; - } - - std::optional mgfractal_offset; - if (settings->getV3FNoEx("mgfractal_offset", mgfractal_offset) && mgfractal_offset.has_value()) { - offset = *mgfractal_offset; - } + std::optional mgfractal_scale; + if (settings->getV3FNoEx("mgfractal_scale", mgfractal_scale) && mgfractal_scale.has_value()) { + scale = *mgfractal_scale; + } + + std::optional mgfractal_offset; + if (settings->getV3FNoEx("mgfractal_offset", mgfractal_offset) && mgfractal_offset.has_value()) { + offset = *mgfractal_offset; + } settings->getFloatNoEx("mgfractal_slice_w", slice_w); settings->getFloatNoEx("mgfractal_julia_x", julia_x); diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index 8198cf2666475..f59696bea1ba5 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -276,29 +276,29 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, Key for Special L-System Symbols used in Axioms - 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 leaves (100% chance) - T - move forward one unit with the pen down drawing trunks only - R - move forward one unit with the pen down placing fruit - A - replace with rules set A - B - replace with rules set B - C - replace with rules set C - D - replace with rules set D - a - replace with rules set A, chance 90% - b - replace with rules set B, chance 80% - c - replace with rules set C, chance 70% - d - replace with rules set D, chance 60% - + - yaw the turtle right by angle degrees - - - yaw the turtle left by angle degrees - & - pitch the turtle down by angle degrees - ^ - pitch the turtle up by angle degrees - / - roll the turtle to the right by angle degrees - * - roll the turtle to the left by angle degrees - [ - save in stack current state info - ] - recover from stack state info - - */ + 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 leaves (100% chance) + T - move forward one unit with the pen down drawing trunks only + R - move forward one unit with the pen down placing fruit + A - replace with rules set A + B - replace with rules set B + C - replace with rules set C + D - replace with rules set D + a - replace with rules set A, chance 90% + b - replace with rules set B, chance 80% + c - replace with rules set C, chance 70% + d - replace with rules set D, chance 60% + + - yaw the turtle right by angle degrees + - - yaw the turtle left by angle degrees + & - pitch the turtle down by angle degrees + ^ - pitch the turtle up by angle degrees + / - roll the turtle to the right by angle degrees + * - roll the turtle to the left by angle degrees + [ - save in stack current state info + ] - recover from stack state info + + */ s16 x,y,z; for (s16 i = 0; i < (s16)axiom.size(); i++) { diff --git a/src/noise.cpp b/src/noise.cpp index ee1f1acdbd28c..bfd29e4ee65e0 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -160,8 +160,8 @@ void PcgRandom::getState(u64 state[2]) const void PcgRandom::setState(const u64 state[2]) { - m_state = state[0]; - m_inc = state[1]; + m_state = state[0]; + m_inc = state[1]; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/porting.h b/src/porting.h index 8b753f518fcd9..4963916f0f6bb 100644 --- a/src/porting.h +++ b/src/porting.h @@ -67,9 +67,9 @@ #ifndef _WIN32 // POSIX #include #include - #if defined(__MACH__) && defined(__APPLE__) - #include - #endif + #if defined(__MACH__) && defined(__APPLE__) + #include + #endif #endif namespace porting diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index e343d50db2af4..f6340ff291ef1 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -902,7 +902,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) lua_getfield(L, index, "selection_box"); if(lua_istable(L, -1)) f.selection_box = read_nodebox(L, -1); - lua_pop(L, 1); + lua_pop(L, 1); lua_getfield(L, index, "collision_box"); if(lua_istable(L, -1)) diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 3c8780c1ac8d3..80e85f93f80e5 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -62,130 +62,98 @@ extern struct EnumString es_TileAnimationType[]; extern const std::array object_property_keys; -void read_content_features (lua_State *L, ContentFeatures &f, - int index); -void push_content_features (lua_State *L, - const ContentFeatures &c); +void read_content_features(lua_State *L, ContentFeatures &f, int index); +void push_content_features(lua_State *L, const ContentFeatures &c); -void push_nodebox (lua_State *L, - const NodeBox &box); -void push_palette (lua_State *L, - const std::vector *palette); +void push_nodebox(lua_State *L, const NodeBox &box); +void push_palette(lua_State *L, const std::vector *palette); -TileDef read_tiledef (lua_State *L, int index, - u8 drawtype, bool special); +TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special); -void read_simplesoundspec (lua_State *L, int index, - SoundSpec &spec); -NodeBox read_nodebox (lua_State *L, int index); +void read_simplesoundspec(lua_State *L, int index, SoundSpec &spec); +NodeBox read_nodebox(lua_State *L, int index); -void read_server_sound_params (lua_State *L, int index, - ServerPlayingSound ¶ms); +void read_server_sound_params(lua_State *L, int index, + ServerPlayingSound ¶ms); -void push_dig_params (lua_State *L, - const DigParams ¶ms); -void push_hit_params (lua_State *L, - const HitParams ¶ms); +void push_dig_params(lua_State *L, const DigParams ¶ms); +void push_hit_params(lua_State *L, const HitParams ¶ms); -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); -PointabilityType read_pointability_type (lua_State *L, int index); -Pointabilities read_pointabilities (lua_State *L, int index); -void push_pointability_type (lua_State *L, PointabilityType pointable); -void push_pointabilities (lua_State *L, const Pointabilities &pointabilities); +PointabilityType read_pointability_type(lua_State *L, int index); +Pointabilities read_pointabilities(lua_State *L, int index); +void push_pointability_type(lua_State *L, PointabilityType pointable); +void push_pointabilities(lua_State *L, const Pointabilities &pointabilities); -ToolCapabilities read_tool_capabilities (lua_State *L, int table); -void push_tool_capabilities (lua_State *L, - const ToolCapabilities &prop); -WearBarParams read_wear_bar_params (lua_State *L, int table); -void push_wear_bar_params (lua_State *L, - const WearBarParams &prop); +ToolCapabilities read_tool_capabilities(lua_State *L, int table); +void push_tool_capabilities(lua_State *L, const ToolCapabilities &prop); +WearBarParams read_wear_bar_params(lua_State *L, int table); +void push_wear_bar_params(lua_State *L, const WearBarParams &prop); -void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def, - ItemDefinition &def); -void push_item_definition (lua_State *L, - const ItemDefinition &i); -void push_item_definition_full (lua_State *L, - const ItemDefinition &i); +void read_item_definition(lua_State *L, int index, + const ItemDefinition &default_def, ItemDefinition &def); +void push_item_definition(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, - ServerActiveObject *sao, - ObjectProperties *prop, - IItemDefManager *idef); +void read_object_properties(lua_State *L, int index, + ServerActiveObject *sao, + ObjectProperties *prop, + IItemDefManager *idef); -void push_object_properties (lua_State *L, - const ObjectProperties *prop); +void push_object_properties(lua_State *L, const ObjectProperties *prop); -void push_inventory_list (lua_State *L, - const InventoryList &invlist); -void push_inventory_lists (lua_State *L, - const Inventory &inv); -void read_inventory_list (lua_State *L, int tableindex, - Inventory *inv, const char *name, - IGameDef *gdef, int forcesize=-1); +void push_inventory_list(lua_State *L, const InventoryList &invlist); +void push_inventory_lists(lua_State *L, const Inventory &inv); +void read_inventory_list(lua_State *L, int tableindex, + Inventory *inv, const char *name, + IGameDef *gdef, int forcesize=-1); -MapNode readnode (lua_State *L, int index); -void pushnode (lua_State *L, const MapNode &n); +MapNode readnode(lua_State *L, int index); +void pushnode(lua_State *L, const MapNode &n); -void read_groups (lua_State *L, int index, - ItemGroupList &result); +void read_groups(lua_State *L, int index, ItemGroupList &result); -void push_groups (lua_State *L, - const ItemGroupList &groups); +void push_groups(lua_State *L, const ItemGroupList &groups); //TODO rename to "read_enum_field" -int getenumfield (lua_State *L, int table, - const char *fieldname, - const EnumString *spec, - int default_); +int getenumfield(lua_State *L, int table, const char *fieldname, + const EnumString *spec, int default_); -bool getflagsfield (lua_State *L, int table, - const char *fieldname, - FlagDesc *flagdesc, - u32 *flags, u32 *flagmask); +bool getflagsfield(lua_State *L, int table, const char *fieldname, + FlagDesc *flagdesc, u32 *flags, u32 *flagmask); -bool read_flags (lua_State *L, int index, - FlagDesc *flagdesc, - u32 *flags, u32 *flagmask); +bool read_flags(lua_State *L, int index, FlagDesc *flagdesc, + u32 *flags, u32 *flagmask); -void push_flags_string (lua_State *L, FlagDesc *flagdesc, - u32 flags, u32 flagmask); +void push_flags_string(lua_State *L, FlagDesc *flagdesc, + u32 flags, u32 flagmask); -u32 read_flags_table (lua_State *L, int table, - FlagDesc *flagdesc, u32 *flagmask); +u32 read_flags_table(lua_State *L, int table, + FlagDesc *flagdesc, u32 *flagmask); -void push_items (lua_State *L, - const std::vector &items); +void push_items(lua_State *L, const std::vector &items); -std::vector read_items (lua_State *L, - int index, - IGameDef* gdef); +std::vector read_items(lua_State *L, int index, IGameDef* gdef); -void push_simplesoundspec (lua_State *L, - const SoundSpec &spec); +void push_simplesoundspec(lua_State *L, const SoundSpec &spec); -bool string_to_enum (const EnumString *spec, - int &result, - const std::string &str); +bool string_to_enum(const EnumString *spec, + int &result, const std::string &str); -bool read_noiseparams (lua_State *L, int index, - NoiseParams *np); -void push_noiseparams (lua_State *L, NoiseParams *np); +bool read_noiseparams(lua_State *L, int index, NoiseParams *np); +void push_noiseparams(lua_State *L, NoiseParams *np); -bool read_tree_def (lua_State *L, int idx, - const NodeDefManager *ndef, - treegen::TreeDef &tree_def); +bool read_tree_def(lua_State *L, int idx, + const NodeDefManager *ndef, 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, - const Json::Value &value, - int nullindex); -void read_json_value (lua_State *L, Json::Value &root, - int index, u16 max_depth); +bool push_json_value(lua_State *L, const Json::Value &value, 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. @@ -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 = 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); diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index df47e3b2801f6..947fcd8035fda 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -21,20 +21,19 @@ extern "C" { #include } -std::string getstringfield_default(lua_State *L, int table, - const char *fieldname, const std::string &default_); -bool getboolfield_default(lua_State *L, int table, - const char *fieldname, bool default_); -float getfloatfield_default(lua_State *L, int table, - const char *fieldname, float default_); -int getintfield_default(lua_State *L, int table, - const char *fieldname, int default_); +std::string getstringfield_default(lua_State *L, int table, + const char *fieldname, const std::string &default_); +bool getboolfield_default(lua_State *L, int table, + const char *fieldname, bool default_); +float getfloatfield_default(lua_State *L, int table, + const char *fieldname, float default_); +int getintfield_default(lua_State *L, int table, + const char *fieldname, int default_); bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname); template -bool getintfield(lua_State *L, int table, - const char *fieldname, T &result) +bool getintfield(lua_State *L, int table, const char *fieldname, T &result) { lua_getfield(L, table, fieldname); 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) -v3s16 getv3s16field_default(lua_State *L, int table, - const char *fieldname, v3s16 default_); - -bool getstringfield(lua_State *L, int table, - const char *fieldname, std::string &result); -bool getstringfield(lua_State *L, int table, - const char *fieldname, std::string_view &result); -size_t getstringlistfield(lua_State *L, int table, - const char *fieldname, - std::vector *result); -bool getboolfield(lua_State *L, int table, - const char *fieldname, bool &result); -bool getfloatfield(lua_State *L, int table, - const char *fieldname, float &result); - -void setstringfield(lua_State *L, int table, - const char *fieldname, const std::string &value); -void setintfield(lua_State *L, int table, - const char *fieldname, int value); -void setfloatfield(lua_State *L, int table, - const char *fieldname, float value); -void setboolfield(lua_State *L, int table, - const char *fieldname, bool value); - -v3f checkFloatPos (lua_State *L, int index); -v2f check_v2f (lua_State *L, int index); -v3f check_v3f (lua_State *L, int index); -v3s16 check_v3s16 (lua_State *L, int index); - -v3f read_v3f (lua_State *L, int index); -v2f read_v2f (lua_State *L, int index); -v2s16 read_v2s16 (lua_State *L, int index); -v2s32 read_v2s32 (lua_State *L, int index); -video::SColor read_ARGB8 (lua_State *L, int index); -bool read_color (lua_State *L, int index, - video::SColor *color); -bool is_color_table (lua_State *L, int index); +v3s16 getv3s16field_default(lua_State *L, int table, + const char *fieldname, v3s16 default_); + +bool getstringfield(lua_State *L, int table, + const char *fieldname, std::string &result); +bool getstringfield(lua_State *L, int table, + const char *fieldname, std::string_view &result); +size_t getstringlistfield(lua_State *L, int table, + const char *fieldname, std::vector *result); +bool getboolfield(lua_State *L, int table, + const char *fieldname, bool &result); +bool getfloatfield(lua_State *L, int table, + const char *fieldname, float &result); + +void setstringfield(lua_State *L, int table, + const char *fieldname, const std::string &value); +void setintfield(lua_State *L, int table, + const char *fieldname, int value); +void setfloatfield(lua_State *L, int table, + const char *fieldname, float value); +void setboolfield(lua_State *L, int table, + const char *fieldname, bool value); + +v3f checkFloatPos(lua_State *L, int index); +v2f check_v2f(lua_State *L, int index); +v3f check_v3f(lua_State *L, int index); +v3s16 check_v3s16(lua_State *L, int index); + +v3f read_v3f(lua_State *L, int index); +v2f read_v2f(lua_State *L, int index); +v2s16 read_v2s16(lua_State *L, int index); +v2s32 read_v2s32(lua_State *L, int index); +video::SColor read_ARGB8(lua_State *L, int index); +bool read_color(lua_State *L, int index, video::SColor *color); +bool is_color_table (lua_State *L, int index); /** * 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 */ -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 read_aabb3f_vector (lua_State *L, int index, f32 scale); -size_t read_stringlist (lua_State *L, int index, - std::vector *result); - -void push_v2s16 (lua_State *L, v2s16 p); -void push_v2s32 (lua_State *L, v2s32 p); -void push_v2u32 (lua_State *L, v2u32 p); -void push_v3s16 (lua_State *L, v3s16 p); -void push_aabb3f (lua_State *L, aabb3f box, f32 divisor = 1.0f); -void push_ARGB8 (lua_State *L, video::SColor color); -void pushFloatPos (lua_State *L, v3f p); -void push_v3f (lua_State *L, v3f p); -void push_v2f (lua_State *L, v2f p); -void push_aabb3f_vector (lua_State *L, const std::vector &boxes, - f32 divisor = 1.0f); - -void warn_if_field_exists(lua_State *L, int table, - const char *fieldname, - std::string_view name, - std::string_view message); +size_t read_stringlist(lua_State *L, int index, + std::vector *result); + +void push_v2s16(lua_State *L, v2s16 p); +void push_v2s32(lua_State *L, v2s32 p); +void push_v2u32(lua_State *L, v2u32 p); +void push_v3s16(lua_State *L, v3s16 p); +void push_aabb3f(lua_State *L, aabb3f box, f32 divisor = 1.0f); +void push_ARGB8(lua_State *L, video::SColor color); +void pushFloatPos(lua_State *L, v3f p); +void push_v3f(lua_State *L, v3f p); +void push_v2f(lua_State *L, v2f p); +void push_aabb3f_vector(lua_State *L, const std::vector &boxes, + f32 divisor = 1.0f); + +void warn_if_field_exists(lua_State *L, int table, const char *fieldname, + std::string_view name, std::string_view message); 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 // Note that this returns a floating point result as Lua integers are 32-bit diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 37e23e59f150b..04182041ef0fa 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -445,13 +445,13 @@ int LuaItemStack::l_equals(lua_State *L) NO_MAP_LOCK_REQUIRED; LuaItemStack *o1 = checkObject(L, 1); - // checks for non-userdata argument + // checks for non-userdata argument if (!lua_isuserdata(L, 2)) { lua_pushboolean(L, false); return 1; } - // check that the argument is an ItemStack + // check that the argument is an ItemStack if (!lua_getmetatable(L, 2)) { lua_pushboolean(L, false); return 1; diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index b67b5d44bfbfd..089b8a01e0802 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -182,16 +182,16 @@ int LuaSettings::l_get_flags(lua_State *L) // get_pos(self, key) -> vector or nil int LuaSettings::l_get_pos(lua_State *L) { - NO_MAP_LOCK_REQUIRED; - LuaSettings *o = checkObject(L, 1); - std::string key = luaL_checkstring(L, 2); - - std::optional pos; - if (o->m_settings->getV3FNoEx(key, pos) && pos.has_value()) - push_v3f(L, *pos); - else - lua_pushnil(L); - return 1; + NO_MAP_LOCK_REQUIRED; + LuaSettings *o = checkObject(L, 1); + std::string key = luaL_checkstring(L, 2); + + std::optional pos; + if (o->m_settings->getV3FNoEx(key, pos) && pos.has_value()) + push_v3f(L, *pos); + else + lua_pushnil(L); + return 1; } // set(self, key, value) @@ -247,17 +247,17 @@ int LuaSettings::l_set_np_group(lua_State *L) // set_pos(self, key, value) int LuaSettings::l_set_pos(lua_State *L) { - NO_MAP_LOCK_REQUIRED; - LuaSettings *o = checkObject(L, 1); + NO_MAP_LOCK_REQUIRED; + LuaSettings *o = checkObject(L, 1); - std::string key = luaL_checkstring(L, 2); - v3f value = check_v3f(L, 3); + std::string key = luaL_checkstring(L, 2); + 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 @@ -389,11 +389,11 @@ const luaL_Reg LuaSettings::methods[] = { luamethod(LuaSettings, get_bool), luamethod(LuaSettings, get_np_group), luamethod(LuaSettings, get_flags), - luamethod(LuaSettings, get_pos), + luamethod(LuaSettings, get_pos), luamethod(LuaSettings, set), luamethod(LuaSettings, set_bool), luamethod(LuaSettings, set_np_group), - luamethod(LuaSettings, set_pos), + luamethod(LuaSettings, set_pos), luamethod(LuaSettings, remove), luamethod(LuaSettings, get_names), luamethod(LuaSettings, has), diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h index 63741477a2e7b..d4f48d037dd80 100644 --- a/src/script/lua_api/l_settings.h +++ b/src/script/lua_api/l_settings.h @@ -29,8 +29,8 @@ class LuaSettings : public ModApiBase // get_flags(self, key) -> key/value table static int l_get_flags(lua_State *L); - // get_pos(self, key) -> vector or nil - static int l_get_pos(lua_State *L); + // get_pos(self, key) -> vector or nil + static int l_get_pos(lua_State *L); // set(self, key, value) static int l_set(lua_State *L); @@ -41,8 +41,8 @@ class LuaSettings : public ModApiBase // set_np_group(self, key, value) static int l_set_np_group(lua_State *L); - // set_pos(self, key, value) - static int l_set_pos(lua_State *L); + // set_pos(self, key, value) + static int l_set_pos(lua_State *L); // remove(self, key) -> success static int l_remove(lua_State *L); diff --git a/src/server.cpp b/src/server.cpp index 2bee1c7889c9f..89f597a886bf4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2626,9 +2626,9 @@ void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_co std::string lang_suffixes[3]; for (size_t i = 0; i < 3; 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) return false; for (size_t j = 0; j < 3; j++) { @@ -3890,13 +3890,13 @@ v3f Server::findSpawnPos() { ServerMap &map = m_env->getServerMap(); - std::optional staticSpawnPoint; + std::optional staticSpawnPoint; if (g_settings->getV3FNoEx("static_spawnpoint", staticSpawnPoint) && staticSpawnPoint.has_value()) - { - return *staticSpawnPoint * BS; - } + { + return *staticSpawnPoint * BS; + } - v3f nodeposf; + v3f nodeposf; bool is_good = false; // Limit spawn range to mapgen edges (determined by 'mapgen_limit') diff --git a/src/settings.cpp b/src/settings.cpp index cec3f52399a9c..6a7607cc3adc8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -627,9 +627,9 @@ bool Settings::getNoiseParamsFromGroup(const std::string &name, group->getFloatNoEx("offset", np.offset); group->getFloatNoEx("scale", np.scale); - std::optional spread; + std::optional spread; if (group->getV3FNoEx("spread", spread) && spread.has_value()) - np.spread = *spread; + np.spread = *spread; group->getS32NoEx("seed", np.seed); group->getU16NoEx("octaves", np.octaves); diff --git a/src/unittest/test_irr_matrix4.cpp b/src/unittest/test_irr_matrix4.cpp index 7298821027a4e..764b0a5b27d4e 100644 --- a/src/unittest/test_irr_matrix4.cpp +++ b/src/unittest/test_irr_matrix4.cpp @@ -9,7 +9,7 @@ using matrix4 = core::matrix4; 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}; @@ -19,68 +19,68 @@ constexpr v3f z{0, 0, 1}; TEST_CASE("matrix4") { SECTION("setRotationRadians") { - SECTION("rotation order is ZYX (matrix notation)") { - v3f rot{1, 2, 3}; - matrix4 X, Y, Z, ZYX; - X.setRotationRadians({rot.X, 0, 0}); - Y.setRotationRadians({0, rot.Y, 0}); - Z.setRotationRadians({0, 0, rot.Z}); - ZYX.setRotationRadians(rot); - CHECK(!matrix_equals(X * Y * Z, ZYX)); - CHECK(!matrix_equals(X * Z * Y, ZYX)); - CHECK(!matrix_equals(Y * X * Z, ZYX)); - CHECK(!matrix_equals(Y * Z * X, ZYX)); - CHECK(!matrix_equals(Z * X * Y, ZYX)); - CHECK(matrix_equals(Z * Y * X, ZYX)); - } + SECTION("rotation order is ZYX (matrix notation)") { + v3f rot{1, 2, 3}; + matrix4 X, Y, Z, ZYX; + X.setRotationRadians({rot.X, 0, 0}); + Y.setRotationRadians({0, rot.Y, 0}); + Z.setRotationRadians({0, 0, rot.Z}); + ZYX.setRotationRadians(rot); + CHECK(!matrix_equals(X * Y * Z, ZYX)); + CHECK(!matrix_equals(X * Z * Y, ZYX)); + CHECK(!matrix_equals(Y * X * Z, ZYX)); + CHECK(!matrix_equals(Y * Z * X, ZYX)); + CHECK(!matrix_equals(Z * X * Y, 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 - // for a visualization of what handedness means for rotations + // 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 - SECTION("rotation is right-handed") { - SECTION("rotation around the X-axis is Z-up, counter-clockwise") { - matrix4 X; - X.setRotationRadians({quarter_turn, 0, 0}); - CHECK(X.transformVect(x).equals(x)); - CHECK(X.transformVect(y).equals(z)); - CHECK(X.transformVect(z).equals(-y)); - } + SECTION("rotation is right-handed") { + SECTION("rotation around the X-axis is Z-up, counter-clockwise") { + matrix4 X; + X.setRotationRadians({quarter_turn, 0, 0}); + CHECK(X.transformVect(x).equals(x)); + CHECK(X.transformVect(y).equals(z)); + CHECK(X.transformVect(z).equals(-y)); + } - SECTION("rotation around the Y-axis is Z-up, clockwise") { - matrix4 Y; - Y.setRotationRadians({0, quarter_turn, 0}); - CHECK(Y.transformVect(y).equals(y)); - CHECK(Y.transformVect(x).equals(-z)); - CHECK(Y.transformVect(z).equals(x)); - } + SECTION("rotation around the Y-axis is Z-up, clockwise") { + matrix4 Y; + Y.setRotationRadians({0, quarter_turn, 0}); + CHECK(Y.transformVect(y).equals(y)); + CHECK(Y.transformVect(x).equals(-z)); + CHECK(Y.transformVect(z).equals(x)); + } - SECTION("rotation around the Z-axis is Y-up, counter-clockwise") { - matrix4 Z; - Z.setRotationRadians({0, 0, quarter_turn}); - CHECK(Z.transformVect(z).equals(z)); - CHECK(Z.transformVect(x).equals(y)); - CHECK(Z.transformVect(y).equals(-x)); - } - } + SECTION("rotation around the Z-axis is Y-up, counter-clockwise") { + matrix4 Z; + Z.setRotationRadians({0, 0, quarter_turn}); + CHECK(Z.transformVect(z).equals(z)); + CHECK(Z.transformVect(x).equals(y)); + CHECK(Z.transformVect(y).equals(-x)); + } + } } SECTION("getScale") { - SECTION("correctly gets the length of each row of the 3x3 submatrix") { - matrix4 A( - 1, 2, 3, 0, - 4, 5, 6, 0, - 7, 8, 9, 0, - 0, 0, 0, 1 - ); - v3f scale = A.getScale(); - CHECK(scale.equals(v3f( - v3f(1, 2, 3).getLength(), - v3f(4, 5, 6).getLength(), - v3f(7, 8, 9).getLength() - ))); - } + SECTION("correctly gets the length of each row of the 3x3 submatrix") { + matrix4 A( + 1, 2, 3, 0, + 4, 5, 6, 0, + 7, 8, 9, 0, + 0, 0, 0, 1 + ); + v3f scale = A.getScale(); + CHECK(scale.equals(v3f( + v3f(1, 2, 3).getLength(), + v3f(4, 5, 6).getLength(), + v3f(7, 8, 9).getLength() + ))); + } } } diff --git a/src/unittest/test_settings.cpp b/src/unittest/test_settings.cpp index 411ecb8de50c7..f470fe219426f 100644 --- a/src/unittest/test_settings.cpp +++ b/src/unittest/test_settings.cpp @@ -42,14 +42,14 @@ const char *TestSettings::config_text_before = "floaty_thing = 1.1\n" "stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n" "coord = (1, 2, 4.5)\n" - "coord_invalid = (1,2,3\n" - "coord_invalid_2 = 1, 2, 3 test\n" - "coord_invalid_3 = (test, something, stupid)\n" - "coord_invalid_4 = (1, test, 3)\n" - "coord_invalid_5 = ()\n" - "coord_invalid_6 = (1, 2)\n" - "coord_invalid_7 = (1)\n" - "coord_no_parenthesis = 1,2,3\n" + "coord_invalid = (1,2,3\n" + "coord_invalid_2 = 1, 2, 3 test\n" + "coord_invalid_3 = (test, something, stupid)\n" + "coord_invalid_4 = (1, test, 3)\n" + "coord_invalid_5 = ()\n" + "coord_invalid_6 = (1, 2)\n" + "coord_invalid_7 = (1)\n" + "coord_no_parenthesis = 1,2,3\n" " # this is just a comment\n" "this is an invalid line\n" "asdf = {\n" @@ -103,14 +103,14 @@ const char *TestSettings::config_text_after = "}\n" "zoop = true\n" "coord2 = (1,2,3.25)\n" - "coord_invalid = (1,2,3\n" - "coord_invalid_2 = 1, 2, 3 test\n" - "coord_invalid_3 = (test, something, stupid)\n" - "coord_invalid_4 = (1, test, 3)\n" - "coord_invalid_5 = ()\n" - "coord_invalid_6 = (1, 2)\n" - "coord_invalid_7 = (1)\n" - "coord_no_parenthesis = 1,2,3\n" + "coord_invalid = (1,2,3\n" + "coord_invalid_2 = 1, 2, 3 test\n" + "coord_invalid_3 = (test, something, stupid)\n" + "coord_invalid_4 = (1, test, 3)\n" + "coord_invalid_5 = ()\n" + "coord_invalid_6 = (1, 2)\n" + "coord_invalid_7 = (1)\n" + "coord_no_parenthesis = 1,2,3\n" "floaty_thing_2 = 1.25\n" "groupy_thing = {\n" " animals = cute\n" @@ -169,20 +169,20 @@ void TestSettings::testAllSettings() UASSERT(s.getV3F("coord2").value().Y == 2.0); UASSERT(s.getV3F("coord2").value().Z == 3.25); - std::optional testNotExist; - UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist)); - EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist")); + std::optional testNotExist; + UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist)); + EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist")); - UASSERT(!s.getV3F("coord_invalid").has_value()); - UASSERT(!s.getV3F("coord_invalid_2").has_value()); - UASSERT(!s.getV3F("coord_invalid_3").has_value()); - UASSERT(!s.getV3F("coord_invalid_4").has_value()); - UASSERT(!s.getV3F("coord_invalid_5").has_value()); - UASSERT(!s.getV3F("coord_invalid_6").has_value()); - UASSERT(!s.getV3F("coord_invalid_7").has_value()); + UASSERT(!s.getV3F("coord_invalid").has_value()); + UASSERT(!s.getV3F("coord_invalid_2").has_value()); + UASSERT(!s.getV3F("coord_invalid_3").has_value()); + UASSERT(!s.getV3F("coord_invalid_4").has_value()); + UASSERT(!s.getV3F("coord_invalid_5").has_value()); + UASSERT(!s.getV3F("coord_invalid_6").has_value()); + UASSERT(!s.getV3F("coord_invalid_7").has_value()); - std::optional testNoParenthesis = s.getV3F("coord_no_parenthesis"); - UASSERT(testNoParenthesis.value() == v3f(1, 2, 3)); + std::optional testNoParenthesis = s.getV3F("coord_no_parenthesis"); + UASSERT(testNoParenthesis.value() == v3f(1, 2, 3)); // Test settings groups Settings *group = s.getGroup("asdf"); diff --git a/src/util/numeric.h b/src/util/numeric.h index 6062f07174bda..3082adb31f8cb 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -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) { - if (value + by < 0) return value + by + max; - if (value + by > max) return value + by - max; - return value + by; + if (value + by < 0) return value + by + max; + if (value + by > max) return value + by - max; + return value + by; } inline bool is_power_of_two(u32 n) diff --git a/src/util/string.cpp b/src/util/string.cpp index a0eee85c1bf39..0dbb9c0d30029 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -1070,39 +1070,39 @@ void safe_print_string(std::ostream &os, std::string_view str) std::optional str_to_v3f(std::string_view str) { - str = trim(str); - - if (str.empty()) - return std::nullopt; - - // Strip parentheses if they exist - if (str.front() == '(' && str.back() == ')') { - str.remove_prefix(1); - str.remove_suffix(1); - str = trim(str); - } - - std::istringstream iss((std::string(str))); - - const auto expect_delimiter = [&]() { - const auto c = iss.get(); - return c == ' ' || c == ','; - }; - - v3f value; - if (!(iss >> value.X)) - return std::nullopt; - if (!expect_delimiter()) - return std::nullopt; - if (!(iss >> value.Y)) - return std::nullopt; - if (!expect_delimiter()) - return std::nullopt; - if (!(iss >> value.Z)) - return std::nullopt; - - if (!iss.eof()) - return std::nullopt; - - return value; + str = trim(str); + + if (str.empty()) + return std::nullopt; + + // Strip parentheses if they exist + if (str.front() == '(' && str.back() == ')') { + str.remove_prefix(1); + str.remove_suffix(1); + str = trim(str); + } + + std::istringstream iss((std::string(str))); + + const auto expect_delimiter = [&]() { + const auto c = iss.get(); + return c == ' ' || c == ','; + }; + + v3f value; + if (!(iss >> value.X)) + return std::nullopt; + if (!expect_delimiter()) + return std::nullopt; + if (!(iss >> value.Y)) + return std::nullopt; + if (!expect_delimiter()) + return std::nullopt; + if (!(iss >> value.Z)) + return std::nullopt; + + if (!iss.eof()) + return std::nullopt; + + return value; } diff --git a/src/util/string.h b/src/util/string.h index 16c337b7ffd9a..8b0848f8e154d 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -753,9 +753,9 @@ inline std::string stringw_to_utf8(const irr::core::stringw &input) 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) { std::wstring str = utf8_to_wide(input);