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

@ -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

@ -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)

@ -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))

@ -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

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

@ -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

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

@ -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

@ -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},
})

@ -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", {

@ -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",

@ -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)

@ -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)

@ -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})

@ -234,10 +234,10 @@ core.register_chatcommand("dump_wear_bar", {
})
core.register_chatcommand("set_saturation", {
params = "<saturation>",
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 = "<saturation>",
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
})

@ -39,7 +39,7 @@ public:
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);
}

@ -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;

@ -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;
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
};
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

@ -104,7 +104,7 @@ std::vector<DirListNode> 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;
}

@ -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

@ -777,7 +777,7 @@ void TextDrawer::place(const core::rect<s32> &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;
}

@ -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;

@ -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);

@ -344,7 +344,7 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
Buffer<u8> 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));

@ -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;
}
}

@ -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);

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

@ -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++) {

@ -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];
}
///////////////////////////////////////////////////////////////////////////////

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

@ -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))

@ -62,130 +62,98 @@ extern struct EnumString es_TileAnimationType[];
extern const std::array<const char *, 33> 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<video::SColor> *palette);
void push_nodebox(lua_State *L, const NodeBox &box);
void push_palette(lua_State *L, const std::vector<video::SColor> *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 &params);
void read_server_sound_params(lua_State *L, int index,
ServerPlayingSound &params);
void push_dig_params (lua_State *L,
const DigParams &params);
void push_hit_params (lua_State *L,
const HitParams &params);
void push_dig_params(lua_State *L, const DigParams &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);
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<ItemStack> &items);
void push_items(lua_State *L, const std::vector<ItemStack> &items);
std::vector<ItemStack> read_items (lua_State *L,
int index,
IGameDef* gdef);
std::vector<ItemStack> 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);

@ -21,20 +21,19 @@ extern "C" {
#include <lua.h>
}
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<typename T>
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_);
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<std::string> *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);
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<std::string> *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);
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 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);
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<aabb3f> read_aabb3f_vector (lua_State *L, int index, f32 scale);
size_t read_stringlist (lua_State *L, int index,
std::vector<std::string> *result);
size_t read_stringlist(lua_State *L, int index,
std::vector<std::string> *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<aabb3f> &boxes,
f32 divisor = 1.0f);
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<aabb3f> &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);
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

@ -445,13 +445,13 @@ int LuaItemStack::l_equals(lua_State *L)
NO_MAP_LOCK_REQUIRED;
LuaItemStack *o1 = checkObject<LuaItemStack>(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;

@ -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<LuaSettings>(L, 1);
std::string key = luaL_checkstring(L, 2);
NO_MAP_LOCK_REQUIRED;
LuaSettings *o = checkObject<LuaSettings>(L, 1);
std::string key = luaL_checkstring(L, 2);
std::optional<v3f> pos;
if (o->m_settings->getV3FNoEx(key, pos) && pos.has_value())
push_v3f(L, *pos);
else
lua_pushnil(L);
return 1;
std::optional<v3f> 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<LuaSettings>(L, 1);
NO_MAP_LOCK_REQUIRED;
LuaSettings *o = checkObject<LuaSettings>(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),

@ -29,8 +29,8 @@ private:
// 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 @@ private:
// 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);

@ -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<v3f> staticSpawnPoint;
std::optional<v3f> 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')

@ -627,9 +627,9 @@ bool Settings::getNoiseParamsFromGroup(const std::string &name,
group->getFloatNoEx("offset", np.offset);
group->getFloatNoEx("scale", np.scale);
std::optional<v3f> spread;
std::optional<v3f> 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);

@ -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()
)));
}
}
}

@ -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<v3f> testNotExist;
UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist));
EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist"));
std::optional<v3f> 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<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis");
UASSERT(testNoParenthesis.value() == v3f(1, 2, 3));
std::optional<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis");
UASSERT(testNoParenthesis.value() == v3f(1, 2, 3));
// Test settings groups
Settings *group = s.getGroup("asdf");

@ -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)

@ -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)
{
str = trim(str);
str = trim(str);
if (str.empty())
return std::nullopt;
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);
}
// 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)));
std::istringstream iss((std::string(str)));
const auto expect_delimiter = [&]() {
const auto c = iss.get();
return c == ' ' || c == ',';
};
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;
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;
if (!iss.eof())
return std::nullopt;
return value;
return value;
}

@ -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);