From d7825bca1b3e0ed21c766da3b86c69f1da98917f Mon Sep 17 00:00:00 2001 From: DS Date: Tue, 31 Mar 2020 19:34:42 +0200 Subject: Fix GUI element click-through by changing visibility (#9534) This adds a vector that holds pointers to elements that should only be visible while being drawn. In the guifsmenu's draw func, all elements in this vector are made visible and invisible again. Apart from there, they are always invisible. (Well they are still visible before the first drawn, does this matter? If yes, it could be fixed easily with some lines of code everywhere.) --- src/gui/guiFormSpecMenu.cpp | 30 +++++++++++++++++++++++++++++- src/gui/guiFormSpecMenu.h | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 012ac953f..59cd130ef 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -141,6 +141,8 @@ GUIFormSpecMenu::~GUIFormSpecMenu() background_it->drop(); for (auto &tooltip_rect_it : m_tooltip_rects) tooltip_rect_it.first->drop(); + for (auto &clickthrough_it : m_clickthrough_elements) + clickthrough_it->drop(); delete m_selected_item; delete m_form_src; @@ -742,6 +744,9 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); + // images should let events through + e->grab(); + m_clickthrough_elements.push_back(e); return; } @@ -775,6 +780,9 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); + // images should let events through + e->grab(); + m_clickthrough_elements.push_back(e); return; } errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl; @@ -882,7 +890,9 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen core::rect(pos, pos + geom), name, m_font, m_client); auto style = getStyleForElement("item_image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); - e->drop(); + + // item images should let events through + m_clickthrough_elements.push_back(e); m_fields.push_back(spec); return; @@ -1747,6 +1757,10 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); m_fields.push_back(spec); + + // labels should let events through + e->grab(); + m_clickthrough_elements.push_back(e); } return; @@ -1823,6 +1837,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); m_fields.push_back(spec); + + // vertlabels should let events through + e->grab(); + m_clickthrough_elements.push_back(e); return; } errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl; @@ -2745,6 +2763,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) background_it->drop(); for (auto &tooltip_rect_it : m_tooltip_rects) tooltip_rect_it.first->drop(); + for (auto &clickthrough_it : m_clickthrough_elements) + clickthrough_it->drop(); mydata.size= v2s32(100,100); mydata.screensize = screensize; @@ -2767,6 +2787,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) m_dropdowns.clear(); theme_by_name.clear(); theme_by_type.clear(); + m_clickthrough_elements.clear(); m_bgnonfullscreen = true; m_bgfullscreen = false; @@ -3248,12 +3269,19 @@ void GUIFormSpecMenu::drawMenu() e->setVisible(false); } + // Some elements are only visible while being drawn + for (gui::IGUIElement *e : m_clickthrough_elements) + e->setVisible(true); + /* Call base class (This is where all the drawing happens.) */ gui::IGUIElement::draw(); + for (gui::IGUIElement *e : m_clickthrough_elements) + e->setVisible(false); + // Draw hovered item tooltips for (const std::string &tooltip : m_hovered_item_tooltips) { showTooltip(utf8_to_wide(tooltip), m_default_tooltip_color, diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 184b26f3c..17bfef205 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -307,6 +307,7 @@ protected: std::vector> m_tooltip_rects; std::vector> m_scrollbars; std::vector>> m_dropdowns; + std::vector m_clickthrough_elements; GUIInventoryList::ItemSpec *m_selected_item = nullptr; u16 m_selected_amount = 0; -- cgit v1.2.3 From 3d6b55d3e9b91e6afdbfdcea0268dfb88c69c1c2 Mon Sep 17 00:00:00 2001 From: Elias Åström Date: Thu, 2 Apr 2020 19:24:35 +0200 Subject: Fix texture distortion for flowing liquids (#9561) Previously textures of the side faces on flowing liquid nodes would become distorted on different axis depending on the liquid level. This is because the nodes always had the same texture coordinates, even when the generated face could have different sizes. This solves that problem by adjusting the texture coordinates for the vertices making up the top of the faces, so the textures will not look compressed for smaller faces. --- src/client/content_mapblock.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 5be0caf19..9b4fd221e 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -556,17 +556,24 @@ void MapblockMeshGenerator::drawLiquidSides() for (int j = 0; j < 4; j++) { const UV &vertex = base_vertices[j]; const v3s16 &base = face.p[vertex.u]; + float v = vertex.v; + v3f pos; - pos.X = (base.X - 0.5) * BS; - pos.Z = (base.Z - 0.5) * BS; - if (vertex.v) - pos.Y = neighbor.is_same_liquid ? corner_levels[base.Z][base.X] : -0.5 * BS; - else - pos.Y = !top_is_same_liquid ? corner_levels[base.Z][base.X] : 0.5 * BS; + pos.X = (base.X - 0.5f) * BS; + pos.Z = (base.Z - 0.5f) * BS; + if (vertex.v) { + pos.Y = neighbor.is_same_liquid ? corner_levels[base.Z][base.X] : -0.5f * BS; + } else if (top_is_same_liquid) { + pos.Y = 0.5f * BS; + } else { + pos.Y = corner_levels[base.Z][base.X]; + v += (0.5f * BS - corner_levels[base.Z][base.X]) / BS; + } + if (data->m_smooth_lighting) color = blendLightColor(pos); pos += origin; - vertices[j] = video::S3DVertex(pos.X, pos.Y, pos.Z, 0, 0, 0, color, vertex.u, vertex.v); + vertices[j] = video::S3DVertex(pos.X, pos.Y, pos.Z, 0, 0, 0, color, vertex.u, v); }; collector->append(tile_liquid, vertices, 4, quad_indices, 6); } -- cgit v1.2.3 From 6940e5a191e14c024a123d91a66855ff298c5b84 Mon Sep 17 00:00:00 2001 From: "updatepo.sh" Date: Fri, 3 Apr 2020 23:17:42 +0200 Subject: Update minetest.conf.example, settings_translation_file.cpp --- minetest.conf.example | 55 ++++++++++++++++++++------------------- src/settings_translation_file.cpp | 4 +-- 2 files changed, 30 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/minetest.conf.example b/minetest.conf.example index 5bc41a9a4..1c1796a14 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -1371,7 +1371,7 @@ # ask_reconnect_on_crash = false # From how far clients know about objects, stated in mapblocks (16 nodes). -# +# # Setting this larger than active_block_range will also cause the server # to maintain active objects up to this distance in the direction the # player is looking. (This can avoid mobs suddenly disappearing from view) @@ -1920,7 +1920,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # Second of two 3D noises that together define tunnels. @@ -1933,7 +1933,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise defining giant caverns. @@ -1946,7 +1946,7 @@ # octaves = 5, # persistence = 0.63, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise defining terrain. @@ -1972,7 +1972,7 @@ # octaves = 2, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } ## Mapgen V6 @@ -2312,7 +2312,7 @@ # octaves = 5, # persistence = 0.63, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise defining structure of river canyon walls. @@ -2325,7 +2325,7 @@ # octaves = 4, # persistence = 0.75, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise defining giant caverns. @@ -2338,7 +2338,7 @@ # octaves = 5, # persistence = 0.63, # lacunarity = 2.0, -# flags = +# flags = # } # First of two 3D noises that together define tunnels. @@ -2351,7 +2351,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # Second of two 3D noises that together define tunnels. @@ -2364,7 +2364,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise that determines number of dungeons per mapchunk. @@ -2377,7 +2377,7 @@ # octaves = 2, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } ## Mapgen Carpathian @@ -2620,7 +2620,7 @@ # octaves = 5, # persistence = 0.55, # lacunarity = 2.0, -# flags = +# flags = # } # First of two 3D noises that together define tunnels. @@ -2633,7 +2633,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # Second of two 3D noises that together define tunnels. @@ -2646,7 +2646,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise defining giant caverns. @@ -2659,7 +2659,7 @@ # octaves = 5, # persistence = 0.63, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise that determines number of dungeons per mapchunk. @@ -2672,7 +2672,7 @@ # octaves = 2, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } ## Mapgen Flat @@ -2782,7 +2782,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # Second of two 3D noises that together define tunnels. @@ -2795,7 +2795,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise that determines number of dungeons per mapchunk. @@ -2808,7 +2808,7 @@ # octaves = 2, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } ## Mapgen Fractal @@ -2982,7 +2982,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # Second of two 3D noises that together define tunnels. @@ -2995,7 +2995,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # 3D noise that determines number of dungeons per mapchunk. @@ -3008,7 +3008,7 @@ # octaves = 2, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } ## Mapgen Valleys @@ -3098,7 +3098,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # Second of two 3D noises that together define tunnels. @@ -3111,7 +3111,7 @@ # octaves = 3, # persistence = 0.5, # lacunarity = 2.0, -# flags = +# flags = # } # The depth of dirt or other biome filler node. @@ -3137,7 +3137,7 @@ # octaves = 6, # persistence = 0.63, # lacunarity = 2.0, -# flags = +# flags = # } # Defines large-scale river channel structure. @@ -3189,7 +3189,7 @@ # octaves = 6, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } # Amplifies the valleys. @@ -3228,7 +3228,7 @@ # octaves = 2, # persistence = 0.8, # lacunarity = 2.0, -# flags = +# flags = # } ## Advanced @@ -3292,3 +3292,4 @@ # so see a full list at https://content.minetest.net/help/content_flags/ # type: string # contentdb_flag_blacklist = nonfree, desktop_default + diff --git a/src/settings_translation_file.cpp b/src/settings_translation_file.cpp index 0e38e5c73..9156580c0 100644 --- a/src/settings_translation_file.cpp +++ b/src/settings_translation_file.cpp @@ -286,8 +286,8 @@ fake_function() { gettext("Open the pause menu when the window's focus is lost. Does not pause if a formspec is\nopen."); gettext("Viewing range"); gettext("View distance in nodes."); - gettext("Near clipping plane"); - gettext("Camera 'near clipping plane' distance in nodes, between 0 and 0.5.\nMost users will not need to change this.\nIncreasing can reduce artifacting on weaker GPUs.\n0.1 = Default, 0.25 = Good value for weaker tablets."); + gettext("Near plane"); + gettext("Camera 'near clipping plane' distance in nodes, between 0 and 0.25\nOnly works on GLES platforms. Most users will not need to change this.\nIncreasing can reduce artifacting on weaker GPUs.\n0.1 = Default, 0.25 = Good value for weaker tablets."); gettext("Screen width"); gettext("Width component of the initial window size."); gettext("Screen height"); -- cgit v1.2.3 From 307d7376cf88f3ef30a73f4500971e3a77977068 Mon Sep 17 00:00:00 2001 From: LNJ Date: Sat, 4 Apr 2020 15:52:41 +0200 Subject: Fix 'the the' typos in comments (#9554) --- src/mapgen/mapgen_valleys.cpp | 2 +- src/script/common/c_internal.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 2b8703fa5..ff908b7bb 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -390,7 +390,7 @@ int MapgenValleys::generateTerrain() // Rivers are placed where 'river' is negative if (river < 0.0f) { - // Use the the function -sqrt(1-x^2) which models a circle + // Use the function -sqrt(1-x^2) which models a circle float tr = river / river_size_factor + 1.0f; float depth = (river_depth_bed * std::sqrt(std::fmax(0.0f, 1.0f - tr * tr))); diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index a7dcf9b5f..b19af9f82 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -47,7 +47,7 @@ int script_exception_wrapper(lua_State *L, lua_CFunction f) /* * Note that we can't get tracebacks for LUA_ERRMEM or LUA_ERRERR (without * hacking Lua internals). For LUA_ERRMEM, this is because memory errors will - * not execute the the error handler, and by the time lua_pcall returns the + * not execute the error handler, and by the time lua_pcall returns the * execution stack will have already been unwound. For LUA_ERRERR, there was * another error while trying to generate a backtrace from a LUA_ERRRUN. It is * presumed there is an error with the internal Lua state and thus not possible -- cgit v1.2.3 From 86a0e991efff2fc616372f566a301352be28dae9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Sat, 4 Apr 2020 16:17:15 +0200 Subject: Fix cursor still visible after closing formspec while on HyperText (#9583) --- src/gui/guiHyperText.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 482b74f04..85e562dad 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -1054,12 +1054,14 @@ void GUIHyperText::checkHover(s32 X, s32 Y) } } +#ifndef HAVE_TOUCHSCREENGUI if (m_drawer.m_hovertag) RenderingEngine::get_raw_device()->getCursorControl()->setActiveIcon( gui::ECI_HAND); else RenderingEngine::get_raw_device()->getCursorControl()->setActiveIcon( gui::ECI_NORMAL); +#endif } bool GUIHyperText::OnEvent(const SEvent &event) @@ -1075,8 +1077,12 @@ bool GUIHyperText::OnEvent(const SEvent &event) if (event.EventType == EET_GUI_EVENT && event.GUIEvent.EventType == EGET_ELEMENT_LEFT) { m_drawer.m_hovertag = nullptr; - RenderingEngine::get_raw_device()->getCursorControl()->setActiveIcon( - gui::ECI_NORMAL); +#ifndef HAVE_TOUCHSCREENGUI + gui::ICursorControl *cursor_control = + RenderingEngine::get_raw_device()->getCursorControl(); + if (cursor_control->isVisible()) + cursor_control->setActiveIcon(gui::ECI_NORMAL); +#endif } if (event.EventType == EET_MOUSE_INPUT_EVENT) { -- cgit v1.2.3 From d5c441253669c9f88dea948d261e0d8934d28fb9 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 4 Apr 2020 21:27:23 +0200 Subject: Revert collision tweaks #9365 and #9327 (#9591) This reverts commit df74d369a395f0b99bd23fa3e7fb4c628c3df336. This reverts commit 908e76247922d4adf879b3996c4f75bdbb4e536d. Restores the original collision detection bugs to release 5.2.0 prior the large collision detection fix. --- src/collision.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/collision.cpp b/src/collision.cpp index a4c5454ae..a443be7ab 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -415,12 +415,12 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, Collision uncertainty radius Make it a bit larger than the maximum distance of movement */ - //f32 d = pos_max_d * 1.1f; + f32 d = pos_max_d * 1.1f; + // A fairly large value in here makes moving smoother + //f32 d = 0.15*BS; - - f32 d = 0.3f; // Temporary fix, any nonzero d causes collision glitches, the more the greater it is. - // ultimately it has to be determined if any uncertainty is involved, and if it is, eliminated - // and d & pos_max_d params removed from function calls. + // This should always apply, otherwise there are glitches + assert(d > pos_max_d); // invariant int loopcount = 0; -- cgit v1.2.3 From 0eb3072819e500ea6cc70c7031079472ec2ea569 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Sun, 5 Apr 2020 15:04:41 +0200 Subject: Hypertext: Fix hovercolor not working in global tag (#9582) --- src/gui/guiHyperText.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 85e562dad..e107b5a3e 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -107,7 +107,7 @@ ParsedText::ParsedText(const wchar_t *text) m_root_tag.style["underline"] = "false"; m_root_tag.style["halign"] = "left"; m_root_tag.style["color"] = "#EEEEEE"; - m_root_tag.style["hovercolor"] = m_root_tag.style["color"]; + m_root_tag.style["hovercolor"] = "#FF0000"; m_active_tags.push_front(&m_root_tag); m_style = m_root_tag.style; @@ -115,7 +115,6 @@ ParsedText::ParsedText(const wchar_t *text) // Default simple tags definitions StyleList style; - style["hovercolor"] = "#FF0000"; style["color"] = "#0000FF"; style["underline"] = "true"; m_elementtags["action"] = style; -- cgit v1.2.3 From f45ba78a72d86fd481a2d2064ac63858d69ad7ee Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Mon, 6 Apr 2020 16:54:12 +0200 Subject: Allow relative directories for `screenshot_path`, tweak default path (#9122) This will likely be more intuitive for users and should play better with sandboxed distributions such as Flatpak. In addition, the screenshot directory will now be created if it doesn't exist already. --- builtin/settingtypes.txt | 5 +++-- src/client/client.cpp | 13 ++++++++++++- src/defaultsettings.cpp | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 1f2889b45..a6cf8de60 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -903,8 +903,9 @@ fallback_font_shadow_alpha (Fallback font shadow alpha) int 128 0 255 # This font will be used for certain languages or if the default font is unavailable. fallback_font_path (Fallback font path) filepath fonts/DroidSansFallbackFull.ttf -# Path to save screenshots at. -screenshot_path (Screenshot folder) path +# Path to save screenshots at. Can be an absolute or relative path. +# The folder will be created if it doesn't already exist. +screenshot_path (Screenshot folder) path screenshots # Format of screenshots. screenshot_format (Screenshot format) enum png png,jpg,bmp,pcx,ppm,tga diff --git a/src/client/client.cpp b/src/client/client.cpp index c6d28ce80..e15391dde 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1780,13 +1780,24 @@ void Client::makeScreenshot() char timetstamp_c[64]; strftime(timetstamp_c, sizeof(timetstamp_c), "%Y%m%d_%H%M%S", tm); - std::string filename_base = g_settings->get("screenshot_path") + std::string screenshot_dir; + + if (fs::IsPathAbsolute(g_settings->get("screenshot_path"))) + screenshot_dir = g_settings->get("screenshot_path"); + else + screenshot_dir = porting::path_user + DIR_DELIM + g_settings->get("screenshot_path"); + + std::string filename_base = screenshot_dir + DIR_DELIM + std::string("screenshot_") + std::string(timetstamp_c); std::string filename_ext = "." + g_settings->get("screenshot_format"); std::string filename; + // Create the directory if it doesn't already exist. + // Otherwise, saving the screenshot would fail. + fs::CreateDir(screenshot_dir); + u32 quality = (u32)g_settings->getS32("screenshot_quality"); quality = MYMIN(MYMAX(quality, 0), 100) / 100.0 * 255; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 472522bf4..b6b1ce1f2 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -48,7 +48,7 @@ void set_default_settings(Settings *settings) settings->setDefault("pitch_move", "false"); settings->setDefault("fast_move", "false"); settings->setDefault("noclip", "false"); - settings->setDefault("screenshot_path", "."); + settings->setDefault("screenshot_path", "screenshots"); settings->setDefault("screenshot_format", "png"); settings->setDefault("screenshot_quality", "0"); settings->setDefault("client_unload_unused_data_timeout", "600"); -- cgit v1.2.3 From 3494475df108e3401c6c8463a0aeae0f227fd1fa Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 8 Apr 2020 20:12:58 +0200 Subject: Miscellaneous networking improvements (#9611) fixes #2862 --- src/network/clientopcodes.cpp | 18 +++++++++++++---- src/network/connection.cpp | 35 ++++++++++++++++++++------------- src/network/connection.h | 16 +++++++-------- src/network/connectionthreads.cpp | 41 ++++++++++++++++++++++++++------------- src/network/serveropcodes.cpp | 20 ++++++++++++++----- 5 files changed, 87 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp index 431455b76..0f20047c0 100644 --- a/src/network/clientopcodes.cpp +++ b/src/network/clientopcodes.cpp @@ -126,6 +126,16 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] = const static ServerCommandFactory null_command_factory = { "TOSERVER_NULL", 0, false }; +/* + Channels used for Client -> Server communication + 2: Notifications back to the server (e.g. GOTBLOCKS) + 1: Init and Authentication + 0: everything else + + Packet order is only guaranteed inside a channel, so packets that operate on + the same objects are *required* to be in the same channel. +*/ + const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] = { null_command_factory, // 0x00 @@ -143,7 +153,7 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] = null_command_factory, // 0x0c null_command_factory, // 0x0d null_command_factory, // 0x0e - null_command_factory, // 0x0F + null_command_factory, // 0x0f null_command_factory, // 0x10 { "TOSERVER_INIT2", 1, true }, // 0x11 null_command_factory, // 0x12 @@ -186,7 +196,7 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] = { "TOSERVER_PLAYERITEM", 0, true }, // 0x37 { "TOSERVER_RESPAWN", 0, true }, // 0x38 { "TOSERVER_INTERACT", 0, true }, // 0x39 - { "TOSERVER_REMOVED_SOUNDS", 1, true }, // 0x3a + { "TOSERVER_REMOVED_SOUNDS", 2, true }, // 0x3a { "TOSERVER_NODEMETA_FIELDS", 0, true }, // 0x3b { "TOSERVER_INVENTORY_FIELDS", 0, true }, // 0x3c null_command_factory, // 0x3d @@ -194,8 +204,8 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] = null_command_factory, // 0x3f { "TOSERVER_REQUEST_MEDIA", 1, true }, // 0x40 null_command_factory, // 0x41 - { "TOSERVER_BREATH", 0, true }, // 0x42 old TOSERVER_BREATH. Ignored by servers - { "TOSERVER_CLIENT_READY", 0, true }, // 0x43 + null_command_factory, // 0x42 + { "TOSERVER_CLIENT_READY", 1, true }, // 0x43 null_command_factory, // 0x44 null_command_factory, // 0x45 null_command_factory, // 0x46 diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 36124ce3c..15eda7725 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -924,7 +924,7 @@ UDPPeer::UDPPeer(u16 a_id, Address a_address, Connection* connection) : Peer(a_address,a_id,connection) { for (Channel &channel : channels) - channel.setWindowSize(g_settings->getU16("max_packets_per_iteration")); + channel.setWindowSize(START_RELIABLE_WINDOW_SIZE); } bool UDPPeer::getAddress(MTProtocols type,Address& toset) @@ -975,22 +975,29 @@ void UDPPeer::PutReliableSendCommand(ConnectionCommand &c, if (m_pending_disconnect) return; - if ( channels[c.channelnum].queued_commands.empty() && + Channel &chan = channels[c.channelnum]; + + if (chan.queued_commands.empty() && /* don't queue more packets then window size */ - (channels[c.channelnum].queued_reliables.size() - < (channels[c.channelnum].getWindowSize()/2))) { + (chan.queued_reliables.size() < chan.getWindowSize() / 2)) { LOG(dout_con<getDesc() <<" processing reliable command for peer id: " << c.peer_id <<" data size: " << c.data.getSize() << std::endl); if (!processReliableSendCommand(c,max_packet_size)) { - channels[c.channelnum].queued_commands.push_back(c); + chan.queued_commands.push_back(c); } } else { LOG(dout_con<getDesc() <<" Queueing reliable command for peer id: " << c.peer_id <<" data size: " << c.data.getSize() <= chan.getWindowSize() / 2) { + LOG(derr_con << m_connection->getDesc() + << "Possible packet stall to peer id: " << c.peer_id + << " queued_commands=" << chan.queued_commands.size() + << std::endl); + } } } @@ -1001,6 +1008,8 @@ bool UDPPeer::processReliableSendCommand( if (m_pending_disconnect) return true; + Channel &chan = channels[c.channelnum]; + u32 chunksize_max = max_packet_size - BASE_HEADER_SIZE - RELIABLE_HEADER_SIZE; @@ -1008,13 +1017,13 @@ bool UDPPeer::processReliableSendCommand( sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); std::list> originals; - u16 split_sequence_number = channels[c.channelnum].readNextSplitSeqNum(); + u16 split_sequence_number = chan.readNextSplitSeqNum(); if (c.raw) { originals.emplace_back(c.data); } else { makeAutoSplitPacket(c.data, chunksize_max,split_sequence_number, &originals); - channels[c.channelnum].setNextSplitSeqNum(split_sequence_number); + chan.setNextSplitSeqNum(split_sequence_number); } bool have_sequence_number = true; @@ -1023,7 +1032,7 @@ bool UDPPeer::processReliableSendCommand( volatile u16 initial_sequence_number = 0; for (SharedBuffer &original : originals) { - u16 seqnum = channels[c.channelnum].getOutgoingSequenceNumber(have_sequence_number); + u16 seqnum = chan.getOutgoingSequenceNumber(have_sequence_number); /* oops, we don't have enough sequence numbers to send this packet */ if (!have_sequence_number) @@ -1055,10 +1064,10 @@ bool UDPPeer::processReliableSendCommand( // << " channel: " << (c.channelnum&0xFF) // << " seqnum: " << readU16(&p.data[BASE_HEADER_SIZE+1]) // << std::endl) - channels[c.channelnum].queued_reliables.push(p); + chan.queued_reliables.push(p); pcount++; } - sanity_check(channels[c.channelnum].queued_reliables.size() < 0xFFFF); + sanity_check(chan.queued_reliables.size() < 0xFFFF); return true; } @@ -1073,7 +1082,7 @@ bool UDPPeer::processReliableSendCommand( toadd.pop(); bool successfully_put_back_sequence_number - = channels[c.channelnum].putBackSequenceNumber( + = chan.putBackSequenceNumber( (initial_sequence_number+toadd.size() % (SEQNUM_MAX+1))); FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error"); @@ -1081,7 +1090,7 @@ bool UDPPeer::processReliableSendCommand( // DO NOT REMOVE n_queued! It avoids a deadlock of async locked // 'log_message_mutex' and 'm_list_mutex'. - u32 n_queued = channels[c.channelnum].outgoing_reliables_sent.size(); + u32 n_queued = chan.outgoing_reliables_sent.size(); LOG(dout_con<getDesc() << " Windowsize exceeded on reliable sending " diff --git a/src/network/connection.h b/src/network/connection.h index 0b12bf701..85f021c4c 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -141,7 +141,6 @@ private: === NOTES === A packet is sent through a channel to a peer with a basic header: -TODO: Should we have a receiver_peer_id also? Header (7 bytes): [0] u32 protocol_id [4] session_t sender_peer_id @@ -152,8 +151,7 @@ sender_peer_id: value 1 (PEER_ID_SERVER) is reserved for server these constants are defined in constants.h channel: - The lower the number, the higher the priority is. - Only channels 0, 1 and 2 exist. + Channel numbers have no intrinsic meaning. Currently only 0, 1, 2 exist. */ #define BASE_HEADER_SIZE 7 #define CHANNEL_COUNT 3 @@ -386,12 +384,14 @@ struct ConnectionCommand } }; -/* maximum window size to use, 0xFFFF is theoretical maximum don't think about +/* maximum window size to use, 0xFFFF is theoretical maximum. don't think about * touching it, the less you're away from it the more likely data corruption * will occur */ #define MAX_RELIABLE_WINDOW_SIZE 0x8000 - /* starting value for window size */ +/* starting value for window size */ +#define START_RELIABLE_WINDOW_SIZE 0x400 +/* minimum value for window size */ #define MIN_RELIABLE_WINDOW_SIZE 0x40 class Channel @@ -555,15 +555,15 @@ class Peer { bool isTimedOut(float timeout); - unsigned int m_increment_packets_remaining = 9; - unsigned int m_increment_bytes_remaining = 0; + unsigned int m_increment_packets_remaining = 0; virtual u16 getNextSplitSequenceNumber(u8 channel) { return 0; }; virtual void setNextSplitSequenceNumber(u8 channel, u16 seqnum) {}; virtual SharedBuffer addSplitPacket(u8 channel, const BufferedPacket &toadd, bool reliable) { - fprintf(stderr,"Peer: addSplitPacket called, this is supposed to be never called!\n"); + errorstream << "Peer::addSplitPacket called," + << " this is supposed to be never called!" << std::endl; return SharedBuffer(0); }; diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index f8b58c025..48a4f51ab 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -73,6 +73,7 @@ ConnectionSendThread::ConnectionSendThread(unsigned int max_packet_size, m_timeout(timeout), m_max_data_packets_per_iteration(g_settings->getU16("max_packets_per_iteration")) { + SANITY_CHECK(m_max_data_packets_per_iteration > 1); } void *ConnectionSendThread::run() @@ -107,8 +108,13 @@ void *ConnectionSendThread::run() curtime = porting::getTimeMs(); float dtime = CALC_DTIME(lasttime, curtime); - /* first do all the reliable stuff */ + /* first resend timed-out packets */ runTimeouts(dtime); + if (m_iteration_packets_avaialble == 0) { + LOG(warningstream << m_connection->getDesc() + << " Packet quota used up after re-sending packets, " + << "max=" << m_max_data_packets_per_iteration << std::endl); + } /* translate commands to packets */ ConnectionCommand c = m_connection->m_command_queue.pop_frontNoEx(0); @@ -121,7 +127,7 @@ void *ConnectionSendThread::run() c = m_connection->m_command_queue.pop_frontNoEx(0); } - /* send non reliable packets */ + /* send queued packets */ sendPackets(dtime); END_DEBUG_EXCEPTION_HANDLER @@ -644,6 +650,9 @@ void ConnectionSendThread::sendPackets(float dtime) std::list pendingDisconnect; std::map pending_unreliable; + const unsigned int peer_packet_quota = m_iteration_packets_avaialble + / MYMAX(peerIds.size(), 1); + for (session_t peerId : peerIds) { PeerHelper peer = m_connection->getPeerNoEx(peerId); //peer may have been removed @@ -653,8 +662,7 @@ void ConnectionSendThread::sendPackets(float dtime) << std::endl); continue; } - peer->m_increment_packets_remaining = - m_iteration_packets_avaialble / m_connection->m_peers.size(); + peer->m_increment_packets_remaining = peer_packet_quota; UDPPeer *udpPeer = dynamic_cast(&peer); @@ -751,23 +759,30 @@ void ConnectionSendThread::sendPackets(float dtime) } /* send acks immediately */ - if (packet.ack) { + if (packet.ack || peer->m_increment_packets_remaining > 0 || stopRequested()) { rawSendAsPacket(packet.peer_id, packet.channelnum, packet.data, packet.reliable); - peer->m_increment_packets_remaining = - MYMIN(0, peer->m_increment_packets_remaining--); - } else if ( - (peer->m_increment_packets_remaining > 0) || - (stopRequested())) { - rawSendAsPacket(packet.peer_id, packet.channelnum, - packet.data, packet.reliable); - peer->m_increment_packets_remaining--; + if (peer->m_increment_packets_remaining > 0) + peer->m_increment_packets_remaining--; } else { m_outgoing_queue.push(packet); pending_unreliable[packet.peer_id] = true; } } + if (peer_packet_quota > 0) { + for (session_t peerId : peerIds) { + PeerHelper peer = m_connection->getPeerNoEx(peerId); + if (!peer) + continue; + if (peer->m_increment_packets_remaining == 0) { + LOG(warningstream << m_connection->getDesc() + << " Packet quota used up for peer_id=" << peerId + << ", was " << peer_packet_quota << " pkts" << std::endl); + } + } + } + for (session_t peerId : pendingDisconnect) { if (!pending_unreliable[peerId]) { m_connection->deletePeer(peerId, false); diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp index cca2e56ea..6ee4ff256 100644 --- a/src/network/serveropcodes.cpp +++ b/src/network/serveropcodes.cpp @@ -111,6 +111,16 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] = const static ClientCommandFactory null_command_factory = { "TOCLIENT_NULL", 0, false }; +/* + Channels used for Server -> Client communication + 2: Bulk data (mapblocks, media, ...) + 1: HUD packets + 0: everything else + + Packet order is only guaranteed inside a channel, so packets that operate on + the same objects are *required* to be in the same channel. +*/ + const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] = { null_command_factory, // 0x00 @@ -163,7 +173,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] = { "TOCLIENT_CHAT_MESSAGE", 0, true }, // 0x2F null_command_factory, // 0x30 { "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", 0, true }, // 0x31 - { "TOCLIENT_ACTIVE_OBJECT_MESSAGES", 0, true }, // 0x32 Special packet, sent by 0 (rel) and 1 (unrel) channel + { "TOCLIENT_ACTIVE_OBJECT_MESSAGES", 0, true }, // 0x32 (may be sent as unrel over channel 1 too) { "TOCLIENT_HP", 0, true }, // 0x33 { "TOCLIENT_MOVE_PLAYER", 0, true }, // 0x34 { "TOCLIENT_ACCESS_DENIED_LEGACY", 0, true }, // 0x35 @@ -176,7 +186,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] = { "TOCLIENT_ANNOUNCE_MEDIA", 0, true }, // 0x3C { "TOCLIENT_ITEMDEF", 0, true }, // 0x3D null_command_factory, // 0x3E - { "TOCLIENT_PLAY_SOUND", 0, true }, // 0x3f + { "TOCLIENT_PLAY_SOUND", 0, true }, // 0x3f (may be sent as unrel too) { "TOCLIENT_STOP_SOUND", 0, true }, // 0x40 { "TOCLIENT_PRIVILEGES", 0, true }, // 0x41 { "TOCLIENT_INVENTORY_FORMSPEC", 0, true }, // 0x42 @@ -188,9 +198,9 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] = null_command_factory, // 0x48 { "TOCLIENT_HUDADD", 1, true }, // 0x49 { "TOCLIENT_HUDRM", 1, true }, // 0x4a - { "TOCLIENT_HUDCHANGE", 0, true }, // 0x4b - { "TOCLIENT_HUD_SET_FLAGS", 0, true }, // 0x4c - { "TOCLIENT_HUD_SET_PARAM", 0, true }, // 0x4d + { "TOCLIENT_HUDCHANGE", 1, true }, // 0x4b + { "TOCLIENT_HUD_SET_FLAGS", 1, true }, // 0x4c + { "TOCLIENT_HUD_SET_PARAM", 1, true }, // 0x4d { "TOCLIENT_BREATH", 0, true }, // 0x4e { "TOCLIENT_SET_SKY", 0, true }, // 0x4f { "TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO", 0, true }, // 0x50 -- cgit v1.2.3 From de73f989eb1397b1103236031fd91309b294583c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 8 Apr 2020 20:13:23 +0200 Subject: Overall improvements to log messages (#9598) Hide some unnecessarily verbose ones behind --trace or disable them entirely. Remove duplicate ones. Improve their contents in some places. --- src/client/client.cpp | 40 ++++++++++++++++++++++++++----------- src/client/client.h | 19 ++++-------------- src/client/content_cao.cpp | 6 +++--- src/client/fontengine.cpp | 2 +- src/client/game.cpp | 3 +-- src/client/renderingengine.cpp | 20 ++----------------- src/client/sound_openal.cpp | 16 ++++++++------- src/client/tile.cpp | 9 +++++---- src/content/subgames.cpp | 2 +- src/content_sao.cpp | 12 +++++------ src/craftdef.cpp | 4 ++-- src/emerge.cpp | 1 - src/itemdef.cpp | 6 +++--- src/main.cpp | 8 +------- src/map.cpp | 8 ++++---- src/network/clientpackethandler.cpp | 8 ++++---- src/network/connectionthreads.cpp | 3 +-- src/nodedef.cpp | 2 +- src/script/cpp_api/s_env.cpp | 2 +- src/script/lua_api/l_item.cpp | 1 - src/server.cpp | 17 ++++++++-------- src/server/mods.cpp | 9 +++------ 22 files changed, 87 insertions(+), 111 deletions(-) (limited to 'src') diff --git a/src/client/client.cpp b/src/client/client.cpp index e15391dde..c9cd24cb3 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -60,6 +60,20 @@ with this program; if not, write to the Free Software Foundation, Inc., extern gui::IGUIEnvironment* guienv; +/* + Utility classes +*/ + +void PacketCounter::print(std::ostream &o) const +{ + for (const auto &it : m_packets) { + auto name = it.first >= TOCLIENT_NUM_MSG_TYPES ? "?" + : toClientCommandTable[it.first].name; + o << "cmd " << it.first << " (" << name << ") count " + << it.second << std::endl; + } +} + /* Client */ @@ -336,12 +350,12 @@ void Client::step(float dtime) { float &counter = m_packetcounter_timer; counter -= dtime; - if(counter <= 0.0) + if(counter <= 0.0f) { - counter = 20.0; + counter = 30.0f; infostream << "Client packetcounter (" << m_packetcounter_timer - << "):"<getFloat("server_map_save_interval"); + int n = 0; for (std::unordered_map::const_iterator it = m_mod_storages.begin(); it != m_mod_storages.end(); ++it) { if (it->second->isModified()) { it->second->save(getModStoragePath()); + n++; } } + if (n > 0) + infostream << "Saved " << n << " modified mod storages." << std::endl; } // Write server map @@ -653,8 +670,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) }; name = removeStringEnd(filename, image_ext); if (!name.empty()) { - verbosestream<<"Client: Attempting to load image " - <<"file \""<loadSoundData(name, data); - return true; + TRACESTREAM(<< "Client: Attempting to load sound " + << "file \"" << filename << "\"" << std::endl); + return m_sound->loadSoundData(name, data); } const char *model_ext[] = { @@ -714,8 +730,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) }; name = removeStringEnd(filename, translate_ext); if (!name.empty()) { - verbosestream << "Client: Loading translation: " - << "\"" << filename << "\"" << std::endl; + TRACESTREAM(<< "Client: Loading translation: " + << "\"" << filename << "\"" << std::endl); g_translations->loadTranslation(data); return true; } diff --git a/src/client/client.h b/src/client/client.h index 1291b944c..eea78d456 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -82,30 +82,19 @@ public: void add(u16 command) { - std::map::iterator n = m_packets.find(command); - if(n == m_packets.end()) - { + auto n = m_packets.find(command); + if (n == m_packets.end()) m_packets[command] = 1; - } else - { n->second++; - } } void clear() { - for (auto &m_packet : m_packets) { - m_packet.second = 0; - } + m_packets.clear(); } - void print(std::ostream &o) - { - for (const auto &m_packet : m_packets) { - o << "cmd "<< m_packet.first <<" count "<< m_packet.second << std::endl; - } - } + void print(std::ostream &o) const; private: // command, count diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index d148df522..8509eccb5 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -576,9 +576,10 @@ void GenericCAO::addToScene(ITextureSource *tsrc) m_visuals_expired = false; - if (!m_prop.is_visible) { + if (!m_prop.is_visible) return; - } + + infostream << "GenericCAO::addToScene(): " << m_prop.visual << std::endl; if (m_enable_shaders) { IShaderSource *shader_source = m_client->getShaderSource(); @@ -593,7 +594,6 @@ void GenericCAO::addToScene(ITextureSource *tsrc) } auto grabMatrixNode = [this] { - infostream << "GenericCAO::addToScene(): " << m_prop.visual << std::endl; m_matrixnode = RenderingEngine::get_scene_manager()-> addDummyTransformationSceneNode(); m_matrixnode->grab(); diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp index 2b5841cd8..61d52cc2f 100644 --- a/src/client/fontengine.cpp +++ b/src/client/fontengine.cpp @@ -239,7 +239,7 @@ void FontEngine::updateSkin() FATAL_ERROR_IF(font == NULL, "Could not create/get font"); u32 text_height = font->getDimension(L"Hello, world!").Height; - infostream << "text_height=" << text_height << std::endl; + infostream << "FontEngine: measured text_height=" << text_height << std::endl; } /******************************************************************************/ diff --git a/src/client/game.cpp b/src/client/game.cpp index 0201ded69..437cc7871 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2010,7 +2010,6 @@ void Game::processItemSelection(u16 *new_playeritem) for (u16 i = 0; i <= max_item; i++) { if (wasKeyDown((GameKeyType) (KeyType::SLOT_1 + i))) { *new_playeritem = i; - infostream << "Selected item: " << new_playeritem << std::endl; break; } } @@ -2039,7 +2038,7 @@ void Game::openInventory() if (!player || !player->getCAO()) return; - infostream << "the_game: " << "Launching inventory" << std::endl; + infostream << "Game: Launching inventory" << std::endl; PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client); diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 6e6509eeb..8b7bbf328 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -226,27 +226,17 @@ bool RenderingEngine::setupTopLevelWindow(const std::string &name) { // FIXME: It would make more sense for there to be a switch of some // sort here that would call the correct toplevel setup methods for - // the environment Minetest is running in but for now not deviating - // from the original pattern. + // the environment Minetest is running in. /* Setting Xorg properties for the top level window */ setupTopLevelXorgWindow(name); - /* Done with Xorg properties */ /* Setting general properties for the top level window */ verbosestream << "Client: Configuring general top level" << " window properties" << std::endl; - bool result = setWindowIcon(); - verbosestream << "Client: Finished configuring general top level" - << " window properties" - << std::endl; - /* Done with general properties */ - - // FIXME: setWindowIcon returns a bool result but it is unused. - // For now continue to return this result. return result; } @@ -262,7 +252,7 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) return; } - verbosestream << "Client: Configuring Xorg specific top level" + verbosestream << "Client: Configuring X11-specific top level" << " window properties" << std::endl; @@ -309,8 +299,6 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) Atom NET_WM_PID = XInternAtom(x11_dpl, "_NET_WM_PID", false); pid_t pid = getpid(); - infostream << "Client: PID is '" << static_cast(pid) << "'" - << std::endl; XChangeProperty(x11_dpl, x11_win, NET_WM_PID, XA_CARDINAL, 32, PropModeReplace, @@ -327,10 +315,6 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) XChangeProperty (x11_dpl, x11_win, WM_CLIENT_LEADER, XA_WINDOW, 32, PropModeReplace, reinterpret_cast(&x11_win), 1); - - verbosestream << "Client: Finished configuring Xorg specific top level" - << " window properties" - << std::endl; #endif } diff --git a/src/client/sound_openal.cpp b/src/client/sound_openal.cpp index 8e696f302..d0f935a7a 100644 --- a/src/client/sound_openal.cpp +++ b/src/client/sound_openal.cpp @@ -165,8 +165,8 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile, << "preparing sound buffer" << std::endl; } - infostream << "Audio file " - << filename_for_logging << " loaded" << std::endl; + //infostream << "Audio file " + // << filename_for_logging << " loaded" << std::endl; // Clean up! ov_clear(oggFile); @@ -498,9 +498,11 @@ public: // Remove stopped sounds void maintain() { - verbosestream<<"OpenALSoundManager::maintain(): " - < del_list; for (const auto &sp : m_sounds_playing) { int id = sp.first; @@ -530,7 +532,7 @@ public: SoundBuffer *buf = load_ogg_from_file(filepath); if (buf) addBuffer(name, buf); - return false; + return !!buf; } bool loadSoundData(const std::string &name, @@ -539,7 +541,7 @@ public: SoundBuffer *buf = load_ogg_from_buffer(filedata, name); if (buf) addBuffer(name, buf); - return false; + return !!buf; } void updateListener(const v3f &pos, const v3f &vel, const v3f &at, const v3f &up) diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 3189ab28c..0fa7a4ae2 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -471,8 +471,8 @@ TextureSource::~TextureSource() driver->removeTexture(t); } - infostream << "~TextureSource() "<< textures_before << "/" - << driver->getTextureCount() << std::endl; + infostream << "~TextureSource() before cleanup: "<< textures_before + << " after: " << driver->getTextureCount() << std::endl; } u32 TextureSource::getTextureId(const std::string &name) @@ -763,6 +763,9 @@ void TextureSource::rebuildImagesAndTextures() video::IVideoDriver *driver = RenderingEngine::get_video_driver(); sanity_check(driver); + infostream << "TextureSource: recreating " << m_textureinfo_cache.size() + << " textures" << std::endl; + // Recreate textures for (TextureInfo &ti : m_textureinfo_cache) { video::IImage *img = generateImage(ti.name); @@ -1270,8 +1273,6 @@ bool TextureSource::generateImagePart(std::string part_of_name, video::IImage *img = generateImage(filename); if (img) { core::dimension2d dim = img->getDimension(); - infostream<<"Size "< pos_base(x, y); video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, dim); diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp index bf947cf85..170f54e20 100644 --- a/src/content/subgames.cpp +++ b/src/content/subgames.cpp @@ -253,7 +253,7 @@ std::vector getAvailableWorlds() worldspaths.insert(porting::path_user + DIR_DELIM + "worlds"); infostream << "Searching worlds..." << std::endl; for (const std::string &worldspath : worldspaths) { - infostream << " In " << worldspath << ": " << std::endl; + infostream << " In " << worldspath << ": "; std::vector dirvector = fs::GetDirListing(worldspath); for (const fs::DirListNode &dln : dirvector) { if (!dln.dir) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 75c3eaf37..680bf372a 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -711,13 +711,11 @@ float LuaEntitySAO::getMinimumSavedMovement() std::string LuaEntitySAO::getDescription() { - std::ostringstream os(std::ios::binary); - os<<"LuaEntitySAO at ("; - os<<(m_base_position.X/BS)<<","; - os<<(m_base_position.Y/BS)<<","; - os<<(m_base_position.Z/BS); - os<<")"; - return os.str(); + std::ostringstream oss; + oss << "LuaEntitySAO \"" << m_init_name << "\" "; + auto pos = floatToInt(m_base_position, BS); + oss << "at " << PP(pos); + return oss.str(); } void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason) diff --git a/src/craftdef.cpp b/src/craftdef.cpp index 0181ceb60..210605198 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -1066,8 +1066,8 @@ public: } virtual void registerCraft(CraftDefinition *def, IGameDef *gamedef) { - verbosestream << "registerCraft: registering craft definition: " - << def->dump() << std::endl; + TRACESTREAM(<< "registerCraft: registering craft definition: " + << def->dump() << std::endl); m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].push_back(def); CraftInput input; diff --git a/src/emerge.cpp b/src/emerge.cpp index fc1da4ee7..4835c3fad 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -136,7 +136,6 @@ EmergeManager::EmergeManager(Server *server) nthreads = Thread::getNumberOfProcessors() - 2; if (nthreads < 1) nthreads = 1; - verbosestream << "Using " << nthreads << " emerge threads." << std::endl; m_qlimit_total = g_settings->getU16("emergequeue_limit_total"); if (!g_settings->getU16NoEx("emergequeue_limit_diskonly", m_qlimit_diskonly)) diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 0d0afeb2b..ba7bd6a0b 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -463,7 +463,7 @@ public: } virtual void registerItem(const ItemDefinition &def) { - verbosestream<<"ItemDefManager: registering \""< "< " << convert_to << std::endl); m_aliases[name] = convert_to; } } diff --git a/src/main.cpp b/src/main.cpp index 1993f7c24..8df2fe7d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -207,9 +207,6 @@ int main(int argc, char *argv[]) sanity_check(!game_params.world_path.empty()); - infostream << "Using commanded world path [" - << game_params.world_path << "]" << std::endl; - if (game_params.is_dedicated_server) return run_dedicated_server(game_params, cmd_args) ? 0 : 1; @@ -686,8 +683,6 @@ static bool auto_select_world(GameParams *game_params) // No world was specified; try to select it automatically // Get information about available worlds - verbosestream << _("Determining world path") << std::endl; - std::vector worldspecs = getAvailableWorlds(); std::string world_path; @@ -708,7 +703,7 @@ static bool auto_select_world(GameParams *game_params) // This is the ultimate default world path world_path = porting::path_user + DIR_DELIM + "worlds" + DIR_DELIM + "world"; - infostream << "Creating default world at [" + infostream << "Using default world at [" << world_path << "]" << std::endl; } @@ -770,7 +765,6 @@ static bool determine_subgame(GameParams *game_params) assert(game_params->world_path != ""); // Pre-condition - verbosestream << _("Determining gameid/gamespec") << std::endl; // If world doesn't exist if (!game_params->world_path.empty() && !getWorldExists(game_params->world_path)) { diff --git a/src/map.cpp b/src/map.cpp index 40aba067e..eb69955ee 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1827,10 +1827,10 @@ void ServerMap::save(ModifiedState save_level) */ if(save_level == MOD_STATE_CLEAN || block_count != 0) { - infostream<<"ServerMap: Written: " - <id << " has timed out." - << " (source=peer->timeout_counter)" << std::endl; // Add peer to the list timeouted_peers.push_back(peer->id); @@ -292,7 +291,7 @@ void ConnectionSendThread::runTimeouts(float dtime) // Remove timed out peers for (u16 timeouted_peer : timeouted_peers) { - LOG(derr_con << m_connection->getDesc() + LOG(dout_con << m_connection->getDesc() << "RunTimeouts(): Removing peer " << timeouted_peer << std::endl); m_connection->deletePeer(timeouted_peer, true); } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 977a4533d..b6eca9497 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1458,7 +1458,7 @@ void NodeDefManager::deSerialize(std::istream &is) m_content_features.resize((u32)(i) + 1); m_content_features[i] = f; addNameIdMapping(i, f.name); - verbosestream << "deserialized " << f.name << std::endl; + TRACESTREAM(<< "NodeDef: deserialized " << f.name << std::endl); getNodeBoxUnion(f.selection_box, f, &m_selection_box_union); fixSelectionBoxIntUnion(); diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index ab3b5fe46..8da5debaa 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -86,7 +86,7 @@ void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &t void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) { SCRIPTAPI_PRECHECKHEADER - verbosestream << "scriptapi_add_environment" << std::endl; + verbosestream << "ScriptApiEnv: Environment initialized" << std::endl; setEnv(env); /* diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 0c174feca..ff77cba32 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -522,7 +522,6 @@ int ModApiItemMod::l_register_item_raw(lua_State *L) lua_getfield(L, table, "name"); if(lua_isstring(L, -1)){ name = readParam(L, -1); - verbosestream<<"register_item_raw: "<getFloat("server_map_save_interval"); + int n = 0; for (std::unordered_map::const_iterator it = m_mod_storages.begin(); it != m_mod_storages.end(); ++it) { if (it->second->isModified()) { it->second->save(getModStoragePath()); + n++; } } + if (n > 0) + infostream << "Saved " << n << " modified mod storages." << std::endl; } } @@ -809,7 +812,6 @@ void Server::AsyncRunStep(bool initial_step) disable_single_change_sending ? 5 : 30); break; case MEET_BLOCK_NODE_METADATA_CHANGED: { - verbosestream << "Server: MEET_BLOCK_NODE_METADATA_CHANGED" << std::endl; prof.add("MEET_BLOCK_NODE_METADATA_CHANGED", 1); if (!event->is_private_change) { // Don't send the change yet. Collect them to eliminate dupes. @@ -825,7 +827,6 @@ void Server::AsyncRunStep(bool initial_step) break; } case MEET_OTHER: - infostream << "Server: MEET_OTHER" << std::endl; prof.add("MEET_OTHER", 1); for (const v3s16 &modified_block : event->modified_blocks) { m_clients.markBlockposAsNotSent(modified_block); @@ -2535,9 +2536,6 @@ void Server::fillMediaCache() void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_code) { - verbosestream << "Server: Announcing files to id(" << peer_id << ")" - << std::endl; - // Make packet NetworkPacket pkt(TOCLIENT_ANNOUNCE_MEDIA, 0, peer_id); @@ -2560,6 +2558,9 @@ void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_co pkt << g_settings->get("remote_media"); Send(&pkt); + + verbosestream << "Server: Announcing files to id(" << peer_id + << "): count=" << media_sent << " size=" << pkt.getSize() << std::endl; } struct SendableMedia @@ -2938,10 +2939,8 @@ void Server::UpdateCrafting(RemotePlayer *player) if (!clist || clist->getSize() == 0) return; - if (!clist->checkModified()) { - verbosestream << "Skip Server::UpdateCrafting(): list unmodified" << std::endl; + if (!clist->checkModified()) return; - } // Get a preview for crafting ItemStack preview; diff --git a/src/server/mods.cpp b/src/server/mods.cpp index c5616dcd6..c8d8a28e2 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "scripting_server.h" #include "content/subgames.h" +#include "porting.h" /** * Manage server mods @@ -66,14 +67,10 @@ void ServerModManager::loadMods(ServerScripting *script) "Only characters [a-z0-9_] are allowed."); } std::string script_path = mod.path + DIR_DELIM + "init.lua"; - infostream << " [" << padStringRight(mod.name, 12) << "] [\"" - << script_path << "\"]" << std::endl; - auto t = std::chrono::steady_clock::now(); + auto t = porting::getTimeMs(); script->loadMod(script_path, mod.name); infostream << "Mod \"" << mod.name << "\" loaded after " - << std::chrono::duration_cast( - std::chrono::steady_clock::now() - t).count() * 0.001f - << " seconds" << std::endl; + << (porting::getTimeMs() - t) << " ms" << std::endl; } // Run a callback when mods are loaded -- cgit v1.2.3 From 659245acc7dcc28e345b8dfa50571102f4f07728 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 8 Apr 2020 20:14:08 +0200 Subject: Work around LuaJIT issues on aarch64 (#9614) - Move the text segment below the 47-bit limit, needed for script_exception_wrapper which must be lightuserdata - Replace CUSTOM_RIDX_SCRIPTAPI with full userdata --- src/CMakeLists.txt | 10 ++++++++-- src/script/common/c_internal.h | 9 +++++++++ src/script/cpp_api/s_base.cpp | 4 ++++ src/script/cpp_api/s_security.cpp | 7 ++++++- src/script/lua_api/l_base.cpp | 7 ++++++- 5 files changed, 33 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6afa5b8fe..d579bb965 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -661,7 +661,7 @@ endif() # Set some optimizations and tweaks -include(CheckCXXCompilerFlag) +include(CheckCSourceCompiles) if(MSVC) # Visual Studio @@ -695,13 +695,19 @@ else() else() set(RELEASE_WARNING_FLAGS "") endif() - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(WARNING_FLAGS "${WARNING_FLAGS} -Wsign-compare") endif() + if(APPLE AND USE_LUAJIT) # required per http://luajit.org/install.html SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000") + elseif(UNIX AND USE_LUAJIT) + check_c_source_compiles("#ifndef __aarch64__\n#error\n#endif\nint main(){}" IS_AARCH64) + if(IS_AARCH64) + # Move text segment below LuaJIT's 47-bit limit (see issue #9367) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Ttext-segment=0x200000000") + endif() endif() if(MINGW) diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h index d8cf3fe76..747400769 100644 --- a/src/script/common/c_internal.h +++ b/src/script/common/c_internal.h @@ -54,6 +54,15 @@ extern "C" { #define CUSTOM_RIDX_CURRENT_MOD_NAME (CUSTOM_RIDX_BASE + 2) #define CUSTOM_RIDX_BACKTRACE (CUSTOM_RIDX_BASE + 3) +// Determine if CUSTOM_RIDX_SCRIPTAPI will hold a light or full userdata +#if defined(__aarch64__) && USE_LUAJIT +/* LuaJIT has a 47-bit limit for lightuserdata on this platform and we cannot + * assume that the ScriptApi class was allocated at a fitting address. */ +#define INDIRECT_SCRIPTAPI_RIDX 1 +#else +#define INDIRECT_SCRIPTAPI_RIDX 0 +#endif + // Pushes the error handler onto the stack and returns its index #define PUSH_ERROR_HANDLER(L) \ (lua_rawgeti((L), LUA_REGISTRYINDEX, CUSTOM_RIDX_BACKTRACE), lua_gettop((L))) diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index ecb1ba39b..f234a15d4 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -90,7 +90,11 @@ ScriptApiBase::ScriptApiBase(ScriptingType type): luaL_openlibs(m_luastack); // Make the ScriptApiBase* accessible to ModApiBase +#if INDIRECT_SCRIPTAPI_RIDX + *(void **)(lua_newuserdata(m_luastack, sizeof(void *))) = this; +#else lua_pushlightuserdata(m_luastack, this); +#endif lua_rawseti(m_luastack, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI); // Add and save an error handler diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index b5abcfb5d..2afa3a191 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -499,7 +499,12 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, // Get server from registry lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI); - ScriptApiBase *script = (ScriptApiBase *) lua_touserdata(L, -1); + ScriptApiBase *script; +#if INDIRECT_SCRIPTAPI_RIDX + script = (ScriptApiBase *) *(void**)(lua_touserdata(L, -1)); +#else + script = (ScriptApiBase *) lua_touserdata(L, -1); +#endif lua_pop(L, 1); const IGameDef *gamedef = script->getGameDef(); if (!gamedef) diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 8486fc7bc..c980bba39 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -30,7 +30,12 @@ ScriptApiBase *ModApiBase::getScriptApiBase(lua_State *L) { // Get server from registry lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI); - ScriptApiBase *sapi_ptr = (ScriptApiBase*) lua_touserdata(L, -1); + ScriptApiBase *sapi_ptr; +#if INDIRECT_SCRIPTAPI_RIDX + sapi_ptr = (ScriptApiBase*) *(void**)(lua_touserdata(L, -1)); +#else + sapi_ptr = (ScriptApiBase*) lua_touserdata(L, -1); +#endif lua_pop(L, 1); return sapi_ptr; } -- cgit v1.2.3 From 3ad5388c6d3894e2f4aa7158cc2b62b626f0f967 Mon Sep 17 00:00:00 2001 From: TheTermos <55103816+TheTermos@users.noreply.github.com> Date: Wed, 8 Apr 2020 22:45:05 +0200 Subject: Collision various fixes (#9343) --- src/client/localplayer.h | 2 + src/collision.cpp | 222 +++++++++++++++++++--------------------- src/collision.h | 2 +- src/unittest/test_collision.cpp | 64 ++++++------ 4 files changed, 141 insertions(+), 149 deletions(-) (limited to 'src') diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 95dceb1f4..d88ae17ac 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -141,6 +141,8 @@ public: void setCollisionbox(const aabb3f &box) { m_collisionbox = box; } + const aabb3f& getCollisionbox() const { return m_collisionbox; } + float getZoomFOV() const { return m_zoom_fov; } void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; } diff --git a/src/collision.cpp b/src/collision.cpp index a443be7ab..0d37ea436 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -25,16 +25,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gamedef.h" #ifndef SERVER #include "client/clientenvironment.h" +#include "client/localplayer.h" #endif #include "serverenvironment.h" #include "serverobject.h" #include "util/timetaker.h" #include "profiler.h" -// float error is 10 - 9.96875 = 0.03125 -//#define COLL_ZERO 0.032 // broken unit tests -#define COLL_ZERO 0 - struct NearbyCollisionInfo { NearbyCollisionInfo(bool is_ul, bool is_obj, int bouncy, @@ -61,118 +58,102 @@ struct NearbyCollisionInfo { // The time after which the collision occurs is stored in dtime. CollisionAxis axisAlignedCollision( const aabb3f &staticbox, const aabb3f &movingbox, - const v3f &speed, f32 d, f32 *dtime) + const v3f &speed, f32 *dtime) { //TimeTaker tt("axisAlignedCollision"); - f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X) - COLL_ZERO; // reduce box size for solve collision stuck (flying sand) - f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); // - COLL_ZERO; // Y - no sense for falling, but maybe try later - f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z) - COLL_ZERO; - aabb3f relbox( - movingbox.MinEdge.X - staticbox.MinEdge.X, - movingbox.MinEdge.Y - staticbox.MinEdge.Y, - movingbox.MinEdge.Z - staticbox.MinEdge.Z, - movingbox.MaxEdge.X - staticbox.MinEdge.X, - movingbox.MaxEdge.Y - staticbox.MinEdge.Y, - movingbox.MaxEdge.Z - staticbox.MinEdge.Z + movingbox.MaxEdge.X - movingbox.MinEdge.X + staticbox.MaxEdge.X - staticbox.MinEdge.X, // sum of the widths + movingbox.MaxEdge.Y - movingbox.MinEdge.Y + staticbox.MaxEdge.Y - staticbox.MinEdge.Y, + movingbox.MaxEdge.Z - movingbox.MinEdge.Z + staticbox.MaxEdge.Z - staticbox.MinEdge.Z, + std::max(movingbox.MaxEdge.X, staticbox.MaxEdge.X) - std::min(movingbox.MinEdge.X, staticbox.MinEdge.X), //outer bounding 'box' dimensions + std::max(movingbox.MaxEdge.Y, staticbox.MaxEdge.Y) - std::min(movingbox.MinEdge.Y, staticbox.MinEdge.Y), + std::max(movingbox.MaxEdge.Z, staticbox.MaxEdge.Z) - std::min(movingbox.MinEdge.Z, staticbox.MinEdge.Z) ); - if(speed.X > 0) // Check for collision with X- plane - { - if (relbox.MaxEdge.X <= d) { - *dtime = -relbox.MaxEdge.X / speed.X; - if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) && - (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) && - (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) && - (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO)) - return COLLISION_AXIS_X; - } - else if(relbox.MinEdge.X > xsize) - { - return COLLISION_AXIS_NONE; - } - } - else if(speed.X < 0) // Check for collision with X+ plane - { - if (relbox.MinEdge.X >= xsize - d) { - *dtime = (xsize - relbox.MinEdge.X) / speed.X; - if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) && - (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) && - (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) && - (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO)) - return COLLISION_AXIS_X; - } - else if(relbox.MaxEdge.X < 0) - { - return COLLISION_AXIS_NONE; + const f32 dtime_max = *dtime; + const f32 inner_margin = -1.5f; + f32 distance; + f32 time; + + if (speed.X) { + distance = relbox.MaxEdge.X - relbox.MinEdge.X; + + *dtime = distance >= 0 ? std::abs(distance / speed.X) : -std::abs(distance / speed.X); + time = std::max(*dtime, 0.0f); + + if (distance > inner_margin) { + if (*dtime <= dtime_max) { + if ((speed.X > 0 && staticbox.MaxEdge.X > movingbox.MaxEdge.X) || + (speed.X < 0 && staticbox.MinEdge.X < movingbox.MinEdge.X)) { + if ( + (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y) + - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y) + - relbox.MinEdge.Y < 0) && + (std::max(movingbox.MaxEdge.Z + speed.Z * time, staticbox.MaxEdge.Z) + - std::min(movingbox.MinEdge.Z + speed.Z * time, staticbox.MinEdge.Z) + - relbox.MinEdge.Z < 0) + ) + return COLLISION_AXIS_X; + } + } else { + return COLLISION_AXIS_NONE; + } } } // NO else if here - if(speed.Y > 0) // Check for collision with Y- plane - { - if (relbox.MaxEdge.Y <= d) { - *dtime = -relbox.MaxEdge.Y / speed.Y; - if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) && - (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) && - (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) && - (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO)) - return COLLISION_AXIS_Y; - } - else if(relbox.MinEdge.Y > ysize) - { - return COLLISION_AXIS_NONE; - } - } - else if(speed.Y < 0) // Check for collision with Y+ plane - { - if (relbox.MinEdge.Y >= ysize - d) { - *dtime = (ysize - relbox.MinEdge.Y) / speed.Y; - if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) && - (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) && - (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) && - (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO)) - return COLLISION_AXIS_Y; - } - else if(relbox.MaxEdge.Y < 0) - { - return COLLISION_AXIS_NONE; + if (speed.Y) { + distance = relbox.MaxEdge.Y - relbox.MinEdge.Y; + + *dtime = distance >= 0 ? std::abs(distance / speed.Y) : -std::abs(distance / speed.Y); + time = std::max(*dtime, 0.0f); + + if (distance > inner_margin) { + if (*dtime <= dtime_max) { + if ((speed.Y > 0 && staticbox.MaxEdge.Y > movingbox.MaxEdge.Y) || + (speed.Y < 0 && staticbox.MinEdge.Y < movingbox.MinEdge.Y)) { + if ( + (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X) + - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X) + - relbox.MinEdge.X < 0) && + (std::max(movingbox.MaxEdge.Z + speed.Z * time, staticbox.MaxEdge.Z) + - std::min(movingbox.MinEdge.Z + speed.Z * time, staticbox.MinEdge.Z) + - relbox.MinEdge.Z < 0) + ) + return COLLISION_AXIS_Y; + } + } else { + return COLLISION_AXIS_NONE; + } } } // NO else if here - if(speed.Z > 0) // Check for collision with Z- plane - { - if (relbox.MaxEdge.Z <= d) { - *dtime = -relbox.MaxEdge.Z / speed.Z; - if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) && - (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) && - (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) && - (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO)) - return COLLISION_AXIS_Z; - } - //else if(relbox.MinEdge.Z > zsize) - //{ - // return COLLISION_AXIS_NONE; - //} - } - else if(speed.Z < 0) // Check for collision with Z+ plane - { - if (relbox.MinEdge.Z >= zsize - d) { - *dtime = (zsize - relbox.MinEdge.Z) / speed.Z; - if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) && - (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) && - (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) && - (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO)) - return COLLISION_AXIS_Z; + if (speed.Z) { + distance = relbox.MaxEdge.Z - relbox.MinEdge.Z; + + *dtime = distance >= 0 ? std::abs(distance / speed.Z) : -std::abs(distance / speed.Z); + time = std::max(*dtime, 0.0f); + + if (distance > inner_margin) { + if (*dtime <= dtime_max) { + if ((speed.Z > 0 && staticbox.MaxEdge.Z > movingbox.MaxEdge.Z) || + (speed.Z < 0 && staticbox.MinEdge.Z < movingbox.MinEdge.Z)) { + if ( + (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X) + - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X) + - relbox.MinEdge.X < 0) && + (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y) + - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y) + - relbox.MinEdge.Y < 0) + ) + return COLLISION_AXIS_Z; + } + } } - //else if(relbox.MaxEdge.Z < 0) - //{ - // return COLLISION_AXIS_NONE; - //} } return COLLISION_AXIS_NONE; @@ -405,22 +386,25 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, } } } +#ifndef SERVER + if (self && c_env) { + LocalPlayer *lplayer = c_env->getLocalPlayer(); + if (lplayer->getParent() == nullptr) { + aabb3f lplayer_collisionbox = lplayer->getCollisionbox(); + v3f lplayer_pos = lplayer->getPosition(); + lplayer_collisionbox.MinEdge += lplayer_pos; + lplayer_collisionbox.MaxEdge += lplayer_pos; + cinfo.emplace_back(false, true, 0, v3s16(), lplayer_collisionbox); + } + } +#endif } //tt3 /* Collision detection */ - /* - Collision uncertainty radius - Make it a bit larger than the maximum distance of movement - */ - f32 d = pos_max_d * 1.1f; - // A fairly large value in here makes moving smoother - //f32 d = 0.15*BS; - - // This should always apply, otherwise there are glitches - assert(d > pos_max_d); // invariant + f32 d = 0.0f; int loopcount = 0; @@ -450,9 +434,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, continue; // Find nearest collision of the two boxes (raytracing-like) - f32 dtime_tmp; + f32 dtime_tmp = nearest_dtime; CollisionAxis collided = axisAlignedCollision(box_info.box, - movingbox, *speed_f, d, &dtime_tmp); + movingbox, *speed_f, &dtime_tmp); if (collided == -1 || dtime_tmp >= nearest_dtime) continue; @@ -470,11 +454,18 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, // Otherwise, a collision occurred. NearbyCollisionInfo &nearest_info = cinfo[nearest_boxindex]; const aabb3f& cbox = nearest_info.box; + + //movingbox except moved to the horizontal position it would be after step up + aabb3f stepbox = movingbox; + stepbox.MinEdge.X += speed_f->X * dtime; + stepbox.MinEdge.Z += speed_f->Z * dtime; + stepbox.MaxEdge.X += speed_f->X * dtime; + stepbox.MaxEdge.Z += speed_f->Z * dtime; // Check for stairs. bool step_up = (nearest_collided != COLLISION_AXIS_Y) && // must not be Y direction (movingbox.MinEdge.Y < cbox.MaxEdge.Y) && (movingbox.MinEdge.Y + stepheight > cbox.MaxEdge.Y) && - (!wouldCollideWithCeiling(cinfo, movingbox, + (!wouldCollideWithCeiling(cinfo, stepbox, cbox.MaxEdge.Y - movingbox.MinEdge.Y, d)); @@ -483,7 +474,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, // Move to the point of collision and reduce dtime by nearest_dtime if (nearest_dtime < 0) { - // Handle negative nearest_dtime (can be caused by the d allowance) + // Handle negative nearest_dtime if (!step_up) { if (nearest_collided == COLLISION_AXIS_X) pos_f->X += speed_f->X * nearest_dtime; @@ -562,9 +553,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, Object touches ground if object's minimum Y is near node's maximum Y and object's X-Z-area overlaps with the node's X-Z-area. - - Use 0.15*BS so that it is easier to get on a node. */ + if (cbox.MaxEdge.X - d > box.MinEdge.X && cbox.MinEdge.X + d < box.MaxEdge.X && cbox.MaxEdge.Z - d > box.MinEdge.Z && cbox.MinEdge.Z + d < box.MaxEdge.Z) { @@ -574,7 +564,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, box.MinEdge += *pos_f; box.MaxEdge += *pos_f; } - if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.15f * BS) { + if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.05f) { result.touching_ground = true; if (box_info.is_object) diff --git a/src/collision.h b/src/collision.h index 85df02c96..fa47cccc1 100644 --- a/src/collision.h +++ b/src/collision.h @@ -77,7 +77,7 @@ collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef, // dtime receives time until first collision, invalid if -1 is returned CollisionAxis axisAlignedCollision( const aabb3f &staticbox, const aabb3f &movingbox, - const v3f &speed, f32 d, f32 *dtime); + const v3f &speed, f32 *dtime); // Helper function: // Checks if moving the movingbox up by the given distance would hit a ceiling. diff --git a/src/unittest/test_collision.cpp b/src/unittest/test_collision.cpp index 332d3fa13..2f39c2489 100644 --- a/src/unittest/test_collision.cpp +++ b/src/unittest/test_collision.cpp @@ -50,38 +50,38 @@ void TestCollision::testAxisAlignedCollision() aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1); v3f v(1, 0, 0); - f32 dtime = 0; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 1.000) < 0.001); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1); v3f v(-1, 0, 0); - f32 dtime = 0; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx-2, by+1.5, bz, bx-1, by+2.5, bz-1); v3f v(1, 0, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1); v3f v(0.5, 0.1, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 3.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 3.000) < 0.001); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1); v3f v(0.5, 0.1, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 3.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 3.000) < 0.001); } @@ -90,38 +90,38 @@ void TestCollision::testAxisAlignedCollision() aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1); v3f v(-1, 0, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 1.000) < 0.001); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1); v3f v(1, 0, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx+2, by, bz+1.5, bx+3, by+1, bz+3.5); v3f v(-1, 0, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1); v3f v(-0.5, 0.2, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 1); // Y, not X! + f32 dtime = 2.5f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 1); // Y, not X! UASSERT(fabs(dtime - 2.500) < 0.001); } { aabb3f s(bx, by, bz, bx+1, by+1, bz+1); aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1); v3f v(-0.5, 0.3, 0); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 2.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 2.000) < 0.001); } @@ -132,48 +132,48 @@ void TestCollision::testAxisAlignedCollision() aabb3f s(bx, by, bz, bx+2, by+2, bz+2); aabb3f m(bx+2.3, by+2.29, bz+2.29, bx+4.2, by+4.2, bz+4.2); v3f v(-1./3, -1./3, -1./3); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 0.9) < 0.001); } { aabb3f s(bx, by, bz, bx+2, by+2, bz+2); aabb3f m(bx+2.29, by+2.3, bz+2.29, bx+4.2, by+4.2, bz+4.2); v3f v(-1./3, -1./3, -1./3); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 1); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 1); UASSERT(fabs(dtime - 0.9) < 0.001); } { aabb3f s(bx, by, bz, bx+2, by+2, bz+2); aabb3f m(bx+2.29, by+2.29, bz+2.3, bx+4.2, by+4.2, bz+4.2); v3f v(-1./3, -1./3, -1./3); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 2); + f32 dtime = 1.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 2); UASSERT(fabs(dtime - 0.9) < 0.001); } { aabb3f s(bx, by, bz, bx+2, by+2, bz+2); aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.3, by-2.29, bz-2.29); v3f v(1./7, 1./7, 1./7); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0); + f32 dtime = 17.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0); UASSERT(fabs(dtime - 16.1) < 0.001); } { aabb3f s(bx, by, bz, bx+2, by+2, bz+2); aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.3, bz-2.29); v3f v(1./7, 1./7, 1./7); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 1); + f32 dtime = 17.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 1); UASSERT(fabs(dtime - 16.1) < 0.001); } { aabb3f s(bx, by, bz, bx+2, by+2, bz+2); aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.29, bz-2.3); v3f v(1./7, 1./7, 1./7); - f32 dtime; - UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 2); + f32 dtime = 17.0f; + UASSERT(axisAlignedCollision(s, m, v, &dtime) == 2); UASSERT(fabs(dtime - 16.1) < 0.001); } } -- cgit v1.2.3 From f648fb76aef96a1da608c64346fc65d4dd44caa8 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 10 Apr 2020 19:49:20 +0200 Subject: Drop genericobject.{cpp,h} (#9629) * Drop genericobject.{cpp,h} This file is not for generic object but for ActiveObject message passing. Put ownership of the various commands to the right objects and cleanup the related code. * Protect ServerActiveObject::m_messages_out * typo fix --- build/android/jni/Android.mk | 1 - src/CMakeLists.txt | 1 - src/activeobject.h | 16 ++ src/client/clientenvironment.cpp | 2 +- src/client/content_cao.cpp | 38 +++-- src/client/content_cao.h | 1 + src/content_sao.cpp | 266 ++++++++++++++++++++++++--------- src/content_sao.h | 19 +++ src/genericobject.cpp | 207 ------------------------- src/genericobject.h | 87 ----------- src/network/networkprotocol.h | 8 +- src/server.cpp | 7 +- src/serverenvironment.cpp | 5 +- src/serverobject.cpp | 31 ++++ src/serverobject.h | 16 +- util/travis/clang-format-whitelist.txt | 2 - 16 files changed, 300 insertions(+), 407 deletions(-) delete mode 100644 src/genericobject.cpp delete mode 100644 src/genericobject.h (limited to 'src') diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index 72b0daab6..a2f32440a 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -176,7 +176,6 @@ LOCAL_SRC_FILES := \ jni/src/environment.cpp \ jni/src/face_position_cache.cpp \ jni/src/filesys.cpp \ - jni/src/genericobject.cpp \ jni/src/gettext.cpp \ jni/src/gui/guiAnimatedImage.cpp \ jni/src/gui/guiBackgroundImage.cpp \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d579bb965..4b1d6d647 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -384,7 +384,6 @@ set(common_SRCS environment.cpp face_position_cache.cpp filesys.cpp - genericobject.cpp gettext.cpp httpfetch.cpp hud.cpp diff --git a/src/activeobject.h b/src/activeobject.h index 4a2de92cd..c83243f86 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -55,6 +55,22 @@ struct ActiveObjectMessage std::string datastring; }; +enum ActiveObjectCommand { + AO_CMD_SET_PROPERTIES, + AO_CMD_UPDATE_POSITION, + AO_CMD_SET_TEXTURE_MOD, + AO_CMD_SET_SPRITE, + AO_CMD_PUNCHED, + AO_CMD_UPDATE_ARMOR_GROUPS, + AO_CMD_SET_ANIMATION, + AO_CMD_SET_BONE_POSITION, + AO_CMD_ATTACH_TO, + AO_CMD_SET_PHYSICS_OVERRIDE, + AO_CMD_UPDATE_NAMETAG_ATTRIBUTES, + AO_CMD_SPAWN_INFANT, + AO_CMD_SET_ANIMATION_SPEED +}; + /* Parent class for ServerActiveObject and ClientActiveObject */ diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 52d133781..6840f2db3 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -450,7 +450,7 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type, // Object initialized: if ((obj = getActiveObject(new_id))) { // Final step is to update all children which are already known - // Data provided by GENERIC_CMD_SPAWN_INFANT + // Data provided by AO_CMD_SPAWN_INFANT const auto &children = obj->getAttachmentChildIds(); for (auto c_id : children) { if (auto *o = getActiveObject(c_id)) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 8509eccb5..798899f9a 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -304,7 +304,6 @@ void TestCAO::processMessage(const std::string &data) GenericCAO */ -#include "genericobject.h" #include "clientobject.h" GenericCAO::GenericCAO(Client *client, ClientEnvironment *env): @@ -1421,14 +1420,23 @@ void GenericCAO::updateAttachments() } } +void GenericCAO::readAOMessageProperties(std::istream &is) +{ + // Reset object properties first + m_prop = ObjectProperties(); + + // Then read the whole new stream + m_prop.deSerialize(is); +} + void GenericCAO::processMessage(const std::string &data) { //infostream<<"GenericCAO: Got message"<physics_override_sneak_glitch = sneak_glitch; player->physics_override_new_move = new_move; } - } else if (cmd == GENERIC_CMD_SET_ANIMATION) { + } else if (cmd == AO_CMD_SET_ANIMATION) { // TODO: change frames send as v2s32 value v2f range = readV2F32(is); if (!m_is_local_player) { @@ -1565,17 +1573,17 @@ void GenericCAO::processMessage(const std::string &data) updateAnimation(); } } - } else if (cmd == GENERIC_CMD_SET_ANIMATION_SPEED) { + } else if (cmd == AO_CMD_SET_ANIMATION_SPEED) { m_animation_speed = readF32(is); updateAnimationSpeed(); - } else if (cmd == GENERIC_CMD_SET_BONE_POSITION) { + } else if (cmd == AO_CMD_SET_BONE_POSITION) { std::string bone = deSerializeString(is); v3f position = readV3F32(is); v3f rotation = readV3F32(is); m_bone_position[bone] = core::vector2d(position, rotation); updateBonePosition(); - } else if (cmd == GENERIC_CMD_ATTACH_TO) { + } else if (cmd == AO_CMD_ATTACH_TO) { u16 parent_id = readS16(is); std::string bone = deSerializeString(is); v3f position = readV3F32(is); @@ -1586,7 +1594,7 @@ void GenericCAO::processMessage(const std::string &data) // localplayer itself can't be attached to localplayer if (!m_is_local_player) m_is_visible = !m_attached_to_local; - } else if (cmd == GENERIC_CMD_PUNCHED) { + } else if (cmd == AO_CMD_PUNCHED) { u16 result_hp = readU16(is); // Use this instead of the send damage to not interfere with prediction @@ -1624,7 +1632,7 @@ void GenericCAO::processMessage(const std::string &data) if (!m_is_player) clearChildAttachments(); } - } else if (cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS) { + } else if (cmd == AO_CMD_UPDATE_ARMOR_GROUPS) { m_armor_groups.clear(); int armor_groups_size = readU16(is); for(int i=0; inametag_pos = pos; } - } else if (cmd == GENERIC_CMD_SPAWN_INFANT) { + } else if (cmd == AO_CMD_SPAWN_INFANT) { u16 child_id = readU16(is); u8 type = readU8(is); // maybe this will be useful later (void)type; diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 7c29cbf17..c53b81433 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -68,6 +68,7 @@ struct SmoothTranslatorWrappedv3f : SmoothTranslator class GenericCAO : public ClientActiveObject { private: + void readAOMessageProperties(std::istream &is); // Only set at initialization std::string m_name = ""; bool m_is_player = false; diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 680bf372a..be7674f52 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "remoteplayer.h" #include "server.h" #include "scripting_server.h" -#include "genericobject.h" #include "settings.h" #include #include @@ -289,6 +288,120 @@ void UnitSAO::notifyObjectPropertiesModified() m_properties_sent = false; } +std::string UnitSAO::generateUpdateAttachmentCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_ATTACH_TO); + // parameters + writeS16(os, m_attachment_parent_id); + os << serializeString(m_attachment_bone); + writeV3F32(os, m_attachment_position); + writeV3F32(os, m_attachment_rotation); + return os.str(); +} + +std::string UnitSAO::generateUpdateBonePositionCommand(const std::string &bone, + const v3f &position, const v3f &rotation) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_BONE_POSITION); + // parameters + os << serializeString(bone); + writeV3F32(os, position); + writeV3F32(os, rotation); + return os.str(); +} + + +std::string UnitSAO::generateUpdateAnimationSpeedCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_ANIMATION_SPEED); + // parameters + writeF32(os, m_animation_speed); + return os.str(); +} + +std::string UnitSAO::generateUpdateAnimationCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_ANIMATION); + // parameters + writeV2F32(os, m_animation_range); + writeF32(os, m_animation_speed); + writeF32(os, m_animation_blend); + // these are sent inverted so we get true when the server sends nothing + writeU8(os, !m_animation_loop); + return os.str(); +} + + +std::string UnitSAO::generateUpdateArmorGroupsCommand() const +{ + std::ostringstream os(std::ios::binary); + writeU8(os, AO_CMD_UPDATE_ARMOR_GROUPS); + writeU16(os, m_armor_groups.size()); + for (const auto &armor_group : m_armor_groups) { + os<>::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - std::string str = gob_cmd_update_bone_position((*ii).first, + std::string str = generateUpdateBonePositionCommand((*ii).first, (*ii).second.X, (*ii).second.Y); // create message and add to list ActiveObjectMessage aom(getId(), true, str); @@ -538,7 +647,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) if (!m_attachment_sent) { m_attachment_sent = true; - std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation); + std::string str = generateUpdateAttachmentCommand(); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); @@ -560,16 +669,14 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) std::ostringstream msg_os(std::ios::binary); msg_os << serializeLongString(getPropertyPacket()); // message 1 - msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 - msg_os << serializeLongString(gob_cmd_update_animation( - m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3 + msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 + msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 for (std::unordered_map>::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first, + msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size } - msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, - m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4 + msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 int message_count = 4 + m_bone_position.size(); for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); (ii != m_attachment_child_ids.end()); ++ii) { @@ -577,12 +684,11 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) message_count++; // TODO after a protocol bump: only send the object initialization data // to older clients (superfluous since this message exists) - msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), - obj->getClientInitializationData(protocol_version))); + msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); } } - msg_os << serializeLongString(gob_cmd_set_texture_mod(m_current_texture_modifier)); + msg_os << serializeLongString(generateSetTextureModCommand()); message_count++; writeU8(os, message_count); @@ -655,10 +761,8 @@ u16 LuaEntitySAO::punch(v3f dir, setHP((s32)getHP() - result.damage, PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); - std::string str = gob_cmd_punched(getHP()); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + sendPunchCommand(); } } @@ -750,11 +854,9 @@ v3f LuaEntitySAO::getAcceleration() void LuaEntitySAO::setTextureMod(const std::string &mod) { - std::string str = gob_cmd_set_texture_mod(mod); m_current_texture_modifier = mod; // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, generateSetTextureModCommand()); } std::string LuaEntitySAO::getTextureMod() const @@ -762,18 +864,42 @@ std::string LuaEntitySAO::getTextureMod() const return m_current_texture_modifier; } + +std::string LuaEntitySAO::generateSetTextureModCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_TEXTURE_MOD); + // parameters + os << serializeString(m_current_texture_modifier); + return os.str(); +} + +std::string LuaEntitySAO::generateSetSpriteCommand(v2s16 p, u16 num_frames, + f32 framelength, bool select_horiz_by_yawpitch) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_SPRITE); + // parameters + writeV2S16(os, p); + writeU16(os, num_frames); + writeF32(os, framelength); + writeU8(os, select_horiz_by_yawpitch); + return os.str(); +} + void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength, bool select_horiz_by_yawpitch) { - std::string str = gob_cmd_set_sprite( + std::string str = generateSetSpriteCommand( p, num_frames, framelength, select_horiz_by_yawpitch ); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } std::string LuaEntitySAO::getName() @@ -783,7 +909,7 @@ std::string LuaEntitySAO::getName() std::string LuaEntitySAO::getPropertyPacket() { - return gob_cmd_set_properties(m_prop); + return generateSetPropertiesCommand(m_prop); } void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) @@ -802,7 +928,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) float update_interval = m_env->getSendRecommendedInterval(); - std::string str = gob_cmd_update_position( + std::string str = generateUpdatePositionCommand( m_base_position, m_velocity, m_acceleration, @@ -812,8 +938,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) update_interval ); // create message and add to list - ActiveObjectMessage aom(getId(), false, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), false, str); } bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const @@ -949,28 +1074,23 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) std::ostringstream msg_os(std::ios::binary); msg_os << serializeLongString(getPropertyPacket()); // message 1 - msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 - msg_os << serializeLongString(gob_cmd_update_animation( - m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3 + msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 + msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 for (std::unordered_map>::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first, + msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size } - msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, - m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4 - msg_os << serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed, - m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak, - m_physics_override_sneak_glitch, m_physics_override_new_move)); // 5 - // (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only. - msg_os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6 + msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 + msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5 + // (AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only. + msg_os << serializeLongString(generateUpdateNametagAttributesCommand(m_prop.nametag_color)); // 6 int message_count = 6 + m_bone_position.size(); for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); ii != m_attachment_child_ids.end(); ++ii) { if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { message_count++; - msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(), - obj->getClientInitializationData(protocol_version))); + msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); } } @@ -1116,7 +1236,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) else pos = m_base_position; - std::string str = gob_cmd_update_position( + std::string str = generateUpdatePositionCommand( pos, v3f(0.0f, 0.0f, 0.0f), v3f(0.0f, 0.0f, 0.0f), @@ -1126,61 +1246,63 @@ void PlayerSAO::step(float dtime, bool send_recommended) update_interval ); // create message and add to list - ActiveObjectMessage aom(getId(), false, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), false, str); } if (!m_armor_groups_sent) { m_armor_groups_sent = true; - std::string str = gob_cmd_update_armor_groups( - m_armor_groups); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); } if (!m_physics_override_sent) { m_physics_override_sent = true; - std::string str = gob_cmd_update_physics_override(m_physics_override_speed, - m_physics_override_jump, m_physics_override_gravity, - m_physics_override_sneak, m_physics_override_sneak_glitch, - m_physics_override_new_move); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand()); } if (!m_animation_sent) { m_animation_sent = true; - std::string str = gob_cmd_update_animation( - m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand()); } if (!m_bone_position_sent) { m_bone_position_sent = true; for (std::unordered_map>::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - std::string str = gob_cmd_update_bone_position((*ii).first, + std::string str = generateUpdateBonePositionCommand((*ii).first, (*ii).second.X, (*ii).second.Y); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } } if (!m_attachment_sent) { m_attachment_sent = true; - std::string str = gob_cmd_update_attachment(m_attachment_parent_id, - m_attachment_bone, m_attachment_position, m_attachment_rotation); + std::string str = generateUpdateAttachmentCommand(); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } } +std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_PHYSICS_OVERRIDE); + // parameters + writeF32(os, m_physics_override_speed); + writeF32(os, m_physics_override_jump); + writeF32(os, m_physics_override_gravity); + // these are sent inverted so we get true when the server sends nothing + writeU8(os, !m_physics_override_sneak); + writeU8(os, !m_physics_override_sneak_glitch); + writeU8(os, !m_physics_override_new_move); + return os.str(); +} + void PlayerSAO::setBasePosition(const v3f &position) { if (m_player && position != m_base_position) @@ -1284,10 +1406,8 @@ u16 PlayerSAO::punch(v3f dir, // No effect if PvP disabled or if immortal if (isImmortal() || !g_settings->getBool("enable_pvp")) { if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { - std::string str = gob_cmd_punched(getHP()); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + sendPunchCommand(); return 0; } } @@ -1307,10 +1427,8 @@ u16 PlayerSAO::punch(v3f dir, PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); } else { // override client prediction if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { - std::string str = gob_cmd_punched(getHP()); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + sendPunchCommand(); } } @@ -1408,7 +1526,7 @@ void PlayerSAO::unlinkPlayerSessionAndSave() std::string PlayerSAO::getPropertyPacket() { m_prop.is_visible = (true); - return gob_cmd_set_properties(m_prop); + return generateSetPropertiesCommand(m_prop); } void PlayerSAO::setMaxSpeedOverride(const v3f &vel) diff --git a/src/content_sao.h b/src/content_sao.h index e9047daf0..e0304299a 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -67,6 +67,19 @@ public: ServerActiveObject *getParent() const; ObjectProperties* accessObjectProperties(); void notifyObjectPropertiesModified(); + + std::string generateUpdateAttachmentCommand() const; + std::string generateUpdateAnimationSpeedCommand() const; + std::string generateUpdateAnimationCommand() const; + std::string generateUpdateArmorGroupsCommand() const; + static std::string generateUpdatePositionCommand(const v3f &position, const v3f &velocity, + const v3f &acceleration, const v3f &rotation, bool do_interpolate, + bool is_movement_end, f32 update_interval); + std::string generateSetPropertiesCommand(const ObjectProperties &prop) const; + void sendPunchCommand(); + static std::string generateUpdateBonePositionCommand(const std::string &bone, + const v3f &position, const v3f &rotation); + protected: u16 m_hp = 1; @@ -98,6 +111,8 @@ protected: private: void onAttach(int parent_id); void onDetach(int parent_id); + + std::string generatePunchCommand(u16 result_hp) const; }; /* @@ -155,6 +170,9 @@ public: private: std::string getPropertyPacket(); void sendPosition(bool do_interpolate, bool is_movement_end); + std::string generateSetTextureModCommand() const; + static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames, f32 framelength, + bool select_horiz_by_yawpitch); std::string m_init_name; std::string m_init_state; @@ -350,6 +368,7 @@ public: private: std::string getPropertyPacket(); void unlinkPlayerSessionAndSave(); + std::string generateUpdatePhysicsOverrideCommand() const; RemotePlayer *m_player = nullptr; session_t m_peer_id = 0; diff --git a/src/genericobject.cpp b/src/genericobject.cpp deleted file mode 100644 index 49d16001f..000000000 --- a/src/genericobject.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* -Minetest -Copyright (C) 2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "genericobject.h" -#include -#include "util/serialize.h" - -std::string gob_cmd_set_properties(const ObjectProperties &prop) -{ - std::ostringstream os(std::ios::binary); - writeU8(os, GENERIC_CMD_SET_PROPERTIES); - prop.serialize(os); - return os.str(); -} - -ObjectProperties gob_read_set_properties(std::istream &is) -{ - ObjectProperties prop; - prop.deSerialize(is); - return prop; -} - -std::string gob_cmd_update_position( - v3f position, - v3f velocity, - v3f acceleration, - v3f rotation, - bool do_interpolate, - bool is_movement_end, - f32 update_interval -){ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, GENERIC_CMD_UPDATE_POSITION); - // pos - writeV3F32(os, position); - // velocity - writeV3F32(os, velocity); - // acceleration - writeV3F32(os, acceleration); - // rotation - writeV3F32(os, rotation); - // do_interpolate - writeU8(os, do_interpolate); - // is_end_position (for interpolation) - writeU8(os, is_movement_end); - // update_interval (for interpolation) - writeF32(os, update_interval); - return os.str(); -} - -std::string gob_cmd_set_texture_mod(const std::string &mod) -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, GENERIC_CMD_SET_TEXTURE_MOD); - // parameters - os< - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#pragma once - -#include -#include "irrlichttypes_bloated.h" -#include -#include "itemgroup.h" - -enum GenericCMD { - GENERIC_CMD_SET_PROPERTIES, - GENERIC_CMD_UPDATE_POSITION, - GENERIC_CMD_SET_TEXTURE_MOD, - GENERIC_CMD_SET_SPRITE, - GENERIC_CMD_PUNCHED, - GENERIC_CMD_UPDATE_ARMOR_GROUPS, - GENERIC_CMD_SET_ANIMATION, - GENERIC_CMD_SET_BONE_POSITION, - GENERIC_CMD_ATTACH_TO, - GENERIC_CMD_SET_PHYSICS_OVERRIDE, - GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES, - GENERIC_CMD_SPAWN_INFANT, - GENERIC_CMD_SET_ANIMATION_SPEED -}; - -#include "object_properties.h" -std::string gob_cmd_set_properties(const ObjectProperties &prop); -ObjectProperties gob_read_set_properties(std::istream &is); - -std::string gob_cmd_update_position( - v3f position, - v3f velocity, - v3f acceleration, - v3f rotation, - bool do_interpolate, - bool is_movement_end, - f32 update_interval -); - -std::string gob_cmd_set_texture_mod(const std::string &mod); - -std::string gob_cmd_set_sprite( - v2s16 p, - u16 num_frames, - f32 framelength, - bool select_horiz_by_yawpitch -); - -std::string gob_cmd_punched(u16 result_hp); - -std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups); - -std::string gob_cmd_update_physics_override(float physics_override_speed, - float physics_override_jump, float physics_override_gravity, - bool sneak, bool sneak_glitch, bool new_move); - -std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend, bool frame_loop); - -std::string gob_cmd_update_animation_speed(float frame_speed); - -std::string gob_cmd_update_bone_position(const std::string &bone, v3f position, - v3f rotation); - -std::string gob_cmd_update_attachment(int parent_id, const std::string &bone, - v3f position, v3f rotation); - -std::string gob_cmd_update_nametag_attributes(video::SColor color); - -std::string gob_cmd_update_infant(u16 id, u8 type, - const std::string &client_initialization_data); diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index d3799868b..7223ce05c 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -70,8 +70,8 @@ with this program; if not, write to the Free Software Foundation, Inc., PROTOCOL_VERSION 14: Added transfer of player pressed keys to the server Added new messages for mesh and bone animation, as well as attachments - GENERIC_CMD_SET_ANIMATION - GENERIC_CMD_SET_BONE_POSITION + AO_CMD_SET_ANIMATION + AO_CMD_SET_BONE_POSITION GENERIC_CMD_SET_ATTACHMENT PROTOCOL_VERSION 15: Serialization format changes @@ -87,7 +87,7 @@ with this program; if not, write to the Free Software Foundation, Inc., damageGroups added to ToolCapabilities sound_place added to ItemDefinition PROTOCOL_VERSION 19: - GENERIC_CMD_SET_PHYSICS_OVERRIDE + AO_CMD_SET_PHYSICS_OVERRIDE PROTOCOL_VERSION 20: TOCLIENT_HUDADD TOCLIENT_HUDRM @@ -131,7 +131,7 @@ with this program; if not, write to the Free Software Foundation, Inc., Add TOCLIENT_HELLO for presenting server to client after client presentation Add TOCLIENT_AUTH_ACCEPT to accept connection from client - Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO + Rename GENERIC_CMD_SET_ATTACHMENT to AO_CMD_ATTACH_TO PROTOCOL_VERSION 26: Add TileDef tileable_horizontal, tileable_vertical flags PROTOCOL_VERSION 27: diff --git a/src/server.cpp b/src/server.cpp index 9eea45b31..062fe0798 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -35,7 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "mapblock.h" #include "serverobject.h" -#include "genericobject.h" #include "settings.h" #include "profiler.h" #include "log.h" @@ -721,7 +720,7 @@ void Server::AsyncRunStep(bool initial_step) // Go through every message for (const ActiveObjectMessage &aom : *list) { // Send position updates to players who do not see the attachment - if (aom.datastring[0] == GENERIC_CMD_UPDATE_POSITION) { + if (aom.datastring[0] == AO_CMD_UPDATE_POSITION) { if (sao->getId() == player->getId()) continue; @@ -1819,9 +1818,7 @@ void Server::SendPlayerHP(session_t peer_id) m_script->player_event(playersao,"health_changed"); // Send to other clients - std::string str = gob_cmd_punched(playersao->getHP()); - ActiveObjectMessage aom(playersao->getId(), true, str); - playersao->m_messages_out.push(aom); + playersao->sendPunchCommand(); } void Server::SendPlayerBreath(PlayerSAO *sao) diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 333d32ff5..2d3ee078e 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1420,10 +1420,7 @@ void ServerEnvironment::step(float dtime) // Step object obj->step(dtime, send_recommended); // Read messages from object - while (!obj->m_messages_out.empty()) { - this->m_active_object_messages.push(obj->m_messages_out.front()); - obj->m_messages_out.pop(); - } + obj->dumpAOMessagesToQueue(m_active_object_messages); }; m_ao_manager.step(dtime, cb_state); } diff --git a/src/serverobject.cpp b/src/serverobject.cpp index 1ed33f66b..119a41b7b 100644 --- a/src/serverobject.cpp +++ b/src/serverobject.cpp @@ -81,3 +81,34 @@ bool ServerActiveObject::setWieldedItem(const ItemStack &item) { return false; } + +std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 protocol_version) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SPAWN_INFANT); + // parameters + writeU16(os, infant_id); + writeU8(os, getSendType()); + os << serializeLongString(getClientInitializationData(protocol_version)); + return os.str(); +} + +std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const video::SColor &color) const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_UPDATE_NAMETAG_ATTRIBUTES); + // parameters + writeU8(os, 1); // version for forward compatibility + writeARGB8(os, color); + return os.str(); +} + +void ServerActiveObject::dumpAOMessagesToQueue(std::queue &queue) +{ + while (!m_messages_out.empty()) { + queue.push(m_messages_out.front()); + m_messages_out.pop(); + } +} \ No newline at end of file diff --git a/src/serverobject.h b/src/serverobject.h index 48689fcb4..2e013a6b6 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -113,7 +113,7 @@ public: The return value of this is passed to the client-side object when it is created */ - virtual std::string getClientInitializationData(u16 protocol_version){return "";} + virtual std::string getClientInitializationData(u16 protocol_version) {return "";} /* The return value of this is passed to the server-side object @@ -192,6 +192,10 @@ public: m_attached_particle_spawners.erase(id); } + std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version); + std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const; + + void dumpAOMessagesToQueue(std::queue &queue); /* Number of players which know about this object. Object won't be @@ -236,11 +240,6 @@ public: */ v3s16 m_static_block = v3s16(1337,1337,1337); - /* - Queue of messages to be sent to the client - */ - std::queue m_messages_out; - protected: virtual void onAttach(int parent_id) {} virtual void onDetach(int parent_id) {} @@ -255,6 +254,11 @@ protected: v3f m_base_position; std::unordered_set m_attached_particle_spawners; + /* + Queue of messages to be sent to the client + */ + std::queue m_messages_out; + private: // Used for creating objects based on type static std::map m_types; diff --git a/util/travis/clang-format-whitelist.txt b/util/travis/clang-format-whitelist.txt index 05b4a96c4..7b2fd8236 100644 --- a/util/travis/clang-format-whitelist.txt +++ b/util/travis/clang-format-whitelist.txt @@ -151,8 +151,6 @@ src/fontengine.h src/game.cpp src/gamedef.h src/game.h -src/genericobject.cpp -src/genericobject.h src/gettext.cpp src/gettext.h src/gui/guiAnimatedImage.cpp -- cgit v1.2.3 From 35e778ee9ff2e0e9ab096eaf2d1a903c5eaa42b3 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 10 Apr 2020 20:10:51 +0200 Subject: Move clientsimpleobject.h to client folder (#9630) This file is only called from client folder, retrieve its friends :) --- src/client/clientsimpleobject.h | 35 +++++++++++++++++++++++++++++++++++ src/clientsimpleobject.h | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 src/client/clientsimpleobject.h delete mode 100644 src/clientsimpleobject.h (limited to 'src') diff --git a/src/client/clientsimpleobject.h b/src/client/clientsimpleobject.h new file mode 100644 index 000000000..f4a40bcd3 --- /dev/null +++ b/src/client/clientsimpleobject.h @@ -0,0 +1,35 @@ +/* +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "irrlichttypes_bloated.h" +class ClientEnvironment; + +class ClientSimpleObject +{ +protected: +public: + bool m_to_be_removed = false; + + ClientSimpleObject() = default; + virtual ~ClientSimpleObject() = default; + + virtual void step(float dtime) {} +}; diff --git a/src/clientsimpleobject.h b/src/clientsimpleobject.h deleted file mode 100644 index f4a40bcd3..000000000 --- a/src/clientsimpleobject.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -Minetest -Copyright (C) 2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#pragma once - -#include "irrlichttypes_bloated.h" -class ClientEnvironment; - -class ClientSimpleObject -{ -protected: -public: - bool m_to_be_removed = false; - - ClientSimpleObject() = default; - virtual ~ClientSimpleObject() = default; - - virtual void step(float dtime) {} -}; -- cgit v1.2.3 From aa3cf400e2ca4096517e926dbae5b6337b2f1876 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 10 Apr 2020 20:36:16 +0200 Subject: Print error if invalid mapgen alias was detected (#9579) --- src/mapgen/mapgen.cpp | 7 +++++++ src/mapgen/mapgen_v6.cpp | 15 +++++++++++++++ src/mapgen/treegen.cpp | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) (limited to 'src') diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 79c429ff6..6c426ba41 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -629,6 +629,13 @@ MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emer // Lava falls back to water as both are suitable as cave liquids. if (c_lava_source == CONTENT_IGNORE) c_lava_source = c_water_source; + + if (c_stone == CONTENT_IGNORE) + errorstream << "Mapgen: Mapgen alias 'mapgen_stone' is invalid!" << std::endl; + if (c_water_source == CONTENT_IGNORE) + errorstream << "Mapgen: Mapgen alias 'mapgen_water_source' is invalid!" << std::endl; + if (c_river_water_source == CONTENT_IGNORE) + warningstream << "Mapgen: Mapgen alias 'mapgen_river_water_source' is invalid!" << std::endl; } diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index 653adc8ec..8a863c044 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -132,6 +132,21 @@ MapgenV6::MapgenV6(MapgenV6Params *params, EmergeManager *emerge) c_stair_cobble = c_cobble; if (c_stair_desert_stone == CONTENT_IGNORE) c_stair_desert_stone = c_desert_stone; + + if (c_stone == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_stone' is invalid!" << std::endl; + if (c_dirt == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_dirt' is invalid!" << std::endl; + if (c_dirt_with_grass == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_dirt_with_grass' is invalid!" << std::endl; + if (c_sand == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_sand' is invalid!" << std::endl; + if (c_water_source == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_water_source' is invalid!" << std::endl; + if (c_lava_source == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_lava_source' is invalid!" << std::endl; + if (c_cobble == CONTENT_IGNORE) + errorstream << "Mapgen v6: Mapgen alias 'mapgen_cobble' is invalid!" << std::endl; } diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index 0d8af2851..89bdef73b 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -44,6 +44,12 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, MapNode treenode(ndef->getId("mapgen_tree")); MapNode leavesnode(ndef->getId("mapgen_leaves")); MapNode applenode(ndef->getId("mapgen_apple")); + if (treenode == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_tree' is invalid!" << std::endl; + if (leavesnode == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_leaves' is invalid!" << std::endl; + if (applenode == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_apple' is invalid!" << std::endl; PseudoRandom pr(seed); s16 trunk_h = pr.range(4, 5); @@ -145,6 +151,9 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, TreeDef tree_definition) { MapNode dirtnode(ndef->getId("mapgen_dirt")); + if (dirtnode == CONTENT_IGNORE) + errorstream << "Treegen (make_ltree): Mapgen alias 'mapgen_dirt' is invalid!" << std::endl; + s32 seed; if (tree_definition.explicit_seed) seed = tree_definition.seed + 14002; @@ -662,6 +671,10 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, c_tree = ndef->getId("mapgen_tree"); if (c_leaves == CONTENT_IGNORE) c_leaves = ndef->getId("mapgen_leaves"); + if (c_tree == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_jungletree' is invalid!" << std::endl; + if (c_leaves == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_jungleleaves' is invalid!" << std::endl; MapNode treenode(c_tree); MapNode leavesnode(c_leaves); @@ -765,6 +778,10 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, c_leaves = ndef->getId("mapgen_leaves"); if (c_snow == CONTENT_IGNORE) c_snow = CONTENT_AIR; + if (c_tree == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_pine_tree' is invalid!" << std::endl; + if (c_leaves == CONTENT_IGNORE) + errorstream << "Treegen: Mapgen alias 'mapgen_pine_needles' is invalid!" << std::endl; MapNode treenode(c_tree); MapNode leavesnode(c_leaves); -- cgit v1.2.3 From f105bc8dc2444d98a9cd74a2caa0013ce2e07008 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 10 Apr 2020 21:45:07 +0200 Subject: A few initialization cleanups --- src/client/client.cpp | 8 ++++++-- src/client/game.cpp | 5 ++++- src/script/scripting_client.cpp | 8 +++++--- src/script/scripting_client.h | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/client/client.cpp b/src/client/client.cpp index c9cd24cb3..c3e2a4d2a 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -178,7 +178,7 @@ void Client::loadMods() infostream << mod.name << " "; infostream << std::endl; - // Load and run "mod" scripts + // Load "mod" scripts for (const ModSpec &mod : m_mods) { if (!string_allowed(mod.name, MODNAME_ALLOWED_CHARS)) { throw ModError("Error loading mod \"" + mod.name + @@ -188,7 +188,7 @@ void Client::loadMods() scanModIntoMemory(mod.name, mod.path); } - // Load and run "mod" scripts + // Run them for (const ModSpec &mod : m_mods) m_script->loadModFromMemory(mod.name); @@ -197,10 +197,14 @@ void Client::loadMods() // Run a callback when mods are loaded m_script->on_mods_loaded(); + + // Create objects if they're ready if (m_state == LC_Ready) m_script->on_client_ready(m_env.getLocalPlayer()); if (m_camera) m_script->on_camera_ready(m_camera); + if (m_minimap) + m_script->on_minimap_ready(m_minimap); } bool Client::checkBuiltinIntegrity() diff --git a/src/client/game.cpp b/src/client/game.cpp index 437cc7871..505108caf 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1407,8 +1407,11 @@ bool Game::createClient(const std::string &playername, } mapper = client->getMinimap(); - if (mapper) + if (mapper) { mapper->setMinimapMode(MINIMAP_MODE_OFF); + if (client->modsLoaded()) + client->getScript()->on_minimap_ready(mapper); + } return true; } diff --git a/src/script/scripting_client.cpp b/src/script/scripting_client.cpp index 1288b1df7..6643a9509 100644 --- a/src/script/scripting_client.cpp +++ b/src/script/scripting_client.cpp @@ -55,9 +55,6 @@ ClientScripting::ClientScripting(Client *client): InitializeModApi(L, top); lua_pop(L, 1); - if (client->getMinimap()) - LuaMinimap::create(L, client->getMinimap()); - // Push builtin initialization type lua_pushstring(L, "client"); lua_setglobal(L, "INIT"); @@ -94,3 +91,8 @@ void ClientScripting::on_camera_ready(Camera *camera) { LuaCamera::create(getStack(), camera); } + +void ClientScripting::on_minimap_ready(Minimap *minimap) +{ + LuaMinimap::create(getStack(), minimap); +} diff --git a/src/script/scripting_client.h b/src/script/scripting_client.h index cfecfa165..3088029f0 100644 --- a/src/script/scripting_client.h +++ b/src/script/scripting_client.h @@ -28,6 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc., class Client; class LocalPlayer; class Camera; +class Minimap; + class ClientScripting: virtual public ScriptApiBase, public ScriptApiSecurity, @@ -38,6 +40,7 @@ public: ClientScripting(Client *client); void on_client_ready(LocalPlayer *localplayer); void on_camera_ready(Camera *camera); + void on_minimap_ready(Minimap *minimap); private: virtual void InitializeModApi(lua_State *L, int top); -- cgit v1.2.3 From 054c5dfaa35dd79560a465ccc0ef214cb5f34c88 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 10 Apr 2020 22:06:24 +0200 Subject: scriptapi: Sort out ServerEnvironment / Environment distinction properly The API implementation is shared between CSM and SSM. Functions should retrieve a plain env when they do not need any server-specific functions. --- src/environment.cpp | 18 +++++++++++++++ src/environment.h | 10 +++++++++ src/script/lua_api/l_env.cpp | 50 +++++++++++++---------------------------- src/script/lua_api/l_internal.h | 29 ++++++++++++++++++++++-- src/script/lua_api/l_object.cpp | 2 +- src/serverenvironment.cpp | 18 --------------- src/serverenvironment.h | 10 --------- 7 files changed, 72 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/environment.cpp b/src/environment.cpp index 906f35219..c997be3ff 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -83,6 +83,24 @@ float Environment::getTimeOfDayF() return m_time_of_day_f; } +bool Environment::line_of_sight(v3f pos1, v3f pos2, v3s16 *p) +{ + // Iterate trough nodes on the line + voxalgo::VoxelLineIterator iterator(pos1 / BS, (pos2 - pos1) / BS); + do { + MapNode n = getMap().getNode(iterator.m_current_node_pos); + + // Return non-air + if (n.param0 != CONTENT_AIR) { + if (p) + *p = iterator.m_current_node_pos; + return false; + } + iterator.next(); + } while (iterator.m_current_index <= iterator.m_last_index); + return true; +} + /* Check if a node is pointable */ diff --git a/src/environment.h b/src/environment.h index f568ba228..91c33ba15 100644 --- a/src/environment.h +++ b/src/environment.h @@ -76,6 +76,16 @@ public: u32 getDayCount(); + /*! + * Returns false if the given line intersects with a + * non-air node, true otherwise. + * \param pos1 start of the line + * \param pos2 end of the line + * \param p output, position of the first non-air node + * the line intersects + */ + bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p = nullptr); + /*! * Gets the objects pointed by the shootline as * pointed things. diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 3169fa4cf..31e582d3d 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -139,8 +139,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n) int LuaRaycast::l_next(lua_State *L) { - MAP_LOCK_REQUIRED; - GET_ENV_PTR; + GET_PLAIN_ENV_PTR; bool csm = false; #ifndef SERVER @@ -384,7 +383,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L) // timeofday: nil = current time, 0 = night, 0.5 = day int ModApiEnvMod::l_get_node_light(lua_State *L) { - GET_ENV_PTR; + GET_PLAIN_ENV_PTR; // Do it v3s16 pos = read_v3s16(L, 1); @@ -488,10 +487,7 @@ int ModApiEnvMod::l_punch_node(lua_State *L) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_max_level(lua_State *L) { - Environment *env = getEnv(L); - if (!env) { - return 0; - } + GET_PLAIN_ENV_PTR; v3s16 pos = read_v3s16(L, 1); MapNode n = env->getMap().getNode(pos); @@ -503,10 +499,7 @@ int ModApiEnvMod::l_get_node_max_level(lua_State *L) // pos = {x=num, y=num, z=num} int ModApiEnvMod::l_get_node_level(lua_State *L) { - Environment *env = getEnv(L); - if (!env) { - return 0; - } + GET_PLAIN_ENV_PTR; v3s16 pos = read_v3s16(L, 1); MapNode n = env->getMap().getNode(pos); @@ -551,7 +544,7 @@ int ModApiEnvMod::l_add_node_level(lua_State *L) // find_nodes_with_meta(pos1, pos2) int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) { - GET_ENV_PTR; + GET_PLAIN_ENV_PTR; std::vector positions = env->getMap().findNodesWithMetadata( check_v3s16(L, 1), check_v3s16(L, 2)); @@ -728,10 +721,7 @@ int ModApiEnvMod::l_set_timeofday(lua_State *L) // get_timeofday() -> 0...1 int ModApiEnvMod::l_get_timeofday(lua_State *L) { - Environment *env = getEnv(L); - if (!env) { - return 0; - } + GET_PLAIN_ENV_PTR; // Do it int timeofday_mh = env->getTimeOfDay(); @@ -743,10 +733,7 @@ int ModApiEnvMod::l_get_timeofday(lua_State *L) // get_day_count() -> int int ModApiEnvMod::l_get_day_count(lua_State *L) { - Environment *env = getEnv(L); - if (!env) { - return 0; - } + GET_PLAIN_ENV_PTR; lua_pushnumber(L, env->getDayCount()); return 1; @@ -767,12 +754,9 @@ int ModApiEnvMod::l_get_gametime(lua_State *L) // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_node_near(lua_State *L) { - Environment *env = getEnv(L); - if (!env) { - return 0; - } + GET_PLAIN_ENV_PTR; - const NodeDefManager *ndef = getGameDef(L)->ndef(); + const NodeDefManager *ndef = env->getGameDef()->ndef(); v3s16 pos = read_v3s16(L, 1); int radius = luaL_checkinteger(L, 2); std::vector filter; @@ -815,20 +799,19 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) // nodenames: eg. {"ignore", "group:tree"} or "default:dirt" int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { - GET_ENV_PTR; + GET_PLAIN_ENV_PTR; v3s16 minp = read_v3s16(L, 1); v3s16 maxp = read_v3s16(L, 2); sortBoxVerticies(minp, maxp); + const NodeDefManager *ndef = env->getGameDef()->ndef(); + #ifndef SERVER - const NodeDefManager *ndef = getClient(L) ? getClient(L)->ndef() : getServer(L)->ndef(); if (getClient(L)) { minp = getClient(L)->CSMClampPos(minp); maxp = getClient(L)->CSMClampPos(maxp); } -#else - const NodeDefManager *ndef = getServer(L)->ndef(); #endif v3s16 cube = maxp - minp + 1; @@ -892,20 +875,19 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) * TODO */ - GET_ENV_PTR; + GET_PLAIN_ENV_PTR; v3s16 minp = read_v3s16(L, 1); v3s16 maxp = read_v3s16(L, 2); sortBoxVerticies(minp, maxp); + const NodeDefManager *ndef = env->getGameDef()->ndef(); + #ifndef SERVER - const NodeDefManager *ndef = getClient(L) ? getClient(L)->ndef() : getServer(L)->ndef(); if (getClient(L)) { minp = getClient(L)->CSMClampPos(minp); maxp = getClient(L)->CSMClampPos(maxp); } -#else - const NodeDefManager *ndef = getServer(L)->ndef(); #endif v3s16 cube = maxp - minp + 1; @@ -1034,7 +1016,7 @@ int ModApiEnvMod::l_clear_objects(lua_State *L) // line_of_sight(pos1, pos2) -> true/false, pos int ModApiEnvMod::l_line_of_sight(lua_State *L) { - GET_ENV_PTR; + GET_PLAIN_ENV_PTR; // read position 1 from lua v3f pos1 = checkFloatPos(L, 1); diff --git a/src/script/lua_api/l_internal.h b/src/script/lua_api/l_internal.h index bbedfe46e..a86eeaf79 100644 --- a/src/script/lua_api/l_internal.h +++ b/src/script/lua_api/l_internal.h @@ -32,14 +32,39 @@ with this program; if not, write to the Free Software Foundation, Inc., #define luamethod_aliased(class, name, alias) {#name, class::l_##name}, {#alias, class::l_##name} #define API_FCT(name) registerFunction(L, #name, l_##name, top) -#define MAP_LOCK_REQUIRED -#define NO_MAP_LOCK_REQUIRED +// For future use +#define MAP_LOCK_REQUIRED ((void)0) +#define NO_MAP_LOCK_REQUIRED ((void)0) +/* In debug mode ensure no code tries to retrieve the server env when it isn't + * actually available (in CSM) */ +#if !defined(SERVER) && !defined(NDEBUG) +#define DEBUG_ASSERT_NO_CLIENTAPI \ + FATAL_ERROR_IF(getClient(L) != nullptr, "Tried " \ + "to retrieve ServerEnvironment on client") +#else +#define DEBUG_ASSERT_NO_CLIENTAPI ((void)0) +#endif + +// Retrieve ServerEnvironment pointer as `env` (no map lock) #define GET_ENV_PTR_NO_MAP_LOCK \ + DEBUG_ASSERT_NO_CLIENTAPI; \ ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \ if (env == NULL) \ return 0 +// Retrieve ServerEnvironment pointer as `env` #define GET_ENV_PTR \ MAP_LOCK_REQUIRED; \ GET_ENV_PTR_NO_MAP_LOCK + +// Retrieve Environment pointer as `env` (no map lock) +#define GET_PLAIN_ENV_PTR_NO_MAP_LOCK \ + Environment *env = (Environment *)getEnv(L); \ + if (env == NULL) \ + return 0 + +// Retrieve Environment pointer as `env` +#define GET_PLAIN_ENV_PTR \ + MAP_LOCK_REQUIRED; \ + GET_PLAIN_ENV_PTR_NO_MAP_LOCK diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 23ed1ffe0..5cd978d73 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -533,7 +533,7 @@ int ObjectRef::l_set_local_animation(lua_State *L) // get_local_animation(self) int ObjectRef::l_get_local_animation(lua_State *L) { - NO_MAP_LOCK_REQUIRED + NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); if (player == NULL) diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 2d3ee078e..0ccbd772b 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -545,24 +545,6 @@ bool ServerEnvironment::removePlayerFromDatabase(const std::string &name) return m_player_database->removePlayer(name); } -bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, v3s16 *p) -{ - // Iterate trough nodes on the line - voxalgo::VoxelLineIterator iterator(pos1 / BS, (pos2 - pos1) / BS); - do { - MapNode n = getMap().getNode(iterator.m_current_node_pos); - - // Return non-air - if (n.param0 != CONTENT_AIR) { - if (p) - *p = iterator.m_current_node_pos; - return false; - } - iterator.next(); - } while (iterator.m_current_index <= iterator.m_last_index); - return true; -} - void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason, const std::string &str_reason, bool reconnect) { diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 3c7b7d059..bf10e3ca8 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -334,16 +334,6 @@ public: // This makes stuff happen void step(f32 dtime); - /*! - * Returns false if the given line intersects with a - * non-air node, true otherwise. - * \param pos1 start of the line - * \param pos2 end of the line - * \param p output, position of the first non-air node - * the line intersects - */ - bool line_of_sight(v3f pos1, v3f pos2, v3s16 *p = NULL); - u32 getGameTime() const { return m_game_time; } void reportMaxLagEstimate(float f) { m_max_lag_estimate = f; } -- cgit v1.2.3 From 5f3a17eb65c1ad9259f03bde346a8d69fe0c1069 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 10 Apr 2020 22:53:08 +0200 Subject: Implement minetest.sound_fade() --- doc/client_lua_api.txt | 7 +++++++ src/script/lua_api/l_client.cpp | 22 +++++++++++++++++++--- src/script/lua_api/l_client.h | 6 ++++++ src/script/lua_api/l_nodemeta.cpp | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 3612f851b..2c8ffd4d4 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -734,6 +734,13 @@ Call these functions only at load time! * `spec` is a `SimpleSoundSpec` * `parameters` is a sound parameter table * `minetest.sound_stop(handle)` + * `handle` is a handle returned by `minetest.sound_play` +* `minetest.sound_fade(handle, step, gain)` + * `handle` is a handle returned by `minetest.sound_play` + * `step` determines how fast a sound will fade. + Negative step will lower the sound volume, positive step will increase + the sound volume. + * `gain` the target gain for the fade. ### Timing * `minetest.after(time, func, ...)` diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index fba182492..e30c05260 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -209,7 +209,7 @@ int ModApiClient::l_gettext(lua_State *L) return 1; } -// get_node(pos) +// get_node_or_nil(pos) // pos = {x=num, y=num, z=num} int ModApiClient::l_get_node_or_nil(lua_State *L) { @@ -228,6 +228,7 @@ int ModApiClient::l_get_node_or_nil(lua_State *L) return 1; } +// get_langauge() int ModApiClient::l_get_language(lua_State *L) { #ifdef _WIN32 @@ -244,6 +245,7 @@ int ModApiClient::l_get_language(lua_State *L) return 2; } +// get_wielded_item() int ModApiClient::l_get_wielded_item(lua_State *L) { Client *client = getClient(L); @@ -266,12 +268,14 @@ int ModApiClient::l_get_meta(lua_State *L) return 1; } +// sound_play(spec, parameters) int ModApiClient::l_sound_play(lua_State *L) { ISoundManager *sound = getClient(L)->getSoundManager(); SimpleSoundSpec spec; read_soundspec(L, 1, spec); + float gain = 1.0f; float pitch = 1.0f; bool looped = false; @@ -293,21 +297,32 @@ int ModApiClient::l_sound_play(lua_State *L) } } - handle = sound->playSound(spec.name, looped, gain * spec.gain, 0.0f, pitch); + handle = sound->playSound(spec.name, looped, gain * spec.gain, spec.fade, pitch); lua_pushinteger(L, handle); return 1; } +// sound_stop(handle) int ModApiClient::l_sound_stop(lua_State *L) { - u32 handle = luaL_checkinteger(L, 1); + s32 handle = luaL_checkinteger(L, 1); getClient(L)->getSoundManager()->stopSound(handle); return 0; } +// sound_fade(handle, step, gain) +int ModApiClient::l_sound_fade(lua_State *L) +{ + s32 handle = luaL_checkinteger(L, 1); + float step = readParam(L, 2); + float gain = readParam(L, 3); + getClient(L)->getSoundManager()->fadeSound(handle, step, gain); + return 0; +} + // get_server_info() int ModApiClient::l_get_server_info(lua_State *L) { @@ -426,6 +441,7 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(get_meta); API_FCT(sound_play); API_FCT(sound_stop); + API_FCT(sound_fade); API_FCT(get_server_info); API_FCT(get_item_def); API_FCT(get_node_def); diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index 6d1f70b1d..5dc3efdad 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -69,6 +69,7 @@ private: // get_node(pos) static int l_get_node_or_nil(lua_State *L); + // get_language() static int l_get_language(lua_State *L); // get_wielded_item() @@ -77,10 +78,15 @@ private: // get_meta(pos) static int l_get_meta(lua_State *L); + // sound_play(spec, parameters) static int l_sound_play(lua_State *L); + // sound_stop(handle) static int l_sound_stop(lua_State *L); + // sound_fade(handle, step, gain) + static int l_sound_fade(lua_State *L); + // get_server_info() static int l_get_server_info(lua_State *L); diff --git a/src/script/lua_api/l_nodemeta.cpp b/src/script/lua_api/l_nodemeta.cpp index 229ce73db..57052cb42 100644 --- a/src/script/lua_api/l_nodemeta.cpp +++ b/src/script/lua_api/l_nodemeta.cpp @@ -55,11 +55,13 @@ Metadata* NodeMetaRef::getmeta(bool auto_create) void NodeMetaRef::clearMeta() { + SANITY_CHECK(!m_is_local); m_env->getMap().removeNodeMetadata(m_p); } void NodeMetaRef::reportMetadataChange(const std::string *name) { + SANITY_CHECK(!m_is_local); // NOTE: This same code is in rollback_interface.cpp // Inform other things that the metadata has changed NodeMetadata *meta = dynamic_cast(m_meta); -- cgit v1.2.3 From 1292bdbbcec45613c95aff9f2ea88aa49af25011 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 11 Apr 2020 00:09:11 +0200 Subject: Various features and fixes --- clientmods/preview/init.lua | 40 +++---------------- doc/client_lua_api.txt | 31 ++++++++++++--- src/script/lua_api/l_client.cpp | 26 +++++-------- src/script/lua_api/l_localplayer.cpp | 74 ++++++++++++++++++++++++++++++------ src/script/lua_api/l_localplayer.h | 21 +++++++++- 5 files changed, 123 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 5777adcaf..d2440369a 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -31,6 +31,7 @@ core.after(4, function() end) core.after(1, function() + print("armor: " .. dump(core.localplayer:get_armor_groups())) id = core.localplayer:hud_add({ hud_elem_type = "text", name = "example", @@ -125,19 +126,6 @@ core.register_chatcommand("dump", { end, }) -core.register_chatcommand("colorize_test", { - func = function(param) - return true, core.colorize("red", param) - end, -}) - -core.register_chatcommand("test_node", { - func = function(param) - core.display_chat_message(dump(core.get_node({x=0, y=0, z=0}))) - core.display_chat_message(dump(core.get_node_or_nil({x=0, y=0, z=0}))) - end, -}) - local function preview_minimap() local minimap = core.ui.minimap if not minimap then @@ -157,7 +145,7 @@ end core.after(2, function() print("[PREVIEW] loaded " .. modname .. " mod") modstorage:set_string("current_mod", modname) - print(modstorage:get_string("current_mod")) + assert(modstorage:get_string("current_mod") == modname) preview_minimap() end) @@ -184,30 +172,12 @@ end) core.register_on_punchnode(function(pos, node) print("The local player punched a node!") - local itemstack = core.get_wielded_item() - --[[ - -- getters - print(dump(itemstack:is_empty())) - print(dump(itemstack:get_name())) - print(dump(itemstack:get_count())) - print(dump(itemstack:get_wear())) - print(dump(itemstack:get_meta())) - print(dump(itemstack:get_metadata() - print(dump(itemstack:is_known())) - --print(dump(itemstack:get_definition())) - print(dump(itemstack:get_tool_capabilities())) - print(dump(itemstack:to_string())) - print(dump(itemstack:to_table())) - -- setters - print(dump(itemstack:set_name("default:dirt"))) - print(dump(itemstack:set_count("95"))) - print(dump(itemstack:set_wear(934))) - print(dump(itemstack:get_meta())) - print(dump(itemstack:get_metadata())) - --]] + local itemstack = core.localplayer:get_wielded_item() print(dump(itemstack:to_table())) print("pos:" .. dump(pos)) print("node:" .. dump(node)) + local meta = core.get_meta(pos) + print("punched meta: " .. (meta and dump(meta:to_table()) or "(missing)")) return false end) diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 2c8ffd4d4..71df91c68 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -804,8 +804,6 @@ Call these functions only at load time! * get max available level for leveled node ### Player -* `minetest.get_wielded_item()` - * Returns the itemstack the local player is holding * `minetest.send_chat_message(message)` * Act as if `message` was typed by the player into the terminal. * `minetest.run_server_chatcommand(cmd, param)` @@ -1006,6 +1004,10 @@ Methods: * returns player HP * `get_name()` * returns player name +* `get_wield_index()` + * returns the index of the wielded item +* `get_wielded_item()` + * returns the itemstack the player is holding * `is_attached()` * returns true if player is attached * `is_touching_ground()` @@ -1029,7 +1031,8 @@ Methods: jump = float, gravity = float, sneak = boolean, - sneak_glitch = boolean + sneak_glitch = boolean, + new_move = boolean, } ``` @@ -1081,8 +1084,26 @@ Methods: * returns last look horizontal angle * `get_last_look_vertical()`: * returns last look vertical angle -* `get_key_pressed()`: - * returns last key typed by the player +* `get_control()`: + * returns pressed player controls + +```lua + { + up = boolean, + down = boolean, + left = boolean, + right = boolean, + jump = boolean, + aux1 = boolean, + sneak = boolean, + zoom = boolean, + LMB = boolean, + RMB = boolean, + } +``` + +* `get_armor_groups()` + * returns a table with the armor group ratings * `hud_add(definition)` * add a HUD element described by HUD def, returns ID number on success and `nil` on failure. * See [`HUD definition`](#hud-definition-hud_add-hud_get) diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index e30c05260..aaced7cd0 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_base.h" #include "gettext.h" #include "l_internal.h" -#include "lua_api/l_item.h" #include "lua_api/l_nodemeta.h" #include "gui/mainmenumanager.h" #include "map.h" @@ -245,25 +244,18 @@ int ModApiClient::l_get_language(lua_State *L) return 2; } -// get_wielded_item() -int ModApiClient::l_get_wielded_item(lua_State *L) -{ - Client *client = getClient(L); - LocalPlayer *player = client->getEnv().getLocalPlayer(); - if (!player) - return 0; - - ItemStack selected_item; - player->getWieldedItem(&selected_item, nullptr); - LuaItemStack::create(L, selected_item); - return 1; -} - // get_meta(pos) int ModApiClient::l_get_meta(lua_State *L) { v3s16 p = read_v3s16(L, 1); - NodeMetadata *meta = getClient(L)->getEnv().getMap().getNodeMetadata(p); + + // check restrictions first + bool pos_ok; + getClient(L)->CSMGetNode(p, &pos_ok); + if (!pos_ok) + return 0; + + NodeMetadata *meta = getEnv(L)->getMap().getNodeMetadata(p); NodeMetaRef::createClient(L, meta); return 1; } @@ -390,6 +382,7 @@ int ModApiClient::l_get_node_def(lua_State *L) return 1; } +// get_privilege_list() int ModApiClient::l_get_privilege_list(lua_State *L) { const Client *client = getClient(L); @@ -436,7 +429,6 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(send_respawn); API_FCT(gettext); API_FCT(get_node_or_nil); - API_FCT(get_wielded_item); API_FCT(disconnect); API_FCT(get_meta); API_FCT(sound_play); diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 821b1cb66..851ede535 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -19,10 +19,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "l_localplayer.h" #include "l_internal.h" +#include "lua_api/l_item.h" #include "script/common/c_converter.h" #include "client/localplayer.h" #include "hud.h" #include "common/c_content.h" +#include "client/content_cao.h" LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m) { @@ -74,6 +76,26 @@ int LuaLocalPlayer::l_get_name(lua_State *L) return 1; } +// get_wield_index(self) +int LuaLocalPlayer::l_get_wield_index(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + + lua_pushinteger(L, player->getWieldIndex()); + return 1; +} + +// get_wielded_item(self) +int LuaLocalPlayer::l_get_wielded_item(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + + ItemStack selected_item; + player->getWieldedItem(&selected_item, nullptr); + LuaItemStack::create(L, selected_item); + return 1; +} + int LuaLocalPlayer::l_is_attached(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -130,6 +152,7 @@ int LuaLocalPlayer::l_swimming_vertical(lua_State *L) return 1; } +// get_physics_override(self) int LuaLocalPlayer::l_get_physics_override(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -150,14 +173,9 @@ int LuaLocalPlayer::l_get_physics_override(lua_State *L) lua_pushboolean(L, player->physics_override_sneak_glitch); lua_setfield(L, -2, "sneak_glitch"); - return 1; -} - -int LuaLocalPlayer::l_get_override_pos(lua_State *L) -{ - LocalPlayer *player = getobject(L, 1); + lua_pushboolean(L, player->physics_override_new_move); + lua_setfield(L, -2, "new_move"); - push_v3f(L, player->getPosition()); return 1; } @@ -193,14 +211,33 @@ int LuaLocalPlayer::l_get_last_look_horizontal(lua_State *L) return 1; } -int LuaLocalPlayer::l_get_key_pressed(lua_State *L) +// get_control(self) +int LuaLocalPlayer::l_get_control(lua_State *L) { LocalPlayer *player = getobject(L, 1); + const PlayerControl &c = player->getPlayerControl(); + + auto set = [L] (const char *name, bool value) { + lua_pushboolean(L, value); + lua_setfield(L, -2, name); + }; + + lua_createtable(L, 0, 12); + set("up", c.up); + set("down", c.down); + set("left", c.left); + set("right", c.right); + set("jump", c.jump); + set("aux1", c.aux1); + set("sneak", c.sneak); + set("zoom", c.zoom); + set("LMB", c.LMB); + set("RMB", c.RMB); - lua_pushinteger(L, player->last_keyPressed); return 1; } +// get_breath(self) int LuaLocalPlayer::l_get_breath(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -209,6 +246,7 @@ int LuaLocalPlayer::l_get_breath(lua_State *L) return 1; } +// get_pos(self) int LuaLocalPlayer::l_get_pos(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -217,6 +255,7 @@ int LuaLocalPlayer::l_get_pos(lua_State *L) return 1; } +// get_movement_acceleration(self) int LuaLocalPlayer::l_get_movement_acceleration(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -234,6 +273,7 @@ int LuaLocalPlayer::l_get_movement_acceleration(lua_State *L) return 1; } +// get_movement_speed(self) int LuaLocalPlayer::l_get_movement_speed(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -257,6 +297,7 @@ int LuaLocalPlayer::l_get_movement_speed(lua_State *L) return 1; } +// get_movement(self) int LuaLocalPlayer::l_get_movement(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -278,6 +319,13 @@ int LuaLocalPlayer::l_get_movement(lua_State *L) return 1; } +// get_armor_groups(self) +int LuaLocalPlayer::l_get_armor_groups(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + push_groups(L, player->getCAO()->getGroups()); + return 1; +} // hud_add(self, form) int LuaLocalPlayer::l_hud_add(lua_State *L) @@ -407,6 +455,8 @@ const luaL_Reg LuaLocalPlayer::methods[] = { luamethod(LuaLocalPlayer, get_velocity), luamethod(LuaLocalPlayer, get_hp), luamethod(LuaLocalPlayer, get_name), + luamethod(LuaLocalPlayer, get_wield_index), + luamethod(LuaLocalPlayer, get_wielded_item), luamethod(LuaLocalPlayer, is_attached), luamethod(LuaLocalPlayer, is_touching_ground), luamethod(LuaLocalPlayer, is_in_liquid), @@ -415,17 +465,19 @@ const luaL_Reg LuaLocalPlayer::methods[] = { luamethod(LuaLocalPlayer, is_climbing), luamethod(LuaLocalPlayer, swimming_vertical), luamethod(LuaLocalPlayer, get_physics_override), - luamethod(LuaLocalPlayer, get_override_pos), + // TODO: figure our if these are useful in any way luamethod(LuaLocalPlayer, get_last_pos), luamethod(LuaLocalPlayer, get_last_velocity), luamethod(LuaLocalPlayer, get_last_look_horizontal), luamethod(LuaLocalPlayer, get_last_look_vertical), - luamethod(LuaLocalPlayer, get_key_pressed), + // + luamethod(LuaLocalPlayer, get_control), luamethod(LuaLocalPlayer, get_breath), luamethod(LuaLocalPlayer, get_pos), luamethod(LuaLocalPlayer, get_movement_acceleration), luamethod(LuaLocalPlayer, get_movement_speed), luamethod(LuaLocalPlayer, get_movement), + luamethod(LuaLocalPlayer, get_armor_groups), luamethod(LuaLocalPlayer, hud_add), luamethod(LuaLocalPlayer, hud_remove), luamethod(LuaLocalPlayer, hud_change), diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index 01de2ed4e..4413f2bdb 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -32,12 +32,21 @@ private: // garbage collector static int gc_object(lua_State *L); + // get_velocity(self) static int l_get_velocity(lua_State *L); + // get_hp(self) static int l_get_hp(lua_State *L); + // get_name(self) static int l_get_name(lua_State *L); + // get_wield_index(self) + static int l_get_wield_index(lua_State *L); + + // get_wielded_item(self) + static int l_get_wielded_item(lua_State *L); + static int l_is_attached(lua_State *L); static int l_is_touching_ground(lua_State *L); static int l_is_in_liquid(lua_State *L); @@ -54,18 +63,28 @@ private: static int l_get_last_velocity(lua_State *L); static int l_get_last_look_vertical(lua_State *L); static int l_get_last_look_horizontal(lua_State *L); - static int l_get_key_pressed(lua_State *L); + // get_control(self) + static int l_get_control(lua_State *L); + + // get_breath(self) static int l_get_breath(lua_State *L); + // get_pos(self) static int l_get_pos(lua_State *L); + // get_movement_acceleration(self) static int l_get_movement_acceleration(lua_State *L); + // get_movement_speed(self) static int l_get_movement_speed(lua_State *L); + // get_movement(self) static int l_get_movement(lua_State *L); + // get_armor_groups(self) + static int l_get_armor_groups(lua_State *L); + // hud_add(self, id, form) static int l_hud_add(lua_State *L); -- cgit v1.2.3 From fbf74dc52456b13b0dbd7bb9d3206e5828254910 Mon Sep 17 00:00:00 2001 From: Alex <24834740+GreenXenith@users.noreply.github.com> Date: Sat, 11 Apr 2020 04:45:14 -0700 Subject: Use TILE_MATERIAL_ALPHA for use_texture_alpha entity flag (#9639) Fixes #9637. --- src/client/content_cao.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 798899f9a..39ea4ab1e 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -584,7 +584,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc) IShaderSource *shader_source = m_client->getShaderSource(); u32 shader_id = shader_source->getShader( "object_shader", - TILE_MATERIAL_BASIC, + (m_prop.use_texture_alpha) ? TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC, NDT_NORMAL); m_material_type = shader_source->getShaderInfo(shader_id).material; } else { -- cgit v1.2.3 From 01b3f26c7bc62305b205136bb95a2a4550761c3c Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 11 Apr 2020 15:31:02 +0200 Subject: Formspec: No spec ID for static text labels Fixes #9634 --- src/gui/guiFormSpecMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 59cd130ef..acb153569 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1424,7 +1424,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, if (!is_editable && !is_multiline) { // spec field id to 0, this stops submit searching for a value that isn't there gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, - this, spec.fid); + this, 0); return; } -- cgit v1.2.3 From 6d43736172f8459cb70219186ae003c56c389f2a Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Fri, 10 Apr 2020 21:25:42 +0200 Subject: Move serveractiveobject & unitsao Move serverobject.{cpp,h} to server/serveractiveobject.{cpp,h} Move UnitSAO class to dedicated files --- build/android/jni/Android.mk | 2 +- src/CMakeLists.txt | 1 - src/collision.cpp | 2 +- src/content_sao.cpp | 296 ------------------------------ src/content_sao.h | 92 +--------- src/emerge.cpp | 1 - src/environment.cpp | 1 - src/inventorymanager.cpp | 2 +- src/mapgen/mapgen_v6.cpp | 1 - src/script/common/c_content.cpp | 2 +- src/script/cpp_api/s_base.cpp | 2 +- src/script/lua_api/l_object.cpp | 2 +- src/server.cpp | 2 +- src/server/CMakeLists.txt | 2 + src/server/activeobjectmgr.h | 2 +- src/server/serveractiveobject.cpp | 114 ++++++++++++ src/server/serveractiveobject.h | 265 +++++++++++++++++++++++++++ src/server/unit_sao.cpp | 318 +++++++++++++++++++++++++++++++++ src/server/unit_sao.h | 113 ++++++++++++ src/serverobject.cpp | 114 ------------ src/serverobject.h | 265 --------------------------- util/travis/clang-format-whitelist.txt | 6 +- 22 files changed, 823 insertions(+), 782 deletions(-) create mode 100644 src/server/serveractiveobject.cpp create mode 100644 src/server/serveractiveobject.h create mode 100644 src/server/unit_sao.cpp create mode 100644 src/server/unit_sao.h delete mode 100644 src/serverobject.cpp delete mode 100644 src/serverobject.h (limited to 'src') diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index a2f32440a..32a16c174 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -259,7 +259,7 @@ LOCAL_SRC_FILES := \ jni/src/serverenvironment.cpp \ jni/src/serverlist.cpp \ jni/src/server/mods.cpp \ - jni/src/serverobject.cpp \ + jni/src/server/serveractiveobject.cpp \ jni/src/settings.cpp \ jni/src/staticobject.cpp \ jni/src/tileanimation.cpp \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b1d6d647..faa117d41 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -421,7 +421,6 @@ set(common_SRCS server.cpp serverenvironment.cpp serverlist.cpp - serverobject.cpp settings.cpp staticobject.cpp terminal_chat_console.cpp diff --git a/src/collision.cpp b/src/collision.cpp index 0d37ea436..d9fbd3202 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/localplayer.h" #endif #include "serverenvironment.h" -#include "serverobject.h" +#include "server/serveractiveobject.h" #include "util/timetaker.h" #include "profiler.h" diff --git a/src/content_sao.cpp b/src/content_sao.cpp index be7674f52..0d387b53a 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -106,302 +106,6 @@ private: // Prototype (registers item for deserialization) TestSAO proto_TestSAO(NULL, v3f(0,0,0)); -/* - UnitSAO - */ - -UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos): - ServerActiveObject(env, pos) -{ - // Initialize something to armor groups - m_armor_groups["fleshy"] = 100; -} - -ServerActiveObject *UnitSAO::getParent() const -{ - if (!m_attachment_parent_id) - return nullptr; - // Check if the parent still exists - ServerActiveObject *obj = m_env->getActiveObject(m_attachment_parent_id); - - return obj; -} - -void UnitSAO::setArmorGroups(const ItemGroupList &armor_groups) -{ - m_armor_groups = armor_groups; - m_armor_groups_sent = false; -} - -const ItemGroupList &UnitSAO::getArmorGroups() const -{ - return m_armor_groups; -} - -void UnitSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop) -{ - // store these so they can be updated to clients - m_animation_range = frame_range; - m_animation_speed = frame_speed; - m_animation_blend = frame_blend; - m_animation_loop = frame_loop; - m_animation_sent = false; -} - -void UnitSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop) -{ - *frame_range = m_animation_range; - *frame_speed = m_animation_speed; - *frame_blend = m_animation_blend; - *frame_loop = m_animation_loop; -} - -void UnitSAO::setAnimationSpeed(float frame_speed) -{ - m_animation_speed = frame_speed; - m_animation_speed_sent = false; -} - -void UnitSAO::setBonePosition(const std::string &bone, v3f position, v3f rotation) -{ - // store these so they can be updated to clients - m_bone_position[bone] = core::vector2d(position, rotation); - m_bone_position_sent = false; -} - -void UnitSAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotation) -{ - *position = m_bone_position[bone].X; - *rotation = m_bone_position[bone].Y; -} - -void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation) -{ - // Attachments need to be handled on both the server and client. - // If we just attach on the server, we can only copy the position of the parent. Attachments - // are still sent to clients at an interval so players might see them lagging, plus we can't - // read and attach to skeletal bones. - // If we just attach on the client, the server still sees the child at its original location. - // This breaks some things so we also give the server the most accurate representation - // even if players only see the client changes. - - int old_parent = m_attachment_parent_id; - m_attachment_parent_id = parent_id; - m_attachment_bone = bone; - m_attachment_position = position; - m_attachment_rotation = rotation; - m_attachment_sent = false; - - if (parent_id != old_parent) { - onDetach(old_parent); - onAttach(parent_id); - } -} - -void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position, - v3f *rotation) const -{ - *parent_id = m_attachment_parent_id; - *bone = m_attachment_bone; - *position = m_attachment_position; - *rotation = m_attachment_rotation; -} - -void UnitSAO::clearChildAttachments() -{ - for (int child_id : m_attachment_child_ids) { - // Child can be NULL if it was deleted earlier - if (ServerActiveObject *child = m_env->getActiveObject(child_id)) - child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); - } - m_attachment_child_ids.clear(); -} - -void UnitSAO::clearParentAttachment() -{ - ServerActiveObject *parent = nullptr; - if (m_attachment_parent_id) { - parent = m_env->getActiveObject(m_attachment_parent_id); - setAttachment(0, "", m_attachment_position, m_attachment_rotation); - } else { - setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); - } - // Do it - if (parent) - parent->removeAttachmentChild(m_id); -} - -void UnitSAO::addAttachmentChild(int child_id) -{ - m_attachment_child_ids.insert(child_id); -} - -void UnitSAO::removeAttachmentChild(int child_id) -{ - m_attachment_child_ids.erase(child_id); -} - -const std::unordered_set &UnitSAO::getAttachmentChildIds() const -{ - return m_attachment_child_ids; -} - -void UnitSAO::onAttach(int parent_id) -{ - if (!parent_id) - return; - - ServerActiveObject *parent = m_env->getActiveObject(parent_id); - - if (!parent || parent->isGone()) - return; // Do not try to notify soon gone parent - - if (parent->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) { - // Call parent's on_attach field - m_env->getScriptIface()->luaentity_on_attach_child(parent_id, this); - } -} - -void UnitSAO::onDetach(int parent_id) -{ - if (!parent_id) - return; - - ServerActiveObject *parent = m_env->getActiveObject(parent_id); - if (getType() == ACTIVEOBJECT_TYPE_LUAENTITY) - m_env->getScriptIface()->luaentity_on_detach(m_id, parent); - - if (!parent || parent->isGone()) - return; // Do not try to notify soon gone parent - - if (parent->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) - m_env->getScriptIface()->luaentity_on_detach_child(parent_id, this); -} - -ObjectProperties* UnitSAO::accessObjectProperties() -{ - return &m_prop; -} - -void UnitSAO::notifyObjectPropertiesModified() -{ - m_properties_sent = false; -} - -std::string UnitSAO::generateUpdateAttachmentCommand() const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_ATTACH_TO); - // parameters - writeS16(os, m_attachment_parent_id); - os << serializeString(m_attachment_bone); - writeV3F32(os, m_attachment_position); - writeV3F32(os, m_attachment_rotation); - return os.str(); -} - -std::string UnitSAO::generateUpdateBonePositionCommand(const std::string &bone, - const v3f &position, const v3f &rotation) -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SET_BONE_POSITION); - // parameters - os << serializeString(bone); - writeV3F32(os, position); - writeV3F32(os, rotation); - return os.str(); -} - - -std::string UnitSAO::generateUpdateAnimationSpeedCommand() const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SET_ANIMATION_SPEED); - // parameters - writeF32(os, m_animation_speed); - return os.str(); -} - -std::string UnitSAO::generateUpdateAnimationCommand() const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SET_ANIMATION); - // parameters - writeV2F32(os, m_animation_range); - writeF32(os, m_animation_speed); - writeF32(os, m_animation_blend); - // these are sent inverted so we get true when the server sends nothing - writeU8(os, !m_animation_loop); - return os.str(); -} - - -std::string UnitSAO::generateUpdateArmorGroupsCommand() const -{ - std::ostringstream os(std::ios::binary); - writeU8(os, AO_CMD_UPDATE_ARMOR_GROUPS); - writeU16(os, m_armor_groups.size()); - for (const auto &armor_group : m_armor_groups) { - os< &getAttachmentChildIds() const; - ServerActiveObject *getParent() const; - ObjectProperties* accessObjectProperties(); - void notifyObjectPropertiesModified(); - - std::string generateUpdateAttachmentCommand() const; - std::string generateUpdateAnimationSpeedCommand() const; - std::string generateUpdateAnimationCommand() const; - std::string generateUpdateArmorGroupsCommand() const; - static std::string generateUpdatePositionCommand(const v3f &position, const v3f &velocity, - const v3f &acceleration, const v3f &rotation, bool do_interpolate, - bool is_movement_end, f32 update_interval); - std::string generateSetPropertiesCommand(const ObjectProperties &prop) const; - void sendPunchCommand(); - static std::string generateUpdateBonePositionCommand(const std::string &bone, - const v3f &position, const v3f &rotation); - -protected: - u16 m_hp = 1; - - v3f m_rotation; - - bool m_properties_sent = true; - ObjectProperties m_prop; - - ItemGroupList m_armor_groups; - bool m_armor_groups_sent = false; - - v2f m_animation_range; - float m_animation_speed = 0.0f; - float m_animation_blend = 0.0f; - bool m_animation_loop = true; - bool m_animation_sent = false; - bool m_animation_speed_sent = false; - - // Stores position and rotation for each bone name - std::unordered_map> m_bone_position; - bool m_bone_position_sent = false; - - int m_attachment_parent_id = 0; - std::unordered_set m_attachment_child_ids; - std::string m_attachment_bone = ""; - v3f m_attachment_position; - v3f m_attachment_rotation; - bool m_attachment_sent = false; -private: - void onAttach(int parent_id); - void onDetach(int parent_id); - - std::string generatePunchCommand(u16 result_hp) const; -}; - /* LuaEntitySAO needs some internals exposed. */ diff --git a/src/emerge.cpp b/src/emerge.cpp index 4835c3fad..fe885447c 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -42,7 +42,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "profiler.h" #include "scripting_server.h" #include "server.h" -#include "serverobject.h" #include "settings.h" #include "voxel.h" diff --git a/src/environment.cpp b/src/environment.cpp index c997be3ff..6751f39e4 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "environment.h" #include "collision.h" #include "raycast.h" -#include "serverobject.h" #include "scripting_server.h" #include "server.h" #include "daynightratio.h" diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index 5a24f95a4..b6f464901 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "serverenvironment.h" #include "scripting_server.h" -#include "serverobject.h" +#include "server/serveractiveobject.h" #include "settings.h" #include "craftdef.h" #include "rollback_interface.h" diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index 8a863c044..f473f725d 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -//#include "serverobject.h" #include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index accbb1a87..60f12052f 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "log.h" #include "tool.h" -#include "serverobject.h" +#include "server/serveractiveobject.h" #include "porting.h" #include "mapgen/mg_schematic.h" #include "noise.h" diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index f234a15d4..16c20eeae 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_security.h" #include "lua_api/l_object.h" #include "common/c_converter.h" -#include "serverobject.h" +#include "server/serveractiveobject.h" #include "filesys.h" #include "content/mods.h" #include "porting.h" diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 5cd978d73..1ea144a1c 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_content.h" #include "log.h" #include "tool.h" -#include "serverobject.h" +#include "server/serveractiveobject.h" #include "content_sao.h" #include "remoteplayer.h" #include "server.h" diff --git a/src/server.cpp b/src/server.cpp index 062fe0798..529466f6b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "version.h" #include "filesys.h" #include "mapblock.h" -#include "serverobject.h" +#include "server/serveractiveobject.h" #include "settings.h" #include "profiler.h" #include "log.h" diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index e964c69ff..9fa5ed9fa 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,4 +1,6 @@ set(server_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/activeobjectmgr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/unit_sao.cpp PARENT_SCOPE) diff --git a/src/server/activeobjectmgr.h b/src/server/activeobjectmgr.h index a502ac6ed..5fea1bea6 100644 --- a/src/server/activeobjectmgr.h +++ b/src/server/activeobjectmgr.h @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "../activeobjectmgr.h" -#include "serverobject.h" +#include "serveractiveobject.h" namespace server { diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp new file mode 100644 index 000000000..3aa78c7d5 --- /dev/null +++ b/src/server/serveractiveobject.cpp @@ -0,0 +1,114 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "serveractiveobject.h" +#include +#include "inventory.h" +#include "constants.h" // BS +#include "log.h" + +ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos): + ActiveObject(0), + m_env(env), + m_base_position(pos) +{ +} + +ServerActiveObject* ServerActiveObject::create(ActiveObjectType type, + ServerEnvironment *env, u16 id, v3f pos, + const std::string &data) +{ + // Find factory function + std::map::iterator n; + n = m_types.find(type); + if(n == m_types.end()) { + // These are 0.3 entity types, return without error. + if (ACTIVEOBJECT_TYPE_ITEM <= type && type <= ACTIVEOBJECT_TYPE_MOBV2) { + return NULL; + } + + // If factory is not found, just return. + warningstream<<"ServerActiveObject: No factory for type=" + <second; + ServerActiveObject *object = (*f)(env, pos, data); + return object; +} + +void ServerActiveObject::registerType(u16 type, Factory f) +{ + std::map::iterator n; + n = m_types.find(type); + if(n != m_types.end()) + return; + m_types[type] = f; +} + +float ServerActiveObject::getMinimumSavedMovement() +{ + return 2.0*BS; +} + +ItemStack ServerActiveObject::getWieldedItem(ItemStack *selected, ItemStack *hand) const +{ + *selected = ItemStack(); + if (hand) + *hand = ItemStack(); + + return ItemStack(); +} + +bool ServerActiveObject::setWieldedItem(const ItemStack &item) +{ + return false; +} + +std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 protocol_version) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SPAWN_INFANT); + // parameters + writeU16(os, infant_id); + writeU8(os, getSendType()); + os << serializeLongString(getClientInitializationData(protocol_version)); + return os.str(); +} + +std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const video::SColor &color) const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_UPDATE_NAMETAG_ATTRIBUTES); + // parameters + writeU8(os, 1); // version for forward compatibility + writeARGB8(os, color); + return os.str(); +} + +void ServerActiveObject::dumpAOMessagesToQueue(std::queue &queue) +{ + while (!m_messages_out.empty()) { + queue.push(m_messages_out.front()); + m_messages_out.pop(); + } +} \ No newline at end of file diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h new file mode 100644 index 000000000..2e013a6b6 --- /dev/null +++ b/src/server/serveractiveobject.h @@ -0,0 +1,265 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include +#include "irrlichttypes_bloated.h" +#include "activeobject.h" +#include "inventorymanager.h" +#include "itemgroup.h" +#include "util/container.h" + +/* + +Some planning +------------- + +* Server environment adds an active object, which gets the id 1 +* The active object list is scanned for each client once in a while, + and it finds out what objects have been added that are not known + by the client yet. This scan is initiated by the Server class and + the result ends up directly to the server. +* A network packet is created with the info and sent to the client. +* Environment converts objects to static data and static data to + objects, based on how close players are to them. + +*/ + +class ServerEnvironment; +struct ItemStack; +struct ToolCapabilities; +struct ObjectProperties; +struct PlayerHPChangeReason; + +class ServerActiveObject : public ActiveObject +{ +public: + /* + NOTE: m_env can be NULL, but step() isn't called if it is. + Prototypes are used that way. + */ + ServerActiveObject(ServerEnvironment *env, v3f pos); + virtual ~ServerActiveObject() = default; + + virtual ActiveObjectType getSendType() const + { return getType(); } + + // Called after id has been set and has been inserted in environment + virtual void addedToEnvironment(u32 dtime_s){}; + // Called before removing from environment + virtual void removingFromEnvironment(){}; + // Returns true if object's deletion is the job of the + // environment + virtual bool environmentDeletes() const + { return true; } + + // Create a certain type of ServerActiveObject + static ServerActiveObject* create(ActiveObjectType type, + ServerEnvironment *env, u16 id, v3f pos, + const std::string &data); + + /* + Some simple getters/setters + */ + v3f getBasePosition() const { return m_base_position; } + void setBasePosition(v3f pos){ m_base_position = pos; } + ServerEnvironment* getEnv(){ return m_env; } + + /* + Some more dynamic interface + */ + + virtual void setPos(const v3f &pos) + { setBasePosition(pos); } + // continuous: if true, object does not stop immediately at pos + virtual void moveTo(v3f pos, bool continuous) + { setBasePosition(pos); } + // If object has moved less than this and data has not changed, + // saving to disk may be omitted + virtual float getMinimumSavedMovement(); + + virtual std::string getDescription(){return "SAO";} + + /* + Step object in time. + Messages added to messages are sent to client over network. + + send_recommended: + True at around 5-10 times a second, same for all objects. + This is used to let objects send most of the data at the + same time so that the data can be combined in a single + packet. + */ + virtual void step(float dtime, bool send_recommended){} + + /* + The return value of this is passed to the client-side object + when it is created + */ + virtual std::string getClientInitializationData(u16 protocol_version) {return "";} + + /* + The return value of this is passed to the server-side object + when it is created (converted from static to active - actually + the data is the static form) + */ + virtual void getStaticData(std::string *result) const + { + assert(isStaticAllowed()); + *result = ""; + } + /* + Return false in here to never save and instead remove object + on unload. getStaticData() will not be called in that case. + */ + virtual bool isStaticAllowed() const + {return true;} + + // Returns tool wear + virtual u16 punch(v3f dir, + const ToolCapabilities *toolcap = nullptr, + ServerActiveObject *puncher = nullptr, + float time_from_last_punch = 1000000.0f) + { return 0; } + virtual void rightClick(ServerActiveObject *clicker) + {} + virtual void setHP(s32 hp, const PlayerHPChangeReason &reason) + {} + virtual u16 getHP() const + { return 0; } + + virtual void setArmorGroups(const ItemGroupList &armor_groups) + {} + virtual const ItemGroupList &getArmorGroups() const + { static ItemGroupList rv; return rv; } + virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity) + {} + virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop) + {} + virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop) + {} + virtual void setAnimationSpeed(float frame_speed) + {} + virtual void setBonePosition(const std::string &bone, v3f position, v3f rotation) + {} + virtual void getBonePosition(const std::string &bone, v3f *position, v3f *lotation) + {} + virtual const std::unordered_set &getAttachmentChildIds() const + { static std::unordered_set rv; return rv; } + virtual ServerActiveObject *getParent() const { return nullptr; } + virtual ObjectProperties* accessObjectProperties() + { return NULL; } + virtual void notifyObjectPropertiesModified() + {} + + // Inventory and wielded item + virtual Inventory *getInventory() const + { return NULL; } + virtual InventoryLocation getInventoryLocation() const + { return InventoryLocation(); } + virtual void setInventoryModified() + {} + virtual std::string getWieldList() const + { return ""; } + virtual u16 getWieldIndex() const + { return 0; } + virtual ItemStack getWieldedItem(ItemStack *selected, + ItemStack *hand = nullptr) const; + virtual bool setWieldedItem(const ItemStack &item); + inline void attachParticleSpawner(u32 id) + { + m_attached_particle_spawners.insert(id); + } + inline void detachParticleSpawner(u32 id) + { + m_attached_particle_spawners.erase(id); + } + + std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version); + std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const; + + void dumpAOMessagesToQueue(std::queue &queue); + + /* + Number of players which know about this object. Object won't be + deleted until this is 0 to keep the id preserved for the right + object. + */ + u16 m_known_by_count = 0; + + /* + - Whether this object is to be removed when nobody knows about + it anymore. + - Removal is delayed to preserve the id for the time during which + it could be confused to some other object by some client. + - This is usually set to true by the step() method when the object wants + to be deleted but can be set by anything else too. + */ + bool m_pending_removal = false; + + /* + Same purpose as m_pending_removal but for deactivation. + deactvation = save static data in block, remove active object + + If this is set alongside with m_pending_removal, removal takes + priority. + */ + bool m_pending_deactivation = false; + + /* + A getter that unifies the above to answer the question: + "Can the environment still interact with this object?" + */ + inline bool isGone() const + { return m_pending_removal || m_pending_deactivation; } + + /* + Whether the object's static data has been stored to a block + */ + bool m_static_exists = false; + /* + The block from which the object was loaded from, and in which + a copy of the static data resides. + */ + v3s16 m_static_block = v3s16(1337,1337,1337); + +protected: + virtual void onAttach(int parent_id) {} + virtual void onDetach(int parent_id) {} + + // Used for creating objects based on type + typedef ServerActiveObject* (*Factory) + (ServerEnvironment *env, v3f pos, + const std::string &data); + static void registerType(u16 type, Factory f); + + ServerEnvironment *m_env; + v3f m_base_position; + std::unordered_set m_attached_particle_spawners; + + /* + Queue of messages to be sent to the client + */ + std::queue m_messages_out; + +private: + // Used for creating objects based on type + static std::map m_types; +}; diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp new file mode 100644 index 000000000..66be67522 --- /dev/null +++ b/src/server/unit_sao.cpp @@ -0,0 +1,318 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2013-2020 Minetest core developers & community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "unit_sao.h" +#include "scripting_server.h" +#include "serverenvironment.h" + +/* + UnitSAO + */ + +UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos): + ServerActiveObject(env, pos) +{ + // Initialize something to armor groups + m_armor_groups["fleshy"] = 100; +} + +ServerActiveObject *UnitSAO::getParent() const +{ + if (!m_attachment_parent_id) + return nullptr; + // Check if the parent still exists + ServerActiveObject *obj = m_env->getActiveObject(m_attachment_parent_id); + + return obj; +} + +void UnitSAO::setArmorGroups(const ItemGroupList &armor_groups) +{ + m_armor_groups = armor_groups; + m_armor_groups_sent = false; +} + +const ItemGroupList &UnitSAO::getArmorGroups() const +{ + return m_armor_groups; +} + +void UnitSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop) +{ + // store these so they can be updated to clients + m_animation_range = frame_range; + m_animation_speed = frame_speed; + m_animation_blend = frame_blend; + m_animation_loop = frame_loop; + m_animation_sent = false; +} + +void UnitSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop) +{ + *frame_range = m_animation_range; + *frame_speed = m_animation_speed; + *frame_blend = m_animation_blend; + *frame_loop = m_animation_loop; +} + +void UnitSAO::setAnimationSpeed(float frame_speed) +{ + m_animation_speed = frame_speed; + m_animation_speed_sent = false; +} + +void UnitSAO::setBonePosition(const std::string &bone, v3f position, v3f rotation) +{ + // store these so they can be updated to clients + m_bone_position[bone] = core::vector2d(position, rotation); + m_bone_position_sent = false; +} + +void UnitSAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotation) +{ + *position = m_bone_position[bone].X; + *rotation = m_bone_position[bone].Y; +} + +void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation) +{ + // Attachments need to be handled on both the server and client. + // If we just attach on the server, we can only copy the position of the parent. Attachments + // are still sent to clients at an interval so players might see them lagging, plus we can't + // read and attach to skeletal bones. + // If we just attach on the client, the server still sees the child at its original location. + // This breaks some things so we also give the server the most accurate representation + // even if players only see the client changes. + + int old_parent = m_attachment_parent_id; + m_attachment_parent_id = parent_id; + m_attachment_bone = bone; + m_attachment_position = position; + m_attachment_rotation = rotation; + m_attachment_sent = false; + + if (parent_id != old_parent) { + onDetach(old_parent); + onAttach(parent_id); + } +} + +void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position, + v3f *rotation) const +{ + *parent_id = m_attachment_parent_id; + *bone = m_attachment_bone; + *position = m_attachment_position; + *rotation = m_attachment_rotation; +} + +void UnitSAO::clearChildAttachments() +{ + for (int child_id : m_attachment_child_ids) { + // Child can be NULL if it was deleted earlier + if (ServerActiveObject *child = m_env->getActiveObject(child_id)) + child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); + } + m_attachment_child_ids.clear(); +} + +void UnitSAO::clearParentAttachment() +{ + ServerActiveObject *parent = nullptr; + if (m_attachment_parent_id) { + parent = m_env->getActiveObject(m_attachment_parent_id); + setAttachment(0, "", m_attachment_position, m_attachment_rotation); + } else { + setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); + } + // Do it + if (parent) + parent->removeAttachmentChild(m_id); +} + +void UnitSAO::addAttachmentChild(int child_id) +{ + m_attachment_child_ids.insert(child_id); +} + +void UnitSAO::removeAttachmentChild(int child_id) +{ + m_attachment_child_ids.erase(child_id); +} + +const std::unordered_set &UnitSAO::getAttachmentChildIds() const +{ + return m_attachment_child_ids; +} + +void UnitSAO::onAttach(int parent_id) +{ + if (!parent_id) + return; + + ServerActiveObject *parent = m_env->getActiveObject(parent_id); + + if (!parent || parent->isGone()) + return; // Do not try to notify soon gone parent + + if (parent->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) { + // Call parent's on_attach field + m_env->getScriptIface()->luaentity_on_attach_child(parent_id, this); + } +} + +void UnitSAO::onDetach(int parent_id) +{ + if (!parent_id) + return; + + ServerActiveObject *parent = m_env->getActiveObject(parent_id); + if (getType() == ACTIVEOBJECT_TYPE_LUAENTITY) + m_env->getScriptIface()->luaentity_on_detach(m_id, parent); + + if (!parent || parent->isGone()) + return; // Do not try to notify soon gone parent + + if (parent->getType() == ACTIVEOBJECT_TYPE_LUAENTITY) + m_env->getScriptIface()->luaentity_on_detach_child(parent_id, this); +} + +ObjectProperties* UnitSAO::accessObjectProperties() +{ + return &m_prop; +} + +void UnitSAO::notifyObjectPropertiesModified() +{ + m_properties_sent = false; +} + +std::string UnitSAO::generateUpdateAttachmentCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_ATTACH_TO); + // parameters + writeS16(os, m_attachment_parent_id); + os << serializeString(m_attachment_bone); + writeV3F32(os, m_attachment_position); + writeV3F32(os, m_attachment_rotation); + return os.str(); +} + +std::string UnitSAO::generateUpdateBonePositionCommand(const std::string &bone, + const v3f &position, const v3f &rotation) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_BONE_POSITION); + // parameters + os << serializeString(bone); + writeV3F32(os, position); + writeV3F32(os, rotation); + return os.str(); +} + + +std::string UnitSAO::generateUpdateAnimationSpeedCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_ANIMATION_SPEED); + // parameters + writeF32(os, m_animation_speed); + return os.str(); +} + +std::string UnitSAO::generateUpdateAnimationCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_ANIMATION); + // parameters + writeV2F32(os, m_animation_range); + writeF32(os, m_animation_speed); + writeF32(os, m_animation_blend); + // these are sent inverted so we get true when the server sends nothing + writeU8(os, !m_animation_loop); + return os.str(); +} + + +std::string UnitSAO::generateUpdateArmorGroupsCommand() const +{ + std::ostringstream os(std::ios::binary); + writeU8(os, AO_CMD_UPDATE_ARMOR_GROUPS); + writeU16(os, m_armor_groups.size()); + for (const auto &armor_group : m_armor_groups) { + os< +Copyright (C) 2013-2020 Minetest core developers & community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "object_properties.h" +#include "serveractiveobject.h" + +class UnitSAO: public ServerActiveObject +{ +public: + UnitSAO(ServerEnvironment *env, v3f pos); + virtual ~UnitSAO() = default; + + void setRotation(v3f rotation) { m_rotation = rotation; } + const v3f &getRotation() const { return m_rotation; } + v3f getRadRotation() { return m_rotation * core::DEGTORAD; } + + // Deprecated + f32 getRadYawDep() const { return (m_rotation.Y + 90.) * core::DEGTORAD; } + + u16 getHP() const { return m_hp; } + // Use a function, if isDead can be defined by other conditions + bool isDead() const { return m_hp == 0; } + + inline bool isAttached() const + { return getParent(); } + + inline bool isImmortal() const + { return itemgroup_get(getArmorGroups(), "immortal"); } + + void setArmorGroups(const ItemGroupList &armor_groups); + const ItemGroupList &getArmorGroups() const; + void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop); + void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop); + void setAnimationSpeed(float frame_speed); + void setBonePosition(const std::string &bone, v3f position, v3f rotation); + void getBonePosition(const std::string &bone, v3f *position, v3f *rotation); + void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation); + void getAttachment(int *parent_id, std::string *bone, v3f *position, + v3f *rotation) const; + void clearChildAttachments(); + void clearParentAttachment(); + void addAttachmentChild(int child_id); + void removeAttachmentChild(int child_id); + const std::unordered_set &getAttachmentChildIds() const; + ServerActiveObject *getParent() const; + ObjectProperties* accessObjectProperties(); + void notifyObjectPropertiesModified(); + + std::string generateUpdateAttachmentCommand() const; + std::string generateUpdateAnimationSpeedCommand() const; + std::string generateUpdateAnimationCommand() const; + std::string generateUpdateArmorGroupsCommand() const; + static std::string generateUpdatePositionCommand(const v3f &position, const v3f &velocity, + const v3f &acceleration, const v3f &rotation, bool do_interpolate, + bool is_movement_end, f32 update_interval); + std::string generateSetPropertiesCommand(const ObjectProperties &prop) const; + void sendPunchCommand(); + static std::string generateUpdateBonePositionCommand(const std::string &bone, + const v3f &position, const v3f &rotation); + +protected: + u16 m_hp = 1; + + v3f m_rotation; + + bool m_properties_sent = true; + ObjectProperties m_prop; + + ItemGroupList m_armor_groups; + bool m_armor_groups_sent = false; + + v2f m_animation_range; + float m_animation_speed = 0.0f; + float m_animation_blend = 0.0f; + bool m_animation_loop = true; + bool m_animation_sent = false; + bool m_animation_speed_sent = false; + + // Stores position and rotation for each bone name + std::unordered_map> m_bone_position; + bool m_bone_position_sent = false; + + int m_attachment_parent_id = 0; + std::unordered_set m_attachment_child_ids; + std::string m_attachment_bone = ""; + v3f m_attachment_position; + v3f m_attachment_rotation; + bool m_attachment_sent = false; +private: + void onAttach(int parent_id); + void onDetach(int parent_id); + + std::string generatePunchCommand(u16 result_hp) const; +}; diff --git a/src/serverobject.cpp b/src/serverobject.cpp deleted file mode 100644 index 119a41b7b..000000000 --- a/src/serverobject.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* -Minetest -Copyright (C) 2010-2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "serverobject.h" -#include -#include "inventory.h" -#include "constants.h" // BS -#include "log.h" - -ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos): - ActiveObject(0), - m_env(env), - m_base_position(pos) -{ -} - -ServerActiveObject* ServerActiveObject::create(ActiveObjectType type, - ServerEnvironment *env, u16 id, v3f pos, - const std::string &data) -{ - // Find factory function - std::map::iterator n; - n = m_types.find(type); - if(n == m_types.end()) { - // These are 0.3 entity types, return without error. - if (ACTIVEOBJECT_TYPE_ITEM <= type && type <= ACTIVEOBJECT_TYPE_MOBV2) { - return NULL; - } - - // If factory is not found, just return. - warningstream<<"ServerActiveObject: No factory for type=" - <second; - ServerActiveObject *object = (*f)(env, pos, data); - return object; -} - -void ServerActiveObject::registerType(u16 type, Factory f) -{ - std::map::iterator n; - n = m_types.find(type); - if(n != m_types.end()) - return; - m_types[type] = f; -} - -float ServerActiveObject::getMinimumSavedMovement() -{ - return 2.0*BS; -} - -ItemStack ServerActiveObject::getWieldedItem(ItemStack *selected, ItemStack *hand) const -{ - *selected = ItemStack(); - if (hand) - *hand = ItemStack(); - - return ItemStack(); -} - -bool ServerActiveObject::setWieldedItem(const ItemStack &item) -{ - return false; -} - -std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 protocol_version) -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SPAWN_INFANT); - // parameters - writeU16(os, infant_id); - writeU8(os, getSendType()); - os << serializeLongString(getClientInitializationData(protocol_version)); - return os.str(); -} - -std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const video::SColor &color) const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_UPDATE_NAMETAG_ATTRIBUTES); - // parameters - writeU8(os, 1); // version for forward compatibility - writeARGB8(os, color); - return os.str(); -} - -void ServerActiveObject::dumpAOMessagesToQueue(std::queue &queue) -{ - while (!m_messages_out.empty()) { - queue.push(m_messages_out.front()); - m_messages_out.pop(); - } -} \ No newline at end of file diff --git a/src/serverobject.h b/src/serverobject.h deleted file mode 100644 index 2e013a6b6..000000000 --- a/src/serverobject.h +++ /dev/null @@ -1,265 +0,0 @@ -/* -Minetest -Copyright (C) 2010-2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#pragma once - -#include -#include "irrlichttypes_bloated.h" -#include "activeobject.h" -#include "inventorymanager.h" -#include "itemgroup.h" -#include "util/container.h" - -/* - -Some planning -------------- - -* Server environment adds an active object, which gets the id 1 -* The active object list is scanned for each client once in a while, - and it finds out what objects have been added that are not known - by the client yet. This scan is initiated by the Server class and - the result ends up directly to the server. -* A network packet is created with the info and sent to the client. -* Environment converts objects to static data and static data to - objects, based on how close players are to them. - -*/ - -class ServerEnvironment; -struct ItemStack; -struct ToolCapabilities; -struct ObjectProperties; -struct PlayerHPChangeReason; - -class ServerActiveObject : public ActiveObject -{ -public: - /* - NOTE: m_env can be NULL, but step() isn't called if it is. - Prototypes are used that way. - */ - ServerActiveObject(ServerEnvironment *env, v3f pos); - virtual ~ServerActiveObject() = default; - - virtual ActiveObjectType getSendType() const - { return getType(); } - - // Called after id has been set and has been inserted in environment - virtual void addedToEnvironment(u32 dtime_s){}; - // Called before removing from environment - virtual void removingFromEnvironment(){}; - // Returns true if object's deletion is the job of the - // environment - virtual bool environmentDeletes() const - { return true; } - - // Create a certain type of ServerActiveObject - static ServerActiveObject* create(ActiveObjectType type, - ServerEnvironment *env, u16 id, v3f pos, - const std::string &data); - - /* - Some simple getters/setters - */ - v3f getBasePosition() const { return m_base_position; } - void setBasePosition(v3f pos){ m_base_position = pos; } - ServerEnvironment* getEnv(){ return m_env; } - - /* - Some more dynamic interface - */ - - virtual void setPos(const v3f &pos) - { setBasePosition(pos); } - // continuous: if true, object does not stop immediately at pos - virtual void moveTo(v3f pos, bool continuous) - { setBasePosition(pos); } - // If object has moved less than this and data has not changed, - // saving to disk may be omitted - virtual float getMinimumSavedMovement(); - - virtual std::string getDescription(){return "SAO";} - - /* - Step object in time. - Messages added to messages are sent to client over network. - - send_recommended: - True at around 5-10 times a second, same for all objects. - This is used to let objects send most of the data at the - same time so that the data can be combined in a single - packet. - */ - virtual void step(float dtime, bool send_recommended){} - - /* - The return value of this is passed to the client-side object - when it is created - */ - virtual std::string getClientInitializationData(u16 protocol_version) {return "";} - - /* - The return value of this is passed to the server-side object - when it is created (converted from static to active - actually - the data is the static form) - */ - virtual void getStaticData(std::string *result) const - { - assert(isStaticAllowed()); - *result = ""; - } - /* - Return false in here to never save and instead remove object - on unload. getStaticData() will not be called in that case. - */ - virtual bool isStaticAllowed() const - {return true;} - - // Returns tool wear - virtual u16 punch(v3f dir, - const ToolCapabilities *toolcap = nullptr, - ServerActiveObject *puncher = nullptr, - float time_from_last_punch = 1000000.0f) - { return 0; } - virtual void rightClick(ServerActiveObject *clicker) - {} - virtual void setHP(s32 hp, const PlayerHPChangeReason &reason) - {} - virtual u16 getHP() const - { return 0; } - - virtual void setArmorGroups(const ItemGroupList &armor_groups) - {} - virtual const ItemGroupList &getArmorGroups() const - { static ItemGroupList rv; return rv; } - virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity) - {} - virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop) - {} - virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop) - {} - virtual void setAnimationSpeed(float frame_speed) - {} - virtual void setBonePosition(const std::string &bone, v3f position, v3f rotation) - {} - virtual void getBonePosition(const std::string &bone, v3f *position, v3f *lotation) - {} - virtual const std::unordered_set &getAttachmentChildIds() const - { static std::unordered_set rv; return rv; } - virtual ServerActiveObject *getParent() const { return nullptr; } - virtual ObjectProperties* accessObjectProperties() - { return NULL; } - virtual void notifyObjectPropertiesModified() - {} - - // Inventory and wielded item - virtual Inventory *getInventory() const - { return NULL; } - virtual InventoryLocation getInventoryLocation() const - { return InventoryLocation(); } - virtual void setInventoryModified() - {} - virtual std::string getWieldList() const - { return ""; } - virtual u16 getWieldIndex() const - { return 0; } - virtual ItemStack getWieldedItem(ItemStack *selected, - ItemStack *hand = nullptr) const; - virtual bool setWieldedItem(const ItemStack &item); - inline void attachParticleSpawner(u32 id) - { - m_attached_particle_spawners.insert(id); - } - inline void detachParticleSpawner(u32 id) - { - m_attached_particle_spawners.erase(id); - } - - std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version); - std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const; - - void dumpAOMessagesToQueue(std::queue &queue); - - /* - Number of players which know about this object. Object won't be - deleted until this is 0 to keep the id preserved for the right - object. - */ - u16 m_known_by_count = 0; - - /* - - Whether this object is to be removed when nobody knows about - it anymore. - - Removal is delayed to preserve the id for the time during which - it could be confused to some other object by some client. - - This is usually set to true by the step() method when the object wants - to be deleted but can be set by anything else too. - */ - bool m_pending_removal = false; - - /* - Same purpose as m_pending_removal but for deactivation. - deactvation = save static data in block, remove active object - - If this is set alongside with m_pending_removal, removal takes - priority. - */ - bool m_pending_deactivation = false; - - /* - A getter that unifies the above to answer the question: - "Can the environment still interact with this object?" - */ - inline bool isGone() const - { return m_pending_removal || m_pending_deactivation; } - - /* - Whether the object's static data has been stored to a block - */ - bool m_static_exists = false; - /* - The block from which the object was loaded from, and in which - a copy of the static data resides. - */ - v3s16 m_static_block = v3s16(1337,1337,1337); - -protected: - virtual void onAttach(int parent_id) {} - virtual void onDetach(int parent_id) {} - - // Used for creating objects based on type - typedef ServerActiveObject* (*Factory) - (ServerEnvironment *env, v3f pos, - const std::string &data); - static void registerType(u16 type, Factory f); - - ServerEnvironment *m_env; - v3f m_base_position; - std::unordered_set m_attached_particle_spawners; - - /* - Queue of messages to be sent to the client - */ - std::queue m_messages_out; - -private: - // Used for creating objects based on type - static std::map m_types; -}; diff --git a/util/travis/clang-format-whitelist.txt b/util/travis/clang-format-whitelist.txt index 7b2fd8236..816ec2c59 100644 --- a/util/travis/clang-format-whitelist.txt +++ b/util/travis/clang-format-whitelist.txt @@ -402,16 +402,14 @@ src/script/scripting_server.cpp src/script/scripting_server.h src/serialization.cpp src/serialization.h -src/serveractiveobjectmap.cpp -src/serveractiveobjectmap.h src/server.cpp src/serverenvironment.cpp src/serverenvironment.h src/server.h src/serverlist.cpp src/serverlist.h -src/serverobject.cpp -src/serverobject.h +src/server/serveractiveobject.cpp +src/server/serveractiveobject.h src/settings.cpp src/settings.h src/settings_translation_file.cpp -- cgit v1.2.3 From c99e8df07fe88c0b19363beca09e12f151bc13d0 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 11 Apr 2020 09:35:27 +0200 Subject: pass clang-format --- src/server/unit_sao.cpp | 44 +++++++++++++++++++++----------------------- src/server/unit_sao.h | 29 +++++++++++++++++------------ 2 files changed, 38 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index 66be67522..b30b7a76b 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., UnitSAO */ -UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos): - ServerActiveObject(env, pos) +UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos) : ServerActiveObject(env, pos) { // Initialize something to armor groups m_armor_groups["fleshy"] = 100; @@ -54,7 +53,8 @@ const ItemGroupList &UnitSAO::getArmorGroups() const return m_armor_groups; } -void UnitSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop) +void UnitSAO::setAnimation( + v2f frame_range, float frame_speed, float frame_blend, bool frame_loop) { // store these so they can be updated to clients m_animation_range = frame_range; @@ -64,7 +64,8 @@ void UnitSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend m_animation_sent = false; } -void UnitSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop) +void UnitSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, + bool *frame_loop) { *frame_range = m_animation_range; *frame_speed = m_animation_speed; @@ -91,14 +92,15 @@ void UnitSAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotat *rotation = m_bone_position[bone].Y; } -void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation) +void UnitSAO::setAttachment( + int parent_id, const std::string &bone, v3f position, v3f rotation) { // Attachments need to be handled on both the server and client. - // If we just attach on the server, we can only copy the position of the parent. Attachments - // are still sent to clients at an interval so players might see them lagging, plus we can't - // read and attach to skeletal bones. - // If we just attach on the client, the server still sees the child at its original location. - // This breaks some things so we also give the server the most accurate representation + // If we just attach on the server, we can only copy the position of the parent. + // Attachments are still sent to clients at an interval so players might see them + // lagging, plus we can't read and attach to skeletal bones. If we just attach on + // the client, the server still sees the child at its original location. This + // breaks some things so we also give the server the most accurate representation // even if players only see the client changes. int old_parent = m_attachment_parent_id; @@ -114,8 +116,8 @@ void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position } } -void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position, - v3f *rotation) const +void UnitSAO::getAttachment( + int *parent_id, std::string *bone, v3f *position, v3f *rotation) const { *parent_id = m_attachment_parent_id; *bone = m_attachment_bone; @@ -194,7 +196,7 @@ void UnitSAO::onDetach(int parent_id) m_env->getScriptIface()->luaentity_on_detach_child(parent_id, this); } -ObjectProperties* UnitSAO::accessObjectProperties() +ObjectProperties *UnitSAO::accessObjectProperties() { return &m_prop; } @@ -217,8 +219,8 @@ std::string UnitSAO::generateUpdateAttachmentCommand() const return os.str(); } -std::string UnitSAO::generateUpdateBonePositionCommand(const std::string &bone, - const v3f &position, const v3f &rotation) +std::string UnitSAO::generateUpdateBonePositionCommand( + const std::string &bone, const v3f &position, const v3f &rotation) { std::ostringstream os(std::ios::binary); // command @@ -230,7 +232,6 @@ std::string UnitSAO::generateUpdateBonePositionCommand(const std::string &bone, return os.str(); } - std::string UnitSAO::generateUpdateAnimationSpeedCommand() const { std::ostringstream os(std::ios::binary); @@ -255,23 +256,21 @@ std::string UnitSAO::generateUpdateAnimationCommand() const return os.str(); } - std::string UnitSAO::generateUpdateArmorGroupsCommand() const { std::ostringstream os(std::ios::binary); writeU8(os, AO_CMD_UPDATE_ARMOR_GROUPS); writeU16(os, m_armor_groups.size()); for (const auto &armor_group : m_armor_groups) { - os< &getAttachmentChildIds() const; ServerActiveObject *getParent() const; - ObjectProperties* accessObjectProperties(); + ObjectProperties *accessObjectProperties(); void notifyObjectPropertiesModified(); std::string generateUpdateAttachmentCommand() const; std::string generateUpdateAnimationSpeedCommand() const; std::string generateUpdateAnimationCommand() const; std::string generateUpdateArmorGroupsCommand() const; - static std::string generateUpdatePositionCommand(const v3f &position, const v3f &velocity, - const v3f &acceleration, const v3f &rotation, bool do_interpolate, - bool is_movement_end, f32 update_interval); + static std::string generateUpdatePositionCommand(const v3f &position, + const v3f &velocity, const v3f &acceleration, const v3f &rotation, + bool do_interpolate, bool is_movement_end, f32 update_interval); std::string generateSetPropertiesCommand(const ObjectProperties &prop) const; void sendPunchCommand(); static std::string generateUpdateBonePositionCommand(const std::string &bone, - const v3f &position, const v3f &rotation); + const v3f &position, const v3f &rotation); protected: u16 m_hp = 1; @@ -105,6 +109,7 @@ protected: v3f m_attachment_position; v3f m_attachment_rotation; bool m_attachment_sent = false; + private: void onAttach(int parent_id); void onDetach(int parent_id); -- cgit v1.2.3 From 894a34aef48024a752a1ef151d046955d83858d0 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 11 Apr 2020 09:59:09 +0200 Subject: Move PlayerSAO to dedicated files --- src/clientiface.cpp | 3 +- src/content_sao.cpp | 676 +--------------------------------- src/content_sao.h | 299 --------------- src/database/database-files.cpp | 2 +- src/database/database-postgresql.cpp | 2 +- src/database/database-sqlite3.cpp | 2 +- src/network/serverpackethandler.cpp | 2 +- src/remoteplayer.cpp | 2 +- src/script/common/c_content.cpp | 3 +- src/script/cpp_api/s_base.cpp | 2 +- src/script/cpp_api/s_player.h | 1 + src/script/lua_api/l_env.cpp | 3 +- src/script/lua_api/l_object.cpp | 2 +- src/server.cpp | 2 +- src/server/CMakeLists.txt | 1 + src/server/player_sao.cpp | 695 +++++++++++++++++++++++++++++++++++ src/server/player_sao.h | 325 ++++++++++++++++ src/server/unit_sao.cpp | 4 - src/serverenvironment.cpp | 4 +- 19 files changed, 1038 insertions(+), 992 deletions(-) create mode 100644 src/server/player_sao.cpp create mode 100644 src/server/player_sao.h (limited to 'src') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index dceaa64f2..17237f73e 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "clientiface.h" +#include "content_sao.h" #include "network/connection.h" #include "network/serveropcodes.h" #include "remoteplayer.h" @@ -27,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverenvironment.h" #include "map.h" #include "emerge.h" -#include "content_sao.h" // TODO this is used for cleanup of only +#include "server/player_sao.h" #include "log.h" #include "util/srp.h" #include "face_position_cache.h" diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 0d387b53a..7ec17aa82 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "remoteplayer.h" #include "server.h" #include "scripting_server.h" +#include "server/player_sao.h" #include "settings.h" #include #include @@ -678,678 +679,3 @@ bool LuaEntitySAO::collideWithObjects() const { return m_prop.collideWithObjects; } - -/* - PlayerSAO -*/ - -// No prototype, PlayerSAO does not need to be deserialized - -PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, - bool is_singleplayer): - UnitSAO(env_, v3f(0,0,0)), - m_player(player_), - m_peer_id(peer_id_), - m_is_singleplayer(is_singleplayer) -{ - SANITY_CHECK(m_peer_id != PEER_ID_INEXISTENT); - - m_prop.hp_max = PLAYER_MAX_HP_DEFAULT; - m_prop.breath_max = PLAYER_MAX_BREATH_DEFAULT; - m_prop.physical = false; - m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f); - m_prop.selectionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f); - m_prop.pointable = true; - // Start of default appearance, this should be overwritten by Lua - m_prop.visual = "upright_sprite"; - m_prop.visual_size = v3f(1, 2, 1); - m_prop.textures.clear(); - m_prop.textures.emplace_back("player.png"); - m_prop.textures.emplace_back("player_back.png"); - m_prop.colors.clear(); - m_prop.colors.emplace_back(255, 255, 255, 255); - m_prop.spritediv = v2s16(1,1); - m_prop.eye_height = 1.625f; - // End of default appearance - m_prop.is_visible = true; - m_prop.backface_culling = false; - m_prop.makes_footstep_sound = true; - m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS; - m_hp = m_prop.hp_max; - m_breath = m_prop.breath_max; - // Disable zoom in survival mode using a value of 0 - m_prop.zoom_fov = g_settings->getBool("creative_mode") ? 15.0f : 0.0f; - - if (!g_settings->getBool("enable_damage")) - m_armor_groups["immortal"] = 1; -} - -void PlayerSAO::finalize(RemotePlayer *player, const std::set &privs) -{ - assert(player); - m_player = player; - m_privs = privs; -} - -v3f PlayerSAO::getEyeOffset() const -{ - return v3f(0, BS * m_prop.eye_height, 0); -} - -std::string PlayerSAO::getDescription() -{ - return std::string("player ") + m_player->getName(); -} - -// Called after id has been set and has been inserted in environment -void PlayerSAO::addedToEnvironment(u32 dtime_s) -{ - ServerActiveObject::addedToEnvironment(dtime_s); - ServerActiveObject::setBasePosition(m_base_position); - m_player->setPlayerSAO(this); - m_player->setPeerId(m_peer_id); - m_last_good_position = m_base_position; -} - -// Called before removing from environment -void PlayerSAO::removingFromEnvironment() -{ - ServerActiveObject::removingFromEnvironment(); - if (m_player->getPlayerSAO() == this) { - unlinkPlayerSessionAndSave(); - for (u32 attached_particle_spawner : m_attached_particle_spawners) { - m_env->deleteParticleSpawner(attached_particle_spawner, false); - } - } -} - -std::string PlayerSAO::getClientInitializationData(u16 protocol_version) -{ - std::ostringstream os(std::ios::binary); - - // Protocol >= 15 - writeU8(os, 1); // version - os << serializeString(m_player->getName()); // name - writeU8(os, 1); // is_player - writeS16(os, getId()); // id - writeV3F32(os, m_base_position); - writeV3F32(os, m_rotation); - writeU16(os, getHP()); - - std::ostringstream msg_os(std::ios::binary); - msg_os << serializeLongString(getPropertyPacket()); // message 1 - msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 - msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y)); // m_bone_position.size - } - msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 - msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5 - // (AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only. - msg_os << serializeLongString(generateUpdateNametagAttributesCommand(m_prop.nametag_color)); // 6 - int message_count = 6 + m_bone_position.size(); - for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); - ii != m_attachment_child_ids.end(); ++ii) { - if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { - message_count++; - msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); - } - } - - writeU8(os, message_count); - os.write(msg_os.str().c_str(), msg_os.str().size()); - - // return result - return os.str(); -} - -void PlayerSAO::getStaticData(std::string * result) const -{ - FATAL_ERROR("Obsolete function"); -} - -void PlayerSAO::step(float dtime, bool send_recommended) -{ - if (!isImmortal() && m_drowning_interval.step(dtime, 2.0f)) { - // Get nose/mouth position, approximate with eye position - v3s16 p = floatToInt(getEyePosition(), BS); - MapNode n = m_env->getMap().getNode(p); - const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); - // If node generates drown - if (c.drowning > 0 && m_hp > 0) { - if (m_breath > 0) - setBreath(m_breath - 1); - - // No more breath, damage player - if (m_breath == 0) { - PlayerHPChangeReason reason(PlayerHPChangeReason::DROWNING); - setHP(m_hp - c.drowning, reason); - m_env->getGameDef()->SendPlayerHPOrDie(this, reason); - } - } - } - - if (m_breathing_interval.step(dtime, 0.5f) && !isImmortal()) { - // Get nose/mouth position, approximate with eye position - v3s16 p = floatToInt(getEyePosition(), BS); - MapNode n = m_env->getMap().getNode(p); - const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); - // If player is alive & not drowning & not in ignore & not immortal, breathe - if (m_breath < m_prop.breath_max && c.drowning == 0 && - n.getContent() != CONTENT_IGNORE && m_hp > 0) - setBreath(m_breath + 1); - } - - if (!isImmortal() && m_node_hurt_interval.step(dtime, 1.0f)) { - u32 damage_per_second = 0; - std::string nodename; - // Lowest and highest damage points are 0.1 within collisionbox - float dam_top = m_prop.collisionbox.MaxEdge.Y - 0.1f; - - // Sequence of damage points, starting 0.1 above feet and progressing - // upwards in 1 node intervals, stopping below top damage point. - for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) { - v3s16 p = floatToInt(m_base_position + - v3f(0.0f, dam_height * BS, 0.0f), BS); - MapNode n = m_env->getMap().getNode(p); - const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); - if (c.damage_per_second > damage_per_second) { - damage_per_second = c.damage_per_second; - nodename = c.name; - } - } - - // Top damage point - v3s16 ptop = floatToInt(m_base_position + - v3f(0.0f, dam_top * BS, 0.0f), BS); - MapNode ntop = m_env->getMap().getNode(ptop); - const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop); - if (c.damage_per_second > damage_per_second) { - damage_per_second = c.damage_per_second; - nodename = c.name; - } - - if (damage_per_second != 0 && m_hp > 0) { - s32 newhp = (s32)m_hp - (s32)damage_per_second; - PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE, nodename); - setHP(newhp, reason); - m_env->getGameDef()->SendPlayerHPOrDie(this, reason); - } - } - - if (!m_properties_sent) { - m_properties_sent = true; - std::string str = getPropertyPacket(); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - m_env->getScriptIface()->player_event(this, "properties_changed"); - } - - // If attached, check that our parent is still there. If it isn't, detach. - if (m_attachment_parent_id && !isAttached()) { - m_attachment_parent_id = 0; - m_attachment_bone = ""; - m_attachment_position = v3f(0.0f, 0.0f, 0.0f); - m_attachment_rotation = v3f(0.0f, 0.0f, 0.0f); - setBasePosition(m_last_good_position); - m_env->getGameDef()->SendMovePlayer(m_peer_id); - } - - //dstream<<"PlayerSAO::step: dtime: "<getMaxLagEstimate() * 2.0f; - if(lag_pool_max < LAG_POOL_MIN) - lag_pool_max = LAG_POOL_MIN; - m_dig_pool.setMax(lag_pool_max); - m_move_pool.setMax(lag_pool_max); - - // Increment cheat prevention timers - m_dig_pool.add(dtime); - m_move_pool.add(dtime); - m_time_from_last_teleport += dtime; - m_time_from_last_punch += dtime; - m_nocheat_dig_time += dtime; - m_max_speed_override_time = MYMAX(m_max_speed_override_time - dtime, 0.0f); - - // Each frame, parent position is copied if the object is attached, - // otherwise it's calculated normally. - // If the object gets detached this comes into effect automatically from - // the last known origin. - if (isAttached()) { - v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); - m_last_good_position = pos; - setBasePosition(pos); - } - - if (!send_recommended) - return; - - if (m_position_not_sent) { - m_position_not_sent = false; - float update_interval = m_env->getSendRecommendedInterval(); - v3f pos; - // When attached, the position is only sent to clients where the - // parent isn't known - if (isAttached()) - pos = m_last_good_position; - else - pos = m_base_position; - - std::string str = generateUpdatePositionCommand( - pos, - v3f(0.0f, 0.0f, 0.0f), - v3f(0.0f, 0.0f, 0.0f), - m_rotation, - true, - false, - update_interval - ); - // create message and add to list - m_messages_out.emplace(getId(), false, str); - } - - if (!m_armor_groups_sent) { - m_armor_groups_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); - } - - if (!m_physics_override_sent) { - m_physics_override_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand()); - } - - if (!m_animation_sent) { - m_animation_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand()); - } - - if (!m_bone_position_sent) { - m_bone_position_sent = true; - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - std::string str = generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } - } - - if (!m_attachment_sent) { - m_attachment_sent = true; - std::string str = generateUpdateAttachmentCommand(); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - } -} - -std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SET_PHYSICS_OVERRIDE); - // parameters - writeF32(os, m_physics_override_speed); - writeF32(os, m_physics_override_jump); - writeF32(os, m_physics_override_gravity); - // these are sent inverted so we get true when the server sends nothing - writeU8(os, !m_physics_override_sneak); - writeU8(os, !m_physics_override_sneak_glitch); - writeU8(os, !m_physics_override_new_move); - return os.str(); -} - -void PlayerSAO::setBasePosition(const v3f &position) -{ - if (m_player && position != m_base_position) - m_player->setDirty(true); - - // This needs to be ran for attachments too - ServerActiveObject::setBasePosition(position); - - // Updating is not wanted/required for player migration - if (m_env) { - m_position_not_sent = true; - } -} - -void PlayerSAO::setPos(const v3f &pos) -{ - if(isAttached()) - return; - - // Send mapblock of target location - v3s16 blockpos = v3s16(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); - m_env->getGameDef()->SendBlock(m_peer_id, blockpos); - - setBasePosition(pos); - // Movement caused by this command is always valid - m_last_good_position = pos; - m_move_pool.empty(); - m_time_from_last_teleport = 0.0; - m_env->getGameDef()->SendMovePlayer(m_peer_id); -} - -void PlayerSAO::moveTo(v3f pos, bool continuous) -{ - if(isAttached()) - return; - - setBasePosition(pos); - // Movement caused by this command is always valid - m_last_good_position = pos; - m_move_pool.empty(); - m_time_from_last_teleport = 0.0; - m_env->getGameDef()->SendMovePlayer(m_peer_id); -} - -void PlayerSAO::setPlayerYaw(const float yaw) -{ - v3f rotation(0, yaw, 0); - if (m_player && yaw != m_rotation.Y) - m_player->setDirty(true); - - // Set player model yaw, not look view - UnitSAO::setRotation(rotation); -} - -void PlayerSAO::setFov(const float fov) -{ - if (m_player && fov != m_fov) - m_player->setDirty(true); - - m_fov = fov; -} - -void PlayerSAO::setWantedRange(const s16 range) -{ - if (m_player && range != m_wanted_range) - m_player->setDirty(true); - - m_wanted_range = range; -} - -void PlayerSAO::setPlayerYawAndSend(const float yaw) -{ - setPlayerYaw(yaw); - m_env->getGameDef()->SendMovePlayer(m_peer_id); -} - -void PlayerSAO::setLookPitch(const float pitch) -{ - if (m_player && pitch != m_pitch) - m_player->setDirty(true); - - m_pitch = pitch; -} - -void PlayerSAO::setLookPitchAndSend(const float pitch) -{ - setLookPitch(pitch); - m_env->getGameDef()->SendMovePlayer(m_peer_id); -} - -u16 PlayerSAO::punch(v3f dir, - const ToolCapabilities *toolcap, - ServerActiveObject *puncher, - float time_from_last_punch) -{ - if (!toolcap) - return 0; - - FATAL_ERROR_IF(!puncher, "Punch action called without SAO"); - - // No effect if PvP disabled or if immortal - if (isImmortal() || !g_settings->getBool("enable_pvp")) { - if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { - // create message and add to list - sendPunchCommand(); - return 0; - } - } - - s32 old_hp = getHP(); - HitParams hitparams = getHitParams(m_armor_groups, toolcap, - time_from_last_punch); - - PlayerSAO *playersao = m_player->getPlayerSAO(); - - bool damage_handled = m_env->getScriptIface()->on_punchplayer(playersao, - puncher, time_from_last_punch, toolcap, dir, - hitparams.hp); - - if (!damage_handled) { - setHP((s32)getHP() - (s32)hitparams.hp, - PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); - } else { // override client prediction - if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { - // create message and add to list - sendPunchCommand(); - } - } - - actionstream << puncher->getDescription() << " (id=" << puncher->getId() << - ", hp=" << puncher->getHP() << ") punched " << - getDescription() << " (id=" << m_id << ", hp=" << m_hp << - "), damage=" << (old_hp - (s32)getHP()) << - (damage_handled ? " (handled by Lua)" : "") << std::endl; - - return hitparams.wear; -} - -void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason) -{ - s32 oldhp = m_hp; - - hp = rangelim(hp, 0, m_prop.hp_max); - - if (oldhp != hp) { - s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason); - if (hp_change == 0) - return; - - hp = rangelim(oldhp + hp_change, 0, m_prop.hp_max); - } - - if (hp < oldhp && isImmortal()) - return; - - m_hp = hp; - - // Update properties on death - if ((hp == 0) != (oldhp == 0)) - m_properties_sent = false; -} - -void PlayerSAO::setBreath(const u16 breath, bool send) -{ - if (m_player && breath != m_breath) - m_player->setDirty(true); - - m_breath = rangelim(breath, 0, m_prop.breath_max); - - if (send) - m_env->getGameDef()->SendPlayerBreath(this); -} - -Inventory *PlayerSAO::getInventory() const -{ - return m_player ? &m_player->inventory : nullptr; -} - -InventoryLocation PlayerSAO::getInventoryLocation() const -{ - InventoryLocation loc; - loc.setPlayer(m_player->getName()); - return loc; -} - -u16 PlayerSAO::getWieldIndex() const -{ - return m_player->getWieldIndex(); -} - -ItemStack PlayerSAO::getWieldedItem(ItemStack *selected, ItemStack *hand) const -{ - return m_player->getWieldedItem(selected, hand); -} - -bool PlayerSAO::setWieldedItem(const ItemStack &item) -{ - InventoryList *mlist = m_player->inventory.getList(getWieldList()); - if (mlist) { - mlist->changeItem(m_player->getWieldIndex(), item); - return true; - } - return false; -} - -void PlayerSAO::disconnected() -{ - m_peer_id = PEER_ID_INEXISTENT; - m_pending_removal = true; -} - -void PlayerSAO::unlinkPlayerSessionAndSave() -{ - assert(m_player->getPlayerSAO() == this); - m_player->setPeerId(PEER_ID_INEXISTENT); - m_env->savePlayer(m_player); - m_player->setPlayerSAO(NULL); - m_env->removePlayer(m_player); -} - -std::string PlayerSAO::getPropertyPacket() -{ - m_prop.is_visible = (true); - return generateSetPropertiesCommand(m_prop); -} - -void PlayerSAO::setMaxSpeedOverride(const v3f &vel) -{ - if (m_max_speed_override_time == 0.0f) - m_max_speed_override = vel; - else - m_max_speed_override += vel; - if (m_player) { - float accel = MYMIN(m_player->movement_acceleration_default, - m_player->movement_acceleration_air); - m_max_speed_override_time = m_max_speed_override.getLength() / accel / BS; - } -} - -bool PlayerSAO::checkMovementCheat() -{ - if (isAttached() || m_is_singleplayer || - g_settings->getBool("disable_anticheat")) { - m_last_good_position = m_base_position; - return false; - } - - bool cheated = false; - /* - Check player movements - - NOTE: Actually the server should handle player physics like the - client does and compare player's position to what is calculated - on our side. This is required when eg. players fly due to an - explosion. Altough a node-based alternative might be possible - too, and much more lightweight. - */ - - float override_max_H, override_max_V; - if (m_max_speed_override_time > 0.0f) { - override_max_H = MYMAX(fabs(m_max_speed_override.X), fabs(m_max_speed_override.Z)); - override_max_V = fabs(m_max_speed_override.Y); - } else { - override_max_H = override_max_V = 0.0f; - } - - float player_max_walk = 0; // horizontal movement - float player_max_jump = 0; // vertical upwards movement - - if (m_privs.count("fast") != 0) - player_max_walk = m_player->movement_speed_fast; // Fast speed - else - player_max_walk = m_player->movement_speed_walk; // Normal speed - player_max_walk *= m_physics_override_speed; - player_max_walk = MYMAX(player_max_walk, override_max_H); - - player_max_jump = m_player->movement_speed_jump * m_physics_override_jump; - // FIXME: Bouncy nodes cause practically unbound increase in Y speed, - // until this can be verified correctly, tolerate higher jumping speeds - player_max_jump *= 2.0; - player_max_jump = MYMAX(player_max_jump, override_max_V); - - // Don't divide by zero! - if (player_max_walk < 0.0001f) - player_max_walk = 0.0001f; - if (player_max_jump < 0.0001f) - player_max_jump = 0.0001f; - - v3f diff = (m_base_position - m_last_good_position); - float d_vert = diff.Y; - diff.Y = 0; - float d_horiz = diff.getLength(); - float required_time = d_horiz / player_max_walk; - - // FIXME: Checking downwards movement is not easily possible currently, - // the server could calculate speed differences to examine the gravity - if (d_vert > 0) { - // In certain cases (water, ladders) walking speed is applied vertically - float s = MYMAX(player_max_jump, player_max_walk); - required_time = MYMAX(required_time, d_vert / s); - } - - if (m_move_pool.grab(required_time)) { - m_last_good_position = m_base_position; - } else { - const float LAG_POOL_MIN = 5.0; - float lag_pool_max = m_env->getMaxLagEstimate() * 2.0; - lag_pool_max = MYMAX(lag_pool_max, LAG_POOL_MIN); - if (m_time_from_last_teleport > lag_pool_max) { - actionstream << "Player " << m_player->getName() - << " moved too fast; resetting position" - << std::endl; - cheated = true; - } - setBasePosition(m_last_good_position); - } - return cheated; -} - -bool PlayerSAO::getCollisionBox(aabb3f *toset) const -{ - //update collision box - toset->MinEdge = m_prop.collisionbox.MinEdge * BS; - toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; - - toset->MinEdge += m_base_position; - toset->MaxEdge += m_base_position; - return true; -} - -bool PlayerSAO::getSelectionBox(aabb3f *toset) const -{ - if (!m_prop.is_visible || !m_prop.pointable) { - return false; - } - - toset->MinEdge = m_prop.selectionbox.MinEdge * BS; - toset->MaxEdge = m_prop.selectionbox.MaxEdge * BS; - - return true; -} - -float PlayerSAO::getZoomFOV() const -{ - return m_prop.zoom_fov; -} diff --git a/src/content_sao.h b/src/content_sao.h index 32ab922d6..5387fd108 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -99,302 +99,3 @@ private: std::string m_current_texture_modifier = ""; }; -/* - PlayerSAO needs some internals exposed. -*/ - -class LagPool -{ - float m_pool = 15.0f; - float m_max = 15.0f; -public: - LagPool() = default; - - void setMax(float new_max) - { - m_max = new_max; - if(m_pool > new_max) - m_pool = new_max; - } - - void add(float dtime) - { - m_pool -= dtime; - if(m_pool < 0) - m_pool = 0; - } - - void empty() - { - m_pool = m_max; - } - - bool grab(float dtime) - { - if(dtime <= 0) - return true; - if(m_pool + dtime > m_max) - return false; - m_pool += dtime; - return true; - } -}; - -class RemotePlayer; - -class PlayerSAO : public UnitSAO -{ -public: - PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, - bool is_singleplayer); - - ActiveObjectType getType() const - { return ACTIVEOBJECT_TYPE_PLAYER; } - ActiveObjectType getSendType() const - { return ACTIVEOBJECT_TYPE_GENERIC; } - std::string getDescription(); - - /* - Active object <-> environment interface - */ - - void addedToEnvironment(u32 dtime_s); - void removingFromEnvironment(); - bool isStaticAllowed() const { return false; } - std::string getClientInitializationData(u16 protocol_version); - void getStaticData(std::string *result) const; - void step(float dtime, bool send_recommended); - void setBasePosition(const v3f &position); - void setPos(const v3f &pos); - void moveTo(v3f pos, bool continuous); - void setPlayerYaw(const float yaw); - // Data should not be sent at player initialization - void setPlayerYawAndSend(const float yaw); - void setLookPitch(const float pitch); - // Data should not be sent at player initialization - void setLookPitchAndSend(const float pitch); - f32 getLookPitch() const { return m_pitch; } - f32 getRadLookPitch() const { return m_pitch * core::DEGTORAD; } - // Deprecated - f32 getRadLookPitchDep() const { return -1.0 * m_pitch * core::DEGTORAD; } - void setFov(const float pitch); - f32 getFov() const { return m_fov; } - void setWantedRange(const s16 range); - s16 getWantedRange() const { return m_wanted_range; } - - /* - Interaction interface - */ - - u16 punch(v3f dir, - const ToolCapabilities *toolcap, - ServerActiveObject *puncher, - float time_from_last_punch); - void rightClick(ServerActiveObject *clicker) {} - void setHP(s32 hp, const PlayerHPChangeReason &reason); - void setHPRaw(u16 hp) { m_hp = hp; } - s16 readDamage(); - u16 getBreath() const { return m_breath; } - void setBreath(const u16 breath, bool send = true); - - /* - Inventory interface - */ - Inventory *getInventory() const; - InventoryLocation getInventoryLocation() const; - void setInventoryModified() {} - std::string getWieldList() const { return "main"; } - u16 getWieldIndex() const; - ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const; - bool setWieldedItem(const ItemStack &item); - - /* - PlayerSAO-specific - */ - - void disconnected(); - - RemotePlayer *getPlayer() { return m_player; } - session_t getPeerID() const { return m_peer_id; } - - // Cheat prevention - - v3f getLastGoodPosition() const - { - return m_last_good_position; - } - float resetTimeFromLastPunch() - { - float r = m_time_from_last_punch; - m_time_from_last_punch = 0.0; - return r; - } - void noCheatDigStart(const v3s16 &p) - { - m_nocheat_dig_pos = p; - m_nocheat_dig_time = 0; - } - v3s16 getNoCheatDigPos() - { - return m_nocheat_dig_pos; - } - float getNoCheatDigTime() - { - return m_nocheat_dig_time; - } - void noCheatDigEnd() - { - m_nocheat_dig_pos = v3s16(32767, 32767, 32767); - } - LagPool& getDigPool() - { - return m_dig_pool; - } - void setMaxSpeedOverride(const v3f &vel); - // Returns true if cheated - bool checkMovementCheat(); - - // Other - - void updatePrivileges(const std::set &privs, - bool is_singleplayer) - { - m_privs = privs; - m_is_singleplayer = is_singleplayer; - } - - bool getCollisionBox(aabb3f *toset) const; - bool getSelectionBox(aabb3f *toset) const; - bool collideWithObjects() const { return true; } - - void finalize(RemotePlayer *player, const std::set &privs); - - v3f getEyePosition() const { return m_base_position + getEyeOffset(); } - v3f getEyeOffset() const; - float getZoomFOV() const; - - inline Metadata &getMeta() { return m_meta; } - -private: - std::string getPropertyPacket(); - void unlinkPlayerSessionAndSave(); - std::string generateUpdatePhysicsOverrideCommand() const; - - RemotePlayer *m_player = nullptr; - session_t m_peer_id = 0; - - // Cheat prevention - LagPool m_dig_pool; - LagPool m_move_pool; - v3f m_last_good_position; - float m_time_from_last_teleport = 0.0f; - float m_time_from_last_punch = 0.0f; - v3s16 m_nocheat_dig_pos = v3s16(32767, 32767, 32767); - float m_nocheat_dig_time = 0.0f; - float m_max_speed_override_time = 0.0f; - v3f m_max_speed_override = v3f(0.0f, 0.0f, 0.0f); - - // Timers - IntervalLimiter m_breathing_interval; - IntervalLimiter m_drowning_interval; - IntervalLimiter m_node_hurt_interval; - - bool m_position_not_sent = false; - - // Cached privileges for enforcement - std::set m_privs; - bool m_is_singleplayer; - - u16 m_breath = PLAYER_MAX_BREATH_DEFAULT; - f32 m_pitch = 0.0f; - f32 m_fov = 0.0f; - s16 m_wanted_range = 0.0f; - - Metadata m_meta; -public: - float m_physics_override_speed = 1.0f; - float m_physics_override_jump = 1.0f; - float m_physics_override_gravity = 1.0f; - bool m_physics_override_sneak = true; - bool m_physics_override_sneak_glitch = false; - bool m_physics_override_new_move = true; - bool m_physics_override_sent = false; -}; - - -struct PlayerHPChangeReason { - enum Type : u8 { - SET_HP, - PLAYER_PUNCH, - FALL, - NODE_DAMAGE, - DROWNING, - RESPAWN - }; - - Type type = SET_HP; - bool from_mod = false; - int lua_reference = -1; - - // For PLAYER_PUNCH - ServerActiveObject *object = nullptr; - // For NODE_DAMAGE - std::string node; - - inline bool hasLuaReference() const - { - return lua_reference >= 0; - } - - bool setTypeFromString(const std::string &typestr) - { - if (typestr == "set_hp") - type = SET_HP; - else if (typestr == "punch") - type = PLAYER_PUNCH; - else if (typestr == "fall") - type = FALL; - else if (typestr == "node_damage") - type = NODE_DAMAGE; - else if (typestr == "drown") - type = DROWNING; - else if (typestr == "respawn") - type = RESPAWN; - else - return false; - - return true; - } - - std::string getTypeAsString() const - { - switch (type) { - case PlayerHPChangeReason::SET_HP: - return "set_hp"; - case PlayerHPChangeReason::PLAYER_PUNCH: - return "punch"; - case PlayerHPChangeReason::FALL: - return "fall"; - case PlayerHPChangeReason::NODE_DAMAGE: - return "node_damage"; - case PlayerHPChangeReason::DROWNING: - return "drown"; - case PlayerHPChangeReason::RESPAWN: - return "respawn"; - default: - return "?"; - } - } - - PlayerHPChangeReason(Type type): - type(type) - {} - - PlayerHPChangeReason(Type type, ServerActiveObject *object): - type(type), object(object) - {} - - PlayerHPChangeReason(Type type, std::string node): - type(type), node(node) - {} -}; diff --git a/src/database/database-files.cpp b/src/database/database-files.cpp index d09f1c074..d2b0b1543 100644 --- a/src/database/database-files.cpp +++ b/src/database/database-files.cpp @@ -20,11 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "database-files.h" -#include "content_sao.h" #include "remoteplayer.h" #include "settings.h" #include "porting.h" #include "filesys.h" +#include "server/player_sao.h" #include "util/string.h" // !!! WARNING !!! diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index d7c94ff15..77385e240 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -36,8 +36,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "debug.h" #include "exceptions.h" #include "settings.h" -#include "content_sao.h" #include "remoteplayer.h" +#include "server/player_sao.h" Database_PostgreSQL::Database_PostgreSQL(const std::string &connect_string) : m_connect_string(connect_string) diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 1bacdfe6c..4560743b9 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -33,8 +33,8 @@ SQLite format specification: #include "settings.h" #include "porting.h" #include "util/string.h" -#include "content_sao.h" #include "remoteplayer.h" +#include "server/player_sao.h" #include diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 23bcc867f..b2fdb2a22 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -20,7 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "chatmessage.h" #include "server.h" #include "log.h" -#include "content_sao.h" #include "emerge.h" #include "mapblock.h" #include "modchannels.h" @@ -34,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "network/connection.h" #include "network/networkprotocol.h" #include "network/serveropcodes.h" +#include "server/player_sao.h" #include "util/auth.h" #include "util/base64.h" #include "util/pointedthing.h" diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp index 1a8fec68c..7a603d53e 100644 --- a/src/remoteplayer.cpp +++ b/src/remoteplayer.cpp @@ -20,13 +20,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "remoteplayer.h" #include -#include "content_sao.h" #include "filesys.h" #include "gamedef.h" #include "porting.h" // strlcpy #include "server.h" #include "settings.h" #include "convert_json.h" +#include "server/player_sao.h" /* RemotePlayer diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 60f12052f..c8cd7539f 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_types.h" #include "nodedef.h" #include "object_properties.h" -#include "content_sao.h" #include "cpp_api/s_node.h" #include "lua_api/l_object.h" #include "lua_api/l_item.h" @@ -29,10 +28,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server.h" #include "log.h" #include "tool.h" -#include "server/serveractiveobject.h" #include "porting.h" #include "mapgen/mg_schematic.h" #include "noise.h" +#include "server/player_sao.h" #include "util/pointedthing.h" #include "debug.h" // For FATAL_ERROR #include diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 16c20eeae..150baf77e 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cpp_api/s_security.h" #include "lua_api/l_object.h" #include "common/c_converter.h" -#include "server/serveractiveobject.h" +#include "server/player_sao.h" #include "filesys.h" #include "content/mods.h" #include "porting.h" diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index cf24ddc73..7ca3d8f30 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -28,6 +28,7 @@ struct InventoryLocation; struct ItemStack; struct ToolCapabilities; struct PlayerHPChangeReason; +class ServerActiveObject; class ScriptApiPlayer : virtual public ScriptApiBase { diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 31e582d3d..438669feb 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include "lua_api/l_env.h" #include "lua_api/l_internal.h" #include "lua_api/l_nodemeta.h" @@ -25,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_vmanip.h" #include "common/c_converter.h" #include "common/c_content.h" -#include #include "scripting_server.h" #include "environment.h" #include "mapblock.h" @@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "pathfinder.h" #include "face_position_cache.h" #include "remoteplayer.h" +#include "server/player_sao.h" #ifndef SERVER #include "client/client.h" #endif diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 1ea144a1c..95c96235e 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -27,12 +27,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_content.h" #include "log.h" #include "tool.h" -#include "server/serveractiveobject.h" #include "content_sao.h" #include "remoteplayer.h" #include "server.h" #include "hud.h" #include "scripting_server.h" +#include "server/player_sao.h" /* ObjectRef diff --git a/src/server.cpp b/src/server.cpp index 529466f6b..85d07fbc4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -47,7 +47,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen/mg_biome.h" #include "content_mapnode.h" #include "content_nodemeta.h" -#include "content_sao.h" #include "content/mods.h" #include "modchannels.h" #include "serverlist.h" @@ -64,6 +63,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "chatmessage.h" #include "chat_interface.h" #include "remoteplayer.h" +#include "server/player_sao.h" class ClientNotFoundException : public BaseException { diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 9fa5ed9fa..26eaed5ac 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,6 +1,7 @@ set(server_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/activeobjectmgr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/player_sao.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp ${CMAKE_CURRENT_SOURCE_DIR}/unit_sao.cpp PARENT_SCOPE) diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp new file mode 100644 index 000000000..58fcea5fe --- /dev/null +++ b/src/server/player_sao.cpp @@ -0,0 +1,695 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2013-2020 Minetest core developers & community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "player_sao.h" +#include "nodedef.h" +#include "remoteplayer.h" +#include "scripting_server.h" +#include "server.h" +#include "serverenvironment.h" + +PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, + bool is_singleplayer): + UnitSAO(env_, v3f(0,0,0)), + m_player(player_), + m_peer_id(peer_id_), + m_is_singleplayer(is_singleplayer) +{ + SANITY_CHECK(m_peer_id != PEER_ID_INEXISTENT); + + m_prop.hp_max = PLAYER_MAX_HP_DEFAULT; + m_prop.breath_max = PLAYER_MAX_BREATH_DEFAULT; + m_prop.physical = false; + m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f); + m_prop.selectionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f); + m_prop.pointable = true; + // Start of default appearance, this should be overwritten by Lua + m_prop.visual = "upright_sprite"; + m_prop.visual_size = v3f(1, 2, 1); + m_prop.textures.clear(); + m_prop.textures.emplace_back("player.png"); + m_prop.textures.emplace_back("player_back.png"); + m_prop.colors.clear(); + m_prop.colors.emplace_back(255, 255, 255, 255); + m_prop.spritediv = v2s16(1,1); + m_prop.eye_height = 1.625f; + // End of default appearance + m_prop.is_visible = true; + m_prop.backface_culling = false; + m_prop.makes_footstep_sound = true; + m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS; + m_hp = m_prop.hp_max; + m_breath = m_prop.breath_max; + // Disable zoom in survival mode using a value of 0 + m_prop.zoom_fov = g_settings->getBool("creative_mode") ? 15.0f : 0.0f; + + if (!g_settings->getBool("enable_damage")) + m_armor_groups["immortal"] = 1; +} + +void PlayerSAO::finalize(RemotePlayer *player, const std::set &privs) +{ + assert(player); + m_player = player; + m_privs = privs; +} + +v3f PlayerSAO::getEyeOffset() const +{ + return v3f(0, BS * m_prop.eye_height, 0); +} + +std::string PlayerSAO::getDescription() +{ + return std::string("player ") + m_player->getName(); +} + +// Called after id has been set and has been inserted in environment +void PlayerSAO::addedToEnvironment(u32 dtime_s) +{ + ServerActiveObject::addedToEnvironment(dtime_s); + ServerActiveObject::setBasePosition(m_base_position); + m_player->setPlayerSAO(this); + m_player->setPeerId(m_peer_id); + m_last_good_position = m_base_position; +} + +// Called before removing from environment +void PlayerSAO::removingFromEnvironment() +{ + ServerActiveObject::removingFromEnvironment(); + if (m_player->getPlayerSAO() == this) { + unlinkPlayerSessionAndSave(); + for (u32 attached_particle_spawner : m_attached_particle_spawners) { + m_env->deleteParticleSpawner(attached_particle_spawner, false); + } + } +} + +std::string PlayerSAO::getClientInitializationData(u16 protocol_version) +{ + std::ostringstream os(std::ios::binary); + + // Protocol >= 15 + writeU8(os, 1); // version + os << serializeString(m_player->getName()); // name + writeU8(os, 1); // is_player + writeS16(os, getId()); // id + writeV3F32(os, m_base_position); + writeV3F32(os, m_rotation); + writeU16(os, getHP()); + + std::ostringstream msg_os(std::ios::binary); + msg_os << serializeLongString(getPropertyPacket()); // message 1 + msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 + msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 + for (std::unordered_map>::const_iterator + ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { + msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, + (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + } + msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 + msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5 + // (AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only. + msg_os << serializeLongString(generateUpdateNametagAttributesCommand(m_prop.nametag_color)); // 6 + int message_count = 6 + m_bone_position.size(); + for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); + ii != m_attachment_child_ids.end(); ++ii) { + if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { + message_count++; + msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); + } + } + + writeU8(os, message_count); + os.write(msg_os.str().c_str(), msg_os.str().size()); + + // return result + return os.str(); +} + +void PlayerSAO::getStaticData(std::string * result) const +{ + FATAL_ERROR("Obsolete function"); +} + +void PlayerSAO::step(float dtime, bool send_recommended) +{ + if (!isImmortal() && m_drowning_interval.step(dtime, 2.0f)) { + // Get nose/mouth position, approximate with eye position + v3s16 p = floatToInt(getEyePosition(), BS); + MapNode n = m_env->getMap().getNode(p); + const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); + // If node generates drown + if (c.drowning > 0 && m_hp > 0) { + if (m_breath > 0) + setBreath(m_breath - 1); + + // No more breath, damage player + if (m_breath == 0) { + PlayerHPChangeReason reason(PlayerHPChangeReason::DROWNING); + setHP(m_hp - c.drowning, reason); + m_env->getGameDef()->SendPlayerHPOrDie(this, reason); + } + } + } + + if (m_breathing_interval.step(dtime, 0.5f) && !isImmortal()) { + // Get nose/mouth position, approximate with eye position + v3s16 p = floatToInt(getEyePosition(), BS); + MapNode n = m_env->getMap().getNode(p); + const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); + // If player is alive & not drowning & not in ignore & not immortal, breathe + if (m_breath < m_prop.breath_max && c.drowning == 0 && + n.getContent() != CONTENT_IGNORE && m_hp > 0) + setBreath(m_breath + 1); + } + + if (!isImmortal() && m_node_hurt_interval.step(dtime, 1.0f)) { + u32 damage_per_second = 0; + std::string nodename; + // Lowest and highest damage points are 0.1 within collisionbox + float dam_top = m_prop.collisionbox.MaxEdge.Y - 0.1f; + + // Sequence of damage points, starting 0.1 above feet and progressing + // upwards in 1 node intervals, stopping below top damage point. + for (float dam_height = 0.1f; dam_height < dam_top; dam_height++) { + v3s16 p = floatToInt(m_base_position + + v3f(0.0f, dam_height * BS, 0.0f), BS); + MapNode n = m_env->getMap().getNode(p); + const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n); + if (c.damage_per_second > damage_per_second) { + damage_per_second = c.damage_per_second; + nodename = c.name; + } + } + + // Top damage point + v3s16 ptop = floatToInt(m_base_position + + v3f(0.0f, dam_top * BS, 0.0f), BS); + MapNode ntop = m_env->getMap().getNode(ptop); + const ContentFeatures &c = m_env->getGameDef()->ndef()->get(ntop); + if (c.damage_per_second > damage_per_second) { + damage_per_second = c.damage_per_second; + nodename = c.name; + } + + if (damage_per_second != 0 && m_hp > 0) { + s32 newhp = (s32)m_hp - (s32)damage_per_second; + PlayerHPChangeReason reason(PlayerHPChangeReason::NODE_DAMAGE, nodename); + setHP(newhp, reason); + m_env->getGameDef()->SendPlayerHPOrDie(this, reason); + } + } + + if (!m_properties_sent) { + m_properties_sent = true; + std::string str = getPropertyPacket(); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + m_env->getScriptIface()->player_event(this, "properties_changed"); + } + + // If attached, check that our parent is still there. If it isn't, detach. + if (m_attachment_parent_id && !isAttached()) { + m_attachment_parent_id = 0; + m_attachment_bone = ""; + m_attachment_position = v3f(0.0f, 0.0f, 0.0f); + m_attachment_rotation = v3f(0.0f, 0.0f, 0.0f); + setBasePosition(m_last_good_position); + m_env->getGameDef()->SendMovePlayer(m_peer_id); + } + + //dstream<<"PlayerSAO::step: dtime: "<getMaxLagEstimate() * 2.0f; + if(lag_pool_max < LAG_POOL_MIN) + lag_pool_max = LAG_POOL_MIN; + m_dig_pool.setMax(lag_pool_max); + m_move_pool.setMax(lag_pool_max); + + // Increment cheat prevention timers + m_dig_pool.add(dtime); + m_move_pool.add(dtime); + m_time_from_last_teleport += dtime; + m_time_from_last_punch += dtime; + m_nocheat_dig_time += dtime; + m_max_speed_override_time = MYMAX(m_max_speed_override_time - dtime, 0.0f); + + // Each frame, parent position is copied if the object is attached, + // otherwise it's calculated normally. + // If the object gets detached this comes into effect automatically from + // the last known origin. + if (isAttached()) { + v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); + m_last_good_position = pos; + setBasePosition(pos); + } + + if (!send_recommended) + return; + + if (m_position_not_sent) { + m_position_not_sent = false; + float update_interval = m_env->getSendRecommendedInterval(); + v3f pos; + // When attached, the position is only sent to clients where the + // parent isn't known + if (isAttached()) + pos = m_last_good_position; + else + pos = m_base_position; + + std::string str = generateUpdatePositionCommand( + pos, + v3f(0.0f, 0.0f, 0.0f), + v3f(0.0f, 0.0f, 0.0f), + m_rotation, + true, + false, + update_interval + ); + // create message and add to list + m_messages_out.emplace(getId(), false, str); + } + + if (!m_armor_groups_sent) { + m_armor_groups_sent = true; + // create message and add to list + m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); + } + + if (!m_physics_override_sent) { + m_physics_override_sent = true; + // create message and add to list + m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand()); + } + + if (!m_animation_sent) { + m_animation_sent = true; + // create message and add to list + m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand()); + } + + if (!m_bone_position_sent) { + m_bone_position_sent = true; + for (std::unordered_map>::const_iterator + ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { + std::string str = generateUpdateBonePositionCommand((*ii).first, + (*ii).second.X, (*ii).second.Y); + // create message and add to list + m_messages_out.emplace(getId(), true, str); + } + } + + if (!m_attachment_sent) { + m_attachment_sent = true; + std::string str = generateUpdateAttachmentCommand(); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + } +} + +std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_PHYSICS_OVERRIDE); + // parameters + writeF32(os, m_physics_override_speed); + writeF32(os, m_physics_override_jump); + writeF32(os, m_physics_override_gravity); + // these are sent inverted so we get true when the server sends nothing + writeU8(os, !m_physics_override_sneak); + writeU8(os, !m_physics_override_sneak_glitch); + writeU8(os, !m_physics_override_new_move); + return os.str(); +} + +void PlayerSAO::setBasePosition(const v3f &position) +{ + if (m_player && position != m_base_position) + m_player->setDirty(true); + + // This needs to be ran for attachments too + ServerActiveObject::setBasePosition(position); + + // Updating is not wanted/required for player migration + if (m_env) { + m_position_not_sent = true; + } +} + +void PlayerSAO::setPos(const v3f &pos) +{ + if(isAttached()) + return; + + // Send mapblock of target location + v3s16 blockpos = v3s16(pos.X / MAP_BLOCKSIZE, pos.Y / MAP_BLOCKSIZE, pos.Z / MAP_BLOCKSIZE); + m_env->getGameDef()->SendBlock(m_peer_id, blockpos); + + setBasePosition(pos); + // Movement caused by this command is always valid + m_last_good_position = pos; + m_move_pool.empty(); + m_time_from_last_teleport = 0.0; + m_env->getGameDef()->SendMovePlayer(m_peer_id); +} + +void PlayerSAO::moveTo(v3f pos, bool continuous) +{ + if(isAttached()) + return; + + setBasePosition(pos); + // Movement caused by this command is always valid + m_last_good_position = pos; + m_move_pool.empty(); + m_time_from_last_teleport = 0.0; + m_env->getGameDef()->SendMovePlayer(m_peer_id); +} + +void PlayerSAO::setPlayerYaw(const float yaw) +{ + v3f rotation(0, yaw, 0); + if (m_player && yaw != m_rotation.Y) + m_player->setDirty(true); + + // Set player model yaw, not look view + UnitSAO::setRotation(rotation); +} + +void PlayerSAO::setFov(const float fov) +{ + if (m_player && fov != m_fov) + m_player->setDirty(true); + + m_fov = fov; +} + +void PlayerSAO::setWantedRange(const s16 range) +{ + if (m_player && range != m_wanted_range) + m_player->setDirty(true); + + m_wanted_range = range; +} + +void PlayerSAO::setPlayerYawAndSend(const float yaw) +{ + setPlayerYaw(yaw); + m_env->getGameDef()->SendMovePlayer(m_peer_id); +} + +void PlayerSAO::setLookPitch(const float pitch) +{ + if (m_player && pitch != m_pitch) + m_player->setDirty(true); + + m_pitch = pitch; +} + +void PlayerSAO::setLookPitchAndSend(const float pitch) +{ + setLookPitch(pitch); + m_env->getGameDef()->SendMovePlayer(m_peer_id); +} + +u16 PlayerSAO::punch(v3f dir, + const ToolCapabilities *toolcap, + ServerActiveObject *puncher, + float time_from_last_punch) +{ + if (!toolcap) + return 0; + + FATAL_ERROR_IF(!puncher, "Punch action called without SAO"); + + // No effect if PvP disabled or if immortal + if (isImmortal() || !g_settings->getBool("enable_pvp")) { + if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + // create message and add to list + sendPunchCommand(); + return 0; + } + } + + s32 old_hp = getHP(); + HitParams hitparams = getHitParams(m_armor_groups, toolcap, + time_from_last_punch); + + PlayerSAO *playersao = m_player->getPlayerSAO(); + + bool damage_handled = m_env->getScriptIface()->on_punchplayer(playersao, + puncher, time_from_last_punch, toolcap, dir, + hitparams.hp); + + if (!damage_handled) { + setHP((s32)getHP() - (s32)hitparams.hp, + PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); + } else { // override client prediction + if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + // create message and add to list + sendPunchCommand(); + } + } + + actionstream << puncher->getDescription() << " (id=" << puncher->getId() << + ", hp=" << puncher->getHP() << ") punched " << + getDescription() << " (id=" << m_id << ", hp=" << m_hp << + "), damage=" << (old_hp - (s32)getHP()) << + (damage_handled ? " (handled by Lua)" : "") << std::endl; + + return hitparams.wear; +} + +void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason) +{ + s32 oldhp = m_hp; + + hp = rangelim(hp, 0, m_prop.hp_max); + + if (oldhp != hp) { + s32 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp, reason); + if (hp_change == 0) + return; + + hp = rangelim(oldhp + hp_change, 0, m_prop.hp_max); + } + + if (hp < oldhp && isImmortal()) + return; + + m_hp = hp; + + // Update properties on death + if ((hp == 0) != (oldhp == 0)) + m_properties_sent = false; +} + +void PlayerSAO::setBreath(const u16 breath, bool send) +{ + if (m_player && breath != m_breath) + m_player->setDirty(true); + + m_breath = rangelim(breath, 0, m_prop.breath_max); + + if (send) + m_env->getGameDef()->SendPlayerBreath(this); +} + +Inventory *PlayerSAO::getInventory() const +{ + return m_player ? &m_player->inventory : nullptr; +} + +InventoryLocation PlayerSAO::getInventoryLocation() const +{ + InventoryLocation loc; + loc.setPlayer(m_player->getName()); + return loc; +} + +u16 PlayerSAO::getWieldIndex() const +{ + return m_player->getWieldIndex(); +} + +ItemStack PlayerSAO::getWieldedItem(ItemStack *selected, ItemStack *hand) const +{ + return m_player->getWieldedItem(selected, hand); +} + +bool PlayerSAO::setWieldedItem(const ItemStack &item) +{ + InventoryList *mlist = m_player->inventory.getList(getWieldList()); + if (mlist) { + mlist->changeItem(m_player->getWieldIndex(), item); + return true; + } + return false; +} + +void PlayerSAO::disconnected() +{ + m_peer_id = PEER_ID_INEXISTENT; + m_pending_removal = true; +} + +void PlayerSAO::unlinkPlayerSessionAndSave() +{ + assert(m_player->getPlayerSAO() == this); + m_player->setPeerId(PEER_ID_INEXISTENT); + m_env->savePlayer(m_player); + m_player->setPlayerSAO(NULL); + m_env->removePlayer(m_player); +} + +std::string PlayerSAO::getPropertyPacket() +{ + m_prop.is_visible = (true); + return generateSetPropertiesCommand(m_prop); +} + +void PlayerSAO::setMaxSpeedOverride(const v3f &vel) +{ + if (m_max_speed_override_time == 0.0f) + m_max_speed_override = vel; + else + m_max_speed_override += vel; + if (m_player) { + float accel = MYMIN(m_player->movement_acceleration_default, + m_player->movement_acceleration_air); + m_max_speed_override_time = m_max_speed_override.getLength() / accel / BS; + } +} + +bool PlayerSAO::checkMovementCheat() +{ + if (isAttached() || m_is_singleplayer || + g_settings->getBool("disable_anticheat")) { + m_last_good_position = m_base_position; + return false; + } + + bool cheated = false; + /* + Check player movements + + NOTE: Actually the server should handle player physics like the + client does and compare player's position to what is calculated + on our side. This is required when eg. players fly due to an + explosion. Altough a node-based alternative might be possible + too, and much more lightweight. + */ + + float override_max_H, override_max_V; + if (m_max_speed_override_time > 0.0f) { + override_max_H = MYMAX(fabs(m_max_speed_override.X), fabs(m_max_speed_override.Z)); + override_max_V = fabs(m_max_speed_override.Y); + } else { + override_max_H = override_max_V = 0.0f; + } + + float player_max_walk = 0; // horizontal movement + float player_max_jump = 0; // vertical upwards movement + + if (m_privs.count("fast") != 0) + player_max_walk = m_player->movement_speed_fast; // Fast speed + else + player_max_walk = m_player->movement_speed_walk; // Normal speed + player_max_walk *= m_physics_override_speed; + player_max_walk = MYMAX(player_max_walk, override_max_H); + + player_max_jump = m_player->movement_speed_jump * m_physics_override_jump; + // FIXME: Bouncy nodes cause practically unbound increase in Y speed, + // until this can be verified correctly, tolerate higher jumping speeds + player_max_jump *= 2.0; + player_max_jump = MYMAX(player_max_jump, override_max_V); + + // Don't divide by zero! + if (player_max_walk < 0.0001f) + player_max_walk = 0.0001f; + if (player_max_jump < 0.0001f) + player_max_jump = 0.0001f; + + v3f diff = (m_base_position - m_last_good_position); + float d_vert = diff.Y; + diff.Y = 0; + float d_horiz = diff.getLength(); + float required_time = d_horiz / player_max_walk; + + // FIXME: Checking downwards movement is not easily possible currently, + // the server could calculate speed differences to examine the gravity + if (d_vert > 0) { + // In certain cases (water, ladders) walking speed is applied vertically + float s = MYMAX(player_max_jump, player_max_walk); + required_time = MYMAX(required_time, d_vert / s); + } + + if (m_move_pool.grab(required_time)) { + m_last_good_position = m_base_position; + } else { + const float LAG_POOL_MIN = 5.0; + float lag_pool_max = m_env->getMaxLagEstimate() * 2.0; + lag_pool_max = MYMAX(lag_pool_max, LAG_POOL_MIN); + if (m_time_from_last_teleport > lag_pool_max) { + actionstream << "Player " << m_player->getName() + << " moved too fast; resetting position" + << std::endl; + cheated = true; + } + setBasePosition(m_last_good_position); + } + return cheated; +} + +bool PlayerSAO::getCollisionBox(aabb3f *toset) const +{ + //update collision box + toset->MinEdge = m_prop.collisionbox.MinEdge * BS; + toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; + + toset->MinEdge += m_base_position; + toset->MaxEdge += m_base_position; + return true; +} + +bool PlayerSAO::getSelectionBox(aabb3f *toset) const +{ + if (!m_prop.is_visible || !m_prop.pointable) { + return false; + } + + toset->MinEdge = m_prop.selectionbox.MinEdge * BS; + toset->MaxEdge = m_prop.selectionbox.MaxEdge * BS; + + return true; +} + +float PlayerSAO::getZoomFOV() const +{ + return m_prop.zoom_fov; +} diff --git a/src/server/player_sao.h b/src/server/player_sao.h new file mode 100644 index 000000000..ce1cb1677 --- /dev/null +++ b/src/server/player_sao.h @@ -0,0 +1,325 @@ + +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2013-2020 Minetest core developers & community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "constants.h" +#include "network/networkprotocol.h" +#include "unit_sao.h" +#include "util/numeric.h" + +/* + PlayerSAO needs some internals exposed. +*/ + +class LagPool +{ + float m_pool = 15.0f; + float m_max = 15.0f; +public: + LagPool() = default; + + void setMax(float new_max) + { + m_max = new_max; + if(m_pool > new_max) + m_pool = new_max; + } + + void add(float dtime) + { + m_pool -= dtime; + if(m_pool < 0) + m_pool = 0; + } + + void empty() + { + m_pool = m_max; + } + + bool grab(float dtime) + { + if(dtime <= 0) + return true; + if(m_pool + dtime > m_max) + return false; + m_pool += dtime; + return true; + } +}; + +class RemotePlayer; + +class PlayerSAO : public UnitSAO +{ +public: + PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, + bool is_singleplayer); + + ActiveObjectType getType() const + { return ACTIVEOBJECT_TYPE_PLAYER; } + ActiveObjectType getSendType() const + { return ACTIVEOBJECT_TYPE_GENERIC; } + std::string getDescription(); + + /* + Active object <-> environment interface + */ + + void addedToEnvironment(u32 dtime_s); + void removingFromEnvironment(); + bool isStaticAllowed() const { return false; } + std::string getClientInitializationData(u16 protocol_version); + void getStaticData(std::string *result) const; + void step(float dtime, bool send_recommended); + void setBasePosition(const v3f &position); + void setPos(const v3f &pos); + void moveTo(v3f pos, bool continuous); + void setPlayerYaw(const float yaw); + // Data should not be sent at player initialization + void setPlayerYawAndSend(const float yaw); + void setLookPitch(const float pitch); + // Data should not be sent at player initialization + void setLookPitchAndSend(const float pitch); + f32 getLookPitch() const { return m_pitch; } + f32 getRadLookPitch() const { return m_pitch * core::DEGTORAD; } + // Deprecated + f32 getRadLookPitchDep() const { return -1.0 * m_pitch * core::DEGTORAD; } + void setFov(const float pitch); + f32 getFov() const { return m_fov; } + void setWantedRange(const s16 range); + s16 getWantedRange() const { return m_wanted_range; } + + /* + Interaction interface + */ + + u16 punch(v3f dir, + const ToolCapabilities *toolcap, + ServerActiveObject *puncher, + float time_from_last_punch); + void rightClick(ServerActiveObject *clicker) {} + void setHP(s32 hp, const PlayerHPChangeReason &reason); + void setHPRaw(u16 hp) { m_hp = hp; } + s16 readDamage(); + u16 getBreath() const { return m_breath; } + void setBreath(const u16 breath, bool send = true); + + /* + Inventory interface + */ + Inventory *getInventory() const; + InventoryLocation getInventoryLocation() const; + void setInventoryModified() {} + std::string getWieldList() const { return "main"; } + u16 getWieldIndex() const; + ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const; + bool setWieldedItem(const ItemStack &item); + + /* + PlayerSAO-specific + */ + + void disconnected(); + + RemotePlayer *getPlayer() { return m_player; } + session_t getPeerID() const { return m_peer_id; } + + // Cheat prevention + + v3f getLastGoodPosition() const + { + return m_last_good_position; + } + float resetTimeFromLastPunch() + { + float r = m_time_from_last_punch; + m_time_from_last_punch = 0.0; + return r; + } + void noCheatDigStart(const v3s16 &p) + { + m_nocheat_dig_pos = p; + m_nocheat_dig_time = 0; + } + v3s16 getNoCheatDigPos() + { + return m_nocheat_dig_pos; + } + float getNoCheatDigTime() + { + return m_nocheat_dig_time; + } + void noCheatDigEnd() + { + m_nocheat_dig_pos = v3s16(32767, 32767, 32767); + } + LagPool& getDigPool() + { + return m_dig_pool; + } + void setMaxSpeedOverride(const v3f &vel); + // Returns true if cheated + bool checkMovementCheat(); + + // Other + + void updatePrivileges(const std::set &privs, + bool is_singleplayer) + { + m_privs = privs; + m_is_singleplayer = is_singleplayer; + } + + bool getCollisionBox(aabb3f *toset) const; + bool getSelectionBox(aabb3f *toset) const; + bool collideWithObjects() const { return true; } + + void finalize(RemotePlayer *player, const std::set &privs); + + v3f getEyePosition() const { return m_base_position + getEyeOffset(); } + v3f getEyeOffset() const; + float getZoomFOV() const; + + inline Metadata &getMeta() { return m_meta; } + +private: + std::string getPropertyPacket(); + void unlinkPlayerSessionAndSave(); + std::string generateUpdatePhysicsOverrideCommand() const; + + RemotePlayer *m_player = nullptr; + session_t m_peer_id = 0; + + // Cheat prevention + LagPool m_dig_pool; + LagPool m_move_pool; + v3f m_last_good_position; + float m_time_from_last_teleport = 0.0f; + float m_time_from_last_punch = 0.0f; + v3s16 m_nocheat_dig_pos = v3s16(32767, 32767, 32767); + float m_nocheat_dig_time = 0.0f; + float m_max_speed_override_time = 0.0f; + v3f m_max_speed_override = v3f(0.0f, 0.0f, 0.0f); + + // Timers + IntervalLimiter m_breathing_interval; + IntervalLimiter m_drowning_interval; + IntervalLimiter m_node_hurt_interval; + + bool m_position_not_sent = false; + + // Cached privileges for enforcement + std::set m_privs; + bool m_is_singleplayer; + + u16 m_breath = PLAYER_MAX_BREATH_DEFAULT; + f32 m_pitch = 0.0f; + f32 m_fov = 0.0f; + s16 m_wanted_range = 0.0f; + + Metadata m_meta; +public: + float m_physics_override_speed = 1.0f; + float m_physics_override_jump = 1.0f; + float m_physics_override_gravity = 1.0f; + bool m_physics_override_sneak = true; + bool m_physics_override_sneak_glitch = false; + bool m_physics_override_new_move = true; + bool m_physics_override_sent = false; +}; + + +struct PlayerHPChangeReason { + enum Type : u8 { + SET_HP, + PLAYER_PUNCH, + FALL, + NODE_DAMAGE, + DROWNING, + RESPAWN + }; + + Type type = SET_HP; + bool from_mod = false; + int lua_reference = -1; + + // For PLAYER_PUNCH + ServerActiveObject *object = nullptr; + // For NODE_DAMAGE + std::string node; + + inline bool hasLuaReference() const + { + return lua_reference >= 0; + } + + bool setTypeFromString(const std::string &typestr) + { + if (typestr == "set_hp") + type = SET_HP; + else if (typestr == "punch") + type = PLAYER_PUNCH; + else if (typestr == "fall") + type = FALL; + else if (typestr == "node_damage") + type = NODE_DAMAGE; + else if (typestr == "drown") + type = DROWNING; + else if (typestr == "respawn") + type = RESPAWN; + else + return false; + + return true; + } + + std::string getTypeAsString() const + { + switch (type) { + case PlayerHPChangeReason::SET_HP: + return "set_hp"; + case PlayerHPChangeReason::PLAYER_PUNCH: + return "punch"; + case PlayerHPChangeReason::FALL: + return "fall"; + case PlayerHPChangeReason::NODE_DAMAGE: + return "node_damage"; + case PlayerHPChangeReason::DROWNING: + return "drown"; + case PlayerHPChangeReason::RESPAWN: + return "respawn"; + default: + return "?"; + } + } + + PlayerHPChangeReason(Type type): + type(type) + {} + + PlayerHPChangeReason(Type type, ServerActiveObject *object): + type(type), object(object) + {} + + PlayerHPChangeReason(Type type, std::string node): + type(type), node(node) + {} +}; diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index b30b7a76b..74b0508b8 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -22,10 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_server.h" #include "serverenvironment.h" -/* - UnitSAO - */ - UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos) : ServerActiveObject(env, pos) { // Initialize something to armor groups diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 0ccbd772b..c2ab5c07d 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -17,8 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include "serverenvironment.h" -#include "content_sao.h" #include "settings.h" #include "log.h" #include "mapblock.h" @@ -44,7 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #if USE_POSTGRESQL #include "database/database-postgresql.h" #endif -#include +#include "server/player_sao.h" #define LBM_NAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_:" -- cgit v1.2.3 From 5146086a64d5eeb480948d612a008a2ec81455d4 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 11 Apr 2020 11:22:15 +0200 Subject: Drop content_sao.{cpp,h} Move LuaEntitySAO to a new dedicated file Drop TestSAO (useless object) Drop the old static startup initialized SAO factory, which was pretty useless. This factory was using a std::map for 2 elements, now just use a simple condition owned by ServerEnvironment, which will be lightweight, that will also drop a one time useful test on each LuaEntitySAO creation. This should reduce server load on massive SAO creation --- build/android/jni/Android.mk | 4 +- src/CMakeLists.txt | 1 - src/clientiface.cpp | 2 +- src/content_sao.cpp | 681 --------------------------------- src/content_sao.h | 101 ----- src/mapgen/mapgen.cpp | 1 - src/mapgen/mapgen_carpathian.cpp | 1 - src/mapgen/mapgen_flat.cpp | 1 - src/mapgen/mapgen_fractal.cpp | 1 - src/mapgen/mapgen_v5.cpp | 1 - src/mapgen/mapgen_v6.cpp | 1 - src/mapgen/mapgen_v7.cpp | 1 - src/script/cpp_api/s_base.cpp | 1 - src/script/lua_api/l_env.cpp | 2 +- src/script/lua_api/l_item.cpp | 1 - src/script/lua_api/l_object.cpp | 2 +- src/server/CMakeLists.txt | 1 + src/server/luaentity_sao.cpp | 581 ++++++++++++++++++++++++++++ src/server/luaentity_sao.h | 93 +++++ src/server/player_sao.h | 83 ++-- src/server/serveractiveobject.cpp | 33 -- src/server/serveractiveobject.h | 10 - src/serverenvironment.cpp | 19 +- src/serverenvironment.h | 2 + src/staticobject.cpp | 2 +- src/unittest/test_player.cpp | 1 - util/travis/clang-format-whitelist.txt | 4 +- 27 files changed, 731 insertions(+), 900 deletions(-) delete mode 100644 src/content_sao.cpp delete mode 100644 src/content_sao.h create mode 100644 src/server/luaentity_sao.cpp create mode 100644 src/server/luaentity_sao.h (limited to 'src') diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index 32a16c174..fdbfba9bc 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -161,7 +161,6 @@ LOCAL_SRC_FILES := \ jni/src/content/mods.cpp \ jni/src/content_nodemeta.cpp \ jni/src/content/packages.cpp \ - jni/src/content_sao.cpp \ jni/src/content/subgames.cpp \ jni/src/convert_json.cpp \ jni/src/craftdef.cpp \ @@ -258,8 +257,11 @@ LOCAL_SRC_FILES := \ jni/src/server.cpp \ jni/src/serverenvironment.cpp \ jni/src/serverlist.cpp \ + jni/src/server/luaentity_sao.cpp \ jni/src/server/mods.cpp \ + jni/src/server/player_sao.cpp \ jni/src/server/serveractiveobject.cpp \ + jni/src/server/unit_sao.cpp \ jni/src/settings.cpp \ jni/src/staticobject.cpp \ jni/src/tileanimation.cpp \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index faa117d41..0ebbd628c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -375,7 +375,6 @@ set(common_SRCS collision.cpp content_mapnode.cpp content_nodemeta.cpp - content_sao.cpp convert_json.cpp craftdef.cpp debug.cpp diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 17237f73e..4f954342a 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "clientiface.h" -#include "content_sao.h" #include "network/connection.h" #include "network/serveropcodes.h" #include "remoteplayer.h" @@ -28,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverenvironment.h" #include "map.h" #include "emerge.h" +#include "server/luaentity_sao.h" #include "server/player_sao.h" #include "log.h" #include "util/srp.h" diff --git a/src/content_sao.cpp b/src/content_sao.cpp deleted file mode 100644 index 7ec17aa82..000000000 --- a/src/content_sao.cpp +++ /dev/null @@ -1,681 +0,0 @@ -/* -Minetest -Copyright (C) 2010-2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "content_sao.h" -#include "util/serialize.h" -#include "collision.h" -#include "environment.h" -#include "tool.h" // For ToolCapabilities -#include "gamedef.h" -#include "nodedef.h" -#include "remoteplayer.h" -#include "server.h" -#include "scripting_server.h" -#include "server/player_sao.h" -#include "settings.h" -#include -#include - -std::map ServerActiveObject::m_types; - -/* - TestSAO -*/ - -class TestSAO : public ServerActiveObject -{ -public: - TestSAO(ServerEnvironment *env, v3f pos): - ServerActiveObject(env, pos), - m_timer1(0), - m_age(0) - { - ServerActiveObject::registerType(getType(), create); - } - ActiveObjectType getType() const - { return ACTIVEOBJECT_TYPE_TEST; } - - static ServerActiveObject* create(ServerEnvironment *env, v3f pos, - const std::string &data) - { - return new TestSAO(env, pos); - } - - void step(float dtime, bool send_recommended) - { - m_age += dtime; - if(m_age > 10) - { - m_pending_removal = true; - return; - } - - m_base_position.Y += dtime * BS * 2; - if(m_base_position.Y > 8*BS) - m_base_position.Y = 2*BS; - - if (!send_recommended) - return; - - m_timer1 -= dtime; - if(m_timer1 < 0.0) - { - m_timer1 += 0.125; - - std::string data; - - data += itos(0); // 0 = position - data += " "; - data += itos(m_base_position.X); - data += " "; - data += itos(m_base_position.Y); - data += " "; - data += itos(m_base_position.Z); - - ActiveObjectMessage aom(getId(), false, data); - m_messages_out.push(aom); - } - } - - bool getCollisionBox(aabb3f *toset) const { return false; } - - virtual bool getSelectionBox(aabb3f *toset) const { return false; } - - bool collideWithObjects() const { return false; } - -private: - float m_timer1; - float m_age; -}; - -// Prototype (registers item for deserialization) -TestSAO proto_TestSAO(NULL, v3f(0,0,0)); - -/* - LuaEntitySAO -*/ - -// Prototype (registers item for deserialization) -LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", ""); - -LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, - const std::string &name, const std::string &state): - UnitSAO(env, pos), - m_init_name(name), - m_init_state(state) -{ - // Only register type if no environment supplied - if(env == NULL){ - ServerActiveObject::registerType(getType(), create); - return; - } -} - -LuaEntitySAO::~LuaEntitySAO() -{ - if(m_registered){ - m_env->getScriptIface()->luaentity_Remove(m_id); - } - - for (u32 attached_particle_spawner : m_attached_particle_spawners) { - m_env->deleteParticleSpawner(attached_particle_spawner, false); - } -} - -void LuaEntitySAO::addedToEnvironment(u32 dtime_s) -{ - ServerActiveObject::addedToEnvironment(dtime_s); - - // Create entity from name - m_registered = m_env->getScriptIface()-> - luaentity_Add(m_id, m_init_name.c_str()); - - if(m_registered){ - // Get properties - m_env->getScriptIface()-> - luaentity_GetProperties(m_id, this, &m_prop); - // Initialize HP from properties - m_hp = m_prop.hp_max; - // Activate entity, supplying serialized state - m_env->getScriptIface()-> - luaentity_Activate(m_id, m_init_state, dtime_s); - } else { - m_prop.infotext = m_init_name; - } -} - -ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos, - const std::string &data) -{ - std::string name; - std::string state; - u16 hp = 1; - v3f velocity; - v3f rotation; - - while (!data.empty()) { // breakable, run for one iteration - std::istringstream is(data, std::ios::binary); - // 'version' does not allow to incrementally extend the parameter list thus - // we need another variable to build on top of 'version=1'. Ugly hack but works™ - u8 version2 = 0; - u8 version = readU8(is); - - name = deSerializeString(is); - state = deSerializeLongString(is); - - if (version < 1) - break; - - hp = readU16(is); - velocity = readV3F1000(is); - // yaw must be yaw to be backwards-compatible - rotation.Y = readF1000(is); - - if (is.good()) // EOF for old formats - version2 = readU8(is); - - if (version2 < 1) // PROTOCOL_VERSION < 37 - break; - - // version2 >= 1 - rotation.X = readF1000(is); - rotation.Z = readF1000(is); - - // if (version2 < 2) - // break; - // - break; - } - // create object - infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\"" - << state << "\")" << std::endl; - LuaEntitySAO *sao = new LuaEntitySAO(env, pos, name, state); - sao->m_hp = hp; - sao->m_velocity = velocity; - sao->m_rotation = rotation; - return sao; -} - -void LuaEntitySAO::step(float dtime, bool send_recommended) -{ - if(!m_properties_sent) - { - m_properties_sent = true; - std::string str = getPropertyPacket(); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - } - - // If attached, check that our parent is still there. If it isn't, detach. - if(m_attachment_parent_id && !isAttached()) - { - m_attachment_parent_id = 0; - m_attachment_bone = ""; - m_attachment_position = v3f(0,0,0); - m_attachment_rotation = v3f(0,0,0); - sendPosition(false, true); - } - - m_last_sent_position_timer += dtime; - - // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally - // If the object gets detached this comes into effect automatically from the last known origin - if(isAttached()) - { - v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); - m_base_position = pos; - m_velocity = v3f(0,0,0); - m_acceleration = v3f(0,0,0); - } - else - { - if(m_prop.physical){ - aabb3f box = m_prop.collisionbox; - box.MinEdge *= BS; - box.MaxEdge *= BS; - collisionMoveResult moveresult; - f32 pos_max_d = BS*0.25; // Distance per iteration - v3f p_pos = m_base_position; - v3f p_velocity = m_velocity; - v3f p_acceleration = m_acceleration; - moveresult = collisionMoveSimple(m_env, m_env->getGameDef(), - pos_max_d, box, m_prop.stepheight, dtime, - &p_pos, &p_velocity, p_acceleration, - this, m_prop.collideWithObjects); - - // Apply results - m_base_position = p_pos; - m_velocity = p_velocity; - m_acceleration = p_acceleration; - } else { - m_base_position += dtime * m_velocity + 0.5 * dtime - * dtime * m_acceleration; - m_velocity += dtime * m_acceleration; - } - - if (m_prop.automatic_face_movement_dir && - (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) { - float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI - + m_prop.automatic_face_movement_dir_offset; - float max_rotation_per_sec = - m_prop.automatic_face_movement_max_rotation_per_sec; - - if (max_rotation_per_sec > 0) { - m_rotation.Y = wrapDegrees_0_360(m_rotation.Y); - wrappedApproachShortest(m_rotation.Y, target_yaw, - dtime * max_rotation_per_sec, 360.f); - } else { - // Negative values of max_rotation_per_sec mean disabled. - m_rotation.Y = target_yaw; - } - } - } - - if(m_registered){ - m_env->getScriptIface()->luaentity_Step(m_id, dtime); - } - - if (!send_recommended) - return; - - if(!isAttached()) - { - // TODO: force send when acceleration changes enough? - float minchange = 0.2*BS; - if(m_last_sent_position_timer > 1.0){ - minchange = 0.01*BS; - } else if(m_last_sent_position_timer > 0.2){ - minchange = 0.05*BS; - } - float move_d = m_base_position.getDistanceFrom(m_last_sent_position); - move_d += m_last_sent_move_precision; - float vel_d = m_velocity.getDistanceFrom(m_last_sent_velocity); - if (move_d > minchange || vel_d > minchange || - std::fabs(m_rotation.X - m_last_sent_rotation.X) > 1.0f || - std::fabs(m_rotation.Y - m_last_sent_rotation.Y) > 1.0f || - std::fabs(m_rotation.Z - m_last_sent_rotation.Z) > 1.0f) { - - sendPosition(true, false); - } - } - - if (!m_armor_groups_sent) { - m_armor_groups_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); - } - - if (!m_animation_sent) { - m_animation_sent = true; - std::string str = generateUpdateAnimationCommand(); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - } - - if (!m_animation_speed_sent) { - m_animation_speed_sent = true; - std::string str = generateUpdateAnimationSpeedCommand(); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - } - - if (!m_bone_position_sent) { - m_bone_position_sent = true; - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - std::string str = generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - } - } - - if (!m_attachment_sent) { - m_attachment_sent = true; - std::string str = generateUpdateAttachmentCommand(); - // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); - } -} - -std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) -{ - std::ostringstream os(std::ios::binary); - - // PROTOCOL_VERSION >= 37 - writeU8(os, 1); // version - os << serializeString(""); // name - writeU8(os, 0); // is_player - writeU16(os, getId()); //id - writeV3F32(os, m_base_position); - writeV3F32(os, m_rotation); - writeU16(os, m_hp); - - std::ostringstream msg_os(std::ios::binary); - msg_os << serializeLongString(getPropertyPacket()); // message 1 - msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 - msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y)); // m_bone_position.size - } - msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 - int message_count = 4 + m_bone_position.size(); - for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); - (ii != m_attachment_child_ids.end()); ++ii) { - if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { - message_count++; - // TODO after a protocol bump: only send the object initialization data - // to older clients (superfluous since this message exists) - msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); - } - } - - msg_os << serializeLongString(generateSetTextureModCommand()); - message_count++; - - writeU8(os, message_count); - os.write(msg_os.str().c_str(), msg_os.str().size()); - - // return result - return os.str(); -} - -void LuaEntitySAO::getStaticData(std::string *result) const -{ - verbosestream<getScriptIface()-> - luaentity_GetStaticdata(m_id); - os<= 37 - - writeF1000(os, m_rotation.X); - writeF1000(os, m_rotation.Z); - - // - - *result = os.str(); -} - -u16 LuaEntitySAO::punch(v3f dir, - const ToolCapabilities *toolcap, - ServerActiveObject *puncher, - float time_from_last_punch) -{ - if (!m_registered) { - // Delete unknown LuaEntities when punched - m_pending_removal = true; - return 0; - } - - FATAL_ERROR_IF(!puncher, "Punch action called without SAO"); - - s32 old_hp = getHP(); - ItemStack selected_item, hand_item; - ItemStack tool_item = puncher->getWieldedItem(&selected_item, &hand_item); - - PunchDamageResult result = getPunchDamage( - m_armor_groups, - toolcap, - &tool_item, - time_from_last_punch); - - bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher, - time_from_last_punch, toolcap, dir, result.did_punch ? result.damage : 0); - - if (!damage_handled) { - if (result.did_punch) { - setHP((s32)getHP() - result.damage, - PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); - - // create message and add to list - sendPunchCommand(); - } - } - - if (getHP() == 0 && !isGone()) { - clearParentAttachment(); - clearChildAttachments(); - m_env->getScriptIface()->luaentity_on_death(m_id, puncher); - m_pending_removal = true; - } - - actionstream << puncher->getDescription() << " (id=" << puncher->getId() << - ", hp=" << puncher->getHP() << ") punched " << - getDescription() << " (id=" << m_id << ", hp=" << m_hp << - "), damage=" << (old_hp - (s32)getHP()) << - (damage_handled ? " (handled by Lua)" : "") << std::endl; - - // TODO: give Lua control over wear - return result.wear; -} - -void LuaEntitySAO::rightClick(ServerActiveObject *clicker) -{ - if (!m_registered) - return; - - m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker); -} - -void LuaEntitySAO::setPos(const v3f &pos) -{ - if(isAttached()) - return; - m_base_position = pos; - sendPosition(false, true); -} - -void LuaEntitySAO::moveTo(v3f pos, bool continuous) -{ - if(isAttached()) - return; - m_base_position = pos; - if(!continuous) - sendPosition(true, true); -} - -float LuaEntitySAO::getMinimumSavedMovement() -{ - return 0.1 * BS; -} - -std::string LuaEntitySAO::getDescription() -{ - std::ostringstream oss; - oss << "LuaEntitySAO \"" << m_init_name << "\" "; - auto pos = floatToInt(m_base_position, BS); - oss << "at " << PP(pos); - return oss.str(); -} - -void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason) -{ - m_hp = rangelim(hp, 0, U16_MAX); -} - -u16 LuaEntitySAO::getHP() const -{ - return m_hp; -} - -void LuaEntitySAO::setVelocity(v3f velocity) -{ - m_velocity = velocity; -} - -v3f LuaEntitySAO::getVelocity() -{ - return m_velocity; -} - -void LuaEntitySAO::setAcceleration(v3f acceleration) -{ - m_acceleration = acceleration; -} - -v3f LuaEntitySAO::getAcceleration() -{ - return m_acceleration; -} - -void LuaEntitySAO::setTextureMod(const std::string &mod) -{ - m_current_texture_modifier = mod; - // create message and add to list - m_messages_out.emplace(getId(), true, generateSetTextureModCommand()); -} - -std::string LuaEntitySAO::getTextureMod() const -{ - return m_current_texture_modifier; -} - - -std::string LuaEntitySAO::generateSetTextureModCommand() const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SET_TEXTURE_MOD); - // parameters - os << serializeString(m_current_texture_modifier); - return os.str(); -} - -std::string LuaEntitySAO::generateSetSpriteCommand(v2s16 p, u16 num_frames, - f32 framelength, bool select_horiz_by_yawpitch) -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_SET_SPRITE); - // parameters - writeV2S16(os, p); - writeU16(os, num_frames); - writeF32(os, framelength); - writeU8(os, select_horiz_by_yawpitch); - return os.str(); -} - -void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength, - bool select_horiz_by_yawpitch) -{ - std::string str = generateSetSpriteCommand( - p, - num_frames, - framelength, - select_horiz_by_yawpitch - ); - // create message and add to list - m_messages_out.emplace(getId(), true, str); -} - -std::string LuaEntitySAO::getName() -{ - return m_init_name; -} - -std::string LuaEntitySAO::getPropertyPacket() -{ - return generateSetPropertiesCommand(m_prop); -} - -void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) -{ - // If the object is attached client-side, don't waste bandwidth sending its position to clients - if(isAttached()) - return; - - m_last_sent_move_precision = m_base_position.getDistanceFrom( - m_last_sent_position); - m_last_sent_position_timer = 0; - m_last_sent_position = m_base_position; - m_last_sent_velocity = m_velocity; - //m_last_sent_acceleration = m_acceleration; - m_last_sent_rotation = m_rotation; - - float update_interval = m_env->getSendRecommendedInterval(); - - std::string str = generateUpdatePositionCommand( - m_base_position, - m_velocity, - m_acceleration, - m_rotation, - do_interpolate, - is_movement_end, - update_interval - ); - // create message and add to list - m_messages_out.emplace(getId(), false, str); -} - -bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const -{ - if (m_prop.physical) - { - //update collision box - toset->MinEdge = m_prop.collisionbox.MinEdge * BS; - toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; - - toset->MinEdge += m_base_position; - toset->MaxEdge += m_base_position; - - return true; - } - - return false; -} - -bool LuaEntitySAO::getSelectionBox(aabb3f *toset) const -{ - if (!m_prop.is_visible || !m_prop.pointable) { - return false; - } - - toset->MinEdge = m_prop.selectionbox.MinEdge * BS; - toset->MaxEdge = m_prop.selectionbox.MaxEdge * BS; - - return true; -} - -bool LuaEntitySAO::collideWithObjects() const -{ - return m_prop.collideWithObjects; -} diff --git a/src/content_sao.h b/src/content_sao.h deleted file mode 100644 index 5387fd108..000000000 --- a/src/content_sao.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -Minetest -Copyright (C) 2010-2013 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#pragma once - -#include "network/networkprotocol.h" -#include "util/numeric.h" -#include "server/unit_sao.h" -#include "itemgroup.h" -#include "constants.h" - -/* - LuaEntitySAO needs some internals exposed. -*/ - -class LuaEntitySAO : public UnitSAO -{ -public: - LuaEntitySAO(ServerEnvironment *env, v3f pos, - const std::string &name, const std::string &state); - ~LuaEntitySAO(); - ActiveObjectType getType() const - { return ACTIVEOBJECT_TYPE_LUAENTITY; } - ActiveObjectType getSendType() const - { return ACTIVEOBJECT_TYPE_GENERIC; } - virtual void addedToEnvironment(u32 dtime_s); - static ServerActiveObject* create(ServerEnvironment *env, v3f pos, - const std::string &data); - void step(float dtime, bool send_recommended); - std::string getClientInitializationData(u16 protocol_version); - bool isStaticAllowed() const - { return m_prop.static_save; } - void getStaticData(std::string *result) const; - u16 punch(v3f dir, - const ToolCapabilities *toolcap = nullptr, - ServerActiveObject *puncher = nullptr, - float time_from_last_punch = 1000000.0f); - void rightClick(ServerActiveObject *clicker); - void setPos(const v3f &pos); - void moveTo(v3f pos, bool continuous); - float getMinimumSavedMovement(); - std::string getDescription(); - void setHP(s32 hp, const PlayerHPChangeReason &reason); - u16 getHP() const; - - /* LuaEntitySAO-specific */ - void setVelocity(v3f velocity); - void addVelocity(v3f velocity) - { - m_velocity += velocity; - } - v3f getVelocity(); - void setAcceleration(v3f acceleration); - v3f getAcceleration(); - - void setTextureMod(const std::string &mod); - std::string getTextureMod() const; - void setSprite(v2s16 p, int num_frames, float framelength, - bool select_horiz_by_yawpitch); - std::string getName(); - bool getCollisionBox(aabb3f *toset) const; - bool getSelectionBox(aabb3f *toset) const; - bool collideWithObjects() const; -private: - std::string getPropertyPacket(); - void sendPosition(bool do_interpolate, bool is_movement_end); - std::string generateSetTextureModCommand() const; - static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames, f32 framelength, - bool select_horiz_by_yawpitch); - - std::string m_init_name; - std::string m_init_state; - bool m_registered = false; - - v3f m_velocity; - v3f m_acceleration; - - v3f m_last_sent_position; - v3f m_last_sent_velocity; - v3f m_last_sent_rotation; - float m_last_sent_position_timer = 0.0f; - float m_last_sent_move_precision = 0.0f; - std::string m_current_texture_modifier = ""; -}; - diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 6c426ba41..0094608ec 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "emerge.h" #include "voxelalgorithms.h" diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index 0dc1d33be..bd7ae5e7c 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 879435948..272964b51 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 96febb4f4..97f77d947 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index 447fe8c50..3bd7615c4 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index f473f725d..da9ae1428 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 325c4957a..82556cc4f 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock.h" #include "mapnode.h" #include "map.h" -#include "content_sao.h" #include "nodedef.h" #include "voxelalgorithms.h" //#include "profiler.h" // For TimeTaker diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 150baf77e..df07206d7 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -43,7 +43,6 @@ extern "C" { #include #include #include "script/common/c_content.h" -#include "content_sao.h" #include diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 438669feb..40e50e64a 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -33,12 +33,12 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "daynightratio.h" #include "util/pointedthing.h" -#include "content_sao.h" #include "mapgen/treegen.h" #include "emerge.h" #include "pathfinder.h" #include "face_position_cache.h" #include "remoteplayer.h" +#include "server/luaentity_sao.h" #include "server/player_sao.h" #ifndef SERVER #include "client/client.h" diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index ff77cba32..9f12d3ac7 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemdef.h" #include "nodedef.h" #include "server.h" -#include "content_sao.h" #include "inventory.h" #include "log.h" diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 95c96235e..fa34260bf 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -27,11 +27,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_content.h" #include "log.h" #include "tool.h" -#include "content_sao.h" #include "remoteplayer.h" #include "server.h" #include "hud.h" #include "scripting_server.h" +#include "server/luaentity_sao.h" #include "server/player_sao.h" /* diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 26eaed5ac..4d94504f6 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,5 +1,6 @@ set(server_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/activeobjectmgr.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/luaentity_sao.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp ${CMAKE_CURRENT_SOURCE_DIR}/player_sao.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp new file mode 100644 index 000000000..125939241 --- /dev/null +++ b/src/server/luaentity_sao.cpp @@ -0,0 +1,581 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2013-2020 Minetest core developers & community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "luaentity_sao.h" +#include "collision.h" +#include "constants.h" +#include "player_sao.h" +#include "scripting_server.h" +#include "server.h" +#include "serverenvironment.h" + +LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data) + : UnitSAO(env, pos) +{ + std::string name; + std::string state; + u16 hp = 1; + v3f velocity; + v3f rotation; + + while (!data.empty()) { // breakable, run for one iteration + std::istringstream is(data, std::ios::binary); + // 'version' does not allow to incrementally extend the parameter list thus + // we need another variable to build on top of 'version=1'. Ugly hack but works™ + u8 version2 = 0; + u8 version = readU8(is); + + name = deSerializeString(is); + state = deSerializeLongString(is); + + if (version < 1) + break; + + hp = readU16(is); + velocity = readV3F1000(is); + // yaw must be yaw to be backwards-compatible + rotation.Y = readF1000(is); + + if (is.good()) // EOF for old formats + version2 = readU8(is); + + if (version2 < 1) // PROTOCOL_VERSION < 37 + break; + + // version2 >= 1 + rotation.X = readF1000(is); + rotation.Z = readF1000(is); + + // if (version2 < 2) + // break; + // + break; + } + // create object + infostream << "LuaEntitySAO::create(name=\"" << name << "\" state=\"" + << state << "\")" << std::endl; + + m_init_name = name; + m_init_state = state; + m_hp = hp; + m_velocity = velocity; + m_rotation = rotation; +} + +LuaEntitySAO::~LuaEntitySAO() +{ + if(m_registered){ + m_env->getScriptIface()->luaentity_Remove(m_id); + } + + for (u32 attached_particle_spawner : m_attached_particle_spawners) { + m_env->deleteParticleSpawner(attached_particle_spawner, false); + } +} + +void LuaEntitySAO::addedToEnvironment(u32 dtime_s) +{ + ServerActiveObject::addedToEnvironment(dtime_s); + + // Create entity from name + m_registered = m_env->getScriptIface()-> + luaentity_Add(m_id, m_init_name.c_str()); + + if(m_registered){ + // Get properties + m_env->getScriptIface()-> + luaentity_GetProperties(m_id, this, &m_prop); + // Initialize HP from properties + m_hp = m_prop.hp_max; + // Activate entity, supplying serialized state + m_env->getScriptIface()-> + luaentity_Activate(m_id, m_init_state, dtime_s); + } else { + m_prop.infotext = m_init_name; + } +} + +void LuaEntitySAO::step(float dtime, bool send_recommended) +{ + if(!m_properties_sent) + { + m_properties_sent = true; + std::string str = getPropertyPacket(); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + } + + // If attached, check that our parent is still there. If it isn't, detach. + if(m_attachment_parent_id && !isAttached()) + { + m_attachment_parent_id = 0; + m_attachment_bone = ""; + m_attachment_position = v3f(0,0,0); + m_attachment_rotation = v3f(0,0,0); + sendPosition(false, true); + } + + m_last_sent_position_timer += dtime; + + // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally + // If the object gets detached this comes into effect automatically from the last known origin + if(isAttached()) + { + v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); + m_base_position = pos; + m_velocity = v3f(0,0,0); + m_acceleration = v3f(0,0,0); + } + else + { + if(m_prop.physical){ + aabb3f box = m_prop.collisionbox; + box.MinEdge *= BS; + box.MaxEdge *= BS; + collisionMoveResult moveresult; + f32 pos_max_d = BS*0.25; // Distance per iteration + v3f p_pos = m_base_position; + v3f p_velocity = m_velocity; + v3f p_acceleration = m_acceleration; + moveresult = collisionMoveSimple(m_env, m_env->getGameDef(), + pos_max_d, box, m_prop.stepheight, dtime, + &p_pos, &p_velocity, p_acceleration, + this, m_prop.collideWithObjects); + + // Apply results + m_base_position = p_pos; + m_velocity = p_velocity; + m_acceleration = p_acceleration; + } else { + m_base_position += dtime * m_velocity + 0.5 * dtime + * dtime * m_acceleration; + m_velocity += dtime * m_acceleration; + } + + if (m_prop.automatic_face_movement_dir && + (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) { + float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI + + m_prop.automatic_face_movement_dir_offset; + float max_rotation_per_sec = + m_prop.automatic_face_movement_max_rotation_per_sec; + + if (max_rotation_per_sec > 0) { + m_rotation.Y = wrapDegrees_0_360(m_rotation.Y); + wrappedApproachShortest(m_rotation.Y, target_yaw, + dtime * max_rotation_per_sec, 360.f); + } else { + // Negative values of max_rotation_per_sec mean disabled. + m_rotation.Y = target_yaw; + } + } + } + + if(m_registered){ + m_env->getScriptIface()->luaentity_Step(m_id, dtime); + } + + if (!send_recommended) + return; + + if(!isAttached()) + { + // TODO: force send when acceleration changes enough? + float minchange = 0.2*BS; + if(m_last_sent_position_timer > 1.0){ + minchange = 0.01*BS; + } else if(m_last_sent_position_timer > 0.2){ + minchange = 0.05*BS; + } + float move_d = m_base_position.getDistanceFrom(m_last_sent_position); + move_d += m_last_sent_move_precision; + float vel_d = m_velocity.getDistanceFrom(m_last_sent_velocity); + if (move_d > minchange || vel_d > minchange || + std::fabs(m_rotation.X - m_last_sent_rotation.X) > 1.0f || + std::fabs(m_rotation.Y - m_last_sent_rotation.Y) > 1.0f || + std::fabs(m_rotation.Z - m_last_sent_rotation.Z) > 1.0f) { + + sendPosition(true, false); + } + } + + if (!m_armor_groups_sent) { + m_armor_groups_sent = true; + // create message and add to list + m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); + } + + if (!m_animation_sent) { + m_animation_sent = true; + std::string str = generateUpdateAnimationCommand(); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + } + + if (!m_animation_speed_sent) { + m_animation_speed_sent = true; + std::string str = generateUpdateAnimationSpeedCommand(); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + } + + if (!m_bone_position_sent) { + m_bone_position_sent = true; + for (std::unordered_map>::const_iterator + ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ + std::string str = generateUpdateBonePositionCommand((*ii).first, + (*ii).second.X, (*ii).second.Y); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + } + } + + if (!m_attachment_sent) { + m_attachment_sent = true; + std::string str = generateUpdateAttachmentCommand(); + // create message and add to list + ActiveObjectMessage aom(getId(), true, str); + m_messages_out.push(aom); + } +} + +std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) +{ + std::ostringstream os(std::ios::binary); + + // PROTOCOL_VERSION >= 37 + writeU8(os, 1); // version + os << serializeString(""); // name + writeU8(os, 0); // is_player + writeU16(os, getId()); //id + writeV3F32(os, m_base_position); + writeV3F32(os, m_rotation); + writeU16(os, m_hp); + + std::ostringstream msg_os(std::ios::binary); + msg_os << serializeLongString(getPropertyPacket()); // message 1 + msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 + msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 + for (std::unordered_map>::const_iterator + ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { + msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, + (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + } + msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 + int message_count = 4 + m_bone_position.size(); + for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); + (ii != m_attachment_child_ids.end()); ++ii) { + if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { + message_count++; + // TODO after a protocol bump: only send the object initialization data + // to older clients (superfluous since this message exists) + msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); + } + } + + msg_os << serializeLongString(generateSetTextureModCommand()); + message_count++; + + writeU8(os, message_count); + os.write(msg_os.str().c_str(), msg_os.str().size()); + + // return result + return os.str(); +} + +void LuaEntitySAO::getStaticData(std::string *result) const +{ + verbosestream<getScriptIface()-> + luaentity_GetStaticdata(m_id); + os<= 37 + + writeF1000(os, m_rotation.X); + writeF1000(os, m_rotation.Z); + + // + + *result = os.str(); +} + +u16 LuaEntitySAO::punch(v3f dir, + const ToolCapabilities *toolcap, + ServerActiveObject *puncher, + float time_from_last_punch) +{ + if (!m_registered) { + // Delete unknown LuaEntities when punched + m_pending_removal = true; + return 0; + } + + FATAL_ERROR_IF(!puncher, "Punch action called without SAO"); + + s32 old_hp = getHP(); + ItemStack selected_item, hand_item; + ItemStack tool_item = puncher->getWieldedItem(&selected_item, &hand_item); + + PunchDamageResult result = getPunchDamage( + m_armor_groups, + toolcap, + &tool_item, + time_from_last_punch); + + bool damage_handled = m_env->getScriptIface()->luaentity_Punch(m_id, puncher, + time_from_last_punch, toolcap, dir, result.did_punch ? result.damage : 0); + + if (!damage_handled) { + if (result.did_punch) { + setHP((s32)getHP() - result.damage, + PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); + + // create message and add to list + sendPunchCommand(); + } + } + + if (getHP() == 0 && !isGone()) { + clearParentAttachment(); + clearChildAttachments(); + m_env->getScriptIface()->luaentity_on_death(m_id, puncher); + m_pending_removal = true; + } + + actionstream << puncher->getDescription() << " (id=" << puncher->getId() << + ", hp=" << puncher->getHP() << ") punched " << + getDescription() << " (id=" << m_id << ", hp=" << m_hp << + "), damage=" << (old_hp - (s32)getHP()) << + (damage_handled ? " (handled by Lua)" : "") << std::endl; + + // TODO: give Lua control over wear + return result.wear; +} + +void LuaEntitySAO::rightClick(ServerActiveObject *clicker) +{ + if (!m_registered) + return; + + m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker); +} + +void LuaEntitySAO::setPos(const v3f &pos) +{ + if(isAttached()) + return; + m_base_position = pos; + sendPosition(false, true); +} + +void LuaEntitySAO::moveTo(v3f pos, bool continuous) +{ + if(isAttached()) + return; + m_base_position = pos; + if(!continuous) + sendPosition(true, true); +} + +float LuaEntitySAO::getMinimumSavedMovement() +{ + return 0.1 * BS; +} + +std::string LuaEntitySAO::getDescription() +{ + std::ostringstream oss; + oss << "LuaEntitySAO \"" << m_init_name << "\" "; + auto pos = floatToInt(m_base_position, BS); + oss << "at " << PP(pos); + return oss.str(); +} + +void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason) +{ + m_hp = rangelim(hp, 0, U16_MAX); +} + +u16 LuaEntitySAO::getHP() const +{ + return m_hp; +} + +void LuaEntitySAO::setVelocity(v3f velocity) +{ + m_velocity = velocity; +} + +v3f LuaEntitySAO::getVelocity() +{ + return m_velocity; +} + +void LuaEntitySAO::setAcceleration(v3f acceleration) +{ + m_acceleration = acceleration; +} + +v3f LuaEntitySAO::getAcceleration() +{ + return m_acceleration; +} + +void LuaEntitySAO::setTextureMod(const std::string &mod) +{ + m_current_texture_modifier = mod; + // create message and add to list + m_messages_out.emplace(getId(), true, generateSetTextureModCommand()); +} + +std::string LuaEntitySAO::getTextureMod() const +{ + return m_current_texture_modifier; +} + + +std::string LuaEntitySAO::generateSetTextureModCommand() const +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_TEXTURE_MOD); + // parameters + os << serializeString(m_current_texture_modifier); + return os.str(); +} + +std::string LuaEntitySAO::generateSetSpriteCommand(v2s16 p, u16 num_frames, + f32 framelength, bool select_horiz_by_yawpitch) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, AO_CMD_SET_SPRITE); + // parameters + writeV2S16(os, p); + writeU16(os, num_frames); + writeF32(os, framelength); + writeU8(os, select_horiz_by_yawpitch); + return os.str(); +} + +void LuaEntitySAO::setSprite(v2s16 p, int num_frames, float framelength, + bool select_horiz_by_yawpitch) +{ + std::string str = generateSetSpriteCommand( + p, + num_frames, + framelength, + select_horiz_by_yawpitch + ); + // create message and add to list + m_messages_out.emplace(getId(), true, str); +} + +std::string LuaEntitySAO::getName() +{ + return m_init_name; +} + +std::string LuaEntitySAO::getPropertyPacket() +{ + return generateSetPropertiesCommand(m_prop); +} + +void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) +{ + // If the object is attached client-side, don't waste bandwidth sending its position to clients + if(isAttached()) + return; + + m_last_sent_move_precision = m_base_position.getDistanceFrom( + m_last_sent_position); + m_last_sent_position_timer = 0; + m_last_sent_position = m_base_position; + m_last_sent_velocity = m_velocity; + //m_last_sent_acceleration = m_acceleration; + m_last_sent_rotation = m_rotation; + + float update_interval = m_env->getSendRecommendedInterval(); + + std::string str = generateUpdatePositionCommand( + m_base_position, + m_velocity, + m_acceleration, + m_rotation, + do_interpolate, + is_movement_end, + update_interval + ); + // create message and add to list + m_messages_out.emplace(getId(), false, str); +} + +bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const +{ + if (m_prop.physical) + { + //update collision box + toset->MinEdge = m_prop.collisionbox.MinEdge * BS; + toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS; + + toset->MinEdge += m_base_position; + toset->MaxEdge += m_base_position; + + return true; + } + + return false; +} + +bool LuaEntitySAO::getSelectionBox(aabb3f *toset) const +{ + if (!m_prop.is_visible || !m_prop.pointable) { + return false; + } + + toset->MinEdge = m_prop.selectionbox.MinEdge * BS; + toset->MaxEdge = m_prop.selectionbox.MaxEdge * BS; + + return true; +} + +bool LuaEntitySAO::collideWithObjects() const +{ + return m_prop.collideWithObjects; +} diff --git a/src/server/luaentity_sao.h b/src/server/luaentity_sao.h new file mode 100644 index 000000000..2520c8f5d --- /dev/null +++ b/src/server/luaentity_sao.h @@ -0,0 +1,93 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola +Copyright (C) 2013-2020 Minetest core developers & community + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "unit_sao.h" + +class LuaEntitySAO : public UnitSAO +{ +public: + LuaEntitySAO() = delete; + // Used by the environment to load SAO + LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data); + // Used by the Lua API + LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name, + const std::string &state) : + UnitSAO(env, pos), + m_init_name(name), m_init_state(state) + { + } + ~LuaEntitySAO(); + ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; } + ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; } + virtual void addedToEnvironment(u32 dtime_s); + void step(float dtime, bool send_recommended); + std::string getClientInitializationData(u16 protocol_version); + bool isStaticAllowed() const { return m_prop.static_save; } + void getStaticData(std::string *result) const; + u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr, + ServerActiveObject *puncher = nullptr, + float time_from_last_punch = 1000000.0f); + void rightClick(ServerActiveObject *clicker); + void setPos(const v3f &pos); + void moveTo(v3f pos, bool continuous); + float getMinimumSavedMovement(); + std::string getDescription(); + void setHP(s32 hp, const PlayerHPChangeReason &reason); + u16 getHP() const; + + /* LuaEntitySAO-specific */ + void setVelocity(v3f velocity); + void addVelocity(v3f velocity) { m_velocity += velocity; } + v3f getVelocity(); + void setAcceleration(v3f acceleration); + v3f getAcceleration(); + + void setTextureMod(const std::string &mod); + std::string getTextureMod() const; + void setSprite(v2s16 p, int num_frames, float framelength, + bool select_horiz_by_yawpitch); + std::string getName(); + bool getCollisionBox(aabb3f *toset) const; + bool getSelectionBox(aabb3f *toset) const; + bool collideWithObjects() const; + +private: + std::string getPropertyPacket(); + void sendPosition(bool do_interpolate, bool is_movement_end); + std::string generateSetTextureModCommand() const; + static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames, + f32 framelength, bool select_horiz_by_yawpitch); + + std::string m_init_name; + std::string m_init_state; + bool m_registered = false; + + v3f m_velocity; + v3f m_acceleration; + + v3f m_last_sent_position; + v3f m_last_sent_velocity; + v3f m_last_sent_rotation; + float m_last_sent_position_timer = 0.0f; + float m_last_sent_move_precision = 0.0f; + std::string m_current_texture_modifier = ""; +}; diff --git a/src/server/player_sao.h b/src/server/player_sao.h index ce1cb1677..8571bd4f9 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -1,4 +1,3 @@ - /* Minetest Copyright (C) 2010-2013 celeron55, Perttu Ahola @@ -19,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#pragma once + #include "constants.h" #include "network/networkprotocol.h" #include "unit_sao.h" @@ -32,33 +33,31 @@ class LagPool { float m_pool = 15.0f; float m_max = 15.0f; + public: LagPool() = default; void setMax(float new_max) { m_max = new_max; - if(m_pool > new_max) + if (m_pool > new_max) m_pool = new_max; } void add(float dtime) { m_pool -= dtime; - if(m_pool < 0) + if (m_pool < 0) m_pool = 0; } - void empty() - { - m_pool = m_max; - } + void empty() { m_pool = m_max; } bool grab(float dtime) { - if(dtime <= 0) + if (dtime <= 0) return true; - if(m_pool + dtime > m_max) + if (m_pool + dtime > m_max) return false; m_pool += dtime; return true; @@ -73,10 +72,8 @@ public: PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_, bool is_singleplayer); - ActiveObjectType getType() const - { return ACTIVEOBJECT_TYPE_PLAYER; } - ActiveObjectType getSendType() const - { return ACTIVEOBJECT_TYPE_GENERIC; } + ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_PLAYER; } + ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; } std::string getDescription(); /* @@ -111,10 +108,8 @@ public: Interaction interface */ - u16 punch(v3f dir, - const ToolCapabilities *toolcap, - ServerActiveObject *puncher, - float time_from_last_punch); + u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher, + float time_from_last_punch); void rightClick(ServerActiveObject *clicker) {} void setHP(s32 hp, const PlayerHPChangeReason &reason); void setHPRaw(u16 hp) { m_hp = hp; } @@ -144,10 +139,7 @@ public: // Cheat prevention - v3f getLastGoodPosition() const - { - return m_last_good_position; - } + v3f getLastGoodPosition() const { return m_last_good_position; } float resetTimeFromLastPunch() { float r = m_time_from_last_punch; @@ -159,30 +151,17 @@ public: m_nocheat_dig_pos = p; m_nocheat_dig_time = 0; } - v3s16 getNoCheatDigPos() - { - return m_nocheat_dig_pos; - } - float getNoCheatDigTime() - { - return m_nocheat_dig_time; - } - void noCheatDigEnd() - { - m_nocheat_dig_pos = v3s16(32767, 32767, 32767); - } - LagPool& getDigPool() - { - return m_dig_pool; - } + v3s16 getNoCheatDigPos() { return m_nocheat_dig_pos; } + float getNoCheatDigTime() { return m_nocheat_dig_time; } + void noCheatDigEnd() { m_nocheat_dig_pos = v3s16(32767, 32767, 32767); } + LagPool &getDigPool() { return m_dig_pool; } void setMaxSpeedOverride(const v3f &vel); // Returns true if cheated bool checkMovementCheat(); // Other - void updatePrivileges(const std::set &privs, - bool is_singleplayer) + void updatePrivileges(const std::set &privs, bool is_singleplayer) { m_privs = privs; m_is_singleplayer = is_singleplayer; @@ -236,6 +215,7 @@ private: s16 m_wanted_range = 0.0f; Metadata m_meta; + public: float m_physics_override_speed = 1.0f; float m_physics_override_jump = 1.0f; @@ -246,9 +226,10 @@ public: bool m_physics_override_sent = false; }; - -struct PlayerHPChangeReason { - enum Type : u8 { +struct PlayerHPChangeReason +{ + enum Type : u8 + { SET_HP, PLAYER_PUNCH, FALL, @@ -266,10 +247,7 @@ struct PlayerHPChangeReason { // For NODE_DAMAGE std::string node; - inline bool hasLuaReference() const - { - return lua_reference >= 0; - } + inline bool hasLuaReference() const { return lua_reference >= 0; } bool setTypeFromString(const std::string &typestr) { @@ -311,15 +289,12 @@ struct PlayerHPChangeReason { } } - PlayerHPChangeReason(Type type): - type(type) - {} + PlayerHPChangeReason(Type type) : type(type) {} - PlayerHPChangeReason(Type type, ServerActiveObject *object): + PlayerHPChangeReason(Type type, ServerActiveObject *object) : type(type), object(object) - {} + { + } - PlayerHPChangeReason(Type type, std::string node): - type(type), node(node) - {} + PlayerHPChangeReason(Type type, std::string node) : type(type), node(node) {} }; diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp index 3aa78c7d5..8345ebd47 100644 --- a/src/server/serveractiveobject.cpp +++ b/src/server/serveractiveobject.cpp @@ -30,39 +30,6 @@ ServerActiveObject::ServerActiveObject(ServerEnvironment *env, v3f pos): { } -ServerActiveObject* ServerActiveObject::create(ActiveObjectType type, - ServerEnvironment *env, u16 id, v3f pos, - const std::string &data) -{ - // Find factory function - std::map::iterator n; - n = m_types.find(type); - if(n == m_types.end()) { - // These are 0.3 entity types, return without error. - if (ACTIVEOBJECT_TYPE_ITEM <= type && type <= ACTIVEOBJECT_TYPE_MOBV2) { - return NULL; - } - - // If factory is not found, just return. - warningstream<<"ServerActiveObject: No factory for type=" - <second; - ServerActiveObject *object = (*f)(env, pos, data); - return object; -} - -void ServerActiveObject::registerType(u16 type, Factory f) -{ - std::map::iterator n; - n = m_types.find(type); - if(n != m_types.end()) - return; - m_types[type] = f; -} - float ServerActiveObject::getMinimumSavedMovement() { return 2.0*BS; diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 2e013a6b6..927009aef 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -244,12 +244,6 @@ protected: virtual void onAttach(int parent_id) {} virtual void onDetach(int parent_id) {} - // Used for creating objects based on type - typedef ServerActiveObject* (*Factory) - (ServerEnvironment *env, v3f pos, - const std::string &data); - static void registerType(u16 type, Factory f); - ServerEnvironment *m_env; v3f m_base_position; std::unordered_set m_attached_particle_spawners; @@ -258,8 +252,4 @@ protected: Queue of messages to be sent to the client */ std::queue m_messages_out; - -private: - // Used for creating objects based on type - static std::map m_types; }; diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index c2ab5c07d..32d10f8c0 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #if USE_POSTGRESQL #include "database/database-postgresql.h" #endif +#include "server/luaentity_sao.h" #include "server/player_sao.h" #define LBM_NAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_:" @@ -1778,6 +1779,18 @@ static void print_hexdump(std::ostream &o, const std::string &data) } } +ServerActiveObject* ServerEnvironment::createSAO(ActiveObjectType type, v3f pos, + const std::string &data) +{ + switch (type) { + case ACTIVEOBJECT_TYPE_LUAENTITY: + return new LuaEntitySAO(this, pos, data); + default: + warningstream << "ServerActiveObject: No factory for type=" << type << std::endl; + } + return nullptr; +} + /* Convert stored objects from blocks near the players to active. */ @@ -1811,10 +1824,10 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) std::vector new_stored; for (const StaticObject &s_obj : block->m_static_objects.m_stored) { // Create an active object from the data - ServerActiveObject *obj = ServerActiveObject::create - ((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data); + ServerActiveObject *obj = createSAO((ActiveObjectType) s_obj.type, s_obj.pos, + s_obj.data); // If couldn't create object, store static data back. - if(obj == NULL) { + if (!obj) { errorstream<<"ServerEnvironment::activateObjects(): " <<"failed to create active object from static object " <<"in block "< m_particle_spawners; std::unordered_map m_particle_spawner_attachments; + + ServerActiveObject* createSAO(ActiveObjectType type, v3f pos, const std::string &data); }; diff --git a/src/staticobject.cpp b/src/staticobject.cpp index bebca12ec..5ccb7baf5 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "staticobject.h" #include "util/serialize.h" -#include "content_sao.h" +#include "server/serveractiveobject.h" StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_): type(s_obj->getType()), diff --git a/src/unittest/test_player.cpp b/src/unittest/test_player.cpp index e2b1cd855..6990b4016 100644 --- a/src/unittest/test_player.cpp +++ b/src/unittest/test_player.cpp @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "exceptions.h" #include "remoteplayer.h" -#include "content_sao.h" #include "server.h" class TestPlayer : public TestBase diff --git a/util/travis/clang-format-whitelist.txt b/util/travis/clang-format-whitelist.txt index 816ec2c59..bb97da7b5 100644 --- a/util/travis/clang-format-whitelist.txt +++ b/util/travis/clang-format-whitelist.txt @@ -118,8 +118,6 @@ src/content_mapblock.h src/content_mapnode.cpp src/content_nodemeta.cpp src/content_nodemeta.h -src/content_sao.cpp -src/content_sao.h src/convert_json.cpp src/convert_json.h src/craftdef.cpp @@ -408,6 +406,8 @@ src/serverenvironment.h src/server.h src/serverlist.cpp src/serverlist.h +src/server/luaentity_sao.cpp +src/server/player_sao.cpp src/server/serveractiveobject.cpp src/server/serveractiveobject.h src/settings.cpp -- cgit v1.2.3 From 5cc06e4748a82acb36310fee89e72f30b2b35a36 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 11 Apr 2020 19:59:43 +0200 Subject: Reduce ServerEnvironment propagation (#9642) ServerEnvironment is a huge class with many accessors. In various places it's not needed Remove it to reduce the ServerEnvironment view. Idea here is to reduce size of some of our objects to transport lightweight managers and permit easier testing Pathfinder is now tied to a generic map, not a ServerMap, it can be ported to client --- src/mapgen/treegen.cpp | 4 +- src/mapgen/treegen.h | 5 +- src/pathfinder.cpp | 102 ++++++++++++++++--------------------- src/pathfinder.h | 17 ++++--- src/script/lua_api/l_env.cpp | 7 +-- src/script/lua_api/l_nodetimer.cpp | 44 +++------------- src/script/lua_api/l_nodetimer.h | 10 ++-- 7 files changed, 71 insertions(+), 118 deletions(-) (limited to 'src') diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index 89bdef73b..d538e15b4 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "map.h" #include "mapblock.h" -#include "serverenvironment.h" #include "nodedef.h" #include "treegen.h" #include "voxelalgorithms.h" @@ -120,10 +119,9 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree, // L-System tree LUA spawner -treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0, +treegen::error spawn_ltree(ServerMap *map, v3s16 p0, const NodeDefManager *ndef, const TreeDef &tree_definition) { - ServerMap *map = &env->getServerMap(); std::map modified_blocks; MMVManip vmanip(map); v3s16 tree_blockp = getNodeBlockPos(p0); diff --git a/src/mapgen/treegen.h b/src/mapgen/treegen.h index 5ab79f428..447baabb3 100644 --- a/src/mapgen/treegen.h +++ b/src/mapgen/treegen.h @@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class MMVManip; class NodeDefManager; -class ServerEnvironment; - +class ServerMap; namespace treegen { @@ -73,7 +72,7 @@ namespace treegen { treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, TreeDef tree_definition); // Spawn L-systems tree from LUA - treegen::error spawn_ltree (ServerEnvironment *env, v3s16 p0, + treegen::error spawn_ltree (ServerMap *map, v3s16 p0, const NodeDefManager *ndef, const TreeDef &tree_definition); // L-System tree gen helper functions diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index 8195bd643..3f0b98c10 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -23,8 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., /******************************************************************************/ #include "pathfinder.h" -#include "serverenvironment.h" -#include "server.h" +#include "map.h" #include "nodedef.h" //#define PATHFINDER_DEBUG @@ -180,10 +179,8 @@ private: class Pathfinder { public: - /** - * default constructor - */ - Pathfinder() = default; + Pathfinder() = delete; + Pathfinder(Map *map, const NodeDefManager *ndef) : m_map(map), m_ndef(ndef) {} ~Pathfinder(); @@ -197,8 +194,7 @@ public: * @param max_drop maximum number of blocks a path may drop * @param algo Algorithm to use for finding a path */ - std::vector getPath(ServerEnvironment *env, - v3s16 source, + std::vector getPath(v3s16 source, v3s16 destination, unsigned int searchdistance, unsigned int max_jump, @@ -328,7 +324,9 @@ private: friend class GridNodeContainer; GridNodeContainer *m_nodes_container = nullptr; - ServerEnvironment *m_env = 0; /**< minetest environment pointer */ + Map *m_map = nullptr; + + const NodeDefManager *m_ndef = nullptr; friend class PathfinderCompareHeuristic; @@ -410,18 +408,15 @@ class PathfinderCompareHeuristic /* implementation */ /******************************************************************************/ -std::vector get_path(ServerEnvironment* env, - v3s16 source, - v3s16 destination, - unsigned int searchdistance, - unsigned int max_jump, - unsigned int max_drop, - PathAlgorithm algo) +std::vector get_path(Map* map, const NodeDefManager *ndef, + v3s16 source, + v3s16 destination, + unsigned int searchdistance, + unsigned int max_jump, + unsigned int max_drop, + PathAlgorithm algo) { - Pathfinder searchclass; - - return searchclass.getPath(env, - source, destination, + return Pathfinder(map, ndef).getPath(source, destination, searchdistance, max_jump, max_drop, algo); } @@ -521,13 +516,13 @@ void PathGridnode::setCost(v3s16 dir, const PathCost &cost) void GridNodeContainer::initNode(v3s16 ipos, PathGridnode *p_node) { - const NodeDefManager *ndef = m_pathf->m_env->getGameDef()->ndef(); + const NodeDefManager *ndef = m_pathf->m_ndef; PathGridnode &elem = *p_node; v3s16 realpos = m_pathf->getRealPos(ipos); - MapNode current = m_pathf->m_env->getMap().getNode(realpos); - MapNode below = m_pathf->m_env->getMap().getNode(realpos + v3s16(0, -1, 0)); + MapNode current = m_pathf->m_map->getNode(realpos); + MapNode below = m_pathf->m_map->getNode(realpos + v3s16(0, -1, 0)); if ((current.param0 == CONTENT_IGNORE) || @@ -610,8 +605,7 @@ PathGridnode &MapGridNodeContainer::access(v3s16 p) /******************************************************************************/ -std::vector Pathfinder::getPath(ServerEnvironment *env, - v3s16 source, +std::vector Pathfinder::getPath(v3s16 source, v3s16 destination, unsigned int searchdistance, unsigned int max_jump, @@ -624,15 +618,8 @@ std::vector Pathfinder::getPath(ServerEnvironment *env, #endif std::vector retval; - //check parameters - if (env == 0) { - ERROR_TARGET << "Missing environment pointer" << std::endl; - return retval; - } - //initialization m_searchdistance = searchdistance; - m_env = env; m_maxjump = max_jump; m_maxdrop = max_drop; m_start = source; @@ -681,15 +668,14 @@ std::vector Pathfinder::getPath(ServerEnvironment *env, #endif //fail if source or destination is walkable - const NodeDefManager *ndef = m_env->getGameDef()->ndef(); - MapNode node_at_pos = m_env->getMap().getNode(destination); - if (ndef->get(node_at_pos).walkable) { + MapNode node_at_pos = m_map->getNode(destination); + if (m_ndef->get(node_at_pos).walkable) { VERBOSE_TARGET << "Destination is walkable. " << "Pos: " << PP(destination) << std::endl; return retval; } - node_at_pos = m_env->getMap().getNode(source); - if (ndef->get(node_at_pos).walkable) { + node_at_pos = m_map->getNode(source); + if (m_ndef->get(node_at_pos).walkable) { VERBOSE_TARGET << "Source is walkable. " << "Pos: " << PP(source) << std::endl; return retval; @@ -843,7 +829,6 @@ v3s16 Pathfinder::getRealPos(v3s16 ipos) /******************************************************************************/ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) { - const NodeDefManager *ndef = m_env->getGameDef()->ndef(); PathCost retval; retval.updated = true; @@ -857,7 +842,7 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) return retval; } - MapNode node_at_pos2 = m_env->getMap().getNode(pos2); + MapNode node_at_pos2 = m_map->getNode(pos2); //did we get information about node? if (node_at_pos2.param0 == CONTENT_IGNORE ) { @@ -866,9 +851,9 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) return retval; } - if (!ndef->get(node_at_pos2).walkable) { + if (!m_ndef->get(node_at_pos2).walkable) { MapNode node_below_pos2 = - m_env->getMap().getNode(pos2 + v3s16(0, -1, 0)); + m_map->getNode(pos2 + v3s16(0, -1, 0)); //did we get information about node? if (node_below_pos2.param0 == CONTENT_IGNORE ) { @@ -878,7 +863,7 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) } //test if the same-height neighbor is suitable - if (ndef->get(node_below_pos2).walkable) { + if (m_ndef->get(node_below_pos2).walkable) { //SUCCESS! retval.valid = true; retval.value = 1; @@ -889,19 +874,19 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) else { //test if we can fall a couple of nodes (m_maxdrop) v3s16 testpos = pos2 + v3s16(0, -1, 0); - MapNode node_at_pos = m_env->getMap().getNode(testpos); + MapNode node_at_pos = m_map->getNode(testpos); while ((node_at_pos.param0 != CONTENT_IGNORE) && - (!ndef->get(node_at_pos).walkable) && + (!m_ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y)) { testpos += v3s16(0, -1, 0); - node_at_pos = m_env->getMap().getNode(testpos); + node_at_pos = m_map->getNode(testpos); } //did we find surface? if ((testpos.Y >= m_limits.MinEdge.Y) && (node_at_pos.param0 != CONTENT_IGNORE) && - (ndef->get(node_at_pos).walkable)) { + (m_ndef->get(node_at_pos).walkable)) { if ((pos2.Y - testpos.Y - 1) <= m_maxdrop) { //SUCCESS! retval.valid = true; @@ -927,34 +912,34 @@ PathCost Pathfinder::calcCost(v3s16 pos, v3s16 dir) v3s16 targetpos = pos2; // position for jump target v3s16 jumppos = pos; // position for checking if jumping space is free - MapNode node_target = m_env->getMap().getNode(targetpos); - MapNode node_jump = m_env->getMap().getNode(jumppos); + MapNode node_target = m_map->getNode(targetpos); + MapNode node_jump = m_map->getNode(jumppos); bool headbanger = false; // true if anything blocks jumppath while ((node_target.param0 != CONTENT_IGNORE) && - (ndef->get(node_target).walkable) && + (m_ndef->get(node_target).walkable) && (targetpos.Y < m_limits.MaxEdge.Y)) { //if the jump would hit any solid node, discard if ((node_jump.param0 == CONTENT_IGNORE) || - (ndef->get(node_jump).walkable)) { + (m_ndef->get(node_jump).walkable)) { headbanger = true; break; } targetpos += v3s16(0, 1, 0); jumppos += v3s16(0, 1, 0); - node_target = m_env->getMap().getNode(targetpos); - node_jump = m_env->getMap().getNode(jumppos); + node_target = m_map->getNode(targetpos); + node_jump = m_map->getNode(jumppos); } //check headbanger one last time if ((node_jump.param0 == CONTENT_IGNORE) || - (ndef->get(node_jump).walkable)) { + (m_ndef->get(node_jump).walkable)) { headbanger = true; } //did we find surface without banging our head? if ((!headbanger) && (targetpos.Y <= m_limits.MaxEdge.Y) && - (!ndef->get(node_target).walkable)) { + (!m_ndef->get(node_target).walkable)) { if (targetpos.Y - pos2.Y <= m_maxjump) { //SUCCESS! @@ -1254,21 +1239,20 @@ v3s16 Pathfinder::walkDownwards(v3s16 pos, unsigned int max_down) { if (max_down == 0) return pos; v3s16 testpos = v3s16(pos); - MapNode node_at_pos = m_env->getMap().getNode(testpos); - const NodeDefManager *ndef = m_env->getGameDef()->ndef(); + MapNode node_at_pos = m_map->getNode(testpos); unsigned int down = 0; while ((node_at_pos.param0 != CONTENT_IGNORE) && - (!ndef->get(node_at_pos).walkable) && + (!m_ndef->get(node_at_pos).walkable) && (testpos.Y > m_limits.MinEdge.Y) && (down <= max_down)) { testpos += v3s16(0, -1, 0); down++; - node_at_pos = m_env->getMap().getNode(testpos); + node_at_pos = m_map->getNode(testpos); } //did we find surface? if ((testpos.Y >= m_limits.MinEdge.Y) && (node_at_pos.param0 != CONTENT_IGNORE) && - (ndef->get(node_at_pos).walkable)) { + (m_ndef->get(node_at_pos).walkable)) { if (down == 0) { pos = testpos; } else if ((down - 1) <= max_down) { diff --git a/src/pathfinder.h b/src/pathfinder.h index 70f3d6bbc..526aa0ee8 100644 --- a/src/pathfinder.h +++ b/src/pathfinder.h @@ -29,7 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc., /* Forward declarations */ /******************************************************************************/ -class ServerEnvironment; +class NodeDefManager; +class Map; /******************************************************************************/ /* Typedefs and macros */ @@ -54,10 +55,10 @@ typedef enum { /******************************************************************************/ /** c wrapper function to use from scriptapi */ -std::vector get_path(ServerEnvironment *env, - v3s16 source, - v3s16 destination, - unsigned int searchdistance, - unsigned int max_jump, - unsigned int max_drop, - PathAlgorithm algo); +std::vector get_path(Map *map, const NodeDefManager *ndef, + v3s16 source, + v3s16 destination, + unsigned int searchdistance, + unsigned int max_jump, + unsigned int max_drop, + PathAlgorithm algo); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 40e50e64a..e3afe1862 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -577,7 +577,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L) // Do it v3s16 p = read_v3s16(L, 1); - NodeTimerRef::create(L, p, env); + NodeTimerRef::create(L, p, &env->getServerMap()); return 1; } @@ -1193,7 +1193,7 @@ int ModApiEnvMod::l_find_path(lua_State *L) algo = PA_DIJKSTRA; } - std::vector path = get_path(env, pos1, pos2, + std::vector path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2, searchdistance, max_jump, max_drop, algo); if (!path.empty()) { @@ -1257,8 +1257,9 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L) else return 0; + ServerMap *map = &env->getServerMap(); treegen::error e; - if ((e = treegen::spawn_ltree (env, p0, ndef, tree_def)) != treegen::SUCCESS) { + if ((e = treegen::spawn_ltree (map, p0, ndef, tree_def)) != treegen::SUCCESS) { if (e == treegen::UNBALANCED_BRACKETS) { luaL_error(L, "spawn_tree(): closing ']' has no matching opening bracket"); } else { diff --git a/src/script/lua_api/l_nodetimer.cpp b/src/script/lua_api/l_nodetimer.cpp index 15a59744f..c2df52c05 100644 --- a/src/script/lua_api/l_nodetimer.cpp +++ b/src/script/lua_api/l_nodetimer.cpp @@ -41,11 +41,9 @@ int NodeTimerRef::l_set(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - ServerEnvironment *env = o->m_env; - if(env == NULL) return 0; f32 t = readParam(L,2); f32 e = readParam(L,3); - env->getMap().setNodeTimer(NodeTimer(t, e, o->m_p)); + o->m_map->setNodeTimer(NodeTimer(t, e, o->m_p)); return 0; } @@ -53,10 +51,8 @@ int NodeTimerRef::l_start(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - ServerEnvironment *env = o->m_env; - if(env == NULL) return 0; f32 t = readParam(L,2); - env->getMap().setNodeTimer(NodeTimer(t, 0, o->m_p)); + o->m_map->setNodeTimer(NodeTimer(t, 0, o->m_p)); return 0; } @@ -64,9 +60,7 @@ int NodeTimerRef::l_stop(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - ServerEnvironment *env = o->m_env; - if(env == NULL) return 0; - env->getMap().removeNodeTimer(o->m_p); + o->m_map->removeNodeTimer(o->m_p); return 0; } @@ -74,10 +68,7 @@ int NodeTimerRef::l_is_started(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - ServerEnvironment *env = o->m_env; - if(env == NULL) return 0; - - NodeTimer t = env->getMap().getNodeTimer(o->m_p); + NodeTimer t = o->m_map->getNodeTimer(o->m_p); lua_pushboolean(L,(t.timeout != 0)); return 1; } @@ -86,10 +77,7 @@ int NodeTimerRef::l_get_timeout(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - ServerEnvironment *env = o->m_env; - if(env == NULL) return 0; - - NodeTimer t = env->getMap().getNodeTimer(o->m_p); + NodeTimer t = o->m_map->getNodeTimer(o->m_p); lua_pushnumber(L,t.timeout); return 1; } @@ -98,37 +86,21 @@ int NodeTimerRef::l_get_elapsed(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - ServerEnvironment *env = o->m_env; - if(env == NULL) return 0; - - NodeTimer t = env->getMap().getNodeTimer(o->m_p); + NodeTimer t = o->m_map->getNodeTimer(o->m_p); lua_pushnumber(L,t.elapsed); return 1; } - -NodeTimerRef::NodeTimerRef(v3s16 p, ServerEnvironment *env): - m_p(p), - m_env(env) -{ -} - // Creates an NodeTimerRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. -void NodeTimerRef::create(lua_State *L, v3s16 p, ServerEnvironment *env) +void NodeTimerRef::create(lua_State *L, v3s16 p, ServerMap *map) { - NodeTimerRef *o = new NodeTimerRef(p, env); + NodeTimerRef *o = new NodeTimerRef(p, map); *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, className); lua_setmetatable(L, -2); } -void NodeTimerRef::set_null(lua_State *L) -{ - NodeTimerRef *o = checkobject(L, -1); - o->m_env = NULL; -} - void NodeTimerRef::Register(lua_State *L) { lua_newtable(L); diff --git a/src/script/lua_api/l_nodetimer.h b/src/script/lua_api/l_nodetimer.h index b894c5c8c..bbc975fd2 100644 --- a/src/script/lua_api/l_nodetimer.h +++ b/src/script/lua_api/l_nodetimer.h @@ -22,13 +22,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irr_v3d.h" #include "lua_api/l_base.h" -class ServerEnvironment; +class ServerMap; class NodeTimerRef : public ModApiBase { private: v3s16 m_p; - ServerEnvironment *m_env = nullptr; + ServerMap *m_map; static const char className[]; static const luaL_Reg methods[]; @@ -50,14 +50,12 @@ private: static int l_get_elapsed(lua_State *L); public: - NodeTimerRef(v3s16 p, ServerEnvironment *env); + NodeTimerRef(v3s16 p, ServerMap *map) : m_p(p), m_map(map) {} ~NodeTimerRef() = default; // Creates an NodeTimerRef and leaves it on top of stack // Not callable from Lua; all references are created on the C side. - static void create(lua_State *L, v3s16 p, ServerEnvironment *env); - - static void set_null(lua_State *L); + static void create(lua_State *L, v3s16 p, ServerMap *map); static void Register(lua_State *L); }; -- cgit v1.2.3 From 40df3931d882daaeee42c8de69882b9f9df5c312 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 11 Apr 2020 20:03:59 +0200 Subject: Implement DPI scaling for Windows (#9586) --- misc/minetest.exe.manifest | 4 +-- misc/winresource.rc | 6 ++++ src/CMakeLists.txt | 2 +- src/client/renderingengine.cpp | 77 ++++++++++++++++++++++++++++++++---------- src/constants.h | 5 --- 5 files changed, 69 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/misc/minetest.exe.manifest b/misc/minetest.exe.manifest index 3c32b0f8b..18f8c85f4 100644 --- a/misc/minetest.exe.manifest +++ b/misc/minetest.exe.manifest @@ -8,8 +8,8 @@ - - true + + true diff --git a/misc/winresource.rc b/misc/winresource.rc index e1e82581b..ffb493873 100644 --- a/misc/winresource.rc +++ b/misc/winresource.rc @@ -1,6 +1,8 @@ #include +#include #include #include + #ifndef USE_CMAKE_CONFIG_H #define USE_CMAKE_CONFIG_H #endif @@ -13,6 +15,10 @@ #define BUILDMODE "RUN_IN_PLACE=0" #endif +#ifdef __MINGW32__ +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "minetest.exe.manifest" +#endif + LANGUAGE 0, SUBLANG_NEUTRAL 130 ICON "minetest-icon.ico" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ebbd628c..0b550c09c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -451,7 +451,7 @@ if(WIN32) -i${WINRESOURCE_FILE} -o ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${WINRESOURCE_FILE}) + DEPENDS ${WINRESOURCE_FILE} ${MINETEST_EXE_MANIFEST_FILE}) SET(extra_windows_SRCS ${CMAKE_CURRENT_BINARY_DIR}/winresource_rc.o) else(MINGW) # Probably MSVC set(extra_windows_SRCS ${WINRESOURCE_FILE} ${MINETEST_EXE_MANIFEST_FILE}) diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 8b7bbf328..eae6ca7d3 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -45,7 +45,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#endif +#ifdef _WIN32 +#include +#include #endif #if ENABLE_GLES @@ -318,6 +322,28 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name) #endif } +#ifdef _WIN32 +static bool getWindowHandle(irr::video::IVideoDriver *driver, HWND &hWnd) +{ + const video::SExposedVideoData exposedData = driver->getExposedVideoData(); + + switch (driver->getDriverType()) { + case video::EDT_DIRECT3D8: + hWnd = reinterpret_cast(exposedData.D3D8.HWnd); + break; + case video::EDT_DIRECT3D9: + hWnd = reinterpret_cast(exposedData.D3D9.HWnd); + break; + case video::EDT_OPENGL: + hWnd = reinterpret_cast(exposedData.OpenGLWin32.HWnd); + break; + default: + return false; + } + + return true; +} +#endif bool RenderingEngine::setWindowIcon() { @@ -335,22 +361,9 @@ bool RenderingEngine::setWindowIcon() "-xorg-icon-128.png"); #endif #elif defined(_WIN32) - const video::SExposedVideoData exposedData = driver->getExposedVideoData(); HWND hWnd; // Window handle - - switch (driver->getDriverType()) { - case video::EDT_DIRECT3D8: - hWnd = reinterpret_cast(exposedData.D3D8.HWnd); - break; - case video::EDT_DIRECT3D9: - hWnd = reinterpret_cast(exposedData.D3D9.HWnd); - break; - case video::EDT_OPENGL: - hWnd = reinterpret_cast(exposedData.OpenGLWin32.HWnd); - break; - default: + if (!getWindowHandle(driver, hWnd)) return false; - } // Load the ICON from resource file const HICON hicon = LoadIcon(GetModuleHandle(NULL), @@ -632,7 +645,7 @@ const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYP } #ifndef __ANDROID__ -#ifdef XORG_USED +#if defined(XORG_USED) static float calcDisplayDensity() { @@ -667,12 +680,42 @@ float RenderingEngine::getDisplayDensity() return cached_display_density; } -#else // XORG_USED +#elif defined(_WIN32) + + +static float calcDisplayDensity(irr::video::IVideoDriver *driver) +{ + HWND hWnd; + if (getWindowHandle(driver, hWnd)) { + HDC hdc = GetDC(hWnd); + float dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(hWnd, hdc); + return dpi / 96.0f; + } + + /* return manually specified dpi */ + return g_settings->getFloat("screen_dpi") / 96.0f; +} + +float RenderingEngine::getDisplayDensity() +{ + static bool cached = false; + static float display_density; + if (!cached) { + display_density = calcDisplayDensity(get_video_driver()); + cached = true; + } + return display_density; +} + +#else + float RenderingEngine::getDisplayDensity() { return g_settings->getFloat("screen_dpi") / 96.0; } -#endif // XORG_USED + +#endif v2u32 RenderingEngine::getDisplaySize() { diff --git a/src/constants.h b/src/constants.h index 7636b38e0..0a8b22e15 100644 --- a/src/constants.h +++ b/src/constants.h @@ -110,10 +110,5 @@ with this program; if not, write to the Free Software Foundation, Inc., GUI related things */ -// TODO: implement dpi-based scaling for windows and remove this hack -#if defined(_WIN32) -#define TTF_DEFAULT_FONT_SIZE (18) -#else #define TTF_DEFAULT_FONT_SIZE (16) -#endif #define DEFAULT_FONT_SIZE (10) -- cgit v1.2.3 From ba3587e7769113fed9a076ae2e4d2153686fb163 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 11 Apr 2020 21:29:57 +0200 Subject: Fix broken config check in 659245a --- src/script/common/c_internal.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h index 747400769..442546332 100644 --- a/src/script/common/c_internal.h +++ b/src/script/common/c_internal.h @@ -31,6 +31,7 @@ extern "C" { #include } +#include "config.h" #include "common/c_types.h" -- cgit v1.2.3 From f780bae05cc2fdd23a6d7326c770783da8d94ea3 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Sat, 11 Apr 2020 16:39:30 -0400 Subject: Formspecs: Add state-selection to style elements (#9378) --- doc/lua_api.txt | 61 +++++++++--- games/minimal/mods/test/formspec.lua | 5 +- src/client/game.cpp | 9 +- src/gui/StyleSpec.h | 65 ++++++++++-- src/gui/guiButton.cpp | 163 +++++++++++++++--------------- src/gui/guiButton.h | 34 ++++--- src/gui/guiButtonImage.cpp | 102 ++++--------------- src/gui/guiButtonImage.h | 26 ++--- src/gui/guiButtonItemImage.cpp | 15 +-- src/gui/guiButtonItemImage.h | 9 +- src/gui/guiConfirmRegistration.cpp | 8 +- src/gui/guiConfirmRegistration.h | 4 +- src/gui/guiFormSpecMenu.cpp | 187 ++++++++++++++++++++++++----------- src/gui/guiFormSpecMenu.h | 8 +- src/gui/guiKeyChangeMenu.cpp | 12 ++- src/gui/guiKeyChangeMenu.h | 5 +- src/gui/guiPasswordChange.cpp | 10 +- src/gui/guiPasswordChange.h | 5 +- src/gui/guiVolumeChange.cpp | 7 +- src/gui/guiVolumeChange.h | 7 +- src/script/lua_api/l_mainmenu.cpp | 19 ++-- src/util/numeric.h | 10 ++ 22 files changed, 454 insertions(+), 317 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 6ba87d619..b083b2907 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2188,12 +2188,12 @@ Elements * 9-sliced background. See https://en.wikipedia.org/wiki/9-slice_scaling * Middle is a rect which defines the middle of the 9-slice. - * `x` - The middle will be x pixels from all sides. - * `x,y` - The middle will be x pixels from the horizontal and y from the vertical. - * `x,y,x2,y2` - The middle will start at x,y, and end at x2, y2. Negative x2 and y2 values - will be added to the width and height of the texture, allowing it to be used as the - distance from the far end. - * All numbers in middle are integers. + * `x` - The middle will be x pixels from all sides. + * `x,y` - The middle will be x pixels from the horizontal and y from the vertical. + * `x,y,x2,y2` - The middle will start at x,y, and end at x2, y2. Negative x2 and y2 values + will be added to the width and height of the texture, allowing it to be used as the + distance from the far end. + * All numbers in middle are integers. * Example for formspec 8x4 in 16x resolution: image shall be sized 8 times 16px times 4 times 16px * If `auto_clip` is `true`, the background is clipped to the formspec size @@ -2508,16 +2508,28 @@ Elements * `span=`: number of following columns to affect (default: infinite). -### `style[,,...;;;...]` +### `style[,;;;...]` -* Set the style for the named element(s) `name`. +* Set the style for the element(s) matching `selector` by name. +* `selector` can be one of: + * `` - An element name. + * `:` - An element name, a colon, and one or more states. +* `state` is a list of states separated by the `+` character. + * If a state is provided, the style will only take effect when the element is in that state. + * All provided states must be active for the style to apply. * Note: this **must** be before the element is defined. * See [Styling Formspecs]. -### `style_type[,,...;;;...]` +### `style_type[,;;;...]` -* Sets the style for all elements of type(s) `type` which appear after this element. +* Set the style for the element(s) matching `selector` by type. +* `selector` can be one of: + * `` - An element type. + * `:` - An element type, a colon, and one or more states. +* `state` is a list of states separated by the `+` character. + * If a state is provided, the style will only take effect when the element is in that state. + * All provided states must be active for the style to apply. * See [Styling Formspecs]. Migrating to Real Coordinates @@ -2560,23 +2572,32 @@ Styling Formspecs Formspec elements can be themed using the style elements: - style[,,...;;;...] - style_type[,,...;;;...] + style[,;;;...] + style[:,:;;;...] + style_type[,;;;...] + style_type[:,:;;;...] Where a prop is: property_name=property_value +For example: + + style_type[button;bgcolor=#006699] + style[world_delete;bgcolor=red;textcolor=yellow] + button[4,3.95;2.6,1;world_delete;Delete] + A name/type can optionally be a comma separated list of names/types, like so: world_delete,world_create,world_configure button,image_button -For example: +Any name/type in the list can also be accompanied by a `+`-separated list of states, like so: - style_type[button;bgcolor=#006699] - style[world_delete;bgcolor=red;textcolor=yellow] - button[4,3.95;2.6,1;world_delete;Delete] + world_delete:hovered+pressed + button:pressed + +States allow you to apply styles in response to changes in the element, instead of applying at all times. Setting a property to nothing will reset it to the default value. For example: @@ -2654,6 +2675,14 @@ Some types may inherit styles from parent types. * noclip - boolean, set to true to allow the element to exceed formspec bounds. * textcolor - color. Default white. +### Valid States + +* *all elements* + * default - Equivalent to providing no states +* button, button_exit, image_button, item_image_button + * hovered - Active when the mouse is hovering over the element + * pressed - Active when the button is pressed + Markup Language --------------- diff --git a/games/minimal/mods/test/formspec.lua b/games/minimal/mods/test/formspec.lua index d2123b4af..14886aad2 100644 --- a/games/minimal/mods/test/formspec.lua +++ b/games/minimal/mods/test/formspec.lua @@ -65,7 +65,10 @@ local style_fs = [[ style[one_btn13;border=false] item_image_button[1.25,8.35;1,1;default:sword_steel;one_btn13;NoBor] - style[one_btn14;border=false;bgimg=test_bg.png;bgimg_hovered=test_bg_hovered.png;bgimg_pressed=test_bg_pressed.png;fgimg=bubble.png;fgimg_hovered=default_apple.png;fgimg_pressed=heart.png] + style[one_btn14;border=false;bgimg=test_bg.png;fgimg=bubble.png] + style[one_btn14:hovered;bgimg=test_bg_hovered.png;fgimg=default_apple.png;textcolor=red] + style[one_btn14:pressed;bgimg=test_bg_pressed.png;fgimg=heart.png;textcolor=green] + style[one_btn14:hovered+pressed;textcolor=blue] image_button[0,9.6;1,1;bubble.png;one_btn14;Bg] style[one_btn15;border=false;bgimg=test_bg.png;bgimg_hovered=test_bg_hovered.png;bgimg_pressed=test_bg_pressed.png] diff --git a/src/client/game.cpp b/src/client/game.cpp index 505108caf..06e76d170 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1556,7 +1556,8 @@ bool Game::connectToServer(const std::string &playername, } else { registration_confirmation_shown = true; (new GUIConfirmRegistration(guienv, guienv->getRootGUIElement(), -1, - &g_menumgr, client, playername, password, connection_aborted))->drop(); + &g_menumgr, client, playername, password, + connection_aborted, texture_src))->drop(); } } else { wait_time += dtime; @@ -1711,19 +1712,19 @@ inline bool Game::handleCallbacks() if (g_gamecallback->changepassword_requested) { (new GUIPasswordChange(guienv, guiroot, -1, - &g_menumgr, client))->drop(); + &g_menumgr, client, texture_src))->drop(); g_gamecallback->changepassword_requested = false; } if (g_gamecallback->changevolume_requested) { (new GUIVolumeChange(guienv, guiroot, -1, - &g_menumgr))->drop(); + &g_menumgr, texture_src))->drop(); g_gamecallback->changevolume_requested = false; } if (g_gamecallback->keyconfig_requested) { (new GUIKeyChangeMenu(guienv, guiroot, -1, - &g_menumgr))->drop(); + &g_menumgr, texture_src))->drop(); g_gamecallback->keyconfig_requested = false; } diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h index 999c1d237..799fbf46d 100644 --- a/src/gui/StyleSpec.h +++ b/src/gui/StyleSpec.h @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "client/tile.h" // ITextureSource +#include "debug.h" #include "irrlichttypes_extrabloated.h" #include "util/string.h" #include @@ -31,25 +32,34 @@ public: { TEXTCOLOR, BGCOLOR, - BGCOLOR_HOVERED, - BGCOLOR_PRESSED, + BGCOLOR_HOVERED, // Note: Deprecated property + BGCOLOR_PRESSED, // Note: Deprecated property NOCLIP, BORDER, BGIMG, - BGIMG_HOVERED, + BGIMG_HOVERED, // Note: Deprecated property BGIMG_MIDDLE, - BGIMG_PRESSED, + BGIMG_PRESSED, // Note: Deprecated property FGIMG, - FGIMG_HOVERED, - FGIMG_PRESSED, + FGIMG_HOVERED, // Note: Deprecated property + FGIMG_PRESSED, // Note: Deprecated property ALPHA, NUM_PROPERTIES, NONE }; + enum State + { + STATE_DEFAULT = 0, + STATE_HOVERED = 1 << 0, + STATE_PRESSED = 1 << 1, + NUM_STATES = 1 << 2, + STATE_INVALID = 1 << 3, + }; private: std::array property_set{}; std::array properties; + State state_map = STATE_DEFAULT; public: static Property GetPropertyByName(const std::string &name) @@ -99,6 +109,49 @@ public: property_set[prop] = true; } + //! Parses a name and returns the corresponding state enum + static State getStateByName(const std::string &name) + { + if (name == "default") { + return STATE_DEFAULT; + } else if (name == "hovered") { + return STATE_HOVERED; + } else if (name == "pressed") { + return STATE_PRESSED; + } else { + return STATE_INVALID; + } + } + + //! Gets the state that this style is intended for + State getState() const + { + return state_map; + } + + //! Set the given state on this style + void addState(State state) + { + FATAL_ERROR_IF(state >= NUM_STATES, "Out-of-bounds state received"); + + state_map = static_cast(state_map | state); + } + + //! Using a list of styles mapped to state values, calculate the final + // combined style for a state by propagating values in its component states + static StyleSpec getStyleFromStatePropagation(const std::array &styles, State state) + { + StyleSpec temp = styles[StyleSpec::STATE_DEFAULT]; + temp.state_map = state; + for (int i = StyleSpec::STATE_DEFAULT + 1; i <= state; i++) { + if ((state & i) != 0) { + temp = temp | styles[i]; + } + } + + return temp; + } + video::SColor getColor(Property prop, video::SColor def) const { const auto &val = properties[prop]; diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index 4c16ee237..9dfe36bc4 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -14,6 +14,7 @@ #include "irrlicht_changes/static_text.h" #include "porting.h" #include "StyleSpec.h" +#include "util/numeric.h" using namespace irr; using namespace gui; @@ -26,14 +27,15 @@ using namespace gui; //! constructor GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent, - s32 id, core::rect rectangle, bool noclip) + s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, + bool noclip) : IGUIButton(environment, parent, id, rectangle), SpriteBank(0), OverrideFont(0), OverrideColorEnabled(false), OverrideColor(video::SColor(101,255,255,255)), ClickTime(0), HoverTime(0), FocusTime(0), ClickShiftState(false), ClickControlState(false), IsPushButton(false), Pressed(false), - UseAlphaChannel(false), DrawBorder(true), ScaleImage(false) + UseAlphaChannel(false), DrawBorder(true), ScaleImage(false), TSrc(tsrc) { setNotClipped(noclip); @@ -44,14 +46,6 @@ GUIButton::GUIButton(IGUIEnvironment* environment, IGUIElement* parent, // PATCH for (size_t i = 0; i < 4; i++) { Colors[i] = Environment->getSkin()->getColor((EGUI_DEFAULT_COLOR)i); - HoveredColors[i] = irr::video::SColor(Colors[i].getAlpha(), - core::clamp(Colors[i].getRed() * COLOR_HOVERED_MOD, 0, 255), - core::clamp(Colors[i].getGreen() * COLOR_HOVERED_MOD, 0, 255), - core::clamp(Colors[i].getBlue() * COLOR_HOVERED_MOD, 0, 255)); - PressedColors[i] = irr::video::SColor(Colors[i].getAlpha(), - core::clamp(Colors[i].getRed() * COLOR_PRESSED_MOD, 0, 255), - core::clamp(Colors[i].getGreen() * COLOR_PRESSED_MOD, 0, 255), - core::clamp(Colors[i].getBlue() * COLOR_PRESSED_MOD, 0, 255)); } StaticText = gui::StaticText::add(Environment, Text.c_str(), core::rect(0,0,rectangle.getWidth(),rectangle.getHeight()), false, false, this, id); StaticText->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); @@ -262,6 +256,13 @@ void GUIButton::draw() return; // PATCH + // Track hovered state, if it has changed then we need to update the style. + bool hovered = isHovered(); + if (hovered != WasHovered) { + WasHovered = hovered; + setFromState(); + } + GUISkin* skin = dynamic_cast(Environment->getSkin()); video::IVideoDriver* driver = Environment->getVideoDriver(); // END PATCH @@ -271,21 +272,24 @@ void GUIButton::draw() if (!Pressed) { // PATCH - skin->drawColored3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect, - isHovered() ? HoveredColors : Colors); + skin->drawColored3DButtonPaneStandard(this, AbsoluteRect, + &AbsoluteClippingRect, Colors); // END PATCH } else { // PATCH - skin->drawColored3DButtonPanePressed(this, - AbsoluteRect, &AbsoluteClippingRect, PressedColors); + skin->drawColored3DButtonPanePressed(this, AbsoluteRect, + &AbsoluteClippingRect, Colors); // END PATCH } } const core::position2di buttonCenter(AbsoluteRect.getCenter()); - EGUI_BUTTON_IMAGE_STATE imageState = getImageState(Pressed); + // PATCH + // The image changes based on the state, so we use the default every time. + EGUI_BUTTON_IMAGE_STATE imageState = EGBIS_IMAGE_UP; + // END PATCH if ( ButtonImages[(u32)imageState].Texture ) { core::position2d pos(buttonCenter); @@ -548,18 +552,6 @@ void GUIButton::setPressedImage(video::ITexture* image, const core::rect& p setImage(gui::EGBIS_IMAGE_DOWN, image, pos); } -void GUIButton::setHoveredImage(video::ITexture* image) -{ - setImage(gui::EGBIS_IMAGE_UP_MOUSEOVER, image); - setImage(gui::EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER, image); -} - -void GUIButton::setHoveredImage(video::ITexture* image, const core::rect& pos) -{ - setImage(gui::EGBIS_IMAGE_UP_MOUSEOVER, image, pos); - setImage(gui::EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER, image, pos); -} - //! Sets the text displayed by the button void GUIButton::setText(const wchar_t* text) { @@ -618,6 +610,8 @@ void GUIButton::setPressed(bool pressed) skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y))); } } + + setFromState(); } } @@ -729,10 +723,12 @@ void GUIButton::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri } // PATCH -GUIButton* GUIButton::addButton(IGUIEnvironment *environment, const core::rect& rectangle, - IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext) +GUIButton* GUIButton::addButton(IGUIEnvironment *environment, + const core::rect& rectangle, ISimpleTextureSource *tsrc, + IGUIElement* parent, s32 id, const wchar_t* text, + const wchar_t *tooltiptext) { - GUIButton* button = new GUIButton(environment, parent ? parent : environment->getRootGUIElement(), id, rectangle); + GUIButton* button = new GUIButton(environment, parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc); if (text) button->setText(text); @@ -749,76 +745,87 @@ void GUIButton::setColor(video::SColor color) for (size_t i = 0; i < 4; i++) { video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); Colors[i] = base.getInterpolated(color, d); - HoveredColors[i] = irr::video::SColor(Colors[i].getAlpha(), - core::clamp(Colors[i].getRed() * COLOR_HOVERED_MOD, 0, 255), - core::clamp(Colors[i].getGreen() * COLOR_HOVERED_MOD, 0, 255), - core::clamp(Colors[i].getBlue() * COLOR_HOVERED_MOD, 0, 255)); - PressedColors[i] = irr::video::SColor(Colors[i].getAlpha(), - core::clamp(Colors[i].getRed() * COLOR_PRESSED_MOD, 0, 255), - core::clamp(Colors[i].getGreen() * COLOR_PRESSED_MOD, 0, 255), - core::clamp(Colors[i].getBlue() * COLOR_PRESSED_MOD, 0, 255)); } } -void GUIButton::setHoveredColor(video::SColor color) -{ - float d = 0.65f; - for (size_t i = 0; i < 4; i++) { - video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); - HoveredColors[i] = base.getInterpolated(color, d); - } -} -void GUIButton::setPressedColor(video::SColor color) + +//! Set element properties from a StyleSpec corresponding to the button state +void GUIButton::setFromState() { - float d = 0.65f; - for (size_t i = 0; i < 4; i++) { - video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); - PressedColors[i] = base.getInterpolated(color, d); - } + StyleSpec::State state = StyleSpec::STATE_DEFAULT; + + if (isPressed()) + state = static_cast(state | StyleSpec::STATE_PRESSED); + + if (isHovered()) + state = static_cast(state | StyleSpec::STATE_HOVERED); + + setFromStyle(StyleSpec::getStyleFromStatePropagation(Styles, state)); } //! Set element properties from a StyleSpec -void GUIButton::setFromStyle(const StyleSpec& style, ISimpleTextureSource *tsrc) +void GUIButton::setFromStyle(const StyleSpec& style) { + bool hovered = (style.getState() & StyleSpec::STATE_HOVERED) != 0; + bool pressed = (style.getState() & StyleSpec::STATE_PRESSED) != 0; + if (style.isNotDefault(StyleSpec::BGCOLOR)) { + setColor(style.getColor(StyleSpec::BGCOLOR)); - } - if (style.isNotDefault(StyleSpec::BGCOLOR_HOVERED)) { - setHoveredColor(style.getColor(StyleSpec::BGCOLOR_HOVERED)); - } - if (style.isNotDefault(StyleSpec::BGCOLOR_PRESSED)) { - setPressedColor(style.getColor(StyleSpec::BGCOLOR_PRESSED)); + + // If we have a propagated hover/press color, we need to automatically + // lighten/darken it + if (!Styles[style.getState()].isNotDefault(StyleSpec::BGCOLOR)) { + for (size_t i = 0; i < 4; i++) { + if (pressed) { + Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD); + } else if (hovered) { + Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD); + } + } + } + + } else { + for (size_t i = 0; i < 4; i++) { + video::SColor base = + Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); + if (pressed) { + Colors[i] = multiplyColorValue(base, COLOR_PRESSED_MOD); + } else if (hovered) { + Colors[i] = multiplyColorValue(base, COLOR_HOVERED_MOD); + } else { + Colors[i] = base; + } + } } if (style.isNotDefault(StyleSpec::TEXTCOLOR)) { setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR)); + } else { + setOverrideColor(video::SColor(255,255,255,255)); + OverrideColorEnabled = false; } - setNotClipped(style.getBool(StyleSpec::NOCLIP, isNotClipped())); - setDrawBorder(style.getBool(StyleSpec::BORDER, DrawBorder)); + setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); + setDrawBorder(style.getBool(StyleSpec::BORDER, true)); setUseAlphaChannel(style.getBool(StyleSpec::ALPHA, true)); const core::position2di buttonCenter(AbsoluteRect.getCenter()); core::position2d geom(buttonCenter); if (style.isNotDefault(StyleSpec::BGIMG)) { - video::ITexture *texture = style.getTexture(StyleSpec::BGIMG, tsrc); - + video::ITexture *texture = style.getTexture(StyleSpec::BGIMG, + getTextureSource()); setImage(guiScalingImageButton( - Environment->getVideoDriver(), texture, geom.X, geom.Y)); - setScaleImage(true); - } - if (style.isNotDefault(StyleSpec::BGIMG_HOVERED)) { - video::ITexture *hovered_texture = style.getTexture(StyleSpec::BGIMG_HOVERED, tsrc); - - setHoveredImage(guiScalingImageButton( - Environment->getVideoDriver(), hovered_texture, geom.X, geom.Y)); - setScaleImage(true); - } - if (style.isNotDefault(StyleSpec::BGIMG_PRESSED)) { - video::ITexture *pressed_texture = style.getTexture(StyleSpec::BGIMG_PRESSED, tsrc); - - setPressedImage(guiScalingImageButton( - Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y)); + Environment->getVideoDriver(), texture, geom.X, geom.Y)); setScaleImage(true); + } else { + setImage(nullptr); } BgMiddle = style.getRect(StyleSpec::BGIMG_MIDDLE, BgMiddle); } + +//! Set the styles used for each state +void GUIButton::setStyles(const std::array& styles) +{ + Styles = styles; + setFromState(); +} // END PATCH diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h index 3d1f98c32..ef10f926e 100644 --- a/src/gui/guiButton.h +++ b/src/gui/guiButton.h @@ -13,6 +13,7 @@ #include "ITexture.h" #include "SColor.h" #include "guiSkin.h" +#include "StyleSpec.h" using namespace irr; @@ -67,7 +68,6 @@ using namespace irr; #endif class ISimpleTextureSource; -class StyleSpec; class GUIButton : public gui::IGUIButton { @@ -75,7 +75,8 @@ public: //! constructor GUIButton(gui::IGUIEnvironment* environment, gui::IGUIElement* parent, - s32 id, core::rect rectangle, bool noclip=false); + s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, + bool noclip=false); //! destructor virtual ~GUIButton(); @@ -125,16 +126,10 @@ public: //! Sets an image which should be displayed on the button when it is in pressed state. virtual void setPressedImage(video::ITexture* image, const core::rect& pos) override; - //! Sets an image which should be displayed on the button when it is in hovered state. - virtual void setHoveredImage(video::ITexture* image=nullptr); - //! Sets the text displayed by the button virtual void setText(const wchar_t* text) override; // END PATCH - //! Sets an image which should be displayed on the button when it is in hovered state. - virtual void setHoveredImage(video::ITexture* image, const core::rect& pos); - //! Sets the sprite bank used by the button virtual void setSpriteBank(gui::IGUISpriteBank* bank=0) override; @@ -225,22 +220,29 @@ public: void setColor(video::SColor color); // PATCH - void setHoveredColor(video::SColor color); - void setPressedColor(video::SColor color); + //! Set element properties from a StyleSpec corresponding to the button state + void setFromState(); //! Set element properties from a StyleSpec - virtual void setFromStyle(const StyleSpec& style, ISimpleTextureSource *tsrc); + virtual void setFromStyle(const StyleSpec& style); + + //! Set the styles used for each state + void setStyles(const std::array& styles); // END PATCH //! Do not drop returned handle - static GUIButton* addButton(gui::IGUIEnvironment *environment, const core::rect& rectangle, - IGUIElement* parent, s32 id, const wchar_t* text, const wchar_t *tooltiptext=L""); + static GUIButton* addButton(gui::IGUIEnvironment *environment, + const core::rect& rectangle, ISimpleTextureSource *tsrc, + IGUIElement* parent, s32 id, const wchar_t* text, + const wchar_t *tooltiptext=L""); protected: void drawSprite(gui::EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center); gui::EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const; + ISimpleTextureSource *getTextureSource() { return TSrc; } + struct ButtonImage { ButtonImage() : Texture(0), SourceRect(core::rect(0,0,0,0)) @@ -308,6 +310,8 @@ private: ButtonImage ButtonImages[gui::EGBIS_COUNT]; + std::array Styles; + gui::IGUIFont* OverrideFont; bool OverrideColorEnabled; @@ -326,8 +330,8 @@ private: video::SColor Colors[4]; // PATCH - video::SColor HoveredColors[4]; - video::SColor PressedColors[4]; + bool WasHovered = false; + ISimpleTextureSource *TSrc; gui::IGUIStaticText *StaticText; diff --git a/src/gui/guiButtonImage.cpp b/src/gui/guiButtonImage.cpp index 02d920277..2658ad967 100644 --- a/src/gui/guiButtonImage.cpp +++ b/src/gui/guiButtonImage.cpp @@ -30,8 +30,9 @@ using namespace irr; using namespace gui; GUIButtonImage::GUIButtonImage(gui::IGUIEnvironment *environment, - gui::IGUIElement *parent, s32 id, core::rect rectangle, bool noclip) - : GUIButton (environment, parent, id, rectangle, noclip) + gui::IGUIElement *parent, s32 id, core::rect rectangle, + ISimpleTextureSource *tsrc, bool noclip) + : GUIButton (environment, parent, id, rectangle, tsrc, noclip) { m_image = Environment->addImage( core::rect(0,0,rectangle.getWidth(),rectangle.getHeight()), this); @@ -39,100 +40,38 @@ GUIButtonImage::GUIButtonImage(gui::IGUIEnvironment *environment, sendToBack(m_image); } -bool GUIButtonImage::OnEvent(const SEvent& event) -{ - bool result = GUIButton::OnEvent(event); - - EGUI_BUTTON_IMAGE_STATE imageState = getImageState(isPressed(), m_foreground_images); - video::ITexture *texture = m_foreground_images[(u32)imageState].Texture; - if (texture != nullptr) - { - m_image->setImage(texture); - } - - m_image->setVisible(texture != nullptr); - - return result; -} - -void GUIButtonImage::setForegroundImage(EGUI_BUTTON_IMAGE_STATE state, - video::ITexture *image, const core::rect &sourceRect) +void GUIButtonImage::setForegroundImage(video::ITexture *image) { - if (state >= EGBIS_COUNT) + if (image == m_foreground_image) return; - if (image) + if (image != nullptr) image->grab(); - u32 stateIdx = (u32)state; - if (m_foreground_images[stateIdx].Texture) - m_foreground_images[stateIdx].Texture->drop(); - - m_foreground_images[stateIdx].Texture = image; - m_foreground_images[stateIdx].SourceRect = sourceRect; - - EGUI_BUTTON_IMAGE_STATE imageState = getImageState(isPressed(), m_foreground_images); - if (imageState == stateIdx) - m_image->setImage(image); -} - -void GUIButtonImage::setForegroundImage(video::ITexture *image) -{ - setForegroundImage(gui::EGBIS_IMAGE_UP, image); -} - -void GUIButtonImage::setForegroundImage(video::ITexture *image, const core::rect &pos) -{ - setForegroundImage(gui::EGBIS_IMAGE_UP, image, pos); -} - -void GUIButtonImage::setPressedForegroundImage(video::ITexture *image) -{ - setForegroundImage(gui::EGBIS_IMAGE_DOWN, image); -} + if (m_foreground_image != nullptr) + m_foreground_image->drop(); -void GUIButtonImage::setPressedForegroundImage(video::ITexture *image, const core::rect &pos) -{ - setForegroundImage(gui::EGBIS_IMAGE_DOWN, image, pos); + m_foreground_image = image; + m_image->setImage(image); } -void GUIButtonImage::setHoveredForegroundImage(video::ITexture *image) +//! Set element properties from a StyleSpec +void GUIButtonImage::setFromStyle(const StyleSpec& style) { - setForegroundImage(gui::EGBIS_IMAGE_UP_MOUSEOVER, image); - setForegroundImage(gui::EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER, image); -} - -void GUIButtonImage::setHoveredForegroundImage(video::ITexture *image, const core::rect &pos) -{ - setForegroundImage(gui::EGBIS_IMAGE_UP_MOUSEOVER, image, pos); - setForegroundImage(gui::EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER, image, pos); -} - -void GUIButtonImage::setFromStyle(const StyleSpec &style, ISimpleTextureSource *tsrc) -{ - GUIButton::setFromStyle(style, tsrc); + GUIButton::setFromStyle(style); video::IVideoDriver *driver = Environment->getVideoDriver(); const core::position2di buttonCenter(AbsoluteRect.getCenter()); core::position2d geom(buttonCenter); if (style.isNotDefault(StyleSpec::FGIMG)) { - video::ITexture *texture = style.getTexture(StyleSpec::FGIMG, tsrc); + video::ITexture *texture = style.getTexture(StyleSpec::FGIMG, + getTextureSource()); setForegroundImage(guiScalingImageButton(driver, texture, geom.X, geom.Y)); setScaleImage(true); - } - if (style.isNotDefault(StyleSpec::FGIMG_HOVERED)) { - video::ITexture *hovered_texture = style.getTexture(StyleSpec::FGIMG_HOVERED, tsrc); - - setHoveredForegroundImage(guiScalingImageButton(driver, hovered_texture, geom.X, geom.Y)); - setScaleImage(true); - } - if (style.isNotDefault(StyleSpec::FGIMG_PRESSED)) { - video::ITexture *pressed_texture = style.getTexture(StyleSpec::FGIMG_PRESSED, tsrc); - - setPressedForegroundImage(guiScalingImageButton(driver, pressed_texture, geom.X, geom.Y)); - setScaleImage(true); + } else { + setForegroundImage(nullptr); } } @@ -143,11 +82,12 @@ void GUIButtonImage::setScaleImage(bool scaleImage) } GUIButtonImage *GUIButtonImage::addButton(IGUIEnvironment *environment, - const core::rect &rectangle, IGUIElement *parent, s32 id, - const wchar_t *text, const wchar_t *tooltiptext) + const core::rect &rectangle, ISimpleTextureSource *tsrc, + IGUIElement *parent, s32 id, const wchar_t *text, + const wchar_t *tooltiptext) { GUIButtonImage *button = new GUIButtonImage(environment, - parent ? parent : environment->getRootGUIElement(), id, rectangle); + parent ? parent : environment->getRootGUIElement(), id, rectangle, tsrc); if (text) button->setText(text); diff --git a/src/gui/guiButtonImage.h b/src/gui/guiButtonImage.h index 15901ee5d..a948d772b 100644 --- a/src/gui/guiButtonImage.h +++ b/src/gui/guiButtonImage.h @@ -27,33 +27,23 @@ class GUIButtonImage : public GUIButton public: //! constructor GUIButtonImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent, - s32 id, core::rect rectangle, bool noclip = false); - - virtual bool OnEvent(const SEvent& event) override; - - void setForegroundImage(gui::EGUI_BUTTON_IMAGE_STATE state, - video::ITexture *image = nullptr, - const core::rect &sourceRect = core::rect(0, 0, 0, 0)); + s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, + bool noclip = false); void setForegroundImage(video::ITexture *image = nullptr); - void setForegroundImage(video::ITexture *image, const core::rect &pos); - - void setPressedForegroundImage(video::ITexture *image = nullptr); - void setPressedForegroundImage(video::ITexture *image, const core::rect &pos); - - void setHoveredForegroundImage(video::ITexture *image = nullptr); - void setHoveredForegroundImage(video::ITexture *image, const core::rect &pos); - virtual void setFromStyle(const StyleSpec &style, ISimpleTextureSource *tsrc) override; + //! Set element properties from a StyleSpec + virtual void setFromStyle(const StyleSpec& style) override; virtual void setScaleImage(bool scaleImage=true) override; //! Do not drop returned handle static GUIButtonImage *addButton(gui::IGUIEnvironment *environment, - const core::rect &rectangle, IGUIElement *parent, s32 id, - const wchar_t *text, const wchar_t *tooltiptext = L""); + const core::rect &rectangle, ISimpleTextureSource *tsrc, + IGUIElement *parent, s32 id, const wchar_t *text, + const wchar_t *tooltiptext = L""); private: - ButtonImage m_foreground_images[gui::EGBIS_COUNT]; + video::ITexture *m_foreground_image = nullptr; gui::IGUIImage *m_image; }; diff --git a/src/gui/guiButtonItemImage.cpp b/src/gui/guiButtonItemImage.cpp index 5c48b2acd..d8b9042ac 100644 --- a/src/gui/guiButtonItemImage.cpp +++ b/src/gui/guiButtonItemImage.cpp @@ -28,9 +28,11 @@ with this program; if not, write to the Free Software Foundation, Inc., using namespace irr; using namespace gui; -GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent, - s32 id, core::rect rectangle, std::string item, Client *client, bool noclip) - : GUIButton (environment, parent, id, rectangle, noclip) +GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment, + gui::IGUIElement *parent, s32 id, core::rect rectangle, + ISimpleTextureSource *tsrc, std::string item, Client *client, + bool noclip) + : GUIButton (environment, parent, id, rectangle, tsrc, noclip) { m_image = new GUIItemImage(environment, this, id, core::rect(0,0,rectangle.getWidth(),rectangle.getHeight()), @@ -42,12 +44,13 @@ GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment, gui::I } GUIButtonItemImage *GUIButtonItemImage::addButton(IGUIEnvironment *environment, - const core::rect &rectangle, IGUIElement *parent, s32 id, - const wchar_t *text, std::string item, Client *client) + const core::rect &rectangle, ISimpleTextureSource *tsrc, + IGUIElement *parent, s32 id, const wchar_t *text, std::string item, + Client *client) { GUIButtonItemImage *button = new GUIButtonItemImage(environment, parent ? parent : environment->getRootGUIElement(), - id, rectangle, item, client); + id, rectangle, tsrc, item, client); if (text) button->setText(text); diff --git a/src/gui/guiButtonItemImage.h b/src/gui/guiButtonItemImage.h index 0a61874da..9cd0f6188 100644 --- a/src/gui/guiButtonItemImage.h +++ b/src/gui/guiButtonItemImage.h @@ -30,13 +30,14 @@ class GUIButtonItemImage : public GUIButton public: //! constructor GUIButtonItemImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent, - s32 id, core::rect rectangle, std::string item, - Client *client, bool noclip = false); + s32 id, core::rect rectangle, ISimpleTextureSource *tsrc, + std::string item, Client *client, bool noclip = false); //! Do not drop returned handle static GUIButtonItemImage *addButton(gui::IGUIEnvironment *environment, - const core::rect &rectangle, IGUIElement *parent, s32 id, - const wchar_t *text, std::string item, Client *client); + const core::rect &rectangle, ISimpleTextureSource *tsrc, + IGUIElement *parent, s32 id, const wchar_t *text, std::string item, + Client *client); private: std::string m_item_name; diff --git a/src/gui/guiConfirmRegistration.cpp b/src/gui/guiConfirmRegistration.cpp index 0d8bdf54e..58ac42740 100644 --- a/src/gui/guiConfirmRegistration.cpp +++ b/src/gui/guiConfirmRegistration.cpp @@ -40,10 +40,10 @@ const int ID_message = 266; GUIConfirmRegistration::GUIConfirmRegistration(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client, const std::string &playername, const std::string &password, - bool *aborted) : + bool *aborted, ISimpleTextureSource *tsrc) : GUIModalMenu(env, parent, id, menumgr), m_client(client), m_playername(playername), m_password(password), - m_aborted(aborted) + m_aborted(aborted), m_tsrc(tsrc) { #ifdef __ANDROID__ m_touchscreen_visible = false; @@ -130,14 +130,14 @@ void GUIConfirmRegistration::regenerateGui(v2u32 screensize) core::rect rect2(0, 0, 230 * s, 35 * s); rect2 = rect2 + v2s32(size.X / 2 - 220 * s, ypos); text = wgettext("Register and Join"); - GUIButton::addButton(Environment, rect2, this, ID_confirm, text); + GUIButton::addButton(Environment, rect2, m_tsrc, this, ID_confirm, text); delete[] text; } { core::rect rect2(0, 0, 120 * s, 35 * s); rect2 = rect2 + v2s32(size.X / 2 + 70 * s, ypos); text = wgettext("Cancel"); - GUIButton::addButton(Environment, rect2, this, ID_cancel, text); + GUIButton::addButton(Environment, rect2, m_tsrc, this, ID_cancel, text); delete[] text; } { diff --git a/src/gui/guiConfirmRegistration.h b/src/gui/guiConfirmRegistration.h index 42c07e4ed..d8387201d 100644 --- a/src/gui/guiConfirmRegistration.h +++ b/src/gui/guiConfirmRegistration.h @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include class Client; +class ISimpleTextureSource; class GUIConfirmRegistration : public GUIModalMenu { @@ -32,7 +33,7 @@ public: GUIConfirmRegistration(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, Client *client, const std::string &playername, const std::string &password, - bool *aborted); + bool *aborted, ISimpleTextureSource *tsrc); ~GUIConfirmRegistration(); void removeChildren(); @@ -63,4 +64,5 @@ private: const std::string &m_password; bool *m_aborted = nullptr; std::wstring m_pass_confirm = L""; + ISimpleTextureSource *m_tsrc; }; diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index acb153569..6a383a791 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -553,7 +553,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element gui::IGUICheckBox *e = Environment->addCheckBox(fselected, rect, this, spec.fid, spec.flabel.c_str()); - auto style = getStyleForElement("checkbox", name); + auto style = getDefaultStyleForElement("checkbox", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); if (spec.fname == data->focused_fieldname) { @@ -613,7 +613,7 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen GUIScrollBar *e = new GUIScrollBar(Environment, this, spec.fid, rect, is_horizontal, true); - auto style = getStyleForElement("scrollbar", name); + auto style = getDefaultStyleForElement("scrollbar", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setArrowsVisible(data->scrollbar_options.arrow_visiblity); @@ -740,7 +740,7 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) gui::IGUIImage *e = Environment->addImage(rect, this, spec.fid, 0, true); e->setImage(texture); e->setScaleImage(true); - auto style = getStyleForElement("image", spec.fname); + auto style = getDefaultStyleForElement("image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); @@ -776,7 +776,7 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) ); gui::IGUIImage *e = Environment->addImage(texture, pos, true, this, spec.fid, 0); - auto style = getStyleForElement("image", spec.fname); + auto style = getDefaultStyleForElement("image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); @@ -841,7 +841,7 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el if (parts.size() >= 7) e->setFrameIndex(stoi(parts[6]) - 1); - auto style = getStyleForElement("animated_image", spec.fname, "image"); + auto style = getDefaultStyleForElement("animated_image", spec.fname, "image"); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->drop(); @@ -888,7 +888,7 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen GUIItemImage *e = new GUIItemImage(Environment, this, spec.fid, core::rect(pos, pos + geom), name, m_font, m_client); - auto style = getStyleForElement("item_image", spec.fname); + auto style = getDefaultStyleForElement("item_image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); // item images should let events through @@ -949,10 +949,11 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element, if(type == "button_exit") spec.is_exit = true; - GUIButton *e = GUIButton::addButton(Environment, rect, this, spec.fid, spec.flabel.c_str()); + GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, this, + spec.fid, spec.flabel.c_str()); auto style = getStyleForElement(type, name, (type != "button") ? "button" : ""); - e->setFromStyle(style, m_tsrc); + e->setStyles(style); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); @@ -1155,7 +1156,7 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element) if (!str_initial_selection.empty() && str_initial_selection != "0") e->setSelected(stoi(str_initial_selection)); - auto style = getStyleForElement("table", name); + auto style = getDefaultStyleForElement("table", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); m_tables.emplace_back(spec, e); @@ -1231,7 +1232,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element if (!str_initial_selection.empty() && str_initial_selection != "0") e->setSelected(stoi(str_initial_selection)); - auto style = getStyleForElement("textlist", name); + auto style = getDefaultStyleForElement("textlist", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); m_tables.emplace_back(spec, e); @@ -1306,7 +1307,7 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element if (!str_initial_selection.empty()) e->setSelected(stoi(str_initial_selection)-1); - auto style = getStyleForElement("dropdown", name); + auto style = getDefaultStyleForElement("dropdown", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); m_fields.push_back(spec); @@ -1394,7 +1395,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element e->setPasswordBox(true,L'*'); - auto style = getStyleForElement("pwdfield", name, "field"); + auto style = getDefaultStyleForElement("pwdfield", name, "field"); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setDrawBorder(style.getBool(StyleSpec::BORDER, true)); e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); @@ -1454,7 +1455,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, } } - auto style = getStyleForElement(is_multiline ? "textarea" : "field", spec.fname); + auto style = getDefaultStyleForElement(is_multiline ? "textarea" : "field", spec.fname); if (e) { if (is_editable && spec.fname == data->focused_fieldname) @@ -1752,7 +1753,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) spec.flabel.c_str(), rect, false, false, this, spec.fid); e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER); - auto style = getStyleForElement("label", spec.fname); + auto style = getDefaultStyleForElement("label", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); @@ -1832,7 +1833,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen rect, false, false, this, spec.fid); e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); - auto style = getStyleForElement("vertlabel", spec.fname, "label"); + auto style = getDefaultStyleForElement("vertlabel", spec.fname, "label"); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); @@ -1863,17 +1864,8 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem MY_CHECKPOS("imagebutton",0); MY_CHECKGEOM("imagebutton",1); - bool noclip = false; - bool drawborder = true; std::string pressed_image_name; - if (parts.size() >= 7) { - if (parts[5] == "true") - noclip = true; - if (parts[6] == "false") - drawborder = false; - } - if (parts.size() >= 8) { pressed_image_name = parts[7]; } @@ -1911,35 +1903,30 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem if (type == "image_button_exit") spec.is_exit = true; - GUIButtonImage *e = GUIButtonImage::addButton(Environment, rect, this, spec.fid, spec.flabel.c_str()); + GUIButtonImage *e = GUIButtonImage::addButton(Environment, rect, m_tsrc, + this, spec.fid, spec.flabel.c_str()); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); } auto style = getStyleForElement("image_button", spec.fname); - e->setFromStyle(style, m_tsrc); - // We explicitly handle these arguments *after* the style properties in - // order to override them if they are provided + // Override style properties with values specified directly in the element if (!image_name.empty()) - { - video::ITexture *texture = m_tsrc->getTexture(image_name); - e->setForegroundImage(guiScalingImageButton( - Environment->getVideoDriver(), texture, geom.X, geom.Y)); - } - if (!pressed_image_name.empty()) { - video::ITexture *pressed_texture = m_tsrc->getTexture(pressed_image_name); - e->setPressedForegroundImage(guiScalingImageButton( - Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y)); - } - e->setScaleImage(true); + style[StyleSpec::STATE_DEFAULT].set(StyleSpec::FGIMG, image_name); + + if (!pressed_image_name.empty()) + style[StyleSpec::STATE_PRESSED].set(StyleSpec::FGIMG, pressed_image_name); if (parts.size() >= 7) { - e->setNotClipped(noclip); - e->setDrawBorder(drawborder); + style[StyleSpec::STATE_DEFAULT].set(StyleSpec::NOCLIP, parts[5]); + style[StyleSpec::STATE_DEFAULT].set(StyleSpec::BORDER, parts[6]); } + e->setStyles(style); + e->setScaleImage(true); + m_fields.push_back(spec); return; } @@ -2033,7 +2020,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen Environment->setFocus(e); } - auto style = getStyleForElement("tabheader", name); + auto style = getDefaultStyleForElement("tabheader", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, true)); for (const std::string &button : buttons) { @@ -2118,10 +2105,12 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string & 2 ); - GUIButtonItemImage *e_btn = GUIButtonItemImage::addButton(Environment, rect, this, spec_btn.fid, spec_btn.flabel.c_str(), item_name, m_client); + GUIButtonItemImage *e_btn = GUIButtonItemImage::addButton(Environment, + rect, m_tsrc, this, spec_btn.fid, spec_btn.flabel.c_str(), + item_name, m_client); auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button"); - e_btn->setFromStyle(style, m_tsrc); + e_btn->setStyles(style); if (spec_btn.fname == data->focused_fieldname) { Environment->setFocus(e_btn); @@ -2177,7 +2166,7 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element) GUIBox *e = new GUIBox(Environment, this, spec.fid, rect, tmp_color); - auto style = getStyleForElement("box", spec.fname); + auto style = getDefaultStyleForElement("box", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); e->drop(); @@ -2469,6 +2458,7 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b StyleSpec spec; + // Parse properties for (size_t i = 1; i < parts.size(); i++) { size_t equal_pos = parts[i].find('='); if (equal_pos == std::string::npos) { @@ -2500,16 +2490,92 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b for (size_t sel = 0; sel < selectors.size(); sel++) { std::string selector = trim(selectors[sel]); - if (selector.empty()) { - errorstream << "Invalid style element (Empty selector): '" << element - << "'" << std::endl; + // Copy the style properties to a new StyleSpec + // This allows a separate state mask per-selector + StyleSpec selector_spec = spec; + + // Parse state information, if it exists + bool state_valid = true; + size_t state_pos = selector.find(':'); + if (state_pos != std::string::npos) { + std::string state_str = selector.substr(state_pos + 1); + selector = selector.substr(0, state_pos); + + if (state_str.empty()) { + errorstream << "Invalid style element (Invalid state): '" << element + << "'" << std::endl; + state_valid = false; + } else { + std::vector states = split(state_str, '+'); + for (std::string &state : states) { + StyleSpec::State converted = StyleSpec::getStateByName(state); + if (converted == StyleSpec::STATE_INVALID) { + infostream << "Unknown style state " << state << + " in element '" << element << "'" << std::endl; + state_valid = false; + break; + } + + selector_spec.addState(converted); + } + } + } + + if(!state_valid) { + // Skip this selector continue; } if (style_type) { - theme_by_type[selector] |= spec; + theme_by_type[selector].push_back(selector_spec); } else { - theme_by_name[selector] |= spec; + theme_by_name[selector].push_back(selector_spec); + } + + // Backwards-compatibility for existing _hovered/_pressed properties + if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED) + || selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED) + || selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) { + StyleSpec hover_spec; + hover_spec.addState(StyleSpec::STATE_HOVERED); + + if (selector_spec.hasProperty(StyleSpec::BGCOLOR_HOVERED)) { + hover_spec.set(StyleSpec::BGCOLOR, selector_spec.get(StyleSpec::BGCOLOR_HOVERED, "")); + } + if (selector_spec.hasProperty(StyleSpec::BGIMG_HOVERED)) { + hover_spec.set(StyleSpec::BGIMG, selector_spec.get(StyleSpec::BGIMG_HOVERED, "")); + } + if (selector_spec.hasProperty(StyleSpec::FGIMG_HOVERED)) { + hover_spec.set(StyleSpec::FGIMG, selector_spec.get(StyleSpec::FGIMG_HOVERED, "")); + } + + if (style_type) { + theme_by_type[selector].push_back(hover_spec); + } else { + theme_by_name[selector].push_back(hover_spec); + } + } + if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED) + || selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED) + || selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) { + StyleSpec press_spec; + press_spec.addState(StyleSpec::STATE_PRESSED); + + if (selector_spec.hasProperty(StyleSpec::BGCOLOR_PRESSED)) { + press_spec.set(StyleSpec::BGCOLOR, selector_spec.get(StyleSpec::BGCOLOR_PRESSED, "")); + } + if (selector_spec.hasProperty(StyleSpec::BGIMG_PRESSED)) { + press_spec.set(StyleSpec::BGIMG, selector_spec.get(StyleSpec::BGIMG_PRESSED, "")); + } + if (selector_spec.hasProperty(StyleSpec::FGIMG_PRESSED)) { + press_spec.set(StyleSpec::FGIMG, selector_spec.get(StyleSpec::FGIMG_PRESSED, "")); + } + + if (style_type) { + theme_by_type[selector].push_back(press_spec); + } else { + theme_by_name[selector].push_back(press_spec); + } } } @@ -3080,7 +3146,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2 ); const wchar_t *text = wgettext("Proceed"); - GUIButton::addButton(Environment, mydata.rect, this, 257, text); + GUIButton::addButton(Environment, mydata.rect, m_tsrc, this, 257, text); delete[] text; } } @@ -4432,25 +4498,34 @@ std::wstring GUIFormSpecMenu::getLabelByID(s32 id) return L""; } -StyleSpec GUIFormSpecMenu::getStyleForElement(const std::string &type, +StyleSpec GUIFormSpecMenu::getDefaultStyleForElement(const std::string &type, const std::string &name, const std::string &parent_type) { - StyleSpec ret; + return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT]; +} + +std::array GUIFormSpecMenu::getStyleForElement(const std::string &type, + const std::string &name, const std::string &parent_type) +{ + std::array ret; if (!parent_type.empty()) { auto it = theme_by_type.find(parent_type); if (it != theme_by_type.end()) { - ret |= it->second; + for (const StyleSpec &spec : it->second) + ret[(u32)spec.getState()] |= spec; } } auto it = theme_by_type.find(type); if (it != theme_by_type.end()) { - ret |= it->second; + for (const StyleSpec &spec : it->second) + ret[(u32)spec.getState()] |= spec; } it = theme_by_name.find(name); if (it != theme_by_name.end()) { - ret |= it->second; + for (const StyleSpec &spec : it->second) + ret[(u32)spec.getState()] |= spec; } return ret; diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 17bfef205..b3bf67110 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -274,11 +274,13 @@ protected: v2s32 getRealCoordinateBasePos(const std::vector &v_pos); v2s32 getRealCoordinateGeometry(const std::vector &v_geom); - std::unordered_map theme_by_type; - std::unordered_map theme_by_name; + std::unordered_map> theme_by_type; + std::unordered_map> theme_by_name; std::unordered_set property_warned; - StyleSpec getStyleForElement(const std::string &type, + StyleSpec getDefaultStyleForElement(const std::string &type, + const std::string &name="", const std::string &parent_type=""); + std::array getStyleForElement(const std::string &type, const std::string &name="", const std::string &parent_type=""); v2s32 padding; diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp index 3f270fc7a..da0e25c23 100644 --- a/src/gui/guiKeyChangeMenu.cpp +++ b/src/gui/guiKeyChangeMenu.cpp @@ -82,8 +82,10 @@ enum }; GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env, - gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) : -GUIModalMenu(env, parent, id, menumgr) + gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, + ISimpleTextureSource *tsrc) : + GUIModalMenu(env, parent, id, menumgr), + m_tsrc(tsrc) { init_keys(); } @@ -157,7 +159,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(offset.X + 150 * s, offset.Y - 5 * s); const wchar_t *text = wgettext(k->key.name()); - k->button = GUIButton::addButton(Environment, rect, this, k->id, text); + k->button = GUIButton::addButton(Environment, rect, m_tsrc, this, k->id, text); delete[] text; } if ((i + 1) % KMaxButtonPerColumns == 0) { @@ -217,14 +219,14 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(size.X / 2 - 105 * s, size.Y - 40 * s); const wchar_t *text = wgettext("Save"); - GUIButton::addButton(Environment, rect, this, GUI_ID_BACK_BUTTON, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_BACK_BUTTON, text); delete[] text; } { core::rect rect(0, 0, 100 * s, 30 * s); rect += topleft + v2s32(size.X / 2 + 5 * s, size.Y - 40 * s); const wchar_t *text = wgettext("Cancel"); - GUIButton::addButton(Environment, rect, this, GUI_ID_ABORT_BUTTON, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_ABORT_BUTTON, text); delete[] text; } } diff --git a/src/gui/guiKeyChangeMenu.h b/src/gui/guiKeyChangeMenu.h index 528827fd9..1c0f40247 100644 --- a/src/gui/guiKeyChangeMenu.h +++ b/src/gui/guiKeyChangeMenu.h @@ -28,6 +28,8 @@ #include #include +class ISimpleTextureSource; + struct key_setting { int id; @@ -41,7 +43,7 @@ class GUIKeyChangeMenu : public GUIModalMenu { public: GUIKeyChangeMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - IMenuManager *menumgr); + IMenuManager *menumgr, ISimpleTextureSource *tsrc); ~GUIKeyChangeMenu(); void removeChildren(); @@ -74,4 +76,5 @@ private: key_setting *active_key = nullptr; gui::IGUIStaticText *key_used_text = nullptr; std::vector key_settings; + ISimpleTextureSource *m_tsrc; }; diff --git a/src/gui/guiPasswordChange.cpp b/src/gui/guiPasswordChange.cpp index af91ce84c..965a2d6f7 100644 --- a/src/gui/guiPasswordChange.cpp +++ b/src/gui/guiPasswordChange.cpp @@ -38,10 +38,12 @@ const int ID_cancel = 261; GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, - Client* client + Client* client, + ISimpleTextureSource *tsrc ): GUIModalMenu(env, parent, id, menumgr), - m_client(client) + m_client(client), + m_tsrc(tsrc) { } @@ -146,14 +148,14 @@ void GUIPasswordChange::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 100 * s, 30 * s); rect = rect + v2s32(size.X / 4 + 56 * s, ypos); text = wgettext("Change"); - GUIButton::addButton(Environment, rect, this, ID_change, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, ID_change, text); delete[] text; } { core::rect rect(0, 0, 100 * s, 30 * s); rect = rect + v2s32(size.X / 4 + 185 * s, ypos); text = wgettext("Cancel"); - GUIButton::addButton(Environment, rect, this, ID_cancel, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, ID_cancel, text); delete[] text; } diff --git a/src/gui/guiPasswordChange.h b/src/gui/guiPasswordChange.h index 58541a399..7141100c0 100644 --- a/src/gui/guiPasswordChange.h +++ b/src/gui/guiPasswordChange.h @@ -23,12 +23,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include class Client; +class ISimpleTextureSource; class GUIPasswordChange : public GUIModalMenu { public: GUIPasswordChange(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - IMenuManager *menumgr, Client *client); + IMenuManager *menumgr, Client *client, + ISimpleTextureSource *tsrc); ~GUIPasswordChange(); void removeChildren(); @@ -57,4 +59,5 @@ private: std::wstring m_oldpass = L""; std::wstring m_newpass = L""; std::wstring m_newpass_confirm = L""; + ISimpleTextureSource *m_tsrc; }; diff --git a/src/gui/guiVolumeChange.cpp b/src/gui/guiVolumeChange.cpp index 9428cde83..07b11248c 100644 --- a/src/gui/guiVolumeChange.cpp +++ b/src/gui/guiVolumeChange.cpp @@ -38,9 +38,10 @@ const int ID_soundMuteButton = 266; GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr + IMenuManager *menumgr, ISimpleTextureSource *tsrc ): - GUIModalMenu(env, parent, id, menumgr) + GUIModalMenu(env, parent, id, menumgr), + m_tsrc(tsrc) { } @@ -104,7 +105,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 80 * s, 30 * s); rect = rect + v2s32(size.X / 2 - 80 * s / 2, size.Y / 2 + 55 * s); const wchar_t *text = wgettext("Exit"); - GUIButton::addButton(Environment, rect, this, ID_soundExitButton, text); + GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton, text); delete[] text; } { diff --git a/src/gui/guiVolumeChange.h b/src/gui/guiVolumeChange.h index f4f4e9eea..466e17f9d 100644 --- a/src/gui/guiVolumeChange.h +++ b/src/gui/guiVolumeChange.h @@ -23,12 +23,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "modalMenu.h" #include +class ISimpleTextureSource; + class GUIVolumeChange : public GUIModalMenu { public: GUIVolumeChange(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, - IMenuManager *menumgr); + IMenuManager *menumgr, ISimpleTextureSource *tsrc); ~GUIVolumeChange(); void removeChildren(); @@ -46,4 +48,7 @@ public: protected: std::wstring getLabelByID(s32 id) { return L""; } std::string getNameByID(s32 id) { return ""; } + +private: + ISimpleTextureSource *m_tsrc; }; diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 76db7ed13..867e84e13 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -571,9 +571,10 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L) sanity_check(engine != NULL); GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(), - engine->m_parent, - -1, - engine->m_menumanager); + engine->m_parent, + -1, + engine->m_menumanager, + engine->m_texture_source); kmenu->drop(); return 0; } @@ -904,12 +905,12 @@ int ModApiMainMenu::l_show_path_select_dialog(lua_State *L) GUIFileSelectMenu* fileOpenMenu = new GUIFileSelectMenu(RenderingEngine::get_gui_env(), - engine->m_parent, - -1, - engine->m_menumanager, - title, - formname, - is_file_select); + engine->m_parent, + -1, + engine->m_menumanager, + title, + formname, + is_file_select); fileOpenMenu->setTextDest(engine->m_buttonhandler); fileOpenMenu->drop(); return 0; diff --git a/src/util/numeric.h b/src/util/numeric.h index 6f82a18c1..864ab7543 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irr_v2d.h" #include "irr_v3d.h" #include "irr_aabb3d.h" +#include "SColor.h" #include #define rangelim(d, min, max) ((d) < (min) ? (min) : ((d) > (max) ? (max) : (d))) @@ -432,3 +433,12 @@ inline v3f getPitchYawRoll(const core::matrix4 &m) { return getPitchYawRollRad(m) * core::RADTODEG64; } + +// Muliply the RGB value of a color linearly, and clamp to black/white +inline irr::video::SColor multiplyColorValue(const irr::video::SColor &color, float mod) +{ + return irr::video::SColor(color.getAlpha(), + core::clamp(color.getRed() * mod, 0, 255), + core::clamp(color.getGreen() * mod, 0, 255), + core::clamp(color.getBlue() * mod, 0, 255)); +} -- cgit v1.2.3 From af2e6a6a10121cf971d4ce4c33d523b6dc037d31 Mon Sep 17 00:00:00 2001 From: Lars Müller <34514239+appgurueu@users.noreply.github.com> Date: Sat, 11 Apr 2020 23:09:46 +0200 Subject: Improve waypoints and add image variant (#9480) --- doc/client_lua_api.txt | 25 ++++++++- doc/lua_api.txt | 20 ++++++++ src/client/hud.cpp | 111 ++++++++++++++++++++++++---------------- src/client/hud.h | 1 + src/hud.cpp | 1 + src/hud.h | 1 + src/script/common/c_content.cpp | 6 ++- 7 files changed, 118 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 71df91c68..53ed680d0 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -1416,12 +1416,35 @@ Displays a horizontal bar made up of half-images. * `offset`: offset in pixels from position. ### `waypoint` + Displays distance to selected world position. * `name`: The name of the waypoint. * `text`: Distance suffix. Can be blank. -* `number:` An integer containing the RGB value of the color used to draw the text. +* `precision`: Waypoint precision, integer >= 0. Defaults to 10. + If set to 0, distance is not shown. Shown value is `floor(distance*precision)/precision`. + When the precision is an integer multiple of 10, there will be `log_10(precision)` digits after the decimal point. + `precision = 1000`, for example, will show 3 decimal places (eg: `0.999`). + `precision = 2` will show multiples of `0.5`; precision = 5 will show multiples of `0.2` and so on: + `precision = n` will show multiples of `1/n` +* `number:` An integer containing the RGB value of the color used to draw the + text. * `world_pos`: World position of the waypoint. +* `offset`: offset in pixels from position. +* `alignment`: The alignment of the waypoint. + +### `image_waypoint` + +Same as `image`, but does not accept a `position`; the position is instead determined by `world_pos`, the world position of the waypoint. + +* `scale`: The scale of the image, with 1 being the original texture size. + Only the X coordinate scale is used (positive values). + Negative values represent that percentage of the screen it + should take; e.g. `x=-100` means 100% (width). +* `text`: The name of the texture that is displayed. +* `alignment`: The alignment of the image. +* `world_pos`: World position of the waypoint. +* `offset`: offset in pixels from position. ### Particle definition (`add_particle`) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b083b2907..1a9aad344 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1364,10 +1364,30 @@ Displays distance to selected world position. * `name`: The name of the waypoint. * `text`: Distance suffix. Can be blank. +* `precision`: Waypoint precision, integer >= 0. Defaults to 10. + If set to 0, distance is not shown. Shown value is `floor(distance*precision)/precision`. + When the precision is an integer multiple of 10, there will be `log_10(precision)` digits after the decimal point. + `precision = 1000`, for example, will show 3 decimal places (eg: `0.999`). + `precision = 2` will show multiples of `0.5`; precision = 5 will show multiples of `0.2` and so on: + `precision = n` will show multiples of `1/n` * `number:` An integer containing the RGB value of the color used to draw the text. * `world_pos`: World position of the waypoint. +* `offset`: offset in pixels from position. +* `alignment`: The alignment of the waypoint. + +### `image_waypoint` + +Same as `image`, but does not accept a `position`; the position is instead determined by `world_pos`, the world position of the waypoint. +* `scale`: The scale of the image, with 1 being the original texture size. + Only the X coordinate scale is used (positive values). + Negative values represent that percentage of the screen it + should take; e.g. `x=-100` means 100% (width). +* `text`: The name of the texture that is displayed. +* `alignment`: The alignment of the image. +* `world_pos`: World position of the waypoint. +* `offset`: offset in pixels from position. diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 37de6640b..56763e7e4 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -272,6 +272,25 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, } } +// Calculates screen position of waypoint. Returns true if waypoint is visible (in front of the player), else false. +bool Hud::calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos) +{ + v3f w_pos = e->world_pos * BS; + scene::ICameraSceneNode* camera = + RenderingEngine::get_scene_manager()->getActiveCamera(); + w_pos -= intToFloat(camera_offset, BS); + core::matrix4 trans = camera->getProjectionMatrix(); + trans *= camera->getViewMatrix(); + f32 transformed_pos[4] = { w_pos.X, w_pos.Y, w_pos.Z, 1.0f }; + trans.multiplyWith1x4Matrix(transformed_pos); + if (transformed_pos[3] < 0) + return false; + f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : + core::reciprocal(transformed_pos[3]); + pos->X = m_screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5); + pos->Y = m_screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5); + return true; +} void Hud::drawLuaElements(const v3s16 &camera_offset) { @@ -299,28 +318,6 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5), floor(e->pos.Y * (float) m_screensize.Y + 0.5)); switch (e->type) { - case HUD_ELEM_IMAGE: { - video::ITexture *texture = tsrc->getTexture(e->text); - if (!texture) - continue; - - const video::SColor color(255, 255, 255, 255); - const video::SColor colors[] = {color, color, color, color}; - core::dimension2di imgsize(texture->getOriginalSize()); - v2s32 dstsize(imgsize.Width * e->scale.X, - imgsize.Height * e->scale.Y); - if (e->scale.X < 0) - dstsize.X = m_screensize.X * (e->scale.X * -0.01); - if (e->scale.Y < 0) - dstsize.Y = m_screensize.Y * (e->scale.Y * -0.01); - v2s32 offset((e->align.X - 1.0) * dstsize.X / 2, - (e->align.Y - 1.0) * dstsize.Y / 2); - core::rect rect(0, 0, dstsize.X, dstsize.Y); - rect += pos + offset + v2s32(e->offset.X, e->offset.Y); - draw2DImageFilterScaled(driver, texture, rect, - core::rect(core::position2d(0,0), imgsize), - NULL, colors, true); - break; } case HUD_ELEM_TEXT: { video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, @@ -343,34 +340,58 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) inv, e->item, e->dir); break; } case HUD_ELEM_WAYPOINT: { - v3f p_pos = player->getPosition() / BS; - v3f w_pos = e->world_pos * BS; - float distance = std::floor(10 * p_pos.getDistanceFrom(e->world_pos)) / - 10.0f; - scene::ICameraSceneNode* camera = - RenderingEngine::get_scene_manager()->getActiveCamera(); - w_pos -= intToFloat(camera_offset, BS); - core::matrix4 trans = camera->getProjectionMatrix(); - trans *= camera->getViewMatrix(); - f32 transformed_pos[4] = { w_pos.X, w_pos.Y, w_pos.Z, 1.0f }; - trans.multiplyWith1x4Matrix(transformed_pos); - if (transformed_pos[3] < 0) + if (!calculateScreenPos(camera_offset, e, &pos)) break; - f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : - core::reciprocal(transformed_pos[3]); - pos.X = m_screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5); - pos.Y = m_screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5); + v3f p_pos = player->getPosition() / BS; + pos += v2s32(e->offset.X, e->offset.Y); video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); - core::rect size(0, 0, 200, 2 * text_height); std::wstring text = unescape_translate(utf8_to_wide(e->name)); - font->draw(text.c_str(), size + pos, color); - std::ostringstream os; - os << distance << e->text; - text = unescape_translate(utf8_to_wide(os.str())); - pos.Y += text_height; - font->draw(text.c_str(), size + pos, color); + const std::string &unit = e->text; + // waypoints reuse the item field to store precision, item = precision + 1 + u32 item = e->item; + float precision = (item == 0) ? 10.0f : (item - 1.f); + bool draw_precision = precision > 0; + + core::rect bounds(0, 0, font->getDimension(text.c_str()).Width, (draw_precision ? 2:1) * text_height); + pos.Y += (e->align.Y - 1.0) * bounds.getHeight() / 2; + bounds += pos; + font->draw(text.c_str(), bounds + v2s32((e->align.X - 1.0) * bounds.getWidth() / 2, 0), color); + if (draw_precision) { + std::ostringstream os; + float distance = std::floor(precision * p_pos.getDistanceFrom(e->world_pos)) / precision; + os << distance << unit; + text = unescape_translate(utf8_to_wide(os.str())); + bounds.LowerRightCorner.X = bounds.UpperLeftCorner.X + font->getDimension(text.c_str()).Width; + font->draw(text.c_str(), bounds + v2s32((e->align.X - 1.0f) * bounds.getWidth() / 2, text_height), color); + } + break; } + case HUD_ELEM_IMAGE_WAYPOINT: { + if (!calculateScreenPos(camera_offset, e, &pos)) + break; + } + case HUD_ELEM_IMAGE: { + video::ITexture *texture = tsrc->getTexture(e->text); + if (!texture) + continue; + + const video::SColor color(255, 255, 255, 255); + const video::SColor colors[] = {color, color, color, color}; + core::dimension2di imgsize(texture->getOriginalSize()); + v2s32 dstsize(imgsize.Width * e->scale.X, + imgsize.Height * e->scale.Y); + if (e->scale.X < 0) + dstsize.X = m_screensize.X * (e->scale.X * -0.01); + if (e->scale.Y < 0) + dstsize.Y = m_screensize.Y * (e->scale.Y * -0.01); + v2s32 offset((e->align.X - 1.0) * dstsize.X / 2, + (e->align.Y - 1.0) * dstsize.Y / 2); + core::rect rect(0, 0, dstsize.X, dstsize.Y); + rect += pos + offset + v2s32(e->offset.X, e->offset.Y); + draw2DImageFilterScaled(driver, texture, rect, + core::rect(core::position2d(0,0), imgsize), + NULL, colors, true); break; } default: infostream << "Hud::drawLuaElements: ignoring drawform " << e->type << diff --git a/src/client/hud.h b/src/client/hud.h index d9b5e0686..cab115990 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -81,6 +81,7 @@ public: void drawLuaElements(const v3s16 &camera_offset); private: + bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos); void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, s32 count, v2s32 offset, v2s32 size = v2s32()); diff --git a/src/hud.cpp b/src/hud.cpp index 7711e3a4a..39625b5fd 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -27,6 +27,7 @@ const struct EnumString es_HudElementType[] = {HUD_ELEM_STATBAR, "statbar"}, {HUD_ELEM_INVENTORY, "inventory"}, {HUD_ELEM_WAYPOINT, "waypoint"}, + {HUD_ELEM_IMAGE_WAYPOINT, "image_waypoint"}, {0, NULL}, }; diff --git a/src/hud.h b/src/hud.h index 23f189dff..b0977c6a4 100644 --- a/src/hud.h +++ b/src/hud.h @@ -61,6 +61,7 @@ enum HudElementType { HUD_ELEM_STATBAR = 2, HUD_ELEM_INVENTORY = 3, HUD_ELEM_WAYPOINT = 4, + HUD_ELEM_IMAGE_WAYPOINT = 5 }; enum HudElementStat { diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index c8cd7539f..ff9ceec6d 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1850,7 +1850,11 @@ void read_hud_element(lua_State *L, HudElement *elem) elem->name = getstringfield_default(L, 2, "name", ""); elem->text = getstringfield_default(L, 2, "text", ""); elem->number = getintfield_default(L, 2, "number", 0); - elem->item = getintfield_default(L, 2, "item", 0); + if (elem->type == HUD_ELEM_WAYPOINT) + // waypoints reuse the item field to store precision, item = precision + 1 + elem->item = getintfield_default(L, 2, "precision", -1) + 1; + else + elem->item = getintfield_default(L, 2, "item", 0); elem->dir = getintfield_default(L, 2, "direction", 0); elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX, getintfield_default(L, 2, "z_index", 0))); -- cgit v1.2.3 From a24d3b360048bde87113d435ab0cfef78851153c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 12 Apr 2020 01:50:40 +0200 Subject: Play 'player_jump' when player jumps (#9373) --- doc/lua_api.txt | 1 + src/client/game.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1a9aad344..dff6c728e 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -897,6 +897,7 @@ These sound files are played back by the engine if provided. * `player_damage`: Played when the local player takes damage (gain = 0.5) * `player_falling_damage`: Played when the local player takes damage by falling (gain = 0.5) + * `player_jump`: Played when the local player jumps * `default_dig_`: Default node digging sound (see node sound definition for details) diff --git a/src/client/game.cpp b/src/client/game.cpp index 06e76d170..ac6045190 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -266,6 +266,7 @@ class SoundMaker public: bool makes_footstep_sound; float m_player_step_timer; + float m_player_jump_timer; SimpleSoundSpec m_player_step_sound; SimpleSoundSpec m_player_leftpunch_sound; @@ -275,7 +276,8 @@ public: m_sound(sound), m_ndef(ndef), makes_footstep_sound(true), - m_player_step_timer(0) + m_player_step_timer(0.0f), + m_player_jump_timer(0.0f) { } @@ -288,6 +290,14 @@ public: } } + void playPlayerJump() + { + if (m_player_jump_timer <= 0.0f) { + m_player_jump_timer = 0.2f; + m_sound->playSound(SimpleSoundSpec("player_jump", 0.5f), false); + } + } + static void viewBobbingStep(MtEvent *e, void *data) { SoundMaker *sm = (SoundMaker *)data; @@ -302,7 +312,8 @@ public: static void playerJump(MtEvent *e, void *data) { - //SoundMaker *sm = (SoundMaker*)data; + SoundMaker *sm = (SoundMaker *)data; + sm->playPlayerJump(); } static void cameraPunchLeft(MtEvent *e, void *data) @@ -351,6 +362,7 @@ public: void step(float dtime) { m_player_step_timer -= dtime; + m_player_jump_timer -= dtime; } }; -- cgit v1.2.3 From 6cf15cf872cc9ce76990d83d380ca3c4b7485eb1 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 12 Apr 2020 12:02:32 +0200 Subject: GUIFormSpecMenu: Add basic element highlighing debug feature (#9423) Activated using F5 --- src/gui/guiFormSpecMenu.cpp | 10 +++++++++- src/gui/guiFormSpecMenu.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 6a383a791..f3bf04275 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3380,8 +3380,12 @@ void GUIFormSpecMenu::drawMenu() bool hovered_element_found = false; if (hovered != NULL) { - s32 id = hovered->getID(); + if (m_show_debug) { + core::rect rect = hovered->getAbsoluteClippingRect(); + driver->draw2DRectangle(0x22FFFF00, rect, &rect); + } + s32 id = hovered->getID(); u64 delta = 0; if (id == -1) { m_old_tooltip_id = id; @@ -3903,6 +3907,10 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) (kp == getKeySetting("keymap_screenshot"))) { m_client->makeScreenshot(); } + + if (event.KeyInput.PressedDown && kp == getKeySetting("keymap_toggle_debug")) + m_show_debug = !m_show_debug; + if (event.KeyInput.PressedDown && (event.KeyInput.Key==KEY_RETURN || event.KeyInput.Key==KEY_UP || diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index b3bf67110..dc22e8b54 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -343,6 +343,7 @@ private: u16 m_formspec_version = 1; std::string m_focused_element = ""; JoystickController *m_joystick; + bool m_show_debug = false; typedef struct { bool explicit_size; -- cgit v1.2.3 From 0ac999ded725f8efcd26db284161683e37efeecf Mon Sep 17 00:00:00 2001 From: DS Date: Mon, 13 Apr 2020 10:50:07 +0200 Subject: Add scroll_container formspec element (redo) (#9101) New formspec elements: - `scroll_container[,;,;;;]` - `scroll_container_end[]` Other elements can be embedded in this element. Scrollbar must be placed manually. --- build/android/jni/Android.mk | 1 + doc/lua_api.txt | 20 ++++ games/minimal/mods/test/formspec.lua | 69 ++++++++++- src/gui/CMakeLists.txt | 1 + src/gui/guiFormSpecMenu.cpp | 216 +++++++++++++++++++++++++++++------ src/gui/guiFormSpecMenu.h | 5 + src/gui/guiHyperText.cpp | 20 ++-- src/gui/guiHyperText.h | 2 +- src/gui/guiScrollContainer.cpp | 70 ++++++++++++ src/gui/guiScrollContainer.h | 56 +++++++++ src/network/networkprotocol.h | 1 + 11 files changed, 411 insertions(+), 50 deletions(-) create mode 100644 src/gui/guiScrollContainer.cpp create mode 100644 src/gui/guiScrollContainer.h (limited to 'src') diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index fdbfba9bc..b67322d79 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -194,6 +194,7 @@ LOCAL_SRC_FILES := \ jni/src/gui/guiPasswordChange.cpp \ jni/src/gui/guiPathSelectMenu.cpp \ jni/src/gui/guiScrollBar.cpp \ + jni/src/gui/guiScrollContainer.cpp \ jni/src/gui/guiSkin.cpp \ jni/src/gui/guiTable.cpp \ jni/src/gui/guiVolumeChange.cpp \ diff --git a/doc/lua_api.txt b/doc/lua_api.txt index dff6c728e..f43987cd8 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2102,6 +2102,26 @@ Elements * End of a container, following elements are no longer relative to this container. +### `scroll_container[,;,;;;]` + +* Start of a scroll_container block. All contained elements will ... + * take the scroll_container coordinate as position origin, + * be additionally moved by the current value of the scrollbar with the name + `scrollbar name` times `scroll factor` along the orientation `orientation` and + * be clipped to the rectangle defined by `X`, `Y`, `W` and `H`. +* `orientation`: possible values are `vertical` and `horizontal`. +* `scroll factor`: optional, defaults to `0.1`. +* Nesting is possible. +* Some elements might work a little different if they are in a scroll_container. +* Note: If you want the scroll_container to actually work, you also need to add a + scrollbar element with the specified name. Furthermore, it is highly recommended + to use a scrollbaroptions element on this scrollbar. + +### `scroll_container_end[]` + +* End of a scroll_container, following elements are no longer bound to this + container. + ### `list[;;,;,;]` * Show an inventory list if it has been sent to the client. Nothing will diff --git a/games/minimal/mods/test/formspec.lua b/games/minimal/mods/test/formspec.lua index 14886aad2..53e92b243 100644 --- a/games/minimal/mods/test/formspec.lua +++ b/games/minimal/mods/test/formspec.lua @@ -1,5 +1,35 @@ local color = minetest.colorize +local hypertext = minetest.formspec_escape([[ + +
Furnace
+ are crafted and used by the player for the purpose of cooking food and smelting various items. + + Solid block + Itself + No + Inactive:No Active:Yes (8) + No + No + Yes + Yes (99) + default:furnace default:furnace_active + Usage + The furnace menu can be accessed by using the furnace. + The furnace has 3 inventories: An input slot, a fuel slot and 4 output slots. The fire in the furnace will automatically start when there is a smeltable item in the input slot and a fuel in the fuel slot. + As long as the fire is on, the furnace will smelt any smeltable item in the input slot, one by one, until it is empty. When the fire goes off, it will smelt the next item until there are no smeltable items and no fuel items left. + The current stage of cooking can be seen by pointing the furnace or by viewing the furnace menu. In the furnace menu, the flame symbol roughly shows the remaining burning time. The arrow symbol shows the progress of the current smelting process. + Renewing + Furnaces can be crafted from e.g. cobblestone, a renewable resource. + Crafting + Sorry no way to display crafting yet in formspec pages. + Fuel + See Smelting for a list of furnace fuels. + Recipes + See the Smelting page. +]]) + + local clip_fs = [[ style_type[label,button,image_button,item_image_button, tabheader,scrollbar,table,animated_image @@ -188,13 +218,48 @@ Number] animated_image[3,4.25;1,1;;test_animation.png;4;0;3] animated_image[5.5,0.5;5,2;;test_animation.png;4;100] animated_image[5.5,2.75;5,2;;test_animation.jpg;4;100] - ]] + ]], + + "formspec_version[3]".. + "size[12,12]".. + "button[8.5,1;1,1;bla;Bla]".. + "box[1,1;8,6;#00aa]".. + "scroll_container[1,1;8,6;scrbar;vertical]".. + "button[0,1;1,1;lorem;Lorem]".. + "button[0,10;1,1;ipsum;Ipsum]".. + "pwdfield[2,2;1,1;lorem2;Lorem]".. + "list[current_player;main;4,4;1,5;]".. + "box[2,5;3,2;#ffff00]".. + "image[1,10;3,2;bubble.png]".. + "image[3,1;bubble.png]".. + "item_image[2,6;3,2;default:mese]".. + "label[2,15;bla Bli\nfoo bar]".. + "item_image_button[2,3;1,1;default:dirt_with_grass;itemimagebutton;ItemImageButton]".. + "tooltip[0,11;3,2;Buz;#f00;#000]".. + "box[0,11;3,2;#00ff00]".. + "hypertext[3,13;3,3;;" .. hypertext .. "]" .. + "container[0,18]".. + "box[1,2;3,2;#0a0a]".. + "scroll_container[1,2;3,2;scrbar2;horizontal;0.06]".. + "button[0,0;6,1;butnest;Nest]".. + "label[10,0.5;nest]".. + "scroll_container_end[]".. + "scrollbar[1,0;3.5,0.3;horizontal;scrbar2;0]".. + "container_end[]".. + "dropdown[0,6;2;hmdrpdwn;apple,bulb;1]".. + "image_button[0,4;2,2;bubble.png;bubblebutton;bbbbtt;false;true;heart.png]".. + "box[1,22.5;4,1;#a00a]".. + "scroll_container_end[]".. + "scrollbaroptions[max=170]".. -- lowest seen pos is: 0.1*170+6=23 (factor*max+height) + "scrollbar[7.5,0;0.3,4;vertical;scrbar;0]".. + "scrollbar[8,0;0.3,4;vertical;scrbarhmmm;0]".. + "dropdown[0,6;2;hmdrpdwnnn;apple,bulb;1]", } local function show_test_formspec(pname, page_id) page_id = page_id or 2 - local fs = pages[page_id] .. "tabheader[0,0;6,0.65;maintabs;Real Coord,Styles,Noclip,MiscEle;" .. page_id .. ";false;false]" + local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,MiscEle,Scroll Container;" .. page_id .. ";false;false]" minetest.show_formspec(pname, "test:formspec", fs) end diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 110a00595..147f445f4 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -16,6 +16,7 @@ set(gui_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiScrollBar.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/guiScrollContainer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiSkin.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiTable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/guiHyperText.cpp diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index f3bf04275..aac039ad6 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -65,6 +65,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiInventoryList.h" #include "guiItemImage.h" #include "guiScrollBar.h" +#include "guiScrollContainer.h" #include "guiTable.h" #include "intlGUIEditBox.h" #include "guiHyperText.h" @@ -143,6 +144,8 @@ GUIFormSpecMenu::~GUIFormSpecMenu() tooltip_rect_it.first->drop(); for (auto &clickthrough_it : m_clickthrough_elements) clickthrough_it->drop(); + for (auto &scroll_container_it : m_scroll_containers) + scroll_container_it.second->drop(); delete m_selected_item; delete m_form_src; @@ -351,6 +354,102 @@ void GUIFormSpecMenu::parseContainerEnd(parserData* data) } } +void GUIFormSpecMenu::parseScrollContainer(parserData *data, const std::string &element) +{ + std::vector parts = split(element, ';'); + + if (parts.size() < 4 || + (parts.size() > 5 && m_formspec_version <= FORMSPEC_API_VERSION)) { + errorstream << "Invalid scroll_container start element (" << parts.size() + << "): '" << element << "'" << std::endl; + return; + } + + std::vector v_pos = split(parts[0], ','); + std::vector v_geom = split(parts[1], ','); + std::string scrollbar_name = parts[2]; + std::string orientation = parts[3]; + f32 scroll_factor = 0.1f; + if (parts.size() >= 5 && !parts[4].empty()) + scroll_factor = stof(parts[4]); + + MY_CHECKPOS("scroll_container", 0); + MY_CHECKGEOM("scroll_container", 1); + + v2s32 pos = getRealCoordinateBasePos(v_pos); + v2s32 geom = getRealCoordinateGeometry(v_geom); + + if (orientation == "vertical") + scroll_factor *= -imgsize.Y; + else if (orientation == "horizontal") + scroll_factor *= -imgsize.X; + else + warningstream << "GUIFormSpecMenu::parseScrollContainer(): " + << "Invalid scroll_container orientation: " << orientation + << std::endl; + + // old parent (at first: this) + // ^ is parent of clipper + // ^ is parent of mover + // ^ is parent of other elements + + // make clipper + core::rect rect_clipper = core::rect(pos, pos + geom); + + gui::IGUIElement *clipper = new gui::IGUIElement(EGUIET_ELEMENT, Environment, + data->current_parent, 0, rect_clipper); + + // make mover + FieldSpec spec_mover( + "", + L"", + L"", + 258 + m_fields.size() + ); + + core::rect rect_mover = core::rect(0, 0, geom.X, geom.Y); + + GUIScrollContainer *mover = new GUIScrollContainer(Environment, + clipper, spec_mover.fid, rect_mover, orientation, scroll_factor); + + data->current_parent = mover; + + m_scroll_containers.emplace_back(scrollbar_name, mover); + + m_fields.push_back(spec_mover); + + clipper->drop(); + + // remove interferring offset of normal containers + container_stack.push(pos_offset); + pos_offset.X = 0.0f; + pos_offset.Y = 0.0f; +} + +void GUIFormSpecMenu::parseScrollContainerEnd(parserData *data) +{ + if (data->current_parent == this || data->current_parent->getParent() == this || + container_stack.empty()) { + errorstream << "Invalid scroll_container end element, " + << "no matching scroll_container start element" << std::endl; + return; + } + + if (pos_offset.getLengthSQ() != 0.0f) { + // pos_offset is only set by containers and scroll_containers. + // scroll_containers always set it to 0,0 which means that if it is + // not 0,0, it is a normal container that was opened last, not a + // scroll_container + errorstream << "Invalid scroll_container end element, " + << "an inner container was left open" << std::endl; + return; + } + + data->current_parent = data->current_parent->getParent()->getParent(); + pos_offset = container_stack.top(); + container_stack.pop(); +} + void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) { if (m_client == 0) { @@ -443,9 +542,9 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) pos.X + (geom.X - 1) * slot_spacing.X + imgsize.X, pos.Y + (geom.Y - 1) * slot_spacing.Y + imgsize.Y); - GUIInventoryList *e = new GUIInventoryList(Environment, this, spec.fid, - rect, m_invmgr, loc, listname, geom, start_i, imgsize, slot_spacing, - this, data->inventorylist_options, m_font); + GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent, + spec.fid, rect, m_invmgr, loc, listname, geom, start_i, imgsize, + slot_spacing, this, data->inventorylist_options, m_font); m_inventorylists.push_back(e); m_fields.push_back(spec); @@ -550,8 +649,8 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element spec.ftype = f_CheckBox; - gui::IGUICheckBox *e = Environment->addCheckBox(fselected, rect, this, - spec.fid, spec.flabel.c_str()); + gui::IGUICheckBox *e = Environment->addCheckBox(fselected, rect, + data->current_parent, spec.fid, spec.flabel.c_str()); auto style = getDefaultStyleForElement("checkbox", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); @@ -610,8 +709,8 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen spec.ftype = f_ScrollBar; spec.send = true; - GUIScrollBar *e = new GUIScrollBar(Environment, this, spec.fid, rect, - is_horizontal, true); + GUIScrollBar *e = new GUIScrollBar(Environment, data->current_parent, + spec.fid, rect, is_horizontal, true); auto style = getDefaultStyleForElement("scrollbar", name); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); @@ -737,7 +836,8 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) 1 ); core::rect rect(pos, pos + geom); - gui::IGUIImage *e = Environment->addImage(rect, this, spec.fid, 0, true); + gui::IGUIImage *e = Environment->addImage(rect, data->current_parent, + spec.fid, 0, true); e->setImage(texture); e->setScaleImage(true); auto style = getDefaultStyleForElement("image", spec.fname); @@ -774,8 +874,8 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) L"", 258 + m_fields.size() ); - gui::IGUIImage *e = Environment->addImage(texture, pos, true, this, - spec.fid, 0); + gui::IGUIImage *e = Environment->addImage(texture, pos, true, + data->current_parent, spec.fid, 0); auto style = getDefaultStyleForElement("image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); @@ -886,7 +986,7 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen ); spec.ftype = f_ItemImage; - GUIItemImage *e = new GUIItemImage(Environment, this, spec.fid, + GUIItemImage *e = new GUIItemImage(Environment, data->current_parent, spec.fid, core::rect(pos, pos + geom), name, m_font, m_client); auto style = getDefaultStyleForElement("item_image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); @@ -949,8 +1049,8 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element, if(type == "button_exit") spec.is_exit = true; - GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, this, - spec.fid, spec.flabel.c_str()); + GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, + data->current_parent, spec.fid, spec.flabel.c_str()); auto style = getStyleForElement(type, name, (type != "button") ? "button" : ""); e->setStyles(style); @@ -1141,7 +1241,8 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element) } //now really show table - GUITable *e = new GUITable(Environment, this, spec.fid, rect, m_tsrc); + GUITable *e = new GUITable(Environment, data->current_parent, spec.fid, + rect, m_tsrc); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); @@ -1217,7 +1318,8 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element } //now really show list - GUITable *e = new GUITable(Environment, this, spec.fid, rect, m_tsrc); + GUITable *e = new GUITable(Environment, data->current_parent, spec.fid, + rect, m_tsrc); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); @@ -1293,7 +1395,8 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element spec.send = true; //now really show list - gui::IGUIComboBox *e = Environment->addComboBox(rect, this, spec.fid); + gui::IGUIComboBox *e = Environment->addComboBox(rect, data->current_parent, + spec.fid); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); @@ -1379,7 +1482,8 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element ); spec.send = true; - gui::IGUIEditBox * e = Environment->addEditBox(0, rect, true, this, spec.fid); + gui::IGUIEditBox *e = Environment->addEditBox(0, rect, true, + data->current_parent, spec.fid); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); @@ -1390,7 +1494,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element rect.UpperLeftCorner.Y -= font_height; rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height; gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, - this, 0); + data->current_parent, 0); } e->setPasswordBox(true,L'*'); @@ -1425,7 +1529,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, if (!is_editable && !is_multiline) { // spec field id to 0, this stops submit searching for a value that isn't there gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, - this, 0); + data->current_parent, 0); return; } @@ -1443,14 +1547,14 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, if (use_intl_edit_box && g_settings->getBool("freetype")) { e = new gui::intlGUIEditBox(spec.fdefault.c_str(), true, Environment, - this, spec.fid, rect, is_editable, is_multiline); + data->current_parent, spec.fid, rect, is_editable, is_multiline); } else { if (is_multiline) { - e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, - Environment, this, spec.fid, rect, is_editable, true); + e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment, + data->current_parent, spec.fid, rect, is_editable, true); } else if (is_editable) { - e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, - spec.fid); + e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, + data->current_parent, spec.fid); e->grab(); } } @@ -1491,7 +1595,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, rect.UpperLeftCorner.Y -= font_height; rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height; IGUIElement *t = gui::StaticText::add(Environment, spec.flabel.c_str(), - rect, false, true, this, 0); + rect, false, true, data->current_parent, 0); if (t) t->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); @@ -1671,8 +1775,8 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen ); spec.ftype = f_HyperText; - GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment, this, - spec.fid, rect, m_client, m_tsrc); + GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment, + data->current_parent, spec.fid, rect, m_client, m_tsrc); e->drop(); m_fields.push_back(spec); @@ -1750,7 +1854,8 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) 4 ); gui::IGUIStaticText *e = gui::StaticText::add(Environment, - spec.flabel.c_str(), rect, false, false, this, spec.fid); + spec.flabel.c_str(), rect, false, false, data->current_parent, + spec.fid); e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER); auto style = getDefaultStyleForElement("label", spec.fname); @@ -1830,7 +1935,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen 258 + m_fields.size() ); gui::IGUIStaticText *e = gui::StaticText::add(Environment, spec.flabel.c_str(), - rect, false, false, this, spec.fid); + rect, false, false, data->current_parent, spec.fid); e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); auto style = getDefaultStyleForElement("vertlabel", spec.fname, "label"); @@ -1904,7 +2009,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem spec.is_exit = true; GUIButtonImage *e = GUIButtonImage::addButton(Environment, rect, m_tsrc, - this, spec.fid, spec.flabel.c_str()); + data->current_parent, spec.fid, spec.flabel.c_str()); if (spec.fname == data->focused_fieldname) { Environment->setFocus(e); @@ -2010,8 +2115,8 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen core::rect rect = core::rect(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); - gui::IGUITabControl *e = Environment->addTabControl(rect, this, - show_background, show_border, spec.fid); + gui::IGUITabControl *e = Environment->addTabControl(rect, + data->current_parent, show_background, show_border, spec.fid); e->setAlignment(irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_LOWERRIGHT); e->setTabHeight(geom.Y); @@ -2046,7 +2151,6 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &element) { - if (m_client == 0) { warningstream << "invalid use of item_image_button with m_client==0" << std::endl; @@ -2106,7 +2210,7 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string & ); GUIButtonItemImage *e_btn = GUIButtonItemImage::addButton(Environment, - rect, m_tsrc, this, spec_btn.fid, spec_btn.flabel.c_str(), + rect, m_tsrc, data->current_parent, spec_btn.fid, spec_btn.flabel.c_str(), item_name, m_client); auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button"); @@ -2164,7 +2268,8 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element) core::rect rect(pos, pos + geom); - GUIBox *e = new GUIBox(Environment, this, spec.fid, rect, tmp_color); + GUIBox *e = new GUIBox(Environment, data->current_parent, spec.fid, + rect, tmp_color); auto style = getDefaultStyleForElement("box", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); @@ -2316,7 +2421,7 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element) core::rect rect(pos, pos + geom); gui::IGUIElement *e = new gui::IGUIElement(EGUIET_ELEMENT, Environment, - this, fieldspec.fid, rect); + data->current_parent, fieldspec.fid, rect); // the element the rect tooltip is bound to should not block mouse-clicks e->setVisible(false); @@ -2775,6 +2880,16 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) return; } + if (type == "scroll_container") { + parseScrollContainer(data, description); + return; + } + + if (type == "scroll_container_end") { + parseScrollContainerEnd(data); + return; + } + // Ignore others infostream << "Unknown DrawSpec: type=" << type << ", data=\"" << description << "\"" << std::endl; @@ -2831,8 +2946,10 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) tooltip_rect_it.first->drop(); for (auto &clickthrough_it : m_clickthrough_elements) clickthrough_it->drop(); + for (auto &scroll_container_it : m_scroll_containers) + scroll_container_it.second->drop(); - mydata.size= v2s32(100,100); + mydata.size = v2s32(100, 100); mydata.screensize = screensize; mydata.offset = v2f32(0.5f, 0.5f); mydata.anchor = v2f32(0.5f, 0.5f); @@ -2841,6 +2958,9 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) // Base position of contents of form mydata.basepos = getBasePos(); + // the parent for the parsed elements + mydata.current_parent = this; + m_inventorylists.clear(); m_backgrounds.clear(); m_tables.clear(); @@ -2851,6 +2971,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) m_tooltip_rects.clear(); m_inventory_rings.clear(); m_dropdowns.clear(); + m_scroll_containers.clear(); theme_by_name.clear(); theme_by_type.clear(); m_clickthrough_elements.clear(); @@ -3117,11 +3238,24 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) parseElement(&mydata, elements[i]); } - if (!container_stack.empty()) { + if (mydata.current_parent != this) { + errorstream << "Invalid formspec string: scroll_container was never closed!" + << std::endl; + } else if (!container_stack.empty()) { errorstream << "Invalid formspec string: container was never closed!" << std::endl; } + // get the scrollbar elements for scroll_containers + for (const std::pair &c : m_scroll_containers) { + for (const std::pair &b : m_scrollbars) { + if (c.first == b.first.fname) { + c.second->setScrollBar(b.second); + break; + } + } + } + // If there are fields without explicit size[], add a "Proceed" // button and adjust size to fit all the fields. if (mydata.simple_field_count > 0 && !mydata.explicit_size) { @@ -4418,6 +4552,12 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } } + if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) { + // move scroll_containers + for (const std::pair &c : m_scroll_containers) + c.second->onScrollEvent(event.GUIEvent.Caller); + } + if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) { if (event.GUIEvent.Caller->getID() > 257) { bool close_on_enter = true; diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index dc22e8b54..28088416d 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -39,6 +39,7 @@ class ISimpleTextureSource; class Client; class GUIScrollBar; class TexturePool; +class GUIScrollContainer; typedef enum { f_Button, @@ -310,6 +311,7 @@ protected: std::vector> m_scrollbars; std::vector>> m_dropdowns; std::vector m_clickthrough_elements; + std::vector> m_scroll_containers; GUIInventoryList::ItemSpec *m_selected_item = nullptr; u16 m_selected_amount = 0; @@ -359,6 +361,7 @@ private: std::string focused_fieldname; GUITable::TableOptions table_options; GUITable::TableColumns table_columns; + gui::IGUIElement *current_parent = nullptr; GUIInventoryList::Options inventorylist_options; @@ -391,6 +394,8 @@ private: void parseSize(parserData* data, const std::string &element); void parseContainer(parserData* data, const std::string &element); void parseContainerEnd(parserData* data); + void parseScrollContainer(parserData *data, const std::string &element); + void parseScrollContainerEnd(parserData *data); void parseList(parserData* data, const std::string &element); void parseListRing(parserData* data, const std::string &element); void parseCheckbox(parserData* data, const std::string &element); diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index e107b5a3e..88931cdf9 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -917,20 +917,20 @@ void TextDrawer::place(const core::rect &dest_rect) // Draw text in a rectangle with a given offset. Items are actually placed in // relative (to upper left corner) coordinates. -void TextDrawer::draw(const core::rect &dest_rect, +void TextDrawer::draw(const core::rect &clip_rect, const core::position2d &dest_offset) { irr::video::IVideoDriver *driver = m_environment->getVideoDriver(); - core::position2d offset = dest_rect.UpperLeftCorner + dest_offset; + core::position2d offset = dest_offset; offset.Y += m_voffset; if (m_text.background_type == ParsedText::BACKGROUND_COLOR) - driver->draw2DRectangle(m_text.background_color, dest_rect); + driver->draw2DRectangle(m_text.background_color, clip_rect); for (auto &p : m_text.m_paragraphs) { for (auto &el : p.elements) { core::rect rect(el.pos + offset, el.dim); - if (!rect.isRectCollided(dest_rect)) + if (!rect.isRectCollided(clip_rect)) continue; switch (el.type) { @@ -947,7 +947,7 @@ void TextDrawer::draw(const core::rect &dest_rect, if (el.type == ParsedText::ELEMENT_TEXT) el.font->draw(el.text, rect, color, false, true, - &dest_rect); + &clip_rect); if (el.underline && el.drawwidth) { s32 linepos = el.pos.Y + offset.Y + @@ -958,7 +958,7 @@ void TextDrawer::draw(const core::rect &dest_rect, el.pos.X + offset.X + el.drawwidth, linepos + (el.baseline >> 3)); - driver->draw2DRectangle(color, linerect, &dest_rect); + driver->draw2DRectangle(color, linerect, &clip_rect); } } break; @@ -972,7 +972,7 @@ void TextDrawer::draw(const core::rect &dest_rect, irr::core::rect( core::position2d(0, 0), texture->getOriginalSize()), - &dest_rect, 0, true); + &clip_rect, 0, true); } break; case ParsedText::ELEMENT_ITEM: { @@ -982,7 +982,7 @@ void TextDrawer::draw(const core::rect &dest_rect, drawItemStack( m_environment->getVideoDriver(), - g_fontengine->getFont(), item, rect, &dest_rect, + g_fontengine->getFont(), item, rect, &clip_rect, m_client, IT_ROT_OTHER, el.angle, el.rotation ); } break; @@ -1094,6 +1094,7 @@ bool GUIHyperText::OnEvent(const SEvent &event) m_text_scrollpos.Y = -m_vscrollbar->getPos(); m_drawer.draw(m_display_text_rect, m_text_scrollpos); checkHover(event.MouseInput.X, event.MouseInput.Y); + return true; } else if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { ParsedText::Element *element = getElementAt( @@ -1151,7 +1152,8 @@ void GUIHyperText::draw() m_vscrollbar->setPos(0); m_vscrollbar->setVisible(false); } - m_drawer.draw(m_display_text_rect, m_text_scrollpos); + m_drawer.draw(AbsoluteClippingRect, + m_display_text_rect.UpperLeftCorner + m_text_scrollpos); // draw children IGUIElement::draw(); diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index c55f8a705..5b936262e 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -174,7 +174,7 @@ public: void place(const core::rect &dest_rect); inline s32 getHeight() { return m_height; }; - void draw(const core::rect &dest_rect, + void draw(const core::rect &clip_rect, const core::position2d &dest_offset); ParsedText::Element *getElementAt(core::position2d pos); ParsedText::Tag *m_hovertag; diff --git a/src/gui/guiScrollContainer.cpp b/src/gui/guiScrollContainer.cpp new file mode 100644 index 000000000..88cdc7057 --- /dev/null +++ b/src/gui/guiScrollContainer.cpp @@ -0,0 +1,70 @@ +/* +Minetest +Copyright (C) 2020 DS + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "guiScrollContainer.h" + +GUIScrollContainer::GUIScrollContainer(gui::IGUIEnvironment *env, + gui::IGUIElement *parent, s32 id, const core::rect &rectangle, + const std::string &orientation, f32 scrollfactor) : + gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle), + m_scrollbar(nullptr), m_scrollfactor(scrollfactor) +{ + if (orientation == "vertical") + m_orientation = VERTICAL; + else if (orientation == "horizontal") + m_orientation = HORIZONTAL; + else + m_orientation = UNDEFINED; +} + +bool GUIScrollContainer::OnEvent(const SEvent &event) +{ + if (event.EventType == EET_MOUSE_INPUT_EVENT && + event.MouseInput.Event == EMIE_MOUSE_WHEEL && + !event.MouseInput.isLeftPressed() && m_scrollbar) { + Environment->setFocus(m_scrollbar); + bool retval = m_scrollbar->OnEvent(event); + + // a hacky fix for updating the hovering and co. + IGUIElement *hovered_elem = getElementFromPoint(core::position2d( + event.MouseInput.X, event.MouseInput.Y)); + SEvent mov_event = event; + mov_event.MouseInput.Event = EMIE_MOUSE_MOVED; + Environment->postEventFromUser(mov_event); + if (hovered_elem) + hovered_elem->OnEvent(mov_event); + + return retval; + } + + return IGUIElement::OnEvent(event); +} + +void GUIScrollContainer::updateScrolling() +{ + s32 pos = m_scrollbar->getPos(); + core::rect rect = getRelativePosition(); + + if (m_orientation == VERTICAL) + rect.UpperLeftCorner.Y = pos * m_scrollfactor; + else if (m_orientation == HORIZONTAL) + rect.UpperLeftCorner.X = pos * m_scrollfactor; + + setRelativePosition(rect); +} diff --git a/src/gui/guiScrollContainer.h b/src/gui/guiScrollContainer.h new file mode 100644 index 000000000..9eaa880bf --- /dev/null +++ b/src/gui/guiScrollContainer.h @@ -0,0 +1,56 @@ +/* +Minetest +Copyright (C) 2020 DS + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "irrlichttypes_extrabloated.h" +#include "util/string.h" +#include "guiScrollBar.h" + +class GUIScrollContainer : public gui::IGUIElement +{ +public: + GUIScrollContainer(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, + const core::rect &rectangle, const std::string &orientation, + f32 scrollfactor); + + virtual bool OnEvent(const SEvent &event) override; + + inline void onScrollEvent(gui::IGUIElement *caller) + { + if (caller == m_scrollbar) + updateScrolling(); + } + + inline void setScrollBar(GUIScrollBar *scrollbar) { m_scrollbar = scrollbar; } + +private: + enum OrientationEnum + { + VERTICAL, + HORIZONTAL, + UNDEFINED + }; + + GUIScrollBar *m_scrollbar; + OrientationEnum m_orientation; + f32 m_scrollfactor; + + void updateScrolling(); +}; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 7223ce05c..4b7345b15 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -237,6 +237,7 @@ with this program; if not, write to the Free Software Foundation, Inc., Formspec elements are drawn in the order of definition bgcolor[]: use 3 parameters (bgcolor, formspec (now an enum), fbgcolor) box[] and image[] elements enable clipping by default + new element: scroll_container[] */ #define FORMSPEC_API_VERSION 3 -- cgit v1.2.3 From 7e21b3cd4883eb8b9eb7e9ca49e50f6f0c7bc0d6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 13 Apr 2020 20:26:54 +0200 Subject: Remove sound menu and show proper msgs if sound is off (#9069) --- src/client/game.cpp | 66 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index ac6045190..f7234eea6 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1922,29 +1922,47 @@ void Game::processKeyInput() toggleFast(); } else if (wasKeyDown(KeyType::NOCLIP)) { toggleNoClip(); +#if USE_SOUND } else if (wasKeyDown(KeyType::MUTE)) { - bool new_mute_sound = !g_settings->getBool("mute_sound"); - g_settings->setBool("mute_sound", new_mute_sound); - if (new_mute_sound) - m_game_ui->showTranslatedStatusText("Sound muted"); - else - m_game_ui->showTranslatedStatusText("Sound unmuted"); + if (g_settings->getBool("enable_sound")) { + bool new_mute_sound = !g_settings->getBool("mute_sound"); + g_settings->setBool("mute_sound", new_mute_sound); + if (new_mute_sound) + m_game_ui->showTranslatedStatusText("Sound muted"); + else + m_game_ui->showTranslatedStatusText("Sound unmuted"); + } else { + m_game_ui->showTranslatedStatusText("Sound system is disabled"); + } } else if (wasKeyDown(KeyType::INC_VOLUME)) { - float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f); - wchar_t buf[100]; - g_settings->setFloat("sound_volume", new_volume); - const wchar_t *str = wgettext("Volume changed to %d%%"); - swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100)); - delete[] str; - m_game_ui->showStatusText(buf); + if (g_settings->getBool("enable_sound")) { + float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f); + wchar_t buf[100]; + g_settings->setFloat("sound_volume", new_volume); + const wchar_t *str = wgettext("Volume changed to %d%%"); + swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100)); + delete[] str; + m_game_ui->showStatusText(buf); + } else { + m_game_ui->showTranslatedStatusText("Sound system is disabled"); + } } else if (wasKeyDown(KeyType::DEC_VOLUME)) { - float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f); - wchar_t buf[100]; - g_settings->setFloat("sound_volume", new_volume); - const wchar_t *str = wgettext("Volume changed to %d%%"); - swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100)); - delete[] str; - m_game_ui->showStatusText(buf); + if (g_settings->getBool("enable_sound")) { + float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f); + wchar_t buf[100]; + g_settings->setFloat("sound_volume", new_volume); + const wchar_t *str = wgettext("Volume changed to %d%%"); + swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100)); + delete[] str; + m_game_ui->showStatusText(buf); + } else { + m_game_ui->showTranslatedStatusText("Sound system is disabled"); + } +#else + } else if (wasKeyDown(KeyType::MUTE) || wasKeyDown(KeyType::INC_VOLUME) + || wasKeyDown(KeyType::DEC_VOLUME)) { + m_game_ui->showTranslatedStatusText("Sound system is not supported on this build"); +#endif } else if (wasKeyDown(KeyType::CINEMATIC)) { toggleCinematic(); } else if (wasKeyDown(KeyType::SCREENSHOT)) { @@ -4162,8 +4180,12 @@ void Game::showPauseMenu() } #ifndef __ANDROID__ - os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;" - << strgettext("Sound Volume") << "]"; +#if USE_SOUND + if (g_settings->getBool("enable_sound")) { + os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;" + << strgettext("Sound Volume") << "]"; + } +#endif os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;" << strgettext("Change Keys") << "]"; #endif -- cgit v1.2.3 From 5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Tue, 14 Apr 2020 14:41:29 -0400 Subject: Refactor texture overrides and add new features (#9600) * Refactor texture overrides, and add new features: - Texture overrides can support multiple targets in one line - Texture override files can have comment lines - Item images/wield images can be overridden * Formatting changes * Address soime feedback - Pass vectors by const reference - Log syntax errors as warnings - Remove 'C' prefix from TextureOverrideSource * Simplify override target checks with an inline helper function * make linter happy * Apply feedback suggestions Co-Authored-By: rubenwardy * Remove remaining != 0 checks * Update copyright notice Co-authored-by: sfan5 Co-authored-by: rubenwardy --- doc/texture_packs.txt | 45 +++++++++---- src/CMakeLists.txt | 1 + src/client/client.cpp | 7 +- src/itemdef.cpp | 19 ++++++ src/itemdef.h | 5 ++ src/nodedef.cpp | 67 ++++++------------ src/nodedef.h | 12 ++-- src/server.cpp | 7 +- src/texture_override.cpp | 120 +++++++++++++++++++++++++++++++++ src/texture_override.h | 72 ++++++++++++++++++++ util/travis/clang-format-whitelist.txt | 1 + 11 files changed, 285 insertions(+), 71 deletions(-) create mode 100644 src/texture_override.cpp create mode 100644 src/texture_override.h (limited to 'src') diff --git a/doc/texture_packs.txt b/doc/texture_packs.txt index 7ab0aca94..4e7bc93c4 100644 --- a/doc/texture_packs.txt +++ b/doc/texture_packs.txt @@ -145,34 +145,51 @@ are placeholders intended to be overwritten by the game. Texture Overrides ----------------- -You can override the textures of a node from a texture pack using -texture overrides. To do this, create a file in a texture pack -called override.txt +You can override the textures of nodes and items from a +texture pack using texture overrides. To do this, create one or +more files in a texture pack called override.txt Each line in an override.txt file is a rule. It consists of - nodename face-selector texture + itemname target texture For example, default:dirt_with_grass sides default_stone.png -You can use ^ operators as usual: +or + + default:sword_steel inventory my_steel_sword.png + +You can list multiple targets on one line as a comma-separated list: + + default:tree top,bottom my_special_tree.png + +You can use texture modifiers, as usual: default:dirt_with_grass sides default_stone.png^[brighten -Here are face selectors you can choose from: +Finally, if a line is empty or starts with '#' it will be considered +a comment and not read as a rule. You can use this to better organize +your override.txt files. + +Here are targets you can choose from: -| face-selector | behavior | +| target | behavior | |---------------|---------------------------------------------------| -| left | x- | -| right | x+ | -| front | z- | -| back | z+ | -| top | y+ | -| bottom | y- | -| sides | x-, x+, z-, z+ | +| left | x- face | +| right | x+ face | +| front | z- face | +| back | z+ face | +| top | y+ face | +| bottom | y- face | +| sides | x-, x+, z-, z+ faces | | all | All faces. You can also use '*' instead of 'all'. | +| inventory | The inventory texture | +| wield | The texture used when held by the player | + +Nodes support all targets, but other items only support 'inventory' +and 'wield' Designing leaves textures for the leaves rendering options ---------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0b550c09c..fa261547b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -423,6 +423,7 @@ set(common_SRCS settings.cpp staticobject.cpp terminal_chat_console.cpp + texture_override.cpp tileanimation.cpp tool.cpp translation.cpp diff --git a/src/client/client.cpp b/src/client/client.cpp index c3e2a4d2a..8ee0869cd 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1742,8 +1742,11 @@ void Client::afterContentReceived() text = wgettext("Initializing nodes..."); RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 72); m_nodedef->updateAliases(m_itemdef); - for (const auto &path : getTextureDirs()) - m_nodedef->applyTextureOverrides(path + DIR_DELIM + "override.txt"); + for (const auto &path : getTextureDirs()) { + TextureOverrideSource override_source(path + DIR_DELIM + "override.txt"); + m_nodedef->applyTextureOverrides(override_source.getNodeTileOverrides()); + m_itemdef->applyTextureOverrides(override_source.getItemTextureOverrides()); + } m_nodedef->setNodeRegistrationStatus(true); m_nodedef->runNodeResolveCallbacks(); delete[] text; diff --git a/src/itemdef.cpp b/src/itemdef.cpp index ba7bd6a0b..a13b3f7d4 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -422,6 +422,25 @@ public: return get(stack.name).color; } #endif + void applyTextureOverrides(const std::vector &overrides) + { + infostream << "ItemDefManager::applyTextureOverrides(): Applying " + "overrides to textures" << std::endl; + + for (const TextureOverride& texture_override : overrides) { + if (m_item_definitions.find(texture_override.id) == m_item_definitions.end()) { + continue; // Ignore unknown item + } + + ItemDefinition* itemdef = m_item_definitions[texture_override.id]; + + if (texture_override.hasTarget(OverrideTarget::INVENTORY)) + itemdef->inventory_image = texture_override.texture; + + if (texture_override.hasTarget(OverrideTarget::WIELD)) + itemdef->wield_image = texture_override.texture; + } + } void clear() { for(std::map::const_iterator diff --git a/src/itemdef.h b/src/itemdef.h index 45cff582a..f47e6cbe7 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "itemgroup.h" #include "sound.h" +#include "texture_override.h" // TextureOverride class IGameDef; class Client; struct ToolCapabilities; @@ -157,6 +158,10 @@ public: Client *client) const=0; #endif + // Replace the textures of registered nodes with the ones specified in + // the texture pack's override.txt files + virtual void applyTextureOverrides(const std::vector &overrides)=0; + // Remove all registered item and node definitions and aliases // Then re-add the builtin item definitions virtual void clear()=0; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index b6eca9497..37332c3c6 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1304,60 +1304,35 @@ void NodeDefManager::updateAliases(IItemDefManager *idef) } } -void NodeDefManager::applyTextureOverrides(const std::string &override_filepath) +void NodeDefManager::applyTextureOverrides(const std::vector &overrides) { infostream << "NodeDefManager::applyTextureOverrides(): Applying " - "overrides to textures from " << override_filepath << std::endl; - - std::ifstream infile(override_filepath.c_str()); - std::string line; - int line_c = 0; - while (std::getline(infile, line)) { - line_c++; - // Also trim '\r' on DOS-style files - line = trim(line); - if (line.empty()) - continue; - - std::vector splitted = str_split(line, ' '); - if (splitted.size() != 3) { - errorstream << override_filepath - << ":" << line_c << " Could not apply texture override \"" - << line << "\": Syntax error" << std::endl; - continue; - } + "overrides to textures" << std::endl; + for (const TextureOverride& texture_override : overrides) { content_t id; - if (!getId(splitted[0], id)) + if (!getId(texture_override.id, id)) continue; // Ignore unknown node ContentFeatures &nodedef = m_content_features[id]; - if (splitted[1] == "top") - nodedef.tiledef[0].name = splitted[2]; - else if (splitted[1] == "bottom") - nodedef.tiledef[1].name = splitted[2]; - else if (splitted[1] == "right") - nodedef.tiledef[2].name = splitted[2]; - else if (splitted[1] == "left") - nodedef.tiledef[3].name = splitted[2]; - else if (splitted[1] == "back") - nodedef.tiledef[4].name = splitted[2]; - else if (splitted[1] == "front") - nodedef.tiledef[5].name = splitted[2]; - else if (splitted[1] == "all" || splitted[1] == "*") - for (TileDef &i : nodedef.tiledef) - i.name = splitted[2]; - else if (splitted[1] == "sides") - for (int i = 2; i < 6; i++) - nodedef.tiledef[i].name = splitted[2]; - else { - errorstream << override_filepath - << ":" << line_c << " Could not apply texture override \"" - << line << "\": Unknown node side \"" - << splitted[1] << "\"" << std::endl; - continue; - } + if (texture_override.hasTarget(OverrideTarget::TOP)) + nodedef.tiledef[0].name = texture_override.texture; + + if (texture_override.hasTarget(OverrideTarget::BOTTOM)) + nodedef.tiledef[1].name = texture_override.texture; + + if (texture_override.hasTarget(OverrideTarget::RIGHT)) + nodedef.tiledef[2].name = texture_override.texture; + + if (texture_override.hasTarget(OverrideTarget::LEFT)) + nodedef.tiledef[3].name = texture_override.texture; + + if (texture_override.hasTarget(OverrideTarget::BACK)) + nodedef.tiledef[4].name = texture_override.texture; + + if (texture_override.hasTarget(OverrideTarget::FRONT)) + nodedef.tiledef[5].name = texture_override.texture; } } diff --git a/src/nodedef.h b/src/nodedef.h index 1a12aae93..c77d53324 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -33,6 +33,7 @@ class Client; #include "itemgroup.h" #include "sound.h" // SimpleSoundSpec #include "constants.h" // BS +#include "texture_override.h" // TextureOverride #include "tileanimation.h" // PROTOCOL_VERSION >= 37 @@ -583,15 +584,12 @@ public: void updateAliases(IItemDefManager *idef); /*! - * Reads the used texture pack's override.txt, and replaces the textures - * of registered nodes with the ones specified there. + * Replaces the textures of registered nodes with the ones specified in + * the texturepack's override.txt file * - * Format of the input file: in each line - * `node_name top|bottom|right|left|front|back|all|*|sides texture_name.png` - * - * @param override_filepath path to 'texturepack/override.txt' + * @param overrides the texture overrides */ - void applyTextureOverrides(const std::string &override_filepath); + void applyTextureOverrides(const std::vector &overrides); /*! * Only the client uses this. Loads textures and shaders required for diff --git a/src/server.cpp b/src/server.cpp index 85d07fbc4..b3992b9b1 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -373,8 +373,11 @@ void Server::init() std::vector paths; fs::GetRecursiveDirs(paths, g_settings->get("texture_path")); fs::GetRecursiveDirs(paths, m_gamespec.path + DIR_DELIM + "textures"); - for (const std::string &path : paths) - m_nodedef->applyTextureOverrides(path + DIR_DELIM + "override.txt"); + for (const std::string &path : paths) { + TextureOverrideSource override_source(path + DIR_DELIM + "override.txt"); + m_nodedef->applyTextureOverrides(override_source.getNodeTileOverrides()); + m_itemdef->applyTextureOverrides(override_source.getItemTextureOverrides()); + } m_nodedef->setNodeRegistrationStatus(true); diff --git a/src/texture_override.cpp b/src/texture_override.cpp new file mode 100644 index 000000000..10d129b87 --- /dev/null +++ b/src/texture_override.cpp @@ -0,0 +1,120 @@ +/* +Minetest +Copyright (C) 2020 Hugues Ross + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "texture_override.h" + +#include "log.h" +#include "util/string.h" +#include +#include + +TextureOverrideSource::TextureOverrideSource(std::string filepath) +{ + std::ifstream infile(filepath.c_str()); + std::string line; + int line_index = 0; + while (std::getline(infile, line)) { + line_index++; + + // Also trim '\r' on DOS-style files + line = trim(line); + + // Ignore empty lines and comments + if (line.empty() || line[0] == '#') + continue; + + std::vector splitted = str_split(line, ' '); + if (splitted.size() != 3) { + warningstream << filepath << ":" << line_index + << " Syntax error in texture override \"" << line + << "\": Expected 3 arguments, got " << splitted.size() + << std::endl; + continue; + } + + TextureOverride texture_override = {}; + texture_override.id = splitted[0]; + texture_override.texture = splitted[2]; + + // Parse the target mask + std::vector targets = str_split(splitted[1], ','); + for (const std::string &target : targets) { + if (target == "top") + texture_override.target |= static_cast(OverrideTarget::TOP); + else if (target == "bottom") + texture_override.target |= static_cast(OverrideTarget::BOTTOM); + else if (target == "left") + texture_override.target |= static_cast(OverrideTarget::LEFT); + else if (target == "right") + texture_override.target |= static_cast(OverrideTarget::RIGHT); + else if (target == "front") + texture_override.target |= static_cast(OverrideTarget::FRONT); + else if (target == "back") + texture_override.target |= static_cast(OverrideTarget::BACK); + else if (target == "inventory") + texture_override.target |= static_cast(OverrideTarget::INVENTORY); + else if (target == "wield") + texture_override.target |= static_cast(OverrideTarget::WIELD); + else if (target == "sides") + texture_override.target |= static_cast(OverrideTarget::SIDES); + else if (target == "all" || target == "*") + texture_override.target |= static_cast(OverrideTarget::ALL_FACES); + else { + // Report invalid target + warningstream << filepath << ":" << line_index + << " Syntax error in texture override \"" << line + << "\": Unknown target \"" << target << "\"" + << std::endl; + } + } + + // If there are no valid targets, skip adding this override + if (texture_override.target == static_cast(OverrideTarget::INVALID)) { + continue; + } + + m_overrides.push_back(texture_override); + } +} + +//! Get all overrides that apply to item definitions +std::vector TextureOverrideSource::getItemTextureOverrides() +{ + std::vector found_overrides; + + for (const TextureOverride &texture_override : m_overrides) { + if (texture_override.hasTarget(OverrideTarget::ITEM_TARGETS)) + found_overrides.push_back(texture_override); + } + + return found_overrides; +} + +//! Get all overrides that apply to node definitions +std::vector TextureOverrideSource::getNodeTileOverrides() +{ + std::vector found_overrides; + + for (const TextureOverride &texture_override : m_overrides) { + if (texture_override.hasTarget(OverrideTarget::ALL_FACES)) + found_overrides.push_back(texture_override); + } + + return found_overrides; +} diff --git a/src/texture_override.h b/src/texture_override.h new file mode 100644 index 000000000..db03bd014 --- /dev/null +++ b/src/texture_override.h @@ -0,0 +1,72 @@ +/* +Minetest +Copyright (C) 2020 Hugues Ross + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "irrlichttypes.h" +#include +#include + +//! Bitmask enum specifying what a texture override should apply to +enum class OverrideTarget : u8 +{ + INVALID = 0, + TOP = 1 << 0, + BOTTOM = 1 << 1, + LEFT = 1 << 2, + RIGHT = 1 << 3, + FRONT = 1 << 4, + BACK = 1 << 5, + INVENTORY = 1 << 6, + WIELD = 1 << 7, + + SIDES = LEFT | RIGHT | FRONT | BACK, + ALL_FACES = TOP | BOTTOM | SIDES, + ITEM_TARGETS = INVENTORY | WIELD, +}; + +struct TextureOverride +{ + std::string id; + std::string texture; + u8 target; + + // Helper function for checking if an OverrideTarget is found in + // a TextureOverride without casting + inline bool hasTarget(OverrideTarget overrideTarget) const + { + return (target & static_cast(overrideTarget)) != 0; + } +}; + +//! Class that provides texture override information from a texture pack +class TextureOverrideSource +{ +public: + TextureOverrideSource(std::string filepath); + + //! Get all overrides that apply to item definitions + std::vector getItemTextureOverrides(); + + //! Get all overrides that apply to node definitions + std::vector getNodeTileOverrides(); + +private: + std::vector m_overrides; +}; diff --git a/util/travis/clang-format-whitelist.txt b/util/travis/clang-format-whitelist.txt index bb97da7b5..02c8b2660 100644 --- a/util/travis/clang-format-whitelist.txt +++ b/util/travis/clang-format-whitelist.txt @@ -423,6 +423,7 @@ src/subgame.cpp src/subgame.h src/terminal_chat_console.cpp src/terminal_chat_console.h +src/texture_override.cpp src/threading/atomic.h src/threading/event.cpp src/threading/mutex_auto_lock.h -- cgit v1.2.3 From 7c43cf47c37b0204e34d12670d2e6975eb36b45a Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 14 Apr 2020 20:30:02 +0200 Subject: PostgreSQL: Fix listAllLoadableBlocks returning the same block Suggested change from https://github.com/minetest/minetest/issues/9670#issuecomment-613563738 --- src/database/database-postgresql.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index 77385e240..92816205c 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -301,7 +301,7 @@ void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) int numrows = PQntuples(results); for (int row = 0; row < numrows; ++row) - dst.push_back(pg_to_v3s16(results, 0, 0)); + dst.push_back(pg_to_v3s16(results, row, 0)); PQclear(results); } -- cgit v1.2.3 From 2d5bd3bf794672285cfc796edebab2f672f2cab0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 14 Apr 2020 20:44:18 +0200 Subject: scriptapi: Some small optimizations to value pushing (#9669) --- src/script/common/c_content.cpp | 34 ++++++++++++++++----------------- src/script/common/c_converter.cpp | 40 +++++++++++++++++++-------------------- src/script/lua_api/l_env.cpp | 8 ++++---- src/script/lua_api/l_mapgen.cpp | 15 +++++++-------- src/script/lua_api/l_noise.cpp | 14 +++++++------- src/script/lua_api/l_object.cpp | 9 +-------- src/script/lua_api/l_vmanip.cpp | 6 +++--- 7 files changed, 59 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index ff9ceec6d..d73ecedab 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -350,7 +350,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) push_v3f(L, prop->visual_size); lua_setfield(L, -2, "visual_size"); - lua_newtable(L); + lua_createtable(L, prop->textures.size(), 0); u16 i = 1; for (const std::string &texture : prop->textures) { lua_pushlstring(L, texture.c_str(), texture.size()); @@ -358,7 +358,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) } lua_setfield(L, -2, "textures"); - lua_newtable(L); + lua_createtable(L, prop->colors.size(), 0); i = 1; for (const video::SColor &color : prop->colors) { push_ARGB8(L, color); @@ -840,7 +840,7 @@ void push_content_features(lua_State *L, const ContentFeatures &c) lua_pushnumber(L, c.connect_sides); lua_setfield(L, -2, "connect_sides"); - lua_newtable(L); + lua_createtable(L, c.connects_to.size(), 0); u16 i = 1; for (const std::string &it : c.connects_to) { lua_pushlstring(L, it.c_str(), it.size()); @@ -963,7 +963,7 @@ void push_nodebox(lua_State *L, const NodeBox &box) void push_box(lua_State *L, const std::vector &box) { - lua_newtable(L); + lua_createtable(L, box.size(), 0); u8 i = 1; for (const aabb3f &it : box) { push_aabb3f(L, it); @@ -1040,7 +1040,7 @@ void read_soundspec(lua_State *L, int index, SimpleSoundSpec &spec) void push_soundspec(lua_State *L, const SimpleSoundSpec &spec) { - lua_newtable(L); + lua_createtable(L, 0, 3); lua_pushstring(L, spec.name.c_str()); lua_setfield(L, -2, "name"); lua_pushnumber(L, spec.gain); @@ -1125,12 +1125,12 @@ MapNode readnode(lua_State *L, int index, const NodeDefManager *ndef) /******************************************************************************/ void pushnode(lua_State *L, const MapNode &n, const NodeDefManager *ndef) { - lua_newtable(L); + lua_createtable(L, 0, 3); lua_pushstring(L, ndef->get(n).name.c_str()); lua_setfield(L, -2, "name"); - lua_pushnumber(L, n.getParam1()); + lua_pushinteger(L, n.getParam1()); lua_setfield(L, -2, "param1"); - lua_pushnumber(L, n.getParam2()); + lua_pushinteger(L, n.getParam2()); lua_setfield(L, -2, "param2"); } @@ -1163,7 +1163,7 @@ bool string_to_enum(const EnumString *spec, int &result, { const EnumString *esp = spec; while(esp->str){ - if(str == std::string(esp->str)){ + if (!strcmp(str.c_str(), esp->str)) { result = esp->num; return true; } @@ -1438,7 +1438,7 @@ ToolCapabilities read_tool_capabilities( /******************************************************************************/ void push_dig_params(lua_State *L,const DigParams ¶ms) { - lua_newtable(L); + lua_createtable(L, 0, 3); setboolfield(L, -1, "diggable", params.diggable); setfloatfield(L, -1, "time", params.time); setintfield(L, -1, "wear", params.wear); @@ -1447,7 +1447,7 @@ void push_dig_params(lua_State *L,const DigParams ¶ms) /******************************************************************************/ void push_hit_params(lua_State *L,const HitParams ¶ms) { - lua_newtable(L); + lua_createtable(L, 0, 3); setintfield(L, -1, "hp", params.hp); setintfield(L, -1, "wear", params.wear); } @@ -1540,9 +1540,9 @@ void read_groups(lua_State *L, int index, ItemGroupList &result) /******************************************************************************/ void push_groups(lua_State *L, const ItemGroupList &groups) { - lua_newtable(L); + lua_createtable(L, 0, groups.size()); for (const auto &group : groups) { - lua_pushnumber(L, group.second); + lua_pushinteger(L, group.second); lua_setfield(L, -2, group.first.c_str()); } } @@ -1587,7 +1587,7 @@ void luaentity_get(lua_State *L, u16 id) lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); - lua_pushnumber(L, id); + lua_pushinteger(L, id); lua_gettable(L, -2); lua_remove(L, -2); // Remove luaentities lua_remove(L, -2); // Remove core @@ -1689,7 +1689,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, lua_pushboolean(L, value.asInt()); break; case Json::arrayValue: - lua_newtable(L); + lua_createtable(L, value.size(), 0); for (Json::Value::const_iterator it = value.begin(); it != value.end(); ++it) { push_json_value_helper(L, *it, nullindex); @@ -1697,7 +1697,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, } break; case Json::objectValue: - lua_newtable(L); + lua_createtable(L, 0, value.size()); for (Json::Value::const_iterator it = value.begin(); it != value.end(); ++it) { #ifndef JSONCPP_STRING @@ -1824,7 +1824,7 @@ void push_objectRef(lua_State *L, const u16 id) lua_getglobal(L, "core"); lua_getfield(L, -1, "object_refs"); luaL_checktype(L, -1, LUA_TTABLE); - lua_pushnumber(L, id); + lua_pushinteger(L, id); lua_gettable(L, -2); lua_remove(L, -2); // object_refs lua_remove(L, -2); // core diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 3c2f75641..334af61c3 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -62,7 +62,7 @@ void push_float_string(lua_State *L, float value) void push_v3f(lua_State *L, v3f p) { - lua_newtable(L); + lua_createtable(L, 0, 3); lua_pushnumber(L, p.X); lua_setfield(L, -2, "x"); lua_pushnumber(L, p.Y); @@ -73,7 +73,7 @@ void push_v3f(lua_State *L, v3f p) void push_v2f(lua_State *L, v2f p) { - lua_newtable(L); + lua_createtable(L, 0, 2); lua_pushnumber(L, p.X); lua_setfield(L, -2, "x"); lua_pushnumber(L, p.Y); @@ -82,7 +82,7 @@ void push_v2f(lua_State *L, v2f p) void push_v3_float_string(lua_State *L, v3f p) { - lua_newtable(L); + lua_createtable(L, 0, 3); push_float_string(L, p.X); lua_setfield(L, -2, "x"); push_float_string(L, p.Y); @@ -93,7 +93,7 @@ void push_v3_float_string(lua_State *L, v3f p) void push_v2_float_string(lua_State *L, v2f p) { - lua_newtable(L); + lua_createtable(L, 0, 2); push_float_string(L, p.X); lua_setfield(L, -2, "x"); push_float_string(L, p.Y); @@ -115,19 +115,19 @@ v2s16 read_v2s16(lua_State *L, int index) void push_v2s16(lua_State *L, v2s16 p) { - lua_newtable(L); - lua_pushnumber(L, p.X); + lua_createtable(L, 0, 2); + lua_pushinteger(L, p.X); lua_setfield(L, -2, "x"); - lua_pushnumber(L, p.Y); + lua_pushinteger(L, p.Y); lua_setfield(L, -2, "y"); } void push_v2s32(lua_State *L, v2s32 p) { - lua_newtable(L); - lua_pushnumber(L, p.X); + lua_createtable(L, 0, 2); + lua_pushinteger(L, p.X); lua_setfield(L, -2, "x"); - lua_pushnumber(L, p.Y); + lua_pushinteger(L, p.Y); lua_setfield(L, -2, "y"); } @@ -250,14 +250,14 @@ v3d check_v3d(lua_State *L, int index) void push_ARGB8(lua_State *L, video::SColor color) { - lua_newtable(L); - lua_pushnumber(L, color.getAlpha()); + lua_createtable(L, 0, 4); + lua_pushinteger(L, color.getAlpha()); lua_setfield(L, -2, "a"); - lua_pushnumber(L, color.getRed()); + lua_pushinteger(L, color.getRed()); lua_setfield(L, -2, "r"); - lua_pushnumber(L, color.getGreen()); + lua_pushinteger(L, color.getGreen()); lua_setfield(L, -2, "g"); - lua_pushnumber(L, color.getBlue()); + lua_pushinteger(L, color.getBlue()); lua_setfield(L, -2, "b"); } @@ -274,12 +274,12 @@ v3f checkFloatPos(lua_State *L, int index) void push_v3s16(lua_State *L, v3s16 p) { - lua_newtable(L); - lua_pushnumber(L, p.X); + lua_createtable(L, 0, 3); + lua_pushinteger(L, p.X); lua_setfield(L, -2, "x"); - lua_pushnumber(L, p.Y); + lua_pushinteger(L, p.Y); lua_setfield(L, -2, "y"); - lua_pushnumber(L, p.Z); + lua_pushinteger(L, p.Z); lua_setfield(L, -2, "z"); } @@ -386,7 +386,7 @@ aabb3f read_aabb3f(lua_State *L, int index, f32 scale) void push_aabb3f(lua_State *L, aabb3f box) { - lua_newtable(L); + lua_createtable(L, 6, 0); lua_pushnumber(L, box.MinEdge.X); lua_rawseti(L, -2, 1); lua_pushnumber(L, box.MinEdge.Y); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index e3afe1862..8c45a1510 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -73,7 +73,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n, lua_remove(L, -2); // Remove core // Get registered_abms[m_id] - lua_pushnumber(L, m_id); + lua_pushinteger(L, m_id); lua_gettable(L, -2); if(lua_isnil(L, -1)) FATAL_ERROR(""); @@ -116,7 +116,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n) lua_remove(L, -2); // Remove core // Get registered_lbms[m_id] - lua_pushnumber(L, m_id); + lua_pushinteger(L, m_id); lua_gettable(L, -2); FATAL_ERROR_IF(lua_isnil(L, -1), "Entry with given id not found in registered_lbms table"); lua_remove(L, -2); // Remove registered_lbms @@ -550,7 +550,7 @@ int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L) std::vector positions = env->getMap().findNodesWithMetadata( check_v3s16(L, 1), check_v3s16(L, 2)); - lua_newtable(L); + lua_createtable(L, positions.size(), 0); for (size_t i = 0; i != positions.size(); i++) { push_v3s16(L, positions[i]); lua_rawseti(L, -2, i + 1); @@ -1197,7 +1197,7 @@ int ModApiEnvMod::l_find_path(lua_State *L) searchdistance, max_jump, max_drop, algo); if (!path.empty()) { - lua_newtable(L); + lua_createtable(L, path.size(), 0); int top = lua_gettop(L); unsigned int index = 1; for (const v3s16 &i : path) { diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index cb0d6ac95..afe77826a 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -710,7 +710,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) if (!mg->heightmap) return 0; - lua_newtable(L); + lua_createtable(L, maplen, 0); for (size_t i = 0; i != maplen; i++) { lua_pushinteger(L, mg->heightmap[i]); lua_rawseti(L, -2, i + 1); @@ -722,7 +722,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) if (!mg->biomegen) return 0; - lua_newtable(L); + lua_createtable(L, maplen, 0); for (size_t i = 0; i != maplen; i++) { lua_pushinteger(L, mg->biomegen->biomemap[i]); lua_rawseti(L, -2, i + 1); @@ -736,7 +736,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) BiomeGenOriginal *bg = (BiomeGenOriginal *)mg->biomegen; - lua_newtable(L); + lua_createtable(L, maplen, 0); for (size_t i = 0; i != maplen; i++) { lua_pushnumber(L, bg->heatmap[i]); lua_rawseti(L, -2, i + 1); @@ -751,7 +751,7 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) BiomeGenOriginal *bg = (BiomeGenOriginal *)mg->biomegen; - lua_newtable(L); + lua_createtable(L, maplen, 0); for (size_t i = 0; i != maplen; i++) { lua_pushnumber(L, bg->humidmap[i]); lua_rawseti(L, -2, i + 1); @@ -761,13 +761,12 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) } case MGOBJ_GENNOTIFY: { std::map >event_map; - std::map >::iterator it; mg->gennotify.getEvents(event_map); - lua_newtable(L); - for (it = event_map.begin(); it != event_map.end(); ++it) { - lua_newtable(L); + lua_createtable(L, 0, event_map.size()); + for (auto it = event_map.begin(); it != event_map.end(); ++it) { + lua_createtable(L, it->second.size(), 0); for (size_t j = 0; j != it->second.size(); j++) { push_v3s16(L, it->second[j]); diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index e38d319f4..9aeb15709 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -171,9 +171,9 @@ int LuaPerlinNoiseMap::l_get_2d_map(lua_State *L) Noise *n = o->noise; n->perlinMap2D(p.X, p.Y); - lua_newtable(L); + lua_createtable(L, n->sy, 0); for (u32 y = 0; y != n->sy; y++) { - lua_newtable(L); + lua_createtable(L, n->sx, 0); for (u32 x = 0; x != n->sx; x++) { lua_pushnumber(L, n->result[i++]); lua_rawseti(L, -2, x + 1); @@ -200,7 +200,7 @@ int LuaPerlinNoiseMap::l_get_2d_map_flat(lua_State *L) if (use_buffer) lua_pushvalue(L, 3); else - lua_newtable(L); + lua_createtable(L, maplen, 0); for (size_t i = 0; i != maplen; i++) { lua_pushnumber(L, n->result[i]); @@ -224,11 +224,11 @@ int LuaPerlinNoiseMap::l_get_3d_map(lua_State *L) Noise *n = o->noise; n->perlinMap3D(p.X, p.Y, p.Z); - lua_newtable(L); + lua_createtable(L, n->sz, 0); for (u32 z = 0; z != n->sz; z++) { - lua_newtable(L); + lua_createtable(L, n->sy, 0); for (u32 y = 0; y != n->sy; y++) { - lua_newtable(L); + lua_createtable(L, n->sx, 0); for (u32 x = 0; x != n->sx; x++) { lua_pushnumber(L, n->result[i++]); lua_rawseti(L, -2, x + 1); @@ -260,7 +260,7 @@ int LuaPerlinNoiseMap::l_get_3d_map_flat(lua_State *L) if (use_buffer) lua_pushvalue(L, 3); else - lua_newtable(L); + lua_createtable(L, maplen, 0); for (size_t i = 0; i != maplen; i++) { lua_pushnumber(L, n->result[i]); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index fa34260bf..bb1456ac9 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -123,14 +123,7 @@ int ObjectRef::l_get_pos(lua_State *L) ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; - v3f pos = co->getBasePosition() / BS; - lua_newtable(L); - lua_pushnumber(L, pos.X); - lua_setfield(L, -2, "x"); - lua_pushnumber(L, pos.Y); - lua_setfield(L, -2, "y"); - lua_pushnumber(L, pos.Z); - lua_setfield(L, -2, "z"); + push_v3f(L, co->getBasePosition() / BS); return 1; } diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp index fd73d21d1..b99b1d98c 100644 --- a/src/script/lua_api/l_vmanip.cpp +++ b/src/script/lua_api/l_vmanip.cpp @@ -72,7 +72,7 @@ int LuaVoxelManip::l_get_data(lua_State *L) if (use_buffer) lua_pushvalue(L, 2); else - lua_newtable(L); + lua_createtable(L, volume, 0); for (u32 i = 0; i != volume; i++) { lua_Integer cid = vm->m_data[i].getContent(); @@ -261,7 +261,7 @@ int LuaVoxelManip::l_get_light_data(lua_State *L) u32 volume = vm->m_area.getVolume(); - lua_newtable(L); + lua_createtable(L, volume, 0); for (u32 i = 0; i != volume; i++) { lua_Integer light = vm->m_data[i].param1; lua_pushinteger(L, light); @@ -309,7 +309,7 @@ int LuaVoxelManip::l_get_param2_data(lua_State *L) if (use_buffer) lua_pushvalue(L, 2); else - lua_newtable(L); + lua_createtable(L, volume, 0); for (u32 i = 0; i != volume; i++) { lua_Integer param2 = vm->m_data[i].param2; -- cgit v1.2.3 From 5c588f89e79e02cba392abe3d00688772321f88b Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Wed, 15 Apr 2020 08:01:11 +0200 Subject: Verify database connection on interval (#9665) --- src/database/database-postgresql.cpp | 38 +++++++++++++++++++++--------------- src/database/database-postgresql.h | 8 ++++++-- src/database/database-sqlite3.cpp | 26 ++++++++++++------------ src/database/database-sqlite3.h | 12 +++++++++--- src/database/database.h | 4 ++++ src/map.cpp | 5 +++++ src/map.h | 1 + src/serverenvironment.cpp | 5 +++++ src/serverenvironment.h | 1 + 9 files changed, 66 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index 92816205c..c1b81586d 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -90,13 +90,19 @@ void Database_PostgreSQL::connectToDatabase() initStatements(); } -void Database_PostgreSQL::verifyDatabase() +void Database_PostgreSQL::pingDatabase() { - if (PQstatus(m_conn) == CONNECTION_OK) - return; - - PQreset(m_conn); - ping(); + // Verify DB connection with ping + try { + ping(); + } catch (const DatabaseException &e) { + // If ping failed, show the error and try reconnect + PQreset(m_conn); + + errorstream << e.what() << std::endl + << "Reconnecting to database " << m_connect_string << std::endl; + connectToDatabase(); + } } void Database_PostgreSQL::ping() @@ -151,7 +157,7 @@ void Database_PostgreSQL::createTableIfNotExists(const std::string &table_name, void Database_PostgreSQL::beginSave() { - verifyDatabase(); + pingDatabase(); checkResults(PQexec(m_conn, "BEGIN;")); } @@ -227,7 +233,7 @@ bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) return false; } - verifyDatabase(); + pingDatabase(); s32 x, y, z; x = htonl(pos.X); @@ -251,7 +257,7 @@ bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block) { - verifyDatabase(); + pingDatabase(); s32 x, y, z; x = htonl(pos.X); @@ -275,7 +281,7 @@ void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block) bool MapDatabasePostgreSQL::deleteBlock(const v3s16 &pos) { - verifyDatabase(); + pingDatabase(); s32 x, y, z; x = htonl(pos.X); @@ -293,7 +299,7 @@ bool MapDatabasePostgreSQL::deleteBlock(const v3s16 &pos) void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) { - verifyDatabase(); + pingDatabase(); PGresult *results = execPrepared("list_all_loadable_blocks", 0, NULL, NULL, NULL, false, false); @@ -435,7 +441,7 @@ void PlayerDatabasePostgreSQL::initStatements() bool PlayerDatabasePostgreSQL::playerDataExists(const std::string &playername) { - verifyDatabase(); + pingDatabase(); const char *values[] = { playername.c_str() }; PGresult *results = execPrepared("load_player", 1, values, false); @@ -451,7 +457,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player) if (!sao) return; - verifyDatabase(); + pingDatabase(); v3f pos = sao->getBasePosition(); std::string pitch = ftos(sao->getLookPitch()); @@ -535,7 +541,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player) bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao) { sanity_check(sao); - verifyDatabase(); + pingDatabase(); const char *values[] = { player->getName() }; PGresult *results = execPrepared("load_player", 1, values, false, false); @@ -610,7 +616,7 @@ bool PlayerDatabasePostgreSQL::removePlayer(const std::string &name) if (!playerDataExists(name)) return false; - verifyDatabase(); + pingDatabase(); const char *values[] = { name.c_str() }; execPrepared("remove_player", 1, values); @@ -620,7 +626,7 @@ bool PlayerDatabasePostgreSQL::removePlayer(const std::string &name) void PlayerDatabasePostgreSQL::listPlayers(std::vector &res) { - verifyDatabase(); + pingDatabase(); PGresult *results = execPrepared("load_player_list", 0, NULL, false); diff --git a/src/database/database-postgresql.h b/src/database/database-postgresql.h index db0b505c9..5a8b89a51 100644 --- a/src/database/database-postgresql.h +++ b/src/database/database-postgresql.h @@ -32,12 +32,13 @@ public: Database_PostgreSQL(const std::string &connect_string); ~Database_PostgreSQL(); + virtual void pingDatabase(); + void beginSave(); void endSave(); bool initialized() const; - protected: // Conversion helpers inline int pg_to_int(PGresult *res, int row, int col) @@ -82,7 +83,6 @@ protected: } void createTableIfNotExists(const std::string &table_name, const std::string &definition); - void verifyDatabase(); // Database initialization void connectToDatabase(); @@ -113,6 +113,8 @@ public: MapDatabasePostgreSQL(const std::string &connect_string); virtual ~MapDatabasePostgreSQL() = default; + virtual void pingDatabase() { Database_PostgreSQL::pingDatabase(); } + bool saveBlock(const v3s16 &pos, const std::string &data); void loadBlock(const v3s16 &pos, std::string *block); bool deleteBlock(const v3s16 &pos); @@ -132,6 +134,8 @@ public: PlayerDatabasePostgreSQL(const std::string &connect_string); virtual ~PlayerDatabasePostgreSQL() = default; + virtual void pingDatabase() { Database_PostgreSQL::pingDatabase(); } + void savePlayer(RemotePlayer *player); bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); bool removePlayer(const std::string &name); diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 4560743b9..116096f68 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -121,7 +121,7 @@ Database_SQLite3::Database_SQLite3(const std::string &savedir, const std::string void Database_SQLite3::beginSave() { - verifyDatabase(); + pingDatabase(); SQLRES(sqlite3_step(m_stmt_begin), SQLITE_DONE, "Failed to start SQLite3 transaction"); sqlite3_reset(m_stmt_begin); @@ -129,7 +129,7 @@ void Database_SQLite3::beginSave() void Database_SQLite3::endSave() { - verifyDatabase(); + pingDatabase(); SQLRES(sqlite3_step(m_stmt_end), SQLITE_DONE, "Failed to commit SQLite3 transaction"); sqlite3_reset(m_stmt_end); @@ -171,7 +171,7 @@ void Database_SQLite3::openDatabase() "Failed to enable sqlite3 foreign key support"); } -void Database_SQLite3::verifyDatabase() +void Database_SQLite3::pingDatabase() { if (m_initialized) return; @@ -247,7 +247,7 @@ inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3s16 &pos, in bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) { - verifyDatabase(); + pingDatabase(); bindPos(m_stmt_delete, pos); @@ -263,7 +263,7 @@ bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) { - verifyDatabase(); + pingDatabase(); #ifdef __ANDROID__ /** @@ -290,7 +290,7 @@ bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) { - verifyDatabase(); + pingDatabase(); bindPos(m_stmt_read, pos); @@ -311,7 +311,7 @@ void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector &dst) { - verifyDatabase(); + pingDatabase(); while (sqlite3_step(m_stmt_list) == SQLITE_ROW) dst.push_back(getIntegerAsBlock(sqlite3_column_int64(m_stmt_list, 0))); @@ -439,7 +439,7 @@ void PlayerDatabaseSQLite3::initStatements() bool PlayerDatabaseSQLite3::playerDataExists(const std::string &name) { - verifyDatabase(); + pingDatabase(); str_to_sqlite(m_stmt_player_load, 1, name); bool res = (sqlite3_step(m_stmt_player_load) == SQLITE_ROW); sqlite3_reset(m_stmt_player_load); @@ -536,7 +536,7 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player) bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao) { - verifyDatabase(); + pingDatabase(); str_to_sqlite(m_stmt_player_load, 1, player->getName()); if (sqlite3_step(m_stmt_player_load) != SQLITE_ROW) { @@ -600,7 +600,7 @@ bool PlayerDatabaseSQLite3::removePlayer(const std::string &name) void PlayerDatabaseSQLite3::listPlayers(std::vector &res) { - verifyDatabase(); + pingDatabase(); while (sqlite3_step(m_stmt_player_list) == SQLITE_ROW) res.push_back(sqlite_to_string(m_stmt_player_list, 0)); @@ -673,7 +673,7 @@ void AuthDatabaseSQLite3::initStatements() bool AuthDatabaseSQLite3::getAuth(const std::string &name, AuthEntry &res) { - verifyDatabase(); + pingDatabase(); str_to_sqlite(m_stmt_read, 1, name); if (sqlite3_step(m_stmt_read) != SQLITE_ROW) { sqlite3_reset(m_stmt_read); @@ -735,7 +735,7 @@ bool AuthDatabaseSQLite3::createAuth(AuthEntry &authEntry) bool AuthDatabaseSQLite3::deleteAuth(const std::string &name) { - verifyDatabase(); + pingDatabase(); str_to_sqlite(m_stmt_delete, 1, name); sqlite3_vrfy(sqlite3_step(m_stmt_delete), SQLITE_DONE); @@ -749,7 +749,7 @@ bool AuthDatabaseSQLite3::deleteAuth(const std::string &name) void AuthDatabaseSQLite3::listNames(std::vector &res) { - verifyDatabase(); + pingDatabase(); while (sqlite3_step(m_stmt_list_names) == SQLITE_ROW) { res.push_back(sqlite_to_string(m_stmt_list_names, 0)); diff --git a/src/database/database-sqlite3.h b/src/database/database-sqlite3.h index d7202a918..647eddf7a 100644 --- a/src/database/database-sqlite3.h +++ b/src/database/database-sqlite3.h @@ -36,13 +36,13 @@ public: void beginSave(); void endSave(); + // Open and initialize the database if needed + virtual void pingDatabase(); + bool initialized() const { return m_initialized; } protected: Database_SQLite3(const std::string &savedir, const std::string &dbname); - // Open and initialize the database if needed - void verifyDatabase(); - // Convertors inline void str_to_sqlite(sqlite3_stmt *s, int iCol, const std::string &str) const { @@ -146,6 +146,8 @@ public: MapDatabaseSQLite3(const std::string &savedir); virtual ~MapDatabaseSQLite3(); + virtual void pingDatabase() { Database_SQLite3::pingDatabase(); } + bool saveBlock(const v3s16 &pos, const std::string &data); void loadBlock(const v3s16 &pos, std::string *block); bool deleteBlock(const v3s16 &pos); @@ -173,6 +175,8 @@ public: PlayerDatabaseSQLite3(const std::string &savedir); virtual ~PlayerDatabaseSQLite3(); + virtual void pingDatabase() { Database_SQLite3::pingDatabase(); } + void savePlayer(RemotePlayer *player); bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); bool removePlayer(const std::string &name); @@ -208,6 +212,8 @@ public: AuthDatabaseSQLite3(const std::string &savedir); virtual ~AuthDatabaseSQLite3(); + virtual void pingDatabase() { Database_SQLite3::pingDatabase(); } + virtual bool getAuth(const std::string &name, AuthEntry &res); virtual bool saveAuth(const AuthEntry &authEntry); virtual bool createAuth(AuthEntry &authEntry); diff --git a/src/database/database.h b/src/database/database.h index b7d551935..47605a07e 100644 --- a/src/database/database.h +++ b/src/database/database.h @@ -32,6 +32,7 @@ public: virtual void beginSave() = 0; virtual void endSave() = 0; virtual bool initialized() const { return true; } + virtual void pingDatabase() {} }; class MapDatabase : public Database @@ -57,6 +58,8 @@ class PlayerDatabase public: virtual ~PlayerDatabase() = default; + virtual void pingDatabase() {} + virtual void savePlayer(RemotePlayer *player) = 0; virtual bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) = 0; virtual bool removePlayer(const std::string &name) = 0; @@ -83,4 +86,5 @@ public: virtual bool deleteAuth(const std::string &name) = 0; virtual void listNames(std::vector &res) = 0; virtual void reload() = 0; + virtual void pingDatabase() {} }; diff --git a/src/map.cpp b/src/map.cpp index eb69955ee..12e122124 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1887,6 +1887,11 @@ MapDatabase *ServerMap::createDatabase( throw BaseException(std::string("Database backend ") + name + " not supported."); } +void ServerMap::pingDatabase() +{ + dbase->pingDatabase(); +} + void ServerMap::beginSave() { dbase->beginSave(); diff --git a/src/map.h b/src/map.h index da55fb432..ff6b20c4f 100644 --- a/src/map.h +++ b/src/map.h @@ -385,6 +385,7 @@ public: Database functions */ static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf); + void pingDatabase(); // Call these before and after saving of blocks void beginSave(); diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 32d10f8c0..739384673 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1219,6 +1219,11 @@ void ServerEnvironment::step(float dtime) } } + if (m_database_check_interval.step(dtime, 10.0f)) { + m_auth_database->pingDatabase(); + m_player_database->pingDatabase(); + m_map->pingDatabase(); + } /* Manage active block list */ diff --git a/src/serverenvironment.h b/src/serverenvironment.h index e10658249..55ecbd05f 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -435,6 +435,7 @@ private: IntervalLimiter m_object_management_interval; // List of active blocks ActiveBlockList m_active_blocks; + IntervalLimiter m_database_check_interval; IntervalLimiter m_active_blocks_management_interval; IntervalLimiter m_active_block_modifier_interval; IntervalLimiter m_active_blocks_nodemetadata_interval; -- cgit v1.2.3 From 8ae8c1600a66c724565ce7a70e0e5f542f12e38e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 15 Apr 2020 08:01:28 +0200 Subject: Fix parsing JSON with large integers (#9674) --- src/script/common/c_content.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index d73ecedab..25dada757 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1671,10 +1671,10 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, lua_pushvalue(L, nullindex); break; case Json::intValue: - lua_pushinteger(L, value.asInt()); + lua_pushinteger(L, value.asLargestInt()); break; case Json::uintValue: - lua_pushinteger(L, value.asUInt()); + lua_pushinteger(L, value.asLargestUInt()); break; case Json::realValue: lua_pushnumber(L, value.asDouble()); @@ -1700,7 +1700,7 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value, lua_createtable(L, 0, value.size()); for (Json::Value::const_iterator it = value.begin(); it != value.end(); ++it) { -#ifndef JSONCPP_STRING +#if !defined(JSONCPP_STRING) && (JSONCPP_VERSION_MAJOR < 1 || JSONCPP_VERSION_MINOR < 9) const char *str = it.memberName(); lua_pushstring(L, str ? str : ""); #else -- cgit v1.2.3 From 62ae7adab2bebde04864c12543caefbffab24963 Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 15 Apr 2020 16:27:40 +0200 Subject: Android: add Android Studio support, completely redone java part (#9066) --- .gitignore | 20 +- build/android/.gitignore | 11 + build/android/Makefile | 763 --------------------- build/android/app/build.gradle | 108 +++ build/android/app/src/main/AndroidManifest.xml | 60 ++ .../java/net/minetest/minetest/CopyZipTask.java | 82 +++ .../java/net/minetest/minetest/GameActivity.java | 120 ++++ .../net/minetest/minetest/InputDialogActivity.java | 98 +++ .../java/net/minetest/minetest/MainActivity.java | 139 ++++ .../java/net/minetest/minetest/UnzipService.java | 153 +++++ .../app/src/main/res/drawable/background.png | Bin 0 -> 83 bytes build/android/app/src/main/res/drawable/bg.xml | 4 + .../app/src/main/res/layout/activity_main.xml | 30 + .../app/src/main/res/mipmap/ic_launcher.png | Bin 0 -> 5780 bytes build/android/app/src/main/res/values/strings.xml | 10 + build/android/app/src/main/res/values/styles.xml | 22 + build/android/build.gradle | 175 +---- build/android/gradle.properties | 11 +- build/android/gradle/wrapper/gradle-wrapper.jar | Bin 54731 -> 55616 bytes .../gradle/wrapper/gradle-wrapper.properties | 3 +- build/android/gradlew | 22 +- build/android/gradlew.bat | 18 +- build/android/jni/Android.mk | 448 ------------ build/android/jni/Application.mk | 9 - build/android/jni/Deps.mk | 7 - build/android/jni/Irrlicht.mk | 8 - build/android/native/build.gradle | 59 ++ build/android/native/jni/Android.mk | 218 ++++++ build/android/native/jni/Application.mk | 32 + build/android/native/src/main/AndroidManifest.xml | 1 + build/android/patches/irrlicht-back_button.patch | 20 - .../android/patches/irrlicht-native_activity.patch | 13 - build/android/patches/irrlicht-texturehack.patch | 240 ------- build/android/patches/irrlicht-touchcount.patch | 30 - build/android/patches/libvorbis-libogg-fpu.patch | 37 - build/android/patches/openssl_arch.patch | 13 - build/android/settings.gradle | 1 + build/android/src/main/AndroidManifest.xml | 60 -- .../java/net.minetest.minetest/MainActivity.java | 77 --- .../net.minetest.minetest/MinetestAssetCopy.java | 371 ---------- .../net.minetest.minetest/MinetestTextEntry.java | 87 --- .../net.minetest.minetest/MtNativeActivity.java | 108 --- build/android/src/main/res/drawable/background.png | Bin 83 -> 0 bytes build/android/src/main/res/drawable/bg.xml | 4 - build/android/src/main/res/layout/assetcopy.xml | 24 - build/android/src/main/res/mipmap/ic_launcher.png | Bin 5780 -> 0 bytes build/android/src/main/res/values-v21/styles.xml | 17 - build/android/src/main/res/values/strings.xml | 5 - build/android/src/main/res/values/styles.xml | 14 - doc/README.android | 75 +- src/config.h | 6 +- src/main.cpp | 1 - src/porting_android.cpp | 17 +- src/porting_android.h | 5 - src/version.cpp | 5 +- 55 files changed, 1235 insertions(+), 2626 deletions(-) create mode 100644 build/android/.gitignore delete mode 100644 build/android/Makefile create mode 100644 build/android/app/build.gradle create mode 100644 build/android/app/src/main/AndroidManifest.xml create mode 100644 build/android/app/src/main/java/net/minetest/minetest/CopyZipTask.java create mode 100644 build/android/app/src/main/java/net/minetest/minetest/GameActivity.java create mode 100644 build/android/app/src/main/java/net/minetest/minetest/InputDialogActivity.java create mode 100644 build/android/app/src/main/java/net/minetest/minetest/MainActivity.java create mode 100644 build/android/app/src/main/java/net/minetest/minetest/UnzipService.java create mode 100644 build/android/app/src/main/res/drawable/background.png create mode 100644 build/android/app/src/main/res/drawable/bg.xml create mode 100644 build/android/app/src/main/res/layout/activity_main.xml create mode 100644 build/android/app/src/main/res/mipmap/ic_launcher.png create mode 100644 build/android/app/src/main/res/values/strings.xml create mode 100644 build/android/app/src/main/res/values/styles.xml delete mode 100644 build/android/jni/Android.mk delete mode 100644 build/android/jni/Application.mk delete mode 100644 build/android/jni/Deps.mk delete mode 100644 build/android/jni/Irrlicht.mk create mode 100644 build/android/native/build.gradle create mode 100644 build/android/native/jni/Android.mk create mode 100644 build/android/native/jni/Application.mk create mode 100644 build/android/native/src/main/AndroidManifest.xml delete mode 100644 build/android/patches/irrlicht-back_button.patch delete mode 100644 build/android/patches/irrlicht-native_activity.patch delete mode 100644 build/android/patches/irrlicht-texturehack.patch delete mode 100644 build/android/patches/irrlicht-touchcount.patch delete mode 100644 build/android/patches/libvorbis-libogg-fpu.patch delete mode 100644 build/android/patches/openssl_arch.patch delete mode 100644 build/android/src/main/AndroidManifest.xml delete mode 100644 build/android/src/main/java/net.minetest.minetest/MainActivity.java delete mode 100644 build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java delete mode 100644 build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java delete mode 100644 build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java delete mode 100644 build/android/src/main/res/drawable/background.png delete mode 100644 build/android/src/main/res/drawable/bg.xml delete mode 100644 build/android/src/main/res/layout/assetcopy.xml delete mode 100644 build/android/src/main/res/mipmap/ic_launcher.png delete mode 100644 build/android/src/main/res/values-v21/styles.xml delete mode 100644 build/android/src/main/res/values/strings.xml delete mode 100644 build/android/src/main/res/values/styles.xml (limited to 'src') diff --git a/.gitignore b/.gitignore index aae9bf437..9ab69b30e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.swp *.bak* *.orig +.DS_Store # Vim *.vim # Kate @@ -77,17 +78,11 @@ doc/mkdocs/mkdocs.yml ## Build files CMakeFiles Makefile -!build/android/Makefile -build/android/path.cfg -build/android/*.apk -build/android/.externalNativeBuild cmake_install.cmake CMakeCache.txt CPackConfig.cmake CPackSourceConfig.cmake src/test_config.h -src/android_version.h -src/android_version_githash.h src/cmake_config.h src/cmake_config_githash.h src/unittest/test_world/world.mt @@ -109,16 +104,3 @@ cmake_config.h cmake_config_githash.h CMakeDoxy* compile_commands.json - -## Android build files -build/android/src/main/assets -build/android/build -build/android/deps -build/android/libs -build/android/jni/lib -build/android/jni/src -build/android/src/main/jniLibs -build/android/obj -build/android/local.properties -build/android/.gradle -timestamp diff --git a/build/android/.gitignore b/build/android/.gitignore new file mode 100644 index 000000000..e0613f8b3 --- /dev/null +++ b/build/android/.gitignore @@ -0,0 +1,11 @@ +*.iml +.externalNativeBuild +.gradle +app/build +app/release +app/src/main/assets +build +local.properties +native/.* +native/build +native/deps diff --git a/build/android/Makefile b/build/android/Makefile deleted file mode 100644 index 9ec237a75..000000000 --- a/build/android/Makefile +++ /dev/null @@ -1,763 +0,0 @@ -# build options - -OS := $(shell uname) - -# compile with GPROF -# GPROF = 1 - -# build for build platform -API = 14 -APP_PLATFORM = android-$(API) - -ANDR_ROOT = $(shell pwd) -PROJ_ROOT = $(shell realpath $(ANDR_ROOT)/../..) -APP_ROOT = $(ANDR_ROOT)/src/main - -VERSION_MAJOR := $(shell cat $(PROJ_ROOT)/CMakeLists.txt | \ - grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | cut -f2 -d' ') -VERSION_MINOR := $(shell cat $(PROJ_ROOT)/CMakeLists.txt | \ - grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | cut -f2 -d' ') -VERSION_PATCH := $(shell cat $(PROJ_ROOT)/CMakeLists.txt | \ - grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | cut -f2 -d' ') - -################################################################################ -# toolchain config for arm new processors -################################################################################ -TARGET_HOST = arm-linux -TARGET_ABI = armeabi-v7a -TARGET_LIBDIR = armeabi-v7a -TARGET_TOOLCHAIN = arm-linux-androideabi- -TARGET_CFLAGS_ADDON = -mfloat-abi=softfp -mfpu=vfpv3 -O3 -TARGET_CXXFLAGS_ADDON = $(TARGET_CFLAGS_ADDON) -TARGET_ARCH = armv7 -CROSS_CC = clang -CROSS_CXX = clang++ -COMPILER_VERSION = clang -HAVE_LEVELDB = 0 - -################################################################################ -# toolchain config for little endian mips -################################################################################ -#TARGET_HOST = mipsel-linux -#TARGET_ABI = mips -#TARGET_LIBDIR = mips -#TARGET_TOOLCHAIN = mipsel-linux-android- -#TARGET_ARCH = mips32 -#CROSS_CC = mipsel-linux-android-gcc -#CROSS_CXX = mipsel-linux-android-g++ -#COMPILER_VERSION = 4.9 -#HAVE_LEVELDB = 0 - -################################################################################ -# toolchain config for x86 -################################################################################ -#TARGET_HOST = x86-linux -#TARGET_ABI = x86 -#TARGET_LIBDIR = x86 -#TARGET_TOOLCHAIN = x86- -#TARGET_ARCH = x86 -#CROSS_CC = clang -#CROSS_CXX = clang++ -#COMPILER_VERSION = clang -#HAVE_LEVELDB = 0 - -################################################################################ -ASSETS_TIMESTAMP = deps/assets_timestamp - -LEVELDB_DIR = $(ANDR_ROOT)/deps/leveldb/ -LEVELDB_LIB = $(LEVELDB_DIR)libleveldb.a -LEVELDB_TIMESTAMP = $(LEVELDB_DIR)/timestamp -LEVELDB_TIMESTAMP_INT = $(ANDR_ROOT)/deps/leveldb_timestamp -LEVELDB_URL_GIT = https://github.com/google/leveldb -LEVELDB_COMMIT = 2d0320a458d0e6a20fff46d5f80b18bfdcce7018 - -OPENAL_DIR = $(ANDR_ROOT)/deps/openal-soft/ -OPENAL_LIB = $(OPENAL_DIR)libs/$(TARGET_ABI)/libopenal.so -OPENAL_TIMESTAMP = $(OPENAL_DIR)/timestamp -OPENAL_TIMESTAMP_INT = $(ANDR_ROOT)/deps/openal_timestamp -OPENAL_URL_GIT = https://github.com/apportable/openal-soft - -OGG_DIR = $(ANDR_ROOT)/deps/libvorbis-libogg-android/ -OGG_LIB = $(OGG_DIR)libs/$(TARGET_ABI)/libogg.so -VORBIS_LIB = $(OGG_DIR)libs/$(TARGET_ABI)/libogg.so -OGG_TIMESTAMP = $(OGG_DIR)timestamp -OGG_TIMESTAMP_INT = $(ANDR_ROOT)/deps/ogg_timestamp -OGG_URL_GIT = https://gitlab.com/minetest/libvorbis-libogg-android - -IRRLICHT_REVISION = 5150 -IRRLICHT_DIR = $(ANDR_ROOT)/deps/irrlicht/ -IRRLICHT_LIB = $(IRRLICHT_DIR)lib/Android/libIrrlicht.a -IRRLICHT_TIMESTAMP = $(IRRLICHT_DIR)timestamp -IRRLICHT_TIMESTAMP_INT = $(ANDR_ROOT)/deps/irrlicht_timestamp -IRRLICHT_URL_SVN = https://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@$(IRRLICHT_REVISION) - -OPENSSL_VERSION = 1.0.2n -OPENSSL_BASEDIR = openssl-$(OPENSSL_VERSION) -OPENSSL_DIR = $(ANDR_ROOT)/deps/$(OPENSSL_BASEDIR)/ -OPENSSL_LIB = $(OPENSSL_DIR)/libssl.a -OPENSSL_TIMESTAMP = $(OPENSSL_DIR)timestamp -OPENSSL_TIMESTAMP_INT = $(ANDR_ROOT)/deps/openssl_timestamp -OPENSSL_URL = https://www.openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz - -CURL_VERSION = 7.60.0 -CURL_DIR = $(ANDR_ROOT)/deps/curl-$(CURL_VERSION) -CURL_LIB = $(CURL_DIR)/lib/.libs/libcurl.a -CURL_TIMESTAMP = $(CURL_DIR)/timestamp -CURL_TIMESTAMP_INT = $(ANDR_ROOT)/deps/curl_timestamp -CURL_URL_HTTP = https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.bz2 - -FREETYPE_DIR = $(ANDR_ROOT)/deps/freetype2-android/ -FREETYPE_LIB = $(FREETYPE_DIR)/Android/obj/local/$(TARGET_ABI)/libfreetype2-static.a -FREETYPE_TIMESTAMP = $(FREETYPE_DIR)timestamp -FREETYPE_TIMESTAMP_INT = $(ANDR_ROOT)/deps/freetype_timestamp -FREETYPE_URL_GIT = https://github.com/cdave1/freetype2-android - -ICONV_VERSION = 1.16 -ICONV_DIR = $(ANDR_ROOT)/deps/libiconv/ -ICONV_LIB = $(ICONV_DIR)/lib/.libs/libiconv.so -ICONV_TIMESTAMP = $(ICONV_DIR)timestamp -ICONV_TIMESTAMP_INT = $(ANDR_ROOT)/deps/iconv_timestamp -ICONV_URL_HTTP = https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$(ICONV_VERSION).tar.gz - -SQLITE3_FOLDER = sqlite-amalgamation-3240000 -SQLITE3_URL = https://www.sqlite.org/2018/$(SQLITE3_FOLDER).zip - -ANDROID_SDK = $(shell grep '^sdk\.dir' local.properties | sed 's/^.*=[[:space:]]*//') -ANDROID_NDK = $(shell grep '^ndk\.dir' local.properties | sed 's/^.*=[[:space:]]*//') - -#use interim target variable to switch leveldb on or off -ifeq ($(HAVE_LEVELDB),1) - LEVELDB_TARGET = $(LEVELDB_LIB) -endif - -.PHONY : debug release reconfig delconfig \ - leveldb_download clean_leveldb leveldb\ - irrlicht_download clean_irrlicht irrlicht \ - clean_assets assets sqlite3_download \ - freetype_download clean_freetype freetype \ - apk clean_apk \ - clean_all clean prep_srcdir \ - install_debug install_release envpaths all \ - $(ASSETS_TIMESTAMP) $(LEVELDB_TIMESTAMP) \ - $(OPENAL_TIMESTAMP) $(OGG_TIMESTAMP) \ - $(IRRLICHT_TIMESTAMP) $(CURL_TIMESTAMP) \ - $(OPENSSL_TIMESTAMP) \ - $(ANDR_ROOT)/jni/src/android_version.h \ - $(ANDR_ROOT)/jni/src/android_version_githash.h - -debug : local.properties - export NDEBUG=; \ - export BUILD_TYPE=debug; \ - $(MAKE) apk - -all : debug release - -release : local.properties - @export NDEBUG=1; \ - export BUILD_TYPE=release; \ - $(MAKE) apk - -reconfig: delconfig - @$(MAKE) local.properties - -delconfig: - $(RM) local.properties - -local.properties: - @echo "Please specify path of ANDROID NDK"; \ - echo "e.g. $$HOME/Android/Sdk/ndk-bundle/"; \ - read ANDROID_NDK ; \ - if [ ! -d $$ANDROID_NDK ] ; then \ - echo "$$ANDROID_NDK is not a valid folder"; \ - exit 1; \ - fi; \ - echo "ndk.dir = $$ANDROID_NDK" > local.properties; \ - echo "Please specify path of ANDROID SDK"; \ - echo "e.g. $$HOME/Android/Sdk/"; \ - read SDKFLDR ; \ - if [ ! -d $$SDKFLDR ] ; then \ - echo "$$SDKFLDR is not a valid folder"; \ - exit 1; \ - fi; \ - echo "sdk.dir = $$SDKFLDR" >> local.properties; - - -$(OPENAL_TIMESTAMP) : openal_download - @LAST_MODIF=$$(find ${OPENAL_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${OPENAL_TIMESTAMP}; \ - fi - -openal_download : - @if [ ! -d ${OPENAL_DIR} ] ; then \ - echo "openal sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd ${ANDR_ROOT}/deps ; \ - git clone ${OPENAL_URL_GIT} || exit 1; \ - fi - -openal : $(OPENAL_LIB) - -$(OPENAL_LIB): $(OPENAL_TIMESTAMP) - + @REFRESH=0; \ - if [ ! -e ${OPENAL_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${OPENAL_TIMESTAMP} -nt ${OPENAL_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - echo "changed timestamp for openal detected building..."; \ - cd ${OPENAL_DIR}; \ - export APP_PLATFORM=${APP_PLATFORM}; \ - export TARGET_ABI=${TARGET_ABI}; \ - export TARGET_CFLAGS_ADDON="${TARGET_CFLAGS_ADDON}"; \ - export TARGET_CXXFLAGS_ADDON="${TARGET_CXXFLAGS_ADDON}"; \ - export COMPILER_VERSION=${COMPILER_VERSION}; \ - ${ANDROID_NDK}/ndk-build \ - NDK_APPLICATION_MK=${ANDR_ROOT}/jni/Deps.mk || exit 1; \ - touch ${OPENAL_TIMESTAMP}; \ - touch ${OPENAL_TIMESTAMP_INT}; \ - else \ - echo "nothing to be done for openal"; \ - fi - -clean_openal : - $(RM) -rf ${OPENAL_DIR} - -$(OGG_TIMESTAMP) : ogg_download - @LAST_MODIF=$$(find ${OGG_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${OGG_TIMESTAMP}; \ - fi - -ogg_download : - @if [ ! -d ${OGG_DIR} ] ; then \ - echo "ogg sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd ${ANDR_ROOT}/deps ; \ - git clone ${OGG_URL_GIT}|| exit 1; \ - cd libvorbis-libogg-android ; \ - patch -p1 < ${ANDR_ROOT}/patches/libvorbis-libogg-fpu.patch || exit 1; \ - fi - -ogg : $(OGG_LIB) - -$(OGG_LIB): $(OGG_TIMESTAMP) - + @REFRESH=0; \ - if [ ! -e ${OGG_TIMESTAMP_INT} ] ; then \ - echo "${OGG_TIMESTAMP_INT} doesn't exist"; \ - REFRESH=1; \ - fi; \ - if [ ${OGG_TIMESTAMP} -nt ${OGG_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - echo "changed timestamp for ogg detected building..."; \ - cd ${OGG_DIR}; \ - export APP_PLATFORM=${APP_PLATFORM}; \ - export TARGET_ABI=${TARGET_ABI}; \ - ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \ - --toolchain=${TARGET_TOOLCHAIN}${COMPILER_VERSION} \ - --platform=${APP_PLATFORM} \ - --install-dir=$${TOOLCHAIN}; \ - touch ${OGG_TIMESTAMP}; \ - touch ${OGG_TIMESTAMP_INT}; \ - else \ - echo "nothing to be done for libogg/libvorbis"; \ - fi - -clean_ogg : - $(RM) -rf ${OGG_DIR} - -$(OPENSSL_TIMESTAMP) : openssl_download - @LAST_MODIF=$$(find ${OPENSSL_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${OPENSSL_TIMESTAMP}; \ - fi - -openssl_download : - @if [ ! -d ${OPENSSL_DIR} ] ; then \ - echo "openssl sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd ${ANDR_ROOT}/deps ; \ - wget ${OPENSSL_URL} || exit 1; \ - tar -xzf ${OPENSSL_BASEDIR}.tar.gz; \ - cd ${OPENSSL_BASEDIR}; \ - patch -p1 < ${ANDR_ROOT}/patches/openssl_arch.patch; \ - sed -i 's/-mandroid //g' Configure; \ - fi - -openssl : $(OPENSSL_LIB) - -$(OPENSSL_LIB): $(OPENSSL_TIMESTAMP) - @REFRESH=0; \ - if [ ! -e ${OPENSSL_TIMESTAMP_INT} ] ; then \ - echo "${OPENSSL_TIMESTAMP_INT} doesn't exist"; \ - REFRESH=1; \ - fi; \ - if [ ${OPENSSL_TIMESTAMP} -nt ${OPENSSL_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - echo "changed timestamp for openssl detected building..."; \ - cd ${OPENSSL_DIR}; \ - ln -s ${OPENSSL_DIR} ../openssl; \ - export TOOLCHAIN=/tmp/ndk-${TARGET_HOST}-openssl; \ - ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \ - --toolchain=${TARGET_TOOLCHAIN}${COMPILER_VERSION} \ - --platform=${APP_PLATFORM} \ - --stl=libc++ \ - --install-dir=$${TOOLCHAIN}; \ - export PATH="$${TOOLCHAIN}/bin:$${PATH}"; \ - export CFLAGS="$${CFLAGS} ${TARGET_CFLAGS_ADDON}"; \ - export LDFLAGS="$${LDFLAGS} ${TARGET_LDFLAGS_ADDON}"; \ - CC=${CROSS_CC} ./Configure -DL_ENDIAN no-asm android-${TARGET_ARCH} \ - -D__ANDROID_API__=$(API); \ - CC=${CROSS_CC} ANDROID_DEV=/tmp/ndk-${TARGET_HOST} make depend; \ - CC=${CROSS_CC} ANDROID_DEV=/tmp/ndk-${TARGET_HOST} make build_libs; \ - touch ${OPENSSL_TIMESTAMP}; \ - touch ${OPENSSL_TIMESTAMP_INT}; \ - $(RM) -rf $${TOOLCHAIN}; \ - else \ - echo "nothing to be done for openssl"; \ - fi - -clean_openssl : - $(RM) -rf ${OPENSSL_DIR}; \ - $(RM) -rf $(ANDR_ROOT)/deps/${OPENSSL_BASEDIR}.tar.gz; \ - $(RM) -rf $(ANDR_ROOT)/deps/openssl - -$(LEVELDB_TIMESTAMP) : leveldb_download - @LAST_MODIF=$$(find ${LEVELDB_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${LEVELDB_TIMESTAMP}; \ - fi - -leveldb_download : - @if [ ! -d ${LEVELDB_DIR} ] ; then \ - echo "leveldb sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd ${ANDR_ROOT}/deps ; \ - git clone ${LEVELDB_URL_GIT} || exit 1; \ - cd ${LEVELDB_DIR} || exit 1; \ - git checkout ${LEVELDB_COMMIT} || exit 1; \ - fi - -leveldb : $(LEVELDB_LIB) -ifeq ($(HAVE_LEVELDB),1) -$(LEVELDB_LIB): $(LEVELDB_TIMESTAMP) - @REFRESH=0; \ - if [ ! -e ${LEVELDB_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${LEVELDB_TIMESTAMP} -nt ${LEVELDB_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - echo "changed timestamp for leveldb detected building..."; \ - cd deps/leveldb; \ - export CROSS_PREFIX=${TARGET_TOOLCHAIN}; \ - export TOOLCHAIN=/tmp/ndk-${TARGET_HOST}-leveldb; \ - ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \ - --toolchain=${TARGET_TOOLCHAIN}${COMPILER_VERSION} \ - --platform=${APP_PLATFORM} \ - --stl=libc++ \ - --install-dir=$${TOOLCHAIN}; \ - export PATH="$${TOOLCHAIN}/bin:$${PATH}"; \ - export CC=${CROSS_CC}; \ - export CXX=${CROSS_CXX}; \ - export CFLAGS="$${CFLAGS} ${TARGET_CFLAGS_ADDON}"; \ - export CPPFLAGS="$${CPPFLAGS} ${TARGET_CXXFLAGS_ADDON}"; \ - export LDFLAGS="$${LDFLAGS} ${TARGET_LDFLAGS_ADDON}"; \ - export TARGET_OS=OS_ANDROID_CROSSCOMPILE; \ - $(MAKE) || exit 1; \ - touch ${LEVELDB_TIMESTAMP}; \ - touch ${LEVELDB_TIMESTAMP_INT}; \ - $(RM) -rf $${TOOLCHAIN}; \ - else \ - echo "nothing to be done for leveldb"; \ - fi -endif - -clean_leveldb : - ./gradlew cleanLevelDB - -$(FREETYPE_TIMESTAMP) : freetype_download - @LAST_MODIF=$$(find ${FREETYPE_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${FREETYPE_TIMESTAMP}; \ - fi - -freetype_download : - @if [ ! -d ${FREETYPE_DIR} ] ; then \ - echo "freetype sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd deps; \ - git clone ${FREETYPE_URL_GIT} || exit 1; \ - fi - -freetype : $(FREETYPE_LIB) - -$(FREETYPE_LIB) : $(FREETYPE_TIMESTAMP) - + @REFRESH=0; \ - if [ ! -e ${FREETYPE_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ! -e ${FREETYPE_LIB} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${FREETYPE_TIMESTAMP} -nt ${FREETYPE_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - mkdir -p ${FREETYPE_DIR}; \ - echo "changed timestamp for freetype detected building..."; \ - cd ${FREETYPE_DIR}/Android/jni; \ - export APP_PLATFORM=${APP_PLATFORM}; \ - export TARGET_ABI=${TARGET_ABI}; \ - export TARGET_CFLAGS_ADDON="${TARGET_CFLAGS_ADDON}"; \ - export TARGET_CXXFLAGS_ADDON="${TARGET_CXXFLAGS_ADDON}"; \ - export COMPILER_VERSION=${COMPILER_VERSION}; \ - ${ANDROID_NDK}/ndk-build \ - NDK_APPLICATION_MK=${ANDR_ROOT}/jni/Deps.mk || exit 1; \ - touch ${FREETYPE_TIMESTAMP}; \ - touch ${FREETYPE_TIMESTAMP_INT}; \ - else \ - echo "nothing to be done for freetype"; \ - fi - -clean_freetype : - ./gradlew cleanFreetype - -$(ICONV_TIMESTAMP) : iconv_download - @LAST_MODIF=$$(find ${ICONV_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${ICONV_TIMESTAMP}; \ - fi - -iconv_download : - @if [ ! -d ${ICONV_DIR} ] ; then \ - echo "iconv sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd ${ANDR_ROOT}/deps; \ - wget ${ICONV_URL_HTTP} || exit 1; \ - tar -xzf libiconv-${ICONV_VERSION}.tar.gz || exit 1; \ - rm libiconv-${ICONV_VERSION}.tar.gz; \ - ln -s libiconv-${ICONV_VERSION} libiconv; \ - fi - -iconv : $(ICONV_LIB) - -$(ICONV_LIB) : $(ICONV_TIMESTAMP) - @REFRESH=0; \ - if [ ! -e ${ICONV_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ! -e ${ICONV_LIB} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${ICONV_TIMESTAMP} -nt ${ICONV_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - mkdir -p ${ICONV_DIR}; \ - echo "changed timestamp for iconv detected building..."; \ - cd ${ICONV_DIR}; \ - export TOOLCHAIN=/tmp/ndk-${TARGET_HOST}-iconv; \ - ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \ - --toolchain=${TARGET_TOOLCHAIN}${COMPILER_VERSION} \ - --platform=${APP_PLATFORM} \ - --stl=libc++ \ - --install-dir=$${TOOLCHAIN}; \ - export PATH="$${TOOLCHAIN}/bin:$${PATH}"; \ - export CFLAGS="$${CFLAGS} ${TARGET_CFLAGS_ADDON}"; \ - export LDFLAGS="$${LDFLAGS} ${TARGET_LDFLAGS_ADDON} -lstdc++"; \ - export CC=${CROSS_CC}; \ - export CXX=${CROSS_CXX}; \ - export TARGET_OS=OS_ANDROID_CROSSCOMPILE; \ - ./configure --host=${TARGET_HOST} || exit 1; \ - sed -i 's/LIBICONV_VERSION_INFO) /LIBICONV_VERSION_INFO) -avoid-version /g' lib/Makefile; \ - grep "iconv_LDFLAGS" src/Makefile; \ - $(MAKE) -s || exit 1; \ - touch ${ICONV_TIMESTAMP}; \ - touch ${ICONV_TIMESTAMP_INT}; \ - rm -rf ${TOOLCHAIN}; \ - else \ - echo "nothing to be done for iconv"; \ - fi - -clean_iconv : - ./gradlew cleanIconv - -#Note: Texturehack patch is required for gpu's not supporting color format -# correctly. Known bad GPU: -# -geforce on emulator -# -Vivante Corporation GC1000 core (e.g. Galaxy Tab 3) - -irrlicht_download : - @if [ ! -d "deps/irrlicht" ] ; then \ - echo "irrlicht sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd deps; \ - svn co ${IRRLICHT_URL_SVN} irrlicht || exit 1; \ - cd irrlicht; \ - patch -p1 < ${ANDR_ROOT}/patches/irrlicht-touchcount.patch || exit 1; \ - patch -p1 < ${ANDR_ROOT}/patches/irrlicht-back_button.patch || exit 1; \ - patch -p1 < ${ANDR_ROOT}/patches/irrlicht-texturehack.patch || exit 1; \ - patch -p1 < ${ANDR_ROOT}/patches/irrlicht-native_activity.patch || exit 1; \ - fi - -$(IRRLICHT_TIMESTAMP) : irrlicht_download - @LAST_MODIF=$$(find ${IRRLICHT_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${IRRLICHT_TIMESTAMP}; \ - fi - -irrlicht : $(IRRLICHT_LIB) - -$(IRRLICHT_LIB): $(IRRLICHT_TIMESTAMP) $(FREETYPE_LIB) - + @REFRESH=0; \ - if [ ! -e ${IRRLICHT_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ! -e ${IRRLICHT_LIB} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${IRRLICHT_TIMESTAMP} -nt ${IRRLICHT_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - mkdir -p ${IRRLICHT_DIR}; \ - echo "changed timestamp for irrlicht detected building..."; \ - cd deps/irrlicht/source/Irrlicht/Android; \ - export APP_PLATFORM=${APP_PLATFORM}; \ - export TARGET_ABI=${TARGET_ABI}; \ - export TARGET_CFLAGS_ADDON="${TARGET_CFLAGS_ADDON}"; \ - export TARGET_CXXFLAGS_ADDON="${TARGET_CXXFLAGS_ADDON}"; \ - export COMPILER_VERSION=${COMPILER_VERSION}; \ - ${ANDROID_NDK}/ndk-build \ - NDK_APPLICATION_MK=${ANDR_ROOT}/jni/Deps.mk || exit 1; \ - touch ${IRRLICHT_TIMESTAMP}; \ - touch ${IRRLICHT_TIMESTAMP_INT}; \ - else \ - echo "nothing to be done for irrlicht"; \ - fi - -clean_irrlicht : - ./gradlew cleanIrrlicht - -$(CURL_TIMESTAMP) : curl_download - @LAST_MODIF=$$(find ${CURL_DIR} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${CURL_TIMESTAMP}; \ - fi - -curl_download : - @if [ ! -d "deps/curl-${CURL_VERSION}" ] ; then \ - echo "curl sources missing, downloading..."; \ - mkdir -p ${ANDR_ROOT}/deps; \ - cd deps; \ - wget ${CURL_URL_HTTP} || exit 1; \ - tar -xjf curl-${CURL_VERSION}.tar.bz2 || exit 1; \ - rm curl-${CURL_VERSION}.tar.bz2; \ - ln -s curl-${CURL_VERSION} curl; \ - fi - -curl : $(CURL_LIB) - -$(CURL_LIB): $(CURL_TIMESTAMP) $(OPENSSL_LIB) - @REFRESH=0; \ - if [ ! -e ${CURL_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ! -e ${CURL_LIB} ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${CURL_TIMESTAMP} -nt ${CURL_TIMESTAMP_INT} ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - mkdir -p ${CURL_DIR}; \ - echo "changed timestamp for curl detected building..."; \ - cd deps/curl-${CURL_VERSION}; \ - export CROSS_PREFIX=${TARGET_TOOLCHAIN}; \ - export TOOLCHAIN=/tmp/ndk-${TARGET_HOST}-curl; \ - ${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \ - --toolchain=${TARGET_TOOLCHAIN}${COMPILER_VERSION} \ - --platform=${APP_PLATFORM} \ - --stl=libc++ \ - --install-dir=$${TOOLCHAIN}; \ - export PATH="$${TOOLCHAIN}/bin:$${PATH}"; \ - export CC=${CROSS_CC}; \ - export CXX=${CROSS_CXX}; \ - export TARGET_OS=OS_ANDROID_CROSSCOMPILE; \ - export CPPFLAGS="$${CPPFLAGS} -I${OPENSSL_DIR}/include ${TARGET_CFLAGS_ADDON}"; \ - export CFLAGS="$${CFLAGS} ${TARGET_CFLAGS_ADDON}"; \ - export LDFLAGS="$${LDFLAGS} -L${OPENSSL_DIR} ${TARGET_LDFLAGS_ADDON}"; \ - ./configure --host=${TARGET_HOST} --disable-shared --enable-static --with-ssl; \ - $(MAKE) -s || exit 1; \ - touch ${CURL_TIMESTAMP}; \ - touch ${CURL_TIMESTAMP_INT}; \ - $(RM) -rf $${TOOLCHAIN}; \ - else \ - echo "nothing to be done for curl"; \ - fi - -clean_curl : - ./gradlew cleanCURL - -sqlite3_download: deps/${SQLITE3_FOLDER}/sqlite3.c - -deps/${SQLITE3_FOLDER}/sqlite3.c : - cd deps; \ - wget ${SQLITE3_URL}; \ - unzip ${SQLITE3_FOLDER}.zip; \ - ln -s ${SQLITE3_FOLDER} sqlite; \ - cd ${SQLITE3_FOLDER}; - -clean_sqlite3: - ./gradlew cleanSQLite3 - -$(ASSETS_TIMESTAMP) : $(IRRLICHT_LIB) - @mkdir -p ${ANDR_ROOT}/deps; \ - for DIRNAME in {builtin,client,doc,fonts,games,mods,po,textures}; do \ - LAST_MODIF=$$(find ${PROJ_ROOT}/${DIRNAME} -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ]; then \ - touch ${PROJ_ROOT}/${DIRNAME}/timestamp; \ - touch ${ASSETS_TIMESTAMP}; \ - echo ${DIRNAME} changed $$LAST_MODIF; \ - fi; \ - done; \ - LAST_MODIF=$$(find ${IRRLICHT_DIR}/media -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "); \ - if [ $$(basename $$LAST_MODIF) != "timestamp" ] ; then \ - touch ${IRRLICHT_DIR}/media/timestamp; \ - touch ${ASSETS_TIMESTAMP}; \ - fi; \ - if [ ${PROJ_ROOT}/minetest.conf.example -nt ${ASSETS_TIMESTAMP} ] ; then \ - echo "conf changed"; \ - touch ${ASSETS_TIMESTAMP}; \ - fi; \ - if [ ${PROJ_ROOT}/README.txt -nt ${ASSETS_TIMESTAMP} ] ; then \ - touch ${ASSETS_TIMESTAMP}; \ - fi; \ - if [ ! -e $(ASSETS_TIMESTAMP) ] ; then \ - touch $(ASSETS_TIMESTAMP); \ - fi - -assets : $(ASSETS_TIMESTAMP) - @REFRESH=0; \ - if [ ! -e ${ASSETS_TIMESTAMP}.old ] ; then \ - REFRESH=1; \ - fi; \ - if [ ${ASSETS_TIMESTAMP} -nt ${ASSETS_TIMESTAMP}.old ] ; then \ - REFRESH=1; \ - fi; \ - if [ ! -d ${APP_ROOT}/assets ] ; then \ - REFRESH=1; \ - fi; \ - if [ $$REFRESH -ne 0 ] ; then \ - echo "assets changed, refreshing..."; \ - $(MAKE) clean_assets; \ - ./gradlew copyAssets; \ - cp -r ${IRRLICHT_DIR}/media/Shaders ${APP_ROOT}/assets/Minetest/media; \ - cd ${APP_ROOT}/assets || exit 1; \ - find . -name "timestamp" -exec rm {} \; ; \ - find . -name "*.blend" -exec rm {} \; ; \ - find . -name "*~" -exec rm {} \; ; \ - find . -type d -path "*.git" -exec rm -rf {} \; ; \ - find . -type d -path "*.svn" -exec rm -rf {} \; ; \ - find . -type f -path "*.gitignore" -exec rm -rf {} \; ; \ - ls -R | grep ":$$" | sed -e 's/:$$//' -e 's/\.//' -e 's/^\///' > "index.txt"; \ - find -L Minetest > filelist.txt; \ - cp ${ANDR_ROOT}/${ASSETS_TIMESTAMP} ${ANDR_ROOT}/${ASSETS_TIMESTAMP}.old; \ - else \ - echo "nothing to be done for assets"; \ - fi - -clean_assets : - ./gradlew cleanAssets - -apk: local.properties assets $(ICONV_LIB) $(IRRLICHT_LIB) $(CURL_LIB) $(LEVELDB_TARGET) \ - $(OPENAL_LIB) $(OGG_LIB) prep_srcdir $(ANDR_ROOT)/jni/src/android_version.h \ - $(ANDR_ROOT)/jni/src/android_version_githash.h sqlite3_download - + @export TARGET_LIBDIR=${TARGET_LIBDIR}; \ - export HAVE_LEVELDB=${HAVE_LEVELDB}; \ - export APP_PLATFORM=${APP_PLATFORM}; \ - export TARGET_ABI=${TARGET_ABI}; \ - export TARGET_CFLAGS_ADDON="${TARGET_CFLAGS_ADDON}"; \ - export TARGET_CXXFLAGS_ADDON="${TARGET_CXXFLAGS_ADDON}"; \ - export COMPILER_VERSION=${COMPILER_VERSION}; \ - export GPROF=${GPROF}; \ - ${ANDROID_NDK}/ndk-build || exit 1; \ - if [ ! -e ${APP_ROOT}/jniLibs ]; then \ - ln -s ${ANDR_ROOT}/libs ${APP_ROOT}/jniLibs || exit 1; \ - fi; \ - export VERSION_STR="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" && \ - export BUILD_TYPE_C=$$(echo "$${BUILD_TYPE}" | sed 's/./\U&/') && \ - ./gradlew assemble$$BUILD_TYPE_C && \ - echo "APK stored at: build/outputs/apk/$$BUILD_TYPE/Minetest-$$BUILD_TYPE.apk" && \ - echo "You can install it with \`make install_$$BUILD_TYPE\`" - -# These Intentionally doesn't depend on their respective build steps, -# because it takes a while to verify that everything's up-to-date. -install_debug: - ${ANDROID_SDK}/platform-tools/adb install -r build/outputs/apk/debug/Minetest-debug.apk - -install_release: - ${ANDROID_SDK}/platform-tools/adb install -r build/outputs/apk/release/Minetest-release.apk - -prep_srcdir : - @if [ ! -e ${ANDR_ROOT}/jni/src ]; then \ - ln -s ${PROJ_ROOT}/src ${ANDR_ROOT}/jni/src; \ - fi; \ - if [ ! -e ${ANDR_ROOT}/jni/lib ]; then \ - ln -s ${PROJ_ROOT}/lib ${ANDR_ROOT}/jni/lib; \ - fi - -clean_apk : - ./gradlew clean - -clean_all : - ./gradlew cleanAll - -$(ANDR_ROOT)/jni/src/android_version_githash.h : prep_srcdir - @export VERSION_FILE=${ANDR_ROOT}/jni/src/android_version_githash.h; \ - export VERSION_FILE_NEW=$${VERSION_FILE}.new; \ - { \ - echo "#ifndef ANDROID_MT_VERSION_GITHASH_H"; \ - echo "#define ANDROID_MT_VERSION_GITHASH_H"; \ - export GITHASH=$$(git rev-parse --short=8 HEAD); \ - export VERSION_STR="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"; \ - echo "#define VERSION_GITHASH \"$$VERSION_STR-$$GITHASH-Android\""; \ - echo "#endif"; \ - } > "$${VERSION_FILE_NEW}"; \ - if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \ - echo "android_version_githash.h changed, updating..."; \ - mv "$${VERSION_FILE_NEW}" "$${VERSION_FILE}"; \ - else \ - rm "$${VERSION_FILE_NEW}"; \ - fi - - -$(ANDR_ROOT)/jni/src/android_version.h : prep_srcdir - @export VERSION_FILE=${ANDR_ROOT}/jni/src/android_version.h; \ - export VERSION_FILE_NEW=$${VERSION_FILE}.new; \ - { \ - echo "#ifndef ANDROID_MT_VERSION_H"; \ - echo "#define ANDROID_MT_VERSION_H"; \ - echo "#define VERSION_MAJOR ${VERSION_MAJOR}"; \ - echo "#define VERSION_MINOR ${VERSION_MINOR}"; \ - echo "#define VERSION_PATCH ${VERSION_PATCH}"; \ - echo "#define VERSION_STRING STR(VERSION_MAJOR) \".\" STR(VERSION_MINOR) \ - \".\" STR(VERSION_PATCH)"; \ - echo "#endif"; \ - } > $${VERSION_FILE_NEW}; \ - if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \ - echo "android_version.h changed, updating..."; \ - mv "$${VERSION_FILE_NEW}" "$${VERSION_FILE}"; \ - else \ - rm "$${VERSION_FILE_NEW}"; \ - fi - -clean : clean_apk clean_assets diff --git a/build/android/app/build.gradle b/build/android/app/build.gradle new file mode 100644 index 000000000..6a34a6d70 --- /dev/null +++ b/build/android/app/build.gradle @@ -0,0 +1,108 @@ +apply plugin: 'com.android.application' +android { + compileSdkVersion 29 + buildToolsVersion '29.0.3' + ndkVersion '21.0.6113669' + defaultConfig { + applicationId 'net.minetest.minetest' + minSdkVersion 16 + //noinspection OldTargetApi + targetSdkVersion 28 // Workaround for using `/sdcard` instead of the `data` patch for assets + versionName "${versionMajor}.${versionMinor}.${versionPatch}" + versionCode project.versionCode + } + + Properties props = new Properties() + props.load(new FileInputStream(file('../local.properties'))) + + if (props.getProperty('keystore') != null) { + signingConfigs { + release { + storeFile file(props['keystore']) + storePassword props['keystore.password'] + keyAlias props['key'] + keyPassword props['key.password'] + } + } + + buildTypes { + release { + minifyEnabled true + signingConfig signingConfigs.release + } + } + } + + // for multiple APKs + splits { + abi { + enable true + reset() + include 'armeabi-v7a', 'arm64-v8a' + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +task prepareAssets() { + def assetsFolder = "build/assets" + def projRoot = "../../.." + def gameToCopy = "minetest_game" + + copy { + from "${projRoot}/minetest.conf.example", "${projRoot}/README.md" into assetsFolder + } + copy { + from "${projRoot}/doc/lgpl-2.1.txt" into "${assetsFolder}" + rename("lgpl-2.1.txt", "LICENSE.txt") + } + copy { + from "${projRoot}/builtin" into "${assetsFolder}/builtin" + } + copy { + from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders" + } + copy { + from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts" + } + copy { + from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}" + } + /*copy { + // locales broken right now + // ToDo: fix it! + from "${projRoot}/po" into "${assetsFolder}/po" + }*/ + copy { + from "${projRoot}/textures" into "${assetsFolder}/textures" + } + + task zipAssets(type: Zip) { + archiveName "Minetest.zip" + from "${assetsFolder}" + destinationDir file("src/main/assets") + } +} + +preBuild.dependsOn zipAssets + +// Map for the version code that gives each ABI a value. +import com.android.build.OutputFile + +def abiCodes = ['armeabi-v7a': 0, 'arm64-v8a': 1] +android.applicationVariants.all { variant -> + variant.outputs.each { + output -> + def abiName = output.getFilter(OutputFile.ABI) + output.versionCodeOverride = abiCodes.get(abiName, 0) + variant.versionCode + } +} + +dependencies { + implementation project(':native') + implementation 'androidx.appcompat:appcompat:1.1.0' +} diff --git a/build/android/app/src/main/AndroidManifest.xml b/build/android/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..3a5342751 --- /dev/null +++ b/build/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/android/app/src/main/java/net/minetest/minetest/CopyZipTask.java b/build/android/app/src/main/java/net/minetest/minetest/CopyZipTask.java new file mode 100644 index 000000000..770995502 --- /dev/null +++ b/build/android/app/src/main/java/net/minetest/minetest/CopyZipTask.java @@ -0,0 +1,82 @@ +/* +Minetest +Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik +Copyright (C) 2014-2020 ubulem, Bektur Mambetov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +package net.minetest.minetest; + +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; +import android.util.Log; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.ref.WeakReference; + +public class CopyZipTask extends AsyncTask { + + private final WeakReference contextRef; + + CopyZipTask(Context context) { + contextRef = new WeakReference<>(context); + } + + protected String doInBackground(String... params) { + copyAssets(params); + return params[0]; + } + + @Override + protected void onPostExecute(String result) { + startUnzipService(result); + } + + private void copyAsset(String zipName) throws IOException { + String filename = zipName.substring(zipName.lastIndexOf("/") + 1); + try (InputStream in = contextRef.get().getAssets().open(filename); + OutputStream out = new FileOutputStream(zipName)) { + copyFile(in, out); + } + } + + private void copyAssets(String[] zips) { + try { + for (String zipName : zips) + copyAsset(zipName); + } catch (IOException e) { + Log.e("CopyZipTask", e.getLocalizedMessage()); + cancel(true); + } + } + + private void copyFile(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + int read; + while ((read = in.read(buffer)) != -1) + out.write(buffer, 0, read); + } + + private void startUnzipService(String file) { + Intent intent = new Intent(contextRef.get(), UnzipService.class); + intent.putExtra(UnzipService.EXTRA_KEY_IN_FILE, file); + contextRef.get().startService(intent); + } +} diff --git a/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java b/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java new file mode 100644 index 000000000..02b61b598 --- /dev/null +++ b/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java @@ -0,0 +1,120 @@ +/* +Minetest +Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik +Copyright (C) 2014-2020 ubulem, Bektur Mambetov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +package net.minetest.minetest; + +import android.app.NativeActivity; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.view.View; +import android.view.WindowManager; + +public class GameActivity extends NativeActivity { + static { + System.loadLibrary("c++_shared"); + System.loadLibrary("Minetest"); + } + + private int messageReturnCode; + private String messageReturnValue; + + public static native void putMessageBoxResult(String text); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + messageReturnCode = -1; + messageReturnValue = ""; + } + + private void makeFullScreen() { + if (Build.VERSION.SDK_INT >= 19) + this.getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + } + + @Override + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + if (hasFocus) + makeFullScreen(); + } + + @Override + protected void onResume() { + super.onResume(); + makeFullScreen(); + } + + @Override + public void onBackPressed() { + // Ignore the back press so Minetest can handle it + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 101) { + if (resultCode == RESULT_OK) { + String text = data.getStringExtra("text"); + messageReturnCode = 0; + messageReturnValue = text; + } else + messageReturnCode = 1; + } + } + + public void showDialog(String acceptButton, String hint, String current, int editType) { + Intent intent = new Intent(this, InputDialogActivity.class); + Bundle params = new Bundle(); + params.putString("acceptButton", acceptButton); + params.putString("hint", hint); + params.putString("current", current); + params.putInt("editType", editType); + intent.putExtras(params); + startActivityForResult(intent, 101); + messageReturnValue = ""; + messageReturnCode = -1; + } + + public int getDialogState() { + return messageReturnCode; + } + + public String getDialogValue() { + messageReturnCode = -1; + return messageReturnValue; + } + + public float getDensity() { + return getResources().getDisplayMetrics().density; + } + + public int getDisplayHeight() { + return getResources().getDisplayMetrics().heightPixels; + } + + public int getDisplayWidth() { + return getResources().getDisplayMetrics().widthPixels; + } +} diff --git a/build/android/app/src/main/java/net/minetest/minetest/InputDialogActivity.java b/build/android/app/src/main/java/net/minetest/minetest/InputDialogActivity.java new file mode 100644 index 000000000..7c6aa111d --- /dev/null +++ b/build/android/app/src/main/java/net/minetest/minetest/InputDialogActivity.java @@ -0,0 +1,98 @@ +/* +Minetest +Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik +Copyright (C) 2014-2020 ubulem, Bektur Mambetov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +package net.minetest.minetest; + +import android.app.Activity; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.text.InputType; +import android.view.KeyEvent; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; + +import java.util.Objects; + +public class InputDialogActivity extends AppCompatActivity { + private AlertDialog alertDialog; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Bundle b = getIntent().getExtras(); + int editType = Objects.requireNonNull(b).getInt("editType"); + String hint = b.getString("hint"); + String current = b.getString("current"); + final AlertDialog.Builder builder = new AlertDialog.Builder(this); + EditText editText = new EditText(this); + builder.setView(editText); + editText.requestFocus(); + editText.setHint(hint); + editText.setText(current); + final InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); + Objects.requireNonNull(imm).toggleSoftInput(InputMethodManager.SHOW_FORCED, + InputMethodManager.HIDE_IMPLICIT_ONLY); + if (editType == 3) + editText.setInputType(InputType.TYPE_CLASS_TEXT | + InputType.TYPE_TEXT_VARIATION_PASSWORD); + else + editText.setInputType(InputType.TYPE_CLASS_TEXT); + editText.setOnKeyListener((view, KeyCode, event) -> { + if (KeyCode == KeyEvent.KEYCODE_ENTER) { + imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); + pushResult(editText.getText().toString()); + return true; + } + return false; + }); + alertDialog = builder.create(); + if (!this.isFinishing()) + alertDialog.show(); + alertDialog.setOnCancelListener(dialog -> { + pushResult(editText.getText().toString()); + setResult(Activity.RESULT_CANCELED); + alertDialog.dismiss(); + makeFullScreen(); + finish(); + }); + } + + private void pushResult(String text) { + Intent resultData = new Intent(); + resultData.putExtra("text", text); + setResult(AppCompatActivity.RESULT_OK, resultData); + alertDialog.dismiss(); + makeFullScreen(); + finish(); + } + + private void makeFullScreen() { + if (Build.VERSION.SDK_INT >= 19) + this.getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); + } +} diff --git a/build/android/app/src/main/java/net/minetest/minetest/MainActivity.java b/build/android/app/src/main/java/net/minetest/minetest/MainActivity.java new file mode 100644 index 000000000..f37ae6d4b --- /dev/null +++ b/build/android/app/src/main/java/net/minetest/minetest/MainActivity.java @@ -0,0 +1,139 @@ +/* +Minetest +Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik +Copyright (C) 2014-2020 ubulem, Bektur Mambetov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +package net.minetest.minetest; + +import android.Manifest; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MainActivity extends AppCompatActivity { + private final static int versionCode = BuildConfig.VERSION_CODE; + private final static int PERMISSIONS = 1; + private static final String[] REQUIRED_SDK_PERMISSIONS = + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}; + private static final String SETTINGS = "MinetestSettings"; + private static final String TAG_VERSION_CODE = "versionCode"; + private ProgressBar mProgressBar; + private TextView mTextView; + private SharedPreferences sharedPreferences; + private final BroadcastReceiver myReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int progress = 0; + if (intent != null) + progress = intent.getIntExtra(UnzipService.ACTION_PROGRESS, 0); + if (progress >= 0) { + if (mProgressBar != null) { + mProgressBar.setVisibility(View.VISIBLE); + mProgressBar.setProgress(progress); + } + mTextView.setVisibility(View.VISIBLE); + } else + startNative(); + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + IntentFilter filter = new IntentFilter(UnzipService.ACTION_UPDATE); + registerReceiver(myReceiver, filter); + mProgressBar = findViewById(R.id.progressBar); + mTextView = findViewById(R.id.textView); + sharedPreferences = getSharedPreferences(SETTINGS, Context.MODE_PRIVATE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + checkPermission(); + else + checkAppVersion(); + } + + private void checkPermission() { + final List missingPermissions = new ArrayList<>(); + for (final String permission : REQUIRED_SDK_PERMISSIONS) { + final int result = ContextCompat.checkSelfPermission(this, permission); + if (result != PackageManager.PERMISSION_GRANTED) + missingPermissions.add(permission); + } + if (!missingPermissions.isEmpty()) { + final String[] permissions = missingPermissions + .toArray(new String[0]); + ActivityCompat.requestPermissions(this, permissions, PERMISSIONS); + } else { + final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length]; + Arrays.fill(grantResults, PackageManager.PERMISSION_GRANTED); + onRequestPermissionsResult(PERMISSIONS, REQUIRED_SDK_PERMISSIONS, grantResults); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, + @NonNull String[] permissions, @NonNull int[] grantResults) { + if (requestCode == PERMISSIONS) { + for (int grantResult : grantResults) { + if (grantResult != PackageManager.PERMISSION_GRANTED) { + Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show(); + finish(); + } + } + checkAppVersion(); + } + } + + private void checkAppVersion() { + if (sharedPreferences.getInt(TAG_VERSION_CODE, 0) == versionCode) + startNative(); + else + new CopyZipTask(this).execute(getCacheDir() + "/Minetest.zip"); + } + + private void startNative() { + sharedPreferences.edit().putInt(TAG_VERSION_CODE, versionCode).apply(); + Intent intent = new Intent(this, GameActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + unregisterReceiver(myReceiver); + } +} diff --git a/build/android/app/src/main/java/net/minetest/minetest/UnzipService.java b/build/android/app/src/main/java/net/minetest/minetest/UnzipService.java new file mode 100644 index 000000000..ac9116994 --- /dev/null +++ b/build/android/app/src/main/java/net/minetest/minetest/UnzipService.java @@ -0,0 +1,153 @@ +/* +Minetest +Copyright (C) 2014-2020 MoNTE48, Maksim Gamarnik +Copyright (C) 2014-2020 ubulem, Bektur Mambetov + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +package net.minetest.minetest; + +import android.app.IntentService; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Environment; +import android.util.Log; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; + +public class UnzipService extends IntentService { + public static final String ACTION_UPDATE = "net.minetest.minetest.UPDATE"; + public static final String ACTION_PROGRESS = "net.minetest.minetest.PROGRESS"; + public static final String EXTRA_KEY_IN_FILE = "file"; + private static final String TAG = "UnzipService"; + private final int id = 1; + private NotificationManager mNotifyManager; + + public UnzipService() { + super("net.minetest.minetest.UnzipService"); + } + + private void isDir(String dir, String location) { + File f = new File(location + dir); + if (!f.isDirectory()) + f.mkdirs(); + } + + @Override + protected void onHandleIntent(Intent intent) { + createNotification(); + unzip(intent); + } + + private void createNotification() { + String name = "net.minetest.minetest"; + String channelId = "Minetest channel"; + String description = "notifications from Minetest"; + Notification.Builder builder; + if (mNotifyManager == null) + mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + int importance = NotificationManager.IMPORTANCE_LOW; + NotificationChannel mChannel = null; + if (mNotifyManager != null) + mChannel = mNotifyManager.getNotificationChannel(channelId); + if (mChannel == null) { + mChannel = new NotificationChannel(channelId, name, importance); + mChannel.setDescription(description); + // Configure the notification channel, NO SOUND + mChannel.setSound(null, null); + mChannel.enableLights(false); + mChannel.enableVibration(false); + mNotifyManager.createNotificationChannel(mChannel); + } + builder = new Notification.Builder(this, channelId); + } else { + builder = new Notification.Builder(this); + } + builder.setContentTitle(getString(R.string.notification_title)) + .setSmallIcon(R.mipmap.ic_launcher) + .setContentText(getString(R.string.notification_description)); + mNotifyManager.notify(id, builder.build()); + } + + private void unzip(Intent intent) { + String zip = intent.getStringExtra(EXTRA_KEY_IN_FILE); + String location = Environment.getExternalStorageDirectory() + "/Minetest/"; + int per = 0; + int size = getSummarySize(zip); + File zipFile = new File(zip); + int readLen; + byte[] readBuffer = new byte[8192]; + try (FileInputStream fileInputStream = new FileInputStream(zipFile); + ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) { + ZipEntry ze; + while ((ze = zipInputStream.getNextEntry()) != null) { + if (ze.isDirectory()) { + ++per; + isDir(ze.getName(), location); + } else { + publishProgress(100 * ++per / size); + try (OutputStream outputStream = new FileOutputStream(location + ze.getName())) { + while ((readLen = zipInputStream.read(readBuffer)) != -1) { + outputStream.write(readBuffer, 0, readLen); + } + } + } + zipFile.delete(); + } + } catch (FileNotFoundException e) { + Log.e(TAG, e.getLocalizedMessage()); + } catch (IOException e) { + Log.e(TAG, e.getLocalizedMessage()); + } + } + + private void publishProgress(int progress) { + Intent intentUpdate = new Intent(ACTION_UPDATE); + intentUpdate.putExtra(ACTION_PROGRESS, progress); + sendBroadcast(intentUpdate); + } + + private int getSummarySize(String zip) { + int size = 0; + try { + ZipFile zipSize = new ZipFile(zip); + size += zipSize.size(); + } catch (IOException e) { + Log.e(TAG, e.getLocalizedMessage()); + } + return size; + } + + @Override + public void onDestroy() { + super.onDestroy(); + mNotifyManager.cancel(id); + publishProgress(-1); + } +} diff --git a/build/android/app/src/main/res/drawable/background.png b/build/android/app/src/main/res/drawable/background.png new file mode 100644 index 000000000..43bd6089e Binary files /dev/null and b/build/android/app/src/main/res/drawable/background.png differ diff --git a/build/android/app/src/main/res/drawable/bg.xml b/build/android/app/src/main/res/drawable/bg.xml new file mode 100644 index 000000000..903335ed9 --- /dev/null +++ b/build/android/app/src/main/res/drawable/bg.xml @@ -0,0 +1,4 @@ + + diff --git a/build/android/app/src/main/res/layout/activity_main.xml b/build/android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..e6f461f14 --- /dev/null +++ b/build/android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,30 @@ + + + + + + + diff --git a/build/android/app/src/main/res/mipmap/ic_launcher.png b/build/android/app/src/main/res/mipmap/ic_launcher.png new file mode 100644 index 000000000..88a83782c Binary files /dev/null and b/build/android/app/src/main/res/mipmap/ic_launcher.png differ diff --git a/build/android/app/src/main/res/values/strings.xml b/build/android/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..a6fba70d5 --- /dev/null +++ b/build/android/app/src/main/res/values/strings.xml @@ -0,0 +1,10 @@ + + + + Minetest + Loading… + Required permission wasn\'t granted, Minetest can\'t run without it + Loading Minetest + Less than 1 minute… + + diff --git a/build/android/app/src/main/res/values/styles.xml b/build/android/app/src/main/res/values/styles.xml new file mode 100644 index 000000000..618507e63 --- /dev/null +++ b/build/android/app/src/main/res/values/styles.xml @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/build/android/build.gradle b/build/android/build.gradle index fa74cd497..b02e8c6df 100644 --- a/build/android/build.gradle +++ b/build/android/build.gradle @@ -1,10 +1,24 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +project.ext.set("versionMajor", 5) // Version Major +project.ext.set("versionMinor", 3) // Version Minor +project.ext.set("versionPatch", 0) // Version Patch +project.ext.set("versionExtra", "-dev") // Version Extra +project.ext.set("versionCode", 26) // Android Version Code +// NOTE: +2 after each release! +// +1 for ARM and +1 for ARM64 APK's, because +// each APK must have a larger `versionCode` than the previous + buildscript { repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' + classpath 'com.android.tools.build:gradle:3.6.2' + classpath 'org.ajoberstar.grgit:grgit-gradle:4.0.2' + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files } } @@ -15,161 +29,6 @@ allprojects { } } -def curl_version = "7.60.0" -def irrlicht_revision = "5150" -def openal_version = "1.18.2" -def openssl_version = "1.0.2n" -def sqlite3_version = "3240000" - -apply plugin: "com.android.application" - -android { - compileSdkVersion 29 - buildToolsVersion '29.0.2' - - defaultConfig { - versionCode 26 - versionName "${System.env.VERSION_STR}.${versionCode}" - minSdkVersion 14 - targetSdkVersion 29 - applicationId "net.minetest.minetest" - manifestPlaceholders = [package: "net.minetest.minetest", project: project.name] - ndk { - // Specifies the ABI configurations of your native - // libraries Gradle should build and package with your APK. - // abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' - abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a' - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - lintOptions { - disable "OldTargetApi", "GoogleAppIndexingWarning" - } - - Properties props = new Properties() - props.load(new FileInputStream(file("local.properties"))) - - if (props.getProperty("keystore") != null) { - signingConfigs { - release { - storeFile file(props["keystore"]) - storePassword props["keystore.password"] - keyAlias props["key"] - keyPassword props["key.password"] - } - } - - buildTypes { - release { - signingConfig signingConfigs.release - } - } - } -} - -task cleanAssets(type: Delete) { - delete 'src/main/assets' -} - -task copyAssets { - dependsOn 'cleanAssets' - mkdir "src/main/assets" - - def mtAssetsFolder = "src/main/assets/Minetest" - def projRoot = "../.." - def gameToCopy = "minetest_game" - - doLast { - mkdir "${mtAssetsFolder}" - mkdir "${mtAssetsFolder}/client" - mkdir "${mtAssetsFolder}/fonts" - mkdir "${mtAssetsFolder}/games" - mkdir "${mtAssetsFolder}/media" - - copy { - from "${projRoot}/minetest.conf.example", "${projRoot}/README.md" into mtAssetsFolder - } - copy { - from "${projRoot}/doc/lgpl-2.1.txt" into "${mtAssetsFolder}/LICENSE.txt" - } - copy { - from "${projRoot}/builtin" into "${mtAssetsFolder}/builtin" - } - copy { - from "${projRoot}/client/shaders" into "${mtAssetsFolder}/client/shaders" - } - copy { - from "${projRoot}/fonts" include "*.ttf" into "${mtAssetsFolder}/fonts" - } - copy { - from "${projRoot}/games/${gameToCopy}" into "${mtAssetsFolder}/games/${gameToCopy}" - } - copy { - from "${projRoot}/po" into "${mtAssetsFolder}/po" - } - copy { - from "${projRoot}/textures" into "${mtAssetsFolder}/textures" - } - } -} - -task cleanIconv(type: Delete) { - delete 'deps/libiconv' -} - -task cleanIrrlicht(type: Delete) { - delete 'deps/irrlicht' -} - -task cleanLevelDB(type: Delete) { - delete 'deps/leveldb' -} - -task cleanCURL(type: Delete) { - delete 'deps/curl' - delete 'deps/curl-' + curl_version -} - -task cleanOpenSSL(type: Delete) { - delete 'deps/openssl' - delete 'deps/openssl-' + openssl_version - delete 'deps/openssl-' + openssl_version + '.tar.gz' -} - -task cleanOpenAL(type: Delete) { - delete 'deps/openal-soft' -} - -task cleanFreetype(type: Delete) { - delete 'deps/freetype2-android' -} - -task cleanOgg(type: Delete) { - delete 'deps/libvorbis-libogg-android' -} - -task cleanSQLite3(type: Delete) { - delete 'deps/sqlite-amalgamation-' + sqlite3_version - delete 'deps/sqlite-amalgamation-' + sqlite3_version + '.zip' -} - -task cleanAll(type: Delete, dependsOn: [clean, cleanAssets, cleanIconv, - cleanFreetype, cleanIrrlicht, cleanLevelDB, cleanSQLite3, cleanCURL, - cleanOpenSSL, cleanOpenAL, cleanOgg]) { - delete 'deps' - delete 'gen' - delete 'libs' - delete 'obj' - delete 'bin' - delete 'Debug' - delete 'and_env' -} - -dependencies { - implementation 'androidx.core:core:1.1.0' +task clean(type: Delete) { + delete rootProject.buildDir } diff --git a/build/android/gradle.properties b/build/android/gradle.properties index 5465fec0e..53b475cf9 100644 --- a/build/android/gradle.properties +++ b/build/android/gradle.properties @@ -1,2 +1,11 @@ +<#if isLowMemory> +org.gradle.jvmargs=-Xmx4G -XX:MaxPermSize=2G -XX:+HeapDumpOnOutOfMemoryError +<#else> +org.gradle.jvmargs=-Xmx16G -XX:MaxPermSize=8G -XX:+HeapDumpOnOutOfMemoryError + +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.parallel.threads=8 +org.gradle.configureondemand=true android.enableJetifier=true -android.useAndroidX=true \ No newline at end of file +android.useAndroidX=true diff --git a/build/android/gradle/wrapper/gradle-wrapper.jar b/build/android/gradle/wrapper/gradle-wrapper.jar index 6b6ea3ab4..5c2d1cf01 100644 Binary files a/build/android/gradle/wrapper/gradle-wrapper.jar and b/build/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/build/android/gradle/wrapper/gradle-wrapper.properties b/build/android/gradle/wrapper/gradle-wrapper.properties index 22ac96460..d612cf333 100644 --- a/build/android/gradle/wrapper/gradle-wrapper.properties +++ b/build/android/gradle/wrapper/gradle-wrapper.properties @@ -1 +1,2 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +#Mon Apr 06 00:06:16 CEST 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip diff --git a/build/android/gradlew b/build/android/gradlew index cccdd3d51..83f2acfdc 100755 --- a/build/android/gradlew +++ b/build/android/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` diff --git a/build/android/gradlew.bat b/build/android/gradlew.bat index f9553162f..9618d8d96 100644 --- a/build/android/gradlew.bat +++ b/build/android/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk deleted file mode 100644 index b67322d79..000000000 --- a/build/android/jni/Android.mk +++ /dev/null @@ -1,448 +0,0 @@ -LOCAL_PATH := $(call my-dir)/.. - -#LOCAL_ADDRESS_SANITIZER:=true - -include $(CLEAR_VARS) -LOCAL_MODULE := Irrlicht -LOCAL_SRC_FILES := deps/irrlicht/lib/Android/libIrrlicht.a -include $(PREBUILT_STATIC_LIBRARY) - -ifeq ($(HAVE_LEVELDB), 1) - include $(CLEAR_VARS) - LOCAL_MODULE := LevelDB - LOCAL_SRC_FILES := deps/leveldb/libleveldb.a - include $(PREBUILT_STATIC_LIBRARY) -endif - -include $(CLEAR_VARS) -LOCAL_MODULE := curl -LOCAL_SRC_FILES := deps/curl/lib/.libs/libcurl.a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := freetype -LOCAL_SRC_FILES := deps/freetype2-android/Android/obj/local/$(TARGET_ARCH_ABI)/libfreetype2-static.a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := iconv -LOCAL_SRC_FILES := deps/libiconv/lib/.libs/libiconv.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := openal -LOCAL_SRC_FILES := deps/openal-soft/libs/$(TARGET_LIBDIR)/libopenal.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := ogg -LOCAL_SRC_FILES := deps/libvorbis-libogg-android/libs/$(TARGET_LIBDIR)/libogg.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := vorbis -LOCAL_SRC_FILES := deps/libvorbis-libogg-android/libs/$(TARGET_LIBDIR)/libvorbis.so -include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := ssl -LOCAL_SRC_FILES := deps/openssl/libssl.a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := crypto -LOCAL_SRC_FILES := deps/openssl/libcrypto.a -include $(PREBUILT_STATIC_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := minetest - -LOCAL_CPP_FEATURES += exceptions - -ifdef GPROF -GPROF_DEF=-DGPROF -endif - -LOCAL_CFLAGS := -D_IRR_ANDROID_PLATFORM_ \ - -DHAVE_TOUCHSCREENGUI \ - -DENABLE_GLES=1 \ - -DUSE_CURL=1 \ - -DUSE_SOUND=1 \ - -DUSE_FREETYPE=1 \ - -DUSE_LEVELDB=$(HAVE_LEVELDB) \ - $(GPROF_DEF) \ - -pipe -fstrict-aliasing - -ifndef NDEBUG -LOCAL_CFLAGS += -g -D_DEBUG -O0 -fno-omit-frame-pointer -else -LOCAL_CFLAGS += $(TARGET_CFLAGS_ADDON) -endif - -ifdef GPROF -PROFILER_LIBS := android-ndk-profiler -LOCAL_CFLAGS += -pg -endif - -# LOCAL_CFLAGS += -fsanitize=address -# LOCAL_LDFLAGS += -fsanitize=address - -ifeq ($(TARGET_ABI),x86) -LOCAL_CFLAGS += -fno-stack-protector -endif - -LOCAL_C_INCLUDES := \ - jni/src \ - jni/src/script \ - jni/lib/gmp \ - jni/lib/lua/src \ - jni/lib/jsoncpp \ - jni/src/cguittfont \ - deps/irrlicht/include \ - deps/libiconv/include \ - deps/freetype2-android/include \ - deps/curl/include \ - deps/openal-soft/jni/OpenAL/include \ - deps/libvorbis-libogg-android/jni/include \ - deps/leveldb/include \ - deps/sqlite/ - -LOCAL_SRC_FILES := \ - jni/src/ban.cpp \ - jni/src/chat.cpp \ - jni/src/client/activeobjectmgr.cpp \ - jni/src/client/camera.cpp \ - jni/src/client/client.cpp \ - jni/src/client/clientenvironment.cpp \ - jni/src/client/clientlauncher.cpp \ - jni/src/client/clientmap.cpp \ - jni/src/client/clientmedia.cpp \ - jni/src/client/clientobject.cpp \ - jni/src/client/clouds.cpp \ - jni/src/client/content_cao.cpp \ - jni/src/client/content_cso.cpp \ - jni/src/client/content_mapblock.cpp \ - jni/src/client/filecache.cpp \ - jni/src/client/fontengine.cpp \ - jni/src/client/game.cpp \ - jni/src/client/gameui.cpp \ - jni/src/client/guiscalingfilter.cpp \ - jni/src/client/hud.cpp \ - jni/src/clientiface.cpp \ - jni/src/client/imagefilters.cpp \ - jni/src/client/inputhandler.cpp \ - jni/src/client/joystick_controller.cpp \ - jni/src/client/keycode.cpp \ - jni/src/client/localplayer.cpp \ - jni/src/client/mapblock_mesh.cpp \ - jni/src/client/mesh.cpp \ - jni/src/client/meshgen/collector.cpp \ - jni/src/client/mesh_generator_thread.cpp \ - jni/src/client/minimap.cpp \ - jni/src/client/particles.cpp \ - jni/src/client/render/anaglyph.cpp \ - jni/src/client/render/core.cpp \ - jni/src/client/render/factory.cpp \ - jni/src/client/renderingengine.cpp \ - jni/src/client/render/interlaced.cpp \ - jni/src/client/render/pageflip.cpp \ - jni/src/client/render/plain.cpp \ - jni/src/client/render/sidebyside.cpp \ - jni/src/client/render/stereo.cpp \ - jni/src/client/shader.cpp \ - jni/src/client/sky.cpp \ - jni/src/client/sound.cpp \ - jni/src/client/sound_openal.cpp \ - jni/src/client/tile.cpp \ - jni/src/client/wieldmesh.cpp \ - jni/src/collision.cpp \ - jni/src/content/content.cpp \ - jni/src/content_mapnode.cpp \ - jni/src/content/mods.cpp \ - jni/src/content_nodemeta.cpp \ - jni/src/content/packages.cpp \ - jni/src/content/subgames.cpp \ - jni/src/convert_json.cpp \ - jni/src/craftdef.cpp \ - jni/src/database/database.cpp \ - jni/src/database/database-dummy.cpp \ - jni/src/database/database-files.cpp \ - jni/src/database/database-leveldb.cpp \ - jni/src/database/database-sqlite3.cpp \ - jni/src/debug.cpp \ - jni/src/defaultsettings.cpp \ - jni/src/emerge.cpp \ - jni/src/environment.cpp \ - jni/src/face_position_cache.cpp \ - jni/src/filesys.cpp \ - jni/src/gettext.cpp \ - jni/src/gui/guiAnimatedImage.cpp \ - jni/src/gui/guiBackgroundImage.cpp \ - jni/src/gui/guiBox.cpp \ - jni/src/gui/guiButton.cpp \ - jni/src/gui/guiButtonImage.cpp \ - jni/src/gui/guiButtonItemImage.cpp \ - jni/src/gui/guiChatConsole.cpp \ - jni/src/gui/guiConfirmRegistration.cpp \ - jni/src/gui/guiEditBoxWithScrollbar.cpp \ - jni/src/gui/guiEngine.cpp \ - jni/src/gui/guiFormSpecMenu.cpp \ - jni/src/gui/guiHyperText.cpp \ - jni/src/gui/guiInventoryList.cpp \ - jni/src/gui/guiItemImage.cpp \ - jni/src/gui/guiKeyChangeMenu.cpp \ - jni/src/gui/guiPasswordChange.cpp \ - jni/src/gui/guiPathSelectMenu.cpp \ - jni/src/gui/guiScrollBar.cpp \ - jni/src/gui/guiScrollContainer.cpp \ - jni/src/gui/guiSkin.cpp \ - jni/src/gui/guiTable.cpp \ - jni/src/gui/guiVolumeChange.cpp \ - jni/src/gui/intlGUIEditBox.cpp \ - jni/src/gui/modalMenu.cpp \ - jni/src/gui/profilergraph.cpp \ - jni/src/gui/touchscreengui.cpp \ - jni/src/httpfetch.cpp \ - jni/src/hud.cpp \ - jni/src/inventory.cpp \ - jni/src/inventorymanager.cpp \ - jni/src/irrlicht_changes/CGUITTFont.cpp \ - jni/src/irrlicht_changes/static_text.cpp \ - jni/src/itemdef.cpp \ - jni/src/itemstackmetadata.cpp \ - jni/src/light.cpp \ - jni/src/log.cpp \ - jni/src/main.cpp \ - jni/src/mapblock.cpp \ - jni/src/map.cpp \ - jni/src/mapgen/cavegen.cpp \ - jni/src/mapgen/dungeongen.cpp \ - jni/src/mapgen/mapgen_carpathian.cpp \ - jni/src/mapgen/mapgen.cpp \ - jni/src/mapgen/mapgen_flat.cpp \ - jni/src/mapgen/mapgen_fractal.cpp \ - jni/src/mapgen/mapgen_singlenode.cpp \ - jni/src/mapgen/mapgen_v5.cpp \ - jni/src/mapgen/mapgen_v6.cpp \ - jni/src/mapgen/mapgen_v7.cpp \ - jni/src/mapgen/mapgen_valleys.cpp \ - jni/src/mapgen/mg_biome.cpp \ - jni/src/mapgen/mg_decoration.cpp \ - jni/src/mapgen/mg_ore.cpp \ - jni/src/mapgen/mg_schematic.cpp \ - jni/src/mapgen/treegen.cpp \ - jni/src/mapnode.cpp \ - jni/src/mapsector.cpp \ - jni/src/map_settings_manager.cpp \ - jni/src/metadata.cpp \ - jni/src/modchannels.cpp \ - jni/src/nameidmapping.cpp \ - jni/src/nodedef.cpp \ - jni/src/nodemetadata.cpp \ - jni/src/nodetimer.cpp \ - jni/src/noise.cpp \ - jni/src/objdef.cpp \ - jni/src/object_properties.cpp \ - jni/src/pathfinder.cpp \ - jni/src/player.cpp \ - jni/src/porting_android.cpp \ - jni/src/porting.cpp \ - jni/src/profiler.cpp \ - jni/src/raycast.cpp \ - jni/src/reflowscan.cpp \ - jni/src/remoteplayer.cpp \ - jni/src/rollback.cpp \ - jni/src/rollback_interface.cpp \ - jni/src/serialization.cpp \ - jni/src/server/activeobjectmgr.cpp \ - jni/src/server.cpp \ - jni/src/serverenvironment.cpp \ - jni/src/serverlist.cpp \ - jni/src/server/luaentity_sao.cpp \ - jni/src/server/mods.cpp \ - jni/src/server/player_sao.cpp \ - jni/src/server/serveractiveobject.cpp \ - jni/src/server/unit_sao.cpp \ - jni/src/settings.cpp \ - jni/src/staticobject.cpp \ - jni/src/tileanimation.cpp \ - jni/src/tool.cpp \ - jni/src/translation.cpp \ - jni/src/unittest/test_authdatabase.cpp \ - jni/src/unittest/test_collision.cpp \ - jni/src/unittest/test_compression.cpp \ - jni/src/unittest/test_connection.cpp \ - jni/src/unittest/test.cpp \ - jni/src/unittest/test_filepath.cpp \ - jni/src/unittest/test_gameui.cpp \ - jni/src/unittest/test_inventory.cpp \ - jni/src/unittest/test_mapnode.cpp \ - jni/src/unittest/test_map_settings_manager.cpp \ - jni/src/unittest/test_nodedef.cpp \ - jni/src/unittest/test_noderesolver.cpp \ - jni/src/unittest/test_noise.cpp \ - jni/src/unittest/test_objdef.cpp \ - jni/src/unittest/test_profiler.cpp \ - jni/src/unittest/test_random.cpp \ - jni/src/unittest/test_schematic.cpp \ - jni/src/unittest/test_serialization.cpp \ - jni/src/unittest/test_settings.cpp \ - jni/src/unittest/test_socket.cpp \ - jni/src/unittest/test_utilities.cpp \ - jni/src/unittest/test_voxelalgorithms.cpp \ - jni/src/unittest/test_voxelmanipulator.cpp \ - jni/src/util/areastore.cpp \ - jni/src/util/auth.cpp \ - jni/src/util/base64.cpp \ - jni/src/util/directiontables.cpp \ - jni/src/util/enriched_string.cpp \ - jni/src/util/ieee_float.cpp \ - jni/src/util/numeric.cpp \ - jni/src/util/pointedthing.cpp \ - jni/src/util/quicktune.cpp \ - jni/src/util/serialize.cpp \ - jni/src/util/sha1.cpp \ - jni/src/util/srp.cpp \ - jni/src/util/string.cpp \ - jni/src/util/timetaker.cpp \ - jni/src/version.cpp \ - jni/src/voxelalgorithms.cpp \ - jni/src/voxel.cpp - - -# intentionally kept out (we already build openssl itself): jni/src/util/sha256.c - -# Network -LOCAL_SRC_FILES += \ - jni/src/network/address.cpp \ - jni/src/network/connection.cpp \ - jni/src/network/networkpacket.cpp \ - jni/src/network/clientopcodes.cpp \ - jni/src/network/clientpackethandler.cpp \ - jni/src/network/connectionthreads.cpp \ - jni/src/network/serveropcodes.cpp \ - jni/src/network/serverpackethandler.cpp \ - jni/src/network/socket.cpp \ - -# lua api -LOCAL_SRC_FILES += \ - jni/src/script/common/c_content.cpp \ - jni/src/script/common/c_converter.cpp \ - jni/src/script/common/c_internal.cpp \ - jni/src/script/common/c_types.cpp \ - jni/src/script/common/helper.cpp \ - jni/src/script/cpp_api/s_async.cpp \ - jni/src/script/cpp_api/s_base.cpp \ - jni/src/script/cpp_api/s_client.cpp \ - jni/src/script/cpp_api/s_entity.cpp \ - jni/src/script/cpp_api/s_env.cpp \ - jni/src/script/cpp_api/s_inventory.cpp \ - jni/src/script/cpp_api/s_item.cpp \ - jni/src/script/cpp_api/s_mainmenu.cpp \ - jni/src/script/cpp_api/s_modchannels.cpp \ - jni/src/script/cpp_api/s_node.cpp \ - jni/src/script/cpp_api/s_nodemeta.cpp \ - jni/src/script/cpp_api/s_player.cpp \ - jni/src/script/cpp_api/s_security.cpp \ - jni/src/script/cpp_api/s_server.cpp \ - jni/src/script/lua_api/l_areastore.cpp \ - jni/src/script/lua_api/l_auth.cpp \ - jni/src/script/lua_api/l_base.cpp \ - jni/src/script/lua_api/l_camera.cpp \ - jni/src/script/lua_api/l_client.cpp \ - jni/src/script/lua_api/l_craft.cpp \ - jni/src/script/lua_api/l_env.cpp \ - jni/src/script/lua_api/l_inventory.cpp \ - jni/src/script/lua_api/l_item.cpp \ - jni/src/script/lua_api/l_itemstackmeta.cpp\ - jni/src/script/lua_api/l_localplayer.cpp \ - jni/src/script/lua_api/l_mainmenu.cpp \ - jni/src/script/lua_api/l_mapgen.cpp \ - jni/src/script/lua_api/l_metadata.cpp \ - jni/src/script/lua_api/l_minimap.cpp \ - jni/src/script/lua_api/l_modchannels.cpp \ - jni/src/script/lua_api/l_nodemeta.cpp \ - jni/src/script/lua_api/l_nodetimer.cpp \ - jni/src/script/lua_api/l_noise.cpp \ - jni/src/script/lua_api/l_object.cpp \ - jni/src/script/lua_api/l_playermeta.cpp \ - jni/src/script/lua_api/l_particles.cpp \ - jni/src/script/lua_api/l_particles_local.cpp\ - jni/src/script/lua_api/l_rollback.cpp \ - jni/src/script/lua_api/l_server.cpp \ - jni/src/script/lua_api/l_settings.cpp \ - jni/src/script/lua_api/l_sound.cpp \ - jni/src/script/lua_api/l_http.cpp \ - jni/src/script/lua_api/l_storage.cpp \ - jni/src/script/lua_api/l_util.cpp \ - jni/src/script/lua_api/l_vmanip.cpp \ - jni/src/script/scripting_client.cpp \ - jni/src/script/scripting_server.cpp \ - jni/src/script/scripting_mainmenu.cpp - -#freetype2 support -#LOCAL_SRC_FILES += jni/src/cguittfont/xCGUITTFont.cpp - -# GMP -LOCAL_SRC_FILES += jni/lib/gmp/mini-gmp.c - -# Lua -LOCAL_SRC_FILES += \ - jni/lib/lua/src/lapi.c \ - jni/lib/lua/src/lauxlib.c \ - jni/lib/lua/src/lbaselib.c \ - jni/lib/lua/src/lcode.c \ - jni/lib/lua/src/ldblib.c \ - jni/lib/lua/src/ldebug.c \ - jni/lib/lua/src/ldo.c \ - jni/lib/lua/src/ldump.c \ - jni/lib/lua/src/lfunc.c \ - jni/lib/lua/src/lgc.c \ - jni/lib/lua/src/linit.c \ - jni/lib/lua/src/liolib.c \ - jni/lib/lua/src/llex.c \ - jni/lib/lua/src/lmathlib.c \ - jni/lib/lua/src/lmem.c \ - jni/lib/lua/src/loadlib.c \ - jni/lib/lua/src/lobject.c \ - jni/lib/lua/src/lopcodes.c \ - jni/lib/lua/src/loslib.c \ - jni/lib/lua/src/lparser.c \ - jni/lib/lua/src/lstate.c \ - jni/lib/lua/src/lstring.c \ - jni/lib/lua/src/lstrlib.c \ - jni/lib/lua/src/ltable.c \ - jni/lib/lua/src/ltablib.c \ - jni/lib/lua/src/ltm.c \ - jni/lib/lua/src/lundump.c \ - jni/lib/lua/src/lvm.c \ - jni/lib/lua/src/lzio.c \ - jni/lib/lua/src/print.c - -# SQLite3 -LOCAL_SRC_FILES += deps/sqlite/sqlite3.c - -# Threading -LOCAL_SRC_FILES += \ - jni/src/threading/event.cpp \ - jni/src/threading/semaphore.cpp \ - jni/src/threading/thread.cpp - -# JSONCPP -LOCAL_SRC_FILES += jni/lib/jsoncpp/jsoncpp.cpp - -LOCAL_SHARED_LIBRARIES := iconv openal ogg vorbis -LOCAL_STATIC_LIBRARIES := Irrlicht freetype curl ssl crypto android_native_app_glue $(PROFILER_LIBS) - -ifeq ($(HAVE_LEVELDB), 1) - LOCAL_STATIC_LIBRARIES += LevelDB -endif -LOCAL_LDLIBS := -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid - -include $(BUILD_SHARED_LIBRARY) - -# at the end of Android.mk -ifdef GPROF -$(call import-module,android-ndk-profiler) -endif -$(call import-module,android/native_app_glue) diff --git a/build/android/jni/Application.mk b/build/android/jni/Application.mk deleted file mode 100644 index f5eb96ed1..000000000 --- a/build/android/jni/Application.mk +++ /dev/null @@ -1,9 +0,0 @@ -APP_PLATFORM := ${APP_PLATFORM} -APP_ABI := ${TARGET_ABI} -APP_STL := c++_shared -APP_MODULES := minetest -ifndef NDEBUG -APP_OPTIM := debug -endif - -APP_CPPFLAGS += -fexceptions -std=c++11 -frtti diff --git a/build/android/jni/Deps.mk b/build/android/jni/Deps.mk deleted file mode 100644 index 73db2353f..000000000 --- a/build/android/jni/Deps.mk +++ /dev/null @@ -1,7 +0,0 @@ -APP_PLATFORM := ${APP_PLATFORM} -APP_ABI := ${TARGET_ABI} -APP_STL := c++_shared -APP_DEPRECATED_HEADERS := true - -APP_CFLAGS += ${TARGET_CFLAGS_ADDON} -APP_CPPFLAGS += ${TARGET_CXXFLAGS_ADDON} -fexceptions -std=c++11 diff --git a/build/android/jni/Irrlicht.mk b/build/android/jni/Irrlicht.mk deleted file mode 100644 index cedfe3139..000000000 --- a/build/android/jni/Irrlicht.mk +++ /dev/null @@ -1,8 +0,0 @@ -APP_PLATFORM := ${APP_PLATFORM} -APP_ABI := ${TARGET_ABI} -APP_STL := c++_shared -APP_DEPRECATED_HEADERS := true -APP_MODULES := Irrlicht - -APP_CLAFGS += ${TARGET_CFLAGS_ADDON} -APP_CPPFLAGS += ${TARGET_CXXFLAGS_ADDON} -fexceptions diff --git a/build/android/native/build.gradle b/build/android/native/build.gradle new file mode 100644 index 000000000..f06e4e3f0 --- /dev/null +++ b/build/android/native/build.gradle @@ -0,0 +1,59 @@ +apply plugin: 'com.android.library' +import org.ajoberstar.grgit.Grgit + +android { + compileSdkVersion 29 + buildToolsVersion '29.0.3' + ndkVersion '21.0.6113669' + defaultConfig { + minSdkVersion 16 + targetSdkVersion 29 + externalNativeBuild { + ndkBuild { + arguments '-j8', + "versionMajor=${versionMajor}", + "versionMinor=${versionMinor}", + "versionPatch=${versionPatch}", + "versionExtra=${versionExtra}" + } + } + } + + externalNativeBuild { + ndkBuild { + path file('jni/Android.mk') + } + } + + // supported architectures + splits { + abi { + enable true + reset() + include 'armeabi-v7a', 'arm64-v8a'//, 'x86' + } + } + + buildTypes { + release { + externalNativeBuild { + ndkBuild { + arguments 'NDEBUG=1' + } + } + } + } +} + +task cloneGitRepo() { + def destination = file('deps') + if(!destination.exists()) { + def grgit = Grgit.clone( + dir: destination, + uri: 'https://github.com/minetest/minetest_android_deps_binaries' + ) + grgit.close() + } +} + +preBuild.dependsOn cloneGitRepo diff --git a/build/android/native/jni/Android.mk b/build/android/native/jni/Android.mk new file mode 100644 index 000000000..a5cb099e6 --- /dev/null +++ b/build/android/native/jni/Android.mk @@ -0,0 +1,218 @@ +LOCAL_PATH := $(call my-dir)/.. + +#LOCAL_ADDRESS_SANITIZER:=true + +include $(CLEAR_VARS) +LOCAL_MODULE := Curl +LOCAL_SRC_FILES := deps/Android/Curl/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libcurl.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := Freetype +LOCAL_SRC_FILES := deps/Android/Freetype/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libfreetype.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := Irrlicht +LOCAL_SRC_FILES := deps/Android/Irrlicht/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libIrrlicht.a +include $(PREBUILT_STATIC_LIBRARY) + +#include $(CLEAR_VARS) +#LOCAL_MODULE := LevelDB +#LOCAL_SRC_FILES := deps/Android/LevelDB/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libleveldb.a +#include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := LuaJIT +LOCAL_SRC_FILES := deps/Android/LuaJIT/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libluajit.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := mbedTLS +LOCAL_SRC_FILES := deps/Android/mbedTLS/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libmbedtls.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := mbedx509 +LOCAL_SRC_FILES := deps/Android/mbedTLS/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libmbedx509.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := mbedcrypto +LOCAL_SRC_FILES := deps/Android/mbedTLS/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libmbedcrypto.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := OpenAL +LOCAL_SRC_FILES := deps/Android/OpenAL-Soft/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libopenal.a +include $(PREBUILT_STATIC_LIBRARY) + +# You can use `OpenSSL and Crypto` instead `mbedTLS mbedx509 mbedcrypto`, +#but it increase APK size on ~0.7MB +#include $(CLEAR_VARS) +#LOCAL_MODULE := OpenSSL +#LOCAL_SRC_FILES := deps/Android/OpenSSL/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libssl.a +#include $(PREBUILT_STATIC_LIBRARY) + +#include $(CLEAR_VARS) +#LOCAL_MODULE := Crypto +#LOCAL_SRC_FILES := deps/Android/OpenSSL/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libcrypto.a +#include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := Vorbis +LOCAL_SRC_FILES := deps/Android/Vorbis/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libvorbis.a +include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := Minetest + +LOCAL_CFLAGS += \ + -DJSONCPP_NO_LOCALE_SUPPORT \ + -DHAVE_TOUCHSCREENGUI \ + -DENABLE_GLES=1 \ + -DUSE_CURL=1 \ + -DUSE_SOUND=1 \ + -DUSE_FREETYPE=1 \ + -DUSE_LEVELDB=0 \ + -DUSE_LUAJIT=1 \ + -DVERSION_MAJOR=${versionMajor} \ + -DVERSION_MINOR=${versionMinor} \ + -DVERSION_PATCH=${versionPatch} \ + -DVERSION_EXTRA=${versionExtra} \ + $(GPROF_DEF) + +ifdef NDEBUG + LOCAL_CFLAGS += -DNDEBUG=1 +endif + +ifdef GPROF + GPROF_DEF := -DGPROF + PROFILER_LIBS := android-ndk-profiler + LOCAL_CFLAGS += -pg +endif + +LOCAL_C_INCLUDES := \ + ../../../src \ + ../../../src/script \ + ../../../lib/gmp \ + ../../../lib/jsoncpp \ + deps/Android/Curl/include \ + deps/Android/Freetype/include \ + deps/Android/Irrlicht/include \ + deps/Android/LevelDB/include \ + deps/Android/libiconv/include \ + deps/Android/libiconv/libcharset/include \ + deps/Android/LuaJIT/src \ + deps/Android/OpenAL-Soft/include \ + deps/Android/sqlite \ + deps/Android/Vorbis/include + +LOCAL_SRC_FILES := \ + $(wildcard ../../../src/client/*.cpp) \ + $(wildcard ../../../src/client/*/*.cpp) \ + $(wildcard ../../../src/content/*.cpp) \ + ../../../src/database/database.cpp \ + ../../../src/database/database-dummy.cpp \ + ../../../src/database/database-files.cpp \ + ../../../src/database/database-sqlite3.cpp \ + $(wildcard ../../../src/gui/*.cpp) \ + $(wildcard ../../../src/irrlicht_changes/*.cpp) \ + $(wildcard ../../../src/mapgen/*.cpp) \ + $(wildcard ../../../src/network/*.cpp) \ + $(wildcard ../../../src/script/*.cpp) \ + $(wildcard ../../../src/script/*/*.cpp) \ + $(wildcard ../../../src/server/*.cpp) \ + $(wildcard ../../../src/threading/*.cpp) \ + $(wildcard ../../../src/util/*.c) \ + $(wildcard ../../../src/util/*.cpp) \ + ../../../src/ban.cpp \ + ../../../src/chat.cpp \ + ../../../src/clientiface.cpp \ + ../../../src/collision.cpp \ + ../../../src/content_mapnode.cpp \ + ../../../src/content_nodemeta.cpp \ + ../../../src/convert_json.cpp \ + ../../../src/craftdef.cpp \ + ../../../src/debug.cpp \ + ../../../src/defaultsettings.cpp \ + ../../../src/emerge.cpp \ + ../../../src/environment.cpp \ + ../../../src/face_position_cache.cpp \ + ../../../src/filesys.cpp \ + ../../../src/gettext.cpp \ + ../../../src/httpfetch.cpp \ + ../../../src/hud.cpp \ + ../../../src/inventory.cpp \ + ../../../src/inventorymanager.cpp \ + ../../../src/itemdef.cpp \ + ../../../src/itemstackmetadata.cpp \ + ../../../src/light.cpp \ + ../../../src/log.cpp \ + ../../../src/main.cpp \ + ../../../src/map.cpp \ + ../../../src/map_settings_manager.cpp \ + ../../../src/mapblock.cpp \ + ../../../src/mapnode.cpp \ + ../../../src/mapsector.cpp \ + ../../../src/metadata.cpp \ + ../../../src/modchannels.cpp \ + ../../../src/nameidmapping.cpp \ + ../../../src/nodedef.cpp \ + ../../../src/nodemetadata.cpp \ + ../../../src/nodetimer.cpp \ + ../../../src/noise.cpp \ + ../../../src/objdef.cpp \ + ../../../src/object_properties.cpp \ + ../../../src/pathfinder.cpp \ + ../../../src/player.cpp \ + ../../../src/porting.cpp \ + ../../../src/porting_android.cpp \ + ../../../src/profiler.cpp \ + ../../../src/raycast.cpp \ + ../../../src/reflowscan.cpp \ + ../../../src/remoteplayer.cpp \ + ../../../src/rollback.cpp \ + ../../../src/rollback_interface.cpp \ + ../../../src/serialization.cpp \ + ../../../src/server.cpp \ + ../../../src/serverenvironment.cpp \ + ../../../src/serverlist.cpp \ + ../../../src/settings.cpp \ + ../../../src/staticobject.cpp \ + ../../../src/texture_override.cpp \ + ../../../src/tileanimation.cpp \ + ../../../src/tool.cpp \ + ../../../src/translation.cpp \ + ../../../src/version.cpp \ + ../../../src/voxel.cpp \ + ../../../src/voxelalgorithms.cpp + +# LevelDB backend is disabled +# ../../../src/database/database-leveldb.cpp + +# GMP +LOCAL_SRC_FILES += ../../../lib/gmp/mini-gmp.c + +# JSONCPP +LOCAL_SRC_FILES += ../../../lib/jsoncpp/jsoncpp.cpp + +# iconv +LOCAL_SRC_FILES += \ + deps/Android/libiconv/lib/iconv.c \ + deps/Android/libiconv/libcharset/lib/localcharset.c + +# SQLite3 +LOCAL_SRC_FILES += deps/Android/sqlite/sqlite3.c + +LOCAL_STATIC_LIBRARIES += Curl Freetype Irrlicht OpenAL mbedTLS mbedx509 mbedcrypto Vorbis LuaJIT android_native_app_glue $(PROFILER_LIBS) #LevelDB +#OpenSSL Crypto + +LOCAL_LDLIBS := -lEGL -lGLESv1_CM -lGLESv2 -landroid -lOpenSLES + +include $(BUILD_SHARED_LIBRARY) + +ifdef GPROF +$(call import-module,android-ndk-profiler) +endif +$(call import-module,android/native_app_glue) diff --git a/build/android/native/jni/Application.mk b/build/android/native/jni/Application.mk new file mode 100644 index 000000000..82f0148f0 --- /dev/null +++ b/build/android/native/jni/Application.mk @@ -0,0 +1,32 @@ +APP_PLATFORM := ${APP_PLATFORM} +APP_ABI := ${TARGET_ABI} +APP_STL := c++_shared +NDK_TOOLCHAIN_VERSION := clang +APP_SHORT_COMMANDS := true +APP_MODULES := Minetest + +APP_CPPFLAGS := -Ofast -fvisibility=hidden -fexceptions -Wno-deprecated-declarations -Wno-extra-tokens + +ifeq ($(APP_ABI),armeabi-v7a) +APP_CPPFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb +endif + +#ifeq ($(APP_ABI),x86) +#APP_CPPFLAGS += -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 -funroll-loops +#endif + +ifndef NDEBUG +APP_CPPFLAGS := -g -D_DEBUG -O0 -fno-omit-frame-pointer -fexceptions +endif + +APP_CFLAGS := $(APP_CPPFLAGS) -Wno-parentheses-equality #-Werror=shorten-64-to-32 +APP_CXXFLAGS := $(APP_CPPFLAGS) -frtti -std=gnu++17 +APP_LDFLAGS := -Wl,--no-warn-mismatch,--gc-sections,--icf=safe + +ifeq ($(APP_ABI),arm64-v8a) +APP_LDFLAGS := -Wl,--no-warn-mismatch,--gc-sections +endif + +ifndef NDEBUG +APP_LDFLAGS := +endif diff --git a/build/android/native/src/main/AndroidManifest.xml b/build/android/native/src/main/AndroidManifest.xml new file mode 100644 index 000000000..19451c7fd --- /dev/null +++ b/build/android/native/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/build/android/patches/irrlicht-back_button.patch b/build/android/patches/irrlicht-back_button.patch deleted file mode 100644 index e17b81347..000000000 --- a/build/android/patches/irrlicht-back_button.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- irrlicht/source/Irrlicht/Android/CIrrDeviceAndroid.cpp.orig 2015-08-29 15:43:09.000000000 +0300 -+++ irrlicht/source/Irrlicht/Android/CIrrDeviceAndroid.cpp 2016-05-13 21:36:22.880388505 +0300 -@@ -486,7 +486,7 @@ - event.KeyInput.Char = 0; - } - -- device->postEventFromUser(event); -+ status = device->postEventFromUser(event); - } - break; - default: -@@ -543,7 +543,7 @@ - KeyMap[1] = KEY_LBUTTON; // AKEYCODE_SOFT_LEFT - KeyMap[2] = KEY_RBUTTON; // AKEYCODE_SOFT_RIGHT - KeyMap[3] = KEY_HOME; // AKEYCODE_HOME -- KeyMap[4] = KEY_BACK; // AKEYCODE_BACK -+ KeyMap[4] = KEY_CANCEL; // AKEYCODE_BACK - KeyMap[5] = KEY_UNKNOWN; // AKEYCODE_CALL - KeyMap[6] = KEY_UNKNOWN; // AKEYCODE_ENDCALL - KeyMap[7] = KEY_KEY_0; // AKEYCODE_0 diff --git a/build/android/patches/irrlicht-native_activity.patch b/build/android/patches/irrlicht-native_activity.patch deleted file mode 100644 index a9d2610c3..000000000 --- a/build/android/patches/irrlicht-native_activity.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- irrlicht/source/Irrlicht/CEGLManager.cpp.orig 2018-09-11 18:19:51.453403631 +0300 -+++ irrlicht/source/Irrlicht/CEGLManager.cpp 2018-09-11 18:36:24.603471869 +0300 -@@ -9,6 +9,10 @@ - #include "irrString.h" - #include "os.h" - -+#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) -+#include -+#endif -+ - namespace irr - { - namespace video diff --git a/build/android/patches/irrlicht-texturehack.patch b/build/android/patches/irrlicht-texturehack.patch deleted file mode 100644 index a458ede72..000000000 --- a/build/android/patches/irrlicht-texturehack.patch +++ /dev/null @@ -1,240 +0,0 @@ ---- irrlicht/source/Irrlicht/COGLESTexture.cpp.orig 2014-06-22 17:01:13.266568869 +0200 -+++ irrlicht/source/Irrlicht/COGLESTexture.cpp 2014-06-22 17:03:59.298572810 +0200 -@@ -366,112 +366,140 @@ - void(*convert)(const void*, s32, void*) = 0; - getFormatParameters(ColorFormat, InternalFormat, filtering, PixelFormat, PixelType, convert); - -- // make sure we don't change the internal format of existing images -- if (!newTexture) -- InternalFormat = oldInternalFormat; -- -- Driver->setActiveTexture(0, this); -- -- if (Driver->testGLError()) -- os::Printer::log("Could not bind Texture", ELL_ERROR); -- -- // mipmap handling for main texture -- if (!level && newTexture) -- { -- // auto generate if possible and no mipmap data is given -- if (!IsCompressed && HasMipMaps && !mipmapData && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE)) -- { -- if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) -- glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); -- else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY)) -- glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); -- else -- glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); -+ bool retry = false; -+ -+ do { -+ if (retry) { -+ InternalFormat = GL_RGBA; -+ PixelFormat = GL_RGBA; -+ convert = CColorConverter::convert_A8R8G8B8toA8B8G8R8; -+ } -+ // make sure we don't change the internal format of existing images -+ if (!newTexture) -+ InternalFormat = oldInternalFormat; - -- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); -- AutomaticMipmapUpdate=true; -- } -+ Driver->setActiveTexture(0, this); - -- // enable bilinear filter without mipmaps -- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); -- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); -- } -+ if (Driver->testGLError()) -+ os::Printer::log("Could not bind Texture", ELL_ERROR); - -- // now get image data and upload to GPU -+ // mipmap handling for main texture -+ if (!level && newTexture) -+ { -+ // auto generate if possible and no mipmap data is given -+ if (!IsCompressed && HasMipMaps && !mipmapData && Driver->queryFeature(EVDF_MIP_MAP_AUTO_UPDATE)) -+ { -+ if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED)) -+ glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); -+ else if (Driver->getTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY)) -+ glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); -+ else -+ glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); -+ -+ glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); -+ AutomaticMipmapUpdate=true; -+ } -+ -+ // enable bilinear filter without mipmaps -+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); -+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); -+ } - -- u32 compressedImageSize = IImage::getCompressedImageSize(ColorFormat, image->getDimension().Width, image->getDimension().Height); -+ // now get image data and upload to GPU - -- void* source = image->lock(); -+ u32 compressedImageSize = IImage::getCompressedImageSize(ColorFormat, image->getDimension().Width, image->getDimension().Height); - -- IImage* tmpImage = 0; -+ void* source = image->lock(); - -- if (convert) -- { -- tmpImage = new CImage(image->getColorFormat(), image->getDimension()); -- void* dest = tmpImage->lock(); -- convert(source, image->getDimension().getArea(), dest); -- image->unlock(); -- source = dest; -- } -+ IImage* tmpImage = 0; - -- if (newTexture) -- { -- if (IsCompressed) -+ if (convert) - { -- glCompressedTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, image->getDimension().Width, -- image->getDimension().Height, 0, compressedImageSize, source); -+ tmpImage = new CImage(image->getColorFormat(), image->getDimension()); -+ void* dest = tmpImage->lock(); -+ convert(source, image->getDimension().getArea(), dest); -+ image->unlock(); -+ source = dest; - } -- else -- glTexImage2D(GL_TEXTURE_2D, level, InternalFormat, image->getDimension().Width, -- image->getDimension().Height, 0, PixelFormat, PixelType, source); -- } -- else -- { -- if (IsCompressed) -+ -+ if (newTexture) - { -- glCompressedTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width, -- image->getDimension().Height, PixelFormat, compressedImageSize, source); -+ if (IsCompressed) -+ { -+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, InternalFormat, image->getDimension().Width, -+ image->getDimension().Height, 0, compressedImageSize, source); -+ } -+ else -+ glTexImage2D(GL_TEXTURE_2D, level, InternalFormat, image->getDimension().Width, -+ image->getDimension().Height, 0, PixelFormat, PixelType, source); - } - else -- glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width, -- image->getDimension().Height, PixelFormat, PixelType, source); -- } -- -- if (convert) -- { -- tmpImage->unlock(); -- tmpImage->drop(); -- } -- else -- image->unlock(); -- -- if (!level && newTexture) -- { -- if (IsCompressed && !mipmapData) - { -- if (image->hasMipMaps()) -- mipmapData = static_cast(image->lock())+compressedImageSize; -+ if (IsCompressed) -+ { -+ glCompressedTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width, -+ image->getDimension().Height, PixelFormat, compressedImageSize, source); -+ } - else -- HasMipMaps = false; -+ glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, image->getDimension().Width, -+ image->getDimension().Height, PixelFormat, PixelType, source); - } - -- regenerateMipMapLevels(mipmapData); -- -- if (HasMipMaps) // might have changed in regenerateMipMapLevels -+ if (convert) - { -- // enable bilinear mipmap filter -- GLint filteringMipMaps = GL_LINEAR_MIPMAP_NEAREST; -- -- if (filtering != GL_LINEAR) -- filteringMipMaps = GL_NEAREST_MIPMAP_NEAREST; -+ tmpImage->unlock(); -+ tmpImage->drop(); -+ } -+ else -+ image->unlock(); -+ -+ if (glGetError() != GL_NO_ERROR) { -+ static bool warned = false; -+ if ((!retry) && (ColorFormat == ECF_A8R8G8B8)) { -+ -+ if (!warned) { -+ os::Printer::log("Your driver claims to support GL_BGRA but fails on trying to upload a texture, converting to GL_RGBA and trying again", ELL_ERROR); -+ warned = true; -+ } -+ } -+ else if (retry) { -+ os::Printer::log("Neither uploading texture as GL_BGRA nor, converted one using GL_RGBA succeeded", ELL_ERROR); -+ } -+ retry = !retry; -+ continue; -+ } else { -+ retry = false; -+ } - -- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filteringMipMaps); -- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); -+ if (!level && newTexture) -+ { -+ if (IsCompressed && !mipmapData) -+ { -+ if (image->hasMipMaps()) -+ mipmapData = static_cast(image->lock())+compressedImageSize; -+ else -+ HasMipMaps = false; -+ } -+ -+ regenerateMipMapLevels(mipmapData); -+ -+ if (HasMipMaps) // might have changed in regenerateMipMapLevels -+ { -+ // enable bilinear mipmap filter -+ GLint filteringMipMaps = GL_LINEAR_MIPMAP_NEAREST; -+ -+ if (filtering != GL_LINEAR) -+ filteringMipMaps = GL_NEAREST_MIPMAP_NEAREST; -+ -+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filteringMipMaps); -+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering); -+ } - } -- } - -- if (Driver->testGLError()) -- os::Printer::log("Could not glTexImage2D", ELL_ERROR); -+ if (Driver->testGLError()) -+ os::Printer::log("Could not glTexImage2D", ELL_ERROR); -+ } -+ while(retry); - } - - ---- irrlicht/source/Irrlicht/COGLESTexture.cpp.orig 2014-06-25 00:28:50.820501856 +0200 -+++ irrlicht/source/Irrlicht/COGLESTexture.cpp 2014-06-25 00:08:37.712544692 +0200 -@@ -422,6 +422,9 @@ - source = dest; - } - -+ //clear old error -+ glGetError(); -+ - if (newTexture) - { - if (IsCompressed) diff --git a/build/android/patches/irrlicht-touchcount.patch b/build/android/patches/irrlicht-touchcount.patch deleted file mode 100644 index d4e4b9c3e..000000000 --- a/build/android/patches/irrlicht-touchcount.patch +++ /dev/null @@ -1,30 +0,0 @@ ---- irrlicht.orig/include/IEventReceiver.h 2014-06-03 19:43:50.433713133 +0200 -+++ irrlicht/include/IEventReceiver.h 2014-06-03 19:44:36.993711489 +0200 -@@ -375,6 +375,9 @@ - // Y position of simple touch. - s32 Y; - -+ // number of current touches -+ s32 touchedCount; -+ - //! Type of touch event. - ETOUCH_INPUT_EVENT Event; - }; ---- irrlicht.orig/source/Irrlicht/Android/CIrrDeviceAndroid.cpp 2014-06-03 19:43:50.505713130 +0200 -+++ irrlicht/source/Irrlicht/Android/CIrrDeviceAndroid.cpp 2014-06-03 19:45:37.265709359 +0200 -@@ -315,6 +315,7 @@ - event.TouchInput.ID = AMotionEvent_getPointerId(androidEvent, i); - event.TouchInput.X = AMotionEvent_getX(androidEvent, i); - event.TouchInput.Y = AMotionEvent_getY(androidEvent, i); -+ event.TouchInput.touchedCount = AMotionEvent_getPointerCount(androidEvent); - - device->postEventFromUser(event); - } -@@ -326,6 +327,7 @@ - event.TouchInput.ID = AMotionEvent_getPointerId(androidEvent, pointerIndex); - event.TouchInput.X = AMotionEvent_getX(androidEvent, pointerIndex); - event.TouchInput.Y = AMotionEvent_getY(androidEvent, pointerIndex); -+ event.TouchInput.touchedCount = AMotionEvent_getPointerCount(androidEvent); - - device->postEventFromUser(event); - } diff --git a/build/android/patches/libvorbis-libogg-fpu.patch b/build/android/patches/libvorbis-libogg-fpu.patch deleted file mode 100644 index 52ab397ac..000000000 --- a/build/android/patches/libvorbis-libogg-fpu.patch +++ /dev/null @@ -1,37 +0,0 @@ ---- libvorbis-libogg-android/jni/libvorbis-jni/Android.mk.orig 2014-06-17 19:22:50.621559073 +0200 -+++ libvorbis-libogg-android/jni/libvorbis-jni/Android.mk 2014-06-17 19:38:20.641581140 +0200 -@@ -4,9 +4,6 @@ - - LOCAL_MODULE := vorbis-jni - LOCAL_CFLAGS += -I$(LOCAL_PATH)/../include -fsigned-char --ifeq ($(TARGET_ARCH),arm) -- LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp --endif - - LOCAL_SHARED_LIBRARIES := libogg libvorbis - ---- libvorbis-libogg-android/jni/libvorbis/Android.mk.orig 2014-06-17 19:22:39.077558797 +0200 -+++ libvorbis-libogg-android/jni/libvorbis/Android.mk 2014-06-17 19:38:52.121581887 +0200 -@@ -4,9 +4,6 @@ - - LOCAL_MODULE := libvorbis - LOCAL_CFLAGS += -I$(LOCAL_PATH)/../include -ffast-math -fsigned-char --ifeq ($(TARGET_ARCH),arm) -- LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp --endif - LOCAL_SHARED_LIBRARIES := libogg - - LOCAL_SRC_FILES := \ ---- libvorbis-libogg-android/jni/libogg/Android.mk.orig 2014-06-17 19:22:33.965558675 +0200 -+++ libvorbis-libogg-android/jni/libogg/Android.mk 2014-06-17 19:38:25.337581252 +0200 -@@ -4,10 +4,6 @@ - - LOCAL_MODULE := libogg - LOCAL_CFLAGS += -I$(LOCAL_PATH)/../include -ffast-math -fsigned-char --ifeq ($(TARGET_ARCH),arm) -- LOCAL_CFLAGS += -march=armv6 -marm -mfloat-abi=softfp -mfpu=vfp --endif -- - - LOCAL_SRC_FILES := \ - bitwise.c \ diff --git a/build/android/patches/openssl_arch.patch b/build/android/patches/openssl_arch.patch deleted file mode 100644 index d15e2b137..000000000 --- a/build/android/patches/openssl_arch.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- openssl-1.0.2e.orig/Configure 2015-12-03 15:04:23.000000000 +0100 -+++ openssl-1.0.2e/Configure 2015-12-14 21:01:40.351265968 +0100 -@@ -464,8 +464,10 @@ - # Android: linux-* but without pointers to headers and libs. - "android","gcc:-mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${no_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", - "android-x86","gcc:-mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG ${x86_gcc_des} ${x86_gcc_opts}:".eval{my $asm=${x86_elf_asm};$asm=~s/:elf/:android/;$asm}.":dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -+"android-arm","gcc:-march=armv4 -mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${armv4_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", - "android-armv7","gcc:-march=armv7-a -mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -fomit-frame-pointer -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${armv4_asm}:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", - "android-mips","gcc:-mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${mips32_asm}:o32:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", -+"android-mips32","gcc:-mandroid -I\$(ANDROID_DEV)/include -B\$(ANDROID_DEV)/lib -O3 -Wall::-D_REENTRANT::-ldl:BN_LLONG RC4_CHAR RC4_CHUNK DES_INT DES_UNROLL BF_PTR:${mips32_asm}:o32:dlfcn:linux-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", - - #### *BSD [do see comment about ${BSDthreads} above!] - "BSD-generic32","gcc:-O3 -fomit-frame-pointer -Wall::${BSDthreads}:::BN_LLONG RC2_CHAR RC4_INDEX DES_INT DES_UNROLL:${no_asm}:dlfcn:bsd-gcc-shared:-fPIC::.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR)", diff --git a/build/android/settings.gradle b/build/android/settings.gradle index b0cee5dad..b048fca7c 100644 --- a/build/android/settings.gradle +++ b/build/android/settings.gradle @@ -1 +1,2 @@ rootProject.name = "Minetest" +include ':app', ':native' diff --git a/build/android/src/main/AndroidManifest.xml b/build/android/src/main/AndroidManifest.xml deleted file mode 100644 index fb1de9cf0..000000000 --- a/build/android/src/main/AndroidManifest.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/build/android/src/main/java/net.minetest.minetest/MainActivity.java b/build/android/src/main/java/net.minetest.minetest/MainActivity.java deleted file mode 100644 index 71b0ce144..000000000 --- a/build/android/src/main/java/net.minetest.minetest/MainActivity.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.minetest.minetest; - -import android.Manifest; -import android.app.Activity; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class MainActivity extends Activity { - private final static int PERMISSIONS = 1; - private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - checkPermission(); - } else { - next(); - } - } - - private void checkPermission() { - final List missingPermissions = new ArrayList<>(); - // check required permission - for (final String permission : REQUIRED_SDK_PERMISSIONS) { - final int result = ContextCompat.checkSelfPermission(this, permission); - if (result != PackageManager.PERMISSION_GRANTED) { - missingPermissions.add(permission); - } - } - if (!missingPermissions.isEmpty()) { - // request permission - final String[] permissions = missingPermissions - .toArray(new String[0]); - ActivityCompat.requestPermissions(this, permissions, PERMISSIONS); - } else { - final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length]; - Arrays.fill(grantResults, PackageManager.PERMISSION_GRANTED); - onRequestPermissionsResult(PERMISSIONS, REQUIRED_SDK_PERMISSIONS, - grantResults); - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, - @NonNull int[] grantResults) { - if (requestCode == PERMISSIONS) { - for (int index = 0; index < permissions.length; index++) { - if (grantResults[index] != PackageManager.PERMISSION_GRANTED) { - // permission not granted - toast and exit - Toast.makeText(this, R.string.not_granted, Toast.LENGTH_LONG).show(); - finish(); - return; - } - } - // permission were granted - run - next(); - } - } - - private void next() { - Intent intent = new Intent(this, MtNativeActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); - startActivity(intent); - } -} diff --git a/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java b/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java deleted file mode 100644 index 84cfca796..000000000 --- a/build/android/src/main/java/net.minetest.minetest/MinetestAssetCopy.java +++ /dev/null @@ -1,371 +0,0 @@ -package net.minetest.minetest; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.res.AssetFileDescriptor; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.util.Log; -import android.view.Display; -import android.view.View; -import android.widget.ProgressBar; -import android.widget.TextView; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.util.Vector; - -public class MinetestAssetCopy extends Activity { - private ProgressBar m_ProgressBar; - private TextView m_Filename; - private copyAssetTask m_AssetCopy; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.assetcopy); - m_ProgressBar = findViewById(R.id.progressBar1); - m_Filename = findViewById(R.id.textView1); - Display display = getWindowManager().getDefaultDisplay(); - m_ProgressBar.getLayoutParams().width = (int) (display.getWidth() * 0.8); - m_ProgressBar.invalidate(); - - /* check if there's already a copy in progress and reuse in case it is*/ - MinetestAssetCopy prevActivity = - (MinetestAssetCopy) getLastNonConfigurationInstance(); - if (prevActivity != null) { - m_AssetCopy = prevActivity.m_AssetCopy; - } else { - m_AssetCopy = new copyAssetTask(); - m_AssetCopy.execute(); - } - } - - @Override - protected void onResume() { - super.onResume(); - makeFullScreen(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (m_AssetCopy != null) { - m_AssetCopy.cancel(true); - } - } - - private void makeFullScreen() { - if (Build.VERSION.SDK_INT >= 19) - this.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); - } - - @Override - public void onWindowFocusChanged(boolean hasFocus) { - super.onWindowFocusChanged(hasFocus); - if (hasFocus) - makeFullScreen(); - } - - /* preserve asset copy background task to prevent restart of copying */ - /* this way of doing it is not recommended for latest android version */ - /* but the recommended way isn't available on android 2.x */ - public Object onRetainNonConfigurationInstance() { - return this; - } - - @SuppressLint("StaticFieldLeak") - private class copyAssetTask extends AsyncTask { - boolean m_copy_started = false; - String m_Foldername = "media"; - Vector m_foldernames; - Vector m_filenames; - Vector m_tocopy; - Vector m_asset_size_unknown; - - private long getFullSize(String filename) { - long size = 0; - try { - InputStream src = getAssets().open(filename); - byte[] buf = new byte[4096]; - - int len; - while ((len = src.read(buf)) > 0) { - size += len; - } - } catch (IOException e) { - e.printStackTrace(); - } - return size; - } - - @Override - protected String doInBackground(String... files) { - m_foldernames = new Vector<>(); - m_filenames = new Vector<>(); - m_tocopy = new Vector<>(); - m_asset_size_unknown = new Vector<>(); - String baseDir = - Environment.getExternalStorageDirectory().getAbsolutePath() - + "/"; - - - // prepare temp folder - File TempFolder = new File(baseDir + "Minetest/tmp/"); - - if (!TempFolder.exists()) { - TempFolder.mkdir(); - } else { - File[] todel = TempFolder.listFiles(); - - for (File file : todel) { - Log.v("MinetestAssetCopy", "deleting: " + file.getAbsolutePath()); - file.delete(); - } - } - - // add a .nomedia file - try { - OutputStream dst = new FileOutputStream(baseDir + "Minetest/.nomedia"); - dst.close(); - } catch (IOException e) { - Log.e("MinetestAssetCopy", "Failed to create .nomedia file"); - e.printStackTrace(); - } - - - // build lists from prepared data - BuildFolderList(); - BuildFileList(); - - // scan filelist - ProcessFileList(); - - // doing work - m_copy_started = true; - m_ProgressBar.setMax(m_tocopy.size()); - - for (int i = 0; i < m_tocopy.size(); i++) { - try { - String filename = m_tocopy.get(i); - publishProgress(i); - - boolean asset_size_unknown = false; - long filesize = -1; - - if (m_asset_size_unknown.contains(filename)) { - File testme = new File(baseDir + "/" + filename); - - if (testme.exists()) - filesize = testme.length(); - - asset_size_unknown = true; - } - - InputStream src; - try { - src = getAssets().open(filename); - } catch (IOException e) { - Log.e("MinetestAssetCopy", "Copying file: " + filename + " FAILED (not in assets)"); - e.printStackTrace(); - continue; - } - - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len = src.read(buf, 0, 1024); - - /* following handling is crazy but we need to deal with */ - /* compressed assets.Flash chips limited livetime due to */ - /* write operations, we can't allow large files to destroy */ - /* users flash. */ - if (asset_size_unknown) { - if ((len > 0) && (len < buf.length) && (len == filesize)) { - src.close(); - continue; - } - - if (len == buf.length) { - src.close(); - long size = getFullSize(filename); - if (size == filesize) { - continue; - } - src = getAssets().open(filename); - len = src.read(buf, 0, 1024); - } - } - if (len > 0) { - int total_filesize = 0; - OutputStream dst; - try { - dst = new FileOutputStream(baseDir + "/" + filename); - } catch (IOException e) { - Log.e("MinetestAssetCopy", "Copying file: " + baseDir + - "/" + filename + " FAILED (couldn't open output file)"); - e.printStackTrace(); - src.close(); - continue; - } - dst.write(buf, 0, len); - total_filesize += len; - - while ((len = src.read(buf)) > 0) { - dst.write(buf, 0, len); - total_filesize += len; - } - - dst.close(); - Log.v("MinetestAssetCopy", "Copied file: " + - m_tocopy.get(i) + " (" + total_filesize + - " bytes)"); - } else if (len < 0) { - Log.e("MinetestAssetCopy", "Copying file: " + - m_tocopy.get(i) + " failed, size < 0"); - } - src.close(); - } catch (IOException e) { - Log.e("MinetestAssetCopy", "Copying file: " + - m_tocopy.get(i) + " failed"); - e.printStackTrace(); - } - } - return ""; - } - - /** - * update progress bar - */ - protected void onProgressUpdate(Integer... progress) { - - if (m_copy_started) { - String todisplay = m_tocopy.get(progress[0]); - m_ProgressBar.setProgress(progress[0]); - m_Filename.setText(todisplay); - } else { - String todisplay = m_Foldername; - String full_text = "scanning " + todisplay + " ..."; - m_Filename.setText(full_text); - } - } - - /** - * check all files and folders in filelist - */ - void ProcessFileList() { - String FlashBaseDir = - Environment.getExternalStorageDirectory().getAbsolutePath(); - - for (String current_path : m_filenames) { - String FlashPath = FlashBaseDir + "/" + current_path; - - if (isAssetFolder(current_path)) { - /* store information and update gui */ - m_Foldername = current_path; - publishProgress(0); - - /* open file in order to check if it's a folder */ - File current_folder = new File(FlashPath); - if (!current_folder.exists()) { - if (!current_folder.mkdirs()) { - Log.e("MinetestAssetCopy", "\t failed create folder: " + - FlashPath); - } else { - Log.v("MinetestAssetCopy", "\t created folder: " + - FlashPath); - } - } - - continue; - } - - /* if it's not a folder it's most likely a file */ - boolean refresh = true; - - File testme = new File(FlashPath); - - long asset_filesize = -1; - long stored_filesize; - - if (testme.exists()) { - try { - AssetFileDescriptor fd = getAssets().openFd(current_path); - asset_filesize = fd.getLength(); - fd.close(); - } catch (IOException e) { - m_asset_size_unknown.add(current_path); - Log.e("MinetestAssetCopy", "Failed to open asset file \"" + - FlashPath + "\" for size check"); - } - - stored_filesize = testme.length(); - - if (asset_filesize == stored_filesize) - refresh = false; - - } - - if (refresh) - m_tocopy.add(current_path); - } - } - - /** - * read list of folders prepared on package build - */ - void BuildFolderList() { - try { - InputStream is = getAssets().open("index.txt"); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - String line = reader.readLine(); - while (line != null) { - m_foldernames.add(line); - line = reader.readLine(); - } - is.close(); - } catch (IOException e1) { - Log.e("MinetestAssetCopy", "Error on processing index.txt"); - e1.printStackTrace(); - } - } - - /** - * read list of asset files prepared on package build - */ - void BuildFileList() { - long entrycount = 0; - try { - InputStream is = getAssets().open("filelist.txt"); - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - - String line = reader.readLine(); - while (line != null) { - m_filenames.add(line); - line = reader.readLine(); - entrycount++; - } - is.close(); - } catch (IOException e1) { - Log.e("MinetestAssetCopy", "Error on processing filelist.txt"); - e1.printStackTrace(); - } - } - - protected void onPostExecute(String result) { - finish(); - } - - boolean isAssetFolder(String path) { - return m_foldernames.contains(path); - } - } -} diff --git a/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java b/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java deleted file mode 100644 index cb7ba8d3b..000000000 --- a/build/android/src/main/java/net.minetest.minetest/MinetestTextEntry.java +++ /dev/null @@ -1,87 +0,0 @@ -package net.minetest.minetest; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.text.InputType; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnKeyListener; -import android.widget.EditText; - -public class MinetestTextEntry extends Activity { - private final int MultiLineTextInput = 1; - private final int SingleLineTextInput = 2; - private final int SingleLinePasswordInput = 3; - private AlertDialog mTextInputDialog; - private EditText mTextInputWidget; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Bundle b = getIntent().getExtras(); - String acceptButton = b.getString("EnterButton"); - String hint = b.getString("hint"); - String current = b.getString("current"); - int editType = b.getInt("editType"); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - mTextInputWidget = new EditText(this); - mTextInputWidget.setHint(hint); - mTextInputWidget.setText(current); - mTextInputWidget.setMinWidth(300); - if (editType == SingleLinePasswordInput) { - mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT | - InputType.TYPE_TEXT_VARIATION_PASSWORD); - } else { - mTextInputWidget.setInputType(InputType.TYPE_CLASS_TEXT); - } - - builder.setView(mTextInputWidget); - - if (editType == MultiLineTextInput) { - builder.setPositiveButton(acceptButton, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - pushResult(mTextInputWidget.getText().toString()); - } - }); - } - - builder.setOnCancelListener(new DialogInterface.OnCancelListener() { - public void onCancel(DialogInterface dialog) { - cancelDialog(); - } - }); - - mTextInputWidget.setOnKeyListener(new OnKeyListener() { - @Override - public boolean onKey(View view, int KeyCode, KeyEvent event) { - if (KeyCode == KeyEvent.KEYCODE_ENTER) { - - pushResult(mTextInputWidget.getText().toString()); - return true; - } - return false; - } - }); - - mTextInputDialog = builder.create(); - mTextInputDialog.show(); - } - - private void pushResult(String text) { - Intent resultData = new Intent(); - resultData.putExtra("text", text); - setResult(Activity.RESULT_OK, resultData); - mTextInputDialog.dismiss(); - finish(); - } - - private void cancelDialog() { - setResult(Activity.RESULT_CANCELED); - mTextInputDialog.dismiss(); - finish(); - } -} diff --git a/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java b/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java deleted file mode 100644 index f49d078fe..000000000 --- a/build/android/src/main/java/net.minetest.minetest/MtNativeActivity.java +++ /dev/null @@ -1,108 +0,0 @@ -package net.minetest.minetest; - -import android.app.NativeActivity; -import android.content.Intent; -import android.os.Build; -import android.os.Bundle; -import android.view.View; -import android.view.WindowManager; - -public class MtNativeActivity extends NativeActivity { - - static { - System.loadLibrary("c++_shared"); - System.loadLibrary("openal"); - System.loadLibrary("ogg"); - System.loadLibrary("vorbis"); - System.loadLibrary("iconv"); - System.loadLibrary("minetest"); - } - - private int m_MessagReturnCode; - private String m_MessageReturnValue; - - public static native void putMessageBoxResult(String text); - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - m_MessagReturnCode = -1; - m_MessageReturnValue = ""; - } - - @Override - protected void onResume() { - super.onResume(); - makeFullScreen(); - } - - private void makeFullScreen() { - if (Build.VERSION.SDK_INT >= 19) - this.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); - } - - @Override - public void onWindowFocusChanged(boolean hasFocus) { - super.onWindowFocusChanged(hasFocus); - if (hasFocus) - makeFullScreen(); - } - - public void copyAssets() { - Intent intent = new Intent(this, MinetestAssetCopy.class); - startActivity(intent); - } - - public void showDialog(String acceptButton, String hint, String current, - int editType) { - - Intent intent = new Intent(this, MinetestTextEntry.class); - Bundle params = new Bundle(); - params.putString("acceptButton", acceptButton); - params.putString("hint", hint); - params.putString("current", current); - params.putInt("editType", editType); - intent.putExtras(params); - startActivityForResult(intent, 101); - m_MessageReturnValue = ""; - m_MessagReturnCode = -1; - } - - /* ugly code to workaround putMessageBoxResult not beeing found */ - public int getDialogState() { - return m_MessagReturnCode; - } - - public String getDialogValue() { - m_MessagReturnCode = -1; - return m_MessageReturnValue; - } - - public float getDensity() { - return getResources().getDisplayMetrics().density; - } - - public int getDisplayWidth() { - return getResources().getDisplayMetrics().widthPixels; - } - - public int getDisplayHeight() { - return getResources().getDisplayMetrics().heightPixels; - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, - Intent data) { - if (requestCode == 101) { - if (resultCode == RESULT_OK) { - String text = data.getStringExtra("text"); - m_MessagReturnCode = 0; - m_MessageReturnValue = text; - } else { - m_MessagReturnCode = 1; - } - } - } -} diff --git a/build/android/src/main/res/drawable/background.png b/build/android/src/main/res/drawable/background.png deleted file mode 100644 index 43bd6089e..000000000 Binary files a/build/android/src/main/res/drawable/background.png and /dev/null differ diff --git a/build/android/src/main/res/drawable/bg.xml b/build/android/src/main/res/drawable/bg.xml deleted file mode 100644 index c76ec372d..000000000 --- a/build/android/src/main/res/drawable/bg.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/build/android/src/main/res/layout/assetcopy.xml b/build/android/src/main/res/layout/assetcopy.xml deleted file mode 100644 index b3da2f027..000000000 --- a/build/android/src/main/res/layout/assetcopy.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - diff --git a/build/android/src/main/res/mipmap/ic_launcher.png b/build/android/src/main/res/mipmap/ic_launcher.png deleted file mode 100644 index 88a83782c..000000000 Binary files a/build/android/src/main/res/mipmap/ic_launcher.png and /dev/null differ diff --git a/build/android/src/main/res/values-v21/styles.xml b/build/android/src/main/res/values-v21/styles.xml deleted file mode 100644 index 8b0777467..000000000 --- a/build/android/src/main/res/values-v21/styles.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - diff --git a/build/android/src/main/res/values/strings.xml b/build/android/src/main/res/values/strings.xml deleted file mode 100644 index a5eaef5d1..000000000 --- a/build/android/src/main/res/values/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - Preparing media… - Required permission wasn\'t granted, Minetest can\'t run without it - \ No newline at end of file diff --git a/build/android/src/main/res/values/styles.xml b/build/android/src/main/res/values/styles.xml deleted file mode 100644 index 1bd41ae76..000000000 --- a/build/android/src/main/res/values/styles.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - diff --git a/doc/README.android b/doc/README.android index c21279583..f6b67978f 100644 --- a/doc/README.android +++ b/doc/README.android @@ -1,6 +1,5 @@ -Minetest Android port -===================== -Date: 2014 06 28 +Minetest: Android version +========================= Controls -------- @@ -40,25 +39,6 @@ file can usually be found at /mnt/sdcard/Minetest. main menu is too big or small on your device, try changing this value. -Known issues ------------- -Not all issues are fixed by now: - -* Unable to exit from volume menu -- don't use the volume menu, use Android's - volume controls instead. -* 512 MB RAM seems to be inadequate -- this depends on the server you join. - Try to play on more lightweight servers. - -Versioning ----------- -Android version numbers are 4 digits instead of Minetest's 3 digits. The last -number of Android's version represents the Android internal version code. This -version code is strictly incremental. It's incremented for each official -Minetest Android build. - -E.g. prerelease Minetest Android builds have been 0.4.9.3, while the first -official version most likely will be 0.4.10.4 - Requirements ------------ @@ -69,9 +49,9 @@ following software packages. The version number in parenthesis denotes the version that was tested at the time this README was drafted; newer/older versions may or may not work. -* android SDK (api-26) -* android NDK (r17c) -* wget (1.13.4) +* Android SDK 29 +* Android NDK r21 +* Android Studio 3 [optional] Additionally, you'll need to have an Internet connection available on the build system, as the Android build will download some source packages. @@ -79,16 +59,15 @@ build system, as the Android build will download some source packages. Build ----- -Debug build: -* Enter "build/android" subdirectory -* Execute "make" -* Answer the questions about where SDK and NDK are located on your filesystem -* Wait for build to finish - -After the build is finished, the resulting apk can be fond in -build/android/bin/. It will be called Minetest-debug.apk +The new build system Minetest Android is fully functional and is designed to +speed up and simplify the work, as well as adding the possibility of +cross-platform build. +You can use `./gradlew assemblerelease` or `./gradlew assembledebug` from the +command line or use Android Studio and click the build button. -Release build: +When using gradlew, the newest NDK will be downloaded and installed +automatically. Or you can create a `local.properties` file and specify +`sdk.dir` and `ndk.dir` yourself. * In order to make a release build you'll have to have a keystore setup to sign the resulting apk package. How this is done is not part of this README. There @@ -97,32 +76,6 @@ Release build: * Once your keystore is setup, enter build/android subdirectory and create a new file "ant.properties" there. Add following lines to that file: - + > key.store= > key.alias=Minetest - -* Execute "make release" -* Enter your keystore as well as your Mintest key password once asked. Be - careful it's shown on console in clear text! -* The result can be found at "bin/Minetest-release.apk" - -Other things that may be nice to know ------------- -* The environment for Android development tools is saved within Android build - build folder. If you want direct access to it do: - - > make envpaths - > . and_env - - After you've done this you'll have your path and path variables set correct - to use adb and all other Android development tools - -* You can build a single dependency by calling make and the dependency's name, - e.g.: - - > make irrlicht - -* You can completely cleanup a dependency by calling make and the "clean" target, - e.g.: - - > make clean_irrlicht diff --git a/src/config.h b/src/config.h index 039100914..9d58a8cc1 100644 --- a/src/config.h +++ b/src/config.h @@ -11,12 +11,12 @@ #if defined USE_CMAKE_CONFIG_H #include "cmake_config.h" -#elif defined (__ANDROID__) || defined (ANDROID) +#elif defined (__ANDROID__) #define PROJECT_NAME "minetest" #define PROJECT_NAME_C "Minetest" #define STATIC_SHAREDIR "" - #include "android_version.h" - #ifdef NDEBUG + #define VERSION_STRING STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_PATCH) STR(VERSION_EXTRA) +#ifdef NDEBUG #define BUILD_TYPE "Release" #else #define BUILD_TYPE "Debug" diff --git a/src/main.cpp b/src/main.cpp index 8df2fe7d3..db020661a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -457,7 +457,6 @@ static bool create_userdata_path() } else { success = true; } - porting::copyAssets(); #else // Create user data directory success = fs::CreateDir(porting::path_user); diff --git a/src/porting_android.cpp b/src/porting_android.cpp index 7c74f7b5b..4130bdb6d 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -69,10 +69,10 @@ void android_main(android_app *app) /* TODO this doesn't work as expected, no idea why but there's a workaround */ /* for it right now */ extern "C" { - JNIEXPORT void JNICALL Java_net_minetest_MtNativeActivity_putMessageBoxResult( + JNIEXPORT void JNICALL Java_net_minetest_minetest_GameActivity_putMessageBoxResult( JNIEnv * env, jclass thiz, jstring text) { - errorstream << "Java_net_minetest_MtNativeActivity_putMessageBoxResult got: " + errorstream << "Java_net_minetest_minetest_GameActivity_putMessageBoxResult got: " << std::string((const char*)env->GetStringChars(text,0)) << std::endl; } @@ -107,17 +107,6 @@ jclass findClass(std::string classname) return (jclass) jnienv->CallObjectMethod(cls, findClass, strClassName); } -void copyAssets() -{ - jmethodID assetcopy = jnienv->GetMethodID(nativeActivity,"copyAssets","()V"); - - if (assetcopy == 0) { - assert("porting::copyAssets unable to find copy assets method" == 0); - } - - jnienv->CallVoidMethod(app_global->activity->clazz, assetcopy); -} - void initAndroid() { porting::jnienv = NULL; @@ -136,7 +125,7 @@ void initAndroid() exit(-1); } - nativeActivity = findClass("net/minetest/minetest/MtNativeActivity"); + nativeActivity = findClass("net/minetest/minetest/GameActivity"); if (nativeActivity == 0) { errorstream << "porting::initAndroid unable to find java native activity class" << diff --git a/src/porting_android.h b/src/porting_android.h index 0b3f2575e..60eb2a9c0 100644 --- a/src/porting_android.h +++ b/src/porting_android.h @@ -48,11 +48,6 @@ void cleanupAndroid(); */ void initializePathsAndroid(); -/** - * use java function to copy media from assets to external storage - */ -void copyAssets(); - /** * show text input dialog in java * @param acceptButton text to display on accept button diff --git a/src/version.cpp b/src/version.cpp index c0c59ee99..ae5ca3412 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -20,10 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "version.h" #include "config.h" -#if defined(__ANDROID__) - #include "android_version.h" - #include "android_version_githash.h" -#elif defined(USE_CMAKE_CONFIG_H) +#if USE_CMAKE_CONFIG_H #include "cmake_config_githash.h" #endif -- cgit v1.2.3 From e8ac5a31cf12afcfddf8e3ed31e8038930edb06f Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 16 Apr 2020 08:25:48 +0200 Subject: Optimize get_objects_inside_radius calls (#9671) * Optimize getObjectsInsideRadius calls our previous implementation calls the ActiveObjectMgr to return ids and then lookup those ids in the same map and test each object Instead now we call the global map to return the pointers directly and we ask filtering when building the list using lamba. This drop double looping over ranges of active objects (and then filtered one) and drop x lookups on the map regarding the first call results --- src/collision.cpp | 20 +++++++++++--------- src/script/lua_api/l_env.cpp | 24 ++++++++++++------------ src/server/activeobjectmgr.cpp | 10 ++++++---- src/server/activeobjectmgr.h | 5 +++-- src/serverenvironment.cpp | 12 +++++------- src/serverenvironment.h | 5 +++-- src/unittest/test_serveractiveobjectmgr.cpp | 18 +++++++++++++++--- 7 files changed, 55 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/collision.cpp b/src/collision.cpp index d9fbd3202..6d24bc699 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -360,17 +360,19 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, // Calculate distance by speed, add own extent and 1.5m of tolerance f32 distance = speed_f->getLength() * dtime + box_0.getExtent().getLength() + 1.5f * BS; - std::vector s_objects; - s_env->getObjectsInsideRadius(s_objects, *pos_f, distance); - for (u16 obj_id : s_objects) { - ServerActiveObject *current = s_env->getActiveObject(obj_id); - - if (!self || (self != current && - self != current->getParent())) { - objects.push_back((ActiveObject*)current); + // search for objects which are not us, or we are not its parent + // we directly use the callback to populate the result to prevent + // a useless result loop here + auto include_obj_cb = [self, &objects] (ServerActiveObject *obj) { + if (!self || (self != obj && self != obj->getParent())) { + objects.push_back((ActiveObject *)obj); } - } + return false; + }; + + std::vector s_objects; + s_env->getObjectsInsideRadius(s_objects, *pos_f, distance, include_obj_cb); } } diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 8c45a1510..831464d3b 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -681,22 +681,22 @@ int ModApiEnvMod::l_get_player_by_name(lua_State *L) int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L) { GET_ENV_PTR; + ScriptApiBase *script = getScriptApiBase(L); // Do it v3f pos = checkFloatPos(L, 1); float radius = readParam(L, 2) * BS; - std::vector ids; - env->getObjectsInsideRadius(ids, pos, radius); - ScriptApiBase *script = getScriptApiBase(L); - lua_createtable(L, ids.size(), 0); - std::vector::const_iterator iter = ids.begin(); - for(u32 i = 0; iter != ids.end(); ++iter) { - ServerActiveObject *obj = env->getActiveObject(*iter); - if (!obj->isGone()) { - // Insert object reference into table - script->objectrefGetOrCreate(L, obj); - lua_rawseti(L, -2, ++i); - } + std::vector objs; + + auto include_obj_cb = [](ServerActiveObject *obj){ return !obj->isGone(); }; + env->getObjectsInsideRadius(objs, pos, radius, include_obj_cb); + + int i = 0; + lua_createtable(L, objs.size(), 0); + for (const auto obj : objs) { + // Insert object reference into table + script->objectrefGetOrCreate(L, obj); + lua_rawseti(L, -2, ++i); } return 1; } diff --git a/src/server/activeobjectmgr.cpp b/src/server/activeobjectmgr.cpp index 984ae7794..1b8e31409 100644 --- a/src/server/activeobjectmgr.cpp +++ b/src/server/activeobjectmgr.cpp @@ -111,17 +111,19 @@ void ActiveObjectMgr::removeObject(u16 id) } // clang-format on -void ActiveObjectMgr::getObjectsInsideRadius( - const v3f &pos, float radius, std::vector &result) +void ActiveObjectMgr::getObjectsInsideRadius(const v3f &pos, float radius, + std::vector &result, + std::function include_obj_cb) { float r2 = radius * radius; for (auto &activeObject : m_active_objects) { ServerActiveObject *obj = activeObject.second; - u16 id = activeObject.first; const v3f &objectpos = obj->getBasePosition(); if (objectpos.getDistanceFromSQ(pos) > r2) continue; - result.push_back(id); + + if (!include_obj_cb || include_obj_cb(obj)) + result.push_back(obj); } } diff --git a/src/server/activeobjectmgr.h b/src/server/activeobjectmgr.h index 5fea1bea6..bc2085499 100644 --- a/src/server/activeobjectmgr.h +++ b/src/server/activeobjectmgr.h @@ -35,8 +35,9 @@ public: bool registerObject(ServerActiveObject *obj) override; void removeObject(u16 id) override; - void getObjectsInsideRadius( - const v3f &pos, float radius, std::vector &result); + void getObjectsInsideRadius(const v3f &pos, float radius, + std::vector &result, + std::function include_obj_cb); void getAddedActiveObjectsAroundPos(const v3f &player_pos, f32 radius, f32 player_radius, std::set ¤t_objects, diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 739384673..27f0c1e3d 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1608,14 +1608,12 @@ void ServerEnvironment::getSelectedActiveObjects( const core::line3d &shootline_on_map, std::vector &objects) { - std::vector objectIds; - getObjectsInsideRadius(objectIds, shootline_on_map.start, - shootline_on_map.getLength() + 10.0f); + std::vector objs; + getObjectsInsideRadius(objs, shootline_on_map.start, + shootline_on_map.getLength() + 10.0f, nullptr); const v3f line_vector = shootline_on_map.getVector(); - for (u16 objectId : objectIds) { - ServerActiveObject* obj = getActiveObject(objectId); - + for (auto obj : objs) { aabb3f selection_box; if (!obj->getSelectionBox(&selection_box)) continue; @@ -1630,7 +1628,7 @@ void ServerEnvironment::getSelectedActiveObjects( if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector, ¤t_intersection, ¤t_normal)) { objects.emplace_back( - (s16) objectId, current_intersection, current_normal, + (s16) obj->getId(), current_intersection, current_normal, (current_intersection - shootline_on_map.start).getLengthSQ()); } } diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 55ecbd05f..f814b95c0 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -323,9 +323,10 @@ public: bool swapNode(v3s16 p, const MapNode &n); // Find all active objects inside a radius around a point - void getObjectsInsideRadius(std::vector &objects, const v3f &pos, float radius) + void getObjectsInsideRadius(std::vector &objects, const v3f &pos, float radius, + std::function include_obj_cb) { - return m_ao_manager.getObjectsInsideRadius(pos, radius, objects); + return m_ao_manager.getObjectsInsideRadius(pos, radius, objects, include_obj_cb); } // Clear objects, loading and going through every MapBlock diff --git a/src/unittest/test_serveractiveobjectmgr.cpp b/src/unittest/test_serveractiveobjectmgr.cpp index 0806972ab..aa0047400 100644 --- a/src/unittest/test_serveractiveobjectmgr.cpp +++ b/src/unittest/test_serveractiveobjectmgr.cpp @@ -148,14 +148,26 @@ void TestServerActiveObjectMgr::testGetObjectsInsideRadius() saomgr.registerObject(new TestServerActiveObject(p)); } - std::vector result; - saomgr.getObjectsInsideRadius(v3f(), 50, result); + std::vector result; + saomgr.getObjectsInsideRadius(v3f(), 50, result, nullptr); UASSERTCMP(int, ==, result.size(), 1); result.clear(); - saomgr.getObjectsInsideRadius(v3f(), 750, result); + saomgr.getObjectsInsideRadius(v3f(), 750, result, nullptr); UASSERTCMP(int, ==, result.size(), 2); + result.clear(); + saomgr.getObjectsInsideRadius(v3f(), 750000, result, nullptr); + UASSERTCMP(int, ==, result.size(), 5); + + result.clear(); + auto include_obj_cb = [](ServerActiveObject *obj) { + return (obj->getBasePosition().X != 10); + }; + + saomgr.getObjectsInsideRadius(v3f(), 750000, result, include_obj_cb); + UASSERTCMP(int, ==, result.size(), 4); + clearSAOMgr(&saomgr); } -- cgit v1.2.3 From 5cbe8437a8f7efc9c76baf23de700e96ad96b385 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 16 Apr 2020 10:23:48 +0200 Subject: Swap out -ffast-math for a safe subset of optimization flags (#9682) It caused more trouble than its worth. fixes #3943, fixes #5330 --- src/CMakeLists.txt | 7 ++++++- src/collision.cpp | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa261547b..d5f774d77 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -713,6 +713,11 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN") endif() + # Use a safe subset of flags to speed up math calculations: + # - we don't need errno or math exceptions + # - we don't deal with Inf/NaN or signed zero + set(MATH_FLAGS "-fno-math-errno -fno-trapping-math -ffinite-math-only -fno-signed-zeros") + set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops") if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os") @@ -723,7 +728,7 @@ else() AND CMAKE_CXX_COMPILER_VERSION MATCHES "^9\\.") # Clang 9 has broken -ffast-math on glibc else() - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffast-math") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MATH_FLAGS}") endif() endif(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)") set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}") diff --git a/src/collision.cpp b/src/collision.cpp index 6d24bc699..a089f3377 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -32,6 +32,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/timetaker.h" #include "profiler.h" +#ifdef __FAST_MATH__ +#warning "-ffast-math is known to cause bugs in collision code, do not use!" +#endif struct NearbyCollisionInfo { NearbyCollisionInfo(bool is_ul, bool is_obj, int bouncy, -- cgit v1.2.3 From 45999b74e610b13e8cda20c0c420e152b9837ea6 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 16 Apr 2020 18:32:07 +0200 Subject: Camera: Fix shooting line offsets (#9681) Removes duplicated offset calculations from Game and use whatever the Camera class returns. This keeps the eye position nicely in sync, and gets rid of duplicated code. --- src/client/camera.cpp | 26 +++++++++++++++----------- src/client/camera.h | 6 ++++++ src/client/game.cpp | 20 +++++++------------- src/client/localplayer.h | 3 +++ 4 files changed, 31 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 871ea709d..fb1c3ff56 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -333,17 +333,21 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r fall_bobbing *= m_cache_fall_bobbing_amount; } - // Calculate players eye offset for different camera modes - v3f PlayerEyeOffset = player->getEyeOffset(); - if (m_camera_mode == CAMERA_MODE_FIRST) - PlayerEyeOffset += player->eye_offset_first; - else - PlayerEyeOffset += player->eye_offset_third; - - // Set head node transformation - m_headnode->setPosition(PlayerEyeOffset+v3f(0,cameratilt*-player->hurt_tilt_strength+fall_bobbing,0)); - m_headnode->setRotation(v3f(player->getPitch(), 0, cameratilt*player->hurt_tilt_strength)); - m_headnode->updateAbsolutePosition(); + // Calculate and translate the head SceneNode offsets + { + v3f eye_offset = player->getEyeOffset(); + if (m_camera_mode == CAMERA_MODE_FIRST) + eye_offset += player->eye_offset_first; + else + eye_offset += player->eye_offset_third; + + // Set head node transformation + eye_offset.Y += cameratilt * -player->hurt_tilt_strength + fall_bobbing; + m_headnode->setPosition(eye_offset); + m_headnode->setRotation(v3f(player->getPitch(), 0, + cameratilt * player->hurt_tilt_strength)); + m_headnode->updateAbsolutePosition(); + } // Compute relative camera position and target v3f rel_cam_pos = v3f(0,0,0); diff --git a/src/client/camera.h b/src/client/camera.h index 88de3570a..6ec37fe10 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -75,6 +75,12 @@ public: return m_camera_position; } + // Returns the absolute position of the head SceneNode in the world + inline v3f getHeadPosition() const + { + return m_headnode->getAbsolutePosition(); + } + // Get the camera direction (in absolute camera coordinates). // This has view bobbing applied. inline v3f getDirection() const diff --git a/src/client/game.cpp b/src/client/game.cpp index f7234eea6..4b2d7c652 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3029,16 +3029,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) { LocalPlayer *player = client->getEnv().getLocalPlayer(); - v3f player_position = player->getPosition(); - v3f player_eye_position = player->getEyePosition(); - v3f camera_position = camera->getPosition(); - v3f camera_direction = camera->getDirection(); - v3s16 camera_offset = camera->getOffset(); - - if (camera->getCameraMode() == CAMERA_MODE_FIRST) - player_eye_position += player->eye_offset_first; - else - player_eye_position += player->eye_offset_third; + const v3f head_position = camera->getHeadPosition(); + const v3f camera_direction = camera->getDirection(); + const v3s16 camera_offset = camera->getOffset(); /* Calculate what block is the crosshair pointing to @@ -3053,11 +3046,11 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) core::line3d shootline; if (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT) { - shootline = core::line3d(player_eye_position, - player_eye_position + camera_direction * BS * d); + shootline = core::line3d(head_position, + head_position + camera_direction * BS * d); } else { // prevent player pointing anything in front-view - shootline = core::line3d(camera_position, camera_position); + shootline = core::line3d(head_position, head_position); } #ifdef HAVE_TOUCHSCREENGUI @@ -3145,6 +3138,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) } else if (pointed.type == POINTEDTHING_NODE) { handlePointingAtNode(pointed, selected_item, hand_item, dtime); } else if (pointed.type == POINTEDTHING_OBJECT) { + v3f player_position = player->getPosition(); handlePointingAtObject(pointed, tool_item, player_position, show_debug); } else if (input->getLeftState()) { // When button is held down in air, show continuous animation diff --git a/src/client/localplayer.h b/src/client/localplayer.h index d88ae17ac..345aec9d9 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -135,6 +135,9 @@ public: } v3f getPosition() const { return m_position; } + + // Non-transformed eye offset getters + // For accurate positions, use the Camera functions v3f getEyePosition() const { return m_position + getEyeOffset(); } v3f getEyeOffset() const; void setEyeHeight(float eye_height) { m_eye_height = eye_height; } -- cgit v1.2.3 From 57038b3cb4b48d242af8e7dc9d598edf2e1018c4 Mon Sep 17 00:00:00 2001 From: Maksim Date: Thu, 16 Apr 2020 19:19:47 +0200 Subject: Android: fix formspec input for AArch64 devices (#9685) --- src/gui/guiFormSpecMenu.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index aac039ad6..b0255cf1b 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3346,28 +3346,24 @@ bool GUIFormSpecMenu::getAndroidUIInput() if (!hasAndroidUIInput()) return false; + // still waiting + if (porting::getInputDialogState() == -1) + return true; + std::string fieldname = m_jni_field_name; m_jni_field_name.clear(); - for (std::vector::iterator iter = m_fields.begin(); - iter != m_fields.end(); ++iter) { - - if (iter->fname != fieldname) { + for (const FieldSpec &field : m_fields) { + if (field.fname != fieldname) continue; - } - IGUIElement *tochange = getElementFromId(iter->fid, true); - if (tochange == 0) { - return false; - } + IGUIElement *element = getElementFromId(field.fid, true); - if (tochange->getType() != irr::gui::EGUIET_EDIT_BOX) { + if (!element || element->getType() != irr::gui::EGUIET_EDIT_BOX) return false; - } std::string text = porting::getInputDialogValue(); - - ((gui::IGUIEditBox *)tochange)->setText(utf8_to_wide(text).c_str()); + ((gui::IGUIEditBox *)element)->setText(utf8_to_wide(text).c_str()); } return false; } -- cgit v1.2.3 From 093e79ea78c872293386bf10b76416ff284ac5b6 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 16 Apr 2020 19:21:47 +0200 Subject: Drop -Wabi useless flag (#9676) --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5f774d77..c3f4f439f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE(CheckIncludeFiles) INCLUDE(CheckLibraryExists) # Add custom SemiDebug build mode -set(CMAKE_CXX_FLAGS_SEMIDEBUG "-O1 -g -Wall -Wabi" CACHE STRING +set(CMAKE_CXX_FLAGS_SEMIDEBUG "-O1 -g -Wall" CACHE STRING "Flags used by the C++ compiler during semidebug builds." FORCE ) @@ -731,8 +731,8 @@ else() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MATH_FLAGS}") endif() endif(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)") - set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wabi ${WARNING_FLAGS} ${OTHER_FLAGS}") + set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}") if(USE_GPROF) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") -- cgit v1.2.3 From 7539267d370ae9a1b547008a937bd7f57bece541 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 16 Apr 2020 20:43:49 +0200 Subject: Add an option to disable unittest build, & disable them on Docker build (#9677) --- CMakeLists.txt | 1 + Dockerfile | 1 + README.md | 1 + src/CMakeLists.txt | 11 +++++++++-- src/cmake_config.h.in | 1 + src/main.cpp | 6 ++++++ 6 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cf89dd17..ae842918b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set(RUN_IN_PLACE ${DEFAULT_RUN_IN_PLACE} CACHE BOOL set(BUILD_CLIENT TRUE CACHE BOOL "Build client") set(BUILD_SERVER FALSE CACHE BOOL "Build server") +set(BUILD_UNITTESTS TRUE CACHE BOOL "Build unittests") set(WARN_ALL TRUE CACHE BOOL "Enable -Wall for Release build") diff --git a/Dockerfile b/Dockerfile index 3c41ce0f4..7c1107288 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ RUN apk add --no-cache git build-base irrlicht-dev cmake bzip2-dev libpng-dev \ -DCMAKE_INSTALL_PREFIX=/usr/local \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SERVER=TRUE \ + -DBUILD_UNITTESTS=FALSE \ -DBUILD_CLIENT=FALSE && \ make -j2 && \ make install diff --git a/README.md b/README.md index cfd5a8ae0..e9065dfa7 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ General options and their default values: BUILD_CLIENT=TRUE - Build Minetest client BUILD_SERVER=FALSE - Build Minetest server + BUILD_UNITTESTS=TRUE - Build unittest sources CMAKE_BUILD_TYPE=Release - Type of build (Release vs. Debug) Release - Release build Debug - Debug build diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3f4f439f..dbd6b5922 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -435,9 +435,12 @@ set(common_SRCS ${JTHREAD_SRCS} ${common_SCRIPT_SRCS} ${UTIL_SRCS} - ${UNITTEST_SRCS} ) +if(BUILD_UNITTESTS) + set(common_SRCS ${common_SRCS} ${UNITTEST_SRCS}) +endif() + # This gives us the icon and file version information if(WIN32) @@ -472,8 +475,12 @@ set(client_SRCS ${client_network_SRCS} ${client_irrlicht_changes_SRCS} ${client_SCRIPT_SRCS} - ${UNITTEST_CLIENT_SRCS} ) + +if(BUILD_UNITTESTS) + set(client_SRCS ${client_SRCS} ${UNITTEST_CLIENT_SRCS}) +endif() + list(SORT client_SRCS) # Server sources diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index cb54cb488..cac6335d4 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -34,3 +34,4 @@ #cmakedefine01 CURSES_HAVE_NCURSES_CURSES_H #cmakedefine01 CURSES_HAVE_NCURSESW_NCURSES_H #cmakedefine01 CURSES_HAVE_NCURSESW_CURSES_H +#cmakedefine01 BUILD_UNITTESTS diff --git a/src/main.cpp b/src/main.cpp index db020661a..82666e463 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,7 +187,13 @@ int main(int argc, char *argv[]) #ifndef __ANDROID__ // Run unit tests if (cmd_args.getFlag("run-unittests")) { +#if BUILD_UNITTESTS return run_tests(); +#else + errorstream << "Unittest support is not enabled in this binary. " + << "If you want to enable it, compile project with BUILD_UNITTESTS=1 flag." + << std::endl; +#endif } #endif -- cgit v1.2.3 From e88719bcdd49c5bfe295dc89bc2852e0f3dc8065 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 17 Apr 2020 08:10:28 +0200 Subject: Rename "subgame" to "game" in 2 error messages (#9680) --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 82666e463..147f686ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -781,7 +781,7 @@ static bool determine_subgame(GameParams *game_params) gamespec = findSubgame(g_settings->get("default_game")); infostream << "Using default gameid [" << gamespec.id << "]" << std::endl; if (!gamespec.isValid()) { - errorstream << "Subgame specified in default_game [" + errorstream << "Game specified in default_game [" << g_settings->get("default_game") << "] is invalid." << std::endl; return false; @@ -806,7 +806,7 @@ static bool determine_subgame(GameParams *game_params) } if (!gamespec.isValid()) { - errorstream << "Subgame [" << gamespec.id << "] could not be found." + errorstream << "Game [" << gamespec.id << "] could not be found." << std::endl; return false; } -- cgit v1.2.3 From 23c6d0c31f2e0a4a6032b0afb02fab1d5f9c517b Mon Sep 17 00:00:00 2001 From: Maksim Date: Fri, 17 Apr 2020 23:46:30 +0200 Subject: Android: fix handling non-latin characters on older Android devices (#9309) --- src/server.cpp | 8 ++++++++ src/util/string.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/server.cpp b/src/server.cpp index b3992b9b1..c32aa5306 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3031,8 +3031,16 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna line += L"-!- You don't have permission to shout."; broadcast_line = false; } else { + /* + Workaround for fixing chat on Android. Lua doesn't handle + the Cyrillic alphabet and some characters on older Android devices + */ +#ifdef __ANDROID__ + line += L"<" + wname + L"> " + wmessage; +#else line += narrow_to_wide(m_script->formatChatMessage(name, wide_to_narrow(wmessage))); +#endif } /* diff --git a/src/util/string.cpp b/src/util/string.cpp index e6c52585d..2ee3ec735 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -209,6 +209,9 @@ wchar_t *narrow_to_wide_c(const char *str) } std::wstring narrow_to_wide(const std::string &mbs) { +#ifdef __ANDROID__ + return utf8_to_wide(mbs); +#else size_t wcl = mbs.size(); Buffer wcs(wcl + 1); size_t len = mbstowcs(*wcs, mbs.c_str(), wcl); @@ -216,11 +219,15 @@ std::wstring narrow_to_wide(const std::string &mbs) { return L""; wcs[len] = 0; return *wcs; +#endif } std::string wide_to_narrow(const std::wstring &wcs) { +#ifdef __ANDROID__ + return wide_to_utf8(wcs); +#else size_t mbl = wcs.size() * 4; SharedBuffer mbs(mbl+1); size_t len = wcstombs(*mbs, wcs.c_str(), mbl); @@ -229,6 +236,7 @@ std::string wide_to_narrow(const std::wstring &wcs) mbs[len] = 0; return *mbs; +#endif } -- cgit v1.2.3 From 7b57d3f613bab05914d3f7210064a3282ea37013 Mon Sep 17 00:00:00 2001 From: HybridDog <3192173+HybridDog@users.noreply.github.com> Date: Sat, 18 Apr 2020 17:19:53 +0200 Subject: serverpackethandler: Reduce pkt->getPeerId() invocations and more (#9689) --- src/network/serverpackethandler.cpp | 613 ++++++++++++++++-------------------- src/server.h | 1 - 2 files changed, 272 insertions(+), 342 deletions(-) (limited to 'src') diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index b2fdb2a22..c685500ce 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -52,11 +52,12 @@ void Server::handleCommand_Init(NetworkPacket* pkt) if(pkt->getSize() < 1) return; - RemoteClient* client = getClient(pkt->getPeerId(), CS_Created); + session_t peer_id = pkt->getPeerId(); + RemoteClient *client = getClient(peer_id, CS_Created); std::string addr_s; try { - Address address = getPeerAddress(pkt->getPeerId()); + Address address = getPeerAddress(peer_id); addr_s = address.serializeString(); } catch (con::PeerNotFoundException &e) { @@ -66,27 +67,27 @@ void Server::handleCommand_Init(NetworkPacket* pkt) * respond for some time, your server was overloaded or * things like that. */ - infostream << "Server::ProcessData(): Canceling: peer " - << pkt->getPeerId() << " not found" << std::endl; + infostream << "Server::ProcessData(): Canceling: peer " << peer_id << + " not found" << std::endl; return; } // If net_proto_version is set, this client has already been handled if (client->getState() > CS_Created) { - verbosestream << "Server: Ignoring multiple TOSERVER_INITs from " - << addr_s << " (peer_id=" << pkt->getPeerId() << ")" << std::endl; + verbosestream << "Server: Ignoring multiple TOSERVER_INITs from " << + addr_s << " (peer_id=" << peer_id << ")" << std::endl; return; } - verbosestream << "Server: Got TOSERVER_INIT from " << addr_s << " (peer_id=" - << pkt->getPeerId() << ")" << std::endl; + verbosestream << "Server: Got TOSERVER_INIT from " << addr_s << + " (peer_id=" << peer_id << ")" << std::endl; // Do not allow multiple players in simple singleplayer mode. // This isn't a perfect way to do it, but will suffice for now if (m_simple_singleplayer_mode && m_clients.getClientIDs().size() > 1) { - infostream << "Server: Not allowing another client (" << addr_s - << ") to connect in simple singleplayer mode" << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SINGLEPLAYER); + infostream << "Server: Not allowing another client (" << addr_s << + ") to connect in simple singleplayer mode" << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_SINGLEPLAYER); return; } @@ -109,11 +110,11 @@ void Server::handleCommand_Init(NetworkPacket* pkt) depl_serial_v = SER_FMT_VER_INVALID; if (depl_serial_v == SER_FMT_VER_INVALID) { - actionstream << "Server: A mismatched client tried to connect from " - << addr_s << std::endl; - infostream<<"Server: Cannot negotiate serialization version with " - << addr_s << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_VERSION); + actionstream << "Server: A mismatched client tried to connect from " << + addr_s << std::endl; + infostream << "Server: Cannot negotiate serialization version with " << + addr_s << " client_max=" << (int)client_max << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION); return; } @@ -146,9 +147,9 @@ void Server::handleCommand_Init(NetworkPacket* pkt) net_proto_version != LATEST_PROTOCOL_VERSION) || net_proto_version < SERVER_PROTOCOL_VERSION_MIN || net_proto_version > SERVER_PROTOCOL_VERSION_MAX) { - actionstream << "Server: A mismatched client tried to connect from " - << addr_s << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_VERSION); + actionstream << "Server: A mismatched client tried to connect from " << + addr_s << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION); return; } @@ -159,56 +160,56 @@ void Server::handleCommand_Init(NetworkPacket* pkt) size_t pns = playerName.size(); if (pns == 0 || pns > PLAYERNAME_SIZE) { - actionstream << "Server: Player with " - << ((pns > PLAYERNAME_SIZE) ? "a too long" : "an empty") - << " name tried to connect from " << addr_s << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_NAME); + actionstream << "Server: Player with " << + ((pns > PLAYERNAME_SIZE) ? "a too long" : "an empty") << + " name tried to connect from " << addr_s << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_NAME); return; } if (!string_allowed(playerName, PLAYERNAME_ALLOWED_CHARS)) { - actionstream << "Server: Player with an invalid name " - << "tried to connect from " << addr_s << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_CHARS_IN_NAME); + actionstream << "Server: Player with an invalid name tried to connect " + "from " << addr_s << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_CHARS_IN_NAME); return; } - m_clients.setPlayerName(pkt->getPeerId(), playername); + m_clients.setPlayerName(peer_id, playername); //TODO (later) case insensitivity std::string legacyPlayerNameCasing = playerName; if (!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0) { - actionstream << "Server: Player with the name \"singleplayer\" " - << "tried to connect from " << addr_s << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_NAME); + actionstream << "Server: Player with the name \"singleplayer\" tried " + "to connect from " << addr_s << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_NAME); return; } { std::string reason; if (m_script->on_prejoinplayer(playername, addr_s, &reason)) { - actionstream << "Server: Player with the name \"" << playerName << "\" " - << "tried to connect from " << addr_s << " " - << "but it was disallowed for the following reason: " - << reason << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_CUSTOM_STRING, reason); + actionstream << "Server: Player with the name \"" << playerName << + "\" tried to connect from " << addr_s << + " but it was disallowed for the following reason: " << reason << + std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_CUSTOM_STRING, reason); return; } } - infostream << "Server: New connection: \"" << playerName << "\" from " - << addr_s << " (peer_id=" << pkt->getPeerId() << ")" << std::endl; + infostream << "Server: New connection: \"" << playerName << "\" from " << + addr_s << " (peer_id=" << peer_id << ")" << std::endl; // Enforce user limit. // Don't enforce for users that have some admin right or mod permits it. if (m_clients.isUserLimitReached() && playername != g_settings->get("name") && !m_script->can_bypass_userlimit(playername, addr_s)) { - actionstream << "Server: " << playername << " tried to join from " - << addr_s << ", but there" << " are already max_users=" - << g_settings->getU16("max_users") << " players." << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_TOO_MANY_USERS); + actionstream << "Server: " << playername << " tried to join from " << + addr_s << ", but there are already max_users=" << + g_settings->getU16("max_users") << " players." << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_TOO_MANY_USERS); return; } @@ -228,20 +229,19 @@ void Server::handleCommand_Init(NetworkPacket* pkt) auth_mechs |= AUTH_MECHANISM_SRP; client->enc_pwd = encpwd; } else { - actionstream << "User " << playername - << " tried to log in, but password field" - << " was invalid (unknown mechcode)." << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SERVER_FAIL); + actionstream << "User " << playername << " tried to log in, " + "but password field was invalid (unknown mechcode)." << + std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL); return; } } else if (base64_is_valid(encpwd)) { auth_mechs |= AUTH_MECHANISM_LEGACY_PASSWORD; client->enc_pwd = encpwd; } else { - actionstream << "User " << playername - << " tried to log in, but password field" - << " was invalid (invalid base64)." << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SERVER_FAIL); + actionstream << "User " << playername << " tried to log in, but " + "password field was invalid (invalid base64)." << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL); return; } } else { @@ -264,8 +264,8 @@ void Server::handleCommand_Init(NetworkPacket* pkt) verbosestream << "Sending TOCLIENT_HELLO with auth method field: " << auth_mechs << std::endl; - NetworkPacket resp_pkt(TOCLIENT_HELLO, 1 + 4 - + legacyPlayerNameCasing.size(), pkt->getPeerId()); + NetworkPacket resp_pkt(TOCLIENT_HELLO, + 1 + 4 + legacyPlayerNameCasing.size(), peer_id); u16 depl_compress_mode = NETPROTO_COMPRESSION_NONE; resp_pkt << depl_serial_v << depl_compress_mode << net_proto_version @@ -276,16 +276,16 @@ void Server::handleCommand_Init(NetworkPacket* pkt) client->allowed_auth_mechs = auth_mechs; client->setDeployedCompressionMode(depl_compress_mode); - m_clients.event(pkt->getPeerId(), CSE_Hello); + m_clients.event(peer_id, CSE_Hello); } void Server::handleCommand_Init2(NetworkPacket* pkt) { - verbosestream << "Server: Got TOSERVER_INIT2 from " - << pkt->getPeerId() << std::endl; + session_t peer_id = pkt->getPeerId(); + verbosestream << "Server: Got TOSERVER_INIT2 from " << peer_id << std::endl; - m_clients.event(pkt->getPeerId(), CSE_GotInit2); - u16 protocol_version = m_clients.getProtocolVersion(pkt->getPeerId()); + m_clients.event(peer_id, CSE_GotInit2); + u16 protocol_version = m_clients.getProtocolVersion(peer_id); std::string lang; if (pkt->getSize() > 0) @@ -295,45 +295,45 @@ void Server::handleCommand_Init2(NetworkPacket* pkt) Send some initialization data */ - infostream << "Server: Sending content to " - << getPlayerName(pkt->getPeerId()) << std::endl; + infostream << "Server: Sending content to " << getPlayerName(peer_id) << + std::endl; // Send item definitions - SendItemDef(pkt->getPeerId(), m_itemdef, protocol_version); + SendItemDef(peer_id, m_itemdef, protocol_version); // Send node definitions - SendNodeDef(pkt->getPeerId(), m_nodedef, protocol_version); + SendNodeDef(peer_id, m_nodedef, protocol_version); - m_clients.event(pkt->getPeerId(), CSE_SetDefinitionsSent); + m_clients.event(peer_id, CSE_SetDefinitionsSent); // Send media announcement - sendMediaAnnouncement(pkt->getPeerId(), lang); + sendMediaAnnouncement(peer_id, lang); - RemoteClient *client = getClient(pkt->getPeerId(), CS_InitDone); + RemoteClient *client = getClient(peer_id, CS_InitDone); // Send active objects { - PlayerSAO *sao = getPlayerSAO(pkt->getPeerId()); + PlayerSAO *sao = getPlayerSAO(peer_id); if (client && sao) SendActiveObjectRemoveAdd(client, sao); } // Send detached inventories - sendDetachedInventories(pkt->getPeerId(), false); + sendDetachedInventories(peer_id, false); // Send player movement settings - SendMovement(pkt->getPeerId()); + SendMovement(peer_id); // Send time of day u16 time = m_env->getTimeOfDay(); float time_speed = g_settings->getFloat("time_speed"); - SendTimeOfDay(pkt->getPeerId(), time, time_speed); + SendTimeOfDay(peer_id, time, time_speed); - SendCSMRestrictionFlags(pkt->getPeerId()); + SendCSMRestrictionFlags(peer_id); // Warnings about protocol version can be issued here if (client->net_proto_version < LATEST_PROTOCOL_VERSION) { - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, + SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM, L"# Server: WARNING: YOUR CLIENT'S VERSION MAY NOT BE FULLY COMPATIBLE " L"WITH THIS SERVER!")); } @@ -346,8 +346,9 @@ void Server::handleCommand_RequestMedia(NetworkPacket* pkt) *pkt >> numfiles; - infostream << "Sending " << numfiles << " files to " - << getPlayerName(pkt->getPeerId()) << std::endl; + session_t peer_id = pkt->getPeerId(); + infostream << "Sending " << numfiles << " files to " << + getPlayerName(peer_id) << std::endl; verbosestream << "TOSERVER_REQUEST_MEDIA: " << std::endl; for (u16 i = 0; i < numfiles; i++) { @@ -360,7 +361,7 @@ void Server::handleCommand_RequestMedia(NetworkPacket* pkt) << name << std::endl; } - sendRequestedMedia(pkt->getPeerId(), tosend); + sendRequestedMedia(peer_id, tosend); } void Server::handleCommand_ClientReady(NetworkPacket* pkt) @@ -370,18 +371,16 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt) PlayerSAO* playersao = StageTwoClientInit(peer_id); if (playersao == NULL) { - actionstream - << "TOSERVER_CLIENT_READY stage 2 client init failed for peer_id: " - << peer_id << std::endl; + errorstream << "TOSERVER_CLIENT_READY stage 2 client init failed " + "peer_id=" << peer_id << std::endl; DisconnectPeer(peer_id); return; } if (pkt->getSize() < 8) { - errorstream - << "TOSERVER_CLIENT_READY client sent inconsistent data, disconnecting peer_id: " - << peer_id << std::endl; + errorstream << "TOSERVER_CLIENT_READY client sent inconsistent data, " + "disconnecting peer_id: " << peer_id << std::endl; DisconnectPeer(peer_id); return; } @@ -390,9 +389,8 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt) std::string full_ver; *pkt >> major_ver >> minor_ver >> patch_ver >> reserved >> full_ver; - m_clients.setClientVersion( - peer_id, major_ver, minor_ver, patch_ver, - full_ver); + m_clients.setClientVersion(peer_id, major_ver, minor_ver, patch_ver, + full_ver); if (pkt->getRemainingBytes() >= 2) *pkt >> playersao->getPlayer()->formspec_version; @@ -414,7 +412,7 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt) m_script->on_joinplayer(playersao); // Send shutdown timer if shutdown has been scheduled if (m_shutdown_state.isTimerRunning()) { - SendChatMessage(pkt->getPeerId(), m_shutdown_state.getShutdownTimerMessage()); + SendChatMessage(peer_id, m_shutdown_state.getShutdownTimerMessage()); } } @@ -508,21 +506,22 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, void Server::handleCommand_PlayerPos(NetworkPacket* pkt) { - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -568,22 +567,23 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) void Server::handleCommand_InventoryAction(NetworkPacket* pkt) { - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -761,12 +761,13 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt) message += (wchar_t)tmp_wchar; } - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -777,8 +778,8 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt) std::wstring answer_to_sender = handleChat(name, wname, message, true, player); if (!answer_to_sender.empty()) { // Send the answer to sender - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_NORMAL, - answer_to_sender, wname)); + SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_NORMAL, + answer_to_sender, wname)); } } @@ -788,22 +789,23 @@ void Server::handleCommand_Damage(NetworkPacket* pkt) *pkt >> damage; - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -825,105 +827,28 @@ void Server::handleCommand_Damage(NetworkPacket* pkt) } } -void Server::handleCommand_Password(NetworkPacket* pkt) -{ - if (pkt->getSize() != PASSWORD_SIZE * 2) - return; - - std::string oldpwd; - std::string newpwd; - - // Deny for clients using the new protocol - RemoteClient* client = getClient(pkt->getPeerId(), CS_Created); - if (client->net_proto_version >= 25) { - infostream << "Server::handleCommand_Password(): Denying change: " - << " Client protocol version for peer_id=" << pkt->getPeerId() - << " too new!" << std::endl; - return; - } - - for (u16 i = 0; i < PASSWORD_SIZE - 1; i++) { - char c = pkt->getChar(i); - if (c == 0) - break; - oldpwd += c; - } - - for (u16 i = 0; i < PASSWORD_SIZE - 1; i++) { - char c = pkt->getChar(PASSWORD_SIZE + i); - if (c == 0) - break; - newpwd += c; - } - - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); - if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); - return; - } - - if (!base64_is_valid(newpwd)) { - infostream<<"Server: " << player->getName() << - " supplied invalid password hash" << std::endl; - // Wrong old password supplied!! - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, - L"Invalid new password hash supplied. Password NOT changed.")); - return; - } - - infostream << "Server: Client requests a password change from " - << "'" << oldpwd << "' to '" << newpwd << "'" << std::endl; - - std::string playername = player->getName(); - - std::string checkpwd; - m_script->getAuth(playername, &checkpwd, NULL); - - if (oldpwd != checkpwd) { - infostream << "Server: invalid old password" << std::endl; - // Wrong old password supplied!! - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, - L"Invalid old password supplied. Password NOT changed.")); - return; - } - - bool success = m_script->setPassword(playername, newpwd); - if (success) { - actionstream << player->getName() << " changes password" << std::endl; - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, - L"Password change successful.")); - } else { - actionstream << player->getName() << " tries to change password but " - << "it fails" << std::endl; - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, - L"Password change failed or unavailable.")); - } -} - void Server::handleCommand_PlayerItem(NetworkPacket* pkt) { if (pkt->getSize() < 2) return; - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -936,12 +861,13 @@ void Server::handleCommand_PlayerItem(NetworkPacket* pkt) void Server::handleCommand_Respawn(NetworkPacket* pkt) { - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -951,7 +877,7 @@ void Server::handleCommand_Respawn(NetworkPacket* pkt) if (!playersao->isDead()) return; - RespawnPlayer(pkt->getPeerId()); + RespawnPlayer(peer_id); actionstream << player->getName() << " respawns at " << PP(playersao->getBasePosition() / BS) << std::endl; @@ -1006,22 +932,23 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) verbosestream << "TOSERVER_INTERACT: action=" << (int)action << ", item=" << item_i << ", pointed=" << pointed.dump() << std::endl; - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -1030,7 +957,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) << " tried to interact while dead; ignoring." << std::endl; if (pointed.type == POINTEDTHING_NODE) { // Re-send block to revert change on client-side - RemoteClient *client = getClient(pkt->getPeerId()); + RemoteClient *client = getClient(peer_id); v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface); client->SetBlockNotSent(blockpos); } @@ -1081,7 +1008,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) pointed.dump() << " without 'interact' privilege" << std::endl; // Re-send block to revert change on client-side - RemoteClient *client = getClient(pkt->getPeerId()); + RemoteClient *client = getClient(peer_id); // Digging completed -> under if (action == INTERACT_DIGGING_COMPLETED) { v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS)); @@ -1109,7 +1036,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) if (!checkInteractDistance(player, d, pointed.dump())) { // Re-send block to revert change on client-side - RemoteClient *client = getClient(pkt->getPeerId()); + RemoteClient *client = getClient(peer_id); v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS)); client->SetBlockNotSent(blockpos); return; @@ -1132,11 +1059,10 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) n = m_env->getMap().getNode(p_under, &pos_ok); if (!pos_ok) { - infostream << "Server: Not punching: Node not found." - << " Adding block to emerge queue." - << std::endl; - m_emerge->enqueueBlockEmerge(pkt->getPeerId(), - getNodeBlockPos(p_above), false); + infostream << "Server: Not punching: Node not found. " + "Adding block to emerge queue." << std::endl; + m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), + false); } if (n.getContent() != CONTENT_IGNORE) @@ -1202,11 +1128,10 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) bool pos_ok; MapNode n = m_env->getMap().getNode(p_under, &pos_ok); if (!pos_ok) { - infostream << "Server: Not finishing digging: Node not found." - << " Adding block to emerge queue." - << std::endl; - m_emerge->enqueueBlockEmerge(pkt->getPeerId(), - getNodeBlockPos(p_above), false); + infostream << "Server: Not finishing digging: Node not found. " + "Adding block to emerge queue." << std::endl; + m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), + false); } /* Cheat prevention */ @@ -1282,7 +1207,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) m_script->node_on_dig(p_under, n, playersao); v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_under, BS)); - RemoteClient *client = getClient(pkt->getPeerId()); + RemoteClient *client = getClient(peer_id); // Send unusual result (that is, node not being removed) if (m_env->getMap().getNode(p_under).getContent() != CONTENT_AIR) { // Re-send block to revert change on client-side @@ -1304,7 +1229,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) // Reset build time counter if (pointed.type == POINTEDTHING_NODE && selected_item.getDefinition(m_itemdef).type == ITEM_NODE) - getClient(pkt->getPeerId())->m_time_from_building = 0.0; + getClient(peer_id)->m_time_from_building = 0.0; if (pointed.type == POINTEDTHING_OBJECT) { // Right click object @@ -1338,7 +1263,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) // If item has node placement prediction, always send the // blocks to make sure the client knows what exactly happened - RemoteClient *client = getClient(pkt->getPeerId()); + RemoteClient *client = getClient(peer_id); v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS)); v3s16 blockpos2 = getNodeBlockPos(floatToInt(pointed_pos_under, BS)); if (!selected_item.getDefinition(m_itemdef).node_placement_prediction.empty()) { @@ -1441,22 +1366,23 @@ void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt) fields[fieldname] = pkt->readLongString(); } - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -1492,22 +1418,23 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt) fields[fieldname] = pkt->readLongString(); } - RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + RemotePlayer *player = m_env->getPlayer(peer_id); if (player == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } PlayerSAO *playersao = player->getPlayerSAO(); if (playersao == NULL) { - errorstream << "Server::ProcessData(): Canceling: " - "No player object for peer_id=" << pkt->getPeerId() - << " disconnecting peer!" << std::endl; - DisconnectPeer(pkt->getPeerId()); + errorstream << + "Server::ProcessData(): Canceling: No player object for peer_id=" << + peer_id << " disconnecting peer!" << std::endl; + DisconnectPeer(peer_id); return; } @@ -1517,7 +1444,7 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt) } // verify that we displayed the formspec to the user - const auto peer_state_iterator = m_formspec_state_data.find(pkt->getPeerId()); + const auto peer_state_iterator = m_formspec_state_data.find(peer_id); if (peer_state_iterator != m_formspec_state_data.end()) { const std::string &server_formspec_name = peer_state_iterator->second; if (client_formspec_name == server_formspec_name) { @@ -1543,7 +1470,8 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt) void Server::handleCommand_FirstSrp(NetworkPacket* pkt) { - RemoteClient* client = getClient(pkt->getPeerId(), CS_Invalid); + session_t peer_id = pkt->getPeerId(); + RemoteClient *client = getClient(peer_id, CS_Invalid); ClientState cstate = client->getState(); std::string playername = client->getName(); @@ -1551,7 +1479,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) std::string salt; std::string verification_key; - std::string addr_s = getPeerAddress(pkt->getPeerId()).serializeString(); + std::string addr_s = getPeerAddress(peer_id).serializeString(); u8 is_empty; *pkt >> salt >> verification_key >> is_empty; @@ -1565,7 +1493,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) actionstream << "Server: Client from " << addr_s << " tried to set password without being " << "authenticated, or the username being new." << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA); + DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } @@ -1574,7 +1502,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) is_empty == 1) { actionstream << "Server: " << playername << " supplied empty password from " << addr_s << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_EMPTY_PASSWORD); + DenyAccess(peer_id, SERVER_ACCESSDENIED_EMPTY_PASSWORD); return; } @@ -1583,7 +1511,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) initial_ver_key = encode_srp_verifier(verification_key, salt); m_script->createAuth(playername, initial_ver_key); - acceptAuth(pkt->getPeerId(), false); + acceptAuth(peer_id, false); } else { if (cstate < CS_SudoMode) { infostream << "Server::ProcessData(): Ignoring TOSERVER_FIRST_SRP from " @@ -1591,48 +1519,48 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) << std::endl; return; } - m_clients.event(pkt->getPeerId(), CSE_SudoLeave); + m_clients.event(peer_id, CSE_SudoLeave); std::string pw_db_field = encode_srp_verifier(verification_key, salt); bool success = m_script->setPassword(playername, pw_db_field); if (success) { actionstream << playername << " changes password" << std::endl; - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, - L"Password change successful.")); + SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM, + L"Password change successful.")); } else { - actionstream << playername << " tries to change password but " - << "it fails" << std::endl; - SendChatMessage(pkt->getPeerId(), ChatMessage(CHATMESSAGE_TYPE_SYSTEM, - L"Password change failed or unavailable.")); + actionstream << playername << + " tries to change password but it fails" << std::endl; + SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM, + L"Password change failed or unavailable.")); } } } void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) { - RemoteClient* client = getClient(pkt->getPeerId(), CS_Invalid); + session_t peer_id = pkt->getPeerId(); + RemoteClient *client = getClient(peer_id, CS_Invalid); ClientState cstate = client->getState(); bool wantSudo = (cstate == CS_Active); if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) { - actionstream << "Server: got SRP _A packet in wrong state " - << cstate << " from " - << getPeerAddress(pkt->getPeerId()).serializeString() - << ". Ignoring." << std::endl; + actionstream << "Server: got SRP _A packet in wrong state " << cstate << + " from " << getPeerAddress(peer_id).serializeString() << + ". Ignoring." << std::endl; return; } if (client->chosen_mech != AUTH_MECHANISM_NONE) { - actionstream << "Server: got SRP _A packet, while auth" - << "is already going on with mech " << client->chosen_mech - << " from " << getPeerAddress(pkt->getPeerId()).serializeString() - << " (wantSudo=" << wantSudo << "). Ignoring." << std::endl; + actionstream << "Server: got SRP _A packet, while auth is already " + "going on with mech " << client->chosen_mech << " from " << + getPeerAddress(peer_id).serializeString() << + " (wantSudo=" << wantSudo << "). Ignoring." << std::endl; if (wantSudo) { - DenySudoAccess(pkt->getPeerId()); + DenySudoAccess(peer_id); return; } - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA); + DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } @@ -1649,19 +1577,19 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) if (wantSudo) { if (!client->isSudoMechAllowed(chosen)) { - actionstream << "Server: Player \"" << client->getName() - << "\" at " << getPeerAddress(pkt->getPeerId()).serializeString() - << " tried to change password using unallowed mech " - << chosen << "." << std::endl; - DenySudoAccess(pkt->getPeerId()); + actionstream << "Server: Player \"" << client->getName() << + "\" at " << getPeerAddress(peer_id).serializeString() << + " tried to change password using unallowed mech " << chosen << + "." << std::endl; + DenySudoAccess(peer_id); return; } } else { if (!client->isMechAllowed(chosen)) { - actionstream << "Server: Client tried to authenticate from " - << getPeerAddress(pkt->getPeerId()).serializeString() - << " using unallowed mech " << chosen << "." << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA); + actionstream << "Server: Client tried to authenticate from " << + getPeerAddress(peer_id).serializeString() << + " using unallowed mech " << chosen << "." << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } } @@ -1677,10 +1605,10 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) &verifier, &salt); } else if (!decode_srp_verifier_and_salt(client->enc_pwd, &verifier, &salt)) { // Non-base64 errors should have been catched in the init handler - actionstream << "Server: User " << client->getName() - << " tried to log in, but srp verifier field" - << " was invalid (most likely invalid base64)." << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SERVER_FAIL); + actionstream << "Server: User " << client->getName() << + " tried to log in, but srp verifier field was invalid (most likely " + "invalid base64)." << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL); return; } @@ -1700,22 +1628,23 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) << " tried to log in, SRP-6a safety check violated in _A handler." << std::endl; if (wantSudo) { - DenySudoAccess(pkt->getPeerId()); + DenySudoAccess(peer_id); return; } - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA); + DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } - NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, pkt->getPeerId()); + NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, peer_id); resp_pkt << salt << std::string(bytes_B, len_B); Send(&resp_pkt); } void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) { - RemoteClient* client = getClient(pkt->getPeerId(), CS_Invalid); + session_t peer_id = pkt->getPeerId(); + RemoteClient *client = getClient(peer_id, CS_Invalid); ClientState cstate = client->getState(); bool wantSudo = (cstate == CS_Active); @@ -1723,25 +1652,24 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) verbosestream << "Server: Received TOCLIENT_SRP_BYTES_M." << std::endl; if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) { - actionstream << "Server: got SRP _M packet in wrong state " - << cstate << " from " - << getPeerAddress(pkt->getPeerId()).serializeString() - << ". Ignoring." << std::endl; + actionstream << "Server: got SRP _M packet in wrong state " << cstate << + " from " << getPeerAddress(peer_id).serializeString() << + ". Ignoring." << std::endl; return; } if (client->chosen_mech != AUTH_MECHANISM_SRP && client->chosen_mech != AUTH_MECHANISM_LEGACY_PASSWORD) { - actionstream << "Server: got SRP _M packet, while auth" - << "is going on with mech " << client->chosen_mech - << " from " << getPeerAddress(pkt->getPeerId()).serializeString() - << " (wantSudo=" << wantSudo << "). Denying." << std::endl; + actionstream << "Server: got SRP _M packet, while auth is going on " + "with mech " << client->chosen_mech << " from " << + getPeerAddress(peer_id).serializeString() << + " (wantSudo=" << wantSudo << "). Denying." << std::endl; if (wantSudo) { - DenySudoAccess(pkt->getPeerId()); + DenySudoAccess(peer_id); return; } - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA); + DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } @@ -1750,10 +1678,10 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) if (srp_verifier_get_session_key_length((SRPVerifier *) client->auth_data) != bytes_M.size()) { - actionstream << "Server: User " << client->getName() - << " at " << getPeerAddress(pkt->getPeerId()).serializeString() - << " sent bytes_M with invalid length " << bytes_M.size() << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA); + actionstream << "Server: User " << client->getName() << " at " << + getPeerAddress(peer_id).serializeString() << + " sent bytes_M with invalid length " << bytes_M.size() << std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } @@ -1764,21 +1692,19 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) if (!bytes_HAMK) { if (wantSudo) { - actionstream << "Server: User " << client->getName() - << " at " << getPeerAddress(pkt->getPeerId()).serializeString() - << " tried to change their password, but supplied wrong" - << " (SRP) password for authentication." << std::endl; - DenySudoAccess(pkt->getPeerId()); + actionstream << "Server: User " << client->getName() << " at " << + getPeerAddress(peer_id).serializeString() << + " tried to change their password, but supplied wrong (SRP) " + "password for authentication." << std::endl; + DenySudoAccess(peer_id); return; } - std::string ip = getPeerAddress(pkt->getPeerId()).serializeString(); - actionstream << "Server: User " << client->getName() - << " at " << ip - << " supplied wrong password (auth mechanism: SRP)." - << std::endl; + std::string ip = getPeerAddress(peer_id).serializeString(); + actionstream << "Server: User " << client->getName() << " at " << ip << + " supplied wrong password (auth mechanism: SRP)." << std::endl; m_script->on_auth_failure(client->getName(), ip); - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD); + DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_PASSWORD); return; } @@ -1788,15 +1714,16 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) std::string checkpwd; // not used, but needed for passing something if (!m_script->getAuth(playername, &checkpwd, NULL)) { - actionstream << "Server: " << playername << " cannot be authenticated" - << " (auth handler does not work?)" << std::endl; - DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SERVER_FAIL); + actionstream << "Server: " << playername << + " cannot be authenticated (auth handler does not work?)" << + std::endl; + DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL); return; } client->create_player_on_auth_success = false; } - acceptAuth(pkt->getPeerId(), wantSudo); + acceptAuth(peer_id, wantSudo); } /* @@ -1808,20 +1735,21 @@ void Server::handleCommand_ModChannelJoin(NetworkPacket *pkt) std::string channel_name; *pkt >> channel_name; - NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, 1 + 2 + channel_name.size(), - pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, + 1 + 2 + channel_name.size(), peer_id); // Send signal to client to notify join succeed or not if (g_settings->getBool("enable_mod_channels") && - m_modchannel_mgr->joinChannel(channel_name, pkt->getPeerId())) { + m_modchannel_mgr->joinChannel(channel_name, peer_id)) { resp_pkt << (u8) MODCHANNEL_SIGNAL_JOIN_OK; - infostream << "Peer " << pkt->getPeerId() << " joined channel " << channel_name - << std::endl; + infostream << "Peer " << peer_id << " joined channel " << + channel_name << std::endl; } else { resp_pkt << (u8)MODCHANNEL_SIGNAL_JOIN_FAILURE; - infostream << "Peer " << pkt->getPeerId() << " tried to join channel " - << channel_name << ", but was already registered." << std::endl; + infostream << "Peer " << peer_id << " tried to join channel " << + channel_name << ", but was already registered." << std::endl; } resp_pkt << channel_name; Send(&resp_pkt); @@ -1832,19 +1760,20 @@ void Server::handleCommand_ModChannelLeave(NetworkPacket *pkt) std::string channel_name; *pkt >> channel_name; - NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, 1 + 2 + channel_name.size(), - pkt->getPeerId()); + session_t peer_id = pkt->getPeerId(); + NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, + 1 + 2 + channel_name.size(), peer_id); // Send signal to client to notify join succeed or not if (g_settings->getBool("enable_mod_channels") && - m_modchannel_mgr->leaveChannel(channel_name, pkt->getPeerId())) { + m_modchannel_mgr->leaveChannel(channel_name, peer_id)) { resp_pkt << (u8)MODCHANNEL_SIGNAL_LEAVE_OK; - infostream << "Peer " << pkt->getPeerId() << " left channel " << channel_name - << std::endl; + infostream << "Peer " << peer_id << " left channel " << channel_name << + std::endl; } else { resp_pkt << (u8) MODCHANNEL_SIGNAL_LEAVE_FAILURE; - infostream << "Peer " << pkt->getPeerId() << " left channel " << channel_name - << ", but was not registered." << std::endl; + infostream << "Peer " << peer_id << " left channel " << channel_name << + ", but was not registered." << std::endl; } resp_pkt << channel_name; Send(&resp_pkt); @@ -1855,8 +1784,10 @@ void Server::handleCommand_ModChannelMsg(NetworkPacket *pkt) std::string channel_name, channel_msg; *pkt >> channel_name >> channel_msg; - verbosestream << "Mod channel message received from peer " << pkt->getPeerId() - << " on channel " << channel_name << " message: " << channel_msg << std::endl; + session_t peer_id = pkt->getPeerId(); + verbosestream << "Mod channel message received from peer " << peer_id << + " on channel " << channel_name << " message: " << channel_msg << + std::endl; // If mod channels are not enabled, discard message if (!g_settings->getBool("enable_mod_channels")) { @@ -1865,8 +1796,8 @@ void Server::handleCommand_ModChannelMsg(NetworkPacket *pkt) // If channel not registered, signal it and ignore message if (!m_modchannel_mgr->channelRegistered(channel_name)) { - NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, 1 + 2 + channel_name.size(), - pkt->getPeerId()); + NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_SIGNAL, + 1 + 2 + channel_name.size(), peer_id); resp_pkt << (u8)MODCHANNEL_SIGNAL_CHANNEL_NOT_REGISTERED << channel_name; Send(&resp_pkt); return; @@ -1874,5 +1805,5 @@ void Server::handleCommand_ModChannelMsg(NetworkPacket *pkt) // @TODO: filter, rate limit - broadcastModChannelMessage(channel_name, channel_msg, pkt->getPeerId()); + broadcastModChannelMessage(channel_name, channel_msg, peer_id); } diff --git a/src/server.h b/src/server.h index 680de57b5..eecc2c0f0 100644 --- a/src/server.h +++ b/src/server.h @@ -165,7 +165,6 @@ public: void handleCommand_InventoryAction(NetworkPacket* pkt); void handleCommand_ChatMessage(NetworkPacket* pkt); void handleCommand_Damage(NetworkPacket* pkt); - void handleCommand_Password(NetworkPacket* pkt); void handleCommand_PlayerItem(NetworkPacket* pkt); void handleCommand_Respawn(NetworkPacket* pkt); void handleCommand_Interact(NetworkPacket* pkt); -- cgit v1.2.3 From 241bf442608d27df0ce3c74889c357fb5589ab20 Mon Sep 17 00:00:00 2001 From: DS Date: Sat, 18 Apr 2020 17:20:20 +0200 Subject: Apply a scrollbar's default value to scroll containers (#9699) Fixes #9691. --- games/minimal/mods/test/formspec.lua | 2 +- src/gui/guiScrollContainer.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/games/minimal/mods/test/formspec.lua b/games/minimal/mods/test/formspec.lua index 53e92b243..4ab4f2717 100644 --- a/games/minimal/mods/test/formspec.lua +++ b/games/minimal/mods/test/formspec.lua @@ -251,7 +251,7 @@ Number] "box[1,22.5;4,1;#a00a]".. "scroll_container_end[]".. "scrollbaroptions[max=170]".. -- lowest seen pos is: 0.1*170+6=23 (factor*max+height) - "scrollbar[7.5,0;0.3,4;vertical;scrbar;0]".. + "scrollbar[7.5,0;0.3,4;vertical;scrbar;20]".. "scrollbar[8,0;0.3,4;vertical;scrbarhmmm;0]".. "dropdown[0,6;2;hmdrpdwnnn;apple,bulb;1]", } diff --git a/src/gui/guiScrollContainer.h b/src/gui/guiScrollContainer.h index 9eaa880bf..a0306291e 100644 --- a/src/gui/guiScrollContainer.h +++ b/src/gui/guiScrollContainer.h @@ -38,7 +38,11 @@ public: updateScrolling(); } - inline void setScrollBar(GUIScrollBar *scrollbar) { m_scrollbar = scrollbar; } + inline void setScrollBar(GUIScrollBar *scrollbar) + { + m_scrollbar = scrollbar; + updateScrolling(); + } private: enum OrientationEnum -- cgit v1.2.3 From 4fb6b6afa7329676166bbbccb897bd625155d038 Mon Sep 17 00:00:00 2001 From: DS Date: Sat, 18 Apr 2020 17:21:10 +0200 Subject: Formspec: allow lists to change size and existence while the formspec is open (#9700) Fixes #9640. --- src/gui/guiFormSpecMenu.cpp | 30 +----------------------------- src/gui/guiInventoryList.cpp | 42 +++++++++++++++++++++++++++++++----------- src/gui/guiInventoryList.h | 5 ++++- 3 files changed, 36 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index b0255cf1b..85ab2eb50 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -489,38 +489,10 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element) start_i = stoi(startindex); if (geom.X < 0 || geom.Y < 0 || start_i < 0) { - errorstream<< "Invalid list element: '" << element << "'" << std::endl; + errorstream << "Invalid list element: '" << element << "'" << std::endl; return; } - // check for the existence of inventory and list - Inventory *inv = m_invmgr->getInventory(loc); - if (!inv) { - warningstream << "GUIFormSpecMenu::parseList(): " - << "The inventory location " - << "\"" << loc.dump() << "\" doesn't exist" - << std::endl; - return; - } - InventoryList *ilist = inv->getList(listname); - if (!ilist) { - warningstream << "GUIFormSpecMenu::parseList(): " - << "The inventory list \"" << listname << "\" " - << "@ \"" << loc.dump() << "\" doesn't exist" - << std::endl; - return; - } - - // trim geom if it is larger than the actual inventory size - s32 list_size = (s32)ilist->getSize(); - if (list_size < geom.X * geom.Y + start_i) { - list_size -= MYMAX(start_i, 0); - geom.Y = list_size / geom.X; - geom.Y += list_size % geom.X > 0 ? 1 : 0; - if (geom.Y <= 1) - geom.X = list_size; - } - if (!data->explicit_size) warningstream << "invalid use of list without a size[] element" << std::endl; diff --git a/src/gui/guiInventoryList.cpp b/src/gui/guiInventoryList.cpp index 536471229..dfdb60448 100644 --- a/src/gui/guiInventoryList.cpp +++ b/src/gui/guiInventoryList.cpp @@ -47,7 +47,8 @@ GUIInventoryList::GUIInventoryList(gui::IGUIEnvironment *env, m_fs_menu(fs_menu), m_options(options), m_font(font), - m_hovered_i(-1) + m_hovered_i(-1), + m_already_warned(false) { } @@ -58,20 +59,27 @@ void GUIInventoryList::draw() Inventory *inv = m_invmgr->getInventory(m_inventoryloc); if (!inv) { - warningstream << "GUIInventoryList::draw(): " - << "The inventory location " - << "\"" << m_inventoryloc.dump() << "\" doesn't exist anymore" - << std::endl; + if (!m_already_warned) { + warningstream << "GUIInventoryList::draw(): " + << "The inventory location " + << "\"" << m_inventoryloc.dump() << "\" doesn't exist" + << std::endl; + m_already_warned = true; + } return; } InventoryList *ilist = inv->getList(m_listname); if (!ilist) { - warningstream << "GUIInventoryList::draw(): " - << "The inventory list \"" << m_listname << "\" @ \"" - << m_inventoryloc.dump() << "\" doesn't exist anymore" - << std::endl; + if (!m_already_warned) { + warningstream << "GUIInventoryList::draw(): " + << "The inventory list \"" << m_listname << "\" @ \"" + << m_inventoryloc.dump() << "\" doesn't exist" + << std::endl; + m_already_warned = true; + } return; } + m_already_warned = false; video::IVideoDriver *driver = Environment->getVideoDriver(); Client *client = m_fs_menu->getClient(); @@ -80,9 +88,11 @@ void GUIInventoryList::draw() core::rect imgrect(0, 0, m_slot_size.X, m_slot_size.Y); v2s32 base_pos = AbsoluteRect.UpperLeftCorner; + const s32 list_size = (s32)ilist->getSize(); + for (s32 i = 0; i < m_geom.X * m_geom.Y; i++) { s32 item_i = i + m_start_item_i; - if (item_i >= (s32)ilist->getSize()) + if (item_i >= list_size) break; v2s32 p((i % m_geom.X) * m_slot_spacing.X, @@ -192,10 +202,19 @@ bool GUIInventoryList::OnEvent(const SEvent &event) s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const { + // no item if no gui element at pointer if (!IsVisible || AbsoluteClippingRect.getArea() <= 0 || !AbsoluteClippingRect.isPointInside(p)) return -1; + // there can not be an item if the inventory or the inventorylist does not exist + Inventory *inv = m_invmgr->getInventory(m_inventoryloc); + if (!inv) + return -1; + InventoryList *ilist = inv->getList(m_listname); + if (!ilist) + return -1; + core::rect imgrect(0, 0, m_slot_size.X, m_slot_size.Y); v2s32 base_pos = AbsoluteRect.UpperLeftCorner; @@ -210,7 +229,8 @@ s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const rect.clipAgainst(AbsoluteClippingRect); - if (rect.getArea() > 0 && rect.isPointInside(p)) + if (rect.getArea() > 0 && rect.isPointInside(p) && + i + m_start_item_i < (s32)ilist->getSize()) return i + m_start_item_i; return -1; diff --git a/src/gui/guiInventoryList.h b/src/gui/guiInventoryList.h index fd2c3601b..28e95fbbf 100644 --- a/src/gui/guiInventoryList.h +++ b/src/gui/guiInventoryList.h @@ -107,7 +107,7 @@ private: const InventoryLocation m_inventoryloc; const std::string m_listname; - // specifies the width and height of the inventorylist in itemslots + // the specified width and height of the shown inventorylist in itemslots const v2s32 m_geom; // the first item's index in inventory const s32 m_start_item_i; @@ -127,4 +127,7 @@ private: // the index of the hovered item; -1 if no item is hovered s32 m_hovered_i; + + // we do not want to write a warning on every draw + bool m_already_warned; }; -- cgit v1.2.3 From 87829cd7446dd13d1dfd27d96e0b4aeb2f234e33 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 18 Apr 2020 17:21:58 +0200 Subject: script: Move SAO usability check so that it covers all functions (#9698) see also 91eef646a59575bd9ae792e257bb6ad12fafc0b1 --- src/script/lua_api/l_object.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index bb1456ac9..d7afb84da 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -50,6 +50,8 @@ ObjectRef* ObjectRef::checkobject(lua_State *L, int narg) ServerActiveObject* ObjectRef::getobject(ObjectRef *ref) { ServerActiveObject *co = ref->m_object; + if (co && co->isGone()) + return NULL; return co; } @@ -60,8 +62,6 @@ LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref) return NULL; if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY) return NULL; - if (obj->isGone()) - return NULL; return (LuaEntitySAO*)obj; } @@ -72,8 +72,6 @@ PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref) return NULL; if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER) return NULL; - if (obj->isGone()) - return NULL; return (PlayerSAO*)obj; } @@ -132,7 +130,6 @@ int ObjectRef::l_set_pos(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - //LuaEntitySAO *co = getluaobject(ref); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; // pos @@ -147,7 +144,6 @@ int ObjectRef::l_move_to(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - //LuaEntitySAO *co = getluaobject(ref); ServerActiveObject *co = getobject(ref); if (co == NULL) return 0; // pos @@ -1102,17 +1098,13 @@ int ObjectRef::l_add_player_velocity(lua_State *L) ObjectRef *ref = checkobject(L, 1); v3f vel = checkFloatPos(L, 2); - RemotePlayer *player = getplayer(ref); PlayerSAO *co = getplayersao(ref); - if (!player || !co) + if (!co) return 0; - session_t peer_id = player->getPeerId(); - if (peer_id == PEER_ID_INEXISTENT) - return 0; // Do it co->setMaxSpeedOverride(vel); - getServer(L)->SendPlayerSpeed(peer_id, vel); + getServer(L)->SendPlayerSpeed(co->getPeerID(), vel); return 0; } -- cgit v1.2.3 From cdbe3c5e5784b34e548c58b08579ff55b3096fb9 Mon Sep 17 00:00:00 2001 From: Danila Shutov Date: Sun, 19 Apr 2020 19:47:13 +0300 Subject: Reuse object_shader for "wielditem" and "item" entity drawtypes (#9537) --- client/shaders/wielded_shader/opengl_fragment.glsl | 127 --------------------- client/shaders/wielded_shader/opengl_vertex.glsl | 32 ------ src/client/camera.cpp | 2 +- src/client/content_cao.cpp | 9 +- src/client/wieldmesh.cpp | 17 ++- src/client/wieldmesh.h | 2 + 6 files changed, 24 insertions(+), 165 deletions(-) delete mode 100644 client/shaders/wielded_shader/opengl_fragment.glsl delete mode 100644 client/shaders/wielded_shader/opengl_vertex.glsl (limited to 'src') diff --git a/client/shaders/wielded_shader/opengl_fragment.glsl b/client/shaders/wielded_shader/opengl_fragment.glsl deleted file mode 100644 index 546aef71d..000000000 --- a/client/shaders/wielded_shader/opengl_fragment.glsl +++ /dev/null @@ -1,127 +0,0 @@ -uniform sampler2D baseTexture; -uniform sampler2D normalTexture; -uniform sampler2D textureFlags; - -uniform vec4 skyBgColor; -uniform float fogDistance; -uniform vec3 eyePosition; - -varying vec3 vPosition; -varying vec3 worldPosition; - -varying vec3 eyeVec; -varying vec3 lightVec; - -bool normalTexturePresent = false; -bool texTileableHorizontal = false; -bool texTileableVertical = false; -bool texSeamless = false; - -const float e = 2.718281828459; -const float BS = 10.0; -const float fogStart = FOG_START; -const float fogShadingParameter = 1 / ( 1 - fogStart); - -void get_texture_flags() -{ - vec4 flags = texture2D(textureFlags, vec2(0.0, 0.0)); - if (flags.r > 0.5) { - normalTexturePresent = true; - } - if (flags.g > 0.5) { - texTileableHorizontal = true; - } - if (flags.b > 0.5) { - texTileableVertical = true; - } - if (texTileableHorizontal && texTileableVertical) { - texSeamless = true; - } -} - -float intensity(vec3 color) -{ - return (color.r + color.g + color.b) / 3.0; -} - -float get_rgb_height(vec2 uv) -{ - if (texSeamless) { - return intensity(texture2D(baseTexture, uv).rgb); - } else { - return intensity(texture2D(baseTexture, clamp(uv, 0.0, 0.999)).rgb); - } -} - -vec4 get_normal_map(vec2 uv) -{ - vec4 bump = texture2D(normalTexture, uv).rgba; - bump.xyz = normalize(bump.xyz * 2.0 - 1.0); - return bump; -} - -void main(void) -{ - vec3 color; - vec4 bump; - vec2 uv = gl_TexCoord[0].st; - bool use_normalmap = false; - get_texture_flags(); - -#if USE_NORMALMAPS == 1 - if (normalTexturePresent) { - bump = get_normal_map(uv); - use_normalmap = true; - } -#endif - -#if GENERATE_NORMALMAPS == 1 - if (normalTexturePresent == false) { - float tl = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y + SAMPLE_STEP)); - float t = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y - SAMPLE_STEP)); - float tr = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y + SAMPLE_STEP)); - float r = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y)); - float br = get_rgb_height(vec2(uv.x + SAMPLE_STEP, uv.y - SAMPLE_STEP)); - float b = get_rgb_height(vec2(uv.x, uv.y - SAMPLE_STEP)); - float bl = get_rgb_height(vec2(uv.x -SAMPLE_STEP, uv.y - SAMPLE_STEP)); - float l = get_rgb_height(vec2(uv.x - SAMPLE_STEP, uv.y)); - float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl); - float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr); - bump = vec4(normalize(vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0); - use_normalmap = true; - } -#endif - - vec4 base = texture2D(baseTexture, uv).rgba; - -#ifdef ENABLE_BUMPMAPPING - if (use_normalmap) { - vec3 L = normalize(lightVec); - vec3 E = normalize(eyeVec); - float specular = pow(clamp(dot(reflect(L, bump.xyz), E), 0.0, 1.0), 1.0); - float diffuse = dot(-E,bump.xyz); - color = (diffuse + 0.1 * specular) * base.rgb; - } else { - color = base.rgb; - } -#else - color = base.rgb; -#endif - - vec4 col = vec4(color.rgb, base.a); - col *= gl_Color; - // Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?), - // the fog will only be rendered correctly if the last operation before the - // clamp() is an addition. Else, the clamp() seems to be ignored. - // E.g. the following won't work: - // float clarity = clamp(fogShadingParameter - // * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0); - // As additions usually come for free following a multiplication, the new formula - // should be more efficient as well. - // Note: clarity = (1 - fogginess) - float clarity = clamp(fogShadingParameter - - fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0); - col = mix(skyBgColor, col, clarity); - - gl_FragColor = vec4(col.rgb, base.a); -} diff --git a/client/shaders/wielded_shader/opengl_vertex.glsl b/client/shaders/wielded_shader/opengl_vertex.glsl deleted file mode 100644 index 9f05b833a..000000000 --- a/client/shaders/wielded_shader/opengl_vertex.glsl +++ /dev/null @@ -1,32 +0,0 @@ -uniform mat4 mWorldViewProj; -uniform mat4 mWorld; - -uniform vec3 eyePosition; -uniform float animationTimer; - -varying vec3 vPosition; -varying vec3 worldPosition; - -varying vec3 eyeVec; -varying vec3 lightVec; -varying vec3 tsEyeVec; -varying vec3 tsLightVec; - -const float e = 2.718281828459; -const float BS = 10.0; - -void main(void) -{ - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_Position = mWorldViewProj * gl_Vertex; - - vPosition = gl_Position.xyz; - worldPosition = (mWorld * gl_Vertex).xyz; - - vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0); - - lightVec = sunPosition - worldPosition; - eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; - - gl_FrontColor = gl_BackColor = gl_Color; -} diff --git a/src/client/camera.cpp b/src/client/camera.cpp index fb1c3ff56..69bd82a47 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -542,7 +542,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r m_wieldnode->setPosition(wield_position); m_wieldnode->setRotation(wield_rotation); - m_wieldnode->setColor(player->light_color); + m_wieldnode->setNodeLightColor(player->light_color); // Set render distance updateViewingRange(); diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 39ea4ab1e..e9e1cebd3 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -826,11 +826,12 @@ void GenericCAO::setNodeLight(u8 light) video::SColor color(255, light, light, light); if (m_prop.visual == "wielditem" || m_prop.visual == "item") { - // Since these types of visuals are using their own shader - // they should be handled separately if (m_wield_meshnode) - m_wield_meshnode->setColor(color); - } else if (m_enable_shaders) { + m_wield_meshnode->setNodeLightColor(color); + return; + } + + if (m_enable_shaders) { scene::ISceneNode *node = getSceneNode(); if (node == nullptr) diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index 2c6807fab..997eb1b5b 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -347,7 +347,7 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool che scene::SMesh *mesh = nullptr; if (m_enable_shaders) { - u32 shader_id = shdrsrc->getShader("wielded_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); + u32 shader_id = shdrsrc->getShader("object_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); m_material_type = shdrsrc->getShaderInfo(shader_id).material; } @@ -471,6 +471,21 @@ void WieldMeshSceneNode::setColor(video::SColor c) } } +void WieldMeshSceneNode::setNodeLightColor(video::SColor color) +{ + if (!m_meshnode) + return; + + if (m_enable_shaders) { + for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) { + video::SMaterial &material = m_meshnode->getMaterial(i); + material.EmissiveColor = color; + } + } else { + setColor(color); + } +} + void WieldMeshSceneNode::render() { // note: if this method is changed to actually do something, diff --git a/src/client/wieldmesh.h b/src/client/wieldmesh.h index 7c80a811b..933097230 100644 --- a/src/client/wieldmesh.h +++ b/src/client/wieldmesh.h @@ -87,6 +87,8 @@ public: // Must only be used if the constructor was called with lighting = false void setColor(video::SColor color); + void setNodeLightColor(video::SColor color); + scene::IMesh *getMesh() { return m_meshnode->getMesh(); } virtual void render(); -- cgit v1.2.3 From 338195ff250bd7552ef8167348de2eb05e421c29 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 19 Apr 2020 19:07:54 +0200 Subject: Fix alias handling of get_content_id (#9712) fixes #9632 --- src/itemdef.cpp | 34 +++++++++++++--------------------- src/script/lua_api/l_item.cpp | 13 ++++++++++++- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/itemdef.cpp b/src/itemdef.cpp index a13b3f7d4..8e0492827 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -270,17 +270,16 @@ public: // Convert name according to possible alias std::string name = getAlias(name_); // Get the definition - std::map::const_iterator i; - i = m_item_definitions.find(name); - if(i == m_item_definitions.end()) + auto i = m_item_definitions.find(name); + if (i == m_item_definitions.cend()) i = m_item_definitions.find("unknown"); - assert(i != m_item_definitions.end()); + assert(i != m_item_definitions.cend()); return *(i->second); } virtual const std::string &getAlias(const std::string &name) const { - StringMap::const_iterator it = m_aliases.find(name); - if (it != m_aliases.end()) + auto it = m_aliases.find(name); + if (it != m_aliases.cend()) return it->second; return name; } @@ -300,8 +299,7 @@ public: // Convert name according to possible alias std::string name = getAlias(name_); // Get the definition - std::map::const_iterator i; - return m_item_definitions.find(name) != m_item_definitions.end(); + return m_item_definitions.find(name) != m_item_definitions.cend(); } #ifndef SERVER public: @@ -443,11 +441,9 @@ public: } void clear() { - for(std::map::const_iterator - i = m_item_definitions.begin(); - i != m_item_definitions.end(); ++i) + for (auto &i : m_item_definitions) { - delete i->second; + delete i.second; } m_item_definitions.clear(); m_aliases.clear(); @@ -520,10 +516,8 @@ public: u16 count = m_item_definitions.size(); writeU16(os, count); - for (std::map::const_iterator - it = m_item_definitions.begin(); - it != m_item_definitions.end(); ++it) { - ItemDefinition *def = it->second; + for (const auto &it : m_item_definitions) { + ItemDefinition *def = it.second; // Serialize ItemDefinition and write wrapped in a string std::ostringstream tmp_os(std::ios::binary); def->serialize(tmp_os, protocol_version); @@ -532,11 +526,9 @@ public: writeU16(os, m_aliases.size()); - for (StringMap::const_iterator - it = m_aliases.begin(); - it != m_aliases.end(); ++it) { - os << serializeString(it->first); - os << serializeString(it->second); + for (const auto &it : m_aliases) { + os << serializeString(it.first); + os << serializeString(it.second); } } void deSerialize(std::istream &is) diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 9f12d3ac7..0a403acbd 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -609,10 +609,21 @@ int ModApiItemMod::l_get_content_id(lua_State *L) NO_MAP_LOCK_REQUIRED; std::string name = luaL_checkstring(L, 1); + const IItemDefManager *idef = getGameDef(L)->getItemDefManager(); const NodeDefManager *ndef = getGameDef(L)->getNodeDefManager(); + + // If this is called at mod load time, NodeDefManager isn't aware of + // aliases yet, so we need to handle them manually + std::string alias_name = idef->getAlias(name); + content_t content_id; - if (!ndef->getId(name, content_id)) + if (alias_name != name) { + if (!ndef->getId(alias_name, content_id)) + throw LuaError("Unknown node: " + alias_name + + " (from alias " + name + ")"); + } else if (!ndef->getId(name, content_id)) { throw LuaError("Unknown node: " + name); + } lua_pushinteger(L, content_id); return 1; /* number of results */ -- cgit v1.2.3 From 8ef239b448c52485cf94d334c1d8b1c6de37d976 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 20 Apr 2020 23:22:00 +0200 Subject: Improve protocol-level receiving code (#9617) --- src/network/connection.cpp | 4 +- src/network/connectionthreads.cpp | 250 +++++++++++++++++++------------------- src/network/connectionthreads.h | 2 +- 3 files changed, 126 insertions(+), 130 deletions(-) (limited to 'src') diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 15eda7725..3692e45a9 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -1173,7 +1173,9 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout, m_bc_peerhandler(peerhandler) { - m_udpSocket.setTimeoutMs(5); + /* Amount of time Receive() will wait for data, this is entirely different + * from the connection timeout */ + m_udpSocket.setTimeoutMs(500); m_sendThread->setParent(this); m_receiveThread->setParent(this); diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index 13d82e06d..1f33d2ded 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -812,6 +812,14 @@ void *ConnectionReceiveThread::run() ThreadIdentifier); PROFILE(ThreadIdentifier << "ConnectionReceive: [" << m_connection->getDesc() << "]"); + // use IPv6 minimum allowed MTU as receive buffer size as this is + // theoretical reliable upper boundary of a udp packet for all IPv6 enabled + // infrastructure + const unsigned int packet_maxsize = 1500; + SharedBuffer packetdata(packet_maxsize); + + bool packet_queued = true; + #ifdef DEBUG_CONNECTION_KBPS u64 curtime = porting::getTimeMs(); u64 lasttime = curtime; @@ -830,7 +838,7 @@ void *ConnectionReceiveThread::run() #endif /* receive packets */ - receive(); + receive(packetdata, packet_queued); #ifdef DEBUG_CONNECTION_KBPS debug_print_timer += dtime; @@ -892,157 +900,142 @@ void *ConnectionReceiveThread::run() } // Receive packets from the network and buffers and create ConnectionEvents -void ConnectionReceiveThread::receive() +void ConnectionReceiveThread::receive(SharedBuffer &packetdata, + bool &packet_queued) { - // use IPv6 minimum allowed MTU as receive buffer size as this is - // theoretical reliable upper boundary of a udp packet for all IPv6 enabled - // infrastructure - unsigned int packet_maxsize = 1500; - SharedBuffer packetdata(packet_maxsize); - - bool packet_queued = true; - - unsigned int loop_count = 0; - - /* first of all read packets from socket */ - /* check for incoming data available */ - while ((loop_count < 10) && - (m_connection->m_udpSocket.WaitData(50))) { - loop_count++; - try { - if (packet_queued) { - bool data_left = true; - session_t peer_id; - SharedBuffer resultdata; - while (data_left) { - try { - data_left = getFromBuffers(peer_id, resultdata); - if (data_left) { - ConnectionEvent e; - e.dataReceived(peer_id, resultdata); - m_connection->putEvent(e); - } - } - catch (ProcessedSilentlyException &e) { - /* try reading again */ + try { + // First, see if there any buffered packets we can process now + if (packet_queued) { + bool data_left = true; + session_t peer_id; + SharedBuffer resultdata; + while (data_left) { + try { + data_left = getFromBuffers(peer_id, resultdata); + if (data_left) { + ConnectionEvent e; + e.dataReceived(peer_id, resultdata); + m_connection->putEvent(e); } } - packet_queued = false; - } - - Address sender; - s32 received_size = m_connection->m_udpSocket.Receive(sender, *packetdata, - packet_maxsize); - - if ((received_size < BASE_HEADER_SIZE) || - (readU32(&packetdata[0]) != m_connection->GetProtocolID())) { - LOG(derr_con << m_connection->getDesc() - << "Receive(): Invalid incoming packet, " - << "size: " << received_size - << ", protocol: " - << ((received_size >= 4) ? readU32(&packetdata[0]) : -1) - << std::endl); - continue; + catch (ProcessedSilentlyException &e) { + /* try reading again */ + } } + packet_queued = false; + } - session_t peer_id = readPeerId(*packetdata); - u8 channelnum = readChannel(*packetdata); + // Call Receive() to wait for incoming data + Address sender; + s32 received_size = m_connection->m_udpSocket.Receive(sender, + *packetdata, packetdata.getSize()); + if (received_size < 0) + return; - if (channelnum > CHANNEL_COUNT - 1) { - LOG(derr_con << m_connection->getDesc() - << "Receive(): Invalid channel " << (u32)channelnum << std::endl); - throw InvalidIncomingDataException("Channel doesn't exist"); - } + if ((received_size < BASE_HEADER_SIZE) || + (readU32(&packetdata[0]) != m_connection->GetProtocolID())) { + LOG(derr_con << m_connection->getDesc() + << "Receive(): Invalid incoming packet, " + << "size: " << received_size + << ", protocol: " + << ((received_size >= 4) ? readU32(&packetdata[0]) : -1) + << std::endl); + return; + } - /* Try to identify peer by sender address (may happen on join) */ - if (peer_id == PEER_ID_INEXISTENT) { - peer_id = m_connection->lookupPeer(sender); - // We do not have to remind the peer of its - // peer id as the CONTROLTYPE_SET_PEER_ID - // command was sent reliably. - } + session_t peer_id = readPeerId(*packetdata); + u8 channelnum = readChannel(*packetdata); - /* The peer was not found in our lists. Add it. */ - if (peer_id == PEER_ID_INEXISTENT) { - peer_id = m_connection->createPeer(sender, MTP_MINETEST_RELIABLE_UDP, 0); - } + if (channelnum > CHANNEL_COUNT - 1) { + LOG(derr_con << m_connection->getDesc() + << "Receive(): Invalid channel " << (u32)channelnum << std::endl); + return; + } - PeerHelper peer = m_connection->getPeerNoEx(peer_id); + /* Try to identify peer by sender address (may happen on join) */ + if (peer_id == PEER_ID_INEXISTENT) { + peer_id = m_connection->lookupPeer(sender); + // We do not have to remind the peer of its + // peer id as the CONTROLTYPE_SET_PEER_ID + // command was sent reliably. + } - if (!peer) { - LOG(dout_con << m_connection->getDesc() - << " got packet from unknown peer_id: " - << peer_id << " Ignoring." << std::endl); - continue; - } + /* The peer was not found in our lists. Add it. */ + if (peer_id == PEER_ID_INEXISTENT) { + peer_id = m_connection->createPeer(sender, MTP_MINETEST_RELIABLE_UDP, 0); + } - // Validate peer address + PeerHelper peer = m_connection->getPeerNoEx(peer_id); + if (!peer) { + LOG(dout_con << m_connection->getDesc() + << " got packet from unknown peer_id: " + << peer_id << " Ignoring." << std::endl); + return; + } - Address peer_address; + // Validate peer address - if (peer->getAddress(MTP_UDP, peer_address)) { - if (peer_address != sender) { - LOG(derr_con << m_connection->getDesc() - << m_connection->getDesc() - << " Peer " << peer_id << " sending from different address." - " Ignoring." << std::endl); - continue; - } - } else { - - bool invalid_address = true; - if (invalid_address) { - LOG(derr_con << m_connection->getDesc() - << m_connection->getDesc() - << " Peer " << peer_id << " unknown." - " Ignoring." << std::endl); - continue; - } + Address peer_address; + if (peer->getAddress(MTP_UDP, peer_address)) { + if (peer_address != sender) { + LOG(derr_con << m_connection->getDesc() + << " Peer " << peer_id << " sending from different address." + " Ignoring." << std::endl); + return; } + } else { + LOG(derr_con << m_connection->getDesc() + << " Peer " << peer_id << " doesn't have an address?!" + " Ignoring." << std::endl); + return; + } - peer->ResetTimeout(); - - Channel *channel = 0; + peer->ResetTimeout(); - if (dynamic_cast(&peer) != 0) { - channel = &(dynamic_cast(&peer)->channels[channelnum]); - } + Channel *channel = nullptr; + if (dynamic_cast(&peer)) { + channel = &dynamic_cast(&peer)->channels[channelnum]; + } else { + LOG(derr_con << m_connection->getDesc() + << "Receive(): peer_id=" << peer_id << " isn't an UDPPeer?!" + " Ignoring." << std::endl); + return; + } - if (channel != 0) { - channel->UpdateBytesReceived(received_size); - } + channel->UpdateBytesReceived(received_size); - // Throw the received packet to channel->processPacket() + // Throw the received packet to channel->processPacket() - // Make a new SharedBuffer from the data without the base headers - SharedBuffer strippeddata(received_size - BASE_HEADER_SIZE); - memcpy(*strippeddata, &packetdata[BASE_HEADER_SIZE], - strippeddata.getSize()); + // Make a new SharedBuffer from the data without the base headers + SharedBuffer strippeddata(received_size - BASE_HEADER_SIZE); + memcpy(*strippeddata, &packetdata[BASE_HEADER_SIZE], + strippeddata.getSize()); - try { - // Process it (the result is some data with no headers made by us) - SharedBuffer resultdata = processPacket - (channel, strippeddata, peer_id, channelnum, false); + try { + // Process it (the result is some data with no headers made by us) + SharedBuffer resultdata = processPacket + (channel, strippeddata, peer_id, channelnum, false); - LOG(dout_con << m_connection->getDesc() - << " ProcessPacket from peer_id: " << peer_id - << ", channel: " << (u32)channelnum << ", returned " - << resultdata.getSize() << " bytes" << std::endl); + LOG(dout_con << m_connection->getDesc() + << " ProcessPacket from peer_id: " << peer_id + << ", channel: " << (u32)channelnum << ", returned " + << resultdata.getSize() << " bytes" << std::endl); - ConnectionEvent e; - e.dataReceived(peer_id, resultdata); - m_connection->putEvent(e); - } - catch (ProcessedSilentlyException &e) { - } - catch (ProcessedQueued &e) { - packet_queued = true; - } - } - catch (InvalidIncomingDataException &e) { + ConnectionEvent e; + e.dataReceived(peer_id, resultdata); + m_connection->putEvent(e); } catch (ProcessedSilentlyException &e) { } + catch (ProcessedQueued &e) { + // we set it to true anyway (see below) + } + + /* Every time we receive a packet it can happen that a previously + * buffered packet is now ready to process. */ + packet_queued = true; + } + catch (InvalidIncomingDataException &e) { } } @@ -1189,7 +1182,8 @@ SharedBuffer ConnectionReceiveThread::handlePacketType_Control(Channel *chan m_connection->TriggerSend(); } catch (NotFoundException &e) { LOG(derr_con << m_connection->getDesc() - << "WARNING: ACKed packet not in outgoing queue" << std::endl); + << "WARNING: ACKed packet not in outgoing queue" + << " seqnum=" << seqnum << std::endl); channel->UpdatePacketTooLateCounter(); } diff --git a/src/network/connectionthreads.h b/src/network/connectionthreads.h index da4ea92f5..612407c3b 100644 --- a/src/network/connectionthreads.h +++ b/src/network/connectionthreads.h @@ -101,7 +101,7 @@ public: } private: - void receive(); + void receive(SharedBuffer &packetdata, bool &packet_queued); // Returns next data from a buffer if possible // If found, returns true; if not, false. -- cgit v1.2.3 From 4361bfcb4da0b6f9de74c7de9f2d08084877713e Mon Sep 17 00:00:00 2001 From: HybridDog <3192173+HybridDog@users.noreply.github.com> Date: Wed, 22 Apr 2020 00:07:12 +0200 Subject: Fix configuration caching in log_deprecated (#9697) * Fix configuration caching in log_deprecated The configured variable was never set to true. I've set the variables to thread_local because the configuration should be reloaded after reentering the world from mainmenu. --- src/script/common/c_internal.cpp | 9 +++++---- src/script/lua_api/l_util.cpp | 2 +- src/script/lua_api/l_util.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp index b19af9f82..6df1f8b7b 100644 --- a/src/script/common/c_internal.cpp +++ b/src/script/common/c_internal.cpp @@ -157,9 +157,9 @@ static void script_log(lua_State *L, const std::string &message, void log_deprecated(lua_State *L, const std::string &message, int stack_depth) { - static bool configured = false; - static bool do_log = false; - static bool do_error = false; + static thread_local bool configured = false; + static thread_local bool do_log = false; + static thread_local bool do_error = false; // Only read settings on first call if (!configured) { @@ -167,9 +167,10 @@ void log_deprecated(lua_State *L, const std::string &message, int stack_depth) if (value == "log") { do_log = true; } else if (value == "error") { - do_log = true; + do_log = true; do_error = true; } + configured = true; } if (do_log) diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index ae3e5df3d..28ee39fc8 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -44,7 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // log([level,] text) // Writes a line to the logger. -// The one-argument version logs to infostream. +// The one-argument version logs to LL_NONE. // The two-argument version accepts a log level. // Either the special case "deprecated" for deprecation notices, or any specified in // Logger::stringToLevel(name). diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h index 5697aab15..9ff91bb53 100644 --- a/src/script/lua_api/l_util.h +++ b/src/script/lua_api/l_util.h @@ -37,7 +37,7 @@ private: // log([level,] text) // Writes a line to the logger. - // The one-argument version logs to infostream. + // The one-argument version logs to LL_NONE. // The two-argument version accepts a log level. static int l_log(lua_State *L); -- cgit v1.2.3 From 6ba44d74526031a07bbc5093b708b8b99a27456a Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 22 Apr 2020 20:03:46 +0200 Subject: Android: add OpenGL ES 2 support (#9715) .. and bump gradle to 3.6.3 --- build/android/app/build.gradle | 9 ++++++--- build/android/build.gradle | 2 +- src/client/renderingengine.cpp | 7 ++----- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/build/android/app/build.gradle b/build/android/app/build.gradle index 6a34a6d70..9d14cdab8 100644 --- a/build/android/app/build.gradle +++ b/build/android/app/build.gradle @@ -63,8 +63,12 @@ task prepareAssets() { copy { from "${projRoot}/builtin" into "${assetsFolder}/builtin" } - copy { + /*copy { + // ToDo: fix Minetest shaders that currently don't work with OpenGL ES from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders" + }*/ + copy { + from "../native/deps/Android/Irrlicht/shaders" into "${assetsFolder}/client/shaders/Irrlicht" } copy { from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts" @@ -73,8 +77,7 @@ task prepareAssets() { from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}" } /*copy { - // locales broken right now - // ToDo: fix it! + // ToDo: fix broken locales from "${projRoot}/po" into "${assetsFolder}/po" }*/ copy { diff --git a/build/android/build.gradle b/build/android/build.gradle index b02e8c6df..c4de09bf8 100644 --- a/build/android/build.gradle +++ b/build/android/build.gradle @@ -15,7 +15,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.2' + classpath 'com.android.tools.build:gradle:3.6.3' classpath 'org.ajoberstar.grgit:grgit-gradle:4.0.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index eae6ca7d3..f5aca8f58 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -130,12 +130,9 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu"); params.ZBufferBits = 24; #ifdef __ANDROID__ - // clang-format off params.PrivateData = porting::app_global; - params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM + "media" + - DIR_DELIM + "Shaders" + DIR_DELIM).c_str(); - // clang-format on -#elif ENABLE_GLES +#endif +#if ENABLE_GLES // there is no standardized path for these on desktop std::string rel_path = std::string("client") + DIR_DELIM + "shaders" + DIR_DELIM + "Irrlicht"; -- cgit v1.2.3 From ce5b0932f8e17244bd6c1e307f1fce76b16e6474 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 23 Apr 2020 12:16:36 +0200 Subject: Camera: Fix shootline line offsets II (#9730) --- src/client/game.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index 4b2d7c652..3429cc57b 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3029,7 +3029,6 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) { LocalPlayer *player = client->getEnv().getLocalPlayer(); - const v3f head_position = camera->getHeadPosition(); const v3f camera_direction = camera->getDirection(); const v3s16 camera_offset = camera->getOffset(); @@ -3045,13 +3044,22 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) core::line3d shootline; - if (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT) { - shootline = core::line3d(head_position, - head_position + camera_direction * BS * d); - } else { + switch (camera->getCameraMode()) { + case CAMERA_MODE_FIRST: + // Shoot from camera position, with bobbing + shootline.start = camera->getPosition(); + break; + case CAMERA_MODE_THIRD: + // Shoot from player head, no bobbing + shootline.start = camera->getHeadPosition(); + break; + case CAMERA_MODE_THIRD_FRONT: + shootline.start = camera->getHeadPosition(); // prevent player pointing anything in front-view - shootline = core::line3d(head_position, head_position); + d = 0; + break; } + shootline.end = shootline.start + camera_direction * BS * d; #ifdef HAVE_TOUCHSCREENGUI -- cgit v1.2.3 From 914dbeaa0be4b5ef87506b605ef4e241cd3732dc Mon Sep 17 00:00:00 2001 From: luk3yx Date: Thu, 23 Apr 2020 23:07:19 +1200 Subject: Add LevelDB auth database. (#9476) * Add leveldb auth database. --- src/database/database-leveldb.cpp | 98 ++++++++++++++++++++++++++++++++++++++- src/database/database-leveldb.h | 17 +++++++ src/serverenvironment.cpp | 8 ++++ 3 files changed, 122 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/database/database-leveldb.cpp b/src/database/database-leveldb.cpp index 4a4904c6a..1aab4c43d 100644 --- a/src/database/database-leveldb.cpp +++ b/src/database/database-leveldb.cpp @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "filesys.h" #include "exceptions.h" +#include "util/serialize.h" #include "util/string.h" #include "leveldb/db.h" @@ -97,5 +98,100 @@ void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) delete it; } -#endif // USE_LEVELDB +AuthDatabaseLevelDB::AuthDatabaseLevelDB(const std::string &savedir) +{ + leveldb::Options options; + options.create_if_missing = true; + leveldb::Status status = leveldb::DB::Open(options, + savedir + DIR_DELIM + "auth.db", &m_database); + ENSURE_STATUS_OK(status); +} + +AuthDatabaseLevelDB::~AuthDatabaseLevelDB() +{ + delete m_database; +} + +bool AuthDatabaseLevelDB::getAuth(const std::string &name, AuthEntry &res) +{ + std::string raw; + leveldb::Status s = m_database->Get(leveldb::ReadOptions(), name, &raw); + if (!s.ok()) + return false; + std::istringstream is(raw); + + /* + u8 version = 1 + std::string password + u16 number of privileges + for each privilege { + std::string privilege + } + s64 last_login + */ + + if (readU8(is) > 1) + return false; + + res.id = 1; + res.name = name; + res.password = deSerializeString(is); + + u16 privilege_count = readU16(is); + res.privileges.clear(); + res.privileges.reserve(privilege_count); + for (u16 i = 0; i < privilege_count; i++) { + res.privileges.push_back(deSerializeString(is)); + } + + res.last_login = readS64(is); + return true; +} +bool AuthDatabaseLevelDB::saveAuth(const AuthEntry &authEntry) +{ + std::ostringstream os; + writeU8(os, 1); + os << serializeString(authEntry.password); + + size_t privilege_count = authEntry.privileges.size(); + FATAL_ERROR_IF(privilege_count > U16_MAX, + "Unsupported number of privileges"); + writeU16(os, privilege_count); + for (const std::string &privilege : authEntry.privileges) { + os << serializeString(privilege); + } + + writeS64(os, authEntry.last_login); + leveldb::Status s = m_database->Put(leveldb::WriteOptions(), + authEntry.name, os.str()); + return s.ok(); +} + +bool AuthDatabaseLevelDB::createAuth(AuthEntry &authEntry) +{ + return saveAuth(authEntry); +} + +bool AuthDatabaseLevelDB::deleteAuth(const std::string &name) +{ + leveldb::Status s = m_database->Delete(leveldb::WriteOptions(), name); + return s.ok(); +} + +void AuthDatabaseLevelDB::listNames(std::vector &res) +{ + leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions()); + res.clear(); + for (it->SeekToFirst(); it->Valid(); it->Next()) { + res.emplace_back(it->key().ToString()); + } + delete it; +} + +void AuthDatabaseLevelDB::reload() +{ + // No-op for LevelDB. +} + +#endif // USE_LEVELDB diff --git a/src/database/database-leveldb.h b/src/database/database-leveldb.h index d30f9f8f5..a9bd0faa4 100644 --- a/src/database/database-leveldb.h +++ b/src/database/database-leveldb.h @@ -45,4 +45,21 @@ private: leveldb::DB *m_database; }; +class AuthDatabaseLevelDB : public AuthDatabase +{ +public: + AuthDatabaseLevelDB(const std::string &savedir); + virtual ~AuthDatabaseLevelDB(); + + virtual bool getAuth(const std::string &name, AuthEntry &res); + virtual bool saveAuth(const AuthEntry &authEntry); + virtual bool createAuth(AuthEntry &authEntry); + virtual bool deleteAuth(const std::string &name); + virtual void listNames(std::vector &res); + virtual void reload(); + +private: + leveldb::DB *m_database; +}; + #endif // USE_LEVELDB diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 27f0c1e3d..08d796118 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -44,6 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #if USE_POSTGRESQL #include "database/database-postgresql.h" #endif +#if USE_LEVELDB +#include "database/database-leveldb.h" +#endif #include "server/luaentity_sao.h" #include "server/player_sao.h" @@ -2187,6 +2190,11 @@ AuthDatabase *ServerEnvironment::openAuthDatabase( if (name == "files") return new AuthDatabaseFiles(savedir); +#if USE_LEVELDB + if (name == "leveldb") + return new AuthDatabaseLevelDB(savedir); +#endif + throw BaseException(std::string("Database backend ") + name + " not supported."); } -- cgit v1.2.3 From cee3c5e73d7af2a876aa76275234ee76e7cb1bbc Mon Sep 17 00:00:00 2001 From: EvidenceB Kidscode <49488517+EvidenceBKidscode@users.noreply.github.com> Date: Sat, 25 Apr 2020 07:20:00 +0200 Subject: Add server side translations capability (#9733) * Add server side translations capability --- doc/lua_api.txt | 15 ++++++++++++++ src/client/client.cpp | 2 +- src/client/game.cpp | 2 +- src/clientiface.h | 6 ++++++ src/network/serverpackethandler.cpp | 3 +++ src/script/lua_api/l_env.cpp | 16 +++++++++++++++ src/script/lua_api/l_env.h | 3 +++ src/script/lua_api/l_server.cpp | 7 ++++++- src/server.cpp | 22 +++++++++++++++++++- src/server.h | 5 ++++- src/translation.cpp | 13 ++++++++++-- src/translation.h | 5 ++++- src/util/string.cpp | 41 ++++++++++++++++++++++++++++--------- src/util/string.h | 4 ++++ 14 files changed, 126 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 77f06682f..3ca32649a 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -3176,8 +3176,22 @@ Strings that need to be translated can contain several escapes, preceded by `@`. `minetest.translate`, but is in translation files. * `@n` acts as a literal newline as well. +Server side translations +------------------------ + +On some specific cases, server translation could be useful. For example, filter +a list on labels and send results to client. A method is supplied to achieve +that: + +`minetest.get_translated_string(lang_code, string)`: Translates `string` using +translations for `lang_code` language. It gives the same result as if the string +was translated by the client. +The `lang_code` to use for a given player can be retrieved from +the table returned by `minetest.get_player_information(name)`. +IMPORTANT: This functionality should only be used for sorting, filtering or similar purposes. +You do not need to use this to get translated strings to show up on the client. Perlin noise ============ @@ -4153,6 +4167,7 @@ Utilities connection_uptime = 200, -- seconds since client connected protocol_version = 32, -- protocol version used by client formspec_version = 2, -- supported formspec version + lang_code = "fr" -- Language code used for translation -- following information is available on debug build only!!! -- DO NOT USE IN MODS --ser_vers = 26, -- serialization version used by client diff --git a/src/client/client.cpp b/src/client/client.cpp index 8ee0869cd..941fc203d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -736,7 +736,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) if (!name.empty()) { TRACESTREAM(<< "Client: Loading translation: " << "\"" << filename << "\"" << std::endl); - g_translations->loadTranslation(data); + g_client_translations->loadTranslation(data); return true; } diff --git a/src/client/game.cpp b/src/client/game.cpp index 3429cc57b..610522dc2 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1055,7 +1055,7 @@ bool Game::startup(bool *kill, m_invert_mouse = g_settings->getBool("invert_mouse"); m_first_loop_after_window_activation = true; - g_translations->clear(); + g_client_translations->clear(); if (!init(map_dir, address, port, gamespec)) return false; diff --git a/src/clientiface.h b/src/clientiface.h index bf95df4a8..83fa6fe99 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -339,12 +339,18 @@ public: u8 getMinor() const { return m_version_minor; } u8 getPatch() const { return m_version_patch; } const std::string &getFull() const { return m_full_version; } + + void setLangCode(const std::string &code) { m_lang_code = code; } + const std::string &getLangCode() const { return m_lang_code; } private: // Version is stored in here after INIT before INIT2 u8 m_pending_serialization_version = SER_FMT_VER_INVALID; /* current state of client */ ClientState m_state = CS_Created; + + // Client sent language code + std::string m_lang_code; /* Blocks that have been sent to client. diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index c685500ce..5136eb0ec 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -311,6 +311,9 @@ void Server::handleCommand_Init2(NetworkPacket* pkt) RemoteClient *client = getClient(peer_id, CS_InitDone); + // Keep client language for server translations + client->setLangCode(lang); + // Send active objects { PlayerSAO *sao = getPlayerSAO(peer_id); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 831464d3b..3fb58b8c8 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -40,6 +40,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "remoteplayer.h" #include "server/luaentity_sao.h" #include "server/player_sao.h" +#include "util/string.h" +#include "translation.h" #ifndef SERVER #include "client/client.h" #endif @@ -1302,6 +1304,19 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L) return 0; } +// get_translated_string(lang_code, string) +int ModApiEnvMod::l_get_translated_string(lua_State * L) +{ + GET_ENV_PTR; + std::string lang_code = luaL_checkstring(L, 1); + std::string string = luaL_checkstring(L, 2); + getServer(L)->loadTranslationLanguage(lang_code); + string = wide_to_utf8(translate_string(utf8_to_wide(string), + &(*g_server_translations)[lang_code])); + lua_pushstring(L, string.c_str()); + return 1; +} + void ModApiEnvMod::Initialize(lua_State *L, int top) { API_FCT(set_node); @@ -1349,6 +1364,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top) API_FCT(transforming_liquid_add); API_FCT(forceload_block); API_FCT(forceload_free_block); + API_FCT(get_translated_string); } void ModApiEnvMod::InitializeClient(lua_State *L, int top) diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index ac2f8b588..9050b4306 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -187,6 +187,9 @@ private: // stops forceloading a position static int l_forceload_free_block(lua_State *L); + // Get a string translated server side + static int l_get_translated_string(lua_State * L); + public: static void Initialize(lua_State *L, int top); static void InitializeClient(lua_State *L, int top); diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 00e849cdf..7137484e8 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -163,6 +163,7 @@ int ModApiServer::l_get_player_information(lua_State *L) u16 prot_vers; u8 ser_vers,major,minor,patch; std::string vers_string; + std::string lang_code; #define ERET(code) \ if (!(code)) { \ @@ -182,7 +183,7 @@ int ModApiServer::l_get_player_information(lua_State *L) &avg_jitter)) ERET(getServer(L)->getClientInfo(player->getPeerId(), &state, &uptime, &ser_vers, - &prot_vers, &major, &minor, &patch, &vers_string)) + &prot_vers, &major, &minor, &patch, &vers_string, &lang_code)) lua_newtable(L); int table = lua_gettop(L); @@ -237,6 +238,10 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushnumber(L, player->formspec_version); lua_settable(L, table); + lua_pushstring(L, "lang_code"); + lua_pushstring(L, lang_code.c_str()); + lua_settable(L, table); + #ifndef NDEBUG lua_pushstring(L,"serialization_version"); lua_pushnumber(L, ser_vers); diff --git a/src/server.cpp b/src/server.cpp index c32aa5306..af6d3e40d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -64,6 +64,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "chat_interface.h" #include "remoteplayer.h" #include "server/player_sao.h" +#include "translation.h" class ClientNotFoundException : public BaseException { @@ -1266,7 +1267,8 @@ bool Server::getClientInfo( u8* major, u8* minor, u8* patch, - std::string* vers_string + std::string* vers_string, + std::string* lang_code ) { *state = m_clients.getClientState(peer_id); @@ -1286,6 +1288,7 @@ bool Server::getClientInfo( *minor = client->getMinor(); *patch = client->getPatch(); *vers_string = client->getFull(); + *lang_code = client->getLangCode(); m_clients.unlock(); @@ -3937,3 +3940,20 @@ void Server::broadcastModChannelMessage(const std::string &channel, m_script->on_modchannel_message(channel, sender, message); } } + +void Server::loadTranslationLanguage(const std::string &lang_code) +{ + if (g_server_translations->count(lang_code)) + return; // Already loaded + + std::string suffix = "." + lang_code + ".tr"; + for (const auto &i : m_media) { + if (str_ends_with(i.first, suffix)) { + std::ifstream t(i.second.path); + std::string data((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + + (*g_server_translations)[lang_code].loadTranslation(data); + } + } +} diff --git a/src/server.h b/src/server.h index eecc2c0f0..b995aba28 100644 --- a/src/server.h +++ b/src/server.h @@ -334,7 +334,7 @@ public: bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval); bool getClientInfo(session_t peer_id, ClientState *state, u32 *uptime, u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch, - std::string* vers_string); + std::string* vers_string, std::string* lang_code); void printToConsoleOnly(const std::string &text); @@ -358,6 +358,9 @@ public: // Send block to specific player only bool SendBlock(session_t peer_id, const v3s16 &blockpos); + // Load translations for a language + void loadTranslationLanguage(const std::string &lang_code); + // Bind address Address m_bind_addr; diff --git a/src/translation.cpp b/src/translation.cpp index d17467ce7..8bbaee0a3 100644 --- a/src/translation.cpp +++ b/src/translation.cpp @@ -20,9 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "translation.h" #include "log.h" #include "util/string.h" +#include -static Translations main_translations; -Translations *g_translations = &main_translations; + +#ifndef SERVER +// Client translations +Translations client_translations; +Translations *g_client_translations = &client_translations; +#endif + +// Per language server translations +std::unordered_map server_translations; +std::unordered_map *g_server_translations = &server_translations; Translations::~Translations() { diff --git a/src/translation.h b/src/translation.h index 18fc6c38f..71423b15e 100644 --- a/src/translation.h +++ b/src/translation.h @@ -23,7 +23,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include class Translations; -extern Translations *g_translations; +extern std::unordered_map *g_server_translations; +#ifndef SERVER +extern Translations *g_client_translations; +#endif class Translations { diff --git a/src/util/string.cpp b/src/util/string.cpp index 2ee3ec735..6e1db798c 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -693,10 +693,12 @@ void str_replace(std::string &str, char from, char to) * before filling it again. */ -void translate_all(const std::wstring &s, size_t &i, std::wstring &res); +void translate_all(const std::wstring &s, size_t &i, + Translations *translations, std::wstring &res); -void translate_string(const std::wstring &s, const std::wstring &textdomain, - size_t &i, std::wstring &res) { +void translate_string(const std::wstring &s, Translations *translations, + const std::wstring &textdomain, size_t &i, std::wstring &res) +{ std::wostringstream output; std::vector args; int arg_number = 1; @@ -750,7 +752,7 @@ void translate_string(const std::wstring &s, const std::wstring &textdomain, if (arg_number >= 10) { errorstream << "Ignoring too many arguments to translation" << std::endl; std::wstring arg; - translate_all(s, i, arg); + translate_all(s, i, translations, arg); args.push_back(arg); continue; } @@ -758,7 +760,7 @@ void translate_string(const std::wstring &s, const std::wstring &textdomain, output << arg_number; ++arg_number; std::wstring arg; - translate_all(s, i, arg); + translate_all(s, i, translations, arg); args.push_back(arg); } else { // This is an escape sequence *inside* the template string to translate itself. @@ -767,8 +769,13 @@ void translate_string(const std::wstring &s, const std::wstring &textdomain, } } + std::wstring toutput; // Translate the template. - std::wstring toutput = g_translations->getTranslation(textdomain, output.str()); + if (translations != nullptr) + toutput = translations->getTranslation( + textdomain, output.str()); + else + toutput = output.str(); // Put back the arguments in the translated template. std::wostringstream result; @@ -802,7 +809,9 @@ void translate_string(const std::wstring &s, const std::wstring &textdomain, res = result.str(); } -void translate_all(const std::wstring &s, size_t &i, std::wstring &res) { +void translate_all(const std::wstring &s, size_t &i, + Translations *translations, std::wstring &res) +{ std::wostringstream output; while (i < s.length()) { // Not an escape sequence: just add the character. @@ -851,7 +860,7 @@ void translate_all(const std::wstring &s, size_t &i, std::wstring &res) { if (parts.size() > 1) textdomain = parts[1]; std::wstring translated; - translate_string(s, textdomain, i, translated); + translate_string(s, translations, textdomain, i, translated); output << translated; } else { // Another escape sequence, such as colors. Preserve it. @@ -862,9 +871,21 @@ void translate_all(const std::wstring &s, size_t &i, std::wstring &res) { res = output.str(); } -std::wstring translate_string(const std::wstring &s) { +// Translate string server side +std::wstring translate_string(const std::wstring &s, Translations *translations) +{ size_t i = 0; std::wstring res; - translate_all(s, i, res); + translate_all(s, i, translations, res); return res; } + +// Translate string client side +std::wstring translate_string(const std::wstring &s) +{ +#ifdef SERVER + return translate_string(s, nullptr); +#else + return translate_string(s, g_client_translations); +#endif +} diff --git a/src/util/string.h b/src/util/string.h index 0d2a6bdb2..185fb55e2 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -31,6 +31,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include +class Translations; + #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) @@ -650,6 +652,8 @@ std::vector > split(const std::basic_string &s, T delim) return tokens; } +std::wstring translate_string(const std::wstring &s, Translations *translations); + std::wstring translate_string(const std::wstring &s); inline std::wstring unescape_translate(const std::wstring &s) { -- cgit v1.2.3 From 6cc5c7cbb489a429009e769a958f07da33a9d2ca Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Sat, 25 Apr 2020 07:48:04 +0200 Subject: Simplify how parseElement splits element string (#9726) --- src/gui/guiFormSpecMenu.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 85ab2eb50..0ed525f97 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -2668,24 +2668,12 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element) if (parseVersionDirect(element)) return; - std::vector parts = split(element,'['); - - // ugly workaround to keep compatibility - if (parts.size() > 2) { - if (trim(parts[0]) == "image") { - for (unsigned int i=2;i< parts.size(); i++) { - parts[1] += "[" + parts[i]; - } - } - else { return; } - } - - if (parts.size() < 2) { + size_t pos = element.find('['); + if (pos == std::string::npos) return; - } - std::string type = trim(parts[0]); - std::string description = trim(parts[1]); + std::string type = trim(element.substr(0, pos)); + std::string description = element.substr(pos+1); if (type == "container") { parseContainer(data, description); -- cgit v1.2.3 From 49ed0ca00a9a79b5db0bd6cc4589d56d7f1b3d45 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Sat, 25 Apr 2020 03:42:18 -0400 Subject: Ensure game is shutdown if server throws exception (#9742) --- src/client/game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index 610522dc2..3bdac786c 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -4284,7 +4284,6 @@ void the_game(bool *kill, reconnect_requested, &chat_backend, gamespec, simple_singleplayer_mode)) { game.run(); - game.shutdown(); } } catch (SerializationError &e) { @@ -4300,4 +4299,5 @@ void the_game(bool *kill, strgettext("\nCheck debug.txt for details."); errorstream << error_message << std::endl; } + game.shutdown(); } -- cgit v1.2.3 From 73180a73da9b290e2da8629799696cd8c4eab268 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 25 Apr 2020 12:39:17 +0200 Subject: mapblock_mesh: Optimize a few things (#9713) --- src/client/mapblock_mesh.cpp | 91 +++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index a5bee6b88..0a1619b3f 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -225,7 +225,7 @@ static u16 getSmoothLightCombined(const v3s16 &p, return f.light_propagates; }; - std::array obstructed = {{ 1, 1, 1, 1 }}; + bool obstructed[4] = { true, true, true, true }; add_node(0); bool opaque1 = !add_node(1); bool opaque2 = !add_node(2); @@ -372,6 +372,32 @@ void final_color_blend(video::SColor *result, Mesh generation helpers */ +// This table is moved outside getNodeVertexDirs to avoid the compiler using +// a mutex to initialize this table at runtime right in the hot path. +// For details search the internet for "cxa_guard_acquire". +static const v3s16 vertex_dirs_table[] = { + // ( 1, 0, 0) + v3s16( 1,-1, 1), v3s16( 1,-1,-1), + v3s16( 1, 1,-1), v3s16( 1, 1, 1), + // ( 0, 1, 0) + v3s16( 1, 1,-1), v3s16(-1, 1,-1), + v3s16(-1, 1, 1), v3s16( 1, 1, 1), + // ( 0, 0, 1) + v3s16(-1,-1, 1), v3s16( 1,-1, 1), + v3s16( 1, 1, 1), v3s16(-1, 1, 1), + // invalid + v3s16(), v3s16(), v3s16(), v3s16(), + // ( 0, 0,-1) + v3s16( 1,-1,-1), v3s16(-1,-1,-1), + v3s16(-1, 1,-1), v3s16( 1, 1,-1), + // ( 0,-1, 0) + v3s16( 1,-1, 1), v3s16(-1,-1, 1), + v3s16(-1,-1,-1), v3s16( 1,-1,-1), + // (-1, 0, 0) + v3s16(-1,-1,-1), v3s16(-1,-1, 1), + v3s16(-1, 1, 1), v3s16(-1, 1,-1) +}; + /* vertex_dirs: v3s16[4] */ @@ -384,44 +410,16 @@ static void getNodeVertexDirs(const v3s16 &dir, v3s16 *vertex_dirs) 2: top-left 3: top-right */ - if (dir == v3s16(0, 0, 1)) { - // If looking towards z+, this is the face that is behind - // the center point, facing towards z+. - vertex_dirs[0] = v3s16(-1,-1, 1); - vertex_dirs[1] = v3s16( 1,-1, 1); - vertex_dirs[2] = v3s16( 1, 1, 1); - vertex_dirs[3] = v3s16(-1, 1, 1); - } else if (dir == v3s16(0, 0, -1)) { - // faces towards Z- - vertex_dirs[0] = v3s16( 1,-1,-1); - vertex_dirs[1] = v3s16(-1,-1,-1); - vertex_dirs[2] = v3s16(-1, 1,-1); - vertex_dirs[3] = v3s16( 1, 1,-1); - } else if (dir == v3s16(1, 0, 0)) { - // faces towards X+ - vertex_dirs[0] = v3s16( 1,-1, 1); - vertex_dirs[1] = v3s16( 1,-1,-1); - vertex_dirs[2] = v3s16( 1, 1,-1); - vertex_dirs[3] = v3s16( 1, 1, 1); - } else if (dir == v3s16(-1, 0, 0)) { - // faces towards X- - vertex_dirs[0] = v3s16(-1,-1,-1); - vertex_dirs[1] = v3s16(-1,-1, 1); - vertex_dirs[2] = v3s16(-1, 1, 1); - vertex_dirs[3] = v3s16(-1, 1,-1); - } else if (dir == v3s16(0, 1, 0)) { - // faces towards Y+ (assume Z- as "down" in texture) - vertex_dirs[0] = v3s16( 1, 1,-1); - vertex_dirs[1] = v3s16(-1, 1,-1); - vertex_dirs[2] = v3s16(-1, 1, 1); - vertex_dirs[3] = v3s16( 1, 1, 1); - } else if (dir == v3s16(0, -1, 0)) { - // faces towards Y- (assume Z+ as "down" in texture) - vertex_dirs[0] = v3s16( 1,-1, 1); - vertex_dirs[1] = v3s16(-1,-1, 1); - vertex_dirs[2] = v3s16(-1,-1,-1); - vertex_dirs[3] = v3s16( 1,-1,-1); - } + + // Direction must be (1,0,0), (-1,0,0), (0,1,0), (0,-1,0), + // (0,0,1), (0,0,-1) + assert(dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z == 1); + + // Convert direction to single integer for table lookup + u8 idx = (dir.X + 2 * dir.Y + 3 * dir.Z) & 7; + idx = (idx - 1) * 4; + + memcpy(vertex_dirs, &vertex_dirs_table[idx], 4 * sizeof(v3s16)); } static void getNodeTextureCoords(v3f base, const v3f &scale, const v3s16 &dir, float *u, float *v) @@ -892,6 +890,8 @@ static void updateFastFaceRow( u16 lights[4] = {0, 0, 0, 0}; u8 waving; TileSpec tile; + + // Get info of first tile getTileInfo(data, p, face_dir, makes_face, p_corrected, face_dir_corrected, lights, waving, tile); @@ -902,8 +902,6 @@ static void updateFastFaceRow( // If tiling can be done, this is set to false in the next step bool next_is_different = true; - v3s16 p_next; - bool next_makes_face = false; v3s16 next_p_corrected; v3s16 next_face_dir_corrected; @@ -912,9 +910,9 @@ static void updateFastFaceRow( // If at last position, there is nothing to compare to and // the face must be drawn anyway if (j != MAP_BLOCKSIZE - 1) { - p_next = p + translate_dir; + p += translate_dir; - getTileInfo(data, p_next, face_dir, + getTileInfo(data, p, face_dir, next_makes_face, next_p_corrected, next_face_dir_corrected, next_lights, waving, @@ -923,7 +921,7 @@ static void updateFastFaceRow( if (next_makes_face == makes_face && next_p_corrected == p_corrected + translate_dir && next_face_dir_corrected == face_dir_corrected - && memcmp(next_lights, lights, ARRLEN(lights) * sizeof(u16)) == 0 + && memcmp(next_lights, lights, sizeof(lights)) == 0 // Don't apply fast faces to waving water. && (waving != 3 || !waving_liquids) && next_tile.isTileable(tile)) { @@ -961,10 +959,9 @@ static void updateFastFaceRow( makes_face = next_makes_face; p_corrected = next_p_corrected; face_dir_corrected = next_face_dir_corrected; - std::memcpy(lights, next_lights, ARRLEN(lights) * sizeof(u16)); + memcpy(lights, next_lights, sizeof(lights)); if (next_is_different) - tile = next_tile; - p = p_next; + tile = std::move(next_tile); // faster than copy } } -- cgit v1.2.3 From bc60e44d80a02bd48163440da2fd3165c0910376 Mon Sep 17 00:00:00 2001 From: v-rob Date: Sat, 25 Apr 2020 07:55:21 -0700 Subject: Add `animated_image` to clickthrough elements (#9724) --- src/gui/guiFormSpecMenu.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 0ed525f97..567f0ca7e 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -915,7 +915,9 @@ void GUIFormSpecMenu::parseAnimatedImage(parserData *data, const std::string &el auto style = getDefaultStyleForElement("animated_image", spec.fname, "image"); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); - e->drop(); + + // Animated images should let events through + m_clickthrough_elements.push_back(e); m_fields.push_back(spec); } -- cgit v1.2.3 From e1fc72c6f3450c82e2dd3e0892838498a6a8a092 Mon Sep 17 00:00:00 2001 From: theviper121 Date: Sun, 26 Apr 2020 12:32:04 -0500 Subject: Fix UpdateBonePosition() breaking animations (#9577) --- src/client/content_cao.cpp | 48 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index e9e1cebd3..aadd33bb9 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -890,6 +890,11 @@ void GenericCAO::updateNodePos() void GenericCAO::step(float dtime, ClientEnvironment *env) { + if (m_animated_meshnode) { + m_animated_meshnode->animateJoints(); + updateBonePosition(); + } + // Handle model animations and update positions instantly to prevent lags if (m_is_local_player) { LocalPlayer *player = m_env->getLocalPlayer(); @@ -1360,16 +1365,41 @@ void GenericCAO::updateBonePosition() return; m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render - for(std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - std::string bone_name = (*ii).first; - v3f bone_pos = (*ii).second.X; - v3f bone_rot = (*ii).second.Y; + for (auto &it : m_bone_position) { + std::string bone_name = it.first; irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str()); - if(bone) - { - bone->setPosition(bone_pos); + if (bone) { + bone->setPosition(it.second.X); + bone->setRotation(it.second.Y); + } + } + + // search through bones to find mistakenly rotated bones due to bug in Irrlicht + for (u32 i = 0; i < m_animated_meshnode->getJointCount(); ++i) { + irr::scene::IBoneSceneNode *bone = m_animated_meshnode->getJointNode(i); + if (!bone) + continue; + + //If bone is manually positioned there is no need to perform the bug check + bool skip = false; + for (auto &it : m_bone_position) { + if (it.first == bone->getName()) { + skip = true; + break; + } + } + if (skip) + continue; + + // Workaround for Irrlicht bug + // We check each bone to see if it has been rotated ~180deg from its expected position due to a bug in Irricht + // when using EJUOR_CONTROL joint control. If the bug is detected we update the bone to the proper position + // and update the bones transformation. + v3f bone_rot = bone->getRelativeTransformation().getRotationDegrees(); + float offset = fabsf(bone_rot.X - bone->getRotation().X); + if (offset > 179.9f && offset < 180.1f) { bone->setRotation(bone_rot); + bone->updateAbsolutePosition(); } } } @@ -1583,7 +1613,7 @@ void GenericCAO::processMessage(const std::string &data) v3f rotation = readV3F32(is); m_bone_position[bone] = core::vector2d(position, rotation); - updateBonePosition(); + // updateBonePosition(); now called every step } else if (cmd == AO_CMD_ATTACH_TO) { u16 parent_id = readS16(is); std::string bone = deSerializeString(is); -- cgit v1.2.3 From eca6ee911a99f863abf79ab956d4c757e9e4bae3 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 19:32:29 +0200 Subject: Fix mapgen settings in minetest.conf being ignored (#9737) broken since e8a8185d24897ccf964327017effae81aa1c9d40 --- src/map_settings_manager.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map_settings_manager.cpp b/src/map_settings_manager.cpp index 7ef4bf12e..4f070e910 100644 --- a/src/map_settings_manager.cpp +++ b/src/map_settings_manager.cpp @@ -32,7 +32,6 @@ MapSettingsManager::MapSettingsManager(Settings *user_settings, m_user_settings(user_settings) { assert(m_user_settings != NULL); - Mapgen::setDefaultSettings(m_map_settings); } @@ -180,6 +179,16 @@ MapgenParams *MapSettingsManager::makeMapgenParams() params->mgtype = mgtype; + // Load the mapgen param defaults + /* FIXME: Why is it done like this? MapgenParams should just + * set the defaults in its constructor instead. */ + { + Settings default_settings; + Mapgen::setDefaultSettings(&default_settings); + params->MapgenParams::readParams(&default_settings); + params->readParams(&default_settings); + } + // Load the rest of the mapgen params from our active settings params->MapgenParams::readParams(m_user_settings); params->MapgenParams::readParams(m_map_settings); -- cgit v1.2.3 From 68f45fc130341e1b3e7d3207658947324db87d3c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 19:52:09 +0200 Subject: Remove unused lookup table from noise.cpp closes #9757 --- src/noise.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/noise.cpp b/src/noise.cpp index 9c91a6df4..5a1d989cb 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -46,11 +46,6 @@ typedef float (*Interp3dFxn)( float v001, float v101, float v011, float v111, float x, float y, float z); -float cos_lookup[16] = { - 1.0f, 0.9238f, 0.7071f, 0.3826f, .0f, -0.3826f, -0.7071f, -0.9238f, - 1.0f, -0.9238f, -0.7071f, -0.3826f, .0f, 0.3826f, 0.7071f, 0.9238f -}; - FlagDesc flagdesc_noiseparams[] = { {"defaults", NOISE_FLAG_DEFAULTS}, {"eased", NOISE_FLAG_EASED}, -- cgit v1.2.3 From e564bf8eadb5aee7a90b2184b03316917c580aed Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Mon, 27 Apr 2020 06:54:48 +0200 Subject: Add PostgreSQL authentication backend (#9756) * Add PostgreSQL authentication backend --- src/database/database-postgresql.cpp | 175 +++++++++++++++++++++++++++++++++++ src/database/database-postgresql.h | 24 +++++ src/serverenvironment.cpp | 8 ++ 3 files changed, 207 insertions(+) (limited to 'src') diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index c1b81586d..ca750b466 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -166,6 +166,11 @@ void Database_PostgreSQL::endSave() checkResults(PQexec(m_conn, "COMMIT;")); } +void Database_PostgreSQL::rollback() +{ + checkResults(PQexec(m_conn, "ROLLBACK;")); +} + MapDatabasePostgreSQL::MapDatabasePostgreSQL(const std::string &connect_string): Database_PostgreSQL(connect_string), MapDatabase() @@ -637,4 +642,174 @@ void PlayerDatabasePostgreSQL::listPlayers(std::vector &res) PQclear(results); } +AuthDatabasePostgreSQL::AuthDatabasePostgreSQL(const std::string &connect_string) : + Database_PostgreSQL(connect_string), AuthDatabase() +{ + connectToDatabase(); +} + +void AuthDatabasePostgreSQL::createDatabase() +{ + createTableIfNotExists("auth", + "CREATE TABLE auth (" + "id SERIAL," + "name TEXT UNIQUE," + "password TEXT," + "last_login INT NOT NULL DEFAULT 0," + "PRIMARY KEY (id)" + ");"); + + createTableIfNotExists("user_privileges", + "CREATE TABLE user_privileges (" + "id INT," + "privilege TEXT," + "PRIMARY KEY (id, privilege)," + "CONSTRAINT fk_id FOREIGN KEY (id) REFERENCES auth (id) ON DELETE CASCADE" + ");"); +} + +void AuthDatabasePostgreSQL::initStatements() +{ + prepareStatement("auth_read", "SELECT id, name, password, last_login FROM auth WHERE name = $1"); + prepareStatement("auth_write", "UPDATE auth SET name = $1, password = $2, last_login = $3 WHERE id = $4"); + prepareStatement("auth_create", "INSERT INTO auth (name, password, last_login) VALUES ($1, $2, $3) RETURNING id"); + prepareStatement("auth_delete", "DELETE FROM auth WHERE name = $1"); + + prepareStatement("auth_list_names", "SELECT name FROM auth ORDER BY name DESC"); + + prepareStatement("auth_read_privs", "SELECT privilege FROM user_privileges WHERE id = $1"); + prepareStatement("auth_write_privs", "INSERT INTO user_privileges (id, privilege) VALUES ($1, $2)"); + prepareStatement("auth_delete_privs", "DELETE FROM user_privileges WHERE id = $1"); +} + +bool AuthDatabasePostgreSQL::getAuth(const std::string &name, AuthEntry &res) +{ + pingDatabase(); + + const char *values[] = { name.c_str() }; + PGresult *result = execPrepared("auth_read", 1, values, false, false); + int numrows = PQntuples(result); + if (numrows == 0) { + PQclear(result); + return false; + } + + res.id = pg_to_uint(result, 0, 0); + res.name = std::string(PQgetvalue(result, 0, 1), PQgetlength(result, 0, 1)); + res.password = std::string(PQgetvalue(result, 0, 2), PQgetlength(result, 0, 2)); + res.last_login = pg_to_int(result, 0, 3); + + PQclear(result); + + std::string playerIdStr = itos(res.id); + const char *privsValues[] = { playerIdStr.c_str() }; + PGresult *results = execPrepared("auth_read_privs", 1, privsValues, false); + + numrows = PQntuples(results); + for (int row = 0; row < numrows; row++) + res.privileges.emplace_back(PQgetvalue(results, row, 0)); + + PQclear(results); + + return true; +} + +bool AuthDatabasePostgreSQL::saveAuth(const AuthEntry &authEntry) +{ + pingDatabase(); + + beginSave(); + + std::string lastLoginStr = itos(authEntry.last_login); + std::string idStr = itos(authEntry.id); + const char *values[] = { + authEntry.name.c_str() , + authEntry.password.c_str(), + lastLoginStr.c_str(), + idStr.c_str(), + }; + execPrepared("auth_write", 4, values); + + writePrivileges(authEntry); + + endSave(); + return true; +} + +bool AuthDatabasePostgreSQL::createAuth(AuthEntry &authEntry) +{ + pingDatabase(); + + std::string lastLoginStr = itos(authEntry.last_login); + const char *values[] = { + authEntry.name.c_str() , + authEntry.password.c_str(), + lastLoginStr.c_str() + }; + + beginSave(); + + PGresult *result = execPrepared("auth_create", 3, values, false, false); + + int numrows = PQntuples(result); + if (numrows == 0) { + errorstream << "Strange behaviour on auth creation, no ID returned." << std::endl; + PQclear(result); + rollback(); + return false; + } + + authEntry.id = pg_to_uint(result, 0, 0); + PQclear(result); + + writePrivileges(authEntry); + + endSave(); + return true; +} + +bool AuthDatabasePostgreSQL::deleteAuth(const std::string &name) +{ + pingDatabase(); + + const char *values[] = { name.c_str() }; + execPrepared("auth_delete", 1, values); + + // privileges deleted by foreign key on delete cascade + return true; +} + +void AuthDatabasePostgreSQL::listNames(std::vector &res) +{ + pingDatabase(); + + PGresult *results = execPrepared("auth_list_names", 0, + NULL, NULL, NULL, false, false); + + int numrows = PQntuples(results); + + for (int row = 0; row < numrows; ++row) + res.emplace_back(PQgetvalue(results, row, 0)); + + PQclear(results); +} + +void AuthDatabasePostgreSQL::reload() +{ + // noop for PgSQL +} + +void AuthDatabasePostgreSQL::writePrivileges(const AuthEntry &authEntry) +{ + std::string authIdStr = itos(authEntry.id); + const char *values[] = { authIdStr.c_str() }; + execPrepared("auth_delete_privs", 1, values); + + for (const std::string &privilege : authEntry.privileges) { + const char *values[] = { authIdStr.c_str(), privilege.c_str() }; + execPrepared("auth_write_privs", 2, values); + } +} + + #endif // USE_POSTGRESQL diff --git a/src/database/database-postgresql.h b/src/database/database-postgresql.h index 5a8b89a51..340f0a7b8 100644 --- a/src/database/database-postgresql.h +++ b/src/database/database-postgresql.h @@ -36,6 +36,7 @@ public: void beginSave(); void endSave(); + void rollback(); bool initialized() const; @@ -148,3 +149,26 @@ protected: private: bool playerDataExists(const std::string &playername); }; + +class AuthDatabasePostgreSQL : private Database_PostgreSQL, public AuthDatabase +{ +public: + AuthDatabasePostgreSQL(const std::string &connect_string); + virtual ~AuthDatabasePostgreSQL() = default; + + virtual void pingDatabase() { Database_PostgreSQL::pingDatabase(); } + + virtual bool getAuth(const std::string &name, AuthEntry &res); + virtual bool saveAuth(const AuthEntry &authEntry); + virtual bool createAuth(AuthEntry &authEntry); + virtual bool deleteAuth(const std::string &name); + virtual void listNames(std::vector &res); + virtual void reload(); + +protected: + virtual void createDatabase(); + virtual void initStatements(); + +private: + virtual void writePrivileges(const AuthEntry &authEntry); +}; diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 08d796118..27432e973 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -2187,6 +2187,14 @@ AuthDatabase *ServerEnvironment::openAuthDatabase( if (name == "sqlite3") return new AuthDatabaseSQLite3(savedir); +#if USE_POSTGRESQL + if (name == "postgresql") { + std::string connect_string; + conf.getNoEx("pgsql_auth_connection", connect_string); + return new AuthDatabasePostgreSQL(connect_string); + } +#endif + if (name == "files") return new AuthDatabaseFiles(savedir); -- cgit v1.2.3 From f6f6dd140f14a40a43a63a1ba3eccc66fd56d514 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 20:29:16 +0200 Subject: script: Fix add_entity returning unusable ref if object deleted in on_activate --- src/script/lua_api/l_env.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 3fb58b8c8..cabca124d 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -589,19 +589,19 @@ int ModApiEnvMod::l_add_entity(lua_State *L) { GET_ENV_PTR; - // pos v3f pos = checkFloatPos(L, 1); - // content const char *name = luaL_checkstring(L, 2); - // staticdata const char *staticdata = luaL_optstring(L, 3, ""); - // Do it + ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata); int objectid = env->addActiveObject(obj); // If failed to add, return nothing (reads as nil) if(objectid == 0) return 0; - // Return ObjectRef + + // If already deleted (can happen in on_activate), return nil + if (obj->isGone()) + return 0; getScriptApiBase(L)->objectrefGetOrCreate(L, obj); return 1; } -- cgit v1.2.3 From 8a03097450441cc7589507509bf755082a027cc7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 20:57:27 +0200 Subject: script: Put getGuiEngine() inside a client-only #ifdef --- src/script/cpp_api/s_base.h | 4 ++++ src/script/lua_api/l_base.cpp | 2 ++ src/script/lua_api/l_base.h | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index 697e5f556..86f7f7bac 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -136,8 +136,10 @@ protected: Environment* getEnv() { return m_environment; } void setEnv(Environment* env) { m_environment = env; } +#ifndef SERVER GUIEngine* getGuiEngine() { return m_guiengine; } void setGuiEngine(GUIEngine* guiengine) { m_guiengine = guiengine; } +#endif void objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj); @@ -158,6 +160,8 @@ private: IGameDef *m_gamedef = nullptr; Environment *m_environment = nullptr; +#ifndef SERVER GUIEngine *m_guiengine = nullptr; +#endif ScriptingType m_type; }; diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index c980bba39..b8658f62b 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -62,10 +62,12 @@ Environment *ModApiBase::getEnv(lua_State *L) return getScriptApiBase(L)->getEnv(); } +#ifndef SERVER GUIEngine *ModApiBase::getGuiEngine(lua_State *L) { return getScriptApiBase(L)->getGuiEngine(); } +#endif std::string ModApiBase::getCurrentModPath(lua_State *L) { diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h index b46b5b567..e32647628 100644 --- a/src/script/lua_api/l_base.h +++ b/src/script/lua_api/l_base.h @@ -32,12 +32,12 @@ extern "C" { #ifndef SERVER class Client; +class GUIEngine; #endif class ScriptApiBase; class Server; class Environment; -class GUIEngine; class ModApiBase : protected LuaHelper { @@ -46,12 +46,13 @@ public: static Server* getServer(lua_State *L); #ifndef SERVER static Client* getClient(lua_State *L); + static GUIEngine* getGuiEngine(lua_State *L); #endif // !SERVER static IGameDef* getGameDef(lua_State *L); static Environment* getEnv(lua_State *L); - static GUIEngine* getGuiEngine(lua_State *L); + // When we are not loading the mod, this function returns "." static std::string getCurrentModPath(lua_State *L); -- cgit v1.2.3 From 515d38a702f0ebe1f419ce38c86484ecb845ed36 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 20:59:55 +0200 Subject: Fix truncation warning for F1000_MIN, F1000_MAX --- src/util/serialize.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/util/serialize.h b/src/util/serialize.h index 8ef0ad1c2..a4b5a234a 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -52,8 +52,8 @@ with this program; if not, write to the Free Software Foundation, Inc., // not represent the full range, but rather the largest safe range, of values on // all supported architectures. Note: This definition makes assumptions on // platform float-to-int conversion behavior. -#define F1000_MIN ((float)(s32)((-0x7FFFFFFF - 1) / FIXEDPOINT_FACTOR)) -#define F1000_MAX ((float)(s32)((0x7FFFFFFF) / FIXEDPOINT_FACTOR)) +#define F1000_MIN ((float)(s32)((float)(-0x7FFFFFFF - 1) / FIXEDPOINT_FACTOR)) +#define F1000_MAX ((float)(s32)((float)(0x7FFFFFFF) / FIXEDPOINT_FACTOR)) #define STRING_MAX_LEN 0xFFFF #define WIDE_STRING_MAX_LEN 0xFFFF -- cgit v1.2.3 From be71e70a91a3c857652a8b037dac7adf9d0fcdd1 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 27 Apr 2020 07:02:39 +0200 Subject: Script: Enforce type checks if not nil (#9748) * Script: Enforce type checks if not nil --- src/script/common/c_content.cpp | 76 ++++++++++++++++++++++---------------- src/script/common/c_converter.cpp | 32 ++++++++-------- src/script/common/c_converter.h | 6 +-- src/script/lua_api/l_inventory.cpp | 14 ++++--- 4 files changed, 72 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 25dada757..8335fccb5 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -102,7 +102,8 @@ void read_item_definition(lua_State* L, int index, lua_pop(L, 1); lua_getfield(L, index, "sounds"); - if(lua_istable(L, -1)){ + if (!lua_isnil(L, -1)) { + luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, "place"); read_soundspec(L, -1, def.sound_place); lua_pop(L, 1); @@ -182,9 +183,11 @@ void read_object_properties(lua_State *L, int index, { if(index < 0) index = lua_gettop(L) + 1 + index; - if(!lua_istable(L, index)) + if (lua_isnil(L, index)) return; + luaL_checktype(L, -1, LUA_TTABLE); + int hp_max = 0; if (getintfield(L, -1, "hp_max", hp_max)) { prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX); @@ -1027,13 +1030,15 @@ void read_soundspec(lua_State *L, int index, SimpleSoundSpec &spec) { if(index < 0) index = lua_gettop(L) + 1 + index; - if(lua_isnil(L, index)){ - } else if(lua_istable(L, index)){ + if (lua_isnil(L, index)) + return; + + if (lua_istable(L, index)) { getstringfield(L, index, "name", spec.name); getfloatfield(L, index, "gain", spec.gain); getfloatfield(L, index, "fade", spec.fade); getfloatfield(L, index, "pitch", spec.pitch); - } else if(lua_isstring(L, index)){ + } else if (lua_isstring(L, index)) { spec.name = lua_tostring(L, index); } } @@ -1055,9 +1060,13 @@ void push_soundspec(lua_State *L, const SimpleSoundSpec &spec) NodeBox read_nodebox(lua_State *L, int index) { NodeBox nodebox; - if(lua_istable(L, -1)){ - nodebox.type = (NodeBoxType)getenumfield(L, index, "type", - ScriptApiNode::es_NodeBoxType, NODEBOX_REGULAR); + if (lua_isnil(L, -1)) + return nodebox; + + luaL_checktype(L, -1, LUA_TTABLE); + + nodebox.type = (NodeBoxType)getenumfield(L, index, "type", + ScriptApiNode::es_NodeBoxType, NODEBOX_REGULAR); #define NODEBOXREAD(n, s){ \ lua_getfield(L, index, (s)); \ @@ -1067,30 +1076,30 @@ NodeBox read_nodebox(lua_State *L, int index) } #define NODEBOXREADVEC(n, s) \ - lua_getfield(L, index, (s)); \ - if (lua_istable(L, -1)) \ - (n) = read_aabb3f_vector(L, -1, BS); \ - lua_pop(L, 1); + lua_getfield(L, index, (s)); \ + if (lua_istable(L, -1)) \ + (n) = read_aabb3f_vector(L, -1, BS); \ + lua_pop(L, 1); + + NODEBOXREADVEC(nodebox.fixed, "fixed"); + NODEBOXREAD(nodebox.wall_top, "wall_top"); + NODEBOXREAD(nodebox.wall_bottom, "wall_bottom"); + NODEBOXREAD(nodebox.wall_side, "wall_side"); + NODEBOXREADVEC(nodebox.connect_top, "connect_top"); + NODEBOXREADVEC(nodebox.connect_bottom, "connect_bottom"); + NODEBOXREADVEC(nodebox.connect_front, "connect_front"); + NODEBOXREADVEC(nodebox.connect_left, "connect_left"); + NODEBOXREADVEC(nodebox.connect_back, "connect_back"); + NODEBOXREADVEC(nodebox.connect_right, "connect_right"); + NODEBOXREADVEC(nodebox.disconnected_top, "disconnected_top"); + NODEBOXREADVEC(nodebox.disconnected_bottom, "disconnected_bottom"); + NODEBOXREADVEC(nodebox.disconnected_front, "disconnected_front"); + NODEBOXREADVEC(nodebox.disconnected_left, "disconnected_left"); + NODEBOXREADVEC(nodebox.disconnected_back, "disconnected_back"); + NODEBOXREADVEC(nodebox.disconnected_right, "disconnected_right"); + NODEBOXREADVEC(nodebox.disconnected, "disconnected"); + NODEBOXREADVEC(nodebox.disconnected_sides, "disconnected_sides"); - NODEBOXREADVEC(nodebox.fixed, "fixed"); - NODEBOXREAD(nodebox.wall_top, "wall_top"); - NODEBOXREAD(nodebox.wall_bottom, "wall_bottom"); - NODEBOXREAD(nodebox.wall_side, "wall_side"); - NODEBOXREADVEC(nodebox.connect_top, "connect_top"); - NODEBOXREADVEC(nodebox.connect_bottom, "connect_bottom"); - NODEBOXREADVEC(nodebox.connect_front, "connect_front"); - NODEBOXREADVEC(nodebox.connect_left, "connect_left"); - NODEBOXREADVEC(nodebox.connect_back, "connect_back"); - NODEBOXREADVEC(nodebox.connect_right, "connect_right"); - NODEBOXREADVEC(nodebox.disconnected_top, "disconnected_top"); - NODEBOXREADVEC(nodebox.disconnected_bottom, "disconnected_bottom"); - NODEBOXREADVEC(nodebox.disconnected_front, "disconnected_front"); - NODEBOXREADVEC(nodebox.disconnected_left, "disconnected_left"); - NODEBOXREADVEC(nodebox.disconnected_back, "disconnected_back"); - NODEBOXREADVEC(nodebox.disconnected_right, "disconnected_right"); - NODEBOXREADVEC(nodebox.disconnected, "disconnected"); - NODEBOXREADVEC(nodebox.disconnected_sides, "disconnected_sides"); - } return nodebox; } @@ -1519,8 +1528,11 @@ void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask /******************************************************************************/ void read_groups(lua_State *L, int index, ItemGroupList &result) { - if (!lua_istable(L,index)) + if (lua_isnil(L, index)) return; + + luaL_checktype(L, index, LUA_TTABLE); + result.clear(); lua_pushnil(L); if (index < 0) diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 334af61c3..279d8b1a5 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -33,10 +33,9 @@ extern "C" { #define CHECK_TYPE(index, name, type) { \ int t = lua_type(L, (index)); \ if (t != (type)) { \ - std::string traceback = script_get_backtrace(L); \ throw LuaError(std::string("Invalid ") + (name) + \ " (expected " + lua_typename(L, (type)) + \ - " got " + lua_typename(L, t) + ").\n" + traceback); \ + " got " + lua_typename(L, t) + ")."); \ } \ } #define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER) @@ -457,12 +456,22 @@ size_t read_stringlist(lua_State *L, int index, std::vector *result Table field getters */ +bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname) +{ + if (lua_isnil(L, index)) + return false; + + CHECK_TYPE(index, std::string("field \"") + fieldname + '"', type); + return true; +} + bool getstringfield(lua_State *L, int table, const char *fieldname, std::string &result) { lua_getfield(L, table, fieldname); bool got = false; - if(lua_isstring(L, -1)){ + + if (check_field_or_nil(L, -1, LUA_TSTRING, fieldname)) { size_t len = 0; const char *ptr = lua_tolstring(L, -1, &len); if (ptr) { @@ -479,7 +488,8 @@ bool getfloatfield(lua_State *L, int table, { lua_getfield(L, table, fieldname); bool got = false; - if(lua_isnumber(L, -1)){ + + if (check_field_or_nil(L, -1, LUA_TNUMBER, fieldname)) { result = lua_tonumber(L, -1); got = true; } @@ -492,7 +502,8 @@ bool getboolfield(lua_State *L, int table, { lua_getfield(L, table, fieldname); bool got = false; - if(lua_isboolean(L, -1)){ + + if (check_field_or_nil(L, -1, LUA_TBOOLEAN, fieldname)){ result = lua_toboolean(L, -1); got = true; } @@ -511,17 +522,6 @@ size_t getstringlistfield(lua_State *L, int table, const char *fieldname, return num_strings_read; } -std::string checkstringfield(lua_State *L, int table, - const char *fieldname) -{ - lua_getfield(L, table, fieldname); - CHECK_TYPE(-1, std::string("field \"") + fieldname + '"', LUA_TSTRING); - size_t len; - const char *s = lua_tolstring(L, -1, &len); - lua_pop(L, 1); - return std::string(s, len); -} - std::string getstringfield_default(lua_State *L, int table, const char *fieldname, const std::string &default_) { diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 9620bf75a..a4a7079fd 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -45,13 +45,15 @@ float getfloatfield_default(lua_State *L, int table, 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) { lua_getfield(L, table, fieldname); bool got = false; - if (lua_isnumber(L, -1)){ + if (check_field_or_nil(L, -1, LUA_TNUMBER, fieldname)){ result = lua_tointeger(L, -1); got = true; } @@ -87,8 +89,6 @@ bool getboolfield(lua_State *L, int table, const char *fieldname, bool &result); bool getfloatfield(lua_State *L, int table, const char *fieldname, float &result); -std::string checkstringfield(lua_State *L, int table, - const char *fieldname); void setstringfield(lua_State *L, int table, const char *fieldname, const std::string &value); diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index 6e7afa4a4..4c8977898 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -487,7 +487,9 @@ int ModApiInventory::l_get_inventory(lua_State *L) { InventoryLocation loc; - std::string type = checkstringfield(L, 1, "type"); + lua_getfield(L, 1, "type"); + std::string type = luaL_checkstring(L, -1); + lua_pop(L, 1); if(type == "node"){ MAP_LOCK_REQUIRED; @@ -504,11 +506,13 @@ int ModApiInventory::l_get_inventory(lua_State *L) NO_MAP_LOCK_REQUIRED; if (type == "player") { - std::string name = checkstringfield(L, 1, "name"); - loc.setPlayer(name); + lua_getfield(L, 1, "name"); + loc.setPlayer(luaL_checkstring(L, -1)); + lua_pop(L, 1); } else if (type == "detached") { - std::string name = checkstringfield(L, 1, "name"); - loc.setDetached(name); + lua_getfield(L, 1, "name"); + loc.setDetached(luaL_checkstring(L, -1)); + lua_pop(L, 1); } if (getServer(L)->getInventory(loc) != NULL) -- cgit v1.2.3 From 91c4f7f0ea0b653d15bfabc05f5474f8fa1a8806 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Mon, 27 Apr 2020 11:27:27 +0200 Subject: Forbid object:attach(obj, ...) (#9762) Fixes #9761 --- src/script/lua_api/l_object.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index d7afb84da..77e1e7dc2 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -674,8 +674,13 @@ int ObjectRef::l_set_attach(lua_State *L) ServerActiveObject *parent = getobject(parent_ref); if (co == NULL) return 0; + if (parent == NULL) return 0; + + if (co == parent) + throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed."); + // Do it int parent_id = 0; std::string bone; -- cgit v1.2.3 From 13a8ea2dac2217cc898c7fc62c448f4ff6998d46 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 25 Apr 2020 15:24:42 +0200 Subject: Add STATIC_LOCALEDIR to BUILD_INFO and move it to version.cpp --- src/config.h | 10 ---------- src/version.cpp | 14 +++++++++++++- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/config.h b/src/config.h index 9d58a8cc1..5e1164642 100644 --- a/src/config.h +++ b/src/config.h @@ -28,13 +28,3 @@ #define BUILD_TYPE "Debug" #endif #endif - -#define BUILD_INFO \ - "BUILD_TYPE=" BUILD_TYPE "\n" \ - "RUN_IN_PLACE=" STR(RUN_IN_PLACE) "\n" \ - "USE_GETTEXT=" STR(USE_GETTEXT) "\n" \ - "USE_SOUND=" STR(USE_SOUND) "\n" \ - "USE_CURL=" STR(USE_CURL) "\n" \ - "USE_FREETYPE=" STR(USE_FREETYPE) "\n" \ - "USE_LUAJIT=" STR(USE_LUAJIT) "\n" \ - "STATIC_SHAREDIR=" STR(STATIC_SHAREDIR); diff --git a/src/version.cpp b/src/version.cpp index ae5ca3412..241228a6a 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -30,4 +30,16 @@ with this program; if not, write to the Free Software Foundation, Inc., const char *g_version_string = VERSION_STRING; const char *g_version_hash = VERSION_GITHASH; -const char *g_build_info = BUILD_INFO; +const char *g_build_info = + "BUILD_TYPE=" BUILD_TYPE "\n" + "RUN_IN_PLACE=" STR(RUN_IN_PLACE) "\n" + "USE_GETTEXT=" STR(USE_GETTEXT) "\n" + "USE_SOUND=" STR(USE_SOUND) "\n" + "USE_CURL=" STR(USE_CURL) "\n" + "USE_FREETYPE=" STR(USE_FREETYPE) "\n" + "USE_LUAJIT=" STR(USE_LUAJIT) "\n" + "STATIC_SHAREDIR=" STR(STATIC_SHAREDIR) +#if USE_GETTEXT && defined(STATIC_LOCALEDIR) + "\n" "STATIC_LOCALEDIR=" STR(STATIC_LOCALEDIR) +#endif +; -- cgit v1.2.3 From ca8957f500980849fbd3e0c05b7cf3272b18ac97 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 25 Apr 2020 15:44:32 +0200 Subject: Fix detection of in-place path_locale when RUN_IN_PLACE=0 broken by 2349d31bae1bfc4d58fd88efbc88261e69b11dad (side effect) fixes #9745 --- src/gettext.cpp | 5 ++++- src/porting.cpp | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/gettext.cpp b/src/gettext.cpp index 81621ba89..6818004df 100644 --- a/src/gettext.cpp +++ b/src/gettext.cpp @@ -217,7 +217,10 @@ void init_gettext(const char *path, const std::string &configured_language, #endif #endif - static std::string name = lowercase(PROJECT_NAME); + std::string name = lowercase(PROJECT_NAME); + infostream << "Gettext: domainname=\"" << name + << "\" path=\"" << path << "\"" << std::endl; + bindtextdomain(name.c_str(), path); textdomain(name.c_str()); diff --git a/src/porting.cpp b/src/porting.cpp index 76fd592d6..c0381ad06 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -598,18 +598,18 @@ void initializePaths() #if USE_GETTEXT bool found_localedir = false; # ifdef STATIC_LOCALEDIR - if (STATIC_LOCALEDIR[0] && fs::PathExists(STATIC_LOCALEDIR)) { + /* STATIC_LOCALEDIR may be a generalized path such as /usr/share/locale that + * doesn't necessarily contain our locale files, so check data path first. */ + path_locale = getDataPath("locale"); + if (fs::PathExists(path_locale)) { + found_localedir = true; + infostream << "Using in-place locale directory " << path_locale + << " even though a static one was provided." << std::endl; + } else if (STATIC_LOCALEDIR[0] && fs::PathExists(STATIC_LOCALEDIR)) { found_localedir = true; path_locale = STATIC_LOCALEDIR; - infostream << "Using locale directory " << STATIC_LOCALEDIR << std::endl; - } else { - path_locale = getDataPath("locale"); - if (fs::PathExists(path_locale)) { - found_localedir = true; - infostream << "Using in-place locale directory " << path_locale - << " even though a static one was provided " - << "(RUN_IN_PLACE or CUSTOM_LOCALEDIR)." << std::endl; - } + infostream << "Using static locale directory " << STATIC_LOCALEDIR + << std::endl; } # else path_locale = getDataPath("locale"); -- cgit v1.2.3 From aef59f2ad9a5a5a217ddadc05c46fd4d23cef47f Mon Sep 17 00:00:00 2001 From: "k.h.lai" Date: Tue, 28 Apr 2020 02:44:52 +0800 Subject: Remove /LTCG from when compiling with clang-cl (#9765) Remove /LTCG from CMAKE_EXE_LINKER_FLAGS_RELEASE when compiling with clang on Windows --- src/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dbd6b5922..b416faaf3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -676,9 +676,12 @@ if(MSVC) if(CMAKE_SIZEOF_VOID_P EQUAL 4) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE") endif() - #set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF") - + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF") + else() + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF") + endif() set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") -- cgit v1.2.3 From 3475759d1adbd4a64c6250fd87981f783e64f69c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 14 Apr 2020 14:11:33 +0200 Subject: Expose collision information to LuaEntity on_step --- builtin/game/features.lua | 1 + doc/lua_api.txt | 25 ++++++++++++++++++- src/script/common/c_content.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ src/script/common/c_content.h | 4 ++- src/script/cpp_api/s_entity.cpp | 12 ++++++--- src/script/cpp_api/s_entity.h | 4 ++- src/server/luaentity_sao.cpp | 8 +++--- 7 files changed, 98 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/builtin/game/features.lua b/builtin/game/features.lua index 623f8183b..a15475333 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -16,6 +16,7 @@ core.features = { formspec_version_element = true, area_store_persistent_ids = true, pathfinder_works = true, + object_step_has_moveresult = true, } function core.has_feature(arg) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 3ca32649a..5e4e18b62 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4147,6 +4147,8 @@ Utilities area_store_persistent_ids = true, -- Whether minetest.find_path is functional (5.2.0) pathfinder_works = true, + -- Whether Collision info is available to an objects' on_step (5.3.0) + object_step_has_moveresult = true, } * `minetest.has_feature(arg)`: returns `boolean, missing_features` @@ -6579,7 +6581,10 @@ Used by `minetest.register_entity`. on_activate = function(self, staticdata, dtime_s), - on_step = function(self, dtime), + on_step = function(self, dtime, moveresult), + -- Called every server step + -- dtime: Elapsed time + -- moveresult: Table with collision info (only available if physical=true) on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir), @@ -6594,6 +6599,24 @@ Used by `minetest.register_entity`. -- for more info) by using a '_' prefix } +Collision info passed to `on_step`: + + { + touching_ground = boolean, + collides = boolean, + standing_on_object = boolean, + collisions = { + { + type = string, -- "node" or "object", + axis = string, -- "x", "y" or "z" + node_pos = vector, -- if type is "node" + old_speed = vector, + new_speed = vector, + }, + ... + } + } + ABM (ActiveBlockModifier) definition ------------------------------------ diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 8335fccb5..6ff642738 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_types.h" #include "nodedef.h" #include "object_properties.h" +#include "collision.h" #include "cpp_api/s_node.h" #include "lua_api/l_object.h" #include "lua_api/l_item.h" @@ -2002,3 +2003,56 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value) } return stat; } + +/******************************************************************************/ + +// Indices must match values in `enum CollisionType` exactly!! +static const char *collision_type_str[] = { + "node", + "object", +}; + +// Indices must match values in `enum CollisionAxis` exactly!! +static const char *collision_axis_str[] = { + "x", + "y", + "z", +}; + +void push_collision_move_result(lua_State *L, const collisionMoveResult &res) +{ + lua_createtable(L, 0, 4); + + setboolfield(L, -1, "touching_ground", res.touching_ground); + setboolfield(L, -1, "collides", res.collides); + setboolfield(L, -1, "standing_on_object", res.standing_on_object); + + /* collisions */ + lua_createtable(L, res.collisions.size(), 0); + int i = 1; + for (const auto &c : res.collisions) { + lua_createtable(L, 0, 5); + + lua_pushstring(L, collision_type_str[c.type]); + lua_setfield(L, -2, "type"); + + assert(c.axis != COLLISION_AXIS_NONE); + lua_pushstring(L, collision_axis_str[c.axis]); + lua_setfield(L, -2, "axis"); + + if (c.type == COLLISION_NODE) { + push_v3s16(L, c.node_p); + lua_setfield(L, -2, "node_pos"); + } + + push_v3f(L, c.old_speed / BS); + lua_setfield(L, -2, "old_speed"); + + push_v3f(L, c.new_speed / BS); + lua_setfield(L, -2, "new_speed"); + + lua_rawseti(L, -2, i++); + } + lua_setfield(L, -2, "collisions"); + /**/ +} diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 9e755682f..8f32e58eb 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -63,7 +63,9 @@ struct EnumString; struct NoiseParams; class Schematic; class ServerActiveObject; +struct collisionMoveResult; +extern struct EnumString es_TileAnimationType[]; ContentFeatures read_content_features (lua_State *L, int index); void push_content_features (lua_State *L, @@ -196,4 +198,4 @@ void push_hud_element (lua_State *L, HudElement *elem); HudElementStat read_hud_change (lua_State *L, HudElement *elem, void **value); -extern struct EnumString es_TileAnimationType[]; +void push_collision_move_result(lua_State *L, const collisionMoveResult &res); diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp index 26c7e8cd4..ea9320051 100644 --- a/src/script/cpp_api/s_entity.cpp +++ b/src/script/cpp_api/s_entity.cpp @@ -178,12 +178,11 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id, lua_pop(L, 1); } -void ScriptApiEntity::luaentity_Step(u16 id, float dtime) +void ScriptApiEntity::luaentity_Step(u16 id, float dtime, + const collisionMoveResult *moveresult) { SCRIPTAPI_PRECHECKHEADER - //infostream<<"scriptapi_luaentity_step: id="<getScriptIface()->luaentity_Step(m_id, dtime); + if(m_registered) { + m_env->getScriptIface()->luaentity_Step(m_id, dtime, moveresult_p); } if (!send_recommended) -- cgit v1.2.3 From a36c9c3e930608386b983ea76158793fe9d622f6 Mon Sep 17 00:00:00 2001 From: ANAND Date: Tue, 28 Apr 2020 23:00:57 +0530 Subject: Fix breath_bar scaling; delay breath_bar hiding by one second (#8271) PLAYER_MAX_BREATH_DEFAULT was earlier set to 11, so that 10 bubbles are shown before the breath bar disappears. Now, PLAYER_MAX_BREATH_DEFAULT is set to 10, and the breath_bar scaling code in builtin has been tweaked to show all 10 bubbles before hiding the breath_bar --- builtin/game/constants.lua | 2 +- builtin/game/statbars.lua | 36 +++++++++++++++++++++++------------- src/constants.h | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/builtin/game/constants.lua b/builtin/game/constants.lua index 0ee2a7237..54eeea50f 100644 --- a/builtin/game/constants.lua +++ b/builtin/game/constants.lua @@ -24,7 +24,7 @@ core.MAP_BLOCKSIZE = 16 -- Default maximal HP of a player core.PLAYER_MAX_HP_DEFAULT = 20 -- Default maximal breath of a player -core.PLAYER_MAX_BREATH_DEFAULT = 11 +core.PLAYER_MAX_BREATH_DEFAULT = 10 -- light.h -- Maximum value for node 'light_source' parameter diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua index 46c947b60..6b5b54428 100644 --- a/builtin/game/statbars.lua +++ b/builtin/game/statbars.lua @@ -3,22 +3,22 @@ local enable_damage = core.settings:get_bool("enable_damage") local health_bar_definition = { hud_elem_type = "statbar", - position = { x=0.5, y=1 }, + position = {x = 0.5, y = 1}, text = "heart.png", number = core.PLAYER_MAX_HP_DEFAULT, direction = 0, - size = { x=24, y=24 }, - offset = { x=(-10*24)-25, y=-(48+24+16)}, + size = {x = 24, y = 24}, + offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)}, } local breath_bar_definition = { hud_elem_type = "statbar", - position = { x=0.5, y=1 }, + position = {x = 0.5, y = 1}, text = "bubble.png", number = core.PLAYER_MAX_BREATH_DEFAULT, direction = 0, - size = { x=24, y=24 }, - offset = {x=25,y=-(48+24+16)}, + size = {x = 24, y = 24}, + offset = {x = 25, y= -(48 + 24 + 16)}, } local hud_ids = {} @@ -26,7 +26,7 @@ local hud_ids = {} local function scaleToDefault(player, field) -- Scale "hp" or "breath" to the default dimensions local current = player["get_" .. field](player) - local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"] + local nominal = core["PLAYER_MAX_" .. field:upper() .. "_DEFAULT"] local max_display = math.max(nominal, math.max(player:get_properties()[field .. "_max"], current)) return current / max_display * nominal @@ -49,6 +49,7 @@ local function update_builtin_statbars(player) local hud = hud_ids[name] local immortal = player:get_armor_groups().immortal == 1 + if flags.healthbar and enable_damage and not immortal then local number = scaleToDefault(player, "hp") if hud.id_healthbar == nil then @@ -63,19 +64,28 @@ local function update_builtin_statbars(player) hud.id_healthbar = nil end + local show_breathbar = flags.breathbar and enable_damage and not immortal + + local breath = player:get_breath() local breath_max = player:get_properties().breath_max - if flags.breathbar and enable_damage and not immortal and - player:get_breath() < breath_max then + if show_breathbar and breath <= breath_max then local number = 2 * scaleToDefault(player, "breath") - if hud.id_breathbar == nil then + if not hud.id_breathbar and breath < breath_max then local hud_def = table.copy(breath_bar_definition) hud_def.number = number hud.id_breathbar = player:hud_add(hud_def) - else + elseif hud.id_breathbar then player:hud_change(hud.id_breathbar, "number", number) end - elseif hud.id_breathbar then - player:hud_remove(hud.id_breathbar) + end + + if hud.id_breathbar and (not show_breathbar or breath == breath_max) then + minetest.after(1, function(player_name, breath_bar) + local player = minetest.get_player_by_name(player_name) + if player then + player:hud_remove(breath_bar) + end + end, name, hud.id_breathbar) hud.id_breathbar = nil end end diff --git a/src/constants.h b/src/constants.h index 0a8b22e15..c17f3b6af 100644 --- a/src/constants.h +++ b/src/constants.h @@ -93,7 +93,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define PLAYER_MAX_HP_DEFAULT 20 // Default maximal breath of a player -#define PLAYER_MAX_BREATH_DEFAULT 11 +#define PLAYER_MAX_BREATH_DEFAULT 10 // Number of different files to try to save a player to if the first fails // (because of a case-insensitive filesystem) -- cgit v1.2.3 From 56bababcdfce097a4e08cc3d1de8d798e7999ce7 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Mon, 27 Apr 2020 08:31:37 +0200 Subject: Add MetricsBackend with prometheus counter support --- Dockerfile | 22 +++++-- README.md | 1 + builtin/settingtypes.txt | 6 ++ src/CMakeLists.txt | 26 ++++++++ src/cmake_config.h.in | 1 + src/defaultsettings.cpp | 3 + src/map.cpp | 11 +++- src/map.h | 6 +- src/server.cpp | 57 ++++++++++++---- src/server.h | 21 ++++-- src/server/mods.cpp | 1 + src/server/mods.h | 3 + src/util/CMakeLists.txt | 1 + src/util/metricsbackend.cpp | 140 ++++++++++++++++++++++++++++++++++++++++ src/util/metricsbackend.h | 140 ++++++++++++++++++++++++++++++++++++++++ util/ci/build_prometheus_cpp.sh | 13 ++++ 16 files changed, 427 insertions(+), 25 deletions(-) create mode 100644 src/util/metricsbackend.cpp create mode 100644 src/util/metricsbackend.h create mode 100755 util/ci/build_prometheus_cpp.sh (limited to 'src') diff --git a/Dockerfile b/Dockerfile index 7c1107288..72343ab9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,15 +21,29 @@ WORKDIR /usr/src/minetest RUN apk add --no-cache git build-base irrlicht-dev cmake bzip2-dev libpng-dev \ jpeg-dev libxxf86vm-dev mesa-dev sqlite-dev libogg-dev \ libvorbis-dev openal-soft-dev curl-dev freetype-dev zlib-dev \ - gmp-dev jsoncpp-dev postgresql-dev && \ + gmp-dev jsoncpp-dev postgresql-dev ca-certificates && \ git clone --depth=1 -b ${MINETEST_GAME_VERSION} https://github.com/minetest/minetest_game.git ./games/minetest_game && \ - rm -fr ./games/minetest_game/.git && \ - mkdir build && \ + rm -fr ./games/minetest_game/.git + +WORKDIR /usr/src/ +RUN git clone --recursive https://github.com/jupp0r/prometheus-cpp/ && \ + mkdir prometheus-cpp/build && \ + cd prometheus-cpp/build && \ + cmake .. \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_TESTING=0 && \ + make -j2 && \ + make install + +WORKDIR /usr/src/minetest +RUN mkdir build && \ cd build && \ cmake .. \ -DCMAKE_INSTALL_PREFIX=/usr/local \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SERVER=TRUE \ + -DENABLE_PROMETHEUS=TRUE \ -DBUILD_UNITTESTS=FALSE \ -DBUILD_CLIENT=FALSE && \ make -j2 && \ @@ -49,6 +63,6 @@ COPY --from=0 /usr/local/share/doc/minetest/minetest.conf.example /etc/minetest/ USER minetest:minetest -EXPOSE 30000/udp +EXPOSE 30000/udp 30000/tcp CMD ["/usr/local/bin/minetestserver", "--config", "/etc/minetest/minetest.conf"] diff --git a/README.md b/README.md index b3b2b863e..024e7b691 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,7 @@ General options and their default values: ENABLE_SPATIAL=ON - Build with LibSpatial; Speeds up AreaStores ENABLE_SOUND=ON - Build with OpenAL, libogg & libvorbis; in-game sounds ENABLE_LUAJIT=ON - Build with LuaJIT (much faster than non-JIT Lua) + ENABLE_PROMETHEUS=OFF - Build with Prometheus metrics exporter (listens on tcp/30000 by default) ENABLE_SYSTEM_GMP=ON - Use GMP from system (much faster than bundled mini-gmp) ENABLE_SYSTEM_JSONCPP=OFF - Use JsonCPP from system OPENGL_GL_PREFERENCE=LEGACY - Linux client build only; See CMake Policy CMP0072 for reference diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index b9228f384..165ed8c06 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -955,6 +955,12 @@ address (Server address) string # Note that the port field in the main menu overrides this setting. remote_port (Remote port) int 30000 1 65535 +# Prometheus listener address. +# If minetest is compiled with ENABLE_PROMETHEUS option enabled, +# enable metrics listener for Prometheus on that address. +# Metrics can be fetch on http://127.0.0.1:30000/metrics +prometheus_listener_address (Prometheus listener address) string 127.0.0.1:30000 + # Save the map received by the client on disk. enable_local_map_saving (Saving map received from server) bool false diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b416faaf3..710d9e13e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -217,6 +217,26 @@ endif(ENABLE_REDIS) find_package(SQLite3 REQUIRED) +OPTION(ENABLE_PROMETHEUS "Enable prometheus client support" FALSE) +set(USE_PROMETHEUS FALSE) + +if(ENABLE_PROMETHEUS) + find_path(PROMETHEUS_CPP_INCLUDE_DIR NAMES prometheus/counter.h) + find_library(PROMETHEUS_PULL_LIBRARY NAMES prometheus-cpp-pull) + find_library(PROMETHEUS_CORE_LIBRARY NAMES prometheus-cpp-core) + if(PROMETHEUS_CPP_INCLUDE_DIR AND PROMETHEUS_PULL_LIBRARY AND PROMETHEUS_CORE_LIBRARY) + set(PROMETHEUS_LIBRARIES ${PROMETHEUS_PULL_LIBRARY} ${PROMETHEUS_CORE_LIBRARY}) + set(USE_PROMETHEUS TRUE) + include_directories(${PROMETHEUS_CPP_INCLUDE_DIR}) + endif(PROMETHEUS_CPP_INCLUDE_DIR AND PROMETHEUS_PULL_LIBRARY AND PROMETHEUS_CORE_LIBRARY) +endif(ENABLE_PROMETHEUS) + +if(USE_PROMETHEUS) + message(STATUS "Prometheus client enabled.") +else(USE_PROMETHEUS) + message(STATUS "Prometheus client disabled.") +endif(USE_PROMETHEUS) + OPTION(ENABLE_SPATIAL "Enable SpatialIndex AreaStore backend" TRUE) set(USE_SPATIAL FALSE) @@ -597,6 +617,9 @@ if(BUILD_CLIENT) if (USE_REDIS) target_link_libraries(${PROJECT_NAME} ${REDIS_LIBRARY}) endif() + if (USE_PROMETHEUS) + target_link_libraries(${PROJECT_NAME} ${PROMETHEUS_LIBRARIES}) + endif() if (USE_SPATIAL) target_link_libraries(${PROJECT_NAME} ${SPATIAL_LIBRARY}) endif() @@ -632,6 +655,9 @@ if(BUILD_SERVER) if (USE_REDIS) target_link_libraries(${PROJECT_NAME}server ${REDIS_LIBRARY}) endif() + if (USE_PROMETHEUS) + target_link_libraries(${PROJECT_NAME}server ${PROMETHEUS_LIBRARIES}) + endif() if (USE_SPATIAL) target_link_libraries(${PROJECT_NAME}server ${SPATIAL_LIBRARY}) endif() diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index cac6335d4..cfcee4b58 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -23,6 +23,7 @@ #cmakedefine01 USE_LEVELDB #cmakedefine01 USE_LUAJIT #cmakedefine01 USE_POSTGRESQL +#cmakedefine01 USE_PROMETHEUS #cmakedefine01 USE_SPATIAL #cmakedefine01 USE_SYSTEM_GMP #cmakedefine01 USE_REDIS diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index b6b1ce1f2..06daa3b94 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -334,6 +334,9 @@ void set_default_settings(Settings *settings) // Server settings->setDefault("disable_escape_sequences", "false"); settings->setDefault("strip_color_codes", "false"); +#if USE_PROMETHEUS + settings->setDefault("prometheus_listener_address", "127.0.0.1:30000"); +#endif // Network settings->setDefault("enable_ipv6", "true"); diff --git a/src/map.cpp b/src/map.cpp index 12e122124..5f1b984a4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -144,7 +144,7 @@ bool Map::isNodeUnderground(v3s16 p) { v3s16 blockpos = getNodeBlockPos(p); MapBlock *block = getBlockNoCreateNoEx(blockpos); - return block && block->getIsUnderground(); + return block && block->getIsUnderground(); } bool Map::isValidPosition(v3s16 p) @@ -1187,7 +1187,7 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) ServerMap */ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, - EmergeManager *emerge): + EmergeManager *emerge, MetricsBackend *mb): Map(dout_server, gamedef), settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"), m_emerge(emerge) @@ -1221,6 +1221,8 @@ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef, m_savedir = savedir; m_map_saving_enabled = false; + m_save_time_counter = mb->addCounter("minetest_core_map_save_time", "Map save time (in nanoseconds)"); + try { // If directory exists, check contents and load if possible if (fs::PathExists(m_savedir)) { @@ -1777,6 +1779,8 @@ void ServerMap::save(ModifiedState save_level) return; } + u64 start_time = porting::getTimeNs(); + if(save_level == MOD_STATE_CLEAN) infostream<<"ServerMap: Saving whole map, this can take time." <increment(end_time - start_time); } void ServerMap::listAllLoadableBlocks(std::vector &dst) diff --git a/src/map.h b/src/map.h index ff6b20c4f..77ee4da9e 100644 --- a/src/map.h +++ b/src/map.h @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "voxel.h" #include "modifiedstate.h" #include "util/container.h" +#include "util/metricsbackend.h" #include "nodetimer.h" #include "map_settings_manager.h" #include "debug.h" @@ -45,6 +46,7 @@ class NodeMetadata; class IGameDef; class IRollbackManager; class EmergeManager; +class MetricsBackend; class ServerEnvironment; struct BlockMakeData; @@ -324,7 +326,7 @@ public: /* savedir: directory to which map data should be saved */ - ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge); + ServerMap(const std::string &savedir, IGameDef *gamedef, EmergeManager *emerge, MetricsBackend *mb); ~ServerMap(); s32 mapType() const @@ -449,6 +451,8 @@ private: bool m_map_metadata_changed = true; MapDatabase *dbase = nullptr; MapDatabase *dbase_ro = nullptr; + + MetricCounterPtr m_save_time_counter; }; diff --git a/src/server.cpp b/src/server.cpp index af6d3e40d..a7eb52837 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -229,18 +229,46 @@ Server::Server( m_nodedef(createNodeDefManager()), m_craftdef(createCraftDefManager()), m_thread(new ServerThread(this)), - m_uptime(0), m_clients(m_con), m_admin_chat(iface), m_modchannel_mgr(new ModChannelMgr()) { - m_lag = g_settings->getFloat("dedicated_server_step"); - if (m_path_world.empty()) throw ServerError("Supplied empty world path"); if (!gamespec.isValid()) throw ServerError("Supplied invalid gamespec"); + +#if USE_PROMETHEUS + m_metrics_backend = std::unique_ptr(createPrometheusMetricsBackend()); +#else + m_metrics_backend = std::unique_ptr(new MetricsBackend()); +#endif + + m_uptime_counter = m_metrics_backend->addCounter("minetest_core_server_uptime", "Server uptime (in seconds)"); + m_player_gauge = m_metrics_backend->addGauge("minetest_core_player_number", "Number of connected players"); + + m_timeofday_gauge = m_metrics_backend->addGauge( + "minetest_core_timeofday", + "Time of day value"); + + m_lag_gauge = m_metrics_backend->addGauge( + "minetest_core_latency", + "Latency value (in seconds)"); + + m_aom_buffer_counter = m_metrics_backend->addCounter( + "minetest_core_aom_generated_count", + "Number of active object messages generated"); + + m_packet_recv_counter = m_metrics_backend->addCounter( + "minetest_core_server_packet_recv", + "Processable packets received"); + + m_packet_recv_processed_counter = m_metrics_backend->addCounter( + "minetest_core_server_packet_recv_processed", + "Valid received packets processed"); + + m_lag_gauge->set(g_settings->getFloat("dedicated_server_step")); } Server::~Server() @@ -353,7 +381,7 @@ void Server::init() MutexAutoLock envlock(m_env_mutex); // Create the Map (loads map_meta.txt, overriding configured mapgen params) - ServerMap *servermap = new ServerMap(m_path_world, this, m_emerge); + ServerMap *servermap = new ServerMap(m_path_world, this, m_emerge, m_metrics_backend.get()); // Initialize scripting infostream << "Server: Initializing Lua" << std::endl; @@ -511,9 +539,7 @@ void Server::AsyncRunStep(bool initial_step) /* Update uptime */ - { - m_uptime.set(m_uptime.get() + dtime); - } + m_uptime_counter->increment(dtime); handlePeerChanges(); @@ -527,11 +553,13 @@ void Server::AsyncRunStep(bool initial_step) */ m_time_of_day_send_timer -= dtime; - if(m_time_of_day_send_timer < 0.0) { + if (m_time_of_day_send_timer < 0.0) { m_time_of_day_send_timer = g_settings->getFloat("time_send_interval"); u16 time = m_env->getTimeOfDay(); float time_speed = g_settings->getFloat("time_speed"); SendTimeOfDay(PEER_ID_INEXISTENT, time, time_speed); + + m_timeofday_gauge->set(time); } { @@ -603,7 +631,7 @@ void Server::AsyncRunStep(bool initial_step) } m_clients.step(dtime); - m_lag += (m_lag > dtime ? -1 : 1) * dtime/100; + m_lag_gauge->increment((m_lag_gauge->get() > dtime ? -1 : 1) * dtime/100); #if USE_CURL // send masterserver announce { @@ -614,9 +642,9 @@ void Server::AsyncRunStep(bool initial_step) ServerList::AA_START, m_bind_addr.getPort(), m_clients.getPlayerNames(), - m_uptime.get(), + m_uptime_counter->get(), m_env->getGameTime(), - m_lag, + m_lag_gauge->get(), m_gamespec.id, Mapgen::getMapgenName(m_emerge->mgparams->mgtype), m_modmgr->getMods(), @@ -638,6 +666,7 @@ void Server::AsyncRunStep(bool initial_step) const RemoteClientMap &clients = m_clients.getClientList(); ScopeProfiler sp(g_profiler, "Server: update objects within range"); + m_player_gauge->set(clients.size()); for (const auto &client_it : clients) { RemoteClient *client = client_it.second; @@ -703,6 +732,8 @@ void Server::AsyncRunStep(bool initial_step) message_list->push_back(aom); } + m_aom_buffer_counter->increment(buffered_messages.size()); + m_clients.lock(); const RemoteClientMap &clients = m_clients.getClientList(); // Route data to every client @@ -943,7 +974,9 @@ void Server::Receive() } peer_id = pkt.getPeerId(); + m_packet_recv_counter->increment(); ProcessData(&pkt); + m_packet_recv_processed_counter->increment(); } catch (const con::InvalidIncomingDataException &e) { infostream << "Server::Receive(): InvalidIncomingDataException: what()=" << e.what() << std::endl; @@ -3127,7 +3160,7 @@ std::wstring Server::getStatusString() // Version os << L"version=" << narrow_to_wide(g_version_string); // Uptime - os << L", uptime=" << m_uptime.get(); + os << L", uptime=" << m_uptime_counter->get(); // Max lag estimate os << L", max_lag=" << (m_env ? m_env->getMaxLagEstimate() : 0); diff --git a/src/server.h b/src/server.h index b995aba28..71059dd30 100644 --- a/src/server.h +++ b/src/server.h @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "util/thread.h" #include "util/basic_macros.h" +#include "util/metricsbackend.h" #include "serverenvironment.h" #include "clientiface.h" #include "chatmessage.h" @@ -203,7 +204,7 @@ public: // Connection must be locked when called std::wstring getStatusString(); - inline double getUptime() const { return m_uptime.m_value; } + inline double getUptime() const { return m_uptime_counter->get(); } // read shutdown state inline bool isShutdownRequested() const { return m_shutdown_state.is_requested; } @@ -591,9 +592,6 @@ private: float m_step_dtime = 0.0f; std::mutex m_step_dtime_mutex; - // current server step lag counter - float m_lag; - // The server mainly operates in this thread ServerThread *m_thread = nullptr; @@ -602,8 +600,6 @@ private: */ // Timer for sending time of day over network float m_time_of_day_send_timer = 0.0f; - // Uptime of server in seconds - MutexedVariable m_uptime; /* Client interface @@ -677,6 +673,19 @@ private: // ModChannel manager std::unique_ptr m_modchannel_mgr; + + // Global server metrics backend + std::unique_ptr m_metrics_backend; + + // Server metrics + MetricCounterPtr m_uptime_counter; + MetricGaugePtr m_player_gauge; + MetricGaugePtr m_timeofday_gauge; + // current server step lag + MetricGaugePtr m_lag_gauge; + MetricCounterPtr m_aom_buffer_counter; + MetricCounterPtr m_packet_recv_counter; + MetricCounterPtr m_packet_recv_processed_counter; }; /* diff --git a/src/server/mods.cpp b/src/server/mods.cpp index c8d8a28e2..6ac530739 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_server.h" #include "content/subgames.h" #include "porting.h" +#include "util/metricsbackend.h" /** * Manage server mods diff --git a/src/server/mods.h b/src/server/mods.h index 2bc1aa22f..54774bd86 100644 --- a/src/server/mods.h +++ b/src/server/mods.h @@ -20,7 +20,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "content/mods.h" +#include +class MetricsBackend; +class MetricCounter; class ServerScripting; /** diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 199d3aeaa..cd2e468d1 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -5,6 +5,7 @@ set(UTIL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/directiontables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/enriched_string.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ieee_float.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/metricsbackend.cpp ${CMAKE_CURRENT_SOURCE_DIR}/numeric.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pointedthing.cpp ${CMAKE_CURRENT_SOURCE_DIR}/quicktune.cpp diff --git a/src/util/metricsbackend.cpp b/src/util/metricsbackend.cpp new file mode 100644 index 000000000..4454557a3 --- /dev/null +++ b/src/util/metricsbackend.cpp @@ -0,0 +1,140 @@ +/* +Minetest +Copyright (C) 2013-2020 Minetest core developers team + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "metricsbackend.h" +#if USE_PROMETHEUS +#include +#include +#include +#include +#include "log.h" +#include "settings.h" +#endif + +MetricCounterPtr MetricsBackend::addCounter( + const std::string &name, const std::string &help_str) +{ + return std::make_shared(name, help_str); +} + +MetricGaugePtr MetricsBackend::addGauge( + const std::string &name, const std::string &help_str) +{ + return std::make_shared(name, help_str); +} + +#if USE_PROMETHEUS + +class PrometheusMetricCounter : public MetricCounter +{ +public: + PrometheusMetricCounter() = delete; + + PrometheusMetricCounter(const std::string &name, const std::string &help_str, + std::shared_ptr registry) : + MetricCounter(), + m_family(prometheus::BuildCounter() + .Name(name) + .Help(help_str) + .Register(*registry)), + m_counter(m_family.Add({})) + { + } + + virtual ~PrometheusMetricCounter() {} + + virtual void increment(double number) { m_counter.Increment(number); } + virtual double get() const { return m_counter.Value(); } + +private: + prometheus::Family &m_family; + prometheus::Counter &m_counter; +}; + +class PrometheusMetricGauge : public MetricGauge +{ +public: + PrometheusMetricGauge() = delete; + + PrometheusMetricGauge(const std::string &name, const std::string &help_str, + std::shared_ptr registry) : + MetricGauge(), + m_family(prometheus::BuildGauge() + .Name(name) + .Help(help_str) + .Register(*registry)), + m_gauge(m_family.Add({})) + { + } + + virtual ~PrometheusMetricGauge() {} + + virtual void increment(double number) { m_gauge.Increment(number); } + virtual void decrement(double number) { m_gauge.Decrement(number); } + virtual void set(double number) { m_gauge.Set(number); } + virtual double get() const { return m_gauge.Value(); } + +private: + prometheus::Family &m_family; + prometheus::Gauge &m_gauge; +}; + +class PrometheusMetricsBackend : public MetricsBackend +{ +public: + PrometheusMetricsBackend(const std::string &addr) : + MetricsBackend(), m_exposer(std::unique_ptr( + new prometheus::Exposer(addr))), + m_registry(std::make_shared()) + { + m_exposer->RegisterCollectable(m_registry); + } + + virtual ~PrometheusMetricsBackend() {} + + virtual MetricCounterPtr addCounter( + const std::string &name, const std::string &help_str); + virtual MetricGaugePtr addGauge( + const std::string &name, const std::string &help_str); + +private: + std::unique_ptr m_exposer; + std::shared_ptr m_registry; +}; + +MetricCounterPtr PrometheusMetricsBackend::addCounter( + const std::string &name, const std::string &help_str) +{ + return std::make_shared(name, help_str, m_registry); +} + +MetricGaugePtr PrometheusMetricsBackend::addGauge( + const std::string &name, const std::string &help_str) +{ + return std::make_shared(name, help_str, m_registry); +} + +MetricsBackend *createPrometheusMetricsBackend() +{ + std::string addr; + g_settings->getNoEx("prometheus_listener_address", addr); + return new PrometheusMetricsBackend(addr); +} + +#endif diff --git a/src/util/metricsbackend.h b/src/util/metricsbackend.h new file mode 100644 index 000000000..c37306392 --- /dev/null +++ b/src/util/metricsbackend.h @@ -0,0 +1,140 @@ +/* +Minetest +Copyright (C) 2013-2020 Minetest core developers team + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once +#include +#include "config.h" +#include "util/thread.h" + +class MetricCounter +{ +public: + MetricCounter() = default; + + virtual ~MetricCounter() {} + + virtual void increment(double number = 1.0) = 0; + virtual double get() const = 0; +}; + +typedef std::shared_ptr MetricCounterPtr; + +class SimpleMetricCounter : public MetricCounter +{ +public: + SimpleMetricCounter() = delete; + + virtual ~SimpleMetricCounter() {} + + SimpleMetricCounter(const std::string &name, const std::string &help_str) : + MetricCounter(), m_name(name), m_help_str(help_str), + m_counter(0.0) + { + } + + virtual void increment(double number) + { + MutexAutoLock lock(m_mutex); + m_counter += number; + } + virtual double get() const + { + MutexAutoLock lock(m_mutex); + return m_counter; + } + +private: + std::string m_name; + std::string m_help_str; + + mutable std::mutex m_mutex; + double m_counter; +}; + +class MetricGauge +{ +public: + MetricGauge() = default; + virtual ~MetricGauge() {} + + virtual void increment(double number = 1.0) = 0; + virtual void decrement(double number = 1.0) = 0; + virtual void set(double number) = 0; + virtual double get() const = 0; +}; + +typedef std::shared_ptr MetricGaugePtr; + +class SimpleMetricGauge : public MetricGauge +{ +public: + SimpleMetricGauge() = delete; + + SimpleMetricGauge(const std::string &name, const std::string &help_str) : + MetricGauge(), m_name(name), m_help_str(help_str), m_gauge(0.0) + { + } + + virtual ~SimpleMetricGauge() {} + + virtual void increment(double number) + { + MutexAutoLock lock(m_mutex); + m_gauge += number; + } + virtual void decrement(double number) + { + MutexAutoLock lock(m_mutex); + m_gauge -= number; + } + virtual void set(double number) + { + MutexAutoLock lock(m_mutex); + m_gauge = number; + } + virtual double get() const + { + MutexAutoLock lock(m_mutex); + return m_gauge; + } + +private: + std::string m_name; + std::string m_help_str; + + mutable std::mutex m_mutex; + double m_gauge; +}; + +class MetricsBackend +{ +public: + MetricsBackend() = default; + + virtual ~MetricsBackend() {} + + virtual MetricCounterPtr addCounter( + const std::string &name, const std::string &help_str); + virtual MetricGaugePtr addGauge( + const std::string &name, const std::string &help_str); +}; + +#if USE_PROMETHEUS +MetricsBackend *createPrometheusMetricsBackend(); +#endif diff --git a/util/ci/build_prometheus_cpp.sh b/util/ci/build_prometheus_cpp.sh new file mode 100755 index 000000000..edfd574cd --- /dev/null +++ b/util/ci/build_prometheus_cpp.sh @@ -0,0 +1,13 @@ +#! /bin/bash -eu + +cd /tmp +git clone --recursive https://github.com/jupp0r/prometheus-cpp +mkdir prometheus-cpp/build +cd prometheus-cpp/build +cmake .. \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_TESTING=0 +make -j2 +sudo make install + -- cgit v1.2.3 From 3f275d799cdcd61928854bb98ca5eb74af22f31e Mon Sep 17 00:00:00 2001 From: Juozas Date: Wed, 29 Apr 2020 13:49:55 +0300 Subject: Fix gettext detection and locale building (#9772) broken since a368e7e --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 710d9e13e..dd68ceec9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,7 +62,7 @@ set(USE_GETTEXT FALSE) if(ENABLE_GETTEXT) find_package(GettextLib) - if(GETTEXT_FOUND) + if(GETTEXTLIB_FOUND) if(WIN32) message(STATUS "GetText library: ${GETTEXT_LIBRARY}") message(STATUS "GetText DLL: ${GETTEXT_DLL}") @@ -70,7 +70,7 @@ if(ENABLE_GETTEXT) endif() set(USE_GETTEXT TRUE) message(STATUS "GetText enabled; locales found: ${GETTEXT_AVAILABLE_LOCALES}") - endif(GETTEXT_FOUND) + endif(GETTEXTLIB_FOUND) else() mark_as_advanced(GETTEXT_ICONV_DLL GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT) message(STATUS "GetText disabled.") @@ -680,7 +680,7 @@ set(GETTEXT_BLACKLISTED_LOCALES option(APPLY_LOCALE_BLACKLIST "Use a blacklist to avoid broken locales" TRUE) -if (GETTEXT_FOUND AND APPLY_LOCALE_BLACKLIST) +if (GETTEXTLIB_FOUND AND APPLY_LOCALE_BLACKLIST) set(GETTEXT_USED_LOCALES "") foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES}) if (NOT ";${GETTEXT_BLACKLISTED_LOCALES};" MATCHES ";${LOCALE};") -- cgit v1.2.3 From 74d9b6010fd42573d20cdbe78f7aaa07badfbf1b Mon Sep 17 00:00:00 2001 From: Lejo Date: Fri, 1 May 2020 16:47:17 +0200 Subject: Give the online lua mainmenu also the client_list and mods (#8691) --- doc/menu_lua_api.txt | 25 ++++++------ src/script/lua_api/l_mainmenu.cpp | 81 +++++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index df6424ad7..8f5460acb 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -156,18 +156,21 @@ core.get_favorites(location) -> list of favorites (possible in async calls) ^ location: "local" or "online" ^ returns { [1] = { - clients = , - clients_max = , - version = , - password = , - creative = , - damage = , - pvp = , - description = , - name = , - address =
, - port = + clients = , + clients_max = , + version = , + password = , + creative = , + damage = , + pvp = , + description = , + name = , + address =
, + port = + clients_list = + mods = }, + ... } core.delete_favorite(id, location) -> success diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 867e84e13..a76e9f079 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -280,8 +280,8 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) { std::string listtype = "local"; - if (!lua_isnone(L,1)) { - listtype = luaL_checkstring(L,1); + if (!lua_isnone(L, 1)) { + listtype = luaL_checkstring(L, 1); } std::vector servers; @@ -298,7 +298,7 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) for (const Json::Value &server : servers) { - lua_pushnumber(L,index); + lua_pushnumber(L, index); lua_newtable(L); int top_lvl2 = lua_gettop(L); @@ -306,11 +306,11 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) if (!server["clients"].asString().empty()) { std::string clients_raw = server["clients"].asString(); char* endptr = 0; - int numbervalue = strtol(clients_raw.c_str(),&endptr,10); + int numbervalue = strtol(clients_raw.c_str(), &endptr,10); if ((!clients_raw.empty()) && (*endptr == 0)) { - lua_pushstring(L,"clients"); - lua_pushnumber(L,numbervalue); + lua_pushstring(L, "clients"); + lua_pushnumber(L, numbervalue); lua_settable(L, top_lvl2); } } @@ -319,83 +319,83 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) std::string clients_max_raw = server["clients_max"].asString(); char* endptr = 0; - int numbervalue = strtol(clients_max_raw.c_str(),&endptr,10); + int numbervalue = strtol(clients_max_raw.c_str(), &endptr,10); if ((!clients_max_raw.empty()) && (*endptr == 0)) { - lua_pushstring(L,"clients_max"); - lua_pushnumber(L,numbervalue); + lua_pushstring(L, "clients_max"); + lua_pushnumber(L, numbervalue); lua_settable(L, top_lvl2); } } if (!server["version"].asString().empty()) { - lua_pushstring(L,"version"); + lua_pushstring(L, "version"); std::string topush = server["version"].asString(); - lua_pushstring(L,topush.c_str()); + lua_pushstring(L, topush.c_str()); lua_settable(L, top_lvl2); } if (!server["proto_min"].asString().empty()) { - lua_pushstring(L,"proto_min"); + lua_pushstring(L, "proto_min"); lua_pushinteger(L, server["proto_min"].asInt()); lua_settable(L, top_lvl2); } if (!server["proto_max"].asString().empty()) { - lua_pushstring(L,"proto_max"); + lua_pushstring(L, "proto_max"); lua_pushinteger(L, server["proto_max"].asInt()); lua_settable(L, top_lvl2); } if (!server["password"].asString().empty()) { - lua_pushstring(L,"password"); + lua_pushstring(L, "password"); lua_pushboolean(L, server["password"].asBool()); lua_settable(L, top_lvl2); } if (!server["creative"].asString().empty()) { - lua_pushstring(L,"creative"); + lua_pushstring(L, "creative"); lua_pushboolean(L, server["creative"].asBool()); lua_settable(L, top_lvl2); } if (!server["damage"].asString().empty()) { - lua_pushstring(L,"damage"); + lua_pushstring(L, "damage"); lua_pushboolean(L, server["damage"].asBool()); lua_settable(L, top_lvl2); } if (!server["pvp"].asString().empty()) { - lua_pushstring(L,"pvp"); + lua_pushstring(L, "pvp"); lua_pushboolean(L, server["pvp"].asBool()); lua_settable(L, top_lvl2); } if (!server["description"].asString().empty()) { - lua_pushstring(L,"description"); + lua_pushstring(L, "description"); std::string topush = server["description"].asString(); - lua_pushstring(L,topush.c_str()); + lua_pushstring(L, topush.c_str()); lua_settable(L, top_lvl2); } if (!server["name"].asString().empty()) { - lua_pushstring(L,"name"); + lua_pushstring(L, "name"); std::string topush = server["name"].asString(); - lua_pushstring(L,topush.c_str()); + lua_pushstring(L, topush.c_str()); lua_settable(L, top_lvl2); } if (!server["address"].asString().empty()) { - lua_pushstring(L,"address"); + lua_pushstring(L, "address"); std::string topush = server["address"].asString(); - lua_pushstring(L,topush.c_str()); + lua_pushstring(L, topush.c_str()); lua_settable(L, top_lvl2); } if (!server["port"].asString().empty()) { - lua_pushstring(L,"port"); + lua_pushstring(L, "port"); std::string topush = server["port"].asString(); - lua_pushstring(L,topush.c_str()); + lua_pushstring(L, topush.c_str()); lua_settable(L, top_lvl2); } @@ -406,6 +406,37 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) lua_settable(L, top_lvl2); } + if (server["clients_list"].isArray()) { + unsigned int index_lvl2 = 1; + lua_pushstring(L, "clients_list"); + lua_newtable(L); + int top_lvl3 = lua_gettop(L); + for (const Json::Value &client : server["clients_list"]) { + lua_pushnumber(L, index_lvl2); + std::string topush = client.asString(); + lua_pushstring(L, topush.c_str()); + lua_settable(L, top_lvl3); + index_lvl2++; + } + lua_settable(L, top_lvl2); + } + + if (server["mods"].isArray()) { + unsigned int index_lvl2 = 1; + lua_pushstring(L, "mods"); + lua_newtable(L); + int top_lvl3 = lua_gettop(L); + for (const Json::Value &mod : server["mods"]) { + + lua_pushnumber(L, index_lvl2); + std::string topush = mod.asString(); + lua_pushstring(L, topush.c_str()); + lua_settable(L, top_lvl3); + index_lvl2++; + } + lua_settable(L, top_lvl2); + } + lua_settable(L, top); index++; } -- cgit v1.2.3 From ac368af4fe27f61f5a4209cdfe90956ff745993c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 1 May 2020 21:44:28 +0200 Subject: Allow connection info to be missing from minetest.get_player_information() (#9739) fixes #9352 This reverts commit 23c907befea02005e2c0c87fca0131b60aace18a. --- doc/lua_api.txt | 11 +++-- src/network/connection.h | 6 +-- src/script/lua_api/l_server.cpp | 102 ++++++++++++++++++++-------------------- 3 files changed, 61 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 5e4e18b62..f9107b623 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4160,17 +4160,18 @@ Utilities { address = "127.0.0.1", -- IP address of client ip_version = 4, -- IPv4 / IPv6 + connection_uptime = 200, -- seconds since client connected + protocol_version = 32, -- protocol version used by client + formspec_version = 2, -- supported formspec version + lang_code = "fr" -- Language code used for translation + -- the following keys can be missing if no stats have been collected yet min_rtt = 0.01, -- minimum round trip time max_rtt = 0.2, -- maximum round trip time avg_rtt = 0.02, -- average round trip time min_jitter = 0.01, -- minimum packet time jitter max_jitter = 0.5, -- maximum packet time jitter avg_jitter = 0.03, -- average packet time jitter - connection_uptime = 200, -- seconds since client connected - protocol_version = 32, -- protocol version used by client - formspec_version = 2, -- supported formspec version - lang_code = "fr" -- Language code used for translation - -- following information is available on debug build only!!! + -- the following information is available in a debug build only!!! -- DO NOT USE IN MODS --ser_vers = 26, -- serialization version used by client --major = 0, -- major version number diff --git a/src/network/connection.h b/src/network/connection.h index 85f021c4c..47b0805ce 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -612,16 +612,16 @@ class Peer { struct rttstats { float jitter_min = FLT_MAX; float jitter_max = 0.0f; - float jitter_avg = -2.0f; + float jitter_avg = -1.0f; float min_rtt = FLT_MAX; float max_rtt = 0.0f; - float avg_rtt = -2.0f; + float avg_rtt = -1.0f; rttstats() = default; }; rttstats m_rtt; - float m_last_rtt = -2.0f; + float m_last_rtt = -1.0f; // current usage count unsigned int m_usage = 0; diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 7137484e8..b6754938e 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -138,53 +138,54 @@ int ModApiServer::l_get_player_ip(lua_State *L) // get_player_information(name) int ModApiServer::l_get_player_information(lua_State *L) { - NO_MAP_LOCK_REQUIRED; - const char * name = luaL_checkstring(L, 1); - RemotePlayer *player = dynamic_cast(getEnv(L))->getPlayer(name); - if (player == NULL) { + + Server *server = getServer(L); + + const char *name = luaL_checkstring(L, 1); + RemotePlayer *player = server->getEnv().getPlayer(name); + if (!player) { lua_pushnil(L); // no such player return 1; } Address addr; - try - { - addr = getServer(L)->getPeerAddress(player->getPeerId()); - } catch(const con::PeerNotFoundException &) { + try { + addr = server->getPeerAddress(player->getPeerId()); + } catch (const con::PeerNotFoundException &) { dstream << FUNCTION_NAME << ": peer was not found" << std::endl; lua_pushnil(L); // error return 1; } - float min_rtt,max_rtt,avg_rtt,min_jitter,max_jitter,avg_jitter; + float min_rtt, max_rtt, avg_rtt, min_jitter, max_jitter, avg_jitter; ClientState state; u32 uptime; u16 prot_vers; - u8 ser_vers,major,minor,patch; - std::string vers_string; - std::string lang_code; - -#define ERET(code) \ - if (!(code)) { \ - dstream << FUNCTION_NAME << ": peer was not found" << std::endl; \ - lua_pushnil(L); /* error */ \ - return 1; \ + u8 ser_vers, major, minor, patch; + std::string vers_string, lang_code; + + auto getConInfo = [&] (con::rtt_stat_type type, float *value) -> bool { + return server->getClientConInfo(player->getPeerId(), type, value); + }; + + bool have_con_info = + getConInfo(con::MIN_RTT, &min_rtt) && + getConInfo(con::MAX_RTT, &max_rtt) && + getConInfo(con::AVG_RTT, &avg_rtt) && + getConInfo(con::MIN_JITTER, &min_jitter) && + getConInfo(con::MAX_JITTER, &max_jitter) && + getConInfo(con::AVG_JITTER, &avg_jitter); + + bool r = server->getClientInfo(player->getPeerId(), &state, &uptime, + &ser_vers, &prot_vers, &major, &minor, &patch, &vers_string, + &lang_code); + if (!r) { + dstream << FUNCTION_NAME << ": peer was not found" << std::endl; + lua_pushnil(L); // error + return 1; } - ERET(getServer(L)->getClientConInfo(player->getPeerId(), con::MIN_RTT, &min_rtt)) - ERET(getServer(L)->getClientConInfo(player->getPeerId(), con::MAX_RTT, &max_rtt)) - ERET(getServer(L)->getClientConInfo(player->getPeerId(), con::AVG_RTT, &avg_rtt)) - ERET(getServer(L)->getClientConInfo(player->getPeerId(), con::MIN_JITTER, - &min_jitter)) - ERET(getServer(L)->getClientConInfo(player->getPeerId(), con::MAX_JITTER, - &max_jitter)) - ERET(getServer(L)->getClientConInfo(player->getPeerId(), con::AVG_JITTER, - &avg_jitter)) - - ERET(getServer(L)->getClientInfo(player->getPeerId(), &state, &uptime, &ser_vers, - &prot_vers, &major, &minor, &patch, &vers_string, &lang_code)) - lua_newtable(L); int table = lua_gettop(L); @@ -202,29 +203,31 @@ int ModApiServer::l_get_player_information(lua_State *L) } lua_settable(L, table); - lua_pushstring(L,"min_rtt"); - lua_pushnumber(L, min_rtt); - lua_settable(L, table); + if (have_con_info) { // may be missing + lua_pushstring(L, "min_rtt"); + lua_pushnumber(L, min_rtt); + lua_settable(L, table); - lua_pushstring(L,"max_rtt"); - lua_pushnumber(L, max_rtt); - lua_settable(L, table); + lua_pushstring(L, "max_rtt"); + lua_pushnumber(L, max_rtt); + lua_settable(L, table); - lua_pushstring(L,"avg_rtt"); - lua_pushnumber(L, avg_rtt); - lua_settable(L, table); + lua_pushstring(L, "avg_rtt"); + lua_pushnumber(L, avg_rtt); + lua_settable(L, table); - lua_pushstring(L,"min_jitter"); - lua_pushnumber(L, min_jitter); - lua_settable(L, table); + lua_pushstring(L, "min_jitter"); + lua_pushnumber(L, min_jitter); + lua_settable(L, table); - lua_pushstring(L,"max_jitter"); - lua_pushnumber(L, max_jitter); - lua_settable(L, table); + lua_pushstring(L, "max_jitter"); + lua_pushnumber(L, max_jitter); + lua_settable(L, table); - lua_pushstring(L,"avg_jitter"); - lua_pushnumber(L, avg_jitter); - lua_settable(L, table); + lua_pushstring(L, "avg_jitter"); + lua_pushnumber(L, avg_jitter); + lua_settable(L, table); + } lua_pushstring(L,"connection_uptime"); lua_pushnumber(L, uptime); @@ -268,7 +271,6 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_settable(L, table); #endif -#undef ERET return 1; } -- cgit v1.2.3 From e0ea87f1f32273dba2eb5421c2a8c890479ba078 Mon Sep 17 00:00:00 2001 From: ANAND Date: Sat, 2 May 2020 16:22:11 +0530 Subject: set_fov: Add support for time-based transitions (#9705) --- doc/lua_api.txt | 15 ++++--- src/client/camera.cpp | 84 +++++++++++++++++++++++++++++-------- src/client/camera.h | 15 ++++++- src/network/clientpackethandler.cpp | 15 ++++++- src/network/networkprotocol.h | 3 +- src/player.h | 12 ++++-- src/script/lua_api/l_object.cpp | 11 +++-- src/server.cpp | 4 +- 8 files changed, 124 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index f9107b623..44f62f7a7 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -5998,15 +5998,18 @@ object you are working with still exists. * max: bubbles bar is not shown * See [Object properties] for more information * Is limited to range 0 ... 65535 (2^16 - 1) -* `set_fov(fov, is_multiplier)`: Sets player's FOV +* `set_fov(fov, is_multiplier, transition_time)`: Sets player's FOV * `fov`: FOV value. * `is_multiplier`: Set to `true` if the FOV value is a multiplier. Defaults to `false`. - * Set to 0 to clear FOV override. -* `get_fov()`: - * Returns player's FOV override in degrees, and a boolean depending on whether - the value is a multiplier. - * Returns 0 as first value if player's FOV hasn't been overridden. + * `transition_time`: If defined, enables smooth FOV transition. + Interpreted as the time (in seconds) to reach target FOV. + If set to 0, FOV change is instantaneous. Defaults to 0. + * Set `fov` to 0 to clear FOV override. +* `get_fov()`: Returns the following: + * Server-sent FOV value. Returns 0 if an FOV override doesn't exist. + * Boolean indicating whether the FOV value is a multiplier. + * Time (in seconds) taken for the FOV transition. Set by `set_fov`. * `set_attribute(attribute, value)`: DEPRECATED, use get_meta() instead * Sets an extra attribute with value on player. * `value` must be a string, or a number which will be converted to a diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 69bd82a47..1a5253db4 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -86,6 +86,51 @@ Camera::~Camera() m_wieldmgr->drop(); } +void Camera::notifyFovChange() +{ + LocalPlayer *player = m_client->getEnv().getLocalPlayer(); + assert(player); + + PlayerFovSpec spec = player->getFov(); + + /* + * Update m_old_fov_degrees first - it serves as the starting point of the + * upcoming transition. + * + * If an FOV transition is already active, mark current FOV as the start of + * the new transition. If not, set it to the previous transition's target FOV. + */ + if (m_fov_transition_active) + m_old_fov_degrees = m_curr_fov_degrees; + else + m_old_fov_degrees = m_server_sent_fov ? m_target_fov_degrees : m_cache_fov; + + /* + * Update m_server_sent_fov next - it corresponds to the target FOV of the + * upcoming transition. + * + * Set it to m_cache_fov, if server-sent FOV is 0. Otherwise check if + * server-sent FOV is a multiplier, and multiply it with m_cache_fov instead + * of overriding. + */ + if (spec.fov == 0.0f) { + m_server_sent_fov = false; + m_target_fov_degrees = m_cache_fov; + } else { + m_server_sent_fov = true; + m_target_fov_degrees = spec.is_multiplier ? m_cache_fov * spec.fov : spec.fov; + } + + if (spec.transition_time > 0.0f) + m_fov_transition_active = true; + + // If FOV smooth transition is active, initialize required variables + if (m_fov_transition_active) { + m_transition_time = spec.transition_time; + m_fov_diff = m_target_fov_degrees - m_old_fov_degrees; + } +} + bool Camera::successfullyCreated(std::string &error_message) { if (!m_playernode) { @@ -462,33 +507,38 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r m_camera_position = my_cp; /* - * Apply server-sent FOV. If server doesn't enforce FOV, - * check for zoom and set to zoom FOV. - * Otherwise, default to m_cache_fov + * Apply server-sent FOV, instantaneous or smooth transition. + * If not, check for zoom and set to zoom FOV. + * Otherwise, default to m_cache_fov. */ - - f32 fov_degrees; - PlayerFovSpec fov_spec = player->getFov(); - if (fov_spec.fov > 0.0f) { - // If server-sent FOV is a multiplier, multiply - // it with m_cache_fov instead of overriding - if (fov_spec.is_multiplier) - fov_degrees = m_cache_fov * fov_spec.fov; - else - fov_degrees = fov_spec.fov; + if (m_fov_transition_active) { + // Smooth FOV transition + // Dynamically calculate FOV delta based on frametimes + f32 delta = (frametime / m_transition_time) * m_fov_diff; + m_curr_fov_degrees += delta; + + // Mark transition as complete if target FOV has been reached + if ((m_fov_diff > 0.0f && m_curr_fov_degrees >= m_target_fov_degrees) || + (m_fov_diff < 0.0f && m_curr_fov_degrees <= m_target_fov_degrees)) { + m_fov_transition_active = false; + m_curr_fov_degrees = m_target_fov_degrees; + } + } else if (m_server_sent_fov) { + // Instantaneous FOV change + m_curr_fov_degrees = m_target_fov_degrees; } else if (player->getPlayerControl().zoom && player->getZoomFOV() > 0.001f) { // Player requests zoom, apply zoom FOV - fov_degrees = player->getZoomFOV(); + m_curr_fov_degrees = player->getZoomFOV(); } else { // Set to client's selected FOV - fov_degrees = m_cache_fov; + m_curr_fov_degrees = m_cache_fov; } - fov_degrees = rangelim(fov_degrees, 1.0f, 160.0f); + m_curr_fov_degrees = rangelim(m_curr_fov_degrees, 1.0f, 160.0f); // FOV and aspect ratio const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); m_aspect = (f32) window_size.X / (f32) window_size.Y; - m_fov_y = fov_degrees * M_PI / 180.0; + m_fov_y = m_curr_fov_degrees * M_PI / 180.0; // Increase vertical FOV on lower aspect ratios (<16:10) m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect))); m_fov_x = 2 * atan(m_aspect * tan(0.5 * m_fov_y)); diff --git a/src/client/camera.h b/src/client/camera.h index 6ec37fe10..3a59637bc 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -112,6 +112,9 @@ public: return MYMAX(m_fov_x, m_fov_y); } + // Notify about new server-sent FOV and initialize smooth FOV transition + void notifyFovChange(); + // Checks if the constructor was able to create the scene nodes bool successfullyCreated(std::string &error_message); @@ -186,6 +189,9 @@ private: Client *m_client; + // Default Client FOV (as defined by the "fov" setting) + f32 m_cache_fov; + // Absolute camera position v3f m_camera_position; // Absolute camera direction @@ -193,6 +199,14 @@ private: // Camera offset v3s16 m_camera_offset; + // Server-sent FOV variables + bool m_server_sent_fov = false; + f32 m_curr_fov_degrees, m_old_fov_degrees, m_target_fov_degrees; + + // FOV transition variables + bool m_fov_transition_active = false; + f32 m_fov_diff, m_transition_time; + v2f m_wieldmesh_offset = v2f(55.0f, -35.0f); v2f m_arm_dir; v2f m_cam_vel; @@ -230,7 +244,6 @@ private: f32 m_cache_fall_bobbing_amount; f32 m_cache_view_bobbing_amount; - f32 m_cache_fov; bool m_arm_inertia; std::list m_nametags; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index d19dc3818..6428ed752 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/client.h" #include "util/base64.h" +#include "client/camera.h" #include "chatmessage.h" #include "client/clientmedia.h" #include "log.h" @@ -530,11 +531,21 @@ void Client::handleCommand_Movement(NetworkPacket* pkt) void Client::handleCommand_Fov(NetworkPacket *pkt) { f32 fov; - bool is_multiplier; + bool is_multiplier = false; + f32 transition_time = 0.0f; + *pkt >> fov >> is_multiplier; + // Wrap transition_time extraction within a + // try-catch to preserve backwards compat + try { + *pkt >> transition_time; + } catch (PacketError &e) {}; + LocalPlayer *player = m_env.getLocalPlayer(); - player->setFov({ fov, is_multiplier }); + assert(player); + player->setFov({ fov, is_multiplier, transition_time }); + m_camera->notifyFovChange(); } void Client::handleCommand_HP(NetworkPacket *pkt) diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 4b7345b15..73523ea42 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -384,8 +384,9 @@ enum ToClientCommand /* Sends an FOV override/multiplier to client. - float fov + f32 fov bool is_multiplier + f32 transition_time */ TOCLIENT_DEATHSCREEN = 0x37, diff --git a/src/player.h b/src/player.h index de7f427e9..3bc7762fa 100644 --- a/src/player.h +++ b/src/player.h @@ -35,7 +35,13 @@ with this program; if not, write to the Free Software Foundation, Inc., struct PlayerFovSpec { f32 fov; + + // Whether to multiply the client's FOV or to override it bool is_multiplier; + + // The time to be take to trasition to the new FOV value. + // Transition is instantaneous if omitted. Omitted by default. + f32 transition_time; }; struct PlayerControl @@ -186,12 +192,12 @@ public: void setFov(const PlayerFovSpec &spec) { - m_fov_spec = spec; + m_fov_override_spec = spec; } const PlayerFovSpec &getFov() const { - return m_fov_spec; + return m_fov_override_spec; } u32 keyPressed = 0; @@ -208,7 +214,7 @@ protected: char m_name[PLAYERNAME_SIZE]; v3f m_speed; u16 m_wield_index = 0; - PlayerFovSpec m_fov_spec = { 0.0f, false }; + PlayerFovSpec m_fov_override_spec = { 0.0f, false, 0.0f }; std::vector hud; private: diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 77e1e7dc2..dcaee10b2 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1249,7 +1249,7 @@ int ObjectRef::l_set_look_yaw(lua_State *L) return 1; } -// set_fov(self, degrees[, is_multiplier]) +// set_fov(self, degrees[, is_multiplier, transition_time]) int ObjectRef::l_set_fov(lua_State *L) { NO_MAP_LOCK_REQUIRED; @@ -1258,7 +1258,11 @@ int ObjectRef::l_set_fov(lua_State *L) if (!player) return 0; - player->setFov({ static_cast(luaL_checknumber(L, 2)), readParam(L, 3) }); + player->setFov({ + static_cast(luaL_checknumber(L, 2)), + readParam(L, 3, false), + lua_isnumber(L, 4) ? static_cast(luaL_checknumber(L, 4)) : 0.0f + }); getServer(L)->SendPlayerFov(player->getPeerId()); return 0; @@ -1276,8 +1280,9 @@ int ObjectRef::l_get_fov(lua_State *L) PlayerFovSpec fov_spec = player->getFov(); lua_pushnumber(L, fov_spec.fov); lua_pushboolean(L, fov_spec.is_multiplier); + lua_pushnumber(L, fov_spec.transition_time); - return 2; + return 3; } // set_breath(self, breath) diff --git a/src/server.cpp b/src/server.cpp index a7eb52837..0346d197d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1892,10 +1892,10 @@ void Server::SendMovePlayer(session_t peer_id) void Server::SendPlayerFov(session_t peer_id) { - NetworkPacket pkt(TOCLIENT_FOV, 4 + 1, peer_id); + NetworkPacket pkt(TOCLIENT_FOV, 4 + 1 + 4, peer_id); PlayerFovSpec fov_spec = m_env->getPlayer(peer_id)->getFov(); - pkt << fov_spec.fov << fov_spec.is_multiplier; + pkt << fov_spec.fov << fov_spec.is_multiplier << fov_spec.transition_time; Send(&pkt); } -- cgit v1.2.3 From 808eb4c5714da5ac36f4a70653d6b3805060828c Mon Sep 17 00:00:00 2001 From: Lejo Date: Sat, 2 May 2020 12:57:04 +0200 Subject: Auto delete MetaData when = 0 (#8770) * Auto delete MetaData when = 0 --- src/script/lua_api/l_metadata.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/script/lua_api/l_metadata.cpp b/src/script/lua_api/l_metadata.cpp index 21002e6a7..61a25a761 100644 --- a/src/script/lua_api/l_metadata.cpp +++ b/src/script/lua_api/l_metadata.cpp @@ -153,7 +153,9 @@ int MetaDataRef::l_set_int(lua_State *L) MetaDataRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); int a = luaL_checkint(L, 3); - std::string str = itos(a); + std::string str; + if (a != 0) + str = itos(a); Metadata *meta = ref->getmeta(true); if (meta == NULL || str == meta->getString(name)) @@ -191,7 +193,9 @@ int MetaDataRef::l_set_float(lua_State *L) MetaDataRef *ref = checkobject(L, 1); std::string name = luaL_checkstring(L, 2); float a = readParam(L, 3); - std::string str = ftos(a); + std::string str; + if (a != 0) + str = ftos(a); Metadata *meta = ref->getmeta(true); if (meta == NULL || str == meta->getString(name)) -- cgit v1.2.3 From cb9a44ef8998ff66c00187efc508bf8bd6cc2d67 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Sat, 2 May 2020 07:32:02 -0400 Subject: Add 'content_offset' and 'padding' style properties for buttons (#9661) * Add padding and content_offset style properties to buttons --- doc/lua_api.txt | 6 +++- games/minimal/mods/test/formspec.lua | 3 +- src/gui/StyleSpec.h | 54 ++++++++++++++++++++++++++++++++++++ src/gui/guiButton.cpp | 44 ++++++++++++++++------------- src/gui/guiButton.h | 2 ++ 5 files changed, 88 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 988acde89..1ffb5c39b 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2697,10 +2697,14 @@ Some types may inherit styles from parent types. * bgimg - standard background image. Defaults to none. * bgimg_hovered - background image when hovered. Defaults to bgimg when not provided. * bgimg_middle - Makes the bgimg textures render in 9-sliced mode and defines the middle rect. - See background9[] documentation for more details + See background9[] documentation for more details. This property also pads the + button's content when set. * bgimg_pressed - background image when pressed. Defaults to bgimg when not provided. * border - boolean, draw border. Set to false to hide the bevelled button pane. Default true. + * content_offset - 2d vector, shifts the position of the button's content without resizing it. * noclip - boolean, set to true to allow the element to exceed formspec bounds. + * padding - rect, adds space between the edges of the button and the content. This value is + relative to bgimg_middle. * textcolor - color, default white. * checkbox * noclip - boolean, set to true to allow the element to exceed formspec bounds. diff --git a/games/minimal/mods/test/formspec.lua b/games/minimal/mods/test/formspec.lua index 4ab4f2717..a5d3074cd 100644 --- a/games/minimal/mods/test/formspec.lua +++ b/games/minimal/mods/test/formspec.lua @@ -95,7 +95,7 @@ local style_fs = [[ style[one_btn13;border=false] item_image_button[1.25,8.35;1,1;default:sword_steel;one_btn13;NoBor] - style[one_btn14;border=false;bgimg=test_bg.png;fgimg=bubble.png] + style[one_btn14;border=false;bgimg=test_bg.png;fgimg=bubble.png;padding=8] style[one_btn14:hovered;bgimg=test_bg_hovered.png;fgimg=default_apple.png;textcolor=red] style[one_btn14:pressed;bgimg=test_bg_pressed.png;fgimg=heart.png;textcolor=green] style[one_btn14:hovered+pressed;textcolor=blue] @@ -105,6 +105,7 @@ local style_fs = [[ item_image_button[1.25,9.6;1,1;default:sword_steel;one_btn15;Bg] style[one_btn16;border=false;bgimg=test_bg_9slice.png;bgimg_hovered=test_bg_9slice_hovered.png;bgimg_pressed=test_bg_9slice_pressed.png;bgimg_middle=4,6] + style[one_btn16:pressed;content_offset=0,1] button[2.5,9.6;2,1;one_btn16;9-Slice Bg] diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h index 799fbf46d..3e842e826 100644 --- a/src/gui/StyleSpec.h +++ b/src/gui/StyleSpec.h @@ -44,6 +44,8 @@ public: FGIMG_HOVERED, // Note: Deprecated property FGIMG_PRESSED, // Note: Deprecated property ALPHA, + CONTENT_OFFSET, + PADDING, NUM_PROPERTIES, NONE }; @@ -92,6 +94,10 @@ public: return FGIMG_PRESSED; } else if (name == "alpha") { return ALPHA; + } else if (name == "content_offset") { + return CONTENT_OFFSET; + } else if (name == "padding") { + return PADDING; } else { return NONE; } @@ -196,6 +202,29 @@ public: return rect; } + irr::core::vector2d getVector2i(Property prop, irr::core::vector2d def) const + { + const auto &val = properties[prop]; + if (val.empty()) + return def; + + irr::core::vector2d vec; + if (!parseVector2i(val, &vec)) + return def; + + return vec; + } + + irr::core::vector2d getVector2i(Property prop) const + { + const auto &val = properties[prop]; + FATAL_ERROR_IF(val.empty(), "Unexpected missing property"); + + irr::core::vector2d vec; + parseVector2i(val, &vec); + return vec; + } + video::ITexture *getTexture(Property prop, ISimpleTextureSource *tsrc, video::ITexture *def) const { @@ -286,4 +315,29 @@ private: return true; } + + bool parseVector2i(const std::string &value, irr::core::vector2d *parsed_vec) const + { + irr::core::vector2d vec; + std::vector v_vector = split(value, ','); + + if (v_vector.size() == 1) { + s32 x = stoi(v_vector[0]); + vec.X = x; + vec.Y = x; + } else if (v_vector.size() == 2) { + s32 x = stoi(v_vector[0]); + s32 y = stoi(v_vector[1]); + vec.X = x; + vec.Y = y; + } else { + warningstream << "Invalid vector2d string format: \"" << value + << "\"" << std::endl; + return false; + } + + *parsed_vec = vec; + + return true; + } }; diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index 9dfe36bc4..ff35958fd 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -592,25 +592,6 @@ void GUIButton::setPressed(bool pressed) { ClickTime = porting::getTimeMs(); Pressed = pressed; - - GUISkin* skin = dynamic_cast(Environment->getSkin()); - - for(IGUIElement *child : getChildren()) - { - core::rect originalRect = child->getRelativePosition(); - if (Pressed) { - child->setRelativePosition(originalRect + - core::dimension2d( - skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), - skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y))); - } else { - child->setRelativePosition(originalRect - - core::dimension2d( - skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), - skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y))); - } - } - setFromState(); } } @@ -819,7 +800,32 @@ void GUIButton::setFromStyle(const StyleSpec& style) } else { setImage(nullptr); } + BgMiddle = style.getRect(StyleSpec::BGIMG_MIDDLE, BgMiddle); + + // Child padding and offset + Padding = style.getRect(StyleSpec::PADDING, core::rect()); + Padding = core::rect( + Padding.UpperLeftCorner + BgMiddle.UpperLeftCorner, + Padding.LowerRightCorner + BgMiddle.LowerRightCorner); + + GUISkin* skin = dynamic_cast(Environment->getSkin()); + core::vector2d defaultPressOffset( + skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X), + skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y)); + ContentOffset = style.getVector2i(StyleSpec::CONTENT_OFFSET, isPressed() + ? defaultPressOffset + : core::vector2d(0)); + + core::rect childBounds( + Padding.UpperLeftCorner.X + ContentOffset.X, + Padding.UpperLeftCorner.Y + ContentOffset.Y, + AbsoluteRect.getWidth() + Padding.LowerRightCorner.X + ContentOffset.X, + AbsoluteRect.getHeight() + Padding.LowerRightCorner.Y + ContentOffset.Y); + + for (IGUIElement *child : getChildren()) { + child->setRelativePosition(childBounds); + } } //! Set the styles used for each state diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h index ef10f926e..95fa1a2a1 100644 --- a/src/gui/guiButton.h +++ b/src/gui/guiButton.h @@ -336,5 +336,7 @@ private: gui::IGUIStaticText *StaticText; core::rect BgMiddle; + core::rect Padding; + core::vector2d ContentOffset; // END PATCH }; -- cgit v1.2.3 From 66c182531cf7ef06c98a25b4e12db770314bdc91 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 4 May 2020 08:45:31 +0200 Subject: Change default keys for cam/minimap to C/V (#9779) --- README.md | 6 +++--- builtin/settingtypes.txt | 4 ++-- src/defaultsettings.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/README.md b/README.md index 024e7b691..202ba4fe2 100644 --- a/README.md +++ b/README.md @@ -69,15 +69,15 @@ Some can be changed in the key config dialog in the settings tab. | J | Enable/disable fast mode (needs fast privilege) | | H | Enable/disable noclip mode (needs noclip privilege) | | E | Move fast in fast mode | +| C | Cycle through camera modes | +| V | Cycle through minimap modes | +| Shift + V | Change minimap orientation | | F1 | Hide/show HUD | | F2 | Hide/show chat | | F3 | Disable/enable fog | | F4 | Disable/enable camera update (Mapblocks are not updated anymore when disabled, disabled in release builds) | | F5 | Cycle through debug information screens | | F6 | Cycle through profiler info screens | -| F7 | Cycle through camera modes | -| F9 | Cycle through minimap modes | -| Shift + F9 | Change minimap orientation | | F10 | Show/hide console | | F12 | Take screenshot | diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 165ed8c06..c983fb436 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -252,7 +252,7 @@ keymap_cinematic (Cinematic mode key) key # Key for toggling display of minimap. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 -keymap_minimap (Minimap key) key KEY_F9 +keymap_minimap (Minimap key) key KEY_KEY_V # Key for taking screenshots. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 @@ -424,7 +424,7 @@ keymap_toggle_profiler (Profiler toggle key) key KEY_F6 # Key for switching between first- and third-person camera. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 -keymap_camera_mode (Toggle camera mode key) key KEY_F7 +keymap_camera_mode (Toggle camera mode key) key KEY_KEY_C # Key for increasing the viewing range. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 06daa3b94..33654e213 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -80,7 +80,7 @@ void set_default_settings(Settings *settings) settings->setDefault("keymap_chat", "KEY_KEY_T"); settings->setDefault("keymap_cmd", "/"); settings->setDefault("keymap_cmd_local", "."); - settings->setDefault("keymap_minimap", "KEY_F9"); + settings->setDefault("keymap_minimap", "KEY_KEY_V"); settings->setDefault("keymap_console", "KEY_F10"); settings->setDefault("keymap_rangeselect", "KEY_KEY_R"); settings->setDefault("keymap_freemove", "KEY_KEY_K"); @@ -103,7 +103,7 @@ void set_default_settings(Settings *settings) #endif settings->setDefault("keymap_toggle_debug", "KEY_F5"); settings->setDefault("keymap_toggle_profiler", "KEY_F6"); - settings->setDefault("keymap_camera_mode", "KEY_F7"); + settings->setDefault("keymap_camera_mode", "KEY_KEY_C"); settings->setDefault("keymap_screenshot", "KEY_F12"); settings->setDefault("keymap_increase_viewing_range_min", "+"); settings->setDefault("keymap_decrease_viewing_range_min", "-"); -- cgit v1.2.3 From 1b6f40c35632ab5a2066822c8b5d4c09d469f49d Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 4 May 2020 20:02:33 +0200 Subject: Rename moveresult speed to velocity --- doc/lua_api.txt | 4 ++-- src/script/common/c_content.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1ffb5c39b..b1099ec59 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6632,8 +6632,8 @@ Collision info passed to `on_step`: type = string, -- "node" or "object", axis = string, -- "x", "y" or "z" node_pos = vector, -- if type is "node" - old_speed = vector, - new_speed = vector, + old_velocity = vector, + new_velocity = vector, }, ... } diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 6ff642738..95364000c 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -2046,10 +2046,10 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res) } push_v3f(L, c.old_speed / BS); - lua_setfield(L, -2, "old_speed"); + lua_setfield(L, -2, "old_velocity"); push_v3f(L, c.new_speed / BS); - lua_setfield(L, -2, "new_speed"); + lua_setfield(L, -2, "new_velocity"); lua_rawseti(L, -2, i++); } -- cgit v1.2.3 From cad5b987ad4720bd6a49d3604be9e81ea348f799 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 4 May 2020 20:19:12 +0200 Subject: Sky API: Rename *_tint to fog_*_tint for consistency --- src/client/game.cpp | 12 ++++++------ src/client/sky.cpp | 12 ++++++------ src/network/clientpackethandler.cpp | 8 ++++---- src/network/networkprotocol.h | 6 +++--- src/remoteplayer.cpp | 6 +++--- src/script/lua_api/l_object.cpp | 22 +++++++++++----------- src/server.cpp | 4 ++-- src/skyparams.h | 6 +++--- 8 files changed, 38 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index 3bdac786c..d1eb3bba2 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2799,9 +2799,9 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) // Update mesh based skybox colours if applicable. sky->setSkyColors(*event->set_sky); sky->setHorizonTint( - event->set_sky->sun_tint, - event->set_sky->moon_tint, - event->set_sky->tint_type + event->set_sky->fog_sun_tint, + event->set_sky->fog_moon_tint, + event->set_sky->fog_tint_type ); } else if (event->set_sky->type == "skybox" && event->set_sky->textures.size() == 6) { @@ -2811,9 +2811,9 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) sky->setFallbackBgColor(event->set_sky->bgcolor); // Set sunrise and sunset fog tinting: sky->setHorizonTint( - event->set_sky->sun_tint, - event->set_sky->moon_tint, - event->set_sky->tint_type + event->set_sky->fog_sun_tint, + event->set_sky->fog_moon_tint, + event->set_sky->fog_tint_type ); // Add textures to skybox. for (int i = 0; i < 6; i++) diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 7a7b188ce..ce33b96ae 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -529,7 +529,7 @@ void Sky::update(float time_of_day, float time_brightness, pointcolor_sun_f.g = pointcolor_light * (float)m_materials[3].EmissiveColor.getGreen() / 255; } else if (!m_default_tint) { - pointcolor_sun_f = m_sky_params.sun_tint; + pointcolor_sun_f = m_sky_params.fog_sun_tint; } else { pointcolor_sun_f.r = pointcolor_light * 1; pointcolor_sun_f.b = pointcolor_light * @@ -548,9 +548,9 @@ void Sky::update(float time_of_day, float time_brightness, ); } else { pointcolor_moon_f = video::SColorf( - (m_sky_params.moon_tint.getRed() / 255) * pointcolor_light, - (m_sky_params.moon_tint.getGreen() / 255) * pointcolor_light, - (m_sky_params.moon_tint.getBlue() / 255) * pointcolor_light, + (m_sky_params.fog_moon_tint.getRed() / 255) * pointcolor_light, + (m_sky_params.fog_moon_tint.getGreen() / 255) * pointcolor_light, + (m_sky_params.fog_moon_tint.getBlue() / 255) * pointcolor_light, 1 ); } @@ -941,8 +941,8 @@ void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint, std::string use_sun_tint) { // Change sun and moon tinting: - m_sky_params.sun_tint = sun_tint; - m_sky_params.moon_tint = moon_tint; + m_sky_params.fog_sun_tint = sun_tint; + m_sky_params.fog_moon_tint = moon_tint; // Faster than comparing strings every rendering frame if (use_sun_tint == "default") m_default_tint = true; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 6428ed752..8d0225a3d 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1276,9 +1276,9 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt) // Fix for "regular" skies, as color isn't kept: if (skybox.type == "regular") { skybox.sky_color = sky_defaults.getSkyColorDefaults(); - skybox.tint_type = "default"; - skybox.moon_tint = video::SColor(255, 255, 255, 255); - skybox.sun_tint = video::SColor(255, 255, 255, 255); + skybox.fog_tint_type = "default"; + skybox.fog_moon_tint = video::SColor(255, 255, 255, 255); + skybox.fog_sun_tint = video::SColor(255, 255, 255, 255); } else { sun.visible = false; @@ -1313,7 +1313,7 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt) std::string texture; *pkt >> skybox.bgcolor >> skybox.type >> skybox.clouds >> - skybox.sun_tint >> skybox.moon_tint >> skybox.tint_type; + skybox.fog_sun_tint >> skybox.fog_moon_tint >> skybox.fog_tint_type; if (skybox.type == "skybox") { *pkt >> texture_count; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 73523ea42..527ebba7c 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -634,9 +634,9 @@ enum ToClientCommand u8[4] night_sky (ARGB) u8[4] night_horizon (ARGB) u8[4] indoors (ARGB) - u8[4] sun_tint (ARGB) - u8[4] moon_tint (ARGB) - std::string tint_type + u8[4] fog_sun_tint (ARGB) + u8[4] fog_moon_tint (ARGB) + std::string fog_tint_type */ TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50, diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp index 7a603d53e..bef60c792 100644 --- a/src/remoteplayer.cpp +++ b/src/remoteplayer.cpp @@ -74,9 +74,9 @@ RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef): m_skybox_params.sky_color = sky_defaults.getSkyColorDefaults(); m_skybox_params.type = "regular"; m_skybox_params.clouds = true; - m_skybox_params.sun_tint = video::SColor(255, 244, 125, 29); - m_skybox_params.moon_tint = video::SColorf(0.5, 0.6, 0.8, 1).toSColor(); - m_skybox_params.tint_type = "default"; + m_skybox_params.fog_sun_tint = video::SColor(255, 244, 125, 29); + m_skybox_params.fog_moon_tint = video::SColorf(0.5, 0.6, 0.8, 1).toSColor(); + m_skybox_params.fog_tint_type = "default"; m_sun_params = sky_defaults.getSunDefaults(); m_moon_params = sky_defaults.getMoonDefaults(); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index dcaee10b2..f71130378 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1782,19 +1782,19 @@ int ObjectRef::l_set_sky(lua_State *L) lua_pop(L, 1); // Prevent flickering clouds at dawn/dusk: - skybox_params.sun_tint = video::SColor(255, 255, 255, 255); + skybox_params.fog_sun_tint = video::SColor(255, 255, 255, 255); lua_getfield(L, -1, "fog_sun_tint"); - read_color(L, -1, &skybox_params.sun_tint); + read_color(L, -1, &skybox_params.fog_sun_tint); lua_pop(L, 1); - skybox_params.moon_tint = video::SColor(255, 255, 255, 255); + skybox_params.fog_moon_tint = video::SColor(255, 255, 255, 255); lua_getfield(L, -1, "fog_moon_tint"); - read_color(L, -1, &skybox_params.moon_tint); + read_color(L, -1, &skybox_params.fog_moon_tint); lua_pop(L, 1); lua_getfield(L, -1, "fog_tint_type"); if (!lua_isnil(L, -1)) - skybox_params.tint_type = luaL_checkstring(L, -1); + skybox_params.fog_tint_type = luaL_checkstring(L, -1); lua_pop(L, 1); // Because we need to leave the "sky_color" table. @@ -1912,12 +1912,12 @@ int ObjectRef::l_get_sky_color(lua_State *L) push_ARGB8(L, skybox_params.sky_color.indoors); lua_setfield(L, -2, "indoors"); } - push_ARGB8(L, skybox_params.sun_tint); - lua_setfield(L, -2, "sun_tint"); - push_ARGB8(L, skybox_params.moon_tint); - lua_setfield(L, -2, "moon_tint"); - lua_pushstring(L, skybox_params.tint_type.c_str()); - lua_setfield(L, -2, "tint_type"); + push_ARGB8(L, skybox_params.fog_sun_tint); + lua_setfield(L, -2, "fog_sun_tint"); + push_ARGB8(L, skybox_params.fog_moon_tint); + lua_setfield(L, -2, "fog_moon_tint"); + lua_pushstring(L, skybox_params.fog_tint_type.c_str()); + lua_setfield(L, -2, "fog_tint_type"); return 1; } diff --git a/src/server.cpp b/src/server.cpp index 0346d197d..05584be2d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1770,8 +1770,8 @@ void Server::SendSetSky(session_t peer_id, const SkyboxParams ¶ms) pkt << params.clouds; } else { // Handle current clients and future clients pkt << params.bgcolor << params.type - << params.clouds << params.sun_tint - << params.moon_tint << params.tint_type; + << params.clouds << params.fog_sun_tint + << params.fog_moon_tint << params.fog_tint_type; if (params.type == "skybox") { pkt << (u16) params.textures.size(); diff --git a/src/skyparams.h b/src/skyparams.h index 9fdfd89da..c362ef8f3 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -37,9 +37,9 @@ struct SkyboxParams std::vector textures; bool clouds; SkyColor sky_color; - video::SColor sun_tint; - video::SColor moon_tint; - std::string tint_type; + video::SColor fog_sun_tint; + video::SColor fog_moon_tint; + std::string fog_tint_type; }; struct SunParams -- cgit v1.2.3 From f1a05d0f71d69641fd954daf68d13acad91114f1 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Tue, 5 May 2020 08:38:18 +0200 Subject: Fix broken client if openal cannot be opened (#9804) --- src/client/clientlauncher.cpp | 2 +- src/client/game.cpp | 2 +- src/client/sound_openal.cpp | 33 +++++++++++++++++++++++++-------- src/gui/guiEngine.cpp | 4 ++-- 4 files changed, 29 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 2a9d6097f..f18915a55 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -105,7 +105,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args) } RenderingEngine::get_instance()->setupTopLevelWindow(PROJECT_NAME_C); - + /* This changes the minimum allowed number of vertices in a VBO. Default is 500. diff --git a/src/client/game.cpp b/src/client/game.cpp index d1eb3bba2..1577a37db 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1249,7 +1249,7 @@ bool Game::init( bool Game::initSound() { #if USE_SOUND - if (g_settings->getBool("enable_sound")) { + if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) { infostream << "Attempting to use OpenAL audio" << std::endl; sound = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher); if (!sound) diff --git a/src/client/sound_openal.cpp b/src/client/sound_openal.cpp index d0f935a7a..20a651c1d 100644 --- a/src/client/sound_openal.cpp +++ b/src/client/sound_openal.cpp @@ -275,25 +275,38 @@ public: m_device(nullptr, delete_alcdevice), m_context(nullptr, delete_alccontext) { - if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr), delete_alcdevice))) - throw std::runtime_error("Audio: Global Initialization: Device Open"); + } + + bool init() + { + if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr), delete_alcdevice))) { + errorstream << "Audio: Global Initialization: Failed to open device" << std::endl; + return false; + } if (!(m_context = unique_ptr_alccontext( alcCreateContext(m_device.get(), nullptr), delete_alccontext))) { - throw std::runtime_error("Audio: Global Initialization: Context Create"); + errorstream << "Audio: Global Initialization: Failed to create context" << std::endl; + return false; } - if (!alcMakeContextCurrent(m_context.get())) - throw std::runtime_error("Audio: Global Initialization: Context Current"); + if (!alcMakeContextCurrent(m_context.get())) { + errorstream << "Audio: Global Initialization: Failed to make current context" << std::endl; + return false; + } alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); - if (alGetError() != AL_NO_ERROR) - throw std::runtime_error("Audio: Global Initialization: OpenAL Error"); + if (alGetError() != AL_NO_ERROR) { + errorstream << "Audio: Global Initialization: OpenAL Error " << alGetError() << std::endl; + return false; + } infostream << "Audio: Global Initialized: OpenAL " << alGetString(AL_VERSION) << ", using " << alcGetString(m_device.get(), ALC_DEVICE_SPECIFIER) << std::endl; + + return true; } ~SoundManagerSingleton() @@ -682,7 +695,11 @@ public: std::shared_ptr createSoundManagerSingleton() { - return std::shared_ptr(new SoundManagerSingleton()); + auto smg = std::make_shared(); + if (!smg->init()) { + smg.reset(); + } + return smg; } ISoundManager *createOpenALSoundManager(SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher) diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 3107d64cd..b40707d01 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -144,10 +144,10 @@ GUIEngine::GUIEngine(JoystickController *joystick, //create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND - if (g_settings->getBool("enable_sound")) + if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher); #endif - if(!m_sound_manager) + if (!m_sound_manager) m_sound_manager = &dummySoundManager; //create topleft header -- cgit v1.2.3 From d1c6cc72cce7e02dcaca7797b463d071d67d27db Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 5 May 2020 17:05:11 +0200 Subject: Server: Improve some log messages (#9820) --- src/network/serverpackethandler.cpp | 16 +++++++--------- src/server/player_sao.cpp | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 5136eb0ec..adaa9a965 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -111,8 +111,6 @@ void Server::handleCommand_Init(NetworkPacket* pkt) if (depl_serial_v == SER_FMT_VER_INVALID) { actionstream << "Server: A mismatched client tried to connect from " << - addr_s << std::endl; - infostream << "Server: Cannot negotiate serialization version with " << addr_s << " client_max=" << (int)client_max << std::endl; DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION); return; @@ -902,8 +900,8 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std: actionstream << "Player " << player->getName() << " tried to access " << what << " from too far: " - << "d=" << d <<", max_d=" << max_d - << ". ignoring." << std::endl; + << "d=" << d << ", max_d=" << max_d + << "; ignoring." << std::endl; // Call callbacks m_script->on_cheat(player->getPlayerSAO(), "interacted_too_far"); return false; @@ -956,7 +954,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) } if (playersao->isDead()) { - actionstream << "Server: NoCheat: " << player->getName() + actionstream << "Server: " << player->getName() << " tried to interact while dead; ignoring." << std::endl; if (pointed.type == POINTEDTHING_NODE) { // Re-send block to revert change on client-side @@ -1145,7 +1143,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) playersao->noCheatDigEnd(); // If player didn't start digging this, ignore dig if (nocheat_p != p_under) { - infostream << "Server: NoCheat: " << player->getName() + infostream << "Server: " << player->getName() << " started digging " << PP(nocheat_p) << " and completed digging " << PP(p_under) << "; not digging." << std::endl; @@ -1169,9 +1167,9 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) } // If can't dig, ignore dig if (!params.diggable) { - infostream << "Server: NoCheat: " << player->getName() + infostream << "Server: " << player->getName() << " completed digging " << PP(p_under) - << ", which is not diggable with tool. not digging." + << ", which is not diggable with tool; not digging." << std::endl; is_valid_dig = false; // Call callbacks @@ -1195,7 +1193,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) } // Dig not possible else { - infostream << "Server: NoCheat: " << player->getName() + infostream << "Server: " << player->getName() << " completed digging " << PP(p_under) << "too fast; not digging." << std::endl; is_valid_dig = false; diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 58fcea5fe..a4d0f4ce7 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -656,9 +656,9 @@ bool PlayerSAO::checkMovementCheat() float lag_pool_max = m_env->getMaxLagEstimate() * 2.0; lag_pool_max = MYMAX(lag_pool_max, LAG_POOL_MIN); if (m_time_from_last_teleport > lag_pool_max) { - actionstream << "Player " << m_player->getName() - << " moved too fast; resetting position" - << std::endl; + actionstream << "Server: " << m_player->getName() + << " moved too fast: V=" << d_vert << ", H=" << d_horiz + << "; resetting position." << std::endl; cheated = true; } setBasePosition(m_last_good_position); -- cgit v1.2.3 From 2062c80e21b657fed8e68aa48523fa12ad5ef095 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 9 Apr 2020 23:40:12 +0200 Subject: Allow ObjDefManager instances to be cloned --- src/mapgen/mg_biome.cpp | 45 ++++++++++++++++++++ src/mapgen/mg_biome.h | 6 +++ src/mapgen/mg_decoration.cpp | 55 +++++++++++++++++++++++++ src/mapgen/mg_decoration.h | 12 ++++++ src/mapgen/mg_ore.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++ src/mapgen/mg_ore.h | 20 +++++++++ src/mapgen/mg_schematic.cpp | 8 +++- src/mapgen/mg_schematic.h | 4 ++ src/nodedef.cpp | 12 ++++++ src/nodedef.h | 3 ++ src/objdef.cpp | 19 +++++++++ src/objdef.h | 18 ++++++++ src/unittest/test_objdef.cpp | 76 ++++++++++++++++++++++++++++++++-- 13 files changed, 370 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index 345bc8c6a..3a72c43bf 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -92,6 +92,16 @@ void BiomeManager::clear() } +BiomeManager *BiomeManager::clone() const +{ + auto mgr = new BiomeManager(); + assert(mgr); + ObjDefManager::cloneTo(mgr); + mgr->m_server = m_server; + return mgr; +} + + // For BiomeGen type 'BiomeGenOriginal' float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat, NoiseParams &np_heat_blend, u64 seed) @@ -321,6 +331,41 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po //////////////////////////////////////////////////////////////////////////////// +ObjDef *Biome::clone() const +{ + auto obj = new Biome(); + ObjDef::cloneTo(obj); + NodeResolver::cloneTo(obj); + + obj->flags = flags; + + obj->c_top = c_top; + obj->c_filler = c_filler; + obj->c_stone = c_stone; + obj->c_water_top = c_water_top; + obj->c_water = c_water; + obj->c_river_water = c_river_water; + obj->c_riverbed = c_riverbed; + obj->c_dust = c_dust; + obj->c_cave_liquid = c_cave_liquid; + obj->c_dungeon = c_dungeon; + obj->c_dungeon_alt = c_dungeon_alt; + obj->c_dungeon_stair = c_dungeon_stair; + + obj->depth_top = depth_top; + obj->depth_filler = depth_filler; + obj->depth_water_top = depth_water_top; + obj->depth_riverbed = depth_riverbed; + + obj->min_pos = min_pos; + obj->max_pos = max_pos; + obj->heat_point = heat_point; + obj->humidity_point = humidity_point; + obj->vertical_blend = vertical_blend; + + return obj; +} + void Biome::resolveNodeNames() { getIdFromNrBacklog(&c_top, "mapgen_stone", CONTENT_AIR, false); diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index ee148adbc..6aadc32fa 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -42,6 +42,8 @@ enum BiomeType { class Biome : public ObjDef, public NodeResolver { public: + ObjDef *clone() const; + u32 flags; content_t c_top; @@ -191,6 +193,8 @@ public: BiomeManager(Server *server); virtual ~BiomeManager() = default; + BiomeManager *clone() const; + const char *getObjectTitle() const { return "biome"; @@ -232,6 +236,8 @@ public: Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos); private: + BiomeManager() {}; + Server *m_server; }; diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index 28dde0209..db9c696ed 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -67,6 +67,13 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed, return nplaced; } +DecorationManager *DecorationManager::clone() const +{ + auto mgr = new DecorationManager(); + ObjDefManager::cloneTo(mgr); + return mgr; +} + /////////////////////////////////////////////////////////////////////////////// @@ -269,9 +276,42 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) } +void Decoration::cloneTo(Decoration *def) const +{ + ObjDef::cloneTo(def); + def->flags = flags; + def->mapseed = mapseed; + def->c_place_on = c_place_on; + def->sidelen = sidelen; + def->y_min = y_min; + def->y_max = y_max; + def->fill_ratio = fill_ratio; + def->np = np; + def->c_spawnby = c_spawnby; + def->nspawnby = nspawnby; + def->place_offset_y = place_offset_y; + def->biomes = biomes; +} + + /////////////////////////////////////////////////////////////////////////////// +ObjDef *DecoSimple::clone() const +{ + auto def = new DecoSimple(); + Decoration::cloneTo(def); + + def->c_decos = c_decos; + def->deco_height = deco_height; + def->deco_height_max = deco_height_max; + def->deco_param2 = deco_param2; + def->deco_param2_max = deco_param2_max; + + return def; +} + + void DecoSimple::resolveNodeNames() { Decoration::resolveNodeNames(); @@ -351,6 +391,21 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) /////////////////////////////////////////////////////////////////////////////// +ObjDef *DecoSchematic::clone() const +{ + auto def = new DecoSchematic(); + Decoration::cloneTo(def); + NodeResolver::cloneTo(def); + + def->rotation = rotation; + /* FIXME: This is not ideal, we only have a pointer to the schematic despite + * not owning it. Optimally this would be a handle. */ + def->schematic = schematic; // not cloned + + return def; +} + + size_t DecoSchematic::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) { // Schematic could have been unloaded but not the decoration diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h index 03fec04fd..af8fcd7bf 100644 --- a/src/mapgen/mg_decoration.h +++ b/src/mapgen/mg_decoration.h @@ -73,11 +73,16 @@ public: s16 place_offset_y = 0; std::unordered_set biomes; + +protected: + void cloneTo(Decoration *def) const; }; class DecoSimple : public Decoration { public: + ObjDef *clone() const; + virtual void resolveNodeNames(); virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling); @@ -91,6 +96,8 @@ public: class DecoSchematic : public Decoration { public: + ObjDef *clone() const; + DecoSchematic() = default; virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling); @@ -113,6 +120,8 @@ public: DecorationManager(IGameDef *gamedef); virtual ~DecorationManager() = default; + DecorationManager *clone() const; + const char *getObjectTitle() const { return "decoration"; @@ -133,4 +142,7 @@ public: } size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + +private: + DecorationManager() {}; }; diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp index c36249cb9..db647f82b 100644 --- a/src/mapgen/mg_ore.cpp +++ b/src/mapgen/mg_ore.cpp @@ -72,6 +72,14 @@ void OreManager::clear() } +OreManager *OreManager::clone() const +{ + auto mgr = new OreManager(); + ObjDefManager::cloneTo(mgr); + return mgr; +} + + /////////////////////////////////////////////////////////////////////////////// @@ -106,9 +114,37 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) } +void Ore::cloneTo(Ore *def) const +{ + ObjDef::cloneTo(def); + NodeResolver::cloneTo(def); + def->c_ore = c_ore; + def->c_wherein = c_wherein; + def->clust_scarcity = clust_scarcity; + def->clust_num_ores = clust_num_ores; + def->clust_size = clust_size; + def->y_min = y_min; + def->y_max = y_max; + def->ore_param2 = ore_param2; + def->flags = flags; + def->nthresh = nthresh; + def->np = np; + def->noise = nullptr; // cannot be shared! so created on demand + def->biomes = biomes; +} + + /////////////////////////////////////////////////////////////////////////////// +ObjDef *OreScatter::clone() const +{ + auto def = new OreScatter(); + Ore::cloneTo(def); + return def; +} + + void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) { @@ -158,6 +194,19 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, /////////////////////////////////////////////////////////////////////////////// +ObjDef *OreSheet::clone() const +{ + auto def = new OreSheet(); + Ore::cloneTo(def); + + def->column_height_max = column_height_max; + def->column_height_min = column_height_min; + def->column_midpoint_factor = column_midpoint_factor; + + return def; +} + + void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) { @@ -221,6 +270,20 @@ OrePuff::~OrePuff() } +ObjDef *OrePuff::clone() const +{ + auto def = new OrePuff(); + Ore::cloneTo(def); + + def->np_puff_top = np_puff_top; + def->np_puff_bottom = np_puff_bottom; + def->noise_puff_top = nullptr; // cannot be shared, on-demand + def->noise_puff_bottom = nullptr; + + return def; +} + + void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) { @@ -294,6 +357,14 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, /////////////////////////////////////////////////////////////////////////////// +ObjDef *OreBlob::clone() const +{ + auto def = new OreBlob(); + Ore::cloneTo(def); + return def; +} + + void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) { @@ -366,6 +437,19 @@ OreVein::~OreVein() } +ObjDef *OreVein::clone() const +{ + auto def = new OreVein(); + Ore::cloneTo(def); + + def->random_factor = random_factor; + def->noise2 = nullptr; // cannot be shared, on-demand + def->sizey_prev = sizey_prev; + + return def; +} + + void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) { @@ -434,6 +518,19 @@ OreStratum::~OreStratum() } +ObjDef *OreStratum::clone() const +{ + auto def = new OreStratum(); + Ore::cloneTo(def); + + def->np_stratum_thickness = np_stratum_thickness; + def->noise_stratum_thickness = nullptr; // cannot be shared, on-demand + def->stratum_thickness = stratum_thickness; + + return def; +} + + void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) { diff --git a/src/mapgen/mg_ore.h b/src/mapgen/mg_ore.h index d89360c3c..213bdc964 100644 --- a/src/mapgen/mg_ore.h +++ b/src/mapgen/mg_ore.h @@ -74,12 +74,17 @@ public: size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0; + +protected: + void cloneTo(Ore *def) const; }; class OreScatter : public Ore { public: static const bool NEEDS_NOISE = false; + ObjDef *clone() const; + virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap); }; @@ -88,6 +93,8 @@ class OreSheet : public Ore { public: static const bool NEEDS_NOISE = true; + ObjDef *clone() const; + u16 column_height_min; u16 column_height_max; float column_midpoint_factor; @@ -100,6 +107,8 @@ class OrePuff : public Ore { public: static const bool NEEDS_NOISE = true; + ObjDef *clone() const; + NoiseParams np_puff_top; NoiseParams np_puff_bottom; Noise *noise_puff_top = nullptr; @@ -116,6 +125,8 @@ class OreBlob : public Ore { public: static const bool NEEDS_NOISE = true; + ObjDef *clone() const; + virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax, u8 *biomemap); }; @@ -124,6 +135,8 @@ class OreVein : public Ore { public: static const bool NEEDS_NOISE = true; + ObjDef *clone() const; + float random_factor; Noise *noise2 = nullptr; int sizey_prev = 0; @@ -139,6 +152,8 @@ class OreStratum : public Ore { public: static const bool NEEDS_NOISE = false; + ObjDef *clone() const; + NoiseParams np_stratum_thickness; Noise *noise_stratum_thickness = nullptr; u16 stratum_thickness; @@ -155,6 +170,8 @@ public: OreManager(IGameDef *gamedef); virtual ~OreManager() = default; + OreManager *clone() const; + const char *getObjectTitle() const { return "ore"; @@ -183,4 +200,7 @@ public: void clear(); size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); + +private: + OreManager() {}; }; diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index c1acbfd9d..2e04d30e6 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -77,6 +77,11 @@ Schematic::~Schematic() delete []slice_probs; } +ObjDef *Schematic::clone() const +{ + FATAL_ERROR("not cloneable"); +} + void Schematic::resolveNodeNames() { @@ -93,6 +98,7 @@ void Schematic::resolveNodeNames() void Schematic::blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place) { + assert(schemdata && slice_probs); sanity_check(m_ndef != NULL); int xstride = 1; @@ -177,7 +183,7 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place) { assert(vm != NULL); - assert(schemdata != NULL); + assert(schemdata && slice_probs); sanity_check(m_ndef != NULL); //// Determine effective rotation and effective schematic dimensions diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h index 371b37557..770f74053 100644 --- a/src/mapgen/mg_schematic.h +++ b/src/mapgen/mg_schematic.h @@ -95,6 +95,8 @@ public: Schematic(); virtual ~Schematic(); + ObjDef *clone() const; + virtual void resolveNodeNames(); bool loadSchematicFromFile(const std::string &filename, @@ -128,6 +130,8 @@ public: SchematicManager(Server *server); virtual ~SchematicManager() = default; + // not cloneable + virtual void clear(); const char *getObjectTitle() const diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 37332c3c6..65199830f 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1572,6 +1572,18 @@ NodeResolver::~NodeResolver() } +void NodeResolver::cloneTo(NodeResolver *res) const +{ + FATAL_ERROR_IF(!m_resolve_done, "NodeResolver can only be cloned" + " after resolving has completed"); + /* We don't actually do anything significant. Since the node resolving has + * already completed, the class that called us will already have the + * resolved IDs in its data structures (which it copies on its own) */ + res->m_ndef = m_ndef; + res->m_resolve_done = true; +} + + void NodeResolver::nodeResolveInternal() { m_nodenames_idx = 0; diff --git a/src/nodedef.h b/src/nodedef.h index c77d53324..0fce6eab1 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -739,6 +739,9 @@ public: virtual ~NodeResolver(); virtual void resolveNodeNames() = 0; + // required because this class is used as mixin for ObjDef + void cloneTo(NodeResolver *res) const; + bool getIdFromNrBacklog(content_t *result_out, const std::string &node_alt, content_t c_fallback, bool error_on_fallback = true); diff --git a/src/objdef.cpp b/src/objdef.cpp index 08d6844fc..482544d37 100644 --- a/src/objdef.cpp +++ b/src/objdef.cpp @@ -182,3 +182,22 @@ bool ObjDefManager::decodeHandle(ObjDefHandle handle, u32 *index, *uid = get_bits(handle, 24, 7); return true; } + +// Cloning + +void ObjDef::cloneTo(ObjDef *def) const +{ + def->index = index; + def->uid = uid; + def->handle = handle; + def->name = name; +} + +void ObjDefManager::cloneTo(ObjDefManager *mgr) const +{ + mgr->m_ndef = m_ndef; + mgr->m_objects.reserve(m_objects.size()); + for (const auto &obj : m_objects) + mgr->m_objects.push_back(obj->clone()); + mgr->m_objtype = m_objtype; +} diff --git a/src/objdef.h b/src/objdef.h index 9ab3df977..20565029c 100644 --- a/src/objdef.h +++ b/src/objdef.h @@ -45,10 +45,22 @@ class ObjDef { public: virtual ~ObjDef() = default; + // Only implemented by child classes (leafs in class hierarchy) + // Should create new object of its own type, call cloneTo() of parent class + // and copy its own instance variables over + virtual ObjDef *clone() const = 0; + u32 index; u32 uid; ObjDefHandle handle; std::string name; + +protected: + // Only implemented by classes that have children themselves + // by copying the defintion and changing that argument type (!!!) + // Should defer to parent class cloneTo() if applicable and then copy + // over its own properties + void cloneTo(ObjDef *def) const; }; // WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is @@ -60,6 +72,8 @@ public: virtual ~ObjDefManager(); DISABLE_CLASS_COPY(ObjDefManager); + // T *clone() const; // implemented in child class with correct type + virtual const char *getObjectTitle() const { return "ObjDef"; } virtual void clear(); @@ -88,6 +102,10 @@ public: ObjDefType *type, u32 *uid); protected: + ObjDefManager() {}; + // Helper for child classes to implement clone() + void cloneTo(ObjDefManager *mgr) const; + const NodeDefManager *m_ndef; std::vector m_objects; ObjDefType m_objtype; diff --git a/src/unittest/test_objdef.cpp b/src/unittest/test_objdef.cpp index c2acdcfe7..40f7faa9d 100644 --- a/src/unittest/test_objdef.cpp +++ b/src/unittest/test_objdef.cpp @@ -32,6 +32,7 @@ public: void testHandles(); void testAddGetSetClear(); + void testClone(); }; static TestObjDef g_test_instance; @@ -40,10 +41,42 @@ void TestObjDef::runTests(IGameDef *gamedef) { TEST(testHandles); TEST(testAddGetSetClear); + TEST(testClone); } //////////////////////////////////////////////////////////////////////////////// +/* Minimal implementation of ObjDef and ObjDefManager subclass */ + +class MyObjDef : public ObjDef +{ +public: + ObjDef *clone() const + { + auto def = new MyObjDef(); + ObjDef::cloneTo(def); + def->testvalue = testvalue; + return def; + }; + + u32 testvalue; +}; + +class MyObjDefManager : public ObjDefManager +{ +public: + MyObjDefManager(ObjDefType type) : ObjDefManager(NULL, type){}; + MyObjDefManager *clone() const + { + auto mgr = new MyObjDefManager(); + ObjDefManager::cloneTo(mgr); + return mgr; + }; + +protected: + MyObjDefManager(){}; +}; + void TestObjDef::testHandles() { u32 uid = 0; @@ -69,25 +102,25 @@ void TestObjDef::testAddGetSetClear() UASSERTEQ(ObjDefType, testmgr.getType(), OBJDEF_GENERIC); - obj0 = new ObjDef; + obj0 = new MyObjDef; obj0->name = "foobar"; hObj0 = testmgr.add(obj0); UASSERT(hObj0 != OBJDEF_INVALID_HANDLE); UASSERTEQ(u32, obj0->index, 0); - obj1 = new ObjDef; + obj1 = new MyObjDef; obj1->name = "FooBaz"; hObj1 = testmgr.add(obj1); UASSERT(hObj1 != OBJDEF_INVALID_HANDLE); UASSERTEQ(u32, obj1->index, 1); - obj2 = new ObjDef; + obj2 = new MyObjDef; obj2->name = "asdf"; hObj2 = testmgr.add(obj2); UASSERT(hObj2 != OBJDEF_INVALID_HANDLE); UASSERTEQ(u32, obj2->index, 2); - obj3 = new ObjDef; + obj3 = new MyObjDef; obj3->name = "foobaz"; hObj3 = testmgr.add(obj3); UASSERT(hObj3 == OBJDEF_INVALID_HANDLE); @@ -104,3 +137,38 @@ void TestObjDef::testAddGetSetClear() testmgr.clear(); UASSERTEQ(size_t, testmgr.getNumObjects(), 0); } + +void TestObjDef::testClone() +{ + MyObjDefManager testmgr(OBJDEF_GENERIC); + ObjDefManager *mgrcopy; + MyObjDef *obj, *temp2; + ObjDef *temp1; + ObjDefHandle hObj; + + obj = new MyObjDef; + obj->testvalue = 0xee00ff11; + hObj = testmgr.add(obj); + UASSERT(hObj != OBJDEF_INVALID_HANDLE); + + mgrcopy = testmgr.clone(); + UASSERT(mgrcopy); + UASSERTEQ(ObjDefType, mgrcopy->getType(), testmgr.getType()); + UASSERTEQ(size_t, mgrcopy->getNumObjects(), testmgr.getNumObjects()); + + // 1) check that the same handle is still valid on the copy + temp1 = mgrcopy->get(hObj); + UASSERT(temp1); + UASSERT(temp1 == mgrcopy->getRaw(0)); + // 2) check that the copy has the correct C++ class + temp2 = dynamic_cast(temp1); + UASSERT(temp2); + // 3) check that it was correctly copied + UASSERTEQ(u32, obj->testvalue, temp2->testvalue); + // 4) check that it was copied AT ALL (not the same) + UASSERT(obj != temp2); + + testmgr.clear(); + mgrcopy->clear(); + delete mgrcopy; +} -- cgit v1.2.3 From 3c65d1acec27366d88fc3686d3f820175673e203 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 10 Apr 2020 02:05:20 +0200 Subject: Give the Mapgen on each EmergeThread its own Biome/Ore/Deco/SchemManager copy --- src/emerge.cpp | 60 ++++++++++++++++++++++++++++++++++++-- src/emerge.h | 48 ++++++++++++++++++++++++++---- src/mapgen/mapgen.cpp | 17 ++++++----- src/mapgen/mapgen.h | 15 +++++----- src/mapgen/mapgen_carpathian.cpp | 2 +- src/mapgen/mapgen_carpathian.h | 2 +- src/mapgen/mapgen_flat.cpp | 2 +- src/mapgen/mapgen_flat.h | 2 +- src/mapgen/mapgen_fractal.cpp | 2 +- src/mapgen/mapgen_fractal.h | 2 +- src/mapgen/mapgen_singlenode.cpp | 2 +- src/mapgen/mapgen_singlenode.h | 2 +- src/mapgen/mapgen_v5.cpp | 2 +- src/mapgen/mapgen_v5.h | 2 +- src/mapgen/mapgen_v6.cpp | 4 ++- src/mapgen/mapgen_v6.h | 4 +-- src/mapgen/mapgen_v7.cpp | 2 +- src/mapgen/mapgen_v7.h | 2 +- src/mapgen/mapgen_valleys.cpp | 2 +- src/mapgen/mapgen_valleys.h | 2 +- src/mapgen/mg_biome.cpp | 8 ++--- src/mapgen/mg_biome.h | 6 ++-- src/mapgen/mg_decoration.cpp | 16 ++++++++-- src/mapgen/mg_decoration.h | 2 ++ src/mapgen/mg_schematic.cpp | 27 +++++++++++++++-- src/mapgen/mg_schematic.h | 4 ++- src/script/lua_api/l_mapgen.cpp | 63 ++++++++++++++++++++++++---------------- 27 files changed, 225 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/emerge.cpp b/src/emerge.cpp index fe885447c..6e05a45c9 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -109,6 +109,28 @@ private: VoxelArea *m_ignorevariable; }; +EmergeParams::~EmergeParams() +{ + infostream << "EmergeParams: destroying " << this << std::endl; + // Delete everything that was cloned on creation of EmergeParams + delete biomemgr; + delete oremgr; + delete decomgr; + delete schemmgr; +} + +EmergeParams::EmergeParams(EmergeManager *parent, const BiomeManager *biomemgr, + const OreManager *oremgr, const DecorationManager *decomgr, + const SchematicManager *schemmgr) : + ndef(parent->ndef), + enable_mapgen_debug_info(parent->enable_mapgen_debug_info), + gen_notify_on(parent->gen_notify_on), + gen_notify_on_deco_ids(&parent->gen_notify_on_deco_ids), + biomemgr(biomemgr->clone()), oremgr(oremgr->clone()), + decomgr(decomgr->clone()), schemmgr(schemmgr->clone()) +{ +} + //// //// EmergeManager //// @@ -182,14 +204,48 @@ EmergeManager::~EmergeManager() } +BiomeManager *EmergeManager::getWritableBiomeManager() +{ + FATAL_ERROR_IF(!m_mapgens.empty(), + "Writable managers can only be returned before mapgen init"); + return biomemgr; +} + +OreManager *EmergeManager::getWritableOreManager() +{ + FATAL_ERROR_IF(!m_mapgens.empty(), + "Writable managers can only be returned before mapgen init"); + return oremgr; +} + +DecorationManager *EmergeManager::getWritableDecorationManager() +{ + FATAL_ERROR_IF(!m_mapgens.empty(), + "Writable managers can only be returned before mapgen init"); + return decomgr; +} + +SchematicManager *EmergeManager::getWritableSchematicManager() +{ + FATAL_ERROR_IF(!m_mapgens.empty(), + "Writable managers can only be returned before mapgen init"); + return schemmgr; +} + + void EmergeManager::initMapgens(MapgenParams *params) { FATAL_ERROR_IF(!m_mapgens.empty(), "Mapgen already initialised."); mgparams = params; - for (u32 i = 0; i != m_threads.size(); i++) - m_mapgens.push_back(Mapgen::createMapgen(params->mgtype, params, this)); + for (u32 i = 0; i != m_threads.size(); i++) { + EmergeParams *p = new EmergeParams( + this, biomemgr, oremgr, decomgr, schemmgr); + infostream << "EmergeManager: Created params " << p + << " for thread " << i << std::endl; + m_mapgens.push_back(Mapgen::createMapgen(params->mgtype, params, p)); + } } diff --git a/src/emerge.h b/src/emerge.h index df849e542..ab9fca2ba 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -86,6 +86,30 @@ struct BlockEmergeData { EmergeCallbackList callbacks; }; +class EmergeParams { + friend class EmergeManager; +public: + EmergeParams() = delete; + ~EmergeParams(); + DISABLE_CLASS_COPY(EmergeParams); + + const NodeDefManager *ndef; // shared + bool enable_mapgen_debug_info; + + u32 gen_notify_on; + const std::set *gen_notify_on_deco_ids; // shared + + BiomeManager *biomemgr; + OreManager *oremgr; + DecorationManager *decomgr; + SchematicManager *schemmgr; + +private: + EmergeParams(EmergeManager *parent, const BiomeManager *biomemgr, + const OreManager *oremgr, const DecorationManager *decomgr, + const SchematicManager *schemmgr); +}; + class EmergeManager { public: const NodeDefManager *ndef; @@ -106,17 +130,22 @@ public: // Environment is not created until after script initialization. MapSettingsManager *map_settings_mgr; - // Managers of various map generation-related components - BiomeManager *biomemgr; - OreManager *oremgr; - DecorationManager *decomgr; - SchematicManager *schemmgr; - // Methods EmergeManager(Server *server); ~EmergeManager(); DISABLE_CLASS_COPY(EmergeManager); + // no usage restrictions + const BiomeManager *getBiomeManager() const { return biomemgr; } + const OreManager *getOreManager() const { return oremgr; } + const DecorationManager *getDecorationManager() const { return decomgr; } + const SchematicManager *getSchematicManager() const { return schemmgr; } + // only usable before mapgen init + BiomeManager *getWritableBiomeManager(); + OreManager *getWritableOreManager(); + DecorationManager *getWritableDecorationManager(); + SchematicManager *getWritableSchematicManager(); + void initMapgens(MapgenParams *mgparams); void startThreads(); @@ -160,6 +189,13 @@ private: u16 m_qlimit_diskonly; u16 m_qlimit_generate; + // Managers of various map generation-related components + // Note that each Mapgen gets a copy(!) of these to work with + BiomeManager *biomemgr; + OreManager *oremgr; + DecorationManager *decomgr; + SchematicManager *schemmgr; + // Requires m_queue_mutex held EmergeThread *getOptimalThread(); diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 0094608ec..f57529082 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -106,8 +106,8 @@ STATIC_ASSERT( //// Mapgen //// -Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) : - gennotify(emerge->gen_notify_on, &emerge->gen_notify_on_deco_ids) +Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge) : + gennotify(emerge->gen_notify_on, emerge->gen_notify_on_deco_ids) { id = mapgenid; water_level = params->water_level; @@ -156,7 +156,7 @@ const char *Mapgen::getMapgenName(MapgenType mgtype) Mapgen *Mapgen::createMapgen(MapgenType mgtype, MapgenParams *params, - EmergeManager *emerge) + EmergeParams *emerge) { switch (mgtype) { case MAPGEN_CARPATHIAN: @@ -585,7 +585,7 @@ void Mapgen::spreadLight(const v3s16 &nmin, const v3s16 &nmax) //// MapgenBasic //// -MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge) +MapgenBasic::MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge) : Mapgen(mapgenid, params, emerge) { this->m_emerge = emerge; @@ -642,6 +642,8 @@ MapgenBasic::~MapgenBasic() { delete biomegen; delete []heightmap; + + delete m_emerge; // destroying EmergeParams is our responsibility } @@ -974,7 +976,7 @@ void MapgenBasic::generateDungeons(s16 max_stone_y) //// GenerateNotifier::GenerateNotifier(u32 notify_on, - std::set *notify_on_deco_ids) + const std::set *notify_on_deco_ids) { m_notify_on = notify_on; m_notify_on_deco_ids = notify_on_deco_ids; @@ -987,7 +989,8 @@ void GenerateNotifier::setNotifyOn(u32 notify_on) } -void GenerateNotifier::setNotifyOnDecoIds(std::set *notify_on_deco_ids) +void GenerateNotifier::setNotifyOnDecoIds( + const std::set *notify_on_deco_ids) { m_notify_on_deco_ids = notify_on_deco_ids; } @@ -999,7 +1002,7 @@ bool GenerateNotifier::addEvent(GenNotifyType type, v3s16 pos, u32 id) return false; if (type == GENNOTIFY_DECORATION && - m_notify_on_deco_ids->find(id) == m_notify_on_deco_ids->end()) + m_notify_on_deco_ids->find(id) == m_notify_on_deco_ids->cend()) return false; GenNotifyEvent gne; diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index dc325c791..7845c5349 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -51,6 +51,7 @@ class Biome; class BiomeGen; struct BiomeParams; class BiomeManager; +class EmergeParams; class EmergeManager; class MapBlock; class VoxelManipulator; @@ -87,10 +88,10 @@ struct GenNotifyEvent { class GenerateNotifier { public: GenerateNotifier() = default; - GenerateNotifier(u32 notify_on, std::set *notify_on_deco_ids); + GenerateNotifier(u32 notify_on, const std::set *notify_on_deco_ids); void setNotifyOn(u32 notify_on); - void setNotifyOnDecoIds(std::set *notify_on_deco_ids); + void setNotifyOnDecoIds(const std::set *notify_on_deco_ids); bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0); void getEvents(std::map > &event_map); @@ -98,7 +99,7 @@ public: private: u32 m_notify_on = 0; - std::set *m_notify_on_deco_ids; + const std::set *m_notify_on_deco_ids; std::list m_notify_events; }; @@ -176,7 +177,7 @@ public: GenerateNotifier gennotify; Mapgen() = default; - Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge); + Mapgen(int mapgenid, MapgenParams *params, EmergeParams *emerge); virtual ~Mapgen() = default; DISABLE_CLASS_COPY(Mapgen); @@ -215,7 +216,7 @@ public: static MapgenType getMapgenType(const std::string &mgname); static const char *getMapgenName(MapgenType mgtype); static Mapgen *createMapgen(MapgenType mgtype, MapgenParams *params, - EmergeManager *emerge); + EmergeParams *emerge); static MapgenParams *createMapgenParams(MapgenType mgtype); static void getMapgenNames(std::vector *mgnames, bool include_hidden); static void setDefaultSettings(Settings *settings); @@ -243,7 +244,7 @@ private: */ class MapgenBasic : public Mapgen { public: - MapgenBasic(int mapgenid, MapgenParams *params, EmergeManager *emerge); + MapgenBasic(int mapgenid, MapgenParams *params, EmergeParams *emerge); virtual ~MapgenBasic(); virtual void generateBiomes(); @@ -254,7 +255,7 @@ public: virtual void generateDungeons(s16 max_stone_y); protected: - EmergeManager *m_emerge; + EmergeParams *m_emerge; BiomeManager *m_bmgr; Noise *noise_filler_depth; diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index bd7ae5e7c..feb9b428c 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -49,7 +49,7 @@ FlagDesc flagdesc_mapgen_carpathian[] = { /////////////////////////////////////////////////////////////////////////////// -MapgenCarpathian::MapgenCarpathian(MapgenCarpathianParams *params, EmergeManager *emerge) +MapgenCarpathian::MapgenCarpathian(MapgenCarpathianParams *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_CARPATHIAN, params, emerge) { base_level = params->base_level; diff --git a/src/mapgen/mapgen_carpathian.h b/src/mapgen/mapgen_carpathian.h index acd379958..31b2b91d8 100644 --- a/src/mapgen/mapgen_carpathian.h +++ b/src/mapgen/mapgen_carpathian.h @@ -79,7 +79,7 @@ struct MapgenCarpathianParams : public MapgenParams class MapgenCarpathian : public MapgenBasic { public: - MapgenCarpathian(MapgenCarpathianParams *params, EmergeManager *emerge); + MapgenCarpathian(MapgenCarpathianParams *params, EmergeParams *emerge); ~MapgenCarpathian(); virtual MapgenType getType() const { return MAPGEN_CARPATHIAN; } diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp index 272964b51..369777ad2 100644 --- a/src/mapgen/mapgen_flat.cpp +++ b/src/mapgen/mapgen_flat.cpp @@ -47,7 +47,7 @@ FlagDesc flagdesc_mapgen_flat[] = { /////////////////////////////////////////////////////////////////////////////////////// -MapgenFlat::MapgenFlat(MapgenFlatParams *params, EmergeManager *emerge) +MapgenFlat::MapgenFlat(MapgenFlatParams *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_FLAT, params, emerge) { spflags = params->spflags; diff --git a/src/mapgen/mapgen_flat.h b/src/mapgen/mapgen_flat.h index c314c7605..4902a802c 100644 --- a/src/mapgen/mapgen_flat.h +++ b/src/mapgen/mapgen_flat.h @@ -64,7 +64,7 @@ struct MapgenFlatParams : public MapgenParams class MapgenFlat : public MapgenBasic { public: - MapgenFlat(MapgenFlatParams *params, EmergeManager *emerge); + MapgenFlat(MapgenFlatParams *params, EmergeParams *emerge); ~MapgenFlat(); virtual MapgenType getType() const { return MAPGEN_FLAT; } diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index 97f77d947..cb55bc288 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -47,7 +47,7 @@ FlagDesc flagdesc_mapgen_fractal[] = { /////////////////////////////////////////////////////////////////////////////////////// -MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge) +MapgenFractal::MapgenFractal(MapgenFractalParams *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_FRACTAL, params, emerge) { spflags = params->spflags; diff --git a/src/mapgen/mapgen_fractal.h b/src/mapgen/mapgen_fractal.h index 971dfd822..23af925bc 100644 --- a/src/mapgen/mapgen_fractal.h +++ b/src/mapgen/mapgen_fractal.h @@ -72,7 +72,7 @@ struct MapgenFractalParams : public MapgenParams class MapgenFractal : public MapgenBasic { public: - MapgenFractal(MapgenFractalParams *params, EmergeManager *emerge); + MapgenFractal(MapgenFractalParams *params, EmergeParams *emerge); ~MapgenFractal(); virtual MapgenType getType() const { return MAPGEN_FRACTAL; } diff --git a/src/mapgen/mapgen_singlenode.cpp b/src/mapgen/mapgen_singlenode.cpp index b64524e1c..cade9e7a8 100644 --- a/src/mapgen/mapgen_singlenode.cpp +++ b/src/mapgen/mapgen_singlenode.cpp @@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "emerge.h" -MapgenSinglenode::MapgenSinglenode(MapgenParams *params, EmergeManager *emerge) +MapgenSinglenode::MapgenSinglenode(MapgenParams *params, EmergeParams *emerge) : Mapgen(MAPGEN_SINGLENODE, params, emerge) { const NodeDefManager *ndef = emerge->ndef; diff --git a/src/mapgen/mapgen_singlenode.h b/src/mapgen/mapgen_singlenode.h index c21089eda..e056d9ab1 100644 --- a/src/mapgen/mapgen_singlenode.h +++ b/src/mapgen/mapgen_singlenode.h @@ -38,7 +38,7 @@ public: content_t c_node; u8 set_light; - MapgenSinglenode(MapgenParams *params, EmergeManager *emerge); + MapgenSinglenode(MapgenParams *params, EmergeParams *emerge); ~MapgenSinglenode() = default; virtual MapgenType getType() const { return MAPGEN_SINGLENODE; } diff --git a/src/mapgen/mapgen_v5.cpp b/src/mapgen/mapgen_v5.cpp index 3bd7615c4..124667e5d 100644 --- a/src/mapgen/mapgen_v5.cpp +++ b/src/mapgen/mapgen_v5.cpp @@ -44,7 +44,7 @@ FlagDesc flagdesc_mapgen_v5[] = { }; -MapgenV5::MapgenV5(MapgenV5Params *params, EmergeManager *emerge) +MapgenV5::MapgenV5(MapgenV5Params *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_V5, params, emerge) { spflags = params->spflags; diff --git a/src/mapgen/mapgen_v5.h b/src/mapgen/mapgen_v5.h index 17bc466f0..cf4ee4899 100644 --- a/src/mapgen/mapgen_v5.h +++ b/src/mapgen/mapgen_v5.h @@ -64,7 +64,7 @@ struct MapgenV5Params : public MapgenParams class MapgenV5 : public MapgenBasic { public: - MapgenV5(MapgenV5Params *params, EmergeManager *emerge); + MapgenV5(MapgenV5Params *params, EmergeParams *emerge); ~MapgenV5(); virtual MapgenType getType() const { return MAPGEN_V5; } diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index da9ae1428..e9692246c 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -54,7 +54,7 @@ FlagDesc flagdesc_mapgen_v6[] = { ///////////////////////////////////////////////////////////////////////////// -MapgenV6::MapgenV6(MapgenV6Params *params, EmergeManager *emerge) +MapgenV6::MapgenV6(MapgenV6Params *params, EmergeParams *emerge) : Mapgen(MAPGEN_V6, params, emerge) { m_emerge = emerge; @@ -160,6 +160,8 @@ MapgenV6::~MapgenV6() delete noise_humidity; delete[] heightmap; + + delete m_emerge; // our responsibility } diff --git a/src/mapgen/mapgen_v6.h b/src/mapgen/mapgen_v6.h index d8cdcb26f..ff565edec 100644 --- a/src/mapgen/mapgen_v6.h +++ b/src/mapgen/mapgen_v6.h @@ -83,7 +83,7 @@ struct MapgenV6Params : public MapgenParams { class MapgenV6 : public Mapgen { public: - EmergeManager *m_emerge; + EmergeParams *m_emerge; int ystride; u32 spflags; @@ -133,7 +133,7 @@ public: content_t c_stair_cobble; content_t c_stair_desert_stone; - MapgenV6(MapgenV6Params *params, EmergeManager *emerge); + MapgenV6(MapgenV6Params *params, EmergeParams *emerge); ~MapgenV6(); virtual MapgenType getType() const { return MAPGEN_V6; } diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 82556cc4f..43d5d822f 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -51,7 +51,7 @@ FlagDesc flagdesc_mapgen_v7[] = { //////////////////////////////////////////////////////////////////////////////// -MapgenV7::MapgenV7(MapgenV7Params *params, EmergeManager *emerge) +MapgenV7::MapgenV7(MapgenV7Params *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_V7, params, emerge) { spflags = params->spflags; diff --git a/src/mapgen/mapgen_v7.h b/src/mapgen/mapgen_v7.h index 0605c5c97..eeae3a956 100644 --- a/src/mapgen/mapgen_v7.h +++ b/src/mapgen/mapgen_v7.h @@ -75,7 +75,7 @@ struct MapgenV7Params : public MapgenParams { class MapgenV7 : public MapgenBasic { public: - MapgenV7(MapgenV7Params *params, EmergeManager *emerge); + MapgenV7(MapgenV7Params *params, EmergeParams *emerge); ~MapgenV7(); virtual MapgenType getType() const { return MAPGEN_V7; } diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index ff908b7bb..efcc8ee85 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -54,7 +54,7 @@ FlagDesc flagdesc_mapgen_valleys[] = { }; -MapgenValleys::MapgenValleys(MapgenValleysParams *params, EmergeManager *emerge) +MapgenValleys::MapgenValleys(MapgenValleysParams *params, EmergeParams *emerge) : MapgenBasic(MAPGEN_VALLEYS, params, emerge) { // NOTE: MapgenValleys has a hard dependency on BiomeGenOriginal diff --git a/src/mapgen/mapgen_valleys.h b/src/mapgen/mapgen_valleys.h index 1aec68842..34a923dfa 100644 --- a/src/mapgen/mapgen_valleys.h +++ b/src/mapgen/mapgen_valleys.h @@ -84,7 +84,7 @@ class MapgenValleys : public MapgenBasic { public: MapgenValleys(MapgenValleysParams *params, - EmergeManager *emerge); + EmergeParams *emerge); ~MapgenValleys(); virtual MapgenType getType() const { return MAPGEN_VALLEYS; } diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index 3a72c43bf..f3bc4e829 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -78,7 +78,7 @@ void BiomeManager::clear() EmergeManager *emerge = m_server->getEmergeManager(); // Remove all dangling references in Decorations - DecorationManager *decomgr = emerge->decomgr; + DecorationManager *decomgr = emerge->getWritableDecorationManager(); for (size_t i = 0; i != decomgr->getNumObjects(); i++) { Decoration *deco = (Decoration *)decomgr->getRaw(i); deco->biomes.clear(); @@ -104,7 +104,7 @@ BiomeManager *BiomeManager::clone() const // For BiomeGen type 'BiomeGenOriginal' float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat, - NoiseParams &np_heat_blend, u64 seed) + NoiseParams &np_heat_blend, u64 seed) const { return NoisePerlin2D(&np_heat, pos.X, pos.Z, seed) + @@ -114,7 +114,7 @@ float BiomeManager::getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat, // For BiomeGen type 'BiomeGenOriginal' float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity, - NoiseParams &np_humidity_blend, u64 seed) + NoiseParams &np_humidity_blend, u64 seed) const { return NoisePerlin2D(&np_humidity, pos.X, pos.Z, seed) + @@ -123,7 +123,7 @@ float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity // For BiomeGen type 'BiomeGenOriginal' -Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) +Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const { Biome *biome_closest = nullptr; Biome *biome_closest_blend = nullptr; diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index 6aadc32fa..0a4471cc3 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -230,10 +230,10 @@ public: // For BiomeGen type 'BiomeGenOriginal' float getHeatAtPosOriginal(v3s16 pos, NoiseParams &np_heat, - NoiseParams &np_heat_blend, u64 seed); + NoiseParams &np_heat_blend, u64 seed) const; float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity, - NoiseParams &np_humidity_blend, u64 seed); - Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos); + NoiseParams &np_humidity_blend, u64 seed) const; + Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const; private: BiomeManager() {}; diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index db9c696ed..a9b67d239 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -391,6 +391,13 @@ size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling) /////////////////////////////////////////////////////////////////////////////// +DecoSchematic::~DecoSchematic() +{ + if (was_cloned) + delete schematic; +} + + ObjDef *DecoSchematic::clone() const { auto def = new DecoSchematic(); @@ -398,9 +405,12 @@ ObjDef *DecoSchematic::clone() const NodeResolver::cloneTo(def); def->rotation = rotation; - /* FIXME: This is not ideal, we only have a pointer to the schematic despite - * not owning it. Optimally this would be a handle. */ - def->schematic = schematic; // not cloned + /* FIXME: We do not own this schematic, yet we only have a pointer to it + * and not a handle. We are left with no option but to clone it ourselves. + * This is a waste of memory and should be replaced with an alternative + * approach sometime. */ + def->schematic = dynamic_cast(schematic->clone()); + def->was_cloned = true; return def; } diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h index af8fcd7bf..1f9eb4510 100644 --- a/src/mapgen/mg_decoration.h +++ b/src/mapgen/mg_decoration.h @@ -99,11 +99,13 @@ public: ObjDef *clone() const; DecoSchematic() = default; + virtual ~DecoSchematic(); virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p, bool ceiling); Rotation rotation; Schematic *schematic = nullptr; + bool was_cloned = false; // see FIXME inside DecoSchemtic::clone() }; diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index 2e04d30e6..c3bd89f3a 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -43,12 +43,21 @@ SchematicManager::SchematicManager(Server *server) : } +SchematicManager *SchematicManager::clone() const +{ + auto mgr = new SchematicManager(); + assert(mgr); + ObjDefManager::cloneTo(mgr); + return mgr; +} + + void SchematicManager::clear() { EmergeManager *emerge = m_server->getEmergeManager(); // Remove all dangling references in Decorations - DecorationManager *decomgr = emerge->decomgr; + DecorationManager *decomgr = emerge->getWritableDecorationManager(); for (size_t i = 0; i != decomgr->getNumObjects(); i++) { Decoration *deco = (Decoration *)decomgr->getRaw(i); @@ -79,7 +88,21 @@ Schematic::~Schematic() ObjDef *Schematic::clone() const { - FATAL_ERROR("not cloneable"); + auto def = new Schematic(); + ObjDef::cloneTo(def); + NodeResolver::cloneTo(def); + + def->c_nodes = c_nodes; + def->flags = flags; + def->size = size; + FATAL_ERROR_IF(!schemdata, "Schematic can only be cloned after loading"); + u32 nodecount = size.X * size.Y * size.Z; + def->schemdata = new MapNode[nodecount]; + memcpy(def->schemdata, schemdata, sizeof(MapNode) * nodecount); + def->slice_probs = new u8[size.Y]; + memcpy(def->slice_probs, slice_probs, sizeof(u8) * size.Y); + + return def; } diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h index 770f74053..3222085e6 100644 --- a/src/mapgen/mg_schematic.h +++ b/src/mapgen/mg_schematic.h @@ -130,7 +130,7 @@ public: SchematicManager(Server *server); virtual ~SchematicManager() = default; - // not cloneable + SchematicManager *clone() const; virtual void clear(); @@ -145,6 +145,8 @@ public: } private: + SchematicManager() {}; + Server *m_server; }; diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index afe77826a..ba0304be3 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -91,7 +91,7 @@ struct EnumString ModApiMapgen::es_SchematicFormatType[] = {0, NULL}, }; -ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr); +ObjDef *get_objdef(lua_State *L, int index, const ObjDefManager *objmgr); Biome *get_or_load_biome(lua_State *L, int index, BiomeManager *biomemgr); @@ -114,7 +114,7 @@ bool read_deco_schematic(lua_State *L, SchematicManager *schemmgr, DecoSchematic /////////////////////////////////////////////////////////////////////////////// -ObjDef *get_objdef(lua_State *L, int index, ObjDefManager *objmgr) +ObjDef *get_objdef(lua_State *L, int index, const ObjDefManager *objmgr) { if (index < 0) index = lua_gettop(L) + 1 + index; @@ -486,7 +486,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L) if (!biome_str) return 0; - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager(); if (!bmgr) return 0; @@ -508,7 +508,7 @@ int ModApiMapgen::l_get_biome_name(lua_State *L) int biome_id = luaL_checkinteger(L, 1); - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager(); if (!bmgr) return 0; @@ -546,7 +546,7 @@ int ModApiMapgen::l_get_heat(lua_State *L) u64 seed; ss >> seed; - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager(); if (!bmgr) return 0; @@ -587,7 +587,7 @@ int ModApiMapgen::l_get_humidity(lua_State *L) u64 seed; ss >> seed; - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager(); if (!bmgr) return 0; @@ -635,7 +635,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L) u64 seed; ss >> seed; - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + const BiomeManager *bmgr = getServer(L)->getEmergeManager()->getBiomeManager(); if (!bmgr) return 0; @@ -1066,7 +1066,8 @@ int ModApiMapgen::l_get_decoration_id(lua_State *L) if (!deco_str) return 0; - DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr; + const DecorationManager *dmgr = + getServer(L)->getEmergeManager()->getDecorationManager(); if (!dmgr) return 0; @@ -1091,7 +1092,7 @@ int ModApiMapgen::l_register_biome(lua_State *L) luaL_checktype(L, index, LUA_TTABLE); const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + BiomeManager *bmgr = getServer(L)->getEmergeManager()->getWritableBiomeManager(); Biome *biome = read_biome_def(L, index, ndef); if (!biome) @@ -1117,9 +1118,10 @@ int ModApiMapgen::l_register_decoration(lua_State *L) luaL_checktype(L, index, LUA_TTABLE); const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); - DecorationManager *decomgr = getServer(L)->getEmergeManager()->decomgr; - BiomeManager *biomemgr = getServer(L)->getEmergeManager()->biomemgr; - SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; + EmergeManager *emerge = getServer(L)->getEmergeManager(); + DecorationManager *decomgr = emerge->getWritableDecorationManager(); + BiomeManager *biomemgr = emerge->getWritableBiomeManager(); + SchematicManager *schemmgr = emerge->getWritableSchematicManager(); enum DecorationType decotype = (DecorationType)getenumfield(L, index, "deco_type", es_DecorationType, -1); @@ -1274,8 +1276,9 @@ int ModApiMapgen::l_register_ore(lua_State *L) luaL_checktype(L, index, LUA_TTABLE); const NodeDefManager *ndef = getServer(L)->getNodeDefManager(); - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; - OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr; + EmergeManager *emerge = getServer(L)->getEmergeManager(); + BiomeManager *bmgr = emerge->getWritableBiomeManager(); + OreManager *oremgr = emerge->getWritableOreManager(); enum OreType oretype = (OreType)getenumfield(L, index, "ore_type", es_OreType, ORE_SCATTER); @@ -1422,7 +1425,8 @@ int ModApiMapgen::l_register_schematic(lua_State *L) { NO_MAP_LOCK_REQUIRED; - SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; + SchematicManager *schemmgr = + getServer(L)->getEmergeManager()->getWritableSchematicManager(); StringMap replace_names; if (lua_istable(L, 2)) @@ -1449,7 +1453,8 @@ int ModApiMapgen::l_clear_registered_biomes(lua_State *L) { NO_MAP_LOCK_REQUIRED; - BiomeManager *bmgr = getServer(L)->getEmergeManager()->biomemgr; + BiomeManager *bmgr = + getServer(L)->getEmergeManager()->getWritableBiomeManager(); bmgr->clear(); return 0; } @@ -1460,7 +1465,8 @@ int ModApiMapgen::l_clear_registered_decorations(lua_State *L) { NO_MAP_LOCK_REQUIRED; - DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr; + DecorationManager *dmgr = + getServer(L)->getEmergeManager()->getWritableDecorationManager(); dmgr->clear(); return 0; } @@ -1471,7 +1477,8 @@ int ModApiMapgen::l_clear_registered_ores(lua_State *L) { NO_MAP_LOCK_REQUIRED; - OreManager *omgr = getServer(L)->getEmergeManager()->oremgr; + OreManager *omgr = + getServer(L)->getEmergeManager()->getWritableOreManager(); omgr->clear(); return 0; } @@ -1482,7 +1489,8 @@ int ModApiMapgen::l_clear_registered_schematics(lua_State *L) { NO_MAP_LOCK_REQUIRED; - SchematicManager *smgr = getServer(L)->getEmergeManager()->schemmgr; + SchematicManager *smgr = + getServer(L)->getEmergeManager()->getWritableSchematicManager(); smgr->clear(); return 0; } @@ -1508,7 +1516,8 @@ int ModApiMapgen::l_generate_ores(lua_State *L) u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); - emerge->oremgr->placeAllOres(&mg, blockseed, pmin, pmax); + OreManager *oremgr = (OreManager*) emerge->getOreManager(); // FIXME FIXME + oremgr->placeAllOres(&mg, blockseed, pmin, pmax); return 0; } @@ -1534,7 +1543,8 @@ int ModApiMapgen::l_generate_decorations(lua_State *L) u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); - emerge->decomgr->placeAllDecos(&mg, blockseed, pmin, pmax); + DecorationManager *decomgr = (DecorationManager*) emerge->getDecorationManager(); // FIXME FIXME + decomgr->placeAllDecos(&mg, blockseed, pmin, pmax); return 0; } @@ -1614,7 +1624,8 @@ int ModApiMapgen::l_place_schematic(lua_State *L) GET_ENV_PTR; ServerMap *map = &(env->getServerMap()); - SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; + SchematicManager *schemmgr = (SchematicManager*) + getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME //// Read position v3s16 p = check_v3s16(L, 1); @@ -1659,7 +1670,8 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L) { NO_MAP_LOCK_REQUIRED; - SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; + SchematicManager *schemmgr = (SchematicManager*) + getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME //// Read VoxelManip object MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm; @@ -1707,7 +1719,7 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L) { NO_MAP_LOCK_REQUIRED; - SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; + const SchematicManager *schemmgr = getServer(L)->getEmergeManager()->getSchematicManager(); //// Read options bool use_comments = getboolfield_default(L, 3, "lua_use_comments", false); @@ -1758,7 +1770,8 @@ int ModApiMapgen::l_read_schematic(lua_State *L) { NO_MAP_LOCK_REQUIRED; - SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; + const SchematicManager *schemmgr = + getServer(L)->getEmergeManager()->getSchematicManager(); //// Read options std::string write_yslice = getstringfield_default(L, 2, "write_yslice_prob", "all"); -- cgit v1.2.3 From c28fbd06a8bfafc9691a92c90f0cf10ec94cd314 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 10 Apr 2020 02:43:49 +0200 Subject: Fix remaining issues with mapgen scriptapi --- src/emerge.h | 6 ++++++ src/mapgen/mg_biome.cpp | 3 ++- src/mapgen/mg_biome.h | 4 +++- src/mapgen/mg_schematic.cpp | 5 +++-- src/mapgen/mg_schematic.h | 5 +++-- src/objdef.h | 1 + src/script/lua_api/l_mapgen.cpp | 24 ++++++++---------------- 7 files changed, 26 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/emerge.h b/src/emerge.h index ab9fca2ba..6f204666d 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -44,6 +44,7 @@ class OreManager; class DecorationManager; class SchematicManager; class Server; +class ModApiMapgen; // Structure containing inputs/outputs for chunk generation struct BlockMakeData { @@ -111,6 +112,11 @@ private: }; class EmergeManager { + /* The mod API needs unchecked access to allow: + * - using decomgr or oremgr to place decos/ores + * - using schemmgr to load and place schematics + */ + friend class ModApiMapgen; public: const NodeDefManager *ndef; bool enable_mapgen_debug_info; diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index f3bc4e829..8c59ac9e6 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -123,7 +123,8 @@ float BiomeManager::getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity // For BiomeGen type 'BiomeGenOriginal' -Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const +const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, + float humidity, v3s16 pos) const { Biome *biome_closest = nullptr; Biome *biome_closest_blend = nullptr; diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index 0a4471cc3..57f4aa20d 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -90,6 +90,7 @@ struct BiomeParams { s32 seed; }; +// WARNING: this class is not thread-safe class BiomeGen { public: virtual ~BiomeGen() = default; @@ -233,7 +234,8 @@ public: NoiseParams &np_heat_blend, u64 seed) const; float getHumidityAtPosOriginal(v3s16 pos, NoiseParams &np_humidity, NoiseParams &np_humidity_blend, u64 seed) const; - Biome *getBiomeFromNoiseOriginal(float heat, float humidity, v3s16 pos) const; + const Biome *getBiomeFromNoiseOriginal(float heat, float humidity, + v3s16 pos) const; private: BiomeManager() {}; diff --git a/src/mapgen/mg_schematic.cpp b/src/mapgen/mg_schematic.cpp index c3bd89f3a..ba102d997 100644 --- a/src/mapgen/mg_schematic.cpp +++ b/src/mapgen/mg_schematic.cpp @@ -359,7 +359,7 @@ bool Schematic::deserializeFromMts(std::istream *is, bool Schematic::serializeToMts(std::ostream *os, - const std::vector &names) + const std::vector &names) const { std::ostream &ss = *os; @@ -383,7 +383,8 @@ bool Schematic::serializeToMts(std::ostream *os, bool Schematic::serializeToLua(std::ostream *os, - const std::vector &names, bool use_comments, u32 indent_spaces) + const std::vector &names, bool use_comments, + u32 indent_spaces) const { std::ostream &ss = *os; diff --git a/src/mapgen/mg_schematic.h b/src/mapgen/mg_schematic.h index 3222085e6..6b31251b6 100644 --- a/src/mapgen/mg_schematic.h +++ b/src/mapgen/mg_schematic.h @@ -106,9 +106,10 @@ public: bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2); bool deserializeFromMts(std::istream *is, std::vector *names); - bool serializeToMts(std::ostream *os, const std::vector &names); + bool serializeToMts(std::ostream *os, + const std::vector &names) const; bool serializeToLua(std::ostream *os, const std::vector &names, - bool use_comments, u32 indent_spaces); + bool use_comments, u32 indent_spaces) const; void blitToVManip(MMVManip *vm, v3s16 p, Rotation rot, bool force_place); bool placeOnVManip(MMVManip *vm, v3s16 p, u32 flags, Rotation rot, bool force_place); diff --git a/src/objdef.h b/src/objdef.h index 20565029c..e40324a88 100644 --- a/src/objdef.h +++ b/src/objdef.h @@ -66,6 +66,7 @@ protected: // WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is // added/set to. Note that ObjDefs managed by ObjDefManager are NOT refcounted, // so the same ObjDef instance must not be referenced multiple +// TODO: const correctness for getter methods class ObjDefManager { public: ObjDefManager(IGameDef *gamedef, ObjDefType type); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index ba0304be3..584085428 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -490,7 +490,7 @@ int ModApiMapgen::l_get_biome_id(lua_State *L) if (!bmgr) return 0; - Biome *biome = (Biome *)bmgr->getByName(biome_str); + const Biome *biome = (Biome *)bmgr->getByName(biome_str); if (!biome || biome->index == OBJDEF_INVALID_INDEX) return 0; @@ -512,7 +512,7 @@ int ModApiMapgen::l_get_biome_name(lua_State *L) if (!bmgr) return 0; - Biome *b = (Biome *)bmgr->getRaw(biome_id); + const Biome *b = (Biome *)bmgr->getRaw(biome_id); lua_pushstring(L, b->name.c_str()); return 1; @@ -551,8 +551,6 @@ int ModApiMapgen::l_get_heat(lua_State *L) return 0; float heat = bmgr->getHeatAtPosOriginal(pos, np_heat, np_heat_blend, seed); - if (!heat) - return 0; lua_pushnumber(L, heat); @@ -593,8 +591,6 @@ int ModApiMapgen::l_get_humidity(lua_State *L) float humidity = bmgr->getHumidityAtPosOriginal(pos, np_humidity, np_humidity_blend, seed); - if (!humidity) - return 0; lua_pushnumber(L, humidity); @@ -648,7 +644,7 @@ int ModApiMapgen::l_get_biome_data(lua_State *L) if (!humidity) return 0; - Biome *biome = (Biome *)bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos); + const Biome *biome = bmgr->getBiomeFromNoiseOriginal(heat, humidity, pos); if (!biome || biome->index == OBJDEF_INVALID_INDEX) return 0; @@ -1516,8 +1512,7 @@ int ModApiMapgen::l_generate_ores(lua_State *L) u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); - OreManager *oremgr = (OreManager*) emerge->getOreManager(); // FIXME FIXME - oremgr->placeAllOres(&mg, blockseed, pmin, pmax); + emerge->oremgr->placeAllOres(&mg, blockseed, pmin, pmax); return 0; } @@ -1543,8 +1538,7 @@ int ModApiMapgen::l_generate_decorations(lua_State *L) u32 blockseed = Mapgen::getBlockSeed(pmin, mg.seed); - DecorationManager *decomgr = (DecorationManager*) emerge->getDecorationManager(); // FIXME FIXME - decomgr->placeAllDecos(&mg, blockseed, pmin, pmax); + emerge->decomgr->placeAllDecos(&mg, blockseed, pmin, pmax); return 0; } @@ -1624,8 +1618,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L) GET_ENV_PTR; ServerMap *map = &(env->getServerMap()); - SchematicManager *schemmgr = (SchematicManager*) - getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME + SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; //// Read position v3s16 p = check_v3s16(L, 1); @@ -1670,8 +1663,7 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L) { NO_MAP_LOCK_REQUIRED; - SchematicManager *schemmgr = (SchematicManager*) - getServer(L)->getEmergeManager()->getSchematicManager(); // FIXME FIXME + SchematicManager *schemmgr = getServer(L)->getEmergeManager()->schemmgr; //// Read VoxelManip object MMVManip *vm = LuaVoxelManip::checkobject(L, 1)->vm; @@ -1727,7 +1719,7 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L) //// Get schematic bool was_loaded = false; - Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr); + const Schematic *schem = (Schematic *)get_objdef(L, 1, schemmgr); if (!schem) { schem = load_schematic(L, 1, NULL, NULL); was_loaded = true; -- cgit v1.2.3 From f3e87c53a5afc264e657acd99d3a39fbec3b63c9 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 18:33:50 +0200 Subject: Fix thread safety of PcgRandom use in BiomeGen --- src/mapgen/mg_biome.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index 8c59ac9e6..610c38594 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -154,9 +154,11 @@ const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat, } } - mysrand(pos.Y + (heat + humidity) * 0.9f); + const u64 seed = pos.Y + (heat + humidity) * 0.9f; + PcgRandom rng(seed); + if (biome_closest_blend && dist_min_blend <= dist_min && - myrand_range(0, biome_closest_blend->vertical_blend) >= + rng.range(0, biome_closest_blend->vertical_blend) >= pos.Y - biome_closest_blend->max_pos.Y) return biome_closest_blend; @@ -319,10 +321,11 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po // Carefully tune pseudorandom seed variation to avoid single node dither // and create larger scale blending patterns similar to horizontal biome // blend. - mysrand(pos.Y + (heat + humidity) * 0.9f); + const u64 seed = pos.Y + (heat + humidity) * 0.9f; + PcgRandom rng(seed); if (biome_closest_blend && dist_min_blend <= dist_min && - myrand_range(0, biome_closest_blend->vertical_blend) >= + rng.range(0, biome_closest_blend->vertical_blend) >= pos.Y - biome_closest_blend->max_pos.Y) return biome_closest_blend; -- cgit v1.2.3 From cb159f8d8af4556391db8a6875657625733eeb11 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 5 May 2020 20:19:47 +0200 Subject: Fix crash when exiting server during running mapgen easily reproducible with a high num_emerge_threads and /emergeblocks --- src/emerge.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/emerge.cpp b/src/emerge.cpp index 6e05a45c9..a9fc0a4de 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -255,8 +255,9 @@ Mapgen *EmergeManager::getCurrentMapgen() return nullptr; for (u32 i = 0; i != m_threads.size(); i++) { - if (m_threads[i]->isCurrentThread()) - return m_threads[i]->m_mapgen; + EmergeThread *t = m_threads[i]; + if (t->isRunning() && t->isCurrentThread()) + return t->m_mapgen; } return nullptr; @@ -642,8 +643,7 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata, /* Clear generate notifier events */ - Mapgen *mg = m_emerge->getCurrentMapgen(); - mg->gennotify.clearEvents(); + m_mapgen->gennotify.clearEvents(); EMERGE_DBG_OUT("ended up with: " << analyze_block(block)); -- cgit v1.2.3 From b6b80f55c8a2bf4eae440108b3274f2f921e3a94 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 Apr 2020 22:52:00 +0200 Subject: Expose collided objects in moveresult closes #9787 --- doc/lua_api.txt | 1 + src/collision.cpp | 40 ++++++++++++++++++++++++++-------------- src/collision.h | 1 + src/script/common/c_content.cpp | 3 +++ 4 files changed, 31 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b1099ec59..948e0f89e 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6632,6 +6632,7 @@ Collision info passed to `on_step`: type = string, -- "node" or "object", axis = string, -- "x", "y" or "z" node_pos = vector, -- if type is "node" + object = ObjectRef, -- if type is "object" old_velocity = vector, new_velocity = vector, }, diff --git a/src/collision.cpp b/src/collision.cpp index a089f3377..3b5e79a66 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -37,18 +37,30 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif struct NearbyCollisionInfo { - NearbyCollisionInfo(bool is_ul, bool is_obj, int bouncy, - const v3s16 &pos, const aabb3f &box) : + // node + NearbyCollisionInfo(bool is_ul, int bouncy, const v3s16 &pos, + const aabb3f &box) : is_unloaded(is_ul), - is_object(is_obj), + obj(nullptr), bouncy(bouncy), position(pos), box(box) {} + // object + NearbyCollisionInfo(ActiveObject *obj, int bouncy, + const aabb3f &box) : + is_unloaded(false), + obj(obj), + bouncy(bouncy), + box(box) + {} + + inline bool isObject() const { return obj != nullptr; } + bool is_unloaded; bool is_step_up = false; - bool is_object; + ActiveObject *obj; int bouncy; v3s16 position; aabb3f box; @@ -312,13 +324,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, for (auto box : nodeboxes) { box.MinEdge += posf; box.MaxEdge += posf; - cinfo.emplace_back(false, false, n_bouncy_value, p, box); + cinfo.emplace_back(false, n_bouncy_value, p, box); } } else { // Collide with unloaded nodes (position invalid) and loaded // CONTENT_IGNORE nodes (position valid) aabb3f box = getNodeBox(p, BS); - cinfo.emplace_back(true, false, 0, p, box); + cinfo.emplace_back(true, 0, p, box); } } @@ -383,12 +395,10 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, iter != objects.end(); ++iter) { ActiveObject *object = *iter; - if (object) { + if (object && object->collideWithObjects()) { aabb3f object_collisionbox; - if (object->getCollisionBox(&object_collisionbox) && - object->collideWithObjects()) { - cinfo.emplace_back(false, true, 0, v3s16(), object_collisionbox); - } + if (object->getCollisionBox(&object_collisionbox)) + cinfo.emplace_back(object, 0, object_collisionbox); } } #ifndef SERVER @@ -399,7 +409,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, v3f lplayer_pos = lplayer->getPosition(); lplayer_collisionbox.MinEdge += lplayer_pos; lplayer_collisionbox.MaxEdge += lplayer_pos; - cinfo.emplace_back(false, true, 0, v3s16(), lplayer_collisionbox); + ActiveObject *obj = (ActiveObject*) lplayer->getCAO(); + cinfo.emplace_back(obj, 0, lplayer_collisionbox); } } #endif @@ -498,12 +509,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, is_collision = false; CollisionInfo info; - if (nearest_info.is_object) + if (nearest_info.isObject()) info.type = COLLISION_OBJECT; else info.type = COLLISION_NODE; info.node_p = nearest_info.position; + info.object = nearest_info.obj; info.old_speed = *speed_f; info.plane = nearest_collided; @@ -572,7 +584,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.05f) { result.touching_ground = true; - if (box_info.is_object) + if (box_info.isObject()) result.standing_on_object = true; } } diff --git a/src/collision.h b/src/collision.h index fa47cccc1..87a502828 100644 --- a/src/collision.h +++ b/src/collision.h @@ -48,6 +48,7 @@ struct CollisionInfo CollisionType type = COLLISION_NODE; CollisionAxis axis = COLLISION_AXIS_NONE; v3s16 node_p = v3s16(-32768,-32768,-32768); // COLLISION_NODE + ActiveObject *object = nullptr; // COLLISION_OBJECT v3f old_speed; v3f new_speed; int plane = -1; diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 95364000c..dac828316 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -2043,6 +2043,9 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res) if (c.type == COLLISION_NODE) { push_v3s16(L, c.node_p); lua_setfield(L, -2, "node_pos"); + } else if (c.type == COLLISION_OBJECT) { + push_objectRef(L, c.object->getId()); + lua_setfield(L, -2, "object"); } push_v3f(L, c.old_speed / BS); -- cgit v1.2.3 From 4f9a5f67ee745d78fdc3e173972a3df110f989cf Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 6 May 2020 14:25:57 +0200 Subject: Android: porting_android.cpp refactoring (#9687) * Android: porting_android.cpp refactoring * Replace assert to FATAL_ERROR_IF --- src/porting_android.cpp | 135 ++++++++++++++++++++---------------------------- src/porting_android.h | 14 +++-- 2 files changed, 62 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/porting_android.cpp b/src/porting_android.cpp index 4130bdb6d..2c91df235 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -47,8 +47,7 @@ void android_main(android_app *app) Thread::setName("Main"); try { - app_dummy(); - char *argv[] = {strdup(PROJECT_NAME), NULL}; + char *argv[] = {strdup(PROJECT_NAME), nullptr}; main(ARRLEN(argv) - 1, argv); free(argv[0]); } catch (std::exception &e) { @@ -64,85 +63,73 @@ void android_main(android_app *app) exit(retval); } -/* handler for finished message box input */ -/* Intentionally NOT in namespace porting */ -/* TODO this doesn't work as expected, no idea why but there's a workaround */ -/* for it right now */ +/** + * Handler for finished message box input + * Intentionally NOT in namespace porting + * ToDo: this doesn't work as expected, there's a workaround for it right now + */ extern "C" { JNIEXPORT void JNICALL Java_net_minetest_minetest_GameActivity_putMessageBoxResult( - JNIEnv * env, jclass thiz, jstring text) + JNIEnv *env, jclass thiz, jstring text) { - errorstream << "Java_net_minetest_minetest_GameActivity_putMessageBoxResult got: " - << std::string((const char*)env->GetStringChars(text,0)) - << std::endl; + errorstream << + "Java_net_minetest_minetest_GameActivity_putMessageBoxResult got: " << + std::string((const char*) env->GetStringChars(text, nullptr)) << std::endl; } } namespace porting { - -std::string path_storage = DIR_DELIM "sdcard" DIR_DELIM; - -android_app* app_global; -JNIEnv* jnienv; +android_app *app_global; +JNIEnv *jnienv; jclass nativeActivity; -jclass findClass(std::string classname) +jclass findClass(const std::string &classname) { - if (jnienv == 0) { - return 0; - } + if (jnienv == nullptr) + return nullptr; jclass nativeactivity = jnienv->FindClass("android/app/NativeActivity"); - jmethodID getClassLoader = - jnienv->GetMethodID(nativeactivity,"getClassLoader", - "()Ljava/lang/ClassLoader;"); - jobject cls = - jnienv->CallObjectMethod(app_global->activity->clazz, getClassLoader); + jmethodID getClassLoader = jnienv->GetMethodID( + nativeactivity, "getClassLoader", "()Ljava/lang/ClassLoader;"); + jobject cls = jnienv->CallObjectMethod( + app_global->activity->clazz, getClassLoader); jclass classLoader = jnienv->FindClass("java/lang/ClassLoader"); - jmethodID findClass = - jnienv->GetMethodID(classLoader, "loadClass", + jmethodID findClass = jnienv->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); - jstring strClassName = - jnienv->NewStringUTF(classname.c_str()); + jstring strClassName = jnienv->NewStringUTF(classname.c_str()); return (jclass) jnienv->CallObjectMethod(cls, findClass, strClassName); } void initAndroid() { - porting::jnienv = NULL; + porting::jnienv = nullptr; JavaVM *jvm = app_global->activity->vm; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = PROJECT_NAME_C "NativeThread"; - lJavaVMAttachArgs.group = NULL; -#ifdef NDEBUG - // This is a ugly hack as arm v7a non debuggable builds crash without this - // printf ... if someone finds out why please fix it! - infostream << "Attaching native thread. " << std::endl; -#endif - if ( jvm->AttachCurrentThread(&porting::jnienv, &lJavaVMAttachArgs) == JNI_ERR) { + lJavaVMAttachArgs.group = nullptr; + + if (jvm->AttachCurrentThread(&porting::jnienv, &lJavaVMAttachArgs) == JNI_ERR) { errorstream << "Failed to attach native thread to jvm" << std::endl; exit(-1); } nativeActivity = findClass("net/minetest/minetest/GameActivity"); - if (nativeActivity == 0) { + if (nativeActivity == nullptr) errorstream << "porting::initAndroid unable to find java native activity class" << std::endl; - } #ifdef GPROF - /* in the start-up code */ + // in the start-up code __android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME_C, "Initializing GPROF profiler"); - monstartup("libminetest.so"); + monstartup("libMinetest.so"); #endif } void cleanupAndroid() { - #ifdef GPROF errorstream << "Shutting down GPROF profiler" << std::endl; setenv("CPUPROFILE", (path_user + DIR_DELIM + "gmon.out").c_str(), 1); @@ -157,7 +144,7 @@ static std::string javaStringToUTF8(jstring js) { std::string str; // Get string as a UTF-8 c-string - const char *c_str = jnienv->GetStringUTFChars(js, NULL); + const char *c_str = jnienv->GetStringUTFChars(js, nullptr); // Save it str = c_str; // And free the c-string @@ -166,17 +153,15 @@ static std::string javaStringToUTF8(jstring js) } // Calls static method if obj is NULL -static std::string getAndroidPath(jclass cls, jobject obj, jclass cls_File, - jmethodID mt_getAbsPath, const char *getter) +static std::string getAndroidPath( + jclass cls, jobject obj, jmethodID mt_getAbsPath, const char *getter) { // Get getter method jmethodID mt_getter; if (obj) - mt_getter = jnienv->GetMethodID(cls, getter, - "()Ljava/io/File;"); + mt_getter = jnienv->GetMethodID(cls, getter, "()Ljava/io/File;"); else - mt_getter = jnienv->GetStaticMethodID(cls, getter, - "()Ljava/io/File;"); + mt_getter = jnienv->GetStaticMethodID(cls, getter, "()Ljava/io/File;"); // Call getter jobject ob_file; @@ -186,8 +171,7 @@ static std::string getAndroidPath(jclass cls, jobject obj, jclass cls_File, ob_file = jnienv->CallStaticObjectMethod(cls, mt_getter); // Call getAbsolutePath - jstring js_path = (jstring) jnienv->CallObjectMethod(ob_file, - mt_getAbsPath); + auto js_path = (jstring) jnienv->CallObjectMethod(ob_file, mt_getAbsPath); return javaStringToUTF8(js_path); } @@ -201,26 +185,24 @@ void initializePathsAndroid() // Get getAbsolutePath method jmethodID mt_getAbsPath = jnienv->GetMethodID(cls_File, "getAbsolutePath", "()Ljava/lang/String;"); + std::string path_storage = getAndroidPath(cls_Env, nullptr, + mt_getAbsPath, "getExternalStorageDirectory"); - path_cache = getAndroidPath(nativeActivity, app_global->activity->clazz, - cls_File, mt_getAbsPath, "getCacheDir"); - path_storage = getAndroidPath(cls_Env, NULL, cls_File, mt_getAbsPath, - "getExternalStorageDirectory"); path_user = path_storage + DIR_DELIM + PROJECT_NAME_C; path_share = path_storage + DIR_DELIM + PROJECT_NAME_C; - + path_cache = getAndroidPath(nativeActivity, + app_global->activity->clazz, mt_getAbsPath, "getCacheDir"); migrateCachePath(); } -void showInputDialog(const std::string& acceptButton, const std::string& hint, - const std::string& current, int editType) +void showInputDialog(const std::string &acceptButton, const std::string &hint, + const std::string ¤t, int editType) { - jmethodID showdialog = jnienv->GetMethodID(nativeActivity,"showDialog", + jmethodID showdialog = jnienv->GetMethodID(nativeActivity, "showDialog", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V"); - if (showdialog == 0) { - assert("porting::showInputDialog unable to find java show dialog method" == 0); - } + FATAL_ERROR_IF(showdialog == nullptr, + "porting::showInputDialog unable to find java show dialog method"); jstring jacceptButton = jnienv->NewStringUTF(acceptButton.c_str()); jstring jhint = jnienv->NewStringUTF(hint.c_str()); @@ -236,9 +218,8 @@ int getInputDialogState() jmethodID dialogstate = jnienv->GetMethodID(nativeActivity, "getDialogState", "()I"); - if (dialogstate == 0) { - assert("porting::getInputDialogState unable to find java dialog state method" == 0); - } + FATAL_ERROR_IF(dialogstate == nullptr, + "porting::getInputDialogState unable to find java dialog state method"); return jnienv->CallIntMethod(app_global->activity->clazz, dialogstate); } @@ -248,14 +229,13 @@ std::string getInputDialogValue() jmethodID dialogvalue = jnienv->GetMethodID(nativeActivity, "getDialogValue", "()Ljava/lang/String;"); - if (dialogvalue == 0) { - assert("porting::getInputDialogValue unable to find java dialog value method" == 0); - } + FATAL_ERROR_IF(dialogvalue == nullptr, + "porting::getInputDialogValue unable to find java dialog value method"); jobject result = jnienv->CallObjectMethod(app_global->activity->clazz, dialogvalue); - const char* javachars = jnienv->GetStringUTFChars((jstring) result,0); + const char *javachars = jnienv->GetStringUTFChars((jstring) result, nullptr); std::string text(javachars); jnienv->ReleaseStringUTFChars((jstring) result, javachars); @@ -269,12 +249,11 @@ float getDisplayDensity() static float value = 0; if (firstrun) { - jmethodID getDensity = jnienv->GetMethodID(nativeActivity, "getDensity", - "()F"); + jmethodID getDensity = jnienv->GetMethodID(nativeActivity, + "getDensity", "()F"); - if (getDensity == 0) { - assert("porting::getDisplayDensity unable to find java getDensity method" == 0); - } + FATAL_ERROR_IF(getDensity == nullptr, + "porting::getDisplayDensity unable to find java getDensity method"); value = jnienv->CallFloatMethod(app_global->activity->clazz, getDensity); firstrun = false; @@ -291,9 +270,8 @@ v2u32 getDisplaySize() jmethodID getDisplayWidth = jnienv->GetMethodID(nativeActivity, "getDisplayWidth", "()I"); - if (getDisplayWidth == 0) { - assert("porting::getDisplayWidth unable to find java getDisplayWidth method" == 0); - } + FATAL_ERROR_IF(getDisplayWidth == nullptr, + "porting::getDisplayWidth unable to find java getDisplayWidth method"); retval.X = jnienv->CallIntMethod(app_global->activity->clazz, getDisplayWidth); @@ -301,9 +279,8 @@ v2u32 getDisplaySize() jmethodID getDisplayHeight = jnienv->GetMethodID(nativeActivity, "getDisplayHeight", "()I"); - if (getDisplayHeight == 0) { - assert("porting::getDisplayHeight unable to find java getDisplayHeight method" == 0); - } + FATAL_ERROR_IF(getDisplayHeight == nullptr, + "porting::getDisplayHeight unable to find java getDisplayHeight method"); retval.Y = jnienv->CallIntMethod(app_global->activity->clazz, getDisplayHeight); diff --git a/src/porting_android.h b/src/porting_android.h index 60eb2a9c0..42f90b60b 100644 --- a/src/porting_android.h +++ b/src/porting_android.h @@ -30,16 +30,15 @@ with this program; if not, write to the Free Software Foundation, Inc., #include namespace porting { -/** java app **/ +// java app extern android_app *app_global; -/** java <-> c++ interaction interface **/ +// java <-> c++ interaction interface extern JNIEnv *jnienv; -/** - * do initialization required on android only - */ +// do initialization required on android only void initAndroid(); + void cleanupAndroid(); /** @@ -56,8 +55,8 @@ void initializePathsAndroid(); * @param editType type of texfield * (1==multiline text input; 2==single line text input; 3=password field) */ -void showInputDialog(const std::string& acceptButton, - const std::string& hint, const std::string& current, int editType); +void showInputDialog(const std::string &acceptButton, + const std::string &hint, const std::string ¤t, int editType); /** * WORKAROUND for not working callbacks from java -> c++ @@ -75,5 +74,4 @@ std::string getInputDialogValue(); float getDisplayDensity(); v2u32 getDisplaySize(); #endif - } -- cgit v1.2.3 From 664800b2adda44039a85c3566b4ed958abff8b95 Mon Sep 17 00:00:00 2001 From: v-rob Date: Wed, 6 May 2020 10:36:02 -0700 Subject: FormSpec: Add universal style selector `*` (#9718) --- doc/lua_api.txt | 6 ++++-- src/gui/guiFormSpecMenu.cpp | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 948e0f89e..961e1ff37 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2567,7 +2567,7 @@ Elements * Set the style for the element(s) matching `selector` by name. * `selector` can be one of: - * `` - An element name. + * `` - An element name. Includes `*`, which represents every element. * `:` - An element name, a colon, and one or more states. * `state` is a list of states separated by the `+` character. * If a state is provided, the style will only take effect when the element is in that state. @@ -2580,7 +2580,7 @@ Elements * Set the style for the element(s) matching `selector` by type. * `selector` can be one of: - * `` - An element type. + * `` - An element type. Includes `*`, which represents every element. * `:` - An element type, a colon, and one or more states. * `state` is a list of states separated by the `+` character. * If a state is provided, the style will only take effect when the element is in that state. @@ -2647,6 +2647,8 @@ A name/type can optionally be a comma separated list of names/types, like so: world_delete,world_create,world_configure button,image_button +A `*` type can be used to select every element in the formspec. + Any name/type in the list can also be accompanied by a `+`-separated list of states, like so: world_delete:hovered+pressed diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 567f0ca7e..72095a86e 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -4609,20 +4609,32 @@ StyleSpec GUIFormSpecMenu::getDefaultStyleForElement(const std::string &type, return getStyleForElement(type, name, parent_type)[StyleSpec::STATE_DEFAULT]; } -std::array GUIFormSpecMenu::getStyleForElement(const std::string &type, - const std::string &name, const std::string &parent_type) +std::array GUIFormSpecMenu::getStyleForElement( + const std::string &type, const std::string &name, const std::string &parent_type) { std::array ret; + auto it = theme_by_type.find("*"); + if (it != theme_by_type.end()) { + for (const StyleSpec &spec : it->second) + ret[(u32)spec.getState()] |= spec; + } + + it = theme_by_name.find("*"); + if (it != theme_by_name.end()) { + for (const StyleSpec &spec : it->second) + ret[(u32)spec.getState()] |= spec; + } + if (!parent_type.empty()) { - auto it = theme_by_type.find(parent_type); + it = theme_by_type.find(parent_type); if (it != theme_by_type.end()) { for (const StyleSpec &spec : it->second) ret[(u32)spec.getState()] |= spec; } } - auto it = theme_by_type.find(type); + it = theme_by_type.find(type); if (it != theme_by_type.end()) { for (const StyleSpec &spec : it->second) ret[(u32)spec.getState()] |= spec; -- cgit v1.2.3 From 4f9ccd89b347dad3db5ce63d3405a8d60c163af5 Mon Sep 17 00:00:00 2001 From: Jozef Behran Date: Wed, 6 May 2020 21:35:18 +0200 Subject: Get rid of non-ascii characters in the debug display code (#8821) --- src/client/gameui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 138dfb4da..bbe7caeb1 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -128,9 +128,9 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ << "pos: (" << (player_position.X / BS) << ", " << (player_position.Y / BS) << ", " << (player_position.Z / BS) - << ") | yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "° " + << ") | yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "\xC2\xB0 " << yawToDirectionString(cam.camera_yaw) - << " | pitch: " << (-wrapDegrees_180(cam.camera_pitch)) << "°" + << " | pitch: " << (-wrapDegrees_180(cam.camera_pitch)) << "\xC2\xB0" << " | seed: " << ((u64)client->getMapSeed()); if (pointed_old.type == POINTEDTHING_NODE) { -- cgit v1.2.3 From 650168cadac2a45277a9527ae79efb288ba7a4a4 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 7 May 2020 21:39:04 +0200 Subject: Fix Server triggering wrong errors if environment init fails --- src/serverenvironment.cpp | 6 ++++++ src/serverenvironment.h | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 27432e973..6bf7399cf 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -624,6 +624,9 @@ PlayerSAO *ServerEnvironment::loadPlayer(RemotePlayer *player, bool *new_player, void ServerEnvironment::saveMeta() { + if (!m_meta_loaded) + return; + std::string path = m_path_world + DIR_DELIM "env_meta.txt"; // Open file and serialize @@ -650,6 +653,9 @@ void ServerEnvironment::saveMeta() void ServerEnvironment::loadMeta() { + SANITY_CHECK(!m_meta_loaded); + m_meta_loaded = true; + // If file doesn't exist, load default environment metadata if (!fs::PathExists(m_path_world + DIR_DELIM "env_meta.txt")) { infostream << "ServerEnvironment: Loading default environment metadata" diff --git a/src/serverenvironment.h b/src/serverenvironment.h index f814b95c0..e2f1a3784 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -440,6 +440,8 @@ private: IntervalLimiter m_active_blocks_management_interval; IntervalLimiter m_active_block_modifier_interval; IntervalLimiter m_active_blocks_nodemetadata_interval; + // Whether the variables below have been read from file yet + bool m_meta_loaded = false; // Time from the beginning of the game in seconds. // Incremented in step(). u32 m_game_time = 0; -- cgit v1.2.3 From 454dbf83a9bf292910c1495a2aa49fd8b960c28f Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 7 May 2020 22:38:41 +0200 Subject: Server class code cleanups (#9769) * Server::overrideDayNightRatio doesn't require to return bool There is no sense to sending null player, the caller should send a valid object * Server::init: make private & cleanup This function is always called before start() and loads some variables which can be loaded in constructor directly. Make it private and call it directly in start * Split Server inventory responsibility to a dedicated object This splits permit to found various historical issues: * duplicate lookups on player connection * sending inventory to non related player when a player connects * non friendly lookups on detached inventories ownership This reduce the detached inventory complexity and also increased the lookup performance in a quite interesting way for servers with thousands of inventories. --- src/client/game.cpp | 1 - src/main.cpp | 2 - src/network/serverpackethandler.cpp | 11 ++- src/script/lua_api/l_base.cpp | 5 + src/script/lua_api/l_base.h | 2 + src/script/lua_api/l_inventory.cpp | 13 +-- src/script/lua_api/l_object.cpp | 7 +- src/server.cpp | 192 +++++------------------------------- src/server.h | 33 ++----- src/server/CMakeLists.txt | 1 + src/server/serverinventorymgr.cpp | 192 ++++++++++++++++++++++++++++++++++++ src/server/serverinventorymgr.h | 60 +++++++++++ 12 files changed, 312 insertions(+), 207 deletions(-) create mode 100644 src/server/serverinventorymgr.cpp create mode 100644 src/server/serverinventorymgr.h (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index 1577a37db..4d7a85526 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1302,7 +1302,6 @@ bool Game::createSingleplayerServer(const std::string &map_dir, } server = new Server(map_dir, gamespec, simple_singleplayer_mode, bind_addr, false); - server->init(); server->start(); return true; diff --git a/src/main.cpp b/src/main.cpp index 147f686ed..b3b17c2d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -887,7 +887,6 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings & // Create server Server server(game_params.world_path, game_params.game_spec, false, bind_addr, true, &iface); - server.init(); g_term_console.setup(&iface, &kill, admin_nick); @@ -922,7 +921,6 @@ static bool run_dedicated_server(const GameParams &game_params, const Settings & // Create server Server server(game_params.world_path, game_params.game_spec, false, bind_addr, true); - server.init(); server.start(); // Run server diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index adaa9a965..39a912827 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "network/networkprotocol.h" #include "network/serveropcodes.h" #include "server/player_sao.h" +#include "server/serverinventorymgr.h" #include "util/auth.h" #include "util/base64.h" #include "util/pointedthing.h" @@ -620,9 +621,9 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) ma->from_inv.applyCurrentPlayer(player->getName()); ma->to_inv.applyCurrentPlayer(player->getName()); - setInventoryModified(ma->from_inv); + m_inventory_mgr->setInventoryModified(ma->from_inv); if (ma->from_inv != ma->to_inv) - setInventoryModified(ma->to_inv); + m_inventory_mgr->setInventoryModified(ma->to_inv); bool from_inv_is_current_player = (ma->from_inv.type == InventoryLocation::PLAYER) && @@ -687,7 +688,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) da->from_inv.applyCurrentPlayer(player->getName()); - setInventoryModified(da->from_inv); + m_inventory_mgr->setInventoryModified(da->from_inv); /* Disable dropping items out of craftpreview @@ -723,7 +724,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) ca->craft_inv.applyCurrentPlayer(player->getName()); - setInventoryModified(ca->craft_inv); + m_inventory_mgr->setInventoryModified(ca->craft_inv); //bool craft_inv_is_current_player = // (ca->craft_inv.type == InventoryLocation::PLAYER) && @@ -739,7 +740,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) } // Do the action - a->apply(this, playersao, this); + a->apply(m_inventory_mgr.get(), playersao, this); // Eat the action delete a; } diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index b8658f62b..2bee09436 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -45,6 +45,11 @@ Server *ModApiBase::getServer(lua_State *L) return getScriptApiBase(L)->getServer(); } +ServerInventoryManager *ModApiBase::getServerInventoryMgr(lua_State *L) +{ + return getScriptApiBase(L)->getServer()->getInventoryMgr(); +} + #ifndef SERVER Client *ModApiBase::getClient(lua_State *L) { diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h index e32647628..65fce8481 100644 --- a/src/script/lua_api/l_base.h +++ b/src/script/lua_api/l_base.h @@ -38,12 +38,14 @@ class GUIEngine; class ScriptApiBase; class Server; class Environment; +class ServerInventoryManager; class ModApiBase : protected LuaHelper { public: static ScriptApiBase* getScriptApiBase(lua_State *L); static Server* getServer(lua_State *L); + static ServerInventoryManager *getServerInventoryMgr(lua_State *L); #ifndef SERVER static Client* getClient(lua_State *L); static GUIEngine* getGuiEngine(lua_State *L); diff --git a/src/script/lua_api/l_inventory.cpp b/src/script/lua_api/l_inventory.cpp index 4c8977898..e41b5cb41 100644 --- a/src/script/lua_api/l_inventory.cpp +++ b/src/script/lua_api/l_inventory.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_converter.h" #include "common/c_content.h" #include "server.h" +#include "server/serverinventorymgr.h" #include "remoteplayer.h" /* @@ -38,7 +39,7 @@ InvRef* InvRef::checkobject(lua_State *L, int narg) Inventory* InvRef::getinv(lua_State *L, InvRef *ref) { - return getServer(L)->getInventory(ref->m_loc); + return getServerInventoryMgr(L)->getInventory(ref->m_loc); } InventoryList* InvRef::getlist(lua_State *L, InvRef *ref, @@ -54,7 +55,7 @@ InventoryList* InvRef::getlist(lua_State *L, InvRef *ref, void InvRef::reportInventoryChange(lua_State *L, InvRef *ref) { // Inform other things that the inventory has changed - getServer(L)->setInventoryModified(ref->m_loc); + getServerInventoryMgr(L)->setInventoryModified(ref->m_loc); } // Exported functions @@ -497,7 +498,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) v3s16 pos = check_v3s16(L, -1); loc.setNodeMeta(pos); - if (getServer(L)->getInventory(loc) != NULL) + if (getServerInventoryMgr(L)->getInventory(loc) != NULL) InvRef::create(L, loc); else lua_pushnil(L); @@ -515,7 +516,7 @@ int ModApiInventory::l_get_inventory(lua_State *L) lua_pop(L, 1); } - if (getServer(L)->getInventory(loc) != NULL) + if (getServerInventoryMgr(L)->getInventory(loc) != NULL) InvRef::create(L, loc); else lua_pushnil(L); @@ -530,7 +531,7 @@ int ModApiInventory::l_create_detached_inventory_raw(lua_State *L) NO_MAP_LOCK_REQUIRED; const char *name = luaL_checkstring(L, 1); std::string player = readParam(L, 2, ""); - if (getServer(L)->createDetachedInventory(name, player) != NULL) { + if (getServerInventoryMgr(L)->createDetachedInventory(name, getServer(L)->idef(), player) != NULL) { InventoryLocation loc; loc.setDetached(name); InvRef::create(L, loc); @@ -545,7 +546,7 @@ int ModApiInventory::l_remove_detached_inventory_raw(lua_State *L) { NO_MAP_LOCK_REQUIRED; const std::string &name = luaL_checkstring(L, 1); - lua_pushboolean(L, getServer(L)->removeDetachedInventory(name)); + lua_pushboolean(L, getServerInventoryMgr(L)->removeDetachedInventory(name)); return 1; } diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index f71130378..0a9f3117b 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "scripting_server.h" #include "server/luaentity_sao.h" #include "server/player_sao.h" +#include "server/serverinventorymgr.h" /* ObjectRef @@ -289,7 +290,7 @@ int ObjectRef::l_get_inventory(lua_State *L) if (co == NULL) return 0; // Do it InventoryLocation loc = co->getInventoryLocation(); - if (getServer(L)->getInventory(loc) != NULL) + if (getServerInventoryMgr(L)->getInventory(loc) != NULL) InvRef::create(L, loc); else lua_pushnil(L); // An object may have no inventory (nil) @@ -2172,9 +2173,7 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L) ratio = readParam(L, 2); } - if (!getServer(L)->overrideDayNightRatio(player, do_override, ratio)) - return 0; - + getServer(L)->overrideDayNightRatio(player, do_override, ratio); lua_pushboolean(L, true); return 1; } diff --git a/src/server.cpp b/src/server.cpp index 05584be2d..16e026ce2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -64,6 +64,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "chat_interface.h" #include "remoteplayer.h" #include "server/player_sao.h" +#include "server/serverinventorymgr.h" #include "translation.h" class ClientNotFoundException : public BaseException @@ -338,11 +339,6 @@ Server::~Server() infostream << "Server: Deinitializing scripting" << std::endl; delete m_script; - // Delete detached inventories - for (auto &detached_inventory : m_detached_inventories) { - delete detached_inventory.second; - } - while (!m_unsent_map_edit_queue.empty()) { delete m_unsent_map_edit_queue.front(); m_unsent_map_edit_queue.pop(); @@ -388,6 +384,9 @@ void Server::init() m_script = new ServerScripting(this); + // Must be created before mod loading because we have some inventory creation + m_inventory_mgr = std::unique_ptr(new ServerInventoryManager()); + m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); m_modmgr->loadMods(m_script); @@ -422,6 +421,7 @@ void Server::init() // Initialize Environment m_env = new ServerEnvironment(servermap, m_script, this, m_path_world); + m_inventory_mgr->setEnv(m_env); m_clients.setEnv(m_env); if (!servermap->settings_mgr.makeMapgenParams()) @@ -443,6 +443,8 @@ void Server::init() m_env->loadMeta(); + // Those settings can be overwritten in world.mt, they are + // intended to be cached after environment loading. m_liquid_transform_every = g_settings->getFloat("liquid_update"); m_max_chatmessage_length = g_settings->getU16("chat_message_max_size"); m_csm_restriction_flags = g_settings->getU64("csm_restriction_flags"); @@ -451,6 +453,8 @@ void Server::init() void Server::start() { + init(); + infostream << "Starting server on " << m_bind_addr.serializeString() << "..." << std::endl; @@ -1180,82 +1184,6 @@ void Server::onMapEditEvent(const MapEditEvent &event) m_unsent_map_edit_queue.push(new MapEditEvent(event)); } -Inventory* Server::getInventory(const InventoryLocation &loc) -{ - switch (loc.type) { - case InventoryLocation::UNDEFINED: - case InventoryLocation::CURRENT_PLAYER: - break; - case InventoryLocation::PLAYER: - { - RemotePlayer *player = m_env->getPlayer(loc.name.c_str()); - if(!player) - return NULL; - PlayerSAO *playersao = player->getPlayerSAO(); - if(!playersao) - return NULL; - return playersao->getInventory(); - } - break; - case InventoryLocation::NODEMETA: - { - NodeMetadata *meta = m_env->getMap().getNodeMetadata(loc.p); - if(!meta) - return NULL; - return meta->getInventory(); - } - break; - case InventoryLocation::DETACHED: - { - if(m_detached_inventories.count(loc.name) == 0) - return NULL; - return m_detached_inventories[loc.name]; - } - break; - default: - sanity_check(false); // abort - break; - } - return NULL; -} - -void Server::setInventoryModified(const InventoryLocation &loc) -{ - switch(loc.type){ - case InventoryLocation::UNDEFINED: - break; - case InventoryLocation::PLAYER: - { - - RemotePlayer *player = m_env->getPlayer(loc.name.c_str()); - - if (!player) - return; - - player->setModified(true); - player->inventory.setModified(true); - // Updates are sent in ServerEnvironment::step() - } - break; - case InventoryLocation::NODEMETA: - { - MapEditEvent event; - event.type = MEET_BLOCK_NODE_METADATA_CHANGED; - event.p = loc.p; - m_env->getMap().dispatchEvent(event); - } - break; - case InventoryLocation::DETACHED: - { - // Updates are sent in ServerEnvironment::step() - } - break; - default: - sanity_check(false); // abort - break; - } -} - void Server::SetBlocksNotSent(std::map& block) { std::vector clients = m_clients.getClientIDs(); @@ -2712,40 +2640,20 @@ void Server::sendRequestedMedia(session_t peer_id, } } -void Server::sendDetachedInventory(const std::string &name, session_t peer_id) +void Server::sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id) { - const auto &inv_it = m_detached_inventories.find(name); - const auto &player_it = m_detached_inventories_player.find(name); - - if (player_it == m_detached_inventories_player.end() || - player_it->second.empty()) { - // OK. Send to everyone - } else { - if (!m_env) - return; // Mods are not done loading - - RemotePlayer *p = m_env->getPlayer(player_it->second.c_str()); - if (!p) - return; // Player is offline - - if (peer_id != PEER_ID_INEXISTENT && peer_id != p->getPeerId()) - return; // Caller requested send to a different player, so don't send. - - peer_id = p->getPeerId(); - } - NetworkPacket pkt(TOCLIENT_DETACHED_INVENTORY, 0, peer_id); pkt << name; - if (inv_it == m_detached_inventories.end()) { + if (!inventory) { pkt << false; // Remove inventory } else { pkt << true; // Update inventory // Serialization & NetworkPacket isn't a love story std::ostringstream os(std::ios_base::binary); - inv_it->second->serialize(os); - inv_it->second->setModified(false); + inventory->serialize(os); + inventory->setModified(false); const std::string &os_str = os.str(); pkt << static_cast(os_str.size()); // HACK: to keep compatibility with 5.0.0 clients @@ -2760,16 +2668,17 @@ void Server::sendDetachedInventory(const std::string &name, session_t peer_id) void Server::sendDetachedInventories(session_t peer_id, bool incremental) { - for (const auto &detached_inventory : m_detached_inventories) { - const std::string &name = detached_inventory.first; - if (incremental) { - Inventory *inv = detached_inventory.second; - if (!inv || !inv->checkModified()) - continue; - } - - sendDetachedInventory(name, peer_id); + // Lookup player name, to filter detached inventories just after + std::string peer_name; + if (peer_id != PEER_ID_INEXISTENT) { + peer_name = getClient(peer_id, CS_Created)->getName(); } + + auto send_cb = [this, peer_id](const std::string &name, Inventory *inv) { + sendDetachedInventory(inv, name, peer_id); + }; + + m_inventory_mgr->sendDetachedInventories(peer_name, incremental, send_cb); } /* @@ -3442,15 +3351,12 @@ void Server::setClouds(RemotePlayer *player, const CloudParams ¶ms) SendCloudParams(player->getPeerId(), params); } -bool Server::overrideDayNightRatio(RemotePlayer *player, bool do_override, +void Server::overrideDayNightRatio(RemotePlayer *player, bool do_override, float ratio) { - if (!player) - return false; - + sanity_check(player); player->overrideDayNightRatio(do_override, ratio); SendOverrideDayNightRatio(player->getPeerId(), do_override, ratio); - return true; } void Server::notifyPlayers(const std::wstring &msg) @@ -3541,52 +3447,6 @@ void Server::deleteParticleSpawner(const std::string &playername, u32 id) SendDeleteParticleSpawner(peer_id, id); } -Inventory* Server::createDetachedInventory(const std::string &name, const std::string &player) -{ - if(m_detached_inventories.count(name) > 0){ - infostream<<"Server clearing detached inventory \""<second; - m_detached_inventories.erase(inv_it); - - if (!m_env) // Mods are not done loading - return true; - - const auto &player_it = m_detached_inventories_player.find(name); - if (player_it != m_detached_inventories_player.end()) { - RemotePlayer *player = m_env->getPlayer(player_it->second.c_str()); - - if (player && player->getPeerId() != PEER_ID_INEXISTENT) - sendDetachedInventory(name, player->getPeerId()); - - m_detached_inventories_player.erase(player_it); - } else { - // Notify all players about the change - sendDetachedInventory(name, PEER_ID_INEXISTENT); - } - return true; -} - // actions: time-reversed list // Return value: success/failure bool Server::rollbackRevertActions(const std::list &actions, @@ -3607,7 +3467,7 @@ bool Server::rollbackRevertActions(const std::list &actions, for (const RollbackAction &action : actions) { num_tried++; - bool success = action.applyRevert(map, this, this); + bool success = action.applyRevert(map, m_inventory_mgr.get(), this); if(!success){ num_failed++; std::ostringstream os; diff --git a/src/server.h b/src/server.h index 71059dd30..7a1de9370 100644 --- a/src/server.h +++ b/src/server.h @@ -68,6 +68,7 @@ struct MoonParams; struct StarParams; class ServerThread; class ServerModManager; +class ServerInventoryManager; enum ClientDeletionReason { CDR_LEAVE, @@ -116,7 +117,7 @@ struct ServerPlayingSound }; class Server : public con::PeerHandler, public MapEventReceiver, - public InventoryManager, public IGameDef + public IGameDef { public: /* @@ -134,7 +135,6 @@ public: ~Server(); DISABLE_CLASS_COPY(Server); - void init(); void start(); void stop(); // This is mainly a way to pass the time to the server. @@ -196,12 +196,6 @@ public: */ void onMapEditEvent(const MapEditEvent &event); - /* - Shall be called with the environment and the connection locked. - */ - Inventory* getInventory(const InventoryLocation &loc); - void setInventoryModified(const InventoryLocation &loc); - // Connection must be locked when called std::wstring getStatusString(); inline double getUptime() const { return m_uptime_counter->get(); } @@ -253,10 +247,8 @@ public: void deleteParticleSpawner(const std::string &playername, u32 id); - // Creates or resets inventory - Inventory *createDetachedInventory(const std::string &name, - const std::string &player = ""); - bool removeDetachedInventory(const std::string &name); + ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); } + void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id); // Envlock and conlock should be locked when using scriptapi ServerScripting *getScriptIface(){ return m_script; } @@ -318,7 +310,7 @@ public: void setClouds(RemotePlayer *player, const CloudParams ¶ms); - bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness); + void overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness); /* con::PeerHandler implementation. */ void peerAdded(con::Peer *peer); @@ -389,6 +381,8 @@ private: float m_timer = 0.0f; }; + void init(); + void SendMovement(session_t peer_id); void SendHP(session_t peer_id, u16 hp); void SendBreath(session_t peer_id, u16 breath); @@ -457,8 +451,6 @@ private: void sendRequestedMedia(session_t peer_id, const std::vector &tosend); - void sendDetachedInventory(const std::string &name, session_t peer_id); - // Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all) void SendAddParticleSpawner(session_t peer_id, u16 protocol_version, u16 amount, float spawntime, @@ -656,14 +648,6 @@ private: s32 m_next_sound_id = 0; // positive values only s32 nextSoundId(); - /* - Detached inventories (behind m_env_mutex) - */ - // key = name - std::map m_detached_inventories; - // value = "" (visible to all players) or player name - std::map m_detached_inventories_player; - std::unordered_map m_mod_storages; float m_mod_storage_save_timer = 10.0f; @@ -674,6 +658,9 @@ private: // ModChannel manager std::unique_ptr m_modchannel_mgr; + // Inventory manager + std::unique_ptr m_inventory_mgr; + // Global server metrics backend std::unique_ptr m_metrics_backend; diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 4d94504f6..0a5a8f3a7 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -4,5 +4,6 @@ set(server_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp ${CMAKE_CURRENT_SOURCE_DIR}/player_sao.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serveractiveobject.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/serverinventorymgr.cpp ${CMAKE_CURRENT_SOURCE_DIR}/unit_sao.cpp PARENT_SCOPE) diff --git a/src/server/serverinventorymgr.cpp b/src/server/serverinventorymgr.cpp new file mode 100644 index 000000000..555e01ec6 --- /dev/null +++ b/src/server/serverinventorymgr.cpp @@ -0,0 +1,192 @@ +/* +Minetest +Copyright (C) 2010-2020 Minetest core development team + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "serverinventorymgr.h" +#include "map.h" +#include "nodemetadata.h" +#include "player_sao.h" +#include "remoteplayer.h" +#include "server.h" +#include "serverenvironment.h" + +ServerInventoryManager::ServerInventoryManager() : InventoryManager() +{ +} + +ServerInventoryManager::~ServerInventoryManager() +{ + // Delete detached inventories + for (auto &detached_inventory : m_detached_inventories) { + delete detached_inventory.second.inventory; + } +} + +Inventory *ServerInventoryManager::getInventory(const InventoryLocation &loc) +{ + switch (loc.type) { + case InventoryLocation::UNDEFINED: + case InventoryLocation::CURRENT_PLAYER: + break; + case InventoryLocation::PLAYER: { + RemotePlayer *player = m_env->getPlayer(loc.name.c_str()); + if (!player) + return NULL; + PlayerSAO *playersao = player->getPlayerSAO(); + if (!playersao) + return NULL; + return playersao->getInventory(); + } break; + case InventoryLocation::NODEMETA: { + NodeMetadata *meta = m_env->getMap().getNodeMetadata(loc.p); + if (!meta) + return NULL; + return meta->getInventory(); + } break; + case InventoryLocation::DETACHED: { + auto it = m_detached_inventories.find(loc.name); + if (it == m_detached_inventories.end()) + return nullptr; + return it->second.inventory; + } break; + default: + sanity_check(false); // abort + break; + } + return NULL; +} + +void ServerInventoryManager::setInventoryModified(const InventoryLocation &loc) +{ + switch (loc.type) { + case InventoryLocation::UNDEFINED: + break; + case InventoryLocation::PLAYER: { + + RemotePlayer *player = m_env->getPlayer(loc.name.c_str()); + + if (!player) + return; + + player->setModified(true); + player->inventory.setModified(true); + // Updates are sent in ServerEnvironment::step() + } break; + case InventoryLocation::NODEMETA: { + MapEditEvent event; + event.type = MEET_BLOCK_NODE_METADATA_CHANGED; + event.p = loc.p; + m_env->getMap().dispatchEvent(event); + } break; + case InventoryLocation::DETACHED: { + // Updates are sent in ServerEnvironment::step() + } break; + default: + sanity_check(false); // abort + break; + } +} + +Inventory *ServerInventoryManager::createDetachedInventory( + const std::string &name, IItemDefManager *idef, const std::string &player) +{ + if (m_detached_inventories.count(name) > 0) { + infostream << "Server clearing detached inventory \"" << name << "\"" + << std::endl; + delete m_detached_inventories[name].inventory; + } else { + infostream << "Server creating detached inventory \"" << name << "\"" + << std::endl; + } + + Inventory *inv = new Inventory(idef); + sanity_check(inv); + m_detached_inventories[name].inventory = inv; + if (!player.empty()) { + m_detached_inventories[name].owner = player; + + if (!m_env) + return inv; // Mods are not loaded yet, ignore + + RemotePlayer *p = m_env->getPlayer(name.c_str()); + + // if player is connected, send him the inventory + if (p && p->getPeerId() != PEER_ID_INEXISTENT) { + m_env->getGameDef()->sendDetachedInventory( + inv, name, p->getPeerId()); + } + } else { + if (!m_env) + return inv; // Mods are not loaded yet, don't send + + // Inventory is for everybody, broadcast + m_env->getGameDef()->sendDetachedInventory(inv, name, PEER_ID_INEXISTENT); + } + + return inv; +} + +bool ServerInventoryManager::removeDetachedInventory(const std::string &name) +{ + const auto &inv_it = m_detached_inventories.find(name); + if (inv_it == m_detached_inventories.end()) + return false; + + delete inv_it->second.inventory; + const std::string &owner = inv_it->second.owner; + + if (!owner.empty()) { + RemotePlayer *player = m_env->getPlayer(owner.c_str()); + + if (player && player->getPeerId() != PEER_ID_INEXISTENT) + m_env->getGameDef()->sendDetachedInventory( + nullptr, name, player->getPeerId()); + + } else { + // Notify all players about the change + m_env->getGameDef()->sendDetachedInventory( + nullptr, name, PEER_ID_INEXISTENT); + } + + m_detached_inventories.erase(inv_it); + + return true; +} + +void ServerInventoryManager::sendDetachedInventories(const std::string &peer_name, + bool incremental, + std::function apply_cb) +{ + for (const auto &detached_inventory : m_detached_inventories) { + const DetachedInventory &dinv = detached_inventory.second; + if (incremental) { + if (!dinv.inventory || !dinv.inventory->checkModified()) + continue; + } + + // if we are pushing inventories to a specific player + // we should filter to send only the right inventories + if (!peer_name.empty()) { + const std::string &attached_player = dinv.owner; + if (!attached_player.empty() && peer_name != attached_player) + continue; + } + + apply_cb(detached_inventory.first, detached_inventory.second.inventory); + } +} diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h new file mode 100644 index 000000000..d0aac4dae --- /dev/null +++ b/src/server/serverinventorymgr.h @@ -0,0 +1,60 @@ +/* +Minetest +Copyright (C) 2010-2020 Minetest core development team + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include "inventorymanager.h" +#include + +class ServerEnvironment; + +class ServerInventoryManager : public InventoryManager +{ +public: + ServerInventoryManager(); + virtual ~ServerInventoryManager(); + + void setEnv(ServerEnvironment *env) + { + assert(!m_env); + m_env = env; + } + + Inventory *getInventory(const InventoryLocation &loc); + void setInventoryModified(const InventoryLocation &loc); + + // Creates or resets inventory + Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef, + const std::string &player = ""); + bool removeDetachedInventory(const std::string &name); + + void sendDetachedInventories(const std::string &peer_name, bool incremental, + std::function apply_cb); + +private: + struct DetachedInventory + { + Inventory *inventory; + std::string owner; + }; + + ServerEnvironment *m_env = nullptr; + + std::unordered_map m_detached_inventories; +}; \ No newline at end of file -- cgit v1.2.3 From b6242498aad793e579960f871f01ba5bd5456658 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Sat, 9 May 2020 11:14:29 -0400 Subject: Always use same default tabheader height (#9319) Previously the default tabheader height was different when using real coordinates. This resulted in the height of tabs changing when switching tabs in sfinv if some tabs used real coordinates. --- src/gui/guiFormSpecMenu.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 72095a86e..49133f1cb 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -2027,7 +2027,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen // Width is not here because tabs are the width of the text, and // there's no reason to change that. unsigned int i = 0; - std::vector v_geom = {"1", "0.75"}; // Dummy width and default height + std::vector v_geom = {"1", "1"}; // Dummy width and height bool auto_width = true; if (parts.size() == 7) { i++; @@ -2071,6 +2071,9 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen pos = getRealCoordinateBasePos(v_pos); geom = getRealCoordinateGeometry(v_geom); + // Set default height + if (parts.size() <= 6) + geom.Y = m_btn_height * 2; pos.Y -= geom.Y; // TabHeader base pos is the bottom, not the top. if (auto_width) geom.X = DesiredRect.getWidth(); // Set automatic width -- cgit v1.2.3 From 7cb53791c3a6547164a9f8eae10ae8a2e2ddecdb Mon Sep 17 00:00:00 2001 From: TheTermos <55103816+TheTermos@users.noreply.github.com> Date: Sat, 9 May 2020 17:14:56 +0200 Subject: Color gradient for default and 'regular' type sky (#9502) * add regular sky gradient * add regular sky gradient * Update sky.cpp * change default day sky colors --- src/client/sky.cpp | 33 ++++----------------------------- src/skyparams.h | 4 ++-- 2 files changed, 6 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/client/sky.cpp b/src/client/sky.cpp index ce33b96ae..d21b56fcc 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -252,35 +252,10 @@ void Sky::render() if (m_visible) { driver->setMaterial(m_materials[1]); for (u32 j = 0; j < 4; j++) { - video::SColor c = cloudyfogcolor.getInterpolated(m_skycolor, 0.45); - vertices[0] = video::S3DVertex(-1, 0.08, -1, 0, 0, 1, c, t, t); - vertices[1] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, t); - vertices[2] = video::S3DVertex( 1, 0.12, -1, 0, 0, 1, c, o, o); - vertices[3] = video::S3DVertex(-1, 0.12, -1, 0, 0, 1, c, t, o); - for (video::S3DVertex &vertex : vertices) { - if (j == 0) - // Don't switch - {} - else if (j == 1) - // Switch from -Z (south) to +X (east) - vertex.Pos.rotateXZBy(90); - else if (j == 2) - // Switch from -Z (south) to -X (west) - vertex.Pos.rotateXZBy(-90); - else - // Switch from -Z (south) to +Z (north) - vertex.Pos.rotateXZBy(-180); - } - driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); - } - - // Draw far cloudy fog thing at and below all horizons - for (u32 j = 0; j < 4; j++) { - video::SColor c = cloudyfogcolor; - vertices[0] = video::S3DVertex(-1, -1.0, -1, 0, 0, 1, c, t, t); - vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t); - vertices[2] = video::S3DVertex( 1, 0.08, -1, 0, 0, 1, c, o, o); - vertices[3] = video::S3DVertex(-1, 0.08, -1, 0, 0, 1, c, t, o); + vertices[0] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t); + vertices[1] = video::S3DVertex( 1, -0.02, -1, 0, 0, 1, m_bgcolor, o, t); + vertices[2] = video::S3DVertex( 1, 0.45, -1, 0, 0, 1, m_skycolor, o, o); + vertices[3] = video::S3DVertex(-1, 0.45, -1, 0, 0, 1, m_skycolor, t, o); for (video::S3DVertex &vertex : vertices) { if (j == 0) // Don't switch diff --git a/src/skyparams.h b/src/skyparams.h index c362ef8f3..1de494d69 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -76,12 +76,12 @@ public: { SkyColor sky; // Horizon colors - sky.day_horizon = video::SColor(255, 155, 193, 240); + sky.day_horizon = video::SColor(255, 144, 211, 246); sky.indoors = video::SColor(255, 100, 100, 100); sky.dawn_horizon = video::SColor(255, 186, 193, 240); sky.night_horizon = video::SColor(255, 64, 144, 255); // Sky colors - sky.day_sky = video::SColor(255, 140, 186, 250); + sky.day_sky = video::SColor(255, 97, 181, 245); sky.dawn_sky = video::SColor(255, 180, 186, 250); sky.night_sky = video::SColor(255, 0, 107, 255); return sky; -- cgit v1.2.3 From 6e1372bd894d955300c40d69e5c882e9cc7d7523 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 11 May 2020 21:40:45 +0200 Subject: Add support for statbar “off state” icons (#9462) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds support for optional “off state” icons for statbars. “off state icons” can be used to denote the lack of something, like missing hearts or bubbles. Add "off state" textures to the builtin statbars. Co-authored-by: SmallJoker --- builtin/game/statbars.lua | 4 ++ doc/lua_api.txt | 16 ++++-- doc/texture_packs.txt | 4 ++ src/client/clientevent.h | 1 + src/client/game.cpp | 7 +++ src/client/hud.cpp | 96 ++++++++++++++++++++++++++++++------ src/client/hud.h | 5 +- src/hud.cpp | 1 + src/hud.h | 2 + src/network/clientpackethandler.cpp | 15 ++---- src/network/networkprotocol.h | 6 ++- src/script/common/c_content.cpp | 8 +++ src/server.cpp | 3 +- textures/base/pack/bubble_gone.png | Bin 0 -> 68 bytes textures/base/pack/heart_gone.png | Bin 0 -> 68 bytes 15 files changed, 132 insertions(+), 36 deletions(-) create mode 100644 textures/base/pack/bubble_gone.png create mode 100644 textures/base/pack/heart_gone.png (limited to 'src') diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua index 6b5b54428..d192029c5 100644 --- a/builtin/game/statbars.lua +++ b/builtin/game/statbars.lua @@ -5,7 +5,9 @@ local health_bar_definition = { hud_elem_type = "statbar", position = {x = 0.5, y = 1}, text = "heart.png", + text2 = "heart_gone.png", number = core.PLAYER_MAX_HP_DEFAULT, + item = core.PLAYER_MAX_HP_DEFAULT, direction = 0, size = {x = 24, y = 24}, offset = {x = (-10 * 24) - 25, y = -(48 + 24 + 16)}, @@ -15,7 +17,9 @@ local breath_bar_definition = { hud_elem_type = "statbar", position = {x = 0.5, y = 1}, text = "bubble.png", + text2 = "bubble_gone.png", number = core.PLAYER_MAX_BREATH_DEFAULT, + item = core.PLAYER_MAX_BREATH_DEFAULT * 2, direction = 0, size = {x = 24, y = 24}, offset = {x = 25, y= -(48 + 24 + 16)}, diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 961e1ff37..4078e21a1 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1289,9 +1289,9 @@ To account for differing resolutions, the position coordinates are the percentage of the screen, ranging in value from `0` to `1`. The name field is not yet used, but should contain a description of what the -HUD element represents. The direction field is the direction in which something -is drawn. +HUD element represents. +The `direction` field is the direction in which something is drawn. `0` draws from left to right, `1` draws from right to left, `2` draws from top to bottom, and `3` draws from bottom to top. @@ -1355,12 +1355,16 @@ Displays text on the HUD. ### `statbar` -Displays a horizontal bar made up of half-images. +Displays a horizontal bar made up of half-images with an optional background. -* `text`: The name of the texture that is used. +* `text`: The name of the texture to use. +* `text2`: Optional texture name to enable a background / "off state" + texture (useful to visualize the maximal value). Both textures + must have the same size. * `number`: The number of half-textures that are displayed. If odd, will end with a vertically center-split texture. -* `direction` +* `item`: Same as `number` but for the "off state" texture +* `direction`: To which direction the images will extend to * `offset`: offset in pixels from position. * `size`: If used, will force full-image size to this value (override texture pack image size) @@ -7772,6 +7776,8 @@ Used by `Player:hud_add`. Returned by `Player:hud_get`. text = "", + text2 = "", + number = 2, item = 3, diff --git a/doc/texture_packs.txt b/doc/texture_packs.txt index 4e7bc93c4..94151f1a4 100644 --- a/doc/texture_packs.txt +++ b/doc/texture_packs.txt @@ -64,6 +64,8 @@ by texture packs. All existing fallback textures can be found in the directory * `bubble.png`: the bubble texture when the player is drowning (default size: 12×12) +* `bubble_gone.png`: like `bubble.png`, but denotes lack of breath + (transparent by default, same size as bubble.png) * `crack_anylength.png`: node overlay texture when digging @@ -76,6 +78,8 @@ by texture packs. All existing fallback textures can be found in the directory * `heart.png`: used to display the health points of the player (default size: 12×12) +* `heart_gone.png`: like `heart.png`, but denotes lack of health points + (transparent by default, same size as heart.png) * `minimap_mask_round.png`: round minimap mask, white gets replaced by the map * `minimap_mask_square.png`: mask used for the square minimap diff --git a/src/client/clientevent.h b/src/client/clientevent.h index f5689c25b..7f3984b03 100644 --- a/src/client/clientevent.h +++ b/src/client/clientevent.h @@ -136,6 +136,7 @@ struct ClientEvent v3f *world_pos; v2s32 *size; s16 z_index; + std::string *text2; } hudadd; struct { diff --git a/src/client/game.cpp b/src/client/game.cpp index 4d7a85526..422e17d4f 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2672,6 +2672,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam) delete event->hudadd.offset; delete event->hudadd.world_pos; delete event->hudadd.size; + delete event->hudadd.text2; return; } @@ -2689,6 +2690,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam) e->world_pos = *event->hudadd.world_pos; e->size = *event->hudadd.size; e->z_index = event->hudadd.z_index; + e->text2 = *event->hudadd.text2; hud_server_to_client[server_id] = player->addHud(e); delete event->hudadd.pos; @@ -2699,6 +2701,7 @@ void Game::handleClientEvent_HudAdd(ClientEvent *event, CameraOrientation *cam) delete event->hudadd.offset; delete event->hudadd.world_pos; delete event->hudadd.size; + delete event->hudadd.text2; } void Game::handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam) @@ -2771,6 +2774,10 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca case HUD_STAT_Z_INDEX: e->z_index = event->hudchange.data; break; + + case HUD_STAT_TEXT2: + e->text2 = *event->hudchange.sdata; + break; } delete event->hudchange.v3fdata; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 56763e7e4..f8f712762 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -332,7 +332,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) break; } case HUD_ELEM_STATBAR: { v2s32 offs(e->offset.X, e->offset.Y); - drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs, e->size); + drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->text2, + e->number, e->item, offs, e->size); break; } case HUD_ELEM_INVENTORY: { InventoryList *inv = inventory->getList(e->text); @@ -401,8 +402,9 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) } -void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, - s32 count, v2s32 offset, v2s32 size) +void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, + const std::string &texture, const std::string &bgtexture, + s32 count, s32 maxcount, v2s32 offset, v2s32 size) { const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; @@ -411,6 +413,11 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &tex if (!stat_texture) return; + video::ITexture *stat_texture_bg = nullptr; + if (!bgtexture.empty()) { + stat_texture_bg = tsrc->getTexture(bgtexture); + } + core::dimension2di srcd(stat_texture->getOriginalSize()); core::dimension2di dstd; if (size == v2s32()) { @@ -430,43 +437,100 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &tex p += offset; v2s32 steppos; - core::rect srchalfrect, dsthalfrect; switch (drawdir) { case HUD_DIR_RIGHT_LEFT: steppos = v2s32(-1, 0); - srchalfrect = core::rect(srcd.Width / 2, 0, srcd.Width, srcd.Height); - dsthalfrect = core::rect(dstd.Width / 2, 0, dstd.Width, dstd.Height); break; case HUD_DIR_TOP_BOTTOM: steppos = v2s32(0, 1); - srchalfrect = core::rect(0, 0, srcd.Width, srcd.Height / 2); - dsthalfrect = core::rect(0, 0, dstd.Width, dstd.Height / 2); break; case HUD_DIR_BOTTOM_TOP: steppos = v2s32(0, -1); - srchalfrect = core::rect(0, srcd.Height / 2, srcd.Width, srcd.Height); - dsthalfrect = core::rect(0, dstd.Height / 2, dstd.Width, dstd.Height); break; default: + // From left to right steppos = v2s32(1, 0); - srchalfrect = core::rect(0, 0, srcd.Width / 2, srcd.Height); - dsthalfrect = core::rect(0, 0, dstd.Width / 2, dstd.Height); + break; + } + + auto calculate_clipping_rect = [] (core::dimension2di src, + v2s32 steppos) -> core::rect { + + // Create basic rectangle + core::rect rect(0, 0, + src.Width - std::abs(steppos.X) * src.Width / 2, + src.Height - std::abs(steppos.Y) * src.Height / 2 + ); + // Move rectangle left or down + if (steppos.X == -1) + rect += v2s32(src.Width / 2, 0); + if (steppos.Y == -1) + rect += v2s32(0, src.Height / 2); + return rect; + }; + // Rectangles for 1/2 the actual value to display + core::rect srchalfrect, dsthalfrect; + // Rectangles for 1/2 the "off state" texture + core::rect srchalfrect2, dsthalfrect2; + + if (count % 2 == 1) { + // Need to draw halves: Calculate rectangles + srchalfrect = calculate_clipping_rect(srcd, steppos); + dsthalfrect = calculate_clipping_rect(dstd, steppos); + srchalfrect2 = calculate_clipping_rect(srcd, steppos * -1); + dsthalfrect2 = calculate_clipping_rect(dstd, steppos * -1); } + steppos.X *= dstd.Width; steppos.Y *= dstd.Height; + // Draw full textures for (s32 i = 0; i < count / 2; i++) { core::rect srcrect(0, 0, srcd.Width, srcd.Height); - core::rect dstrect(0,0, dstd.Width, dstd.Height); + core::rect dstrect(0, 0, dstd.Width, dstd.Height); dstrect += p; - draw2DImageFilterScaled(driver, stat_texture, dstrect, srcrect, NULL, colors, true); + draw2DImageFilterScaled(driver, stat_texture, + dstrect, srcrect, NULL, colors, true); p += steppos; } if (count % 2 == 1) { - dsthalfrect += p; - draw2DImageFilterScaled(driver, stat_texture, dsthalfrect, srchalfrect, NULL, colors, true); + // Draw half a texture + draw2DImageFilterScaled(driver, stat_texture, + dsthalfrect + p, srchalfrect, NULL, colors, true); + + if (stat_texture_bg && maxcount > count) { + draw2DImageFilterScaled(driver, stat_texture_bg, + dsthalfrect2 + p, srchalfrect2, + NULL, colors, true); + p += steppos; + } + } + + if (stat_texture_bg && maxcount > count / 2) { + // Draw "off state" textures + s32 start_offset; + if (count % 2 == 1) + start_offset = count / 2 + 1; + else + start_offset = count / 2; + for (s32 i = start_offset; i < maxcount / 2; i++) { + core::rect srcrect(0, 0, srcd.Width, srcd.Height); + core::rect dstrect(0, 0, dstd.Width, dstd.Height); + + dstrect += p; + draw2DImageFilterScaled(driver, stat_texture_bg, + dstrect, srcrect, + NULL, colors, true); + p += steppos; + } + + if (maxcount % 2 == 1) { + draw2DImageFilterScaled(driver, stat_texture_bg, + dsthalfrect + p, srchalfrect, + NULL, colors, true); + } } } diff --git a/src/client/hud.h b/src/client/hud.h index cab115990..6274b1a83 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -82,8 +82,9 @@ public: private: bool calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos); - void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, const std::string &texture, - s32 count, v2s32 offset, v2s32 size = v2s32()); + void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, + const std::string &texture, const std::string& bgtexture, + s32 count, s32 maxcount, v2s32 offset, v2s32 size = v2s32()); void drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, s32 inv_offset, InventoryList *mainlist, u16 selectitem, diff --git a/src/hud.cpp b/src/hud.cpp index 39625b5fd..3079b5cd8 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -46,6 +46,7 @@ const struct EnumString es_HudElementStat[] = {HUD_STAT_WORLD_POS, "world_pos"}, {HUD_STAT_SIZE, "size"}, {HUD_STAT_Z_INDEX, "z_index"}, + {HUD_STAT_TEXT2, "text2"}, {0, NULL}, }; diff --git a/src/hud.h b/src/hud.h index b0977c6a4..bab420ed2 100644 --- a/src/hud.h +++ b/src/hud.h @@ -77,6 +77,7 @@ enum HudElementStat { HUD_STAT_WORLD_POS, HUD_STAT_SIZE, HUD_STAT_Z_INDEX, + HUD_STAT_TEXT2, }; struct HudElement { @@ -93,6 +94,7 @@ struct HudElement { v3f world_pos; v2s32 size; s16 z_index = 0; + std::string text2; }; extern const EnumString es_HudElementType[]; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 8d0225a3d..7b1b1368c 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1102,22 +1102,16 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt) v3f world_pos; v2s32 size; s16 z_index = 0; + std::string text2; *pkt >> server_id >> type >> pos >> name >> scale >> text >> number >> item >> dir >> align >> offset; try { *pkt >> world_pos; - } - catch(SerializationError &e) {}; - - try { *pkt >> size; - } catch(SerializationError &e) {}; - - try { *pkt >> z_index; - } - catch(PacketError &e) {} + *pkt >> text2; + } catch(PacketError &e) {}; ClientEvent *event = new ClientEvent(); event->type = CE_HUDADD; @@ -1135,6 +1129,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt) event->hudadd.world_pos = new v3f(world_pos); event->hudadd.size = new v2s32(size); event->hudadd.z_index = z_index; + event->hudadd.text2 = new std::string(text2); m_client_event_queue.push(event); } @@ -1171,7 +1166,7 @@ void Client::handleCommand_HudChange(NetworkPacket* pkt) if (stat == HUD_STAT_POS || stat == HUD_STAT_SCALE || stat == HUD_STAT_ALIGN || stat == HUD_STAT_OFFSET) *pkt >> v2fdata; - else if (stat == HUD_STAT_NAME || stat == HUD_STAT_TEXT) + else if (stat == HUD_STAT_NAME || stat == HUD_STAT_TEXT || stat == HUD_STAT_TEXT2) *pkt >> sdata; else if (stat == HUD_STAT_WORLD_POS) *pkt >> v3fdata; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 527ebba7c..ab924f1db 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -560,10 +560,10 @@ enum ToClientCommand u32 id u8 type v2f1000 pos - u32 len + u16 len u8[len] name v2f1000 scale - u32 len2 + u16 len2 u8[len2] text u32 number u32 item @@ -573,6 +573,8 @@ enum ToClientCommand v3f1000 world_pos v2s32 size s16 z_index + u16 len3 + u8[len3] text2 */ TOCLIENT_HUDRM = 0x4a, diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index dac828316..540b7222f 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1871,6 +1871,7 @@ void read_hud_element(lua_State *L, HudElement *elem) elem->dir = getintfield_default(L, 2, "direction", 0); elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX, getintfield_default(L, 2, "z_index", 0))); + elem->text2 = getstringfield_default(L, 2, "text2", ""); // Deprecated, only for compatibility's sake if (elem->dir == 0) @@ -1939,6 +1940,9 @@ void push_hud_element(lua_State *L, HudElement *elem) lua_pushnumber(L, elem->z_index); lua_setfield(L, -2, "z_index"); + + lua_pushstring(L, elem->text2.c_str()); + lua_setfield(L, -2, "text2"); } HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value) @@ -2000,6 +2004,10 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value) elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX, luaL_checknumber(L, 4))); *value = &elem->z_index; break; + case HUD_STAT_TEXT2: + elem->text2 = luaL_checkstring(L, 4); + *value = &elem->text2; + break; } return stat; } diff --git a/src/server.cpp b/src/server.cpp index 16e026ce2..b28c30e1e 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1621,7 +1621,7 @@ void Server::SendHUDAdd(session_t peer_id, u32 id, HudElement *form) pkt << id << (u8) form->type << form->pos << form->name << form->scale << form->text << form->number << form->item << form->dir << form->align << form->offset << form->world_pos << form->size - << form->z_index; + << form->z_index << form->text2; Send(&pkt); } @@ -1647,6 +1647,7 @@ void Server::SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void break; case HUD_STAT_NAME: case HUD_STAT_TEXT: + case HUD_STAT_TEXT2: pkt << *(std::string *) value; break; case HUD_STAT_WORLD_POS: diff --git a/textures/base/pack/bubble_gone.png b/textures/base/pack/bubble_gone.png new file mode 100644 index 000000000..240ca4f8d Binary files /dev/null and b/textures/base/pack/bubble_gone.png differ diff --git a/textures/base/pack/heart_gone.png b/textures/base/pack/heart_gone.png new file mode 100644 index 000000000..240ca4f8d Binary files /dev/null and b/textures/base/pack/heart_gone.png differ -- cgit v1.2.3 From 9ba24f89f5846de6a8f0d7e01c89acfee1254704 Mon Sep 17 00:00:00 2001 From: Lars Müller <34514239+appgurueu@users.noreply.github.com> Date: Mon, 11 May 2020 21:41:36 +0200 Subject: Damage texture modifier (#9833) Adds a new object property "damage_texture_modifier" --- doc/lua_api.txt | 3 +++ src/client/content_cao.cpp | 14 +++++--------- src/object_properties.cpp | 5 +++++ src/object_properties.h | 1 + src/script/common/c_content.cpp | 4 ++++ 5 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 4078e21a1..db13f4224 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6589,6 +6589,9 @@ Player properties need to be saved manually. -- deleted when the block gets unloaded. -- The get_staticdata() callback is never called then. -- Defaults to 'true'. + + damage_texture_modifier = "^[brighten", + -- Texture modifier to be applied for a short duration when object is hit } Entity definition diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index aadd33bb9..eb1dad22b 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1532,7 +1532,7 @@ void GenericCAO::processMessage(const std::string &data) } else if (cmd == AO_CMD_SET_TEXTURE_MOD) { std::string mod = deSerializeString(is); - // immediatly reset a engine issued texture modifier if a mod sends a different one + // immediately reset a engine issued texture modifier if a mod sends a different one if (m_reset_textures_timer > 0) { m_reset_textures_timer = -1; updateTextures(m_previous_texture_modifier); @@ -1646,13 +1646,11 @@ void GenericCAO::processMessage(const std::string &data) m_smgr, m_env, m_position, v2f(m_prop.visual_size.X, m_prop.visual_size.Y) * BS); m_env->addSimpleObject(simple); - } else if (m_reset_textures_timer < 0) { - // TODO: Execute defined fast response - // Flashing shall suffice as there is no definition + } else if (m_reset_textures_timer < 0 && !m_prop.damage_texture_modifier.empty()) { m_reset_textures_timer = 0.05; if(damage >= 2) m_reset_textures_timer += 0.05 * damage; - updateTextures(m_current_texture_modifier + "^[brighten"); + updateTextures(m_current_texture_modifier + m_prop.damage_texture_modifier); } } @@ -1723,13 +1721,11 @@ bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem, v2f(m_prop.visual_size.X, m_prop.visual_size.Y) * BS); m_env->addSimpleObject(simple); } - // TODO: Execute defined fast response - // Flashing shall suffice as there is no definition - if (m_reset_textures_timer < 0) { + if (m_reset_textures_timer < 0 && !m_prop.damage_texture_modifier.empty()) { m_reset_textures_timer = 0.05; if (result.damage >= 2) m_reset_textures_timer += 0.05 * result.damage; - updateTextures(m_current_texture_modifier + "^[brighten"); + updateTextures(m_current_texture_modifier + m_prop.damage_texture_modifier); } } diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 4cf180b18..6ff344dce 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -68,6 +68,7 @@ std::string ObjectProperties::dump() os << ", eye_height=" << eye_height; os << ", zoom_fov=" << zoom_fov; os << ", use_texture_alpha=" << use_texture_alpha; + os << ", damage_texture_modifier=" << damage_texture_modifier; return os.str(); } @@ -114,6 +115,7 @@ void ObjectProperties::serialize(std::ostream &os) const writeF32(os, eye_height); writeF32(os, zoom_fov); writeU8(os, use_texture_alpha); + os << serializeString(damage_texture_modifier); // Add stuff only at the bottom. // Never remove anything, because we don't want new versions of this @@ -166,4 +168,7 @@ void ObjectProperties::deSerialize(std::istream &is) eye_height = readF32(is); zoom_fov = readF32(is); use_texture_alpha = readU8(is); + try { + damage_texture_modifier = deSerializeString(is); + } catch (SerializationError &e) {} } diff --git a/src/object_properties.h b/src/object_properties.h index 3895f3379..f7848f5a2 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -39,6 +39,7 @@ struct ObjectProperties std::string mesh = ""; v3f visual_size = v3f(1, 1, 1); std::vector textures; + std::string damage_texture_modifier = "^[brighten"; std::vector colors; v2s16 spritediv = v2s16(1, 1); v2s16 initial_sprite_basepos; diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 540b7222f..de9634c42 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -327,6 +327,8 @@ void read_object_properties(lua_State *L, int index, getfloatfield(L, -1, "zoom_fov", prop->zoom_fov); getboolfield(L, -1, "use_texture_alpha", prop->use_texture_alpha); + + getstringfield(L, -1, "damage_texture_modifier", prop->damage_texture_modifier); } /******************************************************************************/ @@ -409,6 +411,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) lua_setfield(L, -2, "zoom_fov"); lua_pushboolean(L, prop->use_texture_alpha); lua_setfield(L, -2, "use_texture_alpha"); + lua_pushlstring(L, prop->damage_texture_modifier.c_str(), prop->damage_texture_modifier.size()); + lua_setfield(L, -2, "damage_texture_modifier"); } /******************************************************************************/ -- cgit v1.2.3 From 836dd4a1e4f97411519578cd9e59b6dbe3b2c00d Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 14 May 2020 19:26:15 +0200 Subject: Add chat_log_level setting (#9223) Log all higher levels in LogOutputBuffer Move StreamLogOutput::logRaw to source file like LogOutputBuffer::logRaw for compiling speed --- builtin/settingtypes.txt | 3 ++ src/client/game.cpp | 16 ++++------- src/defaultsettings.cpp | 1 + src/log.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/log.h | 52 ++++++++-------------------------- 5 files changed, 95 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 9e4473655..b75bf2de5 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1401,6 +1401,9 @@ debug_log_level (Debug log level) enum action ,none,error,warning,action,info,ve # debug.txt is only moved if this setting is positive. debug_log_size_max (Debug log file size threshold) int 50 +# Minimal level of logging to be written to chat. +chat_log_level (Chat log level) enum error ,none,error,warning,action,info,verbose + # Enable IPv6 support (for both client and server). # Required for IPv6 connections to work at all. enable_ipv6 (IPv6) bool true diff --git a/src/client/game.cpp b/src/client/game.cpp index 422e17d4f..e7663a113 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -855,6 +855,7 @@ private: SoundMaker *soundmaker = nullptr; ChatBackend *chat_backend = nullptr; + LogOutputBuffer m_chat_log_buf; EventManager *eventmgr = nullptr; QuicktuneShortcutter *quicktune = nullptr; @@ -926,6 +927,7 @@ private: }; Game::Game() : + m_chat_log_buf(g_logger), m_game_ui(new GameUI()) { g_settings->registerChangedCallback("doubletap_jump", @@ -1192,6 +1194,7 @@ void Game::shutdown() chat_backend->addMessage(L"", L"# Disconnected."); chat_backend->addMessage(L"", L""); + m_chat_log_buf.clear(); if (client) { client->Stop(); @@ -2903,18 +2906,9 @@ void Game::processClientEvents(CameraOrientation *cam) void Game::updateChat(f32 dtime, const v2u32 &screensize) { - // Add chat log output for errors to be shown in chat - static LogOutputBuffer chat_log_error_buf(g_logger, LL_ERROR); - // Get new messages from error log buffer - while (!chat_log_error_buf.empty()) { - std::wstring error_message = utf8_to_wide(chat_log_error_buf.get()); - if (!g_settings->getBool("disable_escape_sequences")) { - error_message.insert(0, L"\x1b(c@red)"); - error_message.append(L"\x1b(c@white)"); - } - chat_backend->addMessage(L"", error_message); - } + while (!m_chat_log_buf.empty()) + chat_backend->addMessage(L"", utf8_to_wide(m_chat_log_buf.get())); // Get new messages from client std::wstring message; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 33654e213..1d0610c0f 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -400,6 +400,7 @@ void set_default_settings(Settings *settings) settings->setDefault("remote_media", ""); settings->setDefault("debug_log_level", "action"); settings->setDefault("debug_log_size_max", "50"); + settings->setDefault("chat_log_level", "error"); settings->setDefault("emergequeue_limit_total", "512"); settings->setDefault("emergequeue_limit_diskonly", "64"); settings->setDefault("emergequeue_limit_generate", "64"); diff --git a/src/log.cpp b/src/log.cpp index 30344b4df..54442c39b 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "debug.h" #include "gettime.h" #include "porting.h" +#include "settings.h" #include "config.h" #include "exceptions.h" #include "util/numeric.h" @@ -338,7 +339,80 @@ void FileLogOutput::setFile(const std::string &filename, s64 file_size_max) "-------------\n" << std::endl; } +void StreamLogOutput::logRaw(LogLevel lev, const std::string &line) +{ + bool colored_message = (Logger::color_mode == LOG_COLOR_ALWAYS) || + (Logger::color_mode == LOG_COLOR_AUTO && is_tty); + if (colored_message) { + switch (lev) { + case LL_ERROR: + // error is red + m_stream << "\033[91m"; + break; + case LL_WARNING: + // warning is yellow + m_stream << "\033[93m"; + break; + case LL_INFO: + // info is a bit dark + m_stream << "\033[37m"; + break; + case LL_VERBOSE: + // verbose is darker than info + m_stream << "\033[2m"; + break; + default: + // action is white + colored_message = false; + } + } + m_stream << line << std::endl; + + if (colored_message) { + // reset to white color + m_stream << "\033[0m"; + } +} + +void LogOutputBuffer::updateLogLevel() +{ + const std::string &conf_loglev = g_settings->get("chat_log_level"); + LogLevel log_level = Logger::stringToLevel(conf_loglev); + if (log_level == LL_MAX) { + warningstream << "Supplied unrecognized chat_log_level; " + "showing none." << std::endl; + log_level = LL_NONE; + } + + m_logger.removeOutput(this); + m_logger.addOutputMaxLevel(this, log_level); +} + +void LogOutputBuffer::logRaw(LogLevel lev, const std::string &line) +{ + std::string color; + + if (!g_settings->getBool("disable_escape_sequences")) { + switch (lev) { + case LL_ERROR: // red + color = "\x1b(c@#F00)"; + break; + case LL_WARNING: // yellow + color = "\x1b(c@#EE0)"; + break; + case LL_INFO: // grey + color = "\x1b(c@#BBB)"; + break; + case LL_VERBOSE: // dark grey + color = "\x1b(c@#888)"; + break; + default: break; + } + } + + m_buffer.push(color.append(line)); +} //// //// *Buffer methods diff --git a/src/log.h b/src/log.h index 6350d8a86..856d3479b 100644 --- a/src/log.h +++ b/src/log.h @@ -124,39 +124,7 @@ public: #endif } - void logRaw(LogLevel lev, const std::string &line) - { - bool colored_message = (Logger::color_mode == LOG_COLOR_ALWAYS) || - (Logger::color_mode == LOG_COLOR_AUTO && is_tty); - if (colored_message) - switch (lev) { - case LL_ERROR: - // error is red - m_stream << "\033[91m"; - break; - case LL_WARNING: - // warning is yellow - m_stream << "\033[93m"; - break; - case LL_INFO: - // info is a bit dark - m_stream << "\033[37m"; - break; - case LL_VERBOSE: - // verbose is darker than info - m_stream << "\033[2m"; - break; - default: - // action is white - colored_message = false; - } - - m_stream << line << std::endl; - - if (colored_message) - // reset to white color - m_stream << "\033[0m"; - } + void logRaw(LogLevel lev, const std::string &line); private: std::ostream &m_stream; @@ -178,23 +146,27 @@ private: class LogOutputBuffer : public ICombinedLogOutput { public: - LogOutputBuffer(Logger &logger, LogLevel lev) : + LogOutputBuffer(Logger &logger) : m_logger(logger) { - m_logger.addOutput(this, lev); - } + updateLogLevel(); + }; - ~LogOutputBuffer() + virtual ~LogOutputBuffer() { m_logger.removeOutput(this); } - void logRaw(LogLevel lev, const std::string &line) + void updateLogLevel(); + + void logRaw(LogLevel lev, const std::string &line); + + void clear() { - m_buffer.push(line); + m_buffer = std::queue(); } - bool empty() + bool empty() const { return m_buffer.empty(); } -- cgit v1.2.3 From 6ef7ad09bbed9176d0d15f53b5cb14ef6e18a3b2 Mon Sep 17 00:00:00 2001 From: TheTermos <55103816+TheTermos@users.noreply.github.com> Date: Thu, 14 May 2020 19:28:27 +0200 Subject: Collision detection - #9343 follow-up (#9764) * truncate speed to prevent inf result * code styling * change truncate() input parameters --- src/collision.cpp | 121 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/collision.cpp b/src/collision.cpp index 3b5e79a66..06ef820c5 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -66,6 +66,22 @@ struct NearbyCollisionInfo { aabb3f box; }; +// Helper functions: +// Truncate floating point numbers to specified number of decimal places +// in order to move all the floating point error to one side of the correct value +static inline f32 truncate(const f32 val, const f32 factor) +{ + return truncf(val * factor) / factor; +} + +static inline v3f truncate(const v3f& vec, const f32 factor) +{ + return v3f( + truncate(vec.X, factor), + truncate(vec.Y, factor), + truncate(vec.Z, factor) + ); +} // Helper function: // Checks for collision of a moving aabbox with a static aabbox @@ -78,70 +94,70 @@ CollisionAxis axisAlignedCollision( //TimeTaker tt("axisAlignedCollision"); aabb3f relbox( - movingbox.MaxEdge.X - movingbox.MinEdge.X + staticbox.MaxEdge.X - staticbox.MinEdge.X, // sum of the widths - movingbox.MaxEdge.Y - movingbox.MinEdge.Y + staticbox.MaxEdge.Y - staticbox.MinEdge.Y, - movingbox.MaxEdge.Z - movingbox.MinEdge.Z + staticbox.MaxEdge.Z - staticbox.MinEdge.Z, + (movingbox.MaxEdge.X - movingbox.MinEdge.X) + (staticbox.MaxEdge.X - staticbox.MinEdge.X), // sum of the widths + (movingbox.MaxEdge.Y - movingbox.MinEdge.Y) + (staticbox.MaxEdge.Y - staticbox.MinEdge.Y), + (movingbox.MaxEdge.Z - movingbox.MinEdge.Z) + (staticbox.MaxEdge.Z - staticbox.MinEdge.Z), std::max(movingbox.MaxEdge.X, staticbox.MaxEdge.X) - std::min(movingbox.MinEdge.X, staticbox.MinEdge.X), //outer bounding 'box' dimensions std::max(movingbox.MaxEdge.Y, staticbox.MaxEdge.Y) - std::min(movingbox.MinEdge.Y, staticbox.MinEdge.Y), std::max(movingbox.MaxEdge.Z, staticbox.MaxEdge.Z) - std::min(movingbox.MinEdge.Z, staticbox.MinEdge.Z) ); const f32 dtime_max = *dtime; - const f32 inner_margin = -1.5f; + f32 inner_margin; // the distance of clipping recovery f32 distance; f32 time; - if (speed.X) { - distance = relbox.MaxEdge.X - relbox.MinEdge.X; - *dtime = distance >= 0 ? std::abs(distance / speed.X) : -std::abs(distance / speed.X); + if (speed.Y) { + distance = relbox.MaxEdge.Y - relbox.MinEdge.Y; + *dtime = distance / std::abs(speed.Y); time = std::max(*dtime, 0.0f); - if (distance > inner_margin) { - if (*dtime <= dtime_max) { - if ((speed.X > 0 && staticbox.MaxEdge.X > movingbox.MaxEdge.X) || - (speed.X < 0 && staticbox.MinEdge.X < movingbox.MinEdge.X)) { - if ( - (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y) - - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y) - - relbox.MinEdge.Y < 0) && + if (*dtime <= dtime_max) { + inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Y - staticbox.MinEdge.Y), -2.0f); + + if ((speed.Y > 0 && staticbox.MinEdge.Y - movingbox.MaxEdge.Y > inner_margin) || + (speed.Y < 0 && movingbox.MinEdge.Y - staticbox.MaxEdge.Y > inner_margin)) { + if ( + (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X) + - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X) + - relbox.MinEdge.X < 0) && (std::max(movingbox.MaxEdge.Z + speed.Z * time, staticbox.MaxEdge.Z) - std::min(movingbox.MinEdge.Z + speed.Z * time, staticbox.MinEdge.Z) - relbox.MinEdge.Z < 0) - ) - return COLLISION_AXIS_X; - } - } else { - return COLLISION_AXIS_NONE; + ) + return COLLISION_AXIS_Y; } } + else { + return COLLISION_AXIS_NONE; + } } // NO else if here - if (speed.Y) { - distance = relbox.MaxEdge.Y - relbox.MinEdge.Y; - - *dtime = distance >= 0 ? std::abs(distance / speed.Y) : -std::abs(distance / speed.Y); + if (speed.X) { + distance = relbox.MaxEdge.X - relbox.MinEdge.X; + *dtime = distance / std::abs(speed.X); time = std::max(*dtime, 0.0f); - if (distance > inner_margin) { - if (*dtime <= dtime_max) { - if ((speed.Y > 0 && staticbox.MaxEdge.Y > movingbox.MaxEdge.Y) || - (speed.Y < 0 && staticbox.MinEdge.Y < movingbox.MinEdge.Y)) { - if ( - (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X) - - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X) - - relbox.MinEdge.X < 0) && + if (*dtime <= dtime_max) { + inner_margin = std::max(-0.5f * (staticbox.MaxEdge.X - staticbox.MinEdge.X), -2.0f); + + if ((speed.X > 0 && staticbox.MinEdge.X - movingbox.MaxEdge.X > inner_margin) || + (speed.X < 0 && movingbox.MinEdge.X - staticbox.MaxEdge.X > inner_margin)) { + if ( + (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y) + - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y) + - relbox.MinEdge.Y < 0) && (std::max(movingbox.MaxEdge.Z + speed.Z * time, staticbox.MaxEdge.Z) - std::min(movingbox.MinEdge.Z + speed.Z * time, staticbox.MinEdge.Z) - relbox.MinEdge.Z < 0) - ) - return COLLISION_AXIS_Y; - } - } else { - return COLLISION_AXIS_NONE; + ) + return COLLISION_AXIS_X; } + } else { + return COLLISION_AXIS_NONE; } } @@ -149,24 +165,23 @@ CollisionAxis axisAlignedCollision( if (speed.Z) { distance = relbox.MaxEdge.Z - relbox.MinEdge.Z; - - *dtime = distance >= 0 ? std::abs(distance / speed.Z) : -std::abs(distance / speed.Z); + *dtime = distance / std::abs(speed.Z); time = std::max(*dtime, 0.0f); - if (distance > inner_margin) { - if (*dtime <= dtime_max) { - if ((speed.Z > 0 && staticbox.MaxEdge.Z > movingbox.MaxEdge.Z) || - (speed.Z < 0 && staticbox.MinEdge.Z < movingbox.MinEdge.Z)) { - if ( - (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X) - - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X) - - relbox.MinEdge.X < 0) && + if (*dtime <= dtime_max) { + inner_margin = std::max(-0.5f * (staticbox.MaxEdge.Z - staticbox.MinEdge.Z), -2.0f); + + if ((speed.Z > 0 && staticbox.MinEdge.Z - movingbox.MaxEdge.Z > inner_margin) || + (speed.Z < 0 && movingbox.MinEdge.Z - staticbox.MaxEdge.Z > inner_margin)) { + if ( + (std::max(movingbox.MaxEdge.X + speed.X * time, staticbox.MaxEdge.X) + - std::min(movingbox.MinEdge.X + speed.X * time, staticbox.MinEdge.X) + - relbox.MinEdge.X < 0) && (std::max(movingbox.MaxEdge.Y + speed.Y * time, staticbox.MaxEdge.Y) - std::min(movingbox.MinEdge.Y + speed.Y * time, staticbox.MinEdge.Y) - relbox.MinEdge.Y < 0) - ) - return COLLISION_AXIS_Z; - } + ) + return COLLISION_AXIS_Z; } } } @@ -245,6 +260,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, speed_f->X = rangelim(speed_f->X, -5000, 5000); speed_f->Z = rangelim(speed_f->Z, -5000, 5000); + *speed_f = truncate(*speed_f, 10000.0f); + /* Collect node boxes in movement range */ @@ -464,7 +481,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, if (nearest_collided == COLLISION_AXIS_NONE) { // No collision with any collision box. - *pos_f += *speed_f * dtime; + *pos_f += truncate(*speed_f * dtime, 100.0f); dtime = 0; // Set to 0 to avoid "infinite" loop due to small FP numbers } else { // Otherwise, a collision occurred. @@ -500,7 +517,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, pos_f->Z += speed_f->Z * nearest_dtime; } } else { - *pos_f += *speed_f * nearest_dtime; + *pos_f += truncate(*speed_f * nearest_dtime, 100.0f); dtime -= nearest_dtime; } -- cgit v1.2.3 From 36d35f2fe31a429c1510df680801940472416d45 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 14 May 2020 21:16:45 +0200 Subject: CSM: Bugfixes to camera:get_pos() and camera:get_fov() closes #9857 --- clientmods/preview/init.lua | 2 +- doc/client_lua_api.txt | 2 +- src/client/camera.cpp | 2 +- src/script/lua_api/l_camera.cpp | 59 +++++++++++++++++++++++++---------------- src/script/lua_api/l_env.cpp | 16 +++++------ 5 files changed, 47 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index d2440369a..089955d2f 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -79,7 +79,7 @@ core.register_on_item_use(function(itemstack, pointed_thing) return false end - local pos = vector.add(core.localplayer:get_pos(), core.camera:get_offset()) + local pos = core.camera:get_pos() local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100)) local rc = core.raycast(pos, pos2) diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 53442d308..c9cd8ac93 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -967,7 +967,7 @@ Please do not try to access the reference until the camera is initialized, other * `get_camera_mode()` * Returns 0, 1, or 2 as described above * `get_fov()` - * Returns: + * Returns a table with X, Y, maximum and actual FOV in degrees: ```lua { diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 1a5253db4..9b311171a 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -540,7 +540,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r m_aspect = (f32) window_size.X / (f32) window_size.Y; m_fov_y = m_curr_fov_degrees * M_PI / 180.0; // Increase vertical FOV on lower aspect ratios (<16:10) - m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect))); + m_fov_y *= core::clamp(sqrt(16./10. / m_aspect), 1.0, 1.4); m_fov_x = 2 * atan(m_aspect * tan(0.5 * m_fov_y)); m_cameranode->setAspectRatio(m_aspect); m_cameranode->setFOV(m_fov_y); diff --git a/src/script/lua_api/l_camera.cpp b/src/script/lua_api/l_camera.cpp index 9c1470284..bfa60be67 100644 --- a/src/script/lua_api/l_camera.cpp +++ b/src/script/lua_api/l_camera.cpp @@ -51,6 +51,7 @@ void LuaCamera::create(lua_State *L, Camera *m) lua_setfield(L, objectstable, "camera"); } +// set_camera_mode(self, mode) int LuaCamera::l_set_camera_mode(lua_State *L) { Camera *camera = getobject(L, 1); @@ -67,17 +68,19 @@ int LuaCamera::l_set_camera_mode(lua_State *L) return 0; } +// get_camera_mode(self) int LuaCamera::l_get_camera_mode(lua_State *L) { Camera *camera = getobject(L, 1); if (!camera) return 0; - lua_pushnumber(L, (int)camera->getCameraMode()); + lua_pushinteger(L, (int)camera->getCameraMode()); return 1; } +// get_fov(self) int LuaCamera::l_get_fov(lua_State *L) { Camera *camera = getobject(L, 1); @@ -85,9 +88,9 @@ int LuaCamera::l_get_fov(lua_State *L) return 0; lua_newtable(L); - lua_pushnumber(L, camera->getFovX() * core::DEGTORAD); + lua_pushnumber(L, camera->getFovX() * core::RADTODEG); lua_setfield(L, -2, "x"); - lua_pushnumber(L, camera->getFovY() * core::DEGTORAD); + lua_pushnumber(L, camera->getFovY() * core::RADTODEG); lua_setfield(L, -2, "y"); lua_pushnumber(L, camera->getCameraNode()->getFOV() * core::RADTODEG); lua_setfield(L, -2, "actual"); @@ -96,16 +99,18 @@ int LuaCamera::l_get_fov(lua_State *L) return 1; } +// get_pos(self) int LuaCamera::l_get_pos(lua_State *L) { Camera *camera = getobject(L, 1); if (!camera) return 0; - push_v3f(L, camera->getPosition()); + push_v3f(L, camera->getPosition() / BS); return 1; } +// get_offset(self) int LuaCamera::l_get_offset(lua_State *L) { LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer(); @@ -115,38 +120,40 @@ int LuaCamera::l_get_offset(lua_State *L) return 1; } +// get_look_dir(self) int LuaCamera::l_get_look_dir(lua_State *L) { - LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer(); - sanity_check(player); - - float pitch = -1.0 * player->getPitch() * core::DEGTORAD; - float yaw = (player->getYaw() + 90.) * core::DEGTORAD; - v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch), - std::cos(pitch) * std::sin(yaw)); + Camera *camera = getobject(L, 1); + if (!camera) + return 0; - push_v3f(L, v); + push_v3f(L, camera->getDirection()); return 1; } +// get_look_horizontal(self) +// FIXME: wouldn't localplayer be a better place for this? int LuaCamera::l_get_look_horizontal(lua_State *L) { LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer(); sanity_check(player); - lua_pushnumber(L, (player->getYaw() + 90.) * core::DEGTORAD); + lua_pushnumber(L, (player->getYaw() + 90.f) * core::DEGTORAD); return 1; } +// get_look_vertical(self) +// FIXME: wouldn't localplayer be a better place for this? int LuaCamera::l_get_look_vertical(lua_State *L) { LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer(); sanity_check(player); - lua_pushnumber(L, -1.0 * player->getPitch() * core::DEGTORAD); + lua_pushnumber(L, -1.0f * player->getPitch() * core::DEGTORAD); return 1; } +// get_aspect_ratio(self) int LuaCamera::l_get_aspect_ratio(lua_State *L) { Camera *camera = getobject(L, 1); @@ -215,13 +222,19 @@ void LuaCamera::Register(lua_State *L) lua_pop(L, 1); } +// clang-format off const char LuaCamera::className[] = "Camera"; -const luaL_Reg LuaCamera::methods[] = {luamethod(LuaCamera, set_camera_mode), - luamethod(LuaCamera, get_camera_mode), luamethod(LuaCamera, get_fov), - luamethod(LuaCamera, get_pos), luamethod(LuaCamera, get_offset), - luamethod(LuaCamera, get_look_dir), - luamethod(LuaCamera, get_look_vertical), - luamethod(LuaCamera, get_look_horizontal), - luamethod(LuaCamera, get_aspect_ratio), - - {0, 0}}; +const luaL_Reg LuaCamera::methods[] = { + luamethod(LuaCamera, set_camera_mode), + luamethod(LuaCamera, get_camera_mode), + luamethod(LuaCamera, get_fov), + luamethod(LuaCamera, get_pos), + luamethod(LuaCamera, get_offset), + luamethod(LuaCamera, get_look_dir), + luamethod(LuaCamera, get_look_vertical), + luamethod(LuaCamera, get_look_horizontal), + luamethod(LuaCamera, get_aspect_ratio), + + {0, 0} +}; +// clang-format on diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index cabca124d..b8a8a5ce1 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -780,8 +780,8 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) #ifndef SERVER // Client API limitations - if (getClient(L)) - radius = getClient(L)->CSMClampRadius(pos, radius); + if (Client *client = getClient(L)) + radius = client->CSMClampRadius(pos, radius); #endif for (int d = start_radius; d <= radius; d++) { @@ -811,9 +811,9 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); #ifndef SERVER - if (getClient(L)) { - minp = getClient(L)->CSMClampPos(minp); - maxp = getClient(L)->CSMClampPos(maxp); + if (Client *client = getClient(L)) { + minp = client->CSMClampPos(minp); + maxp = client->CSMClampPos(maxp); } #endif @@ -887,9 +887,9 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) const NodeDefManager *ndef = env->getGameDef()->ndef(); #ifndef SERVER - if (getClient(L)) { - minp = getClient(L)->CSMClampPos(minp); - maxp = getClient(L)->CSMClampPos(maxp); + if (Client *client = getClient(L)) { + minp = client->CSMClampPos(minp); + maxp = client->CSMClampPos(maxp); } #endif -- cgit v1.2.3 From d76785b4c70d834783d2e578086680941257cfa1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 14 May 2020 21:18:26 +0200 Subject: network: Replace a fatal_error with just error logging --- src/network/connectionthreads.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index 1f33d2ded..9a6617a1c 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -336,11 +336,9 @@ bool ConnectionSendThread::rawSendAsPacket(session_t peer_id, u8 channelnum, { PeerHelper peer = m_connection->getPeerNoEx(peer_id); if (!peer) { - LOG(dout_con << m_connection->getDesc() - << " INFO: dropped packet for non existent peer_id: " - << peer_id << std::endl); - FATAL_ERROR_IF(!reliable, - "Trying to send raw packet reliable but no peer found!"); + LOG(errorstream << m_connection->getDesc() + << " dropped " << (reliable ? "reliable " : "") + << "packet for non existent peer_id: " << peer_id << std::endl); return false; } Channel *channel = &(dynamic_cast(&peer)->channels[channelnum]); -- cgit v1.2.3 From af0f7ac4a2032780eb731918c8fe9dc9e1262b5f Mon Sep 17 00:00:00 2001 From: Paramat Date: Thu, 14 May 2020 22:27:54 +0100 Subject: Add new Mapgen V7 floatland implementation (#9296) Floatland structure is vertically-compressed 3D noise. Uses a lacunarity of 1.618 (the golden ratio) for high quality noise. Floatlands appear between user-settable Y limits, with smooth tapering at each limit. Simple user-settable density adjustment. Shadow propagation is disabled in and just below floatlands, no shadows are cast on the world surface. Can be reconfigured to create a solid upper world layer between the Y limits, lakes/seas can be optionally added to this. --- builtin/settingtypes.txt | 49 ++++++++++++++++++++++- src/mapgen/mapgen_v7.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++----- src/mapgen/mapgen_v7.h | 21 +++++++++- 3 files changed, 160 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index b75bf2de5..d3f2c60b5 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1607,12 +1607,53 @@ mgv6_np_apple_trees (Apple trees noise) noise_params_2d 0, 1, (100, 100, 100), 3 [*Mapgen V7] # Map generation attributes specific to Mapgen v7. -# 'ridges' enables the rivers. +# 'ridges': Rivers. +# 'floatlands': Floating land masses in the atmosphere. +# 'caverns': Giant caves deep underground. mgv7_spflags (Mapgen V7 specific flags) flags mountains,ridges,nofloatlands,caverns mountains,ridges,floatlands,caverns,nomountains,noridges,nofloatlands,nocaverns # Y of mountain density gradient zero level. Used to shift mountains vertically. mgv7_mount_zero_level (Mountain zero level) int 0 +# Lower Y limit of floatlands. +mgv7_floatland_ymin (Floatland minimum Y) int 1024 + +# Upper Y limit of floatlands. +mgv7_floatland_ymax (Floatland maximum Y) int 4096 + +# Y-distance over which floatlands taper from full density to nothing. +# Tapering starts at this distance from the Y limit. +# For a solid floatland layer, this controls the height of hills/mountains. +# Must be less than or equal to half the distance between the Y limits. +mgv7_floatland_taper (Floatland tapering distance) int 256 + +# Exponent of the floatland tapering. Alters the tapering behaviour. +# Value = 1.0 creates a uniform, linear tapering. +# Values > 1.0 create a smooth tapering suitable for the default separated +# floatlands. +# Values < 1.0 (for example 0.25) create a more defined surface level with +# flatter lowlands, suitable for a solid floatland layer. +mgv7_float_taper_exp (Floatland taper exponent) float 2.0 + +# Adjusts the density of the floatland layer. +# Increase value to increase density. Can be positive or negative. +# Value = 0.0: 50% of volume is floatland. +# Value = 2.0 (can be higher depending on 'mgv7_np_floatland', always test +# to be sure) creates a solid floatland layer. +mgv7_floatland_density (Floatland density) float -0.9 + +# Surface level of optional water placed on a solid floatland layer. +# Water is disabled by default and will only be placed if this value is set +# to above 'mgv7_floatland_ymax' - 'mgv7_floatland_taper' (the start of the +# upper tapering). +# ***WARNING, POTENTIAL DANGER TO WORLDS AND SERVER PERFORMANCE***: +# When enabling water placement the floatlands must be configured and tested +# to be a solid layer by setting 'mgv7_floatland_density' to 2.0 (or other +# required value depending on 'mgv7_np_floatland'), to avoid +# server-intensive extreme water flow and to avoid vast flooding of the +# world surface below. +mgv7_floatland_ywater (Floatland water level) int -31000 + # Controls width of tunnels, a smaller value creates wider tunnels. # Value >= 10.0 completely disables generation of tunnels and avoids the # intensive noise calculations. @@ -1682,6 +1723,12 @@ mgv7_np_mountain (Mountain noise) noise_params_3d -0.6, 1, (250, 350, 250), 5333 # 3D noise defining structure of river canyon walls. mgv7_np_ridge (Ridge noise) noise_params_3d 0, 1, (100, 100, 100), 6467, 4, 0.75, 2.0 +# 3D noise defining structure of floatlands. +# If altered from the default, the noise 'scale' (0.7 by default) may need +# to be adjusted, as floatland tapering functions best when this noise has +# a value range of approximately -2.0 to 2.0. +mgv7_np_floatland (Floatland noise) noise_params_3d 0, 0.7, (384, 96, 384), 1009, 4, 0.75, 1.618 + # 3D noise defining giant caverns. mgv7_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 43d5d822f..e93dc9140 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -1,7 +1,7 @@ /* Minetest -Copyright (C) 2013-2019 kwolekr, Ryan Kwolek -Copyright (C) 2014-2019 paramat +Copyright (C) 2014-2020 paramat +Copyright (C) 2013-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -56,6 +56,12 @@ MapgenV7::MapgenV7(MapgenV7Params *params, EmergeParams *emerge) { spflags = params->spflags; mount_zero_level = params->mount_zero_level; + floatland_ymin = params->floatland_ymin; + floatland_ymax = params->floatland_ymax; + floatland_taper = params->floatland_taper; + float_taper_exp = params->float_taper_exp; + floatland_density = params->floatland_density; + floatland_ywater = params->floatland_ywater; cave_width = params->cave_width; large_cave_depth = params->large_cave_depth; @@ -70,6 +76,9 @@ MapgenV7::MapgenV7(MapgenV7Params *params, EmergeParams *emerge) dungeon_ymin = params->dungeon_ymin; dungeon_ymax = params->dungeon_ymax; + // Allocate floatland noise offset cache + this->float_offset_cache = new float[csize.Y + 2]; + // 2D noise noise_terrain_base = new Noise(¶ms->np_terrain_base, seed, csize.X, csize.Z); @@ -100,6 +109,12 @@ MapgenV7::MapgenV7(MapgenV7Params *params, EmergeParams *emerge) new Noise(¶ms->np_ridge, seed, csize.X, csize.Y + 2, csize.Z); } + if (spflags & MGV7_FLOATLANDS) { + // 3D noise, 1 up, 1 down overgeneration + noise_floatland = + new Noise(¶ms->np_floatland, seed, csize.X, csize.Y + 2, csize.Z); + } + // 3D noise, 1 down overgeneration MapgenBasic::np_cave1 = params->np_cave1; MapgenBasic::np_cave2 = params->np_cave2; @@ -126,6 +141,12 @@ MapgenV7::~MapgenV7() delete noise_ridge_uwater; delete noise_ridge; } + + if (spflags & MGV7_FLOATLANDS) { + delete noise_floatland; + } + + delete []float_offset_cache; } @@ -139,6 +160,7 @@ MapgenV7Params::MapgenV7Params(): np_ridge_uwater (0.0, 1.0, v3f(1000, 1000, 1000), 85039, 5, 0.6, 2.0), np_mountain (-0.6, 1.0, v3f(250, 350, 250), 5333, 5, 0.63, 2.0), np_ridge (0.0, 1.0, v3f(100, 100, 100), 6467, 4, 0.75, 2.0), + np_floatland (0.0, 0.7, v3f(384, 96, 384), 1009, 4, 0.75, 1.618), np_cavern (0.0, 1.0, v3f(384, 128, 384), 723, 5, 0.63, 2.0), np_cave1 (0.0, 12.0, v3f(61, 61, 61), 52534, 3, 0.5, 2.0), np_cave2 (0.0, 12.0, v3f(67, 67, 67), 10325, 3, 0.5, 2.0), @@ -151,6 +173,13 @@ void MapgenV7Params::readParams(const Settings *settings) { settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7); settings->getS16NoEx("mgv7_mount_zero_level", mount_zero_level); + settings->getS16NoEx("mgv7_floatland_ymin", floatland_ymin); + settings->getS16NoEx("mgv7_floatland_ymax", floatland_ymax); + settings->getS16NoEx("mgv7_floatland_taper", floatland_taper); + settings->getFloatNoEx("mgv7_float_taper_exp", float_taper_exp); + settings->getFloatNoEx("mgv7_floatland_density", floatland_density); + settings->getS16NoEx("mgv7_floatland_ywater", floatland_ywater); + settings->getFloatNoEx("mgv7_cave_width", cave_width); settings->getS16NoEx("mgv7_large_cave_depth", large_cave_depth); settings->getU16NoEx("mgv7_small_cave_num_min", small_cave_num_min); @@ -173,6 +202,7 @@ void MapgenV7Params::readParams(const Settings *settings) settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater); settings->getNoiseParams("mgv7_np_mountain", np_mountain); settings->getNoiseParams("mgv7_np_ridge", np_ridge); + settings->getNoiseParams("mgv7_np_floatland", np_floatland); settings->getNoiseParams("mgv7_np_cavern", np_cavern); settings->getNoiseParams("mgv7_np_cave1", np_cave1); settings->getNoiseParams("mgv7_np_cave2", np_cave2); @@ -184,6 +214,13 @@ void MapgenV7Params::writeParams(Settings *settings) const { settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7); settings->setS16("mgv7_mount_zero_level", mount_zero_level); + settings->setS16("mgv7_floatland_ymin", floatland_ymin); + settings->setS16("mgv7_floatland_ymax", floatland_ymax); + settings->setS16("mgv7_floatland_taper", floatland_taper); + settings->setFloat("mgv7_float_taper_exp", float_taper_exp); + settings->setFloat("mgv7_floatland_density", floatland_density); + settings->setS16("mgv7_floatland_ywater", floatland_ywater); + settings->setFloat("mgv7_cave_width", cave_width); settings->setS16("mgv7_large_cave_depth", large_cave_depth); settings->setU16("mgv7_small_cave_num_min", small_cave_num_min); @@ -206,6 +243,7 @@ void MapgenV7Params::writeParams(Settings *settings) const settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater); settings->setNoiseParams("mgv7_np_mountain", np_mountain); settings->setNoiseParams("mgv7_np_ridge", np_ridge); + settings->setNoiseParams("mgv7_np_floatland", np_floatland); settings->setNoiseParams("mgv7_np_cavern", np_cavern); settings->setNoiseParams("mgv7_np_cave1", np_cave1); settings->setNoiseParams("mgv7_np_cave2", np_cave2); @@ -357,8 +395,9 @@ void MapgenV7::makeChunk(BlockMakeData *data) updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); // Calculate lighting - // TODO disable in and just below floatlands - bool propagate_shadow = true; + // Limit floatland shadows + bool propagate_shadow = !((spflags & MGV7_FLOATLANDS) && + node_max.Y >= floatland_ymin - csize.Y * 2 && node_min.Y <= floatland_ymax); if (flags & MG_LIGHT) calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), @@ -427,6 +466,12 @@ bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y) } +bool MapgenV7::getFloatlandTerrainFromMap(int idx_xyz, float float_offset) +{ + return noise_floatland->result[idx_xyz] + floatland_density - float_offset >= 0.0f; +} + + int MapgenV7::generateTerrain() { MapNode n_air(CONTENT_AIR); @@ -446,6 +491,35 @@ int MapgenV7::generateTerrain() noise_mountain->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); } + //// Floatlands + // 'Generate floatlands in this mapchunk' bool for + // simplification of condition checks in y-loop. + bool gen_floatlands = false; + u8 cache_index = 0; + // Y values where floatland tapering starts + s16 float_taper_ymax = floatland_ymax - floatland_taper; + s16 float_taper_ymin = floatland_ymin + floatland_taper; + + if ((spflags & MGV7_FLOATLANDS) && + node_max.Y >= floatland_ymin && node_min.Y <= floatland_ymax) { + gen_floatlands = true; + // Calculate noise for floatland generation + noise_floatland->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); + + // Cache floatland noise offset values, for floatland tapering + for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++, cache_index++) { + float float_offset = 0.0f; + if (y > float_taper_ymax) { + float_offset = std::pow((y - float_taper_ymax) / (float)floatland_taper, + float_taper_exp) * 4.0f; + } else if (y < float_taper_ymin) { + float_offset = std::pow((float_taper_ymin - y) / (float)floatland_taper, + float_taper_exp) * 4.0f; + } + float_offset_cache[cache_index] = float_offset; + } + } + //// Place nodes const v3s16 &em = vm->m_area.getExtent(); s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT; @@ -457,13 +531,15 @@ int MapgenV7::generateTerrain() if (surface_y > stone_surface_max_y) stone_surface_max_y = surface_y; + cache_index = 0; u32 vi = vm->m_area.index(x, node_min.Y - 1, z); u32 index3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X); for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++, index3d += ystride, - VoxelArea::add_y(em, vi, 1)) { + VoxelArea::add_y(em, vi, 1), + cache_index++) { if (vm->m_data[vi].getContent() != CONTENT_IGNORE) continue; @@ -474,10 +550,18 @@ int MapgenV7::generateTerrain() vm->m_data[vi] = n_stone; // Mountain terrain if (y > stone_surface_max_y) stone_surface_max_y = y; - } else if (y <= water_level) { + } else if (gen_floatlands && + getFloatlandTerrainFromMap(index3d, + float_offset_cache[cache_index])) { + vm->m_data[vi] = n_stone; // Floatland terrain + if (y > stone_surface_max_y) + stone_surface_max_y = y; + } else if (y <= water_level) { // Surface water vm->m_data[vi] = n_water; + } else if (gen_floatlands && y >= float_taper_ymax && y <= floatland_ywater) { + vm->m_data[vi] = n_water; // Water for solid floatland layer only } else { - vm->m_data[vi] = n_air; + vm->m_data[vi] = n_air; // Air } } } @@ -488,8 +572,8 @@ int MapgenV7::generateTerrain() void MapgenV7::generateRidgeTerrain() { - // TODO disable river canyons in floatlands - if (node_max.Y < water_level - 16) + if (node_max.Y < water_level - 16 || + (node_max.Y >= floatland_ymin && node_min.Y <= floatland_ymax)) return; noise_ridge->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z); diff --git a/src/mapgen/mapgen_v7.h b/src/mapgen/mapgen_v7.h index eeae3a956..4020cd935 100644 --- a/src/mapgen/mapgen_v7.h +++ b/src/mapgen/mapgen_v7.h @@ -1,7 +1,7 @@ /* Minetest -Copyright (C) 2013-2018 kwolekr, Ryan Kwolek -Copyright (C) 2014-2018 paramat +Copyright (C) 2014-2020 paramat +Copyright (C) 2013-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,6 +36,12 @@ extern FlagDesc flagdesc_mapgen_v7[]; struct MapgenV7Params : public MapgenParams { s16 mount_zero_level = 0; + s16 floatland_ymin = 1024; + s16 floatland_ymax = 4096; + s16 floatland_taper = 256; + float float_taper_exp = 2.0f; + float floatland_density = -0.6f; + s16 floatland_ywater = -31000; float cave_width = 0.09f; s16 large_cave_depth = -33; @@ -59,6 +65,7 @@ struct MapgenV7Params : public MapgenParams { NoiseParams np_ridge_uwater; NoiseParams np_mountain; NoiseParams np_ridge; + NoiseParams np_floatland; NoiseParams np_cavern; NoiseParams np_cave1; NoiseParams np_cave2; @@ -87,12 +94,21 @@ public: float baseTerrainLevelFromMap(int index); bool getMountainTerrainAtPoint(s16 x, s16 y, s16 z); bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y); + bool getFloatlandTerrainFromMap(int idx_xyz, float float_offset); int generateTerrain(); void generateRidgeTerrain(); private: s16 mount_zero_level; + s16 floatland_ymin; + s16 floatland_ymax; + s16 floatland_taper; + float float_taper_exp; + float floatland_density; + s16 floatland_ywater; + + float *float_offset_cache = nullptr; Noise *noise_terrain_base; Noise *noise_terrain_alt; @@ -102,4 +118,5 @@ private: Noise *noise_ridge_uwater; Noise *noise_mountain; Noise *noise_ridge; + Noise *noise_floatland; }; -- cgit v1.2.3 From a08251a61e5c6f407621d04b2de4da6812410c66 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 16 May 2020 12:03:36 +0200 Subject: Log protocol ver on mismatched client connect too --- src/network/serverpackethandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 39a912827..2fa9d4196 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -112,7 +112,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) if (depl_serial_v == SER_FMT_VER_INVALID) { actionstream << "Server: A mismatched client tried to connect from " << - addr_s << " client_max=" << (int)client_max << std::endl; + addr_s << " ser_fmt_max=" << (int)client_max << std::endl; DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION); return; } @@ -147,7 +147,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) net_proto_version < SERVER_PROTOCOL_VERSION_MIN || net_proto_version > SERVER_PROTOCOL_VERSION_MAX) { actionstream << "Server: A mismatched client tried to connect from " << - addr_s << std::endl; + addr_s << " proto_max=" << (int)max_net_proto_version << std::endl; DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_VERSION); return; } -- cgit v1.2.3 From c1ce4be756e2554051a27f244303377c0a7d69a6 Mon Sep 17 00:00:00 2001 From: ANAND Date: Sun, 17 May 2020 01:12:31 +0530 Subject: Make automatic_rotate relative, allow setting rotation (#8468) automatic_rotate does not make sense if it is absolute. Make it relative. To avoid bouncing, set_rotation did not update the client when automatic_rotate was set. That's no longer necessary because the new spinning method applies the rotation on top of the current one, and the updates are necessary for set_rotation to actually transform the object. Co-authored-by: ANAND Co-authored-by: Pedro Gimeno --- doc/lua_api.txt | 1 + src/client/content_cao.cpp | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 9685e8307..07758c237 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6555,6 +6555,7 @@ Player properties need to be saved manually. automatic_rotate = 0, -- Set constant rotation in radians per second, positive or negative. + -- Object rotates along the local Y-axis, and works with set_rotation. -- Set to 0 to disable constant rotation. stepheight = 0, diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index eb1dad22b..867bbf2c8 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1077,10 +1077,13 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) updateTextures(m_previous_texture_modifier); } } + if (!getParent() && std::fabs(m_prop.automatic_rotate) > 0.001) { - m_rotation.Y += dtime * m_prop.automatic_rotate * 180 / M_PI; - rot_translator.val_current = m_rotation; - updateNodePos(); + // This is the child node's rotation. It is only used for automatic_rotate. + v3f local_rot = node->getRotation(); + local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG * + m_prop.automatic_rotate); + node->setRotation(local_rot); } if (!getParent() && m_prop.automatic_face_movement_dir && @@ -1501,11 +1504,7 @@ void GenericCAO::processMessage(const std::string &data) m_position = readV3F32(is); m_velocity = readV3F32(is); m_acceleration = readV3F32(is); - - if (std::fabs(m_prop.automatic_rotate) < 0.001f) - m_rotation = readV3F32(is); - else - readV3F32(is); + m_rotation = readV3F32(is); m_rotation = wrapDegrees_0_360_v3f(m_rotation); bool do_interpolate = readU8(is); -- cgit v1.2.3 From a9c3a423231e26ea3edee51d5f0bf949ca8e529b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 17 May 2020 19:09:10 +0100 Subject: Add core.open_url() to main menu API (#8592) --- .../java/net/minetest/minetest/GameActivity.java | 6 ++ builtin/mainmenu/dlg_contentstore.lua | 113 ++++----------------- builtin/mainmenu/tab_credits.lua | 11 +- doc/menu_lua_api.txt | 5 + src/porting.cpp | 30 +++++- src/porting.h | 3 + src/porting_android.cpp | 12 +++ src/porting_android.h | 2 + src/script/lua_api/l_mainmenu.cpp | 9 ++ src/script/lua_api/l_mainmenu.h | 3 + 10 files changed, 98 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java b/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java index 02b61b598..635512569 100644 --- a/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java +++ b/build/android/app/src/main/java/net/minetest/minetest/GameActivity.java @@ -22,6 +22,7 @@ package net.minetest.minetest; import android.app.NativeActivity; import android.content.Intent; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.view.View; @@ -117,4 +118,9 @@ public class GameActivity extends NativeActivity { public int getDisplayWidth() { return getResources().getDisplayMetrics().widthPixels; } + + public void openURL(String url) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(browserIntent); + } } diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 3bc5f60bb..ce5c061c6 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -16,7 +16,6 @@ --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. local store = { packages = {}, packages_full = {} } -local package_dialog = {} -- Screenshot local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb" @@ -44,8 +43,6 @@ local filter_types_type = { } - - local function download_package(param) if core.download_file(param.package.url, param.filename) then return { @@ -195,74 +192,6 @@ local function get_screenshot(package) return defaulttexturedir .. "loading_screenshot.png" end - - -function package_dialog.get_formspec() - local package = package_dialog.package - - store.update_paths() - - local formspec = { - "size[9,4;true]", - "image[0,1;4.5,3;", core.formspec_escape(get_screenshot(package)), ']', - "label[3.8,1;", - minetest.colorize(mt_color_green, core.formspec_escape(package.title)), "\n", - minetest.colorize('#BFBFBF', "by " .. core.formspec_escape(package.author)), "]", - "textarea[4,2;5.3,2;;;", core.formspec_escape(package.short_description), "]", - "button[0,0;2,1;back;", fgettext("Back"), "]", - } - - if not package.path then - formspec[#formspec + 1] = "button[7,0;2,1;install;" - formspec[#formspec + 1] = fgettext("Install") - formspec[#formspec + 1] = "]" - elseif package.installed_release < package.release then - -- The install_ action also handles updating - formspec[#formspec + 1] = "button[7,0;2,1;install;" - formspec[#formspec + 1] = fgettext("Update") - formspec[#formspec + 1] = "]" - formspec[#formspec + 1] = "button[5,0;2,1;uninstall;" - formspec[#formspec + 1] = fgettext("Uninstall") - formspec[#formspec + 1] = "]" - else - formspec[#formspec + 1] = "button[7,0;2,1;uninstall;" - formspec[#formspec + 1] = fgettext("Uninstall") - formspec[#formspec + 1] = "]" - end - - return table.concat(formspec, "") -end - -function package_dialog.handle_submit(this, fields) - if fields.back then - this:delete() - return true - end - - if fields.install then - start_install(this, package_dialog.package) - return true - end - - if fields.uninstall then - local dlg_delmod = create_delete_content_dlg(package_dialog.package) - dlg_delmod:set_parent(this) - this:hide() - dlg_delmod:show() - return true - end - - return false -end - -function package_dialog.create(package) - package_dialog.package = package - return dialog_create("package_view", - package_dialog.get_formspec, - package_dialog.handle_submit, - nil) -end - function store.load() local tmpdir = os.tempfolder() local target = tmpdir .. DIR_DELIM .. "packages.json" @@ -462,44 +391,45 @@ function store.get_formspec(dlgdata) minetest.colorize("#BFBFBF", " by " .. package.author)) formspec[#formspec + 1] = "]" - -- description - if package.path and package.installed_release < package.release then - formspec[#formspec + 1] = "textarea[1.25,0.3;7.5,1;;;" - else - formspec[#formspec + 1] = "textarea[1.25,0.3;9,1;;;" - end - formspec[#formspec + 1] = core.formspec_escape(package.short_description) - formspec[#formspec + 1] = "]" - -- buttons + local description_width = 7.5 if not package.path then - formspec[#formspec + 1] = "button[9.9,0;1.5,1;install_" + formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_" formspec[#formspec + 1] = tostring(i) formspec[#formspec + 1] = ";" formspec[#formspec + 1] = fgettext("Install") formspec[#formspec + 1] = "]" else if package.installed_release < package.release then + description_width = 6 + -- The install_ action also handles updating - formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_" + formspec[#formspec + 1] = "button[6.9,0;1.5,1;install_" formspec[#formspec + 1] = tostring(i) formspec[#formspec + 1] = ";" formspec[#formspec + 1] = fgettext("Update") formspec[#formspec + 1] = "]" end - formspec[#formspec + 1] = "button[9.9,0;1.5,1;uninstall_" + formspec[#formspec + 1] = "button[8.4,0;1.5,1;uninstall_" formspec[#formspec + 1] = tostring(i) formspec[#formspec + 1] = ";" formspec[#formspec + 1] = fgettext("Uninstall") formspec[#formspec + 1] = "]" end - --formspec[#formspec + 1] = "button[9.9,0;1.5,1;view_" - --formspec[#formspec + 1] = tostring(i) - --formspec[#formspec + 1] = ";" - --formspec[#formspec + 1] = fgettext("View") - --formspec[#formspec + 1] = "]" + formspec[#formspec + 1] = "button[9.9,0;1.5,1;view_" + formspec[#formspec + 1] = tostring(i) + formspec[#formspec + 1] = ";" + formspec[#formspec + 1] = fgettext("View") + formspec[#formspec + 1] = "]" + + -- description + formspec[#formspec + 1] = "textarea[1.25,0.3;" + formspec[#formspec + 1] = tostring(description_width) + formspec[#formspec + 1] = ",1;;;" + formspec[#formspec + 1] = core.formspec_escape(package.short_description) + formspec[#formspec + 1] = "]" formspec[#formspec + 1] = "container_end[]" end @@ -576,10 +506,9 @@ function store.handle_submit(this, fields) end if fields["view_" .. i] then - local dlg = package_dialog.create(package) - dlg:set_parent(this) - this:hide() - dlg:show() + local url = ("%s/packages/%s?protocol_version=%d"):format( + core.settings:get("contentdb_url"), package.id, core.get_max_supp_proto()) + core.open_url(url) return true end end diff --git a/builtin/mainmenu/tab_credits.lua b/builtin/mainmenu/tab_credits.lua index 962d2a3b4..c2b7e503a 100644 --- a/builtin/mainmenu/tab_credits.lua +++ b/builtin/mainmenu/tab_credits.lua @@ -101,8 +101,8 @@ return { local logofile = defaulttexturedir .. "logo.png" local version = core.get_version() return "image[0.5,1;" .. core.formspec_escape(logofile) .. "]" .. - "label[0.5,3.2;" .. version.project .. " " .. version.string .. "]" .. - "label[0.5,3.5;http://minetest.net]" .. + "label[0.5,2.8;" .. version.project .. " " .. version.string .. "]" .. + "button[0.5,3;2,2;homepage;minetest.net]" .. "tablecolumns[color;text]" .. "tableoptions[background=#00000000;highlight=#00000000;border=false]" .. "table[3.5,-0.25;8.5,6.05;list_credits;" .. @@ -115,5 +115,10 @@ return { "#FFFF00," .. fgettext("Previous Contributors") .. ",," .. buildCreditList(previous_contributors) .. "," .. ";1]" - end + end, + cbf_button_handler = function(this, fields, name, tabdata) + if fields.homepage then + core.open_url("https://www.minetest.net") + end + end, } diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index 8f5460acb..485c50110 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -234,6 +234,11 @@ core.get_min_supp_proto() core.get_max_supp_proto() ^ returns the maximum supported network protocol version +Other: +core.open_url(url) +^ opens the URL in a web browser, returns false on failure. +^ Must begin with http:// or https:// + Async: core.handle_async(async_job,parameters,finished) ^ execute a function asynchronously diff --git a/src/porting.cpp b/src/porting.cpp index c0381ad06..ef1640467 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -33,22 +33,28 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include + #include #endif #if !defined(_WIN32) #include #include + #if !defined(__ANDROID__) + #include + #endif #endif #if defined(__hpux) #define _PSTAT64 #include #endif +#if defined(__ANDROID__) + #include "porting_android.h" +#endif #include "config.h" #include "debug.h" #include "filesys.h" #include "log.h" #include "util/string.h" -#include "settings.h" #include #include #include @@ -697,6 +703,28 @@ int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...) return c; } +bool openURL(const std::string &url) +{ + if ((url.substr(0, 7) != "http://" && url.substr(0, 8) != "https://") || + url.find_first_of("\r\n") != std::string::npos) { + errorstream << "Invalid url: " << url << std::endl; + return false; + } + +#if defined(_WIN32) + return (intptr_t)ShellExecuteA(NULL, NULL, url.c_str(), NULL, NULL, SW_SHOWNORMAL) > 32; +#elif defined(__ANDROID__) + openURLAndroid(url); + return true; +#elif defined(__APPLE__) + const char *argv[] = {"open", url.c_str(), NULL}; + return posix_spawnp(NULL, "open", NULL, NULL, (char**)argv, environ) == 0; +#else + const char *argv[] = {"xdg-open", url.c_str(), NULL}; + return posix_spawnp(NULL, "xdg-open", NULL, NULL, (char**)argv, environ) == 0; +#endif +} + // Load performance counter frequency only once at startup #ifdef _WIN32 diff --git a/src/porting.h b/src/porting.h index 4d30a5970..f50f0a950 100644 --- a/src/porting.h +++ b/src/porting.h @@ -329,6 +329,9 @@ bool secure_rand_fill_buf(void *buf, size_t len); void attachOrCreateConsole(); int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...); + +bool openURL(const std::string &url); + } // namespace porting #ifdef __ANDROID__ diff --git a/src/porting_android.cpp b/src/porting_android.cpp index 2c91df235..41b521ec2 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -213,6 +213,18 @@ void showInputDialog(const std::string &acceptButton, const std::string &hint, jacceptButton, jhint, jcurrent, jeditType); } +void openURLAndroid(const std::string &url) +{ + jmethodID url_open = jnienv->GetMethodID(nativeActivity, "openURL", + "(Ljava/lang/String;)V"); + + FATAL_ERROR_IF(url_open == nullptr, + "porting::openURLAndroid unable to find java openURL method"); + + jstring jurl = jnienv->NewStringUTF(url.c_str()); + jnienv->CallVoidMethod(app_global->activity->clazz, url_open, jurl); +} + int getInputDialogState() { jmethodID dialogstate = jnienv->GetMethodID(nativeActivity, diff --git a/src/porting_android.h b/src/porting_android.h index 42f90b60b..6eb054041 100644 --- a/src/porting_android.h +++ b/src/porting_android.h @@ -58,6 +58,8 @@ void initializePathsAndroid(); void showInputDialog(const std::string &acceptButton, const std::string &hint, const std::string ¤t, int editType); +void openURLAndroid(const std::string &url); + /** * WORKAROUND for not working callbacks from java -> c++ * get current state of input dialog diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index a76e9f079..f32c477c2 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -1063,6 +1063,14 @@ int ModApiMainMenu::l_get_max_supp_proto(lua_State *L) return 1; } +/******************************************************************************/ +int ModApiMainMenu::l_open_url(lua_State *L) +{ + std::string url = luaL_checkstring(L, 1); + lua_pushboolean(L, porting::openURL(url)); + return 1; +} + /******************************************************************************/ int ModApiMainMenu::l_do_async_callback(lua_State *L) { @@ -1125,6 +1133,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(get_screen_info); API_FCT(get_min_supp_proto); API_FCT(get_max_supp_proto); + API_FCT(open_url); API_FCT(do_async_callback); } diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index b2ca49320..5a16b3bfe 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -145,6 +145,9 @@ private: static int l_get_max_supp_proto(lua_State *L); + // other + static int l_open_url(lua_State *L); + // async static int l_do_async_callback(lua_State *L); -- cgit v1.2.3 From be38a44ffe2355d909774923a517d8b37f932dfe Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 15 May 2020 15:12:37 +0200 Subject: Client: Add sum and average to packetcounter --- src/client/client.cpp | 14 ++++++++++++-- src/client/client.h | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/client/client.cpp b/src/client/client.cpp index 941fc203d..c03c062c6 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -64,6 +64,14 @@ extern gui::IGUIEnvironment* guienv; Utility classes */ +u32 PacketCounter::sum() const +{ + u32 n = 0; + for (const auto &it : m_packets) + n += it.second; + return n; +} + void PacketCounter::print(std::ostream &o) const { for (const auto &it : m_packets) { @@ -357,9 +365,11 @@ void Client::step(float dtime) if(counter <= 0.0f) { counter = 30.0f; + u32 sum = m_packetcounter.sum(); + float avg = sum / counter; - infostream << "Client packetcounter (" << m_packetcounter_timer - << "s):"< m_packets; + std::map m_packets; }; class ClientScripting; -- cgit v1.2.3 From 52430d34d33f0ae3ff188a009307bf0a86048dfe Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 15 May 2020 15:42:33 +0200 Subject: content_mapblock: Move static initialization out of functions --- src/client/content_mapblock.cpp | 54 +++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 9b4fd221e..bf1b4c7d6 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -512,8 +512,7 @@ f32 MapblockMeshGenerator::getCornerLevel(int i, int k) return 0; } -void MapblockMeshGenerator::drawLiquidSides() -{ +namespace { struct LiquidFaceDesc { v3s16 dir; // XZ v3s16 p[2]; // XZ only; 1 means +, 0 means - @@ -521,20 +520,23 @@ void MapblockMeshGenerator::drawLiquidSides() struct UV { int u, v; }; - static const LiquidFaceDesc base_faces[4] = { + static const LiquidFaceDesc liquid_base_faces[4] = { {v3s16( 1, 0, 0), {v3s16(1, 0, 1), v3s16(1, 0, 0)}}, {v3s16(-1, 0, 0), {v3s16(0, 0, 0), v3s16(0, 0, 1)}}, {v3s16( 0, 0, 1), {v3s16(0, 0, 1), v3s16(1, 0, 1)}}, {v3s16( 0, 0, -1), {v3s16(1, 0, 0), v3s16(0, 0, 0)}}, }; - static const UV base_vertices[4] = { + static const UV liquid_base_vertices[4] = { {0, 1}, {1, 1}, {1, 0}, {0, 0} }; +} - for (const auto &face : base_faces) { +void MapblockMeshGenerator::drawLiquidSides() +{ + for (const auto &face : liquid_base_faces) { const NeighborData &neighbor = liquid_neighbors[face.dir.Z + 1][face.dir.X + 1]; // No face between nodes of the same liquid, unless there is node @@ -554,7 +556,7 @@ void MapblockMeshGenerator::drawLiquidSides() video::S3DVertex vertices[4]; for (int j = 0; j < 4; j++) { - const UV &vertex = base_vertices[j]; + const UV &vertex = liquid_base_vertices[j]; const v3s16 &base = face.p[vertex.u]; float v = vertex.v; @@ -1193,15 +1195,14 @@ bool MapblockMeshGenerator::isSameRail(v3s16 dir) (def2.getGroup(raillike_groupname) == raillike_group)); } -void MapblockMeshGenerator::drawRaillikeNode() -{ - static const v3s16 direction[4] = { +namespace { + static const v3s16 rail_direction[4] = { v3s16( 0, 0, 1), v3s16( 0, 0, -1), v3s16(-1, 0, 0), v3s16( 1, 0, 0), }; - static const int slope_angle[4] = {0, 180, 90, -90}; + static const int rail_slope_angle[4] = {0, 180, 90, -90}; enum RailTile { straight, @@ -1214,8 +1215,8 @@ void MapblockMeshGenerator::drawRaillikeNode() int angle; }; static const RailDesc rail_kinds[16] = { - // +x -x -z +z - //------------- + // +x -x -z +z + //------------- {straight, 0}, // . . . . {straight, 0}, // . . . +Z {straight, 0}, // . . -Z . @@ -1233,7 +1234,10 @@ void MapblockMeshGenerator::drawRaillikeNode() {junction, 270}, // +X -X -Z . { cross, 0}, // +X -X -Z +Z }; +} +void MapblockMeshGenerator::drawRaillikeNode() +{ raillike_group = nodedef->get(n).getGroup(raillike_groupname); int code = 0; @@ -1241,14 +1245,14 @@ void MapblockMeshGenerator::drawRaillikeNode() int tile_index; bool sloped = false; for (int dir = 0; dir < 4; dir++) { - bool rail_above = isSameRail(direction[dir] + v3s16(0, 1, 0)); + bool rail_above = isSameRail(rail_direction[dir] + v3s16(0, 1, 0)); if (rail_above) { sloped = true; - angle = slope_angle[dir]; + angle = rail_slope_angle[dir]; } if (rail_above || - isSameRail(direction[dir]) || - isSameRail(direction[dir] + v3s16(0, -1, 0))) + isSameRail(rail_direction[dir]) || + isSameRail(rail_direction[dir] + v3s16(0, -1, 0))) code |= 1 << dir; } @@ -1276,9 +1280,8 @@ void MapblockMeshGenerator::drawRaillikeNode() drawQuad(vertices); } -void MapblockMeshGenerator::drawNodeboxNode() -{ - static const v3s16 tile_dirs[6] = { +namespace { + static const v3s16 nodebox_tile_dirs[6] = { v3s16(0, 1, 0), v3s16(0, -1, 0), v3s16(1, 0, 0), @@ -1288,7 +1291,7 @@ void MapblockMeshGenerator::drawNodeboxNode() }; // we have this order for some reason... - static const v3s16 connection_dirs[6] = { + static const v3s16 nodebox_connection_dirs[6] = { v3s16( 0, 1, 0), // top v3s16( 0, -1, 0), // bottom v3s16( 0, 0, -1), // front @@ -1296,19 +1299,22 @@ void MapblockMeshGenerator::drawNodeboxNode() v3s16( 0, 0, 1), // back v3s16( 1, 0, 0), // right }; +} +void MapblockMeshGenerator::drawNodeboxNode() +{ TileSpec tiles[6]; for (int face = 0; face < 6; face++) { // Handles facedir rotation for textures - getTile(tile_dirs[face], &tiles[face]); + getTile(nodebox_tile_dirs[face], &tiles[face]); } // locate possible neighboring nodes to connect to - int neighbors_set = 0; + u8 neighbors_set = 0; if (f->node_box.type == NODEBOX_CONNECTED) { for (int dir = 0; dir != 6; dir++) { - int flag = 1 << dir; - v3s16 p2 = blockpos_nodes + p + connection_dirs[dir]; + u8 flag = 1 << dir; + v3s16 p2 = blockpos_nodes + p + nodebox_connection_dirs[dir]; MapNode n2 = data->m_vmanip.getNodeNoEx(p2); if (nodedef->nodeboxConnects(n, n2, flag)) neighbors_set |= flag; -- cgit v1.2.3 From 0fc51db7722f9aa1e0aa2dacade6041c932b0731 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 18 May 2020 23:23:25 +0200 Subject: Add missing sao->isGone() checks fixes #9883 --- src/collision.cpp | 3 ++- src/serverenvironment.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/collision.cpp b/src/collision.cpp index 06ef820c5..d85a56884 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -397,7 +397,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, // we directly use the callback to populate the result to prevent // a useless result loop here auto include_obj_cb = [self, &objects] (ServerActiveObject *obj) { - if (!self || (self != obj && self != obj->getParent())) { + if (!obj->isGone() && + (!self || (self != obj && self != obj->getParent()))) { objects.push_back((ActiveObject *)obj); } return false; diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 6bf7399cf..d485c32e8 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1623,6 +1623,8 @@ void ServerEnvironment::getSelectedActiveObjects( const v3f line_vector = shootline_on_map.getVector(); for (auto obj : objs) { + if (obj->isGone()) + continue; aabb3f selection_box; if (!obj->getSelectionBox(&selection_box)) continue; -- cgit v1.2.3 From 7d3972a5049324f776ab008894c34569641f0073 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 19 May 2020 10:10:39 -0700 Subject: Add ability to scale HUD text (#9814) Add 'size' property to HUD text elements that is used for relative font size calculations. --- doc/lua_api.txt | 2 ++ src/client/hud.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 07758c237..9c7c42436 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1356,6 +1356,8 @@ Displays text on the HUD. text. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on. * `alignment`: The alignment of the text. * `offset`: offset in pixels from position. +* `size`: size of the text. + The player-set font size is multiplied by size.x (y value isn't used). ### `statbar` diff --git a/src/client/hud.cpp b/src/client/hud.cpp index f8f712762..4edc229b2 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -319,16 +319,21 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) floor(e->pos.Y * (float) m_screensize.Y + 0.5)); switch (e->type) { case HUD_ELEM_TEXT: { + irr::gui::IGUIFont *textfont = font; + if (e->size.X > 0) + textfont = g_fontengine->getFont( + e->size.X * g_fontengine->getDefaultFontSize()); + video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); core::rect size(0, 0, e->scale.X, text_height * e->scale.Y); std::wstring text = unescape_translate(utf8_to_wide(e->text)); - core::dimension2d textsize = font->getDimension(text.c_str()); + core::dimension2d textsize = textfont->getDimension(text.c_str()); v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2), (e->align.Y - 1.0) * (textsize.Height / 2)); v2s32 offs(e->offset.X, e->offset.Y); - font->draw(text.c_str(), size + pos + offset + offs, color); + textfont->draw(text.c_str(), size + pos + offset + offs, color); break; } case HUD_ELEM_STATBAR: { v2s32 offs(e->offset.X, e->offset.Y); -- cgit v1.2.3 From c94d37827dd3a8be9dcc59bb693032ba7ea07922 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 19 May 2020 21:08:37 +0200 Subject: Rework functionality of leveled nodes (#9852) Co-authored-by: sfan5 Co-authored-by: SmallJoker --- builtin/game/falling.lua | 58 ++++++++++++++++++++++++++++++----------- doc/lua_api.txt | 10 ++++--- src/mapnode.cpp | 21 ++++++++------- src/mapnode.h | 6 ++--- src/nodedef.cpp | 6 +++++ src/nodedef.h | 4 ++- src/script/common/c_content.cpp | 4 +++ src/script/lua_api/l_env.cpp | 4 +-- 8 files changed, 79 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 7037ae885..cdbb13acc 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -109,6 +109,7 @@ core.register_entity(":__builtin:falling_node", { if core.is_colored_paramtype(def.paramtype2) then itemstring = core.itemstring_with_palette(itemstring, node.param2) end + -- FIXME: solution needed for paramtype2 == "leveled" local vsize if def.visual_scale then local s = def.visual_scale * SCALE @@ -122,6 +123,24 @@ core.register_entity(":__builtin:falling_node", { }) end + -- Set collision box (certain nodeboxes only for now) + local nb_types = {fixed=true, leveled=true, connected=true} + if def.drawtype == "nodebox" and def.node_box and + nb_types[def.node_box.type] then + local box = table.copy(def.node_box.fixed) + if type(box[1]) == "table" then + box = #box == 1 and box[1] or nil -- We can only use a single box + end + if box then + if def.paramtype2 == "leveled" and (self.node.level or 0) > 0 then + box[5] = -0.5 + self.node.level / 64 + end + self.object:set_properties({ + collisionbox = box + }) + end + end + -- Rotate entity if def.drawtype == "torchlike" then self.object:set_yaw(math.pi*0.25) @@ -196,13 +215,16 @@ core.register_entity(":__builtin:falling_node", { try_place = function(self, bcp, bcn) local bcd = core.registered_nodes[bcn.name] -- Add levels if dropped on same leveled node - if bcd and bcd.leveled and + if bcd and bcd.paramtype2 == "leveled" and bcn.name == self.node.name then local addlevel = self.node.level - if not addlevel or addlevel <= 0 then + if (addlevel or 0) <= 0 then addlevel = bcd.leveled end - if core.add_node_level(bcp, addlevel) == 0 then + if core.add_node_level(bcp, addlevel) < addlevel then + return true + elseif bcd.buildable_to then + -- Node level has already reached max, don't place anything return true end end @@ -351,6 +373,7 @@ local function convert_to_falling_node(pos, node) if not obj then return false end + -- remember node level, the entities' set_node() uses this node.level = core.get_node_level(pos) local meta = core.get_meta(pos) local metatable = meta and meta:to_table() or {} @@ -436,18 +459,23 @@ function core.check_single_for_falling(p) -- Only spawn falling node if node below is loaded local n_bottom = core.get_node_or_nil(p_bottom) local d_bottom = n_bottom and core.registered_nodes[n_bottom.name] - if d_bottom and - - (core.get_item_group(n.name, "float") == 0 or - d_bottom.liquidtype == "none") and - - (n.name ~= n_bottom.name or (d_bottom.leveled and - core.get_node_level(p_bottom) < - core.get_node_max_level(p_bottom))) and - - (not d_bottom.walkable or d_bottom.buildable_to) then - convert_to_falling_node(p, n) - return true + if d_bottom then + local same = n.name == n_bottom.name + -- Let leveled nodes fall if it can merge with the bottom node + if same and d_bottom.paramtype2 == "leveled" and + core.get_node_level(p_bottom) < + core.get_node_max_level(p_bottom) then + convert_to_falling_node(p, n) + return true + end + -- Otherwise only if the bottom node is considered "fall through" + if not same and + (not d_bottom.walkable or d_bottom.buildable_to) and + (core.get_item_group(n.name, "float") == 0 or + d_bottom.liquidtype == "none") then + convert_to_falling_node(p, n) + return true + end end end diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 9c7c42436..8b7c412ab 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4882,7 +4882,7 @@ Environment access * `minetest.add_node_level(pos, level)` * increase level of leveled node by level, default `level` equals `1` * if `totallevel > maxlevel`, returns rest (`total-max`) - * can be negative for decreasing + * `level` must be between -127 and 127 * `minetest.fix_light(pos1, pos2)`: returns `true`/`false` * resets the light in a cuboid-shaped part of the map and removes lighting bugs. @@ -7012,11 +7012,15 @@ Used by `minetest.register_node`. -- If true, a new liquid source can be created by placing two or more -- sources nearby - leveled = 16, + leveled = 0, -- Only valid for "nodebox" drawtype with 'type = "leveled"'. -- Allows defining the nodebox height without using param2. -- The nodebox height is 'leveled' / 64 nodes. - -- The maximum value of 'leveled' is 127. + -- The maximum value of 'leveled' is `leveled_max`. + + leveled_max = 127, + -- Maximum value for `leveled` (0-127), enforced in + -- `minetest.set_node_level` and `minetest.add_node_level`. liquid_range = 8, -- Number of flowing nodes around source (max. 8) diff --git a/src/mapnode.cpp b/src/mapnode.cpp index bf7e79a71..24d62b504 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -584,7 +584,7 @@ u8 MapNode::getMaxLevel(const NodeDefManager *nodemgr) const if( f.liquid_type == LIQUID_FLOWING || f.param_type_2 == CPT2_FLOWINGLIQUID) return LIQUID_LEVEL_MAX; if(f.leveled || f.param_type_2 == CPT2_LEVELED) - return LEVELED_MAX; + return f.leveled_max; return 0; } @@ -603,14 +603,15 @@ u8 MapNode::getLevel(const NodeDefManager *nodemgr) const if (level) return level; } - if (f.leveled > LEVELED_MAX) - return LEVELED_MAX; + // Return static value from nodedef if param2 isn't used for level + if (f.leveled > f.leveled_max) + return f.leveled_max; return f.leveled; } -u8 MapNode::setLevel(const NodeDefManager *nodemgr, s8 level) +s8 MapNode::setLevel(const NodeDefManager *nodemgr, s16 level) { - u8 rest = 0; + s8 rest = 0; const ContentFeatures &f = nodemgr->get(*this); if (f.param_type_2 == CPT2_FLOWINGLIQUID || f.liquid_type == LIQUID_FLOWING @@ -631,18 +632,18 @@ u8 MapNode::setLevel(const NodeDefManager *nodemgr, s8 level) if (level < 0) { // zero means default for a leveled nodebox rest = level; level = 0; - } else if (level > LEVELED_MAX) { - rest = level - LEVELED_MAX; - level = LEVELED_MAX; + } else if (level > f.leveled_max) { + rest = level - f.leveled_max; + level = f.leveled_max; } setParam2((level & LEVELED_MASK) | (getParam2() & ~LEVELED_MASK)); } return rest; } -u8 MapNode::addLevel(const NodeDefManager *nodemgr, s8 add) +s8 MapNode::addLevel(const NodeDefManager *nodemgr, s16 add) { - s8 level = getLevel(nodemgr); + s16 level = getLevel(nodemgr); level += add; return setLevel(nodemgr, level); } diff --git a/src/mapnode.h b/src/mapnode.h index 7a3d30ddc..32ac1b4f6 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -268,12 +268,12 @@ struct MapNode std::vector *boxes, u8 neighbors = 0) const; /* - Liquid helpers + Liquid/leveled helpers */ u8 getMaxLevel(const NodeDefManager *nodemgr) const; u8 getLevel(const NodeDefManager *nodemgr) const; - u8 setLevel(const NodeDefManager *nodemgr, s8 level = 1); - u8 addLevel(const NodeDefManager *nodemgr, s8 add = 1); + s8 setLevel(const NodeDefManager *nodemgr, s16 level = 1); + s8 addLevel(const NodeDefManager *nodemgr, s16 add = 1); /* Serialization functions diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 65199830f..b8211fceb 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -368,6 +368,7 @@ void ContentFeatures::reset() floodable = false; rightclickable = true; leveled = 0; + leveled_max = LEVELED_MAX; liquid_type = LIQUID_NONE; liquid_alternative_flowing = ""; liquid_alternative_source = ""; @@ -478,6 +479,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const writeU8(os, legacy_wallmounted); os << serializeString(node_dig_prediction); + writeU8(os, leveled_max); } void ContentFeatures::correctAlpha(TileDef *tiles, int length) @@ -586,6 +588,10 @@ void ContentFeatures::deSerialize(std::istream &is) try { node_dig_prediction = deSerializeString(is); + u8 tmp_leveled_max = readU8(is); + if (is.eof()) /* readU8 doesn't throw exceptions so we have to do this */ + throw SerializationError(""); + leveled_max = tmp_leveled_max; } catch(SerializationError &e) {}; } diff --git a/src/nodedef.h b/src/nodedef.h index 0fce6eab1..497e7ee0e 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -326,8 +326,10 @@ struct ContentFeatures std::vector connects_to_ids; // Post effect color, drawn when the camera is inside the node. video::SColor post_effect_color; - // Flowing liquid or snow, value = default level + // Flowing liquid or leveled nodebox, value = default level u8 leveled; + // Maximum value for leveled nodes + u8 leveled_max; // --- LIGHTING-RELATED --- diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index de9634c42..116a59c09 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -694,6 +694,8 @@ ContentFeatures read_content_features(lua_State *L, int index) f.liquid_range = getintfield_default(L, index, "liquid_range", f.liquid_range); f.leveled = getintfield_default(L, index, "leveled", f.leveled); + f.leveled_max = getintfield_default(L, index, + "leveled_max", f.leveled_max); getboolfield(L, index, "liquid_renewable", f.liquid_renewable); f.drowning = getintfield_default(L, index, @@ -860,6 +862,8 @@ void push_content_features(lua_State *L, const ContentFeatures &c) lua_setfield(L, -2, "post_effect_color"); lua_pushnumber(L, c.leveled); lua_setfield(L, -2, "leveled"); + lua_pushnumber(L, c.leveled_max); + lua_setfield(L, -2, "leveled_max"); lua_pushboolean(L, c.sunlight_propagates); lua_setfield(L, -2, "sunlight_propagates"); lua_pushnumber(L, c.light_source); diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index b8a8a5ce1..89ec9dc7e 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -529,13 +529,13 @@ int ModApiEnvMod::l_set_node_level(lua_State *L) // add_node_level(pos, level) // pos = {x=num, y=num, z=num} -// level: 0..63 +// level: -127..127 int ModApiEnvMod::l_add_node_level(lua_State *L) { GET_ENV_PTR; v3s16 pos = read_v3s16(L, 1); - u8 level = 1; + s16 level = 1; if(lua_isnumber(L, 2)) level = lua_tonumber(L, 2); MapNode n = env->getMap().getNode(pos); -- cgit v1.2.3 From 732c8008f495bc344957bd0ccbd4010adb939207 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 20 May 2020 20:13:16 +0200 Subject: CSM: Fix crashing minetest.get_item_def() fixes #9884 --- src/script/common/c_content.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 116a59c09..2157d087d 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -164,7 +164,7 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i) lua_setfield(L, -2, "usable"); lua_pushboolean(L, i.liquids_pointable); lua_setfield(L, -2, "liquids_pointable"); - if (i.type == ITEM_TOOL) { + if (i.tool_capabilities) { push_tool_capabilities(L, *i.tool_capabilities); lua_setfield(L, -2, "tool_capabilities"); } -- cgit v1.2.3 From c47a680db7f3c2f241cc444a1257607492872412 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 19 May 2020 20:45:02 +0200 Subject: Stop wasting memory on identical textures when texture filtering is disabled --- src/client/tile.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 0fa7a4ae2..d03588b2b 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -668,7 +668,14 @@ video::ITexture* TextureSource::getTexture(const std::string &name, u32 *id) video::ITexture* TextureSource::getTextureForMesh(const std::string &name, u32 *id) { - return getTexture(name + "^[applyfiltersformesh", id); + static thread_local bool filter_needed = + g_settings->getBool("texture_clean_transparent") || + ((m_setting_trilinear_filter || m_setting_bilinear_filter) && + g_settings->getS32("texture_min_size") > 1); + // Avoid duplicating texture if it won't actually change + if (filter_needed) + return getTexture(name + "^[applyfiltersformesh", id); + return getTexture(name, id); } Palette* TextureSource::getPalette(const std::string &name) @@ -1623,6 +1630,9 @@ bool TextureSource::generateImagePart(std::string part_of_name, */ else if (str_starts_with(part_of_name, "[applyfiltersformesh")) { + /* IMPORTANT: When changing this, getTextureForMesh() needs to be + * updated too. */ + // Apply the "clean transparent" filter, if configured. if (g_settings->getBool("texture_clean_transparent")) imageCleanTransparent(baseimg, 127); -- cgit v1.2.3 From 42fcfb75e85523a2fa5d99a453c2fabc2c04c0f6 Mon Sep 17 00:00:00 2001 From: Paramat Date: Wed, 20 May 2020 22:16:14 +0100 Subject: Allow more than 255 biomes, document new maximum (#9855) Change biomemap data type from u8 to u16. New technical (not practical) maximum is 65535 biomes. --- doc/lua_api.txt | 4 ++++ src/mapgen/cavegen.cpp | 8 ++++---- src/mapgen/cavegen.h | 8 +++++--- src/mapgen/mapgen.h | 8 ++++---- src/mapgen/mg_biome.h | 6 +++--- src/mapgen/mg_decoration.cpp | 6 ++---- src/mapgen/mg_decoration.h | 4 +++- src/mapgen/mg_ore.cpp | 28 ++++++++++++++-------------- src/mapgen/mg_ore.h | 22 ++++++++++++---------- src/script/lua_api/l_mapgen.cpp | 4 ++-- src/script/lua_api/l_mapgen.h | 2 ++ 11 files changed, 55 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 8b7c412ab..0101bd4cf 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -7443,6 +7443,10 @@ Biome definition Used by `minetest.register_biome`. +The maximum number of biomes that can be used is 65535. However, using an +excessive number of biomes will slow down map generation. Depending on desired +performance and computing power the practical limit is much lower. + { name = "tundra", diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp index a9df4506f..340079821 100644 --- a/src/mapgen/cavegen.cpp +++ b/src/mapgen/cavegen.cpp @@ -1,8 +1,8 @@ /* Minetest -Copyright (C) 2010-2018 celeron55, Perttu Ahola -Copyright (C) 2010-2018 kwolekr, Ryan Kwolek -Copyright (C) 2015-2018 paramat +Copyright (C) 2010-2020 celeron55, Perttu Ahola +Copyright (C) 2015-2020 paramat +Copyright (C) 2010-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -69,7 +69,7 @@ CavesNoiseIntersection::~CavesNoiseIntersection() void CavesNoiseIntersection::generateCaves(MMVManip *vm, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { assert(vm); assert(biomemap); diff --git a/src/mapgen/cavegen.h b/src/mapgen/cavegen.h index ff09f9423..d678d365b 100644 --- a/src/mapgen/cavegen.h +++ b/src/mapgen/cavegen.h @@ -1,7 +1,7 @@ /* Minetest -Copyright (C) 2010-2018 kwolekr, Ryan Kwolek -Copyright (C) 2015-2018 paramat +Copyright (C) 2015-2020 paramat +Copyright (C) 2010-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1 +typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include + class GenerateNotifier; /* @@ -44,7 +46,7 @@ public: NoiseParams *np_cave2, s32 seed, float cave_width); ~CavesNoiseIntersection(); - void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, u8 *biomemap); + void generateCaves(MMVManip *vm, v3s16 nmin, v3s16 nmax, biome_t *biomemap); private: const NodeDefManager *m_ndef; diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index 7845c5349..a92b3b0d0 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -1,8 +1,8 @@ /* Minetest -Copyright (C) 2010-2018 celeron55, Perttu Ahola -Copyright (C) 2013-2018 kwolekr, Ryan Kwolek -Copyright (C) 2015-2018 paramat +Copyright (C) 2010-2020 celeron55, Perttu Ahola +Copyright (C) 2015-2020 paramat +Copyright (C) 2013-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MG_DECORATIONS 0x20 #define MG_BIOMES 0x40 -typedef u8 biome_t; // copy from mg_biome.h to avoid an unnecessary include +typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include class Settings; class MMVManip; diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index 57f4aa20d..be4cfea4d 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -1,7 +1,7 @@ /* Minetest -Copyright (C) 2014-2018 kwolekr, Ryan Kwolek -Copyright (C) 2014-2018 paramat +Copyright (C) 2014-2020 paramat +Copyright (C) 2014-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,7 +32,7 @@ class BiomeManager; //// Biome //// -typedef u8 biome_t; +typedef u16 biome_t; #define BIOME_NONE ((biome_t)0) diff --git a/src/mapgen/mg_decoration.cpp b/src/mapgen/mg_decoration.cpp index a9b67d239..a4cada396 100644 --- a/src/mapgen/mg_decoration.cpp +++ b/src/mapgen/mg_decoration.cpp @@ -206,8 +206,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) // All-surfaces decorations // Check biome of column if (mg->biomemap && !biomes.empty()) { - std::unordered_set::const_iterator iter = - biomes.find(mg->biomemap[mapindex]); + auto iter = biomes.find(mg->biomemap[mapindex]); if (iter == biomes.end()) continue; } @@ -259,8 +258,7 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) continue; if (mg->biomemap && !biomes.empty()) { - std::unordered_set::const_iterator iter = - biomes.find(mg->biomemap[mapindex]); + auto iter = biomes.find(mg->biomemap[mapindex]); if (iter == biomes.end()) continue; } diff --git a/src/mapgen/mg_decoration.h b/src/mapgen/mg_decoration.h index 1f9eb4510..1ea02a527 100644 --- a/src/mapgen/mg_decoration.h +++ b/src/mapgen/mg_decoration.h @@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" #include "nodedef.h" +typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include + class Mapgen; class MMVManip; class PcgRandom; @@ -72,7 +74,7 @@ public: s16 nspawnby; s16 place_offset_y = 0; - std::unordered_set biomes; + std::unordered_set biomes; protected: void cloneTo(Decoration *def) const; diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp index db647f82b..b50ed6a32 100644 --- a/src/mapgen/mg_ore.cpp +++ b/src/mapgen/mg_ore.cpp @@ -1,7 +1,7 @@ /* Minetest -Copyright (C) 2014-2018 kwolekr, Ryan Kwolek -Copyright (C) 2015-2018 paramat +Copyright (C) 2015-2020 paramat +Copyright (C) 2014-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -146,7 +146,7 @@ ObjDef *OreScatter::clone() const void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { PcgRandom pr(blockseed); MapNode n_ore(c_ore, 0, ore_param2); @@ -170,7 +170,7 @@ void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, if (biomemap && !biomes.empty()) { u32 index = sizex * (z0 - nmin.Z) + (x0 - nmin.X); - std::unordered_set::const_iterator it = biomes.find(biomemap[index]); + auto it = biomes.find(biomemap[index]); if (it == biomes.end()) continue; } @@ -208,7 +208,7 @@ ObjDef *OreSheet::clone() const void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -237,7 +237,7 @@ void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, continue; if (biomemap && !biomes.empty()) { - std::unordered_set::const_iterator it = biomes.find(biomemap[index]); + auto it = biomes.find(biomemap[index]); if (it == biomes.end()) continue; } @@ -285,7 +285,7 @@ ObjDef *OrePuff::clone() const void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -312,7 +312,7 @@ void OrePuff::generate(MMVManip *vm, int mapseed, u32 blockseed, continue; if (biomemap && !biomes.empty()) { - std::unordered_set::const_iterator it = biomes.find(biomemap[index]); + auto it = biomes.find(biomemap[index]); if (it == biomes.end()) continue; } @@ -366,7 +366,7 @@ ObjDef *OreBlob::clone() const void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 2404); MapNode n_ore(c_ore, 0, ore_param2); @@ -388,7 +388,7 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, if (biomemap && !biomes.empty()) { u32 bmapidx = sizex * (z0 - nmin.Z) + (x0 - nmin.X); - std::unordered_set::const_iterator it = biomes.find(biomemap[bmapidx]); + auto it = biomes.find(biomemap[bmapidx]); if (it == biomes.end()) continue; } @@ -451,7 +451,7 @@ ObjDef *OreVein::clone() const void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 520); MapNode n_ore(c_ore, 0, ore_param2); @@ -485,7 +485,7 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, if (biomemap && !biomes.empty()) { u32 bmapidx = sizex * (z - nmin.Z) + (x - nmin.X); - std::unordered_set::const_iterator it = biomes.find(biomemap[bmapidx]); + auto it = biomes.find(biomemap[bmapidx]); if (it == biomes.end()) continue; } @@ -532,7 +532,7 @@ ObjDef *OreStratum::clone() const void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) + v3s16 nmin, v3s16 nmax, biome_t *biomemap) { PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -560,7 +560,7 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, for (int z = nmin.Z; z <= nmax.Z; z++) for (int x = nmin.X; x <= nmax.X; x++, index++) { if (biomemap && !biomes.empty()) { - std::unordered_set::const_iterator it = biomes.find(biomemap[index]); + auto it = biomes.find(biomemap[index]); if (it == biomes.end()) continue; } diff --git a/src/mapgen/mg_ore.h b/src/mapgen/mg_ore.h index 213bdc964..76420fab4 100644 --- a/src/mapgen/mg_ore.h +++ b/src/mapgen/mg_ore.h @@ -1,7 +1,7 @@ /* Minetest -Copyright (C) 2014-2018 kwolekr, Ryan Kwolek -Copyright (C) 2015-2018 paramat +Copyright (C) 2015-2020 paramat +Copyright (C) 2014-2016 kwolekr, Ryan Kwolek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" #include "nodedef.h" +typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include + class Noise; class Mapgen; class MMVManip; @@ -64,7 +66,7 @@ public: float nthresh; // threshold for noise at which an ore is placed NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering) Noise *noise = nullptr; - std::unordered_set biomes; + std::unordered_set biomes; Ore() = default;; virtual ~Ore(); @@ -73,7 +75,7 @@ public: size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0; + v3s16 nmin, v3s16 nmax, biome_t *biomemap) = 0; protected: void cloneTo(Ore *def) const; @@ -86,7 +88,7 @@ public: ObjDef *clone() const; virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap); + v3s16 nmin, v3s16 nmax, biome_t *biomemap); }; class OreSheet : public Ore { @@ -100,7 +102,7 @@ public: float column_midpoint_factor; virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap); + v3s16 nmin, v3s16 nmax, biome_t *biomemap); }; class OrePuff : public Ore { @@ -118,7 +120,7 @@ public: virtual ~OrePuff(); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap); + v3s16 nmin, v3s16 nmax, biome_t *biomemap); }; class OreBlob : public Ore { @@ -128,7 +130,7 @@ public: ObjDef *clone() const; virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap); + v3s16 nmin, v3s16 nmax, biome_t *biomemap); }; class OreVein : public Ore { @@ -145,7 +147,7 @@ public: virtual ~OreVein(); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap); + v3s16 nmin, v3s16 nmax, biome_t *biomemap); }; class OreStratum : public Ore { @@ -162,7 +164,7 @@ public: virtual ~OreStratum(); virtual void generate(MMVManip *vm, int mapseed, u32 blockseed, - v3s16 nmin, v3s16 nmax, u8 *biomemap); + v3s16 nmin, v3s16 nmax, biome_t *biomemap); }; class OreManager : public ObjDefManager { diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 584085428..834938e56 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -97,7 +97,7 @@ Biome *get_or_load_biome(lua_State *L, int index, BiomeManager *biomemgr); Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef); size_t get_biome_list(lua_State *L, int index, - BiomeManager *biomemgr, std::unordered_set *biome_id_list); + BiomeManager *biomemgr, std::unordered_set *biome_id_list); Schematic *get_or_load_schematic(lua_State *L, int index, SchematicManager *schemmgr, StringMap *replace_names); @@ -425,7 +425,7 @@ Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef) size_t get_biome_list(lua_State *L, int index, - BiomeManager *biomemgr, std::unordered_set *biome_id_list) + BiomeManager *biomemgr, std::unordered_set *biome_id_list) { if (index < 0) index = lua_gettop(L) + 1 + index; diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 4a6a9ccf4..0bdc56fc5 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -21,6 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_base.h" +typedef u16 biome_t; // copy from mg_biome.h to avoid an unnecessary include + class ModApiMapgen : public ModApiBase { private: -- cgit v1.2.3 From 82e41378937378667cdbdda3ea9e8c1acb5822ea Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 21 May 2020 00:52:10 +0300 Subject: Cache liquid alternative IDs (#8053) --- src/client/content_mapblock.cpp | 4 ++-- src/map.cpp | 12 ++++++------ src/mapnode.cpp | 4 ++-- src/nodedef.cpp | 21 ++++++++++++++++++++- src/nodedef.h | 9 ++++++--- src/server.cpp | 4 ++-- 6 files changed, 38 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index bf1b4c7d6..50efd2e40 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -405,8 +405,8 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing() MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y + 1, p.Z)); MapNode nbottom = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(p.X, p.Y - 1, p.Z)); - c_flowing = nodedef->getId(f->liquid_alternative_flowing); - c_source = nodedef->getId(f->liquid_alternative_source); + c_flowing = f->liquid_alternative_flowing_id; + c_source = f->liquid_alternative_source_id; top_is_same_liquid = (ntop.getContent() == c_flowing) || (ntop.getContent() == c_source); draw_liquid_bottom = (nbottom.getContent() != c_flowing) && (nbottom.getContent() != c_source); if (draw_liquid_bottom) { diff --git a/src/map.cpp b/src/map.cpp index 5f1b984a4..677cbc869 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -568,7 +568,7 @@ void Map::transformLiquids(std::map &modified_blocks, switch (liquid_type) { case LIQUID_SOURCE: liquid_level = LIQUID_LEVEL_SOURCE; - liquid_kind = m_nodedef->getId(cf.liquid_alternative_flowing); + liquid_kind = cf.liquid_alternative_flowing_id; break; case LIQUID_FLOWING: liquid_level = (n0.param2 & LIQUID_LEVEL_MASK); @@ -641,8 +641,8 @@ void Map::transformLiquids(std::map &modified_blocks, case LIQUID_SOURCE: // if this node is not (yet) of a liquid type, choose the first liquid type we encounter if (liquid_kind == CONTENT_AIR) - liquid_kind = m_nodedef->getId(cfnb.liquid_alternative_flowing); - if (m_nodedef->getId(cfnb.liquid_alternative_flowing) != liquid_kind) { + liquid_kind = cfnb.liquid_alternative_flowing_id; + if (cfnb.liquid_alternative_flowing_id != liquid_kind) { neutrals[num_neutrals++] = nb; } else { // Do not count bottom source, it will screw things up @@ -653,8 +653,8 @@ void Map::transformLiquids(std::map &modified_blocks, case LIQUID_FLOWING: // if this node is not (yet) of a liquid type, choose the first liquid type we encounter if (liquid_kind == CONTENT_AIR) - liquid_kind = m_nodedef->getId(cfnb.liquid_alternative_flowing); - if (m_nodedef->getId(cfnb.liquid_alternative_flowing) != liquid_kind) { + liquid_kind = cfnb.liquid_alternative_flowing_id; + if (cfnb.liquid_alternative_flowing_id != liquid_kind) { neutrals[num_neutrals++] = nb; } else { flows[num_flows++] = nb; @@ -680,7 +680,7 @@ void Map::transformLiquids(std::map &modified_blocks, // liquid_kind will be set to either the flowing alternative of the node (if it's a liquid) // or the flowing alternative of the first of the surrounding sources (if it's air), so // it's perfectly safe to use liquid_kind here to determine the new node content. - new_node_content = m_nodedef->getId(m_nodedef->get(liquid_kind).liquid_alternative_source); + new_node_content = m_nodedef->get(liquid_kind).liquid_alternative_source_id; } else if (num_sources >= 1 && sources[0].t != NEIGHBOR_LOWER) { // liquid_kind is set properly, see above max_node_level = new_node_level = LIQUID_LEVEL_MAX; diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 24d62b504..dcf1f6d6e 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -622,10 +622,10 @@ s8 MapNode::setLevel(const NodeDefManager *nodemgr, s16 level) } if (level >= LIQUID_LEVEL_SOURCE) { rest = level - LIQUID_LEVEL_SOURCE; - setContent(nodemgr->getId(f.liquid_alternative_source)); + setContent(f.liquid_alternative_source_id); setParam2(0); } else { - setContent(nodemgr->getId(f.liquid_alternative_flowing)); + setContent(f.liquid_alternative_flowing_id); setParam2((level & LIQUID_LEVEL_MASK) | (getParam2() & ~LIQUID_LEVEL_MASK)); } } else if (f.param_type_2 == CPT2_LEVELED) { diff --git a/src/nodedef.cpp b/src/nodedef.cpp index b8211fceb..cb841e544 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -371,7 +371,9 @@ void ContentFeatures::reset() leveled_max = LEVELED_MAX; liquid_type = LIQUID_NONE; liquid_alternative_flowing = ""; + liquid_alternative_flowing_id = CONTENT_IGNORE; liquid_alternative_source = ""; + liquid_alternative_source_id = CONTENT_IGNORE; liquid_viscosity = 0; liquid_renewable = true; liquid_range = LIQUID_LEVEL_MAX+1; @@ -1444,6 +1446,10 @@ void NodeDefManager::deSerialize(std::istream &is) getNodeBoxUnion(f.selection_box, f, &m_selection_box_union); fixSelectionBoxIntUnion(); } + + // Since liquid_alternative_flowing_id and liquid_alternative_source_id + // are not sent, resolve them client-side too. + resolveCrossrefs(); } @@ -1504,15 +1510,28 @@ void NodeDefManager::resetNodeResolveState() m_pending_resolve_callbacks.clear(); } -void NodeDefManager::mapNodeboxConnections() +static void removeDupes(std::vector &list) +{ + std::sort(list.begin(), list.end()); + auto new_end = std::unique(list.begin(), list.end()); + list.erase(new_end, list.end()); +} + +void NodeDefManager::resolveCrossrefs() { for (ContentFeatures &f : m_content_features) { + if (f.liquid_type != LIQUID_NONE) { + f.liquid_alternative_flowing_id = getId(f.liquid_alternative_flowing); + f.liquid_alternative_source_id = getId(f.liquid_alternative_source); + continue; + } if (f.drawtype != NDT_NODEBOX || f.node_box.type != NODEBOX_CONNECTED) continue; for (const std::string &name : f.connects_to) { getIds(name, f.connects_to_ids); } + removeDupes(f.connects_to_ids); } } diff --git a/src/nodedef.h b/src/nodedef.h index 497e7ee0e..0992001e1 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -368,8 +368,10 @@ struct ContentFeatures enum LiquidType liquid_type; // If the content is liquid, this is the flowing version of the liquid. std::string liquid_alternative_flowing; + content_t liquid_alternative_flowing_id; // If the content is liquid, this is the source version of the liquid. std::string liquid_alternative_source; + content_t liquid_alternative_source_id; // Viscosity for fluid flow, ranging from 1 to 7, with // 1 giving almost instantaneous propagation and 7 being // the slowest possible @@ -428,7 +430,7 @@ struct ContentFeatures } bool sameLiquid(const ContentFeatures &f) const{ if(!isLiquid() || !f.isLiquid()) return false; - return (liquid_alternative_flowing == f.liquid_alternative_flowing); + return (liquid_alternative_flowing_id == f.liquid_alternative_flowing_id); } int getGroup(const std::string &group) const @@ -641,10 +643,11 @@ public: void resetNodeResolveState(); /*! - * Resolves the IDs to which connecting nodes connect from names. + * Resolves (caches the IDs) cross-references between nodes, + * like liquid alternatives. * Must be called after node registration has finished! */ - void mapNodeboxConnections(); + void resolveCrossrefs(); private: /*! diff --git a/src/server.cpp b/src/server.cpp index b28c30e1e..92870f972 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -412,8 +412,8 @@ void Server::init() // Perform pending node name resolutions m_nodedef->runNodeResolveCallbacks(); - // unmap node names for connected nodeboxes - m_nodedef->mapNodeboxConnections(); + // unmap node names in cross-references + m_nodedef->resolveCrossrefs(); // init the recipe hashes to speed up crafting m_craftdef->initHashes(this); -- cgit v1.2.3 From 1357ea1da25bf01acaf95d5f5419d4f83a84ed61 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 22 May 2020 13:23:25 +0200 Subject: Cleanup of particle & particlespawner structures and code (#9893) --- src/CMakeLists.txt | 1 + src/client/clientevent.h | 45 +---- src/client/particles.cpp | 333 ++++++++++++------------------- src/client/particles.h | 58 ++---- src/network/clientpackethandler.cpp | 136 ++++--------- src/particles.cpp | 53 +++++ src/particles.h | 73 +++++++ src/script/lua_api/l_particles.cpp | 186 ++++++++--------- src/script/lua_api/l_particles_local.cpp | 149 ++++++-------- src/server.cpp | 106 ++++------ src/server.h | 42 +--- 11 files changed, 502 insertions(+), 680 deletions(-) create mode 100644 src/particles.cpp create mode 100644 src/particles.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd68ceec9..3d6d1b0ea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -427,6 +427,7 @@ set(common_SRCS noise.cpp objdef.cpp object_properties.cpp + particles.cpp pathfinder.cpp player.cpp porting.cpp diff --git a/src/client/clientevent.h b/src/client/clientevent.h index 7f3984b03..9bd31efce 100644 --- a/src/client/clientevent.h +++ b/src/client/clientevent.h @@ -21,8 +21,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "irrlichttypes_bloated.h" -#include "hud.h" -#include "skyparams.h" + +struct ParticleParameters; +struct ParticleSpawnerParameters; +struct SkyboxParams; +struct SunParams; +struct MoonParams; +struct StarParams; enum ClientEventType : u8 { @@ -77,44 +82,12 @@ struct ClientEvent } show_formspec; // struct{ //} textures_updated; + ParticleParameters *spawn_particle; struct { - v3f *pos; - v3f *vel; - v3f *acc; - f32 expirationtime; - f32 size; - bool collisiondetection; - bool collision_removal; - bool object_collision; - bool vertical; - std::string *texture; - struct TileAnimationParams animation; - u8 glow; - } spawn_particle; - struct - { - u16 amount; - f32 spawntime; - v3f *minpos; - v3f *maxpos; - v3f *minvel; - v3f *maxvel; - v3f *minacc; - v3f *maxacc; - f32 minexptime; - f32 maxexptime; - f32 minsize; - f32 maxsize; - bool collisiondetection; - bool collision_removal; - bool object_collision; + ParticleSpawnerParameters *p; u16 attached_id; - bool vertical; - std::string *texture; u64 id; - struct TileAnimationParams animation; - u8 glow; } add_particlespawner; struct { diff --git a/src/client/particles.cpp b/src/client/particles.cpp index a0e4e54eb..c2e751b4f 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -37,32 +37,31 @@ with this program; if not, write to the Free Software Foundation, Inc., Utility */ -v3f random_v3f(v3f min, v3f max) +static f32 random_f32(f32 min, f32 max) +{ + return rand() / (float)RAND_MAX * (max - min) + min; +} + +static v3f random_v3f(v3f min, v3f max) { return v3f( - rand() / (float)RAND_MAX * (max.X - min.X) + min.X, - rand() / (float)RAND_MAX * (max.Y - min.Y) + min.Y, - rand() / (float)RAND_MAX * (max.Z - min.Z) + min.Z); + random_f32(min.X, max.X), + random_f32(min.Y, max.Y), + random_f32(min.Z, max.Z)); } +/* + Particle +*/ + Particle::Particle( IGameDef *gamedef, LocalPlayer *player, ClientEnvironment *env, - v3f pos, - v3f velocity, - v3f acceleration, - float expirationtime, - float size, - bool collisiondetection, - bool collision_removal, - bool object_collision, - bool vertical, + const ParticleParameters &p, video::ITexture *texture, v2f texpos, v2f texsize, - const struct TileAnimationParams &anim, - u8 glow, video::SColor color ): scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(), @@ -81,33 +80,28 @@ Particle::Particle( m_material.setTexture(0, texture); m_texpos = texpos; m_texsize = texsize; - m_animation = anim; + m_animation = p.animation; // Color m_base_color = color; m_color = color; // Particle related - m_pos = pos; - m_velocity = velocity; - m_acceleration = acceleration; - m_expiration = expirationtime; + m_pos = p.pos; + m_velocity = p.vel; + m_acceleration = p.acc; + m_expiration = p.expirationtime; m_player = player; - m_size = size; - m_collisiondetection = collisiondetection; - m_collision_removal = collision_removal; - m_object_collision = object_collision; - m_vertical = vertical; - m_glow = glow; + m_size = p.size; + m_collisiondetection = p.collisiondetection; + m_collision_removal = p.collision_removal; + m_object_collision = p.object_collision; + m_vertical = p.vertical; + m_glow = p.glow; // Irrlicht stuff - m_collisionbox = aabb3f( - -size / 2, - -size / 2, - -size / 2, - size / 2, - size / 2, - size / 2); + const float c = p.size / 2; + m_collisionbox = aabb3f(-c, -c, -c, c, c, c); this->setAutomaticCulling(scene::EAC_OFF); // Init lighting @@ -255,52 +249,22 @@ void Particle::updateVertices() ParticleSpawner::ParticleSpawner( IGameDef *gamedef, LocalPlayer *player, - u16 amount, - float time, - v3f minpos, v3f maxpos, - v3f minvel, v3f maxvel, - v3f minacc, v3f maxacc, - float minexptime, float maxexptime, - float minsize, float maxsize, - bool collisiondetection, - bool collision_removal, - bool object_collision, + const ParticleSpawnerParameters &p, u16 attached_id, - bool vertical, video::ITexture *texture, - const struct TileAnimationParams &anim, - u8 glow, ParticleManager *p_manager ): - m_particlemanager(p_manager) + m_particlemanager(p_manager), p(p) { m_gamedef = gamedef; m_player = player; - m_amount = amount; - m_spawntime = time; - m_minpos = minpos; - m_maxpos = maxpos; - m_minvel = minvel; - m_maxvel = maxvel; - m_minacc = minacc; - m_maxacc = maxacc; - m_minexptime = minexptime; - m_maxexptime = maxexptime; - m_minsize = minsize; - m_maxsize = maxsize; - m_collisiondetection = collisiondetection; - m_collision_removal = collision_removal; - m_object_collision = object_collision; m_attached_id = attached_id; - m_vertical = vertical; m_texture = texture; m_time = 0; - m_animation = anim; - m_glow = glow; - for (u16 i = 0; i <= m_amount; i++) - { - float spawntime = (float)rand() / (float)RAND_MAX * m_spawntime; + m_spawntimes.reserve(p.amount + 1); + for (u16 i = 0; i <= p.amount; i++) { + float spawntime = rand() / (float)RAND_MAX * p.time; m_spawntimes.push_back(spawntime); } } @@ -309,7 +273,7 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, const core::matrix4 *attached_absolute_pos_rot_matrix) { v3f ppos = m_player->getPosition() / BS; - v3f pos = random_v3f(m_minpos, m_maxpos); + v3f pos = random_v3f(p.minpos, p.maxpos); // Need to apply this first or the following check // will be wrong for attached spawners @@ -326,41 +290,32 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, if (pos.getDistanceFrom(ppos) > radius) return; - v3f vel = random_v3f(m_minvel, m_maxvel); - v3f acc = random_v3f(m_minacc, m_maxacc); + // Parameters for the single particle we're about to spawn + ParticleParameters pp; + pp.pos = pos; + + pp.vel = random_v3f(p.minvel, p.maxvel); + pp.acc = random_v3f(p.minacc, p.maxacc); if (attached_absolute_pos_rot_matrix) { // Apply attachment rotation - attached_absolute_pos_rot_matrix->rotateVect(vel); - attached_absolute_pos_rot_matrix->rotateVect(acc); + attached_absolute_pos_rot_matrix->rotateVect(pp.vel); + attached_absolute_pos_rot_matrix->rotateVect(pp.acc); } - float exptime = rand() / (float)RAND_MAX - * (m_maxexptime - m_minexptime) - + m_minexptime; + pp.expirationtime = random_f32(p.minexptime, p.maxexptime); + pp.size = random_f32(p.minsize, p.maxsize); - float size = rand() / (float)RAND_MAX - * (m_maxsize - m_minsize) - + m_minsize; + p.copyCommon(pp); m_particlemanager->addParticle(new Particle( m_gamedef, m_player, env, - pos, - vel, - acc, - exptime, - size, - m_collisiondetection, - m_collision_removal, - m_object_collision, - m_vertical, + pp, m_texture, v2f(0.0, 0.0), - v2f(1.0, 1.0), - m_animation, - m_glow + v2f(1.0, 1.0) )); } @@ -381,12 +336,11 @@ void ParticleSpawner::step(float dtime, ClientEnvironment *env) } } - if (m_spawntime != 0) { + if (p.time != 0) { // Spawner exists for a predefined timespan - for (std::vector::iterator i = m_spawntimes.begin(); - i != m_spawntimes.end();) { - if ((*i) <= m_time && m_amount > 0) { - --m_amount; + for (auto i = m_spawntimes.begin(); i != m_spawntimes.end(); ) { + if ((*i) <= m_time && p.amount > 0) { + --p.amount; // Pretend to, but don't actually spawn a particle if it is // attached to an unloaded object or distant from player. @@ -405,13 +359,16 @@ void ParticleSpawner::step(float dtime, ClientEnvironment *env) if (unloaded) return; - for (int i = 0; i <= m_amount; i++) { + for (int i = 0; i <= p.amount; i++) { if (rand() / (float)RAND_MAX < dtime) spawnParticle(env, radius, attached_absolute_pos_rot_matrix); } } } +/* + ParticleManager +*/ ParticleManager::ParticleManager(ClientEnvironment *env) : m_env(env) @@ -479,99 +436,84 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, { switch (event->type) { case CE_DELETE_PARTICLESPAWNER: { - MutexAutoLock lock(m_spawner_list_lock); - if (m_particle_spawners.find(event->delete_particlespawner.id) != - m_particle_spawners.end()) { - delete m_particle_spawners.find(event->delete_particlespawner.id)->second; - m_particle_spawners.erase(event->delete_particlespawner.id); - } + deleteParticleSpawner(event->delete_particlespawner.id); // no allocated memory in delete event break; } case CE_ADD_PARTICLESPAWNER: { - { - MutexAutoLock lock(m_spawner_list_lock); - if (m_particle_spawners.find(event->add_particlespawner.id) != - m_particle_spawners.end()) { - delete m_particle_spawners.find(event->add_particlespawner.id)->second; - m_particle_spawners.erase(event->add_particlespawner.id); - } - } + deleteParticleSpawner(event->add_particlespawner.id); + + const ParticleSpawnerParameters &p = *event->add_particlespawner.p; video::ITexture *texture = - client->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture)); + client->tsrc()->getTextureForMesh(p.texture); auto toadd = new ParticleSpawner(client, player, - event->add_particlespawner.amount, - event->add_particlespawner.spawntime, - *event->add_particlespawner.minpos, - *event->add_particlespawner.maxpos, - *event->add_particlespawner.minvel, - *event->add_particlespawner.maxvel, - *event->add_particlespawner.minacc, - *event->add_particlespawner.maxacc, - event->add_particlespawner.minexptime, - event->add_particlespawner.maxexptime, - event->add_particlespawner.minsize, - event->add_particlespawner.maxsize, - event->add_particlespawner.collisiondetection, - event->add_particlespawner.collision_removal, - event->add_particlespawner.object_collision, + p, event->add_particlespawner.attached_id, - event->add_particlespawner.vertical, texture, - event->add_particlespawner.animation, - event->add_particlespawner.glow, this); - /* delete allocated content of event */ - delete event->add_particlespawner.minpos; - delete event->add_particlespawner.maxpos; - delete event->add_particlespawner.minvel; - delete event->add_particlespawner.maxvel; - delete event->add_particlespawner.minacc; - delete event->add_particlespawner.texture; - delete event->add_particlespawner.maxacc; - - { - MutexAutoLock lock(m_spawner_list_lock); - m_particle_spawners[event->add_particlespawner.id] = toadd; - } + addParticleSpawner(event->add_particlespawner.id, toadd); + + delete event->add_particlespawner.p; break; } case CE_SPAWN_PARTICLE: { + const ParticleParameters &p = *event->spawn_particle; video::ITexture *texture = - client->tsrc()->getTextureForMesh(*(event->spawn_particle.texture)); + client->tsrc()->getTextureForMesh(p.texture); Particle *toadd = new Particle(client, player, m_env, - *event->spawn_particle.pos, - *event->spawn_particle.vel, - *event->spawn_particle.acc, - event->spawn_particle.expirationtime, - event->spawn_particle.size, - event->spawn_particle.collisiondetection, - event->spawn_particle.collision_removal, - event->spawn_particle.object_collision, - event->spawn_particle.vertical, + p, texture, v2f(0.0, 0.0), - v2f(1.0, 1.0), - event->spawn_particle.animation, - event->spawn_particle.glow); + v2f(1.0, 1.0)); addParticle(toadd); - delete event->spawn_particle.pos; - delete event->spawn_particle.vel; - delete event->spawn_particle.acc; - delete event->spawn_particle.texture; - + delete event->spawn_particle; break; } default: break; } } +bool ParticleManager::getNodeParticleParams(const MapNode &n, + const ContentFeatures &f, ParticleParameters &p, + video::ITexture **texture, v2f &texpos, v2f &texsize, video::SColor *color) +{ + // No particles for "airlike" nodes + if (f.drawtype == NDT_AIRLIKE) + return false; + + // Texture + u8 texid = rand() % 6; + const TileLayer &tile = f.tiles[texid].layers[0]; + p.animation.type = TAT_NONE; + + // Only use first frame of animated texture + if (tile.material_flags & MATERIAL_FLAG_ANIMATION) + *texture = (*tile.frames)[0].texture; + else + *texture = tile.texture; + + float size = (rand() % 8) / 64.0f; + p.size = BS * size; + if (tile.scale) + size /= tile.scale; + texsize = v2f(size * 2.0f, size * 2.0f); + texpos.X = (rand() % 64) / 64.0f - texsize.X; + texpos.Y = (rand() % 64) / 64.0f - texsize.Y; + + if (tile.has_color) + *color = tile.color; + else + n.getColor(f, color); + + return true; +} + // The final burst of particles when a node is finally dug, *not* particles // spawned during the digging of a node. @@ -593,73 +535,41 @@ void ParticleManager::addDiggingParticles(IGameDef *gamedef, void ParticleManager::addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f) { - // No particles for "airlike" nodes - if (f.drawtype == NDT_AIRLIKE) - return; - - // Texture - u8 texid = myrand_range(0, 5); - const TileLayer &tile = f.tiles[texid].layers[0]; + ParticleParameters p; video::ITexture *texture; - struct TileAnimationParams anim; - anim.type = TAT_NONE; + v2f texpos, texsize; + video::SColor color; - // Only use first frame of animated texture - if (tile.material_flags & MATERIAL_FLAG_ANIMATION) - texture = (*tile.frames)[0].texture; - else - texture = tile.texture; + if (!getNodeParticleParams(n, f, p, &texture, texpos, texsize, &color)) + return; - float size = (rand() % 8) / 64.0f; - float visual_size = BS * size; - if (tile.scale) - size /= tile.scale; - v2f texsize(size * 2.0f, size * 2.0f); - v2f texpos; - texpos.X = (rand() % 64) / 64.0f - texsize.X; - texpos.Y = (rand() % 64) / 64.0f - texsize.Y; + p.expirationtime = (rand() % 100) / 100.0f; // Physics - v3f velocity( + p.vel = v3f( (rand() % 150) / 50.0f - 1.5f, (rand() % 150) / 50.0f, (rand() % 150) / 50.0f - 1.5f ); - v3f acceleration( + p.acc = v3f( 0.0f, -player->movement_gravity * player->physics_override_gravity / BS, 0.0f ); - v3f particlepos = v3f( + p.pos = v3f( (f32)pos.X + (rand() % 100) / 200.0f - 0.25f, (f32)pos.Y + (rand() % 100) / 200.0f - 0.25f, (f32)pos.Z + (rand() % 100) / 200.0f - 0.25f ); - video::SColor color; - if (tile.has_color) - color = tile.color; - else - n.getColor(f, &color); - Particle *toadd = new Particle( gamedef, player, m_env, - particlepos, - velocity, - acceleration, - (rand() % 100) / 100.0f, // expiration time - visual_size, - true, - false, - false, - false, + p, texture, texpos, texsize, - anim, - 0, color); addParticle(toadd); @@ -670,3 +580,20 @@ void ParticleManager::addParticle(Particle *toadd) MutexAutoLock lock(m_particle_list_lock); m_particles.push_back(toadd); } + + +void ParticleManager::addParticleSpawner(u64 id, ParticleSpawner *toadd) +{ + MutexAutoLock lock(m_spawner_list_lock); + m_particle_spawners[id] = toadd; +} + +void ParticleManager::deleteParticleSpawner(u64 id) +{ + MutexAutoLock lock(m_spawner_list_lock); + auto it = m_particle_spawners.find(id); + if (it != m_particle_spawners.end()) { + delete it->second; + m_particle_spawners.erase(it); + } +} diff --git a/src/client/particles.h b/src/client/particles.h index e7b8cbe24..7dda0e1b1 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_extrabloated.h" #include "client/tile.h" #include "localplayer.h" -#include "tileanimation.h" +#include "../particles.h" struct ClientEvent; class ParticleManager; @@ -38,20 +38,10 @@ class Particle : public scene::ISceneNode IGameDef* gamedef, LocalPlayer *player, ClientEnvironment *env, - v3f pos, - v3f velocity, - v3f acceleration, - float expirationtime, - float size, - bool collisiondetection, - bool collision_removal, - bool object_collision, - bool vertical, + const ParticleParameters &p, video::ITexture *texture, v2f texpos, v2f texsize, - const struct TileAnimationParams &anim, - u8 glow, video::SColor color = video::SColor(0xFFFFFFFF) ); ~Particle() = default; @@ -119,20 +109,9 @@ class ParticleSpawner public: ParticleSpawner(IGameDef* gamedef, LocalPlayer *player, - u16 amount, - float time, - v3f minp, v3f maxp, - v3f minvel, v3f maxvel, - v3f minacc, v3f maxacc, - float minexptime, float maxexptime, - float minsize, float maxsize, - bool collisiondetection, - bool collision_removal, - bool object_collision, + const ParticleSpawnerParameters &p, u16 attached_id, - bool vertical, video::ITexture *texture, - const struct TileAnimationParams &anim, u8 glow, ParticleManager* p_manager); ~ParticleSpawner() = default; @@ -140,7 +119,7 @@ public: void step(float dtime, ClientEnvironment *env); bool get_expired () - { return (m_amount <= 0) && m_spawntime != 0; } + { return p.amount <= 0 && p.time != 0; } private: void spawnParticle(ClientEnvironment *env, float radius, @@ -150,27 +129,10 @@ private: float m_time; IGameDef *m_gamedef; LocalPlayer *m_player; - u16 m_amount; - float m_spawntime; - v3f m_minpos; - v3f m_maxpos; - v3f m_minvel; - v3f m_maxvel; - v3f m_minacc; - v3f m_maxacc; - float m_minexptime; - float m_maxexptime; - float m_minsize; - float m_maxsize; + ParticleSpawnerParameters p; video::ITexture *m_texture; std::vector m_spawntimes; - bool m_collisiondetection; - bool m_collision_removal; - bool m_object_collision; - bool m_vertical; u16 m_attached_id; - struct TileAnimationParams m_animation; - u8 m_glow; }; /** @@ -197,8 +159,8 @@ public: /** * This function is only used by client particle spawners * - * We don't need to check the particle spawner list because client ID will n - * ever overlap (u64) + * We don't need to check the particle spawner list because client ID will + * never overlap (u64) * @return new id */ u64 generateSpawnerId() @@ -207,9 +169,15 @@ public: } protected: + static bool getNodeParticleParams(const MapNode &n, const ContentFeatures &f, + ParticleParameters &p, video::ITexture **texture, v2f &texpos, + v2f &texsize, video::SColor *color); + void addParticle(Particle* toadd); private: + void addParticleSpawner(u64 id, ParticleSpawner *toadd); + void deleteParticleSpawner(u64 id); void stepParticles(float dtime); void stepSpawners(float dtime); diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 7b1b1368c..054e60c3c 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -958,114 +958,56 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt) std::string datastring(pkt->getString(0), pkt->getSize()); std::istringstream is(datastring, std::ios_base::binary); - v3f pos = readV3F32(is); - v3f vel = readV3F32(is); - v3f acc = readV3F32(is); - float expirationtime = readF32(is); - float size = readF32(is); - bool collisiondetection = readU8(is); - std::string texture = deSerializeLongString(is); - - bool vertical = false; - bool collision_removal = false; - TileAnimationParams animation; - animation.type = TAT_NONE; - u8 glow = 0; - bool object_collision = false; - try { - vertical = readU8(is); - collision_removal = readU8(is); - animation.deSerialize(is, m_proto_ver); - glow = readU8(is); - object_collision = readU8(is); - } catch (...) {} + ParticleParameters p; + p.deSerialize(is, m_proto_ver); ClientEvent *event = new ClientEvent(); - event->type = CE_SPAWN_PARTICLE; - event->spawn_particle.pos = new v3f (pos); - event->spawn_particle.vel = new v3f (vel); - event->spawn_particle.acc = new v3f (acc); - event->spawn_particle.expirationtime = expirationtime; - event->spawn_particle.size = size; - event->spawn_particle.collisiondetection = collisiondetection; - event->spawn_particle.collision_removal = collision_removal; - event->spawn_particle.object_collision = object_collision; - event->spawn_particle.vertical = vertical; - event->spawn_particle.texture = new std::string(texture); - event->spawn_particle.animation = animation; - event->spawn_particle.glow = glow; + event->type = CE_SPAWN_PARTICLE; + event->spawn_particle = new ParticleParameters(p); m_client_event_queue.push(event); } void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) { - u16 amount; - float spawntime; - v3f minpos; - v3f maxpos; - v3f minvel; - v3f maxvel; - v3f minacc; - v3f maxacc; - float minexptime; - float maxexptime; - float minsize; - float maxsize; - bool collisiondetection; - u32 server_id; - - *pkt >> amount >> spawntime >> minpos >> maxpos >> minvel >> maxvel - >> minacc >> maxacc >> minexptime >> maxexptime >> minsize - >> maxsize >> collisiondetection; - - std::string texture = pkt->readLongString(); - - *pkt >> server_id; - - bool vertical = false; - bool collision_removal = false; - u16 attached_id = 0; - TileAnimationParams animation; - animation.type = TAT_NONE; - u8 glow = 0; - bool object_collision = false; - try { - *pkt >> vertical; - *pkt >> collision_removal; - *pkt >> attached_id; + std::string datastring(pkt->getString(0), pkt->getSize()); + std::istringstream is(datastring, std::ios_base::binary); - // This is horrible but required (why are there two ways to deserialize pkts?) - std::string datastring(pkt->getRemainingString(), pkt->getRemainingBytes()); - std::istringstream is(datastring, std::ios_base::binary); - animation.deSerialize(is, m_proto_ver); - glow = readU8(is); - object_collision = readU8(is); - } catch (...) {} + ParticleSpawnerParameters p; + u32 server_id; + u16 attached_id = 0; + + p.amount = readU16(is); + p.time = readF32(is); + p.minpos = readV3F32(is); + p.maxpos = readV3F32(is); + p.minvel = readV3F32(is); + p.maxvel = readV3F32(is); + p.minacc = readV3F32(is); + p.maxacc = readV3F32(is); + p.minexptime = readF32(is); + p.maxexptime = readF32(is); + p.minsize = readF32(is); + p.maxsize = readF32(is); + p.collisiondetection = readU8(is); + p.texture = deSerializeLongString(is); + + server_id = readU32(is); + + p.vertical = readU8(is); + p.collision_removal = readU8(is); + + attached_id = readU16(is); + + p.animation.deSerialize(is, m_proto_ver); + p.glow = readU8(is); + p.object_collision = readU8(is); auto event = new ClientEvent(); - event->type = CE_ADD_PARTICLESPAWNER; - event->add_particlespawner.amount = amount; - event->add_particlespawner.spawntime = spawntime; - event->add_particlespawner.minpos = new v3f (minpos); - event->add_particlespawner.maxpos = new v3f (maxpos); - event->add_particlespawner.minvel = new v3f (minvel); - event->add_particlespawner.maxvel = new v3f (maxvel); - event->add_particlespawner.minacc = new v3f (minacc); - event->add_particlespawner.maxacc = new v3f (maxacc); - event->add_particlespawner.minexptime = minexptime; - event->add_particlespawner.maxexptime = maxexptime; - event->add_particlespawner.minsize = minsize; - event->add_particlespawner.maxsize = maxsize; - event->add_particlespawner.collisiondetection = collisiondetection; - event->add_particlespawner.collision_removal = collision_removal; - event->add_particlespawner.object_collision = object_collision; - event->add_particlespawner.attached_id = attached_id; - event->add_particlespawner.vertical = vertical; - event->add_particlespawner.texture = new std::string(texture); - event->add_particlespawner.id = server_id; - event->add_particlespawner.animation = animation; - event->add_particlespawner.glow = glow; + event->type = CE_ADD_PARTICLESPAWNER; + event->add_particlespawner.p = new ParticleSpawnerParameters(p); + event->add_particlespawner.attached_id = attached_id; + event->add_particlespawner.id = server_id; m_client_event_queue.push(event); } diff --git a/src/particles.cpp b/src/particles.cpp new file mode 100644 index 000000000..711d189f6 --- /dev/null +++ b/src/particles.cpp @@ -0,0 +1,53 @@ +/* +Minetest +Copyright (C) 2020 sfan5 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "particles.h" +#include "util/serialize.h" + +void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const +{ + writeV3F32(os, pos); + writeV3F32(os, vel); + writeV3F32(os, acc); + writeF32(os, expirationtime); + writeF32(os, size); + writeU8(os, collisiondetection); + os << serializeLongString(texture); + writeU8(os, vertical); + writeU8(os, collision_removal); + animation.serialize(os, 6); /* NOT the protocol ver */ + writeU8(os, glow); + writeU8(os, object_collision); +} + +void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) +{ + pos = readV3F32(is); + vel = readV3F32(is); + acc = readV3F32(is); + expirationtime = readF32(is); + size = readF32(is); + collisiondetection = readU8(is); + texture = deSerializeLongString(is); + vertical = readU8(is); + collision_removal = readU8(is); + animation.deSerialize(is, 6); /* NOT the protocol ver */ + glow = readU8(is); + object_collision = readU8(is); +} diff --git a/src/particles.h b/src/particles.h new file mode 100644 index 000000000..659c1249f --- /dev/null +++ b/src/particles.h @@ -0,0 +1,73 @@ +/* +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#pragma once + +#include +#include "irrlichttypes_bloated.h" +#include "tileanimation.h" + +// This file defines the particle-related structures that both the server and +// client need. The ParticleManager and rendering is in client/particles.h + +struct CommonParticleParams { + bool collisiondetection = false; + bool collision_removal = false; + bool object_collision = false; + bool vertical = false; + std::string texture; + struct TileAnimationParams animation; + u8 glow = 0; + + CommonParticleParams() { + animation.type = TAT_NONE; + } + + /* This helper is useful for copying params from + * ParticleSpawnerParameters to ParticleParameters */ + inline void copyCommon(CommonParticleParams &to) const { + to.collisiondetection = collisiondetection; + to.collision_removal = collision_removal; + to.object_collision = object_collision; + to.vertical = vertical; + to.texture = texture; + to.animation = animation; + to.glow = glow; + } +}; + +struct ParticleParameters : CommonParticleParams { + v3f pos; + v3f vel; + v3f acc; + f32 expirationtime = 1; + f32 size = 1; + + void serialize(std::ostream &os, u16 protocol_ver) const; + void deSerialize(std::istream &is, u16 protocol_ver); +}; + +struct ParticleSpawnerParameters : CommonParticleParams { + u16 amount = 1; + v3f minpos, maxpos, minvel, maxvel, minacc, maxacc; + f32 time = 1; + f32 minexptime = 1, maxexptime = 1, minsize = 1, maxsize = 1; + + // For historical reasons no (de-)serialization methods here +}; diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index 340903ebf..7680aa17b 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_converter.h" #include "common/c_content.h" #include "server.h" -#include "client/particles.h" +#include "particles.h" // add_particle({pos=, velocity=, acceleration=, expirationtime=, // size=, collisiondetection=, collision_removal=, object_collision=, @@ -40,85 +40,81 @@ with this program; if not, write to the Free Software Foundation, Inc., // glow = num int ModApiParticles::l_add_particle(lua_State *L) { - MAP_LOCK_REQUIRED; + NO_MAP_LOCK_REQUIRED; // Get parameters - v3f pos, vel, acc; - float expirationtime, size; - expirationtime = size = 1; - bool collisiondetection, vertical, collision_removal, object_collision; - collisiondetection = vertical = collision_removal = object_collision = false; - struct TileAnimationParams animation; - animation.type = TAT_NONE; - std::string texture; + struct ParticleParameters p; std::string playername; - u8 glow = 0; if (lua_gettop(L) > 1) // deprecated { - log_deprecated(L, "Deprecated add_particle call with individual parameters instead of definition"); - pos = check_v3f(L, 1); - vel = check_v3f(L, 2); - acc = check_v3f(L, 3); - expirationtime = luaL_checknumber(L, 4); - size = luaL_checknumber(L, 5); - collisiondetection = readParam(L, 6); - texture = luaL_checkstring(L, 7); + log_deprecated(L, "Deprecated add_particle call with " + "individual parameters instead of definition"); + p.pos = check_v3f(L, 1); + p.vel = check_v3f(L, 2); + p.acc = check_v3f(L, 3); + p.expirationtime = luaL_checknumber(L, 4); + p.size = luaL_checknumber(L, 5); + p.collisiondetection = readParam(L, 6); + p.texture = luaL_checkstring(L, 7); if (lua_gettop(L) == 8) // only spawn for a single player playername = luaL_checkstring(L, 8); } else if (lua_istable(L, 1)) { lua_getfield(L, 1, "pos"); - pos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(); + if (lua_istable(L, -1)) + p.pos = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "vel"); if (lua_istable(L, -1)) { - vel = check_v3f(L, -1); + p.vel = check_v3f(L, -1); log_deprecated(L, "The use of vel is deprecated. " "Use velocity instead"); } lua_pop(L, 1); lua_getfield(L, 1, "velocity"); - vel = lua_istable(L, -1) ? check_v3f(L, -1) : vel; + if (lua_istable(L, -1)) + p.vel = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "acc"); if (lua_istable(L, -1)) { - acc = check_v3f(L, -1); + p.acc = check_v3f(L, -1); log_deprecated(L, "The use of acc is deprecated. " "Use acceleration instead"); } lua_pop(L, 1); lua_getfield(L, 1, "acceleration"); - acc = lua_istable(L, -1) ? check_v3f(L, -1) : acc; + if (lua_istable(L, -1)) + p.acc = check_v3f(L, -1); lua_pop(L, 1); - expirationtime = getfloatfield_default(L, 1, "expirationtime", 1); - size = getfloatfield_default(L, 1, "size", 1); - collisiondetection = getboolfield_default(L, 1, - "collisiondetection", collisiondetection); - collision_removal = getboolfield_default(L, 1, - "collision_removal", collision_removal); - object_collision = getboolfield_default(L, 1, - "object_collision", object_collision); - vertical = getboolfield_default(L, 1, "vertical", vertical); + p.expirationtime = getfloatfield_default(L, 1, "expirationtime", + p.expirationtime); + p.size = getfloatfield_default(L, 1, "size", p.size); + p.collisiondetection = getboolfield_default(L, 1, + "collisiondetection", p.collisiondetection); + p.collision_removal = getboolfield_default(L, 1, + "collision_removal", p.collision_removal); + p.object_collision = getboolfield_default(L, 1, + "object_collision", p.object_collision); + p.vertical = getboolfield_default(L, 1, "vertical", p.vertical); lua_getfield(L, 1, "animation"); - animation = read_animation_definition(L, -1); + p.animation = read_animation_definition(L, -1); lua_pop(L, 1); - texture = getstringfield_default(L, 1, "texture", ""); - playername = getstringfield_default(L, 1, "playername", ""); + p.texture = getstringfield_default(L, 1, "texture", p.texture); + p.glow = getintfield_default(L, 1, "glow", p.glow); - glow = getintfield_default(L, 1, "glow", 0); + playername = getstringfield_default(L, 1, "playername", ""); } - getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, size, - collisiondetection, collision_removal, object_collision, vertical, - texture, animation, glow); + + getServer(L)->spawnParticle(playername, p); return 1; } @@ -146,84 +142,82 @@ int ModApiParticles::l_add_particle(lua_State *L) // glow = num int ModApiParticles::l_add_particlespawner(lua_State *L) { - MAP_LOCK_REQUIRED; + NO_MAP_LOCK_REQUIRED; // Get parameters - u16 amount = 1; - v3f minpos, maxpos, minvel, maxvel, minacc, maxacc; - float time, minexptime, maxexptime, minsize, maxsize; - time = minexptime = maxexptime = minsize = maxsize = 1; - bool collisiondetection, vertical, collision_removal, object_collision; - collisiondetection = vertical = collision_removal = object_collision = false; - struct TileAnimationParams animation; - animation.type = TAT_NONE; + ParticleSpawnerParameters p; ServerActiveObject *attached = NULL; - std::string texture; std::string playername; - u8 glow = 0; if (lua_gettop(L) > 1) //deprecated { - log_deprecated(L,"Deprecated add_particlespawner call with individual parameters instead of definition"); - amount = luaL_checknumber(L, 1); - time = luaL_checknumber(L, 2); - minpos = check_v3f(L, 3); - maxpos = check_v3f(L, 4); - minvel = check_v3f(L, 5); - maxvel = check_v3f(L, 6); - minacc = check_v3f(L, 7); - maxacc = check_v3f(L, 8); - minexptime = luaL_checknumber(L, 9); - maxexptime = luaL_checknumber(L, 10); - minsize = luaL_checknumber(L, 11); - maxsize = luaL_checknumber(L, 12); - collisiondetection = readParam(L, 13); - texture = luaL_checkstring(L, 14); + log_deprecated(L, "Deprecated add_particlespawner call with " + "individual parameters instead of definition"); + p.amount = luaL_checknumber(L, 1); + p.time = luaL_checknumber(L, 2); + p.minpos = check_v3f(L, 3); + p.maxpos = check_v3f(L, 4); + p.minvel = check_v3f(L, 5); + p.maxvel = check_v3f(L, 6); + p.minacc = check_v3f(L, 7); + p.maxacc = check_v3f(L, 8); + p.minexptime = luaL_checknumber(L, 9); + p.maxexptime = luaL_checknumber(L, 10); + p.minsize = luaL_checknumber(L, 11); + p.maxsize = luaL_checknumber(L, 12); + p.collisiondetection = readParam(L, 13); + p.texture = luaL_checkstring(L, 14); if (lua_gettop(L) == 15) // only spawn for a single player playername = luaL_checkstring(L, 15); } else if (lua_istable(L, 1)) { - amount = getintfield_default(L, 1, "amount", amount); - time = getfloatfield_default(L, 1, "time", time); + p.amount = getintfield_default(L, 1, "amount", p.amount); + p.time = getfloatfield_default(L, 1, "time", p.time); lua_getfield(L, 1, "minpos"); - minpos = lua_istable(L, -1) ? check_v3f(L, -1) : minpos; + if (lua_istable(L, -1)) + p.minpos = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "maxpos"); - maxpos = lua_istable(L, -1) ? check_v3f(L, -1) : maxpos; + if (lua_istable(L, -1)) + p.maxpos = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "minvel"); - minvel = lua_istable(L, -1) ? check_v3f(L, -1) : minvel; + if (lua_istable(L, -1)) + p.minvel = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "maxvel"); - maxvel = lua_istable(L, -1) ? check_v3f(L, -1) : maxvel; + if (lua_istable(L, -1)) + p.maxvel = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "minacc"); - minacc = lua_istable(L, -1) ? check_v3f(L, -1) : minacc; + if (lua_istable(L, -1)) + p.minacc = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "maxacc"); - maxacc = lua_istable(L, -1) ? check_v3f(L, -1) : maxacc; + if (lua_istable(L, -1)) + p.maxacc = check_v3f(L, -1); lua_pop(L, 1); - minexptime = getfloatfield_default(L, 1, "minexptime", minexptime); - maxexptime = getfloatfield_default(L, 1, "maxexptime", maxexptime); - minsize = getfloatfield_default(L, 1, "minsize", minsize); - maxsize = getfloatfield_default(L, 1, "maxsize", maxsize); - collisiondetection = getboolfield_default(L, 1, - "collisiondetection", collisiondetection); - collision_removal = getboolfield_default(L, 1, - "collision_removal", collision_removal); - object_collision = getboolfield_default(L, 1, - "object_collision", object_collision); + p.minexptime = getfloatfield_default(L, 1, "minexptime", p.minexptime); + p.maxexptime = getfloatfield_default(L, 1, "maxexptime", p.maxexptime); + p.minsize = getfloatfield_default(L, 1, "minsize", p.minsize); + p.maxsize = getfloatfield_default(L, 1, "maxsize", p.maxsize); + p.collisiondetection = getboolfield_default(L, 1, + "collisiondetection", p.collisiondetection); + p.collision_removal = getboolfield_default(L, 1, + "collision_removal", p.collision_removal); + p.object_collision = getboolfield_default(L, 1, + "object_collision", p.object_collision); lua_getfield(L, 1, "animation"); - animation = read_animation_definition(L, -1); + p.animation = read_animation_definition(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "attached"); @@ -233,25 +227,13 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) attached = ObjectRef::getobject(ref); } - vertical = getboolfield_default(L, 1, "vertical", vertical); - texture = getstringfield_default(L, 1, "texture", ""); + p.vertical = getboolfield_default(L, 1, "vertical", p.vertical); + p.texture = getstringfield_default(L, 1, "texture", p.texture); playername = getstringfield_default(L, 1, "playername", ""); - glow = getintfield_default(L, 1, "glow", 0); + p.glow = getintfield_default(L, 1, "glow", p.glow); } - u32 id = getServer(L)->addParticleSpawner(amount, time, - minpos, maxpos, - minvel, maxvel, - minacc, maxacc, - minexptime, maxexptime, - minsize, maxsize, - collisiondetection, - collision_removal, - object_collision, - attached, - vertical, - texture, playername, - animation, glow); + u32 id = getServer(L)->addParticleSpawner(p, attached, playername); lua_pushnumber(L, id); return 1; @@ -261,7 +243,7 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) // player (string) is optional int ModApiParticles::l_delete_particlespawner(lua_State *L) { - MAP_LOCK_REQUIRED; + NO_MAP_LOCK_REQUIRED; // Get parameters u32 id = luaL_checknumber(L, 1); diff --git a/src/script/lua_api/l_particles_local.cpp b/src/script/lua_api/l_particles_local.cpp index a9bf55665..9595b2fab 100644 --- a/src/script/lua_api/l_particles_local.cpp +++ b/src/script/lua_api/l_particles_local.cpp @@ -32,56 +32,44 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L) luaL_checktype(L, 1, LUA_TTABLE); // Get parameters - v3f pos, vel, acc; - float expirationtime, size; - bool collisiondetection, vertical, collision_removal; - - struct TileAnimationParams animation; - animation.type = TAT_NONE; - - std::string texture; - - u8 glow; + ParticleParameters p; lua_getfield(L, 1, "pos"); - pos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.pos = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "velocity"); - vel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.vel = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "acceleration"); - acc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.acc = check_v3f(L, -1); lua_pop(L, 1); - expirationtime = getfloatfield_default(L, 1, "expirationtime", 1); - size = getfloatfield_default(L, 1, "size", 1); - collisiondetection = getboolfield_default(L, 1, "collisiondetection", false); - collision_removal = getboolfield_default(L, 1, "collision_removal", false); - vertical = getboolfield_default(L, 1, "vertical", false); + p.expirationtime = getfloatfield_default(L, 1, "expirationtime", + p.expirationtime); + p.size = getfloatfield_default(L, 1, "size", p.size); + p.collisiondetection = getboolfield_default(L, 1, + "collisiondetection", p.collisiondetection); + p.collision_removal = getboolfield_default(L, 1, + "collision_removal", p.collision_removal); + p.object_collision = getboolfield_default(L, 1, + "object_collision", p.object_collision); + p.vertical = getboolfield_default(L, 1, "vertical", p.vertical); lua_getfield(L, 1, "animation"); - animation = read_animation_definition(L, -1); + p.animation = read_animation_definition(L, -1); lua_pop(L, 1); - texture = getstringfield_default(L, 1, "texture", ""); - - glow = getintfield_default(L, 1, "glow", 0); + p.texture = getstringfield_default(L, 1, "texture", p.texture); + p.glow = getintfield_default(L, 1, "glow", p.glow); ClientEvent *event = new ClientEvent(); - event->type = CE_SPAWN_PARTICLE; - event->spawn_particle.pos = new v3f (pos); - event->spawn_particle.vel = new v3f (vel); - event->spawn_particle.acc = new v3f (acc); - event->spawn_particle.expirationtime = expirationtime; - event->spawn_particle.size = size; - event->spawn_particle.collisiondetection = collisiondetection; - event->spawn_particle.collision_removal = collision_removal; - event->spawn_particle.vertical = vertical; - event->spawn_particle.texture = new std::string(texture); - event->spawn_particle.animation = animation; - event->spawn_particle.glow = glow; + event->type = CE_SPAWN_PARTICLE; + event->spawn_particle = new ParticleParameters(p); getClient(L)->pushToEventQueue(event); return 0; @@ -90,94 +78,69 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L) int ModApiParticlesLocal::l_add_particlespawner(lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); - // Get parameters - u16 amount; - v3f minpos, maxpos, minvel, maxvel, minacc, maxacc; - float time, minexptime, maxexptime, minsize, maxsize; - bool collisiondetection, vertical, collision_removal; - struct TileAnimationParams animation; - animation.type = TAT_NONE; - // TODO: Implement this when there is a way to get an objectref. - // ServerActiveObject *attached = NULL; - std::string texture; - u8 glow; + // Get parameters + ParticleSpawnerParameters p; - amount = getintfield_default(L, 1, "amount", 1); - time = getfloatfield_default(L, 1, "time", 1); + p.amount = getintfield_default(L, 1, "amount", p.amount); + p.time = getfloatfield_default(L, 1, "time", p.time); lua_getfield(L, 1, "minpos"); - minpos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.minpos = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "maxpos"); - maxpos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.maxpos = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "minvel"); - minvel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.minvel = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "maxvel"); - maxvel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.maxvel = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "minacc"); - minacc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.minacc = check_v3f(L, -1); lua_pop(L, 1); lua_getfield(L, 1, "maxacc"); - maxacc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0); + if (lua_istable(L, -1)) + p.maxacc = check_v3f(L, -1); lua_pop(L, 1); - minexptime = getfloatfield_default(L, 1, "minexptime", 1); - maxexptime = getfloatfield_default(L, 1, "maxexptime", 1); - minsize = getfloatfield_default(L, 1, "minsize", 1); - maxsize = getfloatfield_default(L, 1, "maxsize", 1); - - collisiondetection = getboolfield_default(L, 1, "collisiondetection", false); - collision_removal = getboolfield_default(L, 1, "collision_removal", false); - vertical = getboolfield_default(L, 1, "vertical", false); + p.minexptime = getfloatfield_default(L, 1, "minexptime", p.minexptime); + p.maxexptime = getfloatfield_default(L, 1, "maxexptime", p.maxexptime); + p.minsize = getfloatfield_default(L, 1, "minsize", p.minsize); + p.maxsize = getfloatfield_default(L, 1, "maxsize", p.maxsize); + p.collisiondetection = getboolfield_default(L, 1, + "collisiondetection", p.collisiondetection); + p.collision_removal = getboolfield_default(L, 1, + "collision_removal", p.collision_removal); + p.object_collision = getboolfield_default(L, 1, + "object_collision", p.object_collision); lua_getfield(L, 1, "animation"); - animation = read_animation_definition(L, -1); + p.animation = read_animation_definition(L, -1); lua_pop(L, 1); - // TODO: Implement this when a way to get an objectref on the client is added -// lua_getfield(L, 1, "attached"); -// if (!lua_isnil(L, -1)) { -// ObjectRef *ref = ObjectRef::checkobject(L, -1); -// lua_pop(L, 1); -// attached = ObjectRef::getobject(ref); -// } - - texture = getstringfield_default(L, 1, "texture", ""); - glow = getintfield_default(L, 1, "glow", 0); + p.vertical = getboolfield_default(L, 1, "vertical", p.vertical); + p.texture = getstringfield_default(L, 1, "texture", p.texture); + p.glow = getintfield_default(L, 1, "glow", p.glow); u64 id = getClient(L)->getParticleManager()->generateSpawnerId(); auto event = new ClientEvent(); - event->type = CE_ADD_PARTICLESPAWNER; - event->add_particlespawner.amount = amount; - event->add_particlespawner.spawntime = time; - event->add_particlespawner.minpos = new v3f (minpos); - event->add_particlespawner.maxpos = new v3f (maxpos); - event->add_particlespawner.minvel = new v3f (minvel); - event->add_particlespawner.maxvel = new v3f (maxvel); - event->add_particlespawner.minacc = new v3f (minacc); - event->add_particlespawner.maxacc = new v3f (maxacc); - event->add_particlespawner.minexptime = minexptime; - event->add_particlespawner.maxexptime = maxexptime; - event->add_particlespawner.minsize = minsize; - event->add_particlespawner.maxsize = maxsize; - event->add_particlespawner.collisiondetection = collisiondetection; - event->add_particlespawner.collision_removal = collision_removal; - event->add_particlespawner.attached_id = 0; - event->add_particlespawner.vertical = vertical; - event->add_particlespawner.texture = new std::string(texture); - event->add_particlespawner.id = id; - event->add_particlespawner.animation = animation; - event->add_particlespawner.glow = glow; + event->type = CE_ADD_PARTICLESPAWNER; + event->add_particlespawner.p = new ParticleSpawnerParameters(p); + event->add_particlespawner.attached_id = 0; + event->add_particlespawner.id = id; getClient(L)->pushToEventQueue(event); lua_pushnumber(L, id); diff --git a/src/server.cpp b/src/server.cpp index 92870f972..68b0131d4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1504,17 +1504,15 @@ void Server::SendShowFormspecMessage(session_t peer_id, const std::string &forms // Spawns a particle on peer with peer_id void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version, - v3f pos, v3f velocity, v3f acceleration, - float expirationtime, float size, bool collisiondetection, - bool collision_removal, bool object_collision, - bool vertical, const std::string &texture, - const struct TileAnimationParams &animation, u8 glow) + const ParticleParameters &p) { static thread_local const float radius = g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS; if (peer_id == PEER_ID_INEXISTENT) { std::vector clients = m_clients.getClientIDs(); + const v3f pos = p.pos * BS; + const float radius_sq = radius * radius; for (const session_t client_id : clients) { RemotePlayer *player = m_env->getPlayer(client_id); @@ -1526,76 +1524,59 @@ void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version, continue; // Do not send to distant clients - if (sao->getBasePosition().getDistanceFrom(pos * BS) > radius) + if (sao->getBasePosition().getDistanceFromSQ(pos) > radius_sq) continue; - SendSpawnParticle(client_id, player->protocol_version, - pos, velocity, acceleration, - expirationtime, size, collisiondetection, collision_removal, - object_collision, vertical, texture, animation, glow); + SendSpawnParticle(client_id, player->protocol_version, p); } return; } + assert(protocol_version != 0); NetworkPacket pkt(TOCLIENT_SPAWN_PARTICLE, 0, peer_id); - pkt << pos << velocity << acceleration << expirationtime - << size << collisiondetection; - pkt.putLongString(texture); - pkt << vertical; - pkt << collision_removal; - // This is horrible but required (why are there two ways to serialize pkts?) - std::ostringstream os(std::ios_base::binary); - animation.serialize(os, protocol_version); - pkt.putRawString(os.str()); - pkt << glow; - pkt << object_collision; + { + // NetworkPacket and iostreams are incompatible... + std::ostringstream oss(std::ios_base::binary); + p.serialize(oss, protocol_version); + pkt.putRawString(oss.str()); + } Send(&pkt); } // Adds a ParticleSpawner on peer with peer_id void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, - u16 amount, float spawntime, v3f minpos, v3f maxpos, - v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, - float minsize, float maxsize, bool collisiondetection, bool collision_removal, - bool object_collision, u16 attached_id, bool vertical, const std::string &texture, u32 id, - const struct TileAnimationParams &animation, u8 glow) + const ParticleSpawnerParameters &p, u16 attached_id, u32 id) { if (peer_id == PEER_ID_INEXISTENT) { - // This sucks and should be replaced: std::vector clients = m_clients.getClientIDs(); for (const session_t client_id : clients) { RemotePlayer *player = m_env->getPlayer(client_id); if (!player) continue; SendAddParticleSpawner(client_id, player->protocol_version, - amount, spawntime, minpos, maxpos, - minvel, maxvel, minacc, maxacc, minexptime, maxexptime, - minsize, maxsize, collisiondetection, collision_removal, - object_collision, attached_id, vertical, texture, id, - animation, glow); + p, attached_id, id); } return; } + assert(protocol_version != 0); - NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 0, peer_id); + NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 100, peer_id); - pkt << amount << spawntime << minpos << maxpos << minvel << maxvel - << minacc << maxacc << minexptime << maxexptime << minsize - << maxsize << collisiondetection; + pkt << p.amount << p.time << p.minpos << p.maxpos << p.minvel + << p.maxvel << p.minacc << p.maxacc << p.minexptime << p.maxexptime + << p.minsize << p.maxsize << p.collisiondetection; - pkt.putLongString(texture); + pkt.putLongString(p.texture); - pkt << id << vertical; - pkt << collision_removal; - pkt << attached_id; - // This is horrible but required - std::ostringstream os(std::ios_base::binary); - animation.serialize(os, protocol_version); - pkt.putRawString(os.str()); - pkt << glow; - pkt << object_collision; + pkt << id << p.vertical << p.collision_removal << attached_id; + { + std::ostringstream os(std::ios_base::binary); + p.animation.serialize(os, protocol_version); + pkt.putRawString(os.str()); + } + pkt << p.glow << p.object_collision; Send(&pkt); } @@ -1604,7 +1585,6 @@ void Server::SendDeleteParticleSpawner(session_t peer_id, u32 id) { NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER, 4, peer_id); - // Ugly error in this packet pkt << id; if (peer_id != PEER_ID_INEXISTENT) @@ -3365,12 +3345,8 @@ void Server::notifyPlayers(const std::wstring &msg) SendChatMessage(PEER_ID_INEXISTENT, ChatMessage(msg)); } -void Server::spawnParticle(const std::string &playername, v3f pos, - v3f velocity, v3f acceleration, - float expirationtime, float size, bool - collisiondetection, bool collision_removal, bool object_collision, - bool vertical, const std::string &texture, - const struct TileAnimationParams &animation, u8 glow) +void Server::spawnParticle(const std::string &playername, + const ParticleParameters &p) { // m_env will be NULL if the server is initializing if (!m_env) @@ -3386,18 +3362,11 @@ void Server::spawnParticle(const std::string &playername, v3f pos, proto_ver = player->protocol_version; } - SendSpawnParticle(peer_id, proto_ver, pos, velocity, acceleration, - expirationtime, size, collisiondetection, collision_removal, - object_collision, vertical, texture, animation, glow); + SendSpawnParticle(peer_id, proto_ver, p); } -u32 Server::addParticleSpawner(u16 amount, float spawntime, - v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, - float minexptime, float maxexptime, float minsize, float maxsize, - bool collisiondetection, bool collision_removal, bool object_collision, - ServerActiveObject *attached, bool vertical, const std::string &texture, - const std::string &playername, const struct TileAnimationParams &animation, - u8 glow) +u32 Server::addParticleSpawner(const ParticleSpawnerParameters &p, + ServerActiveObject *attached, const std::string &playername) { // m_env will be NULL if the server is initializing if (!m_env) @@ -3417,16 +3386,11 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, u32 id; if (attached_id == 0) - id = m_env->addParticleSpawner(spawntime); + id = m_env->addParticleSpawner(p.time); else - id = m_env->addParticleSpawner(spawntime, attached_id); - - SendAddParticleSpawner(peer_id, proto_ver, amount, spawntime, - minpos, maxpos, minvel, maxvel, minacc, maxacc, - minexptime, maxexptime, minsize, maxsize, collisiondetection, - collision_removal, object_collision, attached_id, vertical, - texture, id, animation, glow); + id = m_env->addParticleSpawner(p.time, attached_id); + SendAddParticleSpawner(peer_id, proto_ver, p, attached_id, id); return id; } diff --git a/src/server.h b/src/server.h index 7a1de9370..27943cc29 100644 --- a/src/server.h +++ b/src/server.h @@ -27,7 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content/mods.h" #include "inventorymanager.h" #include "content/subgames.h" -#include "tileanimation.h" // struct TileAnimationParams +#include "tileanimation.h" // TileAnimationParams +#include "particles.h" // ParticleParams #include "network/peerhandler.h" #include "network/address.h" #include "util/numeric.h" @@ -226,24 +227,12 @@ public: void notifyPlayer(const char *name, const std::wstring &msg); void notifyPlayers(const std::wstring &msg); + void spawnParticle(const std::string &playername, - v3f pos, v3f velocity, v3f acceleration, - float expirationtime, float size, - bool collisiondetection, bool collision_removal, bool object_collision, - bool vertical, const std::string &texture, - const struct TileAnimationParams &animation, u8 glow); - - u32 addParticleSpawner(u16 amount, float spawntime, - v3f minpos, v3f maxpos, - v3f minvel, v3f maxvel, - v3f minacc, v3f maxacc, - float minexptime, float maxexptime, - float minsize, float maxsize, - bool collisiondetection, bool collision_removal, bool object_collision, - ServerActiveObject *attached, - bool vertical, const std::string &texture, - const std::string &playername, const struct TileAnimationParams &animation, - u8 glow); + const ParticleParameters &p); + + u32 addParticleSpawner(const ParticleSpawnerParameters &p, + ServerActiveObject *attached, const std::string &playername); void deleteParticleSpawner(const std::string &playername, u32 id); @@ -453,26 +442,13 @@ private: // Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all) void SendAddParticleSpawner(session_t peer_id, u16 protocol_version, - u16 amount, float spawntime, - v3f minpos, v3f maxpos, - v3f minvel, v3f maxvel, - v3f minacc, v3f maxacc, - float minexptime, float maxexptime, - float minsize, float maxsize, - bool collisiondetection, bool collision_removal, bool object_collision, - u16 attached_id, - bool vertical, const std::string &texture, u32 id, - const struct TileAnimationParams &animation, u8 glow); + const ParticleSpawnerParameters &p, u16 attached_id, u32 id); void SendDeleteParticleSpawner(session_t peer_id, u32 id); // Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all) void SendSpawnParticle(session_t peer_id, u16 protocol_version, - v3f pos, v3f velocity, v3f acceleration, - float expirationtime, float size, - bool collisiondetection, bool collision_removal, bool object_collision, - bool vertical, const std::string &texture, - const struct TileAnimationParams &animation, u8 glow); + const ParticleParameters &p); void SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersao); void SendActiveObjectMessages(session_t peer_id, const std::string &datas, -- cgit v1.2.3 From 7ab0c0662a95eb504665c940f92c2fde895929be Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 22 May 2020 14:19:07 +0200 Subject: MacOS: Fix environ not being found --- src/porting.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/porting.cpp b/src/porting.cpp index ef1640467..29af62f7d 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -49,6 +49,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #if defined(__ANDROID__) #include "porting_android.h" #endif +#if defined(__APPLE__) + // For _NSGetEnviron() + // Related: https://gitlab.haskell.org/ghc/ghc/issues/2458 + #include +#endif #include "config.h" #include "debug.h" @@ -718,7 +723,8 @@ bool openURL(const std::string &url) return true; #elif defined(__APPLE__) const char *argv[] = {"open", url.c_str(), NULL}; - return posix_spawnp(NULL, "open", NULL, NULL, (char**)argv, environ) == 0; + return posix_spawnp(NULL, "open", NULL, NULL, (char**)argv, + (*_NSGetEnviron())) == 0; #else const char *argv[] = {"xdg-open", url.c_str(), NULL}; return posix_spawnp(NULL, "xdg-open", NULL, NULL, (char**)argv, environ) == 0; -- cgit v1.2.3 From e79bc40c0a5312baf4e8c3e33048d50b41b4a2ff Mon Sep 17 00:00:00 2001 From: Lejo1 Date: Wed, 20 May 2020 21:54:52 +0200 Subject: Check for valid base64 before decoding (#9904) --- doc/lua_api.txt | 2 +- src/script/lua_api/l_util.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 0101bd4cf..bd0cb8acb 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -5449,7 +5449,7 @@ Misc. * Example: `minetest.rgba(10, 20, 30, 40)`, returns `"#0A141E28"` * `minetest.encode_base64(string)`: returns string encoded in base64 * Encodes a string in base64. -* `minetest.decode_base64(string)`: returns string +* `minetest.decode_base64(string)`: returns string or nil for invalid base64 * Decodes a string encoded in base64. * `minetest.is_protected(pos, name)`: returns boolean * Returning `true` restricts the player `name` from modifying (i.e. digging, diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 28ee39fc8..cd63e20c2 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -318,9 +318,13 @@ int ModApiUtil::l_decode_base64(lua_State *L) NO_MAP_LOCK_REQUIRED; size_t size; - const char *data = luaL_checklstring(L, 1, &size); + const char *d = luaL_checklstring(L, 1, &size); + const std::string data = std::string(d, size); + + if (!base64_is_valid(data)) + return 0; - std::string out = base64_decode(std::string(data, size)); + std::string out = base64_decode(data); lua_pushlstring(L, out.data(), out.size()); return 1; -- cgit v1.2.3 From 037422fdba9a47bd538480988fbf8aad67d66c85 Mon Sep 17 00:00:00 2001 From: Awkor Date: Sat, 23 May 2020 13:23:05 +0200 Subject: Modernize include guards and add missing ones (#9898) --- src/client/hud.h | 4 +--- src/client/render/factory.h | 2 ++ src/gui/guiButtonImage.h | 2 ++ src/gui/guiButtonItemImage.h | 2 ++ src/hud.h | 4 +--- src/script/lua_api/l_particles_local.h | 2 ++ src/util/md32_common.h | 2 ++ 7 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/client/hud.h b/src/client/hud.h index 6274b1a83..e2abf326c 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -18,8 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef CLIENT_HUD_HEADER -#define CLIENT_HUD_HEADER +#pragma once #include #include @@ -147,4 +146,3 @@ void drawItemStack( const v3s16 &angle, const v3s16 &rotation_speed); -#endif diff --git a/src/client/render/factory.h b/src/client/render/factory.h index 22738404a..e3339a836 100644 --- a/src/client/render/factory.h +++ b/src/client/render/factory.h @@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#pragma once + #include #include "core.h" diff --git a/src/gui/guiButtonImage.h b/src/gui/guiButtonImage.h index a948d772b..59a25b4f0 100644 --- a/src/gui/guiButtonImage.h +++ b/src/gui/guiButtonImage.h @@ -17,6 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#pragma once + #include "guiButton.h" #include "IGUIButton.h" diff --git a/src/gui/guiButtonItemImage.h b/src/gui/guiButtonItemImage.h index 9cd0f6188..aad923bda 100644 --- a/src/gui/guiButtonItemImage.h +++ b/src/gui/guiButtonItemImage.h @@ -17,6 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#pragma once + #include "guiButton.h" #include "IGUIButton.h" diff --git a/src/hud.h b/src/hud.h index bab420ed2..e015baec1 100644 --- a/src/hud.h +++ b/src/hud.h @@ -18,8 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef HUD_HEADER -#define HUD_HEADER +#pragma once #include "irrlichttypes_extrabloated.h" #include @@ -101,4 +100,3 @@ extern const EnumString es_HudElementType[]; extern const EnumString es_HudElementStat[]; extern const EnumString es_HudBuiltinElement[]; -#endif diff --git a/src/script/lua_api/l_particles_local.h b/src/script/lua_api/l_particles_local.h index 5dff153b3..d8bb2b1c6 100644 --- a/src/script/lua_api/l_particles_local.h +++ b/src/script/lua_api/l_particles_local.h @@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#pragma once + #include "lua_api/l_base.h" class ModApiParticlesLocal : public ModApiBase diff --git a/src/util/md32_common.h b/src/util/md32_common.h index 085d1d7a5..a4c2099c9 100644 --- a/src/util/md32_common.h +++ b/src/util/md32_common.h @@ -109,6 +109,8 @@ * */ +#pragma once + #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) # error "DATA_ORDER must be defined!" #endif -- cgit v1.2.3 From 15ba75e4cf1d1b8ceaa9d8ce33dcfdd7dbe80741 Mon Sep 17 00:00:00 2001 From: sorcerykid Date: Sat, 23 May 2020 06:24:06 -0500 Subject: Add on_authplayer callback and 'last_login' to on_joinplayer (#9574) Replace on_auth_fail callback with more versatile on_authplayer Better clarify account login process in Lua API documentation Change initial timestamp for newly registered accounts to -1 --- builtin/game/auth.lua | 3 +-- builtin/game/chat.lua | 2 +- builtin/game/deprecated.lua | 16 ++++++++++++++ builtin/game/register.lua | 2 +- doc/lua_api.txt | 20 ++++++++++------- src/network/serverpackethandler.cpp | 44 +++++++++++++++++++------------------ src/script/cpp_api/s_player.cpp | 19 +++++++++++----- src/script/cpp_api/s_player.h | 4 ++-- src/script/cpp_api/s_server.cpp | 14 ++++++++---- src/script/cpp_api/s_server.h | 3 ++- 10 files changed, 81 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 7aedfc82e..fc061666c 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -41,7 +41,6 @@ core.builtin_auth_handler = { return { password = auth_entry.password, privileges = privileges, - -- Is set to nil if unknown last_login = auth_entry.last_login, } end, @@ -53,7 +52,7 @@ core.builtin_auth_handler = { name = name, password = password, privileges = core.string_to_privs(core.settings:get("default_privs")), - last_login = os.time(), + last_login = -1, -- Defer login time calculation until record_login (called by on_joinplayer) }) end, delete_auth = function(name) diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index b9f84e522..aae811794 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -1068,7 +1068,7 @@ core.register_chatcommand("last-login", { param = name end local pauth = core.get_auth_handler().get_auth(param) - if pauth and pauth.last_login then + if pauth and pauth.last_login and pauth.last_login ~= -1 then -- Time in UTC, ISO 8601 format return true, "Last login time was " .. os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login) diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 73e105eb8..20f0482eb 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -70,3 +70,19 @@ core.setting_get = setting_proxy("get") core.setting_setbool = setting_proxy("set_bool") core.setting_getbool = setting_proxy("get_bool") core.setting_save = setting_proxy("write") + +-- +-- core.register_on_auth_fail +-- + +function core.register_on_auth_fail(func) + core.log("deprecated", "core.register_on_auth_fail " .. + "is obsolete and should be replaced by " .. + "core.register_on_authplayer instead.") + + core.register_on_authplayer(function (player_name, ip, is_success) + if not is_success then + func(player_name, ip) + end + end) +end diff --git a/builtin/game/register.lua b/builtin/game/register.lua index eb6c2897c..1034d4f2b 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -607,9 +607,9 @@ core.registered_on_item_eats, core.register_on_item_eat = make_registration() core.registered_on_punchplayers, core.register_on_punchplayer = make_registration() core.registered_on_priv_grant, core.register_on_priv_grant = make_registration() core.registered_on_priv_revoke, core.register_on_priv_revoke = make_registration() +core.registered_on_authplayers, core.register_on_authplayer = make_registration() core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_registration() core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration() -core.registered_on_auth_fail, core.register_on_auth_fail = make_registration() core.registered_on_player_inventory_actions, core.register_on_player_inventory_action = make_registration() core.registered_allow_player_inventory_actions, core.register_allow_player_inventory_action = make_registration() diff --git a/doc/lua_api.txt b/doc/lua_api.txt index bd0cb8acb..26061eccb 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4374,7 +4374,7 @@ Call these functions only at load time! * Called after generating a piece of world. Modifying nodes inside the area is a bit faster than usually. * `minetest.register_on_newplayer(function(ObjectRef))` - * Called after a new player has been created + * Called when a new player enters the world for the first time * `minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage))` * Called when a player is punched * Note: This callback is invoked even if the punched player is dead. @@ -4415,19 +4415,23 @@ Call these functions only at load time! * Called _before_ repositioning of player occurs * return true in func to disable regular player placement * `minetest.register_on_prejoinplayer(function(name, ip))` - * Called before a player joins the game - * If it returns a string, the player is disconnected with that string as + * Called when a client connects to the server, prior to authentication + * If it returns a string, the client is disconnected with that string as reason. -* `minetest.register_on_joinplayer(function(ObjectRef))` +* `minetest.register_on_joinplayer(function(ObjectRef, last_login))` * Called when a player joins the game + * `last_login`: The timestamp of the previous login, or nil if player is new * `minetest.register_on_leaveplayer(function(ObjectRef, timed_out))` * Called when a player leaves the game * `timed_out`: True for timeout, false for other reasons. +* `minetest.register_on_authplayer(function(name, ip, is_success))` + * Called when a client attempts to log into an account. + * `name`: The name of the account being authenticated. + * `ip`: The IP address of the client + * `is_success`: Whether the client was successfully authenticated + * For newly registered accounts, `is_success` will always be true * `minetest.register_on_auth_fail(function(name, ip))` - * Called when a client attempts to log into an account but supplies the - wrong password. - * `ip`: The IP address of the client. - * `name`: The account the client attempted to log into. + * Deprecated: use `minetest.register_on_authplayer(name, ip, is_success)` instead. * `minetest.register_on_cheat(function(ObjectRef, cheat))` * Called when a player cheats * `cheat`: `{type=}`, where `` is one of: diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 2fa9d4196..fed3b6f85 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -409,9 +409,12 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt) // (u16) 1 + std::string represents a pseudo vector serialization representation notice_pkt << (u8) PLAYER_LIST_ADD << (u16) 1 << std::string(playersao->getPlayer()->getName()); m_clients.sendToAll(¬ice_pkt); - m_clients.event(peer_id, CSE_SetClientReady); - m_script->on_joinplayer(playersao); + + s64 last_login; + m_script->getAuth(playersao->getPlayer()->getName(), nullptr, nullptr, &last_login); + m_script->on_joinplayer(playersao, last_login); + // Send shutdown timer if shutdown has been scheduled if (m_shutdown_state.isTimerRunning()) { SendChatMessage(peer_id, m_shutdown_state.getShutdownTimerMessage()); @@ -1512,6 +1515,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) initial_ver_key = encode_srp_verifier(verification_key, salt); m_script->createAuth(playername, initial_ver_key); + m_script->on_authplayer(playername, addr_s, true); acceptAuth(peer_id, false); } else { @@ -1648,24 +1652,25 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) session_t peer_id = pkt->getPeerId(); RemoteClient *client = getClient(peer_id, CS_Invalid); ClientState cstate = client->getState(); + std::string addr_s = getPeerAddress(pkt->getPeerId()).serializeString(); + std::string playername = client->getName(); bool wantSudo = (cstate == CS_Active); verbosestream << "Server: Received TOCLIENT_SRP_BYTES_M." << std::endl; if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) { - actionstream << "Server: got SRP _M packet in wrong state " << cstate << - " from " << getPeerAddress(peer_id).serializeString() << - ". Ignoring." << std::endl; + actionstream << "Server: got SRP _M packet in wrong state " + << cstate << " from " << addr_s + << ". Ignoring." << std::endl; return; } if (client->chosen_mech != AUTH_MECHANISM_SRP && client->chosen_mech != AUTH_MECHANISM_LEGACY_PASSWORD) { - actionstream << "Server: got SRP _M packet, while auth is going on " - "with mech " << client->chosen_mech << " from " << - getPeerAddress(peer_id).serializeString() << - " (wantSudo=" << wantSudo << "). Denying." << std::endl; + actionstream << "Server: got SRP _M packet, while auth" + << "is going on with mech " << client->chosen_mech << " from " + << addr_s << " (wantSudo=" << wantSudo << "). Denying." << std::endl; if (wantSudo) { DenySudoAccess(peer_id); return; @@ -1680,9 +1685,8 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) if (srp_verifier_get_session_key_length((SRPVerifier *) client->auth_data) != bytes_M.size()) { - actionstream << "Server: User " << client->getName() << " at " << - getPeerAddress(peer_id).serializeString() << - " sent bytes_M with invalid length " << bytes_M.size() << std::endl; + actionstream << "Server: User " << playername << " at " << addr_s + << " sent bytes_M with invalid length " << bytes_M.size() << std::endl; DenyAccess(peer_id, SERVER_ACCESSDENIED_UNEXPECTED_DATA); return; } @@ -1694,24 +1698,21 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) if (!bytes_HAMK) { if (wantSudo) { - actionstream << "Server: User " << client->getName() << " at " << - getPeerAddress(peer_id).serializeString() << - " tried to change their password, but supplied wrong (SRP) " - "password for authentication." << std::endl; + actionstream << "Server: User " << playername << " at " << addr_s + << " tried to change their password, but supplied wrong" + << " (SRP) password for authentication." << std::endl; DenySudoAccess(peer_id); return; } - std::string ip = getPeerAddress(peer_id).serializeString(); - actionstream << "Server: User " << client->getName() << " at " << ip << - " supplied wrong password (auth mechanism: SRP)." << std::endl; - m_script->on_auth_failure(client->getName(), ip); + actionstream << "Server: User " << playername << " at " << addr_s + << " supplied wrong password (auth mechanism: SRP)." << std::endl; + m_script->on_authplayer(playername, addr_s, false); DenyAccess(peer_id, SERVER_ACCESSDENIED_WRONG_PASSWORD); return; } if (client->create_player_on_auth_success) { - std::string playername = client->getName(); m_script->createAuth(playername, client->enc_pwd); std::string checkpwd; // not used, but needed for passing something @@ -1725,6 +1726,7 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) client->create_player_on_auth_success = false; } + m_script->on_authplayer(playername, addr_s, true); acceptAuth(peer_id, wantSudo); } diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index df67ea00c..712120c61 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -147,7 +147,7 @@ bool ScriptApiPlayer::can_bypass_userlimit(const std::string &name, const std::s return lua_toboolean(L, -1); } -void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) +void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player, s64 last_login) { SCRIPTAPI_PRECHECKHEADER @@ -156,7 +156,11 @@ void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) lua_getfield(L, -1, "registered_on_joinplayers"); // Call callbacks objectrefGetOrCreate(L, player); - runCallbacks(1, RUN_CALLBACKS_MODE_FIRST); + if (last_login != -1) + lua_pushinteger(L, last_login); + else + lua_pushnil(L); + runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player, @@ -216,16 +220,19 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, runCallbacks(3, RUN_CALLBACKS_MODE_OR_SC); } -void ScriptApiPlayer::on_auth_failure(const std::string &name, const std::string &ip) +void ScriptApiPlayer::on_authplayer(const std::string &name, const std::string &ip, bool is_success) { SCRIPTAPI_PRECHECKHEADER - // Get core.registered_on_auth_failure + // Get core.registered_on_authplayers lua_getglobal(L, "core"); - lua_getfield(L, -1, "registered_on_auth_fail"); + lua_getfield(L, -1, "registered_on_authplayers"); + + // Call callbacks lua_pushstring(L, name.c_str()); lua_pushstring(L, ip.c_str()); - runCallbacks(2, RUN_CALLBACKS_MODE_FIRST); + lua_pushboolean(L, is_success); + runCallbacks(3, RUN_CALLBACKS_MODE_FIRST); } void ScriptApiPlayer::pushMoveArguments( diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index 7ca3d8f30..a337f975b 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -41,7 +41,7 @@ public: bool on_prejoinplayer(const std::string &name, const std::string &ip, std::string *reason); bool can_bypass_userlimit(const std::string &name, const std::string &ip); - void on_joinplayer(ServerActiveObject *player); + void on_joinplayer(ServerActiveObject *player, s64 last_login); void on_leaveplayer(ServerActiveObject *player, bool timeout); void on_cheat(ServerActiveObject *player, const std::string &cheat_type); bool on_punchplayer(ServerActiveObject *player, ServerActiveObject *hitter, @@ -51,7 +51,7 @@ public: const PlayerHPChangeReason &reason); void on_playerReceiveFields(ServerActiveObject *player, const std::string &formname, const StringMap &fields); - void on_auth_failure(const std::string &name, const std::string &ip); + void on_authplayer(const std::string &name, const std::string &ip, bool is_success); // Player inventory callbacks // Return number of accepted items to be moved diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp index 1ce2f9d45..96cb28b28 100644 --- a/src/script/cpp_api/s_server.cpp +++ b/src/script/cpp_api/s_server.cpp @@ -23,7 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., bool ScriptApiServer::getAuth(const std::string &playername, std::string *dst_password, - std::set *dst_privs) + std::set *dst_privs, + s64 *dst_last_login) { SCRIPTAPI_PRECHECKHEADER @@ -43,8 +44,7 @@ bool ScriptApiServer::getAuth(const std::string &playername, luaL_checktype(L, -1, LUA_TTABLE); std::string password; - bool found = getstringfield(L, -1, "password", password); - if (!found) + if (!getstringfield(L, -1, "password", password)) throw LuaError("Authentication handler didn't return password"); if (dst_password) *dst_password = password; @@ -54,7 +54,13 @@ bool ScriptApiServer::getAuth(const std::string &playername, throw LuaError("Authentication handler didn't return privilege table"); if (dst_privs) readPrivileges(-1, *dst_privs); - lua_pop(L, 1); + lua_pop(L, 1); // Remove key from privs table + + s64 last_login; + if(!getintfield(L, -1, "last_login", last_login)) + throw LuaError("Authentication handler didn't return last_login"); + if (dst_last_login) + *dst_last_login = (s64)last_login; return true; } diff --git a/src/script/cpp_api/s_server.h b/src/script/cpp_api/s_server.h index a4cede84d..d8639cba7 100644 --- a/src/script/cpp_api/s_server.h +++ b/src/script/cpp_api/s_server.h @@ -43,7 +43,8 @@ public: /* auth */ bool getAuth(const std::string &playername, std::string *dst_password, - std::set *dst_privs); + std::set *dst_privs, + s64 *dst_last_login = nullptr); void createAuth(const std::string &playername, const std::string &password); bool setPassword(const std::string &playername, -- cgit v1.2.3 From 9d6e7e48d6fb1daff8fedcb2f111164bef61f1e7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 22 May 2020 14:17:03 +0200 Subject: Implement spawning particles with node texture appearance --- build/android/native/jni/Android.mk | 1 + doc/lua_api.txt | 30 ++++++++++++- src/client/particles.cpp | 75 ++++++++++++++++++++++++-------- src/client/particles.h | 4 +- src/network/clientpackethandler.cpp | 10 +++++ src/particles.cpp | 10 +++++ src/particles.h | 6 +++ src/script/lua_api/l_particles.cpp | 14 ++++++ src/script/lua_api/l_particles_local.cpp | 14 ++++++ src/server.cpp | 1 + 10 files changed, 145 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/build/android/native/jni/Android.mk b/build/android/native/jni/Android.mk index a5cb099e6..140947e6a 100644 --- a/build/android/native/jni/Android.mk +++ b/build/android/native/jni/Android.mk @@ -164,6 +164,7 @@ LOCAL_SRC_FILES := \ ../../../src/noise.cpp \ ../../../src/objdef.cpp \ ../../../src/object_properties.cpp \ + ../../../src/particles.cpp \ ../../../src/pathfinder.cpp \ ../../../src/player.cpp \ ../../../src/porting.cpp \ diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 26061eccb..5b3f61c99 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -7835,6 +7835,8 @@ Used by `minetest.add_particle`. size = 1, -- Scales the visual size of the particle texture. + -- If `node` is set, size can be set to 0 to spawn a randomly-sized + -- particle (just like actual node dig particles). collisiondetection = false, -- If true collides with `walkable` nodes and, depending on the @@ -7853,6 +7855,7 @@ Used by `minetest.add_particle`. -- If true faces player using y axis only texture = "image.png", + -- The texture of the particle playername = "singleplayer", -- Optional, if specified spawns particle only on the player's client @@ -7863,6 +7866,17 @@ Used by `minetest.add_particle`. glow = 0 -- Optional, specify particle self-luminescence in darkness. -- Values 0-14. + + node = {name = "ignore", param2 = 0}, + -- Optional, if specified the particle will have the same appearance as + -- node dig particles for the given node. + -- `texture` and `animation` will be ignored if this is set. + + node_tile = 0, + -- Optional, only valid in combination with `node` + -- If set to a valid number 1-6, specifies the tile from which the + -- particle texture is picked. + -- Otherwise, the default behavior is used. (currently: any random tile) } @@ -7892,7 +7906,9 @@ Used by `minetest.add_particlespawner`. maxsize = 1, -- The particles' properties are random values between the min and max -- values. - -- pos, velocity, acceleration, expirationtime, size + -- applies to: pos, velocity, acceleration, expirationtime, size + -- If `node` is set, min and maxsize can be set to 0 to spawn + -- randomly-sized particles (just like actual node dig particles). collisiondetection = false, -- If true collide with `walkable` nodes and, depending on the @@ -7915,6 +7931,7 @@ Used by `minetest.add_particlespawner`. -- If true face player using y axis only texture = "image.png", + -- The texture of the particle playername = "singleplayer", -- Optional, if specified spawns particles only on the player's client @@ -7925,6 +7942,17 @@ Used by `minetest.add_particlespawner`. glow = 0 -- Optional, specify particle self-luminescence in darkness. -- Values 0-14. + + node = {name = "ignore", param2 = 0}, + -- Optional, if specified the particles will have the same appearance as + -- node dig particles for the given node. + -- `texture` and `animation` will be ignored if this is set. + + node_tile = 0, + -- Optional, only valid in combination with `node` + -- If set to a valid number 1-6, specifies the tile from which the + -- particle texture is picked. + -- Otherwise, the default behavior is used. (currently: any random tile) } `HTTPRequest` definition diff --git a/src/client/particles.cpp b/src/client/particles.cpp index c2e751b4f..c78a3e71a 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -304,18 +304,37 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius, } pp.expirationtime = random_f32(p.minexptime, p.maxexptime); - pp.size = random_f32(p.minsize, p.maxsize); - p.copyCommon(pp); + video::ITexture *texture; + v2f texpos, texsize; + video::SColor color(0xFFFFFFFF); + + if (p.node.getContent() != CONTENT_IGNORE) { + const ContentFeatures &f = + m_particlemanager->m_env->getGameDef()->ndef()->get(p.node); + if (!ParticleManager::getNodeParticleParams(p.node, f, pp, &texture, + texpos, texsize, &color, p.node_tile)) + return; + } else { + texture = m_texture; + texpos = v2f(0.0f, 0.0f); + texsize = v2f(1.0f, 1.0f); + } + + // Allow keeping default random size + if (p.maxsize > 0.0f) + pp.size = random_f32(p.minsize, p.maxsize); + m_particlemanager->addParticle(new Particle( m_gamedef, m_player, env, pp, - m_texture, - v2f(0.0, 0.0), - v2f(1.0, 1.0) + texture, + texpos, + texsize, + color )); } @@ -460,17 +479,35 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, break; } case CE_SPAWN_PARTICLE: { - const ParticleParameters &p = *event->spawn_particle; - video::ITexture *texture = - client->tsrc()->getTextureForMesh(p.texture); + ParticleParameters &p = *event->spawn_particle; - Particle *toadd = new Particle(client, player, m_env, - p, - texture, - v2f(0.0, 0.0), - v2f(1.0, 1.0)); + video::ITexture *texture; + v2f texpos, texsize; + video::SColor color(0xFFFFFFFF); + + f32 oldsize = p.size; + + if (p.node.getContent() != CONTENT_IGNORE) { + const ContentFeatures &f = m_env->getGameDef()->ndef()->get(p.node); + if (!getNodeParticleParams(p.node, f, p, &texture, texpos, + texsize, &color, p.node_tile)) + texture = nullptr; + } else { + texture = client->tsrc()->getTextureForMesh(p.texture); + texpos = v2f(0.0f, 0.0f); + texsize = v2f(1.0f, 1.0f); + } + + // Allow keeping default random size + if (oldsize > 0.0f) + p.size = oldsize; - addParticle(toadd); + if (texture) { + Particle *toadd = new Particle(client, player, m_env, + p, texture, texpos, texsize, color); + + addParticle(toadd); + } delete event->spawn_particle; break; @@ -480,15 +517,19 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, } bool ParticleManager::getNodeParticleParams(const MapNode &n, - const ContentFeatures &f, ParticleParameters &p, - video::ITexture **texture, v2f &texpos, v2f &texsize, video::SColor *color) + const ContentFeatures &f, ParticleParameters &p, video::ITexture **texture, + v2f &texpos, v2f &texsize, video::SColor *color, u8 tilenum) { // No particles for "airlike" nodes if (f.drawtype == NDT_AIRLIKE) return false; // Texture - u8 texid = rand() % 6; + u8 texid; + if (tilenum > 0 && tilenum <= 6) + texid = tilenum - 1; + else + texid = rand() % 6; const TileLayer &tile = f.tiles[texid].layers[0]; p.animation.type = TAT_NONE; diff --git a/src/client/particles.h b/src/client/particles.h index 7dda0e1b1..2011f0262 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -42,7 +42,7 @@ class Particle : public scene::ISceneNode video::ITexture *texture, v2f texpos, v2f texsize, - video::SColor color = video::SColor(0xFFFFFFFF) + video::SColor color ); ~Particle() = default; @@ -171,7 +171,7 @@ public: protected: static bool getNodeParticleParams(const MapNode &n, const ContentFeatures &f, ParticleParameters &p, video::ITexture **texture, v2f &texpos, - v2f &texsize, video::SColor *color); + v2f &texsize, video::SColor *color, u8 tilenum = 0); void addParticle(Particle* toadd); diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 054e60c3c..e000acc92 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1003,6 +1003,16 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt) p.glow = readU8(is); p.object_collision = readU8(is); + // This is kinda awful + do { + u16 tmp_param0 = readU16(is); + if (is.eof()) + break; + p.node.param0 = tmp_param0; + p.node.param2 = readU8(is); + p.node_tile = readU8(is); + } while (0); + auto event = new ClientEvent(); event->type = CE_ADD_PARTICLESPAWNER; event->add_particlespawner.p = new ParticleSpawnerParameters(p); diff --git a/src/particles.cpp b/src/particles.cpp index 711d189f6..fd81238dc 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -34,6 +34,9 @@ void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const animation.serialize(os, 6); /* NOT the protocol ver */ writeU8(os, glow); writeU8(os, object_collision); + writeU16(os, node.param0); + writeU8(os, node.param2); + writeU8(os, node_tile); } void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) @@ -50,4 +53,11 @@ void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) animation.deSerialize(is, 6); /* NOT the protocol ver */ glow = readU8(is); object_collision = readU8(is); + // This is kinda awful + u16 tmp_param0 = readU16(is); + if (is.eof()) + return; + node.param0 = tmp_param0; + node.param2 = readU8(is); + node_tile = readU8(is); } diff --git a/src/particles.h b/src/particles.h index 659c1249f..6f518b771 100644 --- a/src/particles.h +++ b/src/particles.h @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "irrlichttypes_bloated.h" #include "tileanimation.h" +#include "mapnode.h" // This file defines the particle-related structures that both the server and // client need. The ParticleManager and rendering is in client/particles.h @@ -34,9 +35,12 @@ struct CommonParticleParams { std::string texture; struct TileAnimationParams animation; u8 glow = 0; + MapNode node; + u8 node_tile = 0; CommonParticleParams() { animation.type = TAT_NONE; + node.setContent(CONTENT_IGNORE); } /* This helper is useful for copying params from @@ -49,6 +53,8 @@ struct CommonParticleParams { to.texture = texture; to.animation = animation; to.glow = glow; + to.node = node; + to.node_tile = node_tile; } }; diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index 7680aa17b..a51c4fe20 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -111,6 +111,13 @@ int ModApiParticles::l_add_particle(lua_State *L) p.texture = getstringfield_default(L, 1, "texture", p.texture); p.glow = getintfield_default(L, 1, "glow", p.glow); + lua_getfield(L, 1, "node"); + if (lua_istable(L, -1)) + p.node = readnode(L, -1, getGameDef(L)->ndef()); + lua_pop(L, 1); + + p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile); + playername = getstringfield_default(L, 1, "playername", ""); } @@ -231,6 +238,13 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) p.texture = getstringfield_default(L, 1, "texture", p.texture); playername = getstringfield_default(L, 1, "playername", ""); p.glow = getintfield_default(L, 1, "glow", p.glow); + + lua_getfield(L, 1, "node"); + if (lua_istable(L, -1)) + p.node = readnode(L, -1, getGameDef(L)->ndef()); + lua_pop(L, 1); + + p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile); } u32 id = getServer(L)->addParticleSpawner(p, attached, playername); diff --git a/src/script/lua_api/l_particles_local.cpp b/src/script/lua_api/l_particles_local.cpp index 9595b2fab..cc68b13a5 100644 --- a/src/script/lua_api/l_particles_local.cpp +++ b/src/script/lua_api/l_particles_local.cpp @@ -67,6 +67,13 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L) p.texture = getstringfield_default(L, 1, "texture", p.texture); p.glow = getintfield_default(L, 1, "glow", p.glow); + lua_getfield(L, 1, "node"); + if (lua_istable(L, -1)) + p.node = readnode(L, -1, getGameDef(L)->ndef()); + lua_pop(L, 1); + + p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile); + ClientEvent *event = new ClientEvent(); event->type = CE_SPAWN_PARTICLE; event->spawn_particle = new ParticleParameters(p); @@ -134,6 +141,13 @@ int ModApiParticlesLocal::l_add_particlespawner(lua_State *L) p.texture = getstringfield_default(L, 1, "texture", p.texture); p.glow = getintfield_default(L, 1, "glow", p.glow); + lua_getfield(L, 1, "node"); + if (lua_istable(L, -1)) + p.node = readnode(L, -1, getGameDef(L)->ndef()); + lua_pop(L, 1); + + p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile); + u64 id = getClient(L)->getParticleManager()->generateSpawnerId(); auto event = new ClientEvent(); diff --git a/src/server.cpp b/src/server.cpp index 68b0131d4..d6e545498 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1577,6 +1577,7 @@ void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, pkt.putRawString(os.str()); } pkt << p.glow << p.object_collision; + pkt << p.node.param0 << p.node.param2 << p.node_tile; Send(&pkt); } -- cgit v1.2.3 From 10c3002aea784b5f0075f3f3e3ec824b6ba546ba Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 22 May 2020 15:25:47 +0200 Subject: Optimize particlespawner sending by not sending to distant players --- src/server.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/server.cpp b/src/server.cpp index d6e545498..8c62584c8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1549,12 +1549,30 @@ void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version, void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version, const ParticleSpawnerParameters &p, u16 attached_id, u32 id) { + static thread_local const float radius = + g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS; + if (peer_id == PEER_ID_INEXISTENT) { std::vector clients = m_clients.getClientIDs(); + const v3f pos = (p.minpos + p.maxpos) / 2.0f * BS; + const float radius_sq = radius * radius; + /* Don't send short-lived spawners to distant players. + * This could be replaced with proper tracking at some point. */ + const bool distance_check = !attached_id && p.time <= 1.0f; + for (const session_t client_id : clients) { RemotePlayer *player = m_env->getPlayer(client_id); if (!player) continue; + + if (distance_check) { + PlayerSAO *sao = player->getPlayerSAO(); + if (!sao) + continue; + if (sao->getBasePosition().getDistanceFromSQ(pos) > radius_sq) + continue; + } + SendAddParticleSpawner(client_id, player->protocol_version, p, attached_id, id); } -- cgit v1.2.3 From a9d6be8b6f769c1b795262f45e81bcb4a2cea4a1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 11 May 2020 20:19:02 +0200 Subject: Fix documentation of emergequeue_limit settings --- builtin/settingtypes.txt | 10 +++++----- minetest.conf.example | 4 ++-- src/emerge.cpp | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 28ea58ffd..e18de3382 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2159,15 +2159,15 @@ chunksize (Chunk size) int 5 enable_mapgen_debug_info (Mapgen debug) bool false # Maximum number of blocks that can be queued for loading. -emergequeue_limit_total (Absolute limit of emerge queues) int 512 +emergequeue_limit_total (Absolute limit of queued blocks to emerge) int 512 # Maximum number of blocks to be queued that are to be loaded from file. -# Set to blank for an appropriate amount to be chosen automatically. -emergequeue_limit_diskonly (Limit of emerge queues on disk) int 64 +# This limit is enforced per player. +emergequeue_limit_diskonly (Per-player limit of queued blocks load from disk) int 64 # Maximum number of blocks to be queued that are to be generated. -# Set to blank for an appropriate amount to be chosen automatically. -emergequeue_limit_generate (Limit of emerge queues to generate) int 64 +# This limit is enforced per player. +emergequeue_limit_generate (Per-player limit of queued blocks to generate) int 64 # Number of emerge threads to use. # Value 0: diff --git a/minetest.conf.example b/minetest.conf.example index f04822c47..17d24a566 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -3251,12 +3251,12 @@ # emergequeue_limit_total = 512 # Maximum number of blocks to be queued that are to be loaded from file. -# Set to blank for an appropriate amount to be chosen automatically. +# This limit is enforced per player. # type: int # emergequeue_limit_diskonly = 64 # Maximum number of blocks to be queued that are to be generated. -# Set to blank for an appropriate amount to be chosen automatically. +# This limit is enforced per player. # type: int # emergequeue_limit_generate = 64 diff --git a/src/emerge.cpp b/src/emerge.cpp index a9fc0a4de..0ac26a682 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -159,6 +159,7 @@ EmergeManager::EmergeManager(Server *server) nthreads = 1; m_qlimit_total = g_settings->getU16("emergequeue_limit_total"); + // FIXME: these fallback values are probably not good if (!g_settings->getU16NoEx("emergequeue_limit_diskonly", m_qlimit_diskonly)) m_qlimit_diskonly = nthreads * 5 + 1; if (!g_settings->getU16NoEx("emergequeue_limit_generate", m_qlimit_generate)) -- cgit v1.2.3 From 5430770b6851a18417f6b2629c9167a5aa38baa5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 11 May 2020 20:22:32 +0200 Subject: Fix constant re-queueing of emerges that will always be unsuccessful --- src/clientiface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/clientiface.cpp b/src/clientiface.cpp index 4f954342a..602a44c90 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -344,10 +344,10 @@ void RemoteClient::GetNextBlocks ( } /* - If block has been marked to not exist on disk (dummy) - and generating new ones is not wanted, skip block. + If block has been marked to not exist on disk (dummy) or is + not generated and generating new ones is not wanted, skip block. */ - if (!generate && surely_not_found_on_disk) { + if (!generate && (surely_not_found_on_disk || block_is_invalid)) { // get next one. continue; } -- cgit v1.2.3 From f51cf7c68af16d0068b91d00ab2cc9abdf2b31d0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 24 May 2020 11:48:51 +0200 Subject: Fix two bugs in content_cao fixes #9889 (backface_culling with visual = "cube") fixes #9916 (crash with visual = "upright_sprite") --- src/client/content_cao.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 867bbf2c8..cdc12f041 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -713,6 +713,8 @@ void GenericCAO::addToScene(ITextureSource *tsrc) mesh->drop(); m_meshnode->setScale(m_prop.visual_size); + m_meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, + m_prop.backface_culling); setSceneNodeMaterial(m_meshnode); } else if (m_prop.visual == "mesh") { @@ -832,19 +834,20 @@ void GenericCAO::setNodeLight(u8 light) } if (m_enable_shaders) { - scene::ISceneNode *node = getSceneNode(); - - if (node == nullptr) - return; - if (m_prop.visual == "upright_sprite") { + if (!m_meshnode) + return; + scene::IMesh *mesh = m_meshnode->getMesh(); for (u32 i = 0; i < mesh->getMeshBufferCount(); ++i) { scene::IMeshBuffer *buf = mesh->getMeshBuffer(i); - video::SMaterial &material = buf->getMaterial(); - material.EmissiveColor = color; + buf->getMaterial().EmissiveColor = color; } } else { + scene::ISceneNode *node = getSceneNode(); + if (!node) + return; + for (u32 i = 0; i < node->getMaterialCount(); ++i) { video::SMaterial &material = node->getMaterial(i); material.EmissiveColor = color; -- cgit v1.2.3 From a9b74f4c3966ad38c2f9a97364d3fdda0e514c93 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 24 May 2020 14:24:13 +0200 Subject: Add chat_font_size setting (#9736) Default font sizes are used when the setting value is 0 or below (clamped by Settings). --- builtin/settingtypes.txt | 4 ++++ src/client/gameui.cpp | 23 +++++++++++++---------- src/defaultsettings.cpp | 4 ++++ src/gui/guiChatConsole.cpp | 4 +++- 4 files changed, 24 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index e18de3382..c787aea2c 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -903,6 +903,10 @@ fallback_font_shadow_alpha (Fallback font shadow alpha) int 128 0 255 # This font will be used for certain languages or if the default font is unavailable. fallback_font_path (Fallback font path) filepath fonts/DroidSansFallbackFull.ttf +# Font size of the recent chat text and chat prompt in point (pt). +# Value 0 will use the default font size. +chat_font_size (Chat font size) int 0 + # Path to save screenshots at. Can be an absolute or relative path. # The folder will be created if it doesn't already exist. screenshot_path (Screenshot folder) path screenshots diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index bbe7caeb1..c216f405d 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -76,6 +76,11 @@ void GameUI::init() m_guitext_chat = gui::StaticText::add(guienv, L"", core::rect(0, 0, 0, 0), //false, false); // Disable word wrap as of now false, true, guiroot); + u16 chat_font_size = g_settings->getU16("chat_font_size"); + if (chat_font_size != 0) { + m_guitext_chat->setOverrideFont(g_fontengine->getFont( + chat_font_size, FM_Unspecified)); + } // Profiler text (size is updated when text is updated) m_guitext_profiler = gui::StaticText::add(guienv, L"", @@ -213,7 +218,6 @@ void GameUI::showTranslatedStatusText(const char *str) void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) { - setStaticText(m_guitext_chat, chat_text); // Update gui element size and position s32 chat_y = 5; @@ -221,16 +225,15 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) if (m_flags.show_debug) chat_y += 2 * g_fontengine->getLineHeight(); - // first pass to calculate height of text to be set const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); - s32 width = std::min(g_fontengine->getTextWidth(chat_text.c_str()) + 10, - window_size.X - 20); - m_guitext_chat->setRelativePosition(core::rect(10, chat_y, width, - chat_y + window_size.Y)); - - // now use real height of text and adjust rect according to this size - m_guitext_chat->setRelativePosition(core::rect(10, chat_y, width, - chat_y + m_guitext_chat->getTextHeight())); + + core::rect chat_size(10, chat_y, + window_size.X - 20, 0); + chat_size.LowerRightCorner.Y = std::min((s32)window_size.Y, + m_guitext_chat->getTextHeight() + chat_y); + + m_guitext_chat->setRelativePosition(chat_size); + setStaticText(m_guitext_chat, chat_text); m_recent_chat_count = recent_chat_count; } diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 1d0610c0f..5d1795003 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -321,8 +321,12 @@ void set_default_settings(Settings *settings) std::string font_size_str = std::to_string(DEFAULT_FONT_SIZE); #endif + // General font settings settings->setDefault("font_size", font_size_str); settings->setDefault("mono_font_size", font_size_str); + settings->setDefault("chat_font_size", "0"); // Default "font_size" + + // ContentDB settings->setDefault("contentdb_url", "https://content.minetest.net"); #ifdef __ANDROID__ settings->setDefault("contentdb_flag_blacklist", "nonfree, android_default"); diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp index e67fae3c6..8de00c12f 100644 --- a/src/gui/guiChatConsole.cpp +++ b/src/gui/guiChatConsole.cpp @@ -74,7 +74,9 @@ GUIChatConsole::GUIChatConsole( m_background_color.setBlue(clamp_u8(myround(console_color.Z))); } - m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono); + u16 chat_font_size = g_settings->getU16("chat_font_size"); + m_font = g_fontengine->getFont(chat_font_size != 0 ? + chat_font_size : FONT_SIZE_UNSPECIFIED, FM_Mono); if (!m_font) { errorstream << "GUIChatConsole: Unable to load mono font" << std::endl; -- cgit v1.2.3 From 212a1123e0fd930faf2467b09761815b849efcaf Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 24 May 2020 15:31:06 +0100 Subject: Fix build on FreeBSD, broken since open_url --- src/porting.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/porting.cpp b/src/porting.cpp index 29af62f7d..d902d3737 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) #include #include + extern char **environ; #elif defined(_WIN32) #include #include -- cgit v1.2.3 From 5311a275235d2132443643199330953c877b794a Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 25 May 2020 19:10:23 +0200 Subject: Silence GCC warning in mapblock_mesh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes following warning: warning: ‘waving’ may be used uninitialized in this function [-Wmaybe-uninitialized] --- src/client/mapblock_mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 0a1619b3f..1020e35f5 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -888,7 +888,7 @@ static void updateFastFaceRow( v3s16 p_corrected; v3s16 face_dir_corrected; u16 lights[4] = {0, 0, 0, 0}; - u8 waving; + u8 waving = 0; TileSpec tile; // Get info of first tile -- cgit v1.2.3 From b546e8938d41aa9e3101fb9d4d5b02924ed73b60 Mon Sep 17 00:00:00 2001 From: Paramat Date: Mon, 25 May 2020 21:11:57 +0100 Subject: L-System trees: Remove hardcoded use of 'mapgen_dirt' alias (#9931) Games often and increasingly do not use this mapgen alias, as it is only required for Mapgen V6. Such games were triggering the recently added error message. Even if this mapgen alias was defined, dirt nodes placed under a wide trunk were inconsistent with biomes that do not use dirt surface nodes. Place trunk nodes below a wide trunk instead of 'mapgen_dirt'. On sloping ground, the trunk then extends down to the surface, instead of the surface rising up to meet the trunk. This looks more natural and does not alter the terrain. --- src/mapgen/treegen.cpp | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/mapgen/treegen.cpp b/src/mapgen/treegen.cpp index d538e15b4..e7e30c880 100644 --- a/src/mapgen/treegen.cpp +++ b/src/mapgen/treegen.cpp @@ -148,10 +148,6 @@ treegen::error spawn_ltree(ServerMap *map, v3s16 p0, treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef, TreeDef tree_definition) { - MapNode dirtnode(ndef->getId("mapgen_dirt")); - if (dirtnode == CONTENT_IGNORE) - errorstream << "Treegen (make_ltree): Mapgen alias 'mapgen_dirt' is invalid!" << std::endl; - s32 seed; if (tree_definition.explicit_seed) seed = tree_definition.seed + 14002; @@ -229,43 +225,43 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, axiom = temp; } - //make sure tree is not floating in the air + // Add trunk nodes below a wide trunk to avoid gaps when tree is on sloping ground if (tree_definition.trunk_type == "double") { - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X + 1, position.Y - 1, position.Z), - dirtnode + tree_definition ); - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X, position.Y - 1, position.Z + 1), - dirtnode + tree_definition ); - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X + 1, position.Y - 1, position.Z + 1), - dirtnode + tree_definition ); } else if (tree_definition.trunk_type == "crossed") { - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X + 1, position.Y - 1, position.Z), - dirtnode + tree_definition ); - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X - 1, position.Y - 1, position.Z), - dirtnode + tree_definition ); - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X, position.Y - 1, position.Z + 1), - dirtnode + tree_definition ); - tree_node_placement( + tree_trunk_placement( vmanip, v3f(position.X, position.Y - 1, position.Z - 1), - dirtnode + tree_definition ); } @@ -372,7 +368,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0, !tree_definition.thin_branches)) { tree_trunk_placement( vmanip, - v3f(position.X +1 , position.Y, position.Z), + v3f(position.X + 1, position.Y, position.Z), tree_definition ); tree_trunk_placement( -- cgit v1.2.3 From 083b285f4319c470f307f0b52f03a2fb68facd38 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 26 May 2020 00:17:52 +0200 Subject: Rename “Minimal development test” to “Development Test” (#9928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 6 +- README.md | 2 +- builtin/mainmenu/dlg_create_world.lua | 12 +- doc/lua_api.txt | 2 +- games/devtest/LICENSE.txt | 4 + games/devtest/README.md | 52 ++ games/devtest/game.conf | 2 + games/devtest/menu/background.png | Bin 0 -> 152 bytes games/devtest/menu/header.png | Bin 0 -> 404 bytes games/devtest/menu/icon.png | Bin 0 -> 217 bytes games/devtest/mods/basenodes/init.lua | 334 ++++++++++ games/devtest/mods/basenodes/mod.conf | 2 + .../textures/basenodes_dirt_with_grass_bottom.png | Bin 0 -> 187 bytes .../textures/basenodes_dirt_with_snow.png | Bin 0 -> 166 bytes .../textures/basenodes_dirt_with_snow_bottom.png | Bin 0 -> 177 bytes .../basenodes/textures/basenodes_snow_sheet.png | Bin 0 -> 166 bytes .../mods/basenodes/textures/default_apple.png | Bin 0 -> 102 bytes .../mods/basenodes/textures/default_cobble.png | Bin 0 -> 340 bytes .../basenodes/textures/default_desert_sand.png | Bin 0 -> 293 bytes .../basenodes/textures/default_desert_stone.png | Bin 0 -> 584 bytes .../mods/basenodes/textures/default_dirt.png | Bin 0 -> 790 bytes .../mods/basenodes/textures/default_grass.png | Bin 0 -> 697 bytes .../mods/basenodes/textures/default_grass_side.png | Bin 0 -> 796 bytes .../mods/basenodes/textures/default_gravel.png | Bin 0 -> 171 bytes .../mods/basenodes/textures/default_ice.png | Bin 0 -> 369 bytes .../basenodes/textures/default_junglegrass.png | Bin 0 -> 201 bytes .../basenodes/textures/default_jungleleaves.png | Bin 0 -> 399 bytes .../mods/basenodes/textures/default_jungletree.png | Bin 0 -> 730 bytes .../basenodes/textures/default_jungletree_top.png | Bin 0 -> 714 bytes .../mods/basenodes/textures/default_lava.png | Bin 0 -> 172 bytes .../basenodes/textures/default_lava_flowing.png | Bin 0 -> 91 bytes .../mods/basenodes/textures/default_leaves.png | Bin 0 -> 883 bytes .../basenodes/textures/default_mossycobble.png | Bin 0 -> 574 bytes .../basenodes/textures/default_pine_needles.png | Bin 0 -> 648 bytes .../mods/basenodes/textures/default_pine_tree.png | Bin 0 -> 604 bytes .../basenodes/textures/default_pine_tree_top.png | Bin 0 -> 174 bytes .../basenodes/textures/default_river_water.png | Bin 0 -> 496 bytes .../textures/default_river_water_flowing.png | Bin 0 -> 99 bytes .../mods/basenodes/textures/default_sand.png | Bin 0 -> 554 bytes .../mods/basenodes/textures/default_snow.png | Bin 0 -> 166 bytes .../mods/basenodes/textures/default_snow_side.png | Bin 0 -> 152 bytes .../mods/basenodes/textures/default_stone.png | Bin 0 -> 313 bytes .../mods/basenodes/textures/default_tree.png | Bin 0 -> 659 bytes .../mods/basenodes/textures/default_tree_top.png | Bin 0 -> 175 bytes .../mods/basenodes/textures/default_water.png | Bin 0 -> 302 bytes .../basenodes/textures/default_water_flowing.png | Bin 0 -> 115 bytes games/devtest/mods/basetools/init.lua | 295 +++++++++ games/devtest/mods/basetools/mod.conf | 2 + .../mods/basetools/textures/basetools_dirtpick.png | Bin 0 -> 307 bytes .../basetools/textures/basetools_firesword.png | Bin 0 -> 190 bytes .../mods/basetools/textures/basetools_icesword.png | Bin 0 -> 190 bytes .../mods/basetools/textures/basetools_mesepick.png | Bin 0 -> 155 bytes .../mods/basetools/textures/basetools_steelaxe.png | Bin 0 -> 131 bytes .../basetools/textures/basetools_steeldagger.png | Bin 0 -> 154 bytes .../basetools/textures/basetools_steelpick.png | Bin 0 -> 159 bytes .../basetools/textures/basetools_steelpick_l1.png | Bin 0 -> 190 bytes .../basetools/textures/basetools_steelpick_l2.png | Bin 0 -> 177 bytes .../basetools/textures/basetools_steelshears.png | Bin 0 -> 208 bytes .../basetools/textures/basetools_steelshovel.png | Bin 0 -> 140 bytes .../basetools/textures/basetools_steelsword.png | Bin 0 -> 163 bytes .../mods/basetools/textures/basetools_stoneaxe.png | Bin 0 -> 130 bytes .../basetools/textures/basetools_stonepick.png | Bin 0 -> 155 bytes .../basetools/textures/basetools_stoneshears.png | Bin 0 -> 224 bytes .../basetools/textures/basetools_stoneshovel.png | Bin 0 -> 134 bytes .../basetools/textures/basetools_stonesword.png | Bin 0 -> 159 bytes .../mods/basetools/textures/basetools_woodaxe.png | Bin 0 -> 121 bytes .../mods/basetools/textures/basetools_woodpick.png | Bin 0 -> 149 bytes .../basetools/textures/basetools_woodshears.png | Bin 0 -> 212 bytes .../basetools/textures/basetools_woodshovel.png | Bin 0 -> 133 bytes .../basetools/textures/basetools_woodsword.png | Bin 0 -> 139 bytes games/devtest/mods/bucket/init.lua | 26 + games/devtest/mods/bucket/mod.conf | 2 + games/devtest/mods/bucket/textures/bucket.png | Bin 0 -> 163 bytes games/devtest/mods/bucket/textures/bucket_lava.png | Bin 0 -> 168 bytes .../devtest/mods/bucket/textures/bucket_water.png | Bin 0 -> 168 bytes games/devtest/mods/chest/init.lua | 27 + games/devtest/mods/chest/mod.conf | 2 + games/devtest/mods/chest/textures/chest_chest.png | Bin 0 -> 163 bytes games/devtest/mods/chest_of_everything/init.lua | 135 ++++ games/devtest/mods/chest_of_everything/mod.conf | 2 + .../textures/chest_of_everything_chest.png | Bin 0 -> 210 bytes games/devtest/mods/dignodes/init.lua | 37 ++ games/devtest/mods/dignodes/mod.conf | 2 + .../mods/dignodes/textures/dignodes_choppy.png | Bin 0 -> 187 bytes .../mods/dignodes/textures/dignodes_cracky.png | Bin 0 -> 193 bytes .../mods/dignodes/textures/dignodes_crumbly.png | Bin 0 -> 172 bytes .../dignodes/textures/dignodes_dig_immediate.png | Bin 0 -> 170 bytes .../mods/dignodes/textures/dignodes_none.png | Bin 0 -> 201 bytes .../mods/dignodes/textures/dignodes_rating1.png | Bin 0 -> 94 bytes .../mods/dignodes/textures/dignodes_rating2.png | Bin 0 -> 92 bytes .../mods/dignodes/textures/dignodes_rating3.png | Bin 0 -> 93 bytes games/devtest/mods/experimental/commands.lua | 215 +++++++ games/devtest/mods/experimental/detached.lua | 29 + games/devtest/mods/experimental/init.lua | 23 + games/devtest/mods/experimental/items.lua | 103 +++ games/devtest/mods/experimental/mod.conf | 2 + .../textures/experimental_callback_node.png | Bin 0 -> 139 bytes .../textures/experimental_particle_sheet.png | Bin 0 -> 208 bytes .../textures/experimental_particle_vertical.png | Bin 0 -> 308 bytes .../textures/experimental_tester_tool_1.png | Bin 0 -> 138 bytes games/devtest/mods/give_initial_stuff/init.lua | 37 ++ games/devtest/mods/give_initial_stuff/mod.conf | 3 + games/devtest/mods/initial_message/init.lua | 9 + games/devtest/mods/initial_message/mod.conf | 2 + games/devtest/mods/mapgen/init.lua | 81 +++ games/devtest/mods/mapgen/mod.conf | 3 + games/devtest/mods/modchannels/init.lua | 14 + games/devtest/mods/modchannels/mod.conf | 2 + games/devtest/mods/soundstuff/init.lua | 170 +++++ games/devtest/mods/soundstuff/mod.conf | 2 + .../mods/soundstuff/sounds/soundstuff_mono.ogg | Bin 0 -> 4362 bytes .../mods/soundstuff/textures/soundstuff_eat.png | Bin 0 -> 113 bytes .../soundstuff/textures/soundstuff_node_blank.png | Bin 0 -> 83 bytes .../textures/soundstuff_node_climbable.png | Bin 0 -> 189 bytes .../soundstuff/textures/soundstuff_node_dig.png | Bin 0 -> 126 bytes .../soundstuff/textures/soundstuff_node_dug.png | Bin 0 -> 132 bytes .../soundstuff/textures/soundstuff_node_fall.png | Bin 0 -> 100 bytes .../textures/soundstuff_node_footstep.png | Bin 0 -> 120 bytes .../soundstuff/textures/soundstuff_node_place.png | Bin 0 -> 115 bytes .../textures/soundstuff_node_place_failed.png | Bin 0 -> 143 bytes .../soundstuff/textures/soundstuff_node_sound.png | Bin 0 -> 116 bytes games/devtest/mods/stairs/init.lua | 65 ++ games/devtest/mods/stairs/mod.conf | 3 + games/devtest/mods/testentities/armor.lua | 41 ++ games/devtest/mods/testentities/callbacks.lua | 75 +++ games/devtest/mods/testentities/init.lua | 3 + games/devtest/mods/testentities/mod.conf | 2 + .../textures/testentities_armorball.png | Bin 0 -> 561 bytes .../textures/testentities_callback.png | Bin 0 -> 156 bytes .../textures/testentities_callback_step.png | Bin 0 -> 166 bytes .../testentities/textures/testentities_cube1.png | Bin 0 -> 130 bytes .../testentities/textures/testentities_cube2.png | Bin 0 -> 128 bytes .../testentities/textures/testentities_cube3.png | Bin 0 -> 124 bytes .../testentities/textures/testentities_cube4.png | Bin 0 -> 126 bytes .../testentities/textures/testentities_cube5.png | Bin 0 -> 126 bytes .../testentities/textures/testentities_cube6.png | Bin 0 -> 126 bytes .../textures/testentities_dungeon_master.png | Bin 0 -> 2855 bytes .../testentities/textures/testentities_sprite.png | Bin 0 -> 120 bytes .../textures/testentities_upright_sprite1.png | Bin 0 -> 114 bytes .../textures/testentities_upright_sprite2.png | Bin 0 -> 119 bytes games/devtest/mods/testentities/visuals.lua | 74 +++ games/devtest/mods/testfood/init.lua | 24 + games/devtest/mods/testfood/mod.conf | 2 + .../mods/testfood/textures/testfood_bad.png | Bin 0 -> 126 bytes .../mods/testfood/textures/testfood_bad2.png | Bin 0 -> 133 bytes .../mods/testfood/textures/testfood_good.png | Bin 0 -> 129 bytes .../mods/testfood/textures/testfood_good2.png | Bin 0 -> 145 bytes games/devtest/mods/testformspec/callbacks.lua | 51 ++ games/devtest/mods/testformspec/dummy_items.lua | 14 + games/devtest/mods/testformspec/formspec.lua | 381 ++++++++++++ games/devtest/mods/testformspec/init.lua | 3 + games/devtest/mods/testformspec/mod.conf | 2 + .../textures/testformspec_animation.jpg | Bin 0 -> 4376 bytes .../textures/testformspec_animation.png | Bin 0 -> 214 bytes .../mods/testformspec/textures/testformspec_bg.png | Bin 0 -> 92 bytes .../textures/testformspec_bg_9slice.png | Bin 0 -> 146 bytes .../textures/testformspec_bg_9slice_hovered.png | Bin 0 -> 146 bytes .../textures/testformspec_bg_9slice_pressed.png | Bin 0 -> 146 bytes .../textures/testformspec_bg_hovered.png | Bin 0 -> 92 bytes .../textures/testformspec_bg_pressed.png | Bin 0 -> 91 bytes .../textures/testformspec_button_image.png | Bin 0 -> 146 bytes .../testformspec/textures/testformspec_hovered.png | Bin 0 -> 195 bytes .../testformspec/textures/testformspec_item.png | Bin 0 -> 182 bytes .../testformspec/textures/testformspec_node.png | Bin 0 -> 113 bytes .../testformspec/textures/testformspec_pressed.png | Bin 0 -> 165 bytes games/devtest/mods/testnodes/README.md | 11 + games/devtest/mods/testnodes/drawtypes.lua | 517 +++++++++++++++ games/devtest/mods/testnodes/init.lua | 10 + games/devtest/mods/testnodes/light.lua | 48 ++ games/devtest/mods/testnodes/liquids.lua | 91 +++ games/devtest/mods/testnodes/meshes.lua | 145 +++++ games/devtest/mods/testnodes/mod.conf | 2 + .../mods/testnodes/models/testnodes_ocorner.obj | 23 + .../mods/testnodes/models/testnodes_pyramid.obj | 24 + games/devtest/mods/testnodes/nodeboxes.lua | 80 +++ games/devtest/mods/testnodes/param2.lua | 168 +++++ games/devtest/mods/testnodes/properties.lua | 270 ++++++++ games/devtest/mods/testnodes/settingtypes.txt | 4 + games/devtest/mods/testnodes/textures.lua | 67 ++ .../mods/testnodes/textures/testnodes_1.png | Bin 0 -> 107 bytes .../mods/testnodes/textures/testnodes_1g.png | Bin 0 -> 104 bytes .../mods/testnodes/textures/testnodes_1w.png | Bin 0 -> 121 bytes .../mods/testnodes/textures/testnodes_1wg.png | Bin 0 -> 122 bytes .../mods/testnodes/textures/testnodes_2.png | Bin 0 -> 112 bytes .../mods/testnodes/textures/testnodes_2g.png | Bin 0 -> 110 bytes .../mods/testnodes/textures/testnodes_2w.png | Bin 0 -> 134 bytes .../mods/testnodes/textures/testnodes_2wg.png | Bin 0 -> 135 bytes .../mods/testnodes/textures/testnodes_3.png | Bin 0 -> 105 bytes .../mods/testnodes/textures/testnodes_3g.png | Bin 0 -> 103 bytes .../mods/testnodes/textures/testnodes_3w.png | Bin 0 -> 112 bytes .../mods/testnodes/textures/testnodes_3wg.png | Bin 0 -> 112 bytes .../mods/testnodes/textures/testnodes_4.png | Bin 0 -> 97 bytes .../mods/testnodes/textures/testnodes_4g.png | Bin 0 -> 95 bytes .../mods/testnodes/textures/testnodes_4w.png | Bin 0 -> 128 bytes .../mods/testnodes/textures/testnodes_4wg.png | Bin 0 -> 128 bytes .../mods/testnodes/textures/testnodes_5.png | Bin 0 -> 98 bytes .../mods/testnodes/textures/testnodes_5g.png | Bin 0 -> 98 bytes .../mods/testnodes/textures/testnodes_5w.png | Bin 0 -> 117 bytes .../mods/testnodes/textures/testnodes_5wg.png | Bin 0 -> 117 bytes .../mods/testnodes/textures/testnodes_6.png | Bin 0 -> 100 bytes .../mods/testnodes/textures/testnodes_6g.png | Bin 0 -> 98 bytes .../mods/testnodes/textures/testnodes_6w.png | Bin 0 -> 117 bytes .../mods/testnodes/textures/testnodes_6wg.png | Bin 0 -> 117 bytes .../mods/testnodes/textures/testnodes_airlike.png | Bin 0 -> 92 bytes .../mods/testnodes/textures/testnodes_allfaces.png | Bin 0 -> 150 bytes .../textures/testnodes_allfaces_optional.png | Bin 0 -> 150 bytes .../mods/testnodes/textures/testnodes_alpha.png | Bin 0 -> 96 bytes .../mods/testnodes/textures/testnodes_alpha128.png | Bin 0 -> 136 bytes .../mods/testnodes/textures/testnodes_alpha191.png | Bin 0 -> 132 bytes .../mods/testnodes/textures/testnodes_alpha64.png | Bin 0 -> 134 bytes .../mods/testnodes/textures/testnodes_anim.png | Bin 0 -> 274 bytes .../textures/testnodes_attached_bottom.png | Bin 0 -> 86 bytes .../testnodes/textures/testnodes_attached_side.png | Bin 0 -> 98 bytes .../testnodes/textures/testnodes_attached_top.png | Bin 0 -> 87 bytes .../textures/testnodes_attachedw_bottom.png | Bin 0 -> 130 bytes .../textures/testnodes_attachedw_side.png | Bin 0 -> 122 bytes .../testnodes/textures/testnodes_attachedw_top.png | Bin 0 -> 109 bytes .../mods/testnodes/textures/testnodes_bouncy.png | Bin 0 -> 106 bytes .../testnodes/textures/testnodes_buildable_to.png | Bin 0 -> 89 bytes .../textures/testnodes_climbable_nojump_side.png | Bin 0 -> 164 bytes .../textures/testnodes_climbable_side.png | Bin 0 -> 150 bytes .../mods/testnodes/textures/testnodes_damage.png | Bin 0 -> 108 bytes .../testnodes/textures/testnodes_damage_neg.png | Bin 0 -> 121 bytes .../mods/testnodes/textures/testnodes_drowning.png | Bin 0 -> 127 bytes .../textures/testnodes_fall_damage_minus.png | Bin 0 -> 116 bytes .../textures/testnodes_fall_damage_plus.png | Bin 0 -> 117 bytes .../testnodes/textures/testnodes_fencelike.png | Bin 0 -> 90 bytes .../mods/testnodes/textures/testnodes_firelike.png | Bin 0 -> 149 bytes .../testnodes/textures/testnodes_glasslike.png | Bin 0 -> 117 bytes .../textures/testnodes_glasslike_detail.png | Bin 0 -> 167 bytes .../textures/testnodes_glasslike_framed.png | Bin 0 -> 88 bytes .../textures/testnodes_glasslike_framed2.png | Bin 0 -> 118 bytes .../testnodes_glasslike_framed_optional.png | Bin 0 -> 128 bytes .../textures/testnodes_glasslikeliquid.png | Bin 0 -> 122 bytes .../mods/testnodes/textures/testnodes_light.png | Bin 0 -> 117 bytes .../mods/testnodes/textures/testnodes_light_1.png | Bin 0 -> 158 bytes .../mods/testnodes/textures/testnodes_light_10.png | Bin 0 -> 147 bytes .../mods/testnodes/textures/testnodes_light_11.png | Bin 0 -> 149 bytes .../mods/testnodes/textures/testnodes_light_12.png | Bin 0 -> 138 bytes .../mods/testnodes/textures/testnodes_light_13.png | Bin 0 -> 137 bytes .../mods/testnodes/textures/testnodes_light_14.png | Bin 0 -> 132 bytes .../mods/testnodes/textures/testnodes_light_2.png | Bin 0 -> 152 bytes .../mods/testnodes/textures/testnodes_light_3.png | Bin 0 -> 150 bytes .../mods/testnodes/textures/testnodes_light_4.png | Bin 0 -> 157 bytes .../mods/testnodes/textures/testnodes_light_5.png | Bin 0 -> 150 bytes .../mods/testnodes/textures/testnodes_light_6.png | Bin 0 -> 154 bytes .../mods/testnodes/textures/testnodes_light_7.png | Bin 0 -> 146 bytes .../mods/testnodes/textures/testnodes_light_8.png | Bin 0 -> 139 bytes .../mods/testnodes/textures/testnodes_light_9.png | Bin 0 -> 149 bytes .../testnodes/textures/testnodes_line_crossing.png | Bin 0 -> 130 bytes .../testnodes/textures/testnodes_line_curved.png | Bin 0 -> 123 bytes .../testnodes/textures/testnodes_line_straight.png | Bin 0 -> 115 bytes .../textures/testnodes_line_t_junction.png | Bin 0 -> 128 bytes .../mods/testnodes/textures/testnodes_liquid.png | Bin 0 -> 95 bytes .../testnodes/textures/testnodes_liquidflowing.png | Bin 0 -> 132 bytes .../textures/testnodes_liquidflowing_r0.png | Bin 0 -> 162 bytes .../textures/testnodes_liquidflowing_r1.png | Bin 0 -> 160 bytes .../textures/testnodes_liquidflowing_r2.png | Bin 0 -> 154 bytes .../textures/testnodes_liquidflowing_r3.png | Bin 0 -> 155 bytes .../textures/testnodes_liquidflowing_r4.png | Bin 0 -> 154 bytes .../textures/testnodes_liquidflowing_r5.png | Bin 0 -> 155 bytes .../textures/testnodes_liquidflowing_r6.png | Bin 0 -> 155 bytes .../textures/testnodes_liquidflowing_r7.png | Bin 0 -> 157 bytes .../textures/testnodes_liquidflowing_r8.png | Bin 0 -> 152 bytes .../testnodes/textures/testnodes_liquidsource.png | Bin 0 -> 128 bytes .../textures/testnodes_liquidsource_r0.png | Bin 0 -> 149 bytes .../textures/testnodes_liquidsource_r1.png | Bin 0 -> 152 bytes .../textures/testnodes_liquidsource_r2.png | Bin 0 -> 152 bytes .../textures/testnodes_liquidsource_r3.png | Bin 0 -> 152 bytes .../textures/testnodes_liquidsource_r4.png | Bin 0 -> 155 bytes .../textures/testnodes_liquidsource_r5.png | Bin 0 -> 150 bytes .../textures/testnodes_liquidsource_r6.png | Bin 0 -> 148 bytes .../textures/testnodes_liquidsource_r7.png | Bin 0 -> 154 bytes .../textures/testnodes_liquidsource_r8.png | Bin 0 -> 148 bytes .../testnodes/textures/testnodes_mesh_stripes.png | Bin 0 -> 150 bytes .../testnodes/textures/testnodes_mesh_stripes2.png | Bin 0 -> 144 bytes .../testnodes/textures/testnodes_mesh_stripes3.png | Bin 0 -> 85 bytes .../testnodes/textures/testnodes_mesh_stripes4.png | Bin 0 -> 93 bytes .../mods/testnodes/textures/testnodes_node.png | Bin 0 -> 89 bytes .../testnodes/textures/testnodes_node_falling.png | Bin 0 -> 112 bytes .../mods/testnodes/textures/testnodes_nodebox.png | Bin 0 -> 112 bytes .../testnodes/textures/testnodes_nojump_side.png | Bin 0 -> 94 bytes .../testnodes/textures/testnodes_nojump_top.png | Bin 0 -> 121 bytes .../mods/testnodes/textures/testnodes_normal.png | Bin 0 -> 92 bytes .../mods/testnodes/textures/testnodes_normal1.png | Bin 0 -> 114 bytes .../mods/testnodes/textures/testnodes_normal2.png | Bin 0 -> 122 bytes .../mods/testnodes/textures/testnodes_normal3.png | Bin 0 -> 114 bytes .../mods/testnodes/textures/testnodes_normal4.png | Bin 0 -> 106 bytes .../mods/testnodes/textures/testnodes_normal5.png | Bin 0 -> 109 bytes .../mods/testnodes/textures/testnodes_normal6.png | Bin 0 -> 111 bytes .../textures/testnodes_palette_facedir.png | Bin 0 -> 87 bytes .../testnodes/textures/testnodes_palette_full.png | Bin 0 -> 568 bytes .../textures/testnodes_palette_wallmounted.png | Bin 0 -> 136 bytes .../testnodes/textures/testnodes_plantlike.png | Bin 0 -> 183 bytes .../textures/testnodes_plantlike_degrotate.png | Bin 0 -> 176 bytes .../textures/testnodes_plantlike_leveled.png | Bin 0 -> 163 bytes .../textures/testnodes_plantlike_meshoptions.png | Bin 0 -> 164 bytes .../textures/testnodes_plantlike_rooted.png | Bin 0 -> 182 bytes .../textures/testnodes_plantlike_rooted_base.png | Bin 0 -> 101 bytes ...tnodes_plantlike_rooted_base_side_degrotate.png | Bin 0 -> 145 bytes ...estnodes_plantlike_rooted_base_side_leveled.png | Bin 0 -> 127 bytes ...odes_plantlike_rooted_base_side_meshoptions.png | Bin 0 -> 128 bytes ...testnodes_plantlike_rooted_base_side_waving.png | Bin 0 -> 126 bytes .../testnodes_plantlike_rooted_degrotate.png | Bin 0 -> 176 bytes .../testnodes_plantlike_rooted_leveled.png | Bin 0 -> 162 bytes .../testnodes_plantlike_rooted_meshoptions.png | Bin 0 -> 162 bytes .../textures/testnodes_plantlike_rooted_waving.png | Bin 0 -> 125 bytes .../textures/testnodes_plantlike_waving.png | Bin 0 -> 127 bytes .../textures/testnodes_rail2_crossing.png | Bin 0 -> 246 bytes .../testnodes/textures/testnodes_rail2_curved.png | Bin 0 -> 253 bytes .../textures/testnodes_rail2_straight.png | Bin 0 -> 246 bytes .../textures/testnodes_rail2_t_junction.png | Bin 0 -> 254 bytes .../testnodes/textures/testnodes_rail_crossing.png | Bin 0 -> 151 bytes .../testnodes/textures/testnodes_rail_curved.png | Bin 0 -> 164 bytes .../testnodes/textures/testnodes_rail_straight.png | Bin 0 -> 133 bytes .../textures/testnodes_rail_t_junction.png | Bin 0 -> 202 bytes .../mods/testnodes/textures/testnodes_signlike.png | Bin 0 -> 150 bytes .../mods/testnodes/textures/testnodes_slippery.png | Bin 0 -> 111 bytes .../textures/testnodes_street_crossing.png | Bin 0 -> 137 bytes .../testnodes/textures/testnodes_street_curved.png | Bin 0 -> 115 bytes .../textures/testnodes_street_straight.png | Bin 0 -> 101 bytes .../textures/testnodes_street_t_junction.png | Bin 0 -> 126 bytes .../textures/testnodes_sunlight_filter.png | Bin 0 -> 113 bytes .../textures/testnodes_torchlike_ceiling.png | Bin 0 -> 157 bytes .../textures/testnodes_torchlike_floor.png | Bin 0 -> 141 bytes .../textures/testnodes_torchlike_wall.png | Bin 0 -> 158 bytes games/devtest/mods/testpathfinder/README.md | 15 + games/devtest/mods/testpathfinder/init.lua | 132 ++++ games/devtest/mods/testpathfinder/mod.conf | 2 + .../textures/testpathfinder_testpathfinder.png | Bin 0 -> 159 bytes .../textures/testpathfinder_waypoint.png | Bin 0 -> 99 bytes .../textures/testpathfinder_waypoint_end.png | Bin 0 -> 147 bytes .../textures/testpathfinder_waypoint_start.png | Bin 0 -> 139 bytes games/devtest/mods/testtools/README.md | 99 +++ games/devtest/mods/testtools/init.lua | 691 +++++++++++++++++++++ games/devtest/mods/testtools/mod.conf | 2 + .../textures/testtools_entity_rotator.png | Bin 0 -> 151 bytes .../testtools/textures/testtools_entity_scaler.png | Bin 0 -> 182 bytes .../textures/testtools_entity_spawner.png | Bin 0 -> 189 bytes .../textures/testtools_falling_node_tool.png | Bin 0 -> 140 bytes .../testtools/textures/testtools_node_setter.png | Bin 0 -> 146 bytes .../textures/testtools_object_attacher.png | Bin 0 -> 173 bytes .../testtools/textures/testtools_object_editor.png | Bin 0 -> 180 bytes .../testtools/textures/testtools_object_mover.png | Bin 0 -> 175 bytes .../testtools/textures/testtools_param2tool.png | Bin 0 -> 127 bytes .../mods/testtools/textures/testtools_remover.png | Bin 0 -> 129 bytes games/devtest/mods/tiled/init.lua | 33 + games/devtest/mods/tiled/mod.conf | 3 + games/devtest/mods/tiled/textures/tiled_tiled.png | Bin 0 -> 410 bytes games/devtest/mods/unittests/crafting.lua | 120 ++++ games/devtest/mods/unittests/crafting_prepare.lua | 88 +++ games/devtest/mods/unittests/init.lua | 16 + games/devtest/mods/unittests/mod.conf | 2 + games/devtest/mods/unittests/player.lua | 73 +++ games/devtest/mods/unittests/random.lua | 10 + .../unittests/textures/unittests_coal_lump.png | Bin 0 -> 160 bytes .../unittests/textures/unittests_iron_lump.png | Bin 0 -> 154 bytes .../textures/unittests_repairable_tool.png | Bin 0 -> 160 bytes .../unittests/textures/unittests_steel_ingot.png | Bin 0 -> 159 bytes .../mods/unittests/textures/unittests_stick.png | Bin 0 -> 147 bytes .../mods/unittests/textures/unittests_torch.png | Bin 0 -> 155 bytes .../textures/unittests_unrepairable_tool.png | Bin 0 -> 157 bytes games/devtest/mods/util_commands/init.lua | 137 ++++ games/devtest/mods/util_commands/mod.conf | 2 + games/devtest/screenshot.png | Bin 0 -> 133364 bytes games/devtest/settingtypes.txt | 37 ++ games/minimal/LICENSE.txt | 4 - games/minimal/README.md | 52 -- games/minimal/game.conf | 2 - games/minimal/menu/background.png | Bin 152 -> 0 bytes games/minimal/menu/header.png | Bin 210 -> 0 bytes games/minimal/menu/icon.png | Bin 217 -> 0 bytes games/minimal/mods/basenodes/init.lua | 334 ---------- games/minimal/mods/basenodes/mod.conf | 2 - .../textures/basenodes_dirt_with_grass_bottom.png | Bin 187 -> 0 bytes .../textures/basenodes_dirt_with_snow.png | Bin 166 -> 0 bytes .../textures/basenodes_dirt_with_snow_bottom.png | Bin 177 -> 0 bytes .../basenodes/textures/basenodes_snow_sheet.png | Bin 166 -> 0 bytes .../mods/basenodes/textures/default_apple.png | Bin 102 -> 0 bytes .../mods/basenodes/textures/default_cobble.png | Bin 340 -> 0 bytes .../basenodes/textures/default_desert_sand.png | Bin 293 -> 0 bytes .../basenodes/textures/default_desert_stone.png | Bin 584 -> 0 bytes .../mods/basenodes/textures/default_dirt.png | Bin 790 -> 0 bytes .../mods/basenodes/textures/default_grass.png | Bin 697 -> 0 bytes .../mods/basenodes/textures/default_grass_side.png | Bin 796 -> 0 bytes .../mods/basenodes/textures/default_gravel.png | Bin 171 -> 0 bytes .../mods/basenodes/textures/default_ice.png | Bin 369 -> 0 bytes .../basenodes/textures/default_junglegrass.png | Bin 201 -> 0 bytes .../basenodes/textures/default_jungleleaves.png | Bin 399 -> 0 bytes .../mods/basenodes/textures/default_jungletree.png | Bin 730 -> 0 bytes .../basenodes/textures/default_jungletree_top.png | Bin 714 -> 0 bytes .../mods/basenodes/textures/default_lava.png | Bin 172 -> 0 bytes .../basenodes/textures/default_lava_flowing.png | Bin 91 -> 0 bytes .../mods/basenodes/textures/default_leaves.png | Bin 883 -> 0 bytes .../basenodes/textures/default_mossycobble.png | Bin 574 -> 0 bytes .../basenodes/textures/default_pine_needles.png | Bin 648 -> 0 bytes .../mods/basenodes/textures/default_pine_tree.png | Bin 604 -> 0 bytes .../basenodes/textures/default_pine_tree_top.png | Bin 174 -> 0 bytes .../basenodes/textures/default_river_water.png | Bin 496 -> 0 bytes .../textures/default_river_water_flowing.png | Bin 99 -> 0 bytes .../mods/basenodes/textures/default_sand.png | Bin 554 -> 0 bytes .../mods/basenodes/textures/default_snow.png | Bin 166 -> 0 bytes .../mods/basenodes/textures/default_snow_side.png | Bin 152 -> 0 bytes .../mods/basenodes/textures/default_stone.png | Bin 313 -> 0 bytes .../mods/basenodes/textures/default_tree.png | Bin 659 -> 0 bytes .../mods/basenodes/textures/default_tree_top.png | Bin 175 -> 0 bytes .../mods/basenodes/textures/default_water.png | Bin 302 -> 0 bytes .../basenodes/textures/default_water_flowing.png | Bin 115 -> 0 bytes games/minimal/mods/basetools/init.lua | 295 --------- games/minimal/mods/basetools/mod.conf | 2 - .../mods/basetools/textures/basetools_dirtpick.png | Bin 307 -> 0 bytes .../basetools/textures/basetools_firesword.png | Bin 190 -> 0 bytes .../mods/basetools/textures/basetools_icesword.png | Bin 190 -> 0 bytes .../mods/basetools/textures/basetools_mesepick.png | Bin 155 -> 0 bytes .../mods/basetools/textures/basetools_steelaxe.png | Bin 131 -> 0 bytes .../basetools/textures/basetools_steeldagger.png | Bin 154 -> 0 bytes .../basetools/textures/basetools_steelpick.png | Bin 159 -> 0 bytes .../basetools/textures/basetools_steelpick_l1.png | Bin 190 -> 0 bytes .../basetools/textures/basetools_steelpick_l2.png | Bin 177 -> 0 bytes .../basetools/textures/basetools_steelshears.png | Bin 208 -> 0 bytes .../basetools/textures/basetools_steelshovel.png | Bin 140 -> 0 bytes .../basetools/textures/basetools_steelsword.png | Bin 163 -> 0 bytes .../mods/basetools/textures/basetools_stoneaxe.png | Bin 130 -> 0 bytes .../basetools/textures/basetools_stonepick.png | Bin 155 -> 0 bytes .../basetools/textures/basetools_stoneshears.png | Bin 224 -> 0 bytes .../basetools/textures/basetools_stoneshovel.png | Bin 134 -> 0 bytes .../basetools/textures/basetools_stonesword.png | Bin 159 -> 0 bytes .../mods/basetools/textures/basetools_woodaxe.png | Bin 121 -> 0 bytes .../mods/basetools/textures/basetools_woodpick.png | Bin 149 -> 0 bytes .../basetools/textures/basetools_woodshears.png | Bin 212 -> 0 bytes .../basetools/textures/basetools_woodshovel.png | Bin 133 -> 0 bytes .../basetools/textures/basetools_woodsword.png | Bin 139 -> 0 bytes games/minimal/mods/bucket/init.lua | 26 - games/minimal/mods/bucket/mod.conf | 2 - games/minimal/mods/bucket/textures/bucket.png | Bin 163 -> 0 bytes games/minimal/mods/bucket/textures/bucket_lava.png | Bin 168 -> 0 bytes .../minimal/mods/bucket/textures/bucket_water.png | Bin 168 -> 0 bytes games/minimal/mods/chest/init.lua | 27 - games/minimal/mods/chest/mod.conf | 2 - games/minimal/mods/chest/textures/chest_chest.png | Bin 163 -> 0 bytes games/minimal/mods/chest_of_everything/init.lua | 135 ---- games/minimal/mods/chest_of_everything/mod.conf | 2 - .../textures/chest_of_everything_chest.png | Bin 210 -> 0 bytes games/minimal/mods/dignodes/init.lua | 37 -- games/minimal/mods/dignodes/mod.conf | 2 - .../mods/dignodes/textures/dignodes_choppy.png | Bin 187 -> 0 bytes .../mods/dignodes/textures/dignodes_cracky.png | Bin 193 -> 0 bytes .../mods/dignodes/textures/dignodes_crumbly.png | Bin 172 -> 0 bytes .../dignodes/textures/dignodes_dig_immediate.png | Bin 170 -> 0 bytes .../mods/dignodes/textures/dignodes_none.png | Bin 201 -> 0 bytes .../mods/dignodes/textures/dignodes_rating1.png | Bin 94 -> 0 bytes .../mods/dignodes/textures/dignodes_rating2.png | Bin 92 -> 0 bytes .../mods/dignodes/textures/dignodes_rating3.png | Bin 93 -> 0 bytes games/minimal/mods/experimental/commands.lua | 215 ------- games/minimal/mods/experimental/detached.lua | 29 - games/minimal/mods/experimental/init.lua | 23 - games/minimal/mods/experimental/items.lua | 103 --- games/minimal/mods/experimental/mod.conf | 2 - .../textures/experimental_callback_node.png | Bin 139 -> 0 bytes .../textures/experimental_particle_sheet.png | Bin 208 -> 0 bytes .../textures/experimental_particle_vertical.png | Bin 308 -> 0 bytes .../textures/experimental_tester_tool_1.png | Bin 138 -> 0 bytes games/minimal/mods/give_initial_stuff/init.lua | 37 -- games/minimal/mods/give_initial_stuff/mod.conf | 3 - games/minimal/mods/initial_message/init.lua | 9 - games/minimal/mods/initial_message/mod.conf | 2 - games/minimal/mods/mapgen/init.lua | 81 --- games/minimal/mods/mapgen/mod.conf | 3 - games/minimal/mods/modchannels/init.lua | 14 - games/minimal/mods/modchannels/mod.conf | 2 - games/minimal/mods/soundstuff/init.lua | 170 ----- games/minimal/mods/soundstuff/mod.conf | 2 - .../mods/soundstuff/sounds/soundstuff_mono.ogg | Bin 4362 -> 0 bytes .../mods/soundstuff/textures/soundstuff_eat.png | Bin 113 -> 0 bytes .../soundstuff/textures/soundstuff_node_blank.png | Bin 83 -> 0 bytes .../textures/soundstuff_node_climbable.png | Bin 189 -> 0 bytes .../soundstuff/textures/soundstuff_node_dig.png | Bin 126 -> 0 bytes .../soundstuff/textures/soundstuff_node_dug.png | Bin 132 -> 0 bytes .../soundstuff/textures/soundstuff_node_fall.png | Bin 100 -> 0 bytes .../textures/soundstuff_node_footstep.png | Bin 120 -> 0 bytes .../soundstuff/textures/soundstuff_node_place.png | Bin 115 -> 0 bytes .../textures/soundstuff_node_place_failed.png | Bin 143 -> 0 bytes .../soundstuff/textures/soundstuff_node_sound.png | Bin 116 -> 0 bytes games/minimal/mods/stairs/init.lua | 65 -- games/minimal/mods/stairs/mod.conf | 3 - games/minimal/mods/testentities/armor.lua | 41 -- games/minimal/mods/testentities/callbacks.lua | 75 --- games/minimal/mods/testentities/init.lua | 3 - games/minimal/mods/testentities/mod.conf | 2 - .../textures/testentities_armorball.png | Bin 561 -> 0 bytes .../textures/testentities_callback.png | Bin 156 -> 0 bytes .../textures/testentities_callback_step.png | Bin 166 -> 0 bytes .../testentities/textures/testentities_cube1.png | Bin 130 -> 0 bytes .../testentities/textures/testentities_cube2.png | Bin 128 -> 0 bytes .../testentities/textures/testentities_cube3.png | Bin 124 -> 0 bytes .../testentities/textures/testentities_cube4.png | Bin 126 -> 0 bytes .../testentities/textures/testentities_cube5.png | Bin 126 -> 0 bytes .../testentities/textures/testentities_cube6.png | Bin 126 -> 0 bytes .../textures/testentities_dungeon_master.png | Bin 2855 -> 0 bytes .../testentities/textures/testentities_sprite.png | Bin 120 -> 0 bytes .../textures/testentities_upright_sprite1.png | Bin 114 -> 0 bytes .../textures/testentities_upright_sprite2.png | Bin 119 -> 0 bytes games/minimal/mods/testentities/visuals.lua | 74 --- games/minimal/mods/testfood/init.lua | 24 - games/minimal/mods/testfood/mod.conf | 2 - .../mods/testfood/textures/testfood_bad.png | Bin 126 -> 0 bytes .../mods/testfood/textures/testfood_bad2.png | Bin 133 -> 0 bytes .../mods/testfood/textures/testfood_good.png | Bin 129 -> 0 bytes .../mods/testfood/textures/testfood_good2.png | Bin 145 -> 0 bytes games/minimal/mods/testformspec/callbacks.lua | 51 -- games/minimal/mods/testformspec/dummy_items.lua | 14 - games/minimal/mods/testformspec/formspec.lua | 381 ------------ games/minimal/mods/testformspec/init.lua | 3 - games/minimal/mods/testformspec/mod.conf | 2 - .../textures/testformspec_animation.jpg | Bin 4376 -> 0 bytes .../textures/testformspec_animation.png | Bin 214 -> 0 bytes .../mods/testformspec/textures/testformspec_bg.png | Bin 92 -> 0 bytes .../textures/testformspec_bg_9slice.png | Bin 146 -> 0 bytes .../textures/testformspec_bg_9slice_hovered.png | Bin 146 -> 0 bytes .../textures/testformspec_bg_9slice_pressed.png | Bin 146 -> 0 bytes .../textures/testformspec_bg_hovered.png | Bin 92 -> 0 bytes .../textures/testformspec_bg_pressed.png | Bin 91 -> 0 bytes .../textures/testformspec_button_image.png | Bin 146 -> 0 bytes .../testformspec/textures/testformspec_hovered.png | Bin 195 -> 0 bytes .../testformspec/textures/testformspec_item.png | Bin 182 -> 0 bytes .../testformspec/textures/testformspec_node.png | Bin 113 -> 0 bytes .../testformspec/textures/testformspec_pressed.png | Bin 165 -> 0 bytes games/minimal/mods/testnodes/README.md | 11 - games/minimal/mods/testnodes/drawtypes.lua | 517 --------------- games/minimal/mods/testnodes/init.lua | 10 - games/minimal/mods/testnodes/light.lua | 48 -- games/minimal/mods/testnodes/liquids.lua | 91 --- games/minimal/mods/testnodes/meshes.lua | 145 ----- games/minimal/mods/testnodes/mod.conf | 2 - .../mods/testnodes/models/testnodes_ocorner.obj | 23 - .../mods/testnodes/models/testnodes_pyramid.obj | 24 - games/minimal/mods/testnodes/nodeboxes.lua | 80 --- games/minimal/mods/testnodes/param2.lua | 168 ----- games/minimal/mods/testnodes/properties.lua | 270 -------- games/minimal/mods/testnodes/settingtypes.txt | 4 - games/minimal/mods/testnodes/textures.lua | 67 -- .../mods/testnodes/textures/testnodes_1.png | Bin 107 -> 0 bytes .../mods/testnodes/textures/testnodes_1g.png | Bin 104 -> 0 bytes .../mods/testnodes/textures/testnodes_1w.png | Bin 121 -> 0 bytes .../mods/testnodes/textures/testnodes_1wg.png | Bin 122 -> 0 bytes .../mods/testnodes/textures/testnodes_2.png | Bin 112 -> 0 bytes .../mods/testnodes/textures/testnodes_2g.png | Bin 110 -> 0 bytes .../mods/testnodes/textures/testnodes_2w.png | Bin 134 -> 0 bytes .../mods/testnodes/textures/testnodes_2wg.png | Bin 135 -> 0 bytes .../mods/testnodes/textures/testnodes_3.png | Bin 105 -> 0 bytes .../mods/testnodes/textures/testnodes_3g.png | Bin 103 -> 0 bytes .../mods/testnodes/textures/testnodes_3w.png | Bin 112 -> 0 bytes .../mods/testnodes/textures/testnodes_3wg.png | Bin 112 -> 0 bytes .../mods/testnodes/textures/testnodes_4.png | Bin 97 -> 0 bytes .../mods/testnodes/textures/testnodes_4g.png | Bin 95 -> 0 bytes .../mods/testnodes/textures/testnodes_4w.png | Bin 128 -> 0 bytes .../mods/testnodes/textures/testnodes_4wg.png | Bin 128 -> 0 bytes .../mods/testnodes/textures/testnodes_5.png | Bin 98 -> 0 bytes .../mods/testnodes/textures/testnodes_5g.png | Bin 98 -> 0 bytes .../mods/testnodes/textures/testnodes_5w.png | Bin 117 -> 0 bytes .../mods/testnodes/textures/testnodes_5wg.png | Bin 117 -> 0 bytes .../mods/testnodes/textures/testnodes_6.png | Bin 100 -> 0 bytes .../mods/testnodes/textures/testnodes_6g.png | Bin 98 -> 0 bytes .../mods/testnodes/textures/testnodes_6w.png | Bin 117 -> 0 bytes .../mods/testnodes/textures/testnodes_6wg.png | Bin 117 -> 0 bytes .../mods/testnodes/textures/testnodes_airlike.png | Bin 92 -> 0 bytes .../mods/testnodes/textures/testnodes_allfaces.png | Bin 150 -> 0 bytes .../textures/testnodes_allfaces_optional.png | Bin 150 -> 0 bytes .../mods/testnodes/textures/testnodes_alpha.png | Bin 96 -> 0 bytes .../mods/testnodes/textures/testnodes_alpha128.png | Bin 136 -> 0 bytes .../mods/testnodes/textures/testnodes_alpha191.png | Bin 132 -> 0 bytes .../mods/testnodes/textures/testnodes_alpha64.png | Bin 134 -> 0 bytes .../mods/testnodes/textures/testnodes_anim.png | Bin 274 -> 0 bytes .../textures/testnodes_attached_bottom.png | Bin 86 -> 0 bytes .../testnodes/textures/testnodes_attached_side.png | Bin 98 -> 0 bytes .../testnodes/textures/testnodes_attached_top.png | Bin 87 -> 0 bytes .../textures/testnodes_attachedw_bottom.png | Bin 130 -> 0 bytes .../textures/testnodes_attachedw_side.png | Bin 122 -> 0 bytes .../testnodes/textures/testnodes_attachedw_top.png | Bin 109 -> 0 bytes .../mods/testnodes/textures/testnodes_bouncy.png | Bin 106 -> 0 bytes .../testnodes/textures/testnodes_buildable_to.png | Bin 89 -> 0 bytes .../textures/testnodes_climbable_nojump_side.png | Bin 164 -> 0 bytes .../textures/testnodes_climbable_side.png | Bin 150 -> 0 bytes .../mods/testnodes/textures/testnodes_damage.png | Bin 108 -> 0 bytes .../testnodes/textures/testnodes_damage_neg.png | Bin 121 -> 0 bytes .../mods/testnodes/textures/testnodes_drowning.png | Bin 127 -> 0 bytes .../textures/testnodes_fall_damage_minus.png | Bin 116 -> 0 bytes .../textures/testnodes_fall_damage_plus.png | Bin 117 -> 0 bytes .../testnodes/textures/testnodes_fencelike.png | Bin 90 -> 0 bytes .../mods/testnodes/textures/testnodes_firelike.png | Bin 149 -> 0 bytes .../testnodes/textures/testnodes_glasslike.png | Bin 117 -> 0 bytes .../textures/testnodes_glasslike_detail.png | Bin 167 -> 0 bytes .../textures/testnodes_glasslike_framed.png | Bin 88 -> 0 bytes .../textures/testnodes_glasslike_framed2.png | Bin 118 -> 0 bytes .../testnodes_glasslike_framed_optional.png | Bin 128 -> 0 bytes .../textures/testnodes_glasslikeliquid.png | Bin 122 -> 0 bytes .../mods/testnodes/textures/testnodes_light.png | Bin 117 -> 0 bytes .../mods/testnodes/textures/testnodes_light_1.png | Bin 158 -> 0 bytes .../mods/testnodes/textures/testnodes_light_10.png | Bin 147 -> 0 bytes .../mods/testnodes/textures/testnodes_light_11.png | Bin 149 -> 0 bytes .../mods/testnodes/textures/testnodes_light_12.png | Bin 138 -> 0 bytes .../mods/testnodes/textures/testnodes_light_13.png | Bin 137 -> 0 bytes .../mods/testnodes/textures/testnodes_light_14.png | Bin 132 -> 0 bytes .../mods/testnodes/textures/testnodes_light_2.png | Bin 152 -> 0 bytes .../mods/testnodes/textures/testnodes_light_3.png | Bin 150 -> 0 bytes .../mods/testnodes/textures/testnodes_light_4.png | Bin 157 -> 0 bytes .../mods/testnodes/textures/testnodes_light_5.png | Bin 150 -> 0 bytes .../mods/testnodes/textures/testnodes_light_6.png | Bin 154 -> 0 bytes .../mods/testnodes/textures/testnodes_light_7.png | Bin 146 -> 0 bytes .../mods/testnodes/textures/testnodes_light_8.png | Bin 139 -> 0 bytes .../mods/testnodes/textures/testnodes_light_9.png | Bin 149 -> 0 bytes .../testnodes/textures/testnodes_line_crossing.png | Bin 130 -> 0 bytes .../testnodes/textures/testnodes_line_curved.png | Bin 123 -> 0 bytes .../testnodes/textures/testnodes_line_straight.png | Bin 115 -> 0 bytes .../textures/testnodes_line_t_junction.png | Bin 128 -> 0 bytes .../mods/testnodes/textures/testnodes_liquid.png | Bin 95 -> 0 bytes .../testnodes/textures/testnodes_liquidflowing.png | Bin 132 -> 0 bytes .../textures/testnodes_liquidflowing_r0.png | Bin 162 -> 0 bytes .../textures/testnodes_liquidflowing_r1.png | Bin 160 -> 0 bytes .../textures/testnodes_liquidflowing_r2.png | Bin 154 -> 0 bytes .../textures/testnodes_liquidflowing_r3.png | Bin 155 -> 0 bytes .../textures/testnodes_liquidflowing_r4.png | Bin 154 -> 0 bytes .../textures/testnodes_liquidflowing_r5.png | Bin 155 -> 0 bytes .../textures/testnodes_liquidflowing_r6.png | Bin 155 -> 0 bytes .../textures/testnodes_liquidflowing_r7.png | Bin 157 -> 0 bytes .../textures/testnodes_liquidflowing_r8.png | Bin 152 -> 0 bytes .../testnodes/textures/testnodes_liquidsource.png | Bin 128 -> 0 bytes .../textures/testnodes_liquidsource_r0.png | Bin 149 -> 0 bytes .../textures/testnodes_liquidsource_r1.png | Bin 152 -> 0 bytes .../textures/testnodes_liquidsource_r2.png | Bin 152 -> 0 bytes .../textures/testnodes_liquidsource_r3.png | Bin 152 -> 0 bytes .../textures/testnodes_liquidsource_r4.png | Bin 155 -> 0 bytes .../textures/testnodes_liquidsource_r5.png | Bin 150 -> 0 bytes .../textures/testnodes_liquidsource_r6.png | Bin 148 -> 0 bytes .../textures/testnodes_liquidsource_r7.png | Bin 154 -> 0 bytes .../textures/testnodes_liquidsource_r8.png | Bin 148 -> 0 bytes .../testnodes/textures/testnodes_mesh_stripes.png | Bin 150 -> 0 bytes .../testnodes/textures/testnodes_mesh_stripes2.png | Bin 144 -> 0 bytes .../testnodes/textures/testnodes_mesh_stripes3.png | Bin 85 -> 0 bytes .../testnodes/textures/testnodes_mesh_stripes4.png | Bin 93 -> 0 bytes .../mods/testnodes/textures/testnodes_node.png | Bin 89 -> 0 bytes .../testnodes/textures/testnodes_node_falling.png | Bin 112 -> 0 bytes .../mods/testnodes/textures/testnodes_nodebox.png | Bin 112 -> 0 bytes .../testnodes/textures/testnodes_nojump_side.png | Bin 94 -> 0 bytes .../testnodes/textures/testnodes_nojump_top.png | Bin 121 -> 0 bytes .../mods/testnodes/textures/testnodes_normal.png | Bin 92 -> 0 bytes .../mods/testnodes/textures/testnodes_normal1.png | Bin 114 -> 0 bytes .../mods/testnodes/textures/testnodes_normal2.png | Bin 122 -> 0 bytes .../mods/testnodes/textures/testnodes_normal3.png | Bin 114 -> 0 bytes .../mods/testnodes/textures/testnodes_normal4.png | Bin 106 -> 0 bytes .../mods/testnodes/textures/testnodes_normal5.png | Bin 109 -> 0 bytes .../mods/testnodes/textures/testnodes_normal6.png | Bin 111 -> 0 bytes .../textures/testnodes_palette_facedir.png | Bin 87 -> 0 bytes .../testnodes/textures/testnodes_palette_full.png | Bin 568 -> 0 bytes .../textures/testnodes_palette_wallmounted.png | Bin 136 -> 0 bytes .../testnodes/textures/testnodes_plantlike.png | Bin 183 -> 0 bytes .../textures/testnodes_plantlike_degrotate.png | Bin 176 -> 0 bytes .../textures/testnodes_plantlike_leveled.png | Bin 163 -> 0 bytes .../textures/testnodes_plantlike_meshoptions.png | Bin 164 -> 0 bytes .../textures/testnodes_plantlike_rooted.png | Bin 182 -> 0 bytes .../textures/testnodes_plantlike_rooted_base.png | Bin 101 -> 0 bytes ...tnodes_plantlike_rooted_base_side_degrotate.png | Bin 145 -> 0 bytes ...estnodes_plantlike_rooted_base_side_leveled.png | Bin 127 -> 0 bytes ...odes_plantlike_rooted_base_side_meshoptions.png | Bin 128 -> 0 bytes ...testnodes_plantlike_rooted_base_side_waving.png | Bin 126 -> 0 bytes .../testnodes_plantlike_rooted_degrotate.png | Bin 176 -> 0 bytes .../testnodes_plantlike_rooted_leveled.png | Bin 162 -> 0 bytes .../testnodes_plantlike_rooted_meshoptions.png | Bin 162 -> 0 bytes .../textures/testnodes_plantlike_rooted_waving.png | Bin 125 -> 0 bytes .../textures/testnodes_plantlike_waving.png | Bin 127 -> 0 bytes .../textures/testnodes_rail2_crossing.png | Bin 246 -> 0 bytes .../testnodes/textures/testnodes_rail2_curved.png | Bin 253 -> 0 bytes .../textures/testnodes_rail2_straight.png | Bin 246 -> 0 bytes .../textures/testnodes_rail2_t_junction.png | Bin 254 -> 0 bytes .../testnodes/textures/testnodes_rail_crossing.png | Bin 151 -> 0 bytes .../testnodes/textures/testnodes_rail_curved.png | Bin 164 -> 0 bytes .../testnodes/textures/testnodes_rail_straight.png | Bin 133 -> 0 bytes .../textures/testnodes_rail_t_junction.png | Bin 202 -> 0 bytes .../mods/testnodes/textures/testnodes_signlike.png | Bin 150 -> 0 bytes .../mods/testnodes/textures/testnodes_slippery.png | Bin 111 -> 0 bytes .../textures/testnodes_street_crossing.png | Bin 137 -> 0 bytes .../testnodes/textures/testnodes_street_curved.png | Bin 115 -> 0 bytes .../textures/testnodes_street_straight.png | Bin 101 -> 0 bytes .../textures/testnodes_street_t_junction.png | Bin 126 -> 0 bytes .../textures/testnodes_sunlight_filter.png | Bin 113 -> 0 bytes .../textures/testnodes_torchlike_ceiling.png | Bin 157 -> 0 bytes .../textures/testnodes_torchlike_floor.png | Bin 141 -> 0 bytes .../textures/testnodes_torchlike_wall.png | Bin 158 -> 0 bytes games/minimal/mods/testpathfinder/README.md | 15 - games/minimal/mods/testpathfinder/init.lua | 132 ---- games/minimal/mods/testpathfinder/mod.conf | 2 - .../textures/testpathfinder_testpathfinder.png | Bin 159 -> 0 bytes .../textures/testpathfinder_waypoint.png | Bin 99 -> 0 bytes .../textures/testpathfinder_waypoint_end.png | Bin 147 -> 0 bytes .../textures/testpathfinder_waypoint_start.png | Bin 139 -> 0 bytes games/minimal/mods/testtools/README.md | 99 --- games/minimal/mods/testtools/init.lua | 691 --------------------- games/minimal/mods/testtools/mod.conf | 2 - .../textures/testtools_entity_rotator.png | Bin 151 -> 0 bytes .../testtools/textures/testtools_entity_scaler.png | Bin 182 -> 0 bytes .../textures/testtools_entity_spawner.png | Bin 189 -> 0 bytes .../textures/testtools_falling_node_tool.png | Bin 140 -> 0 bytes .../testtools/textures/testtools_node_setter.png | Bin 146 -> 0 bytes .../textures/testtools_object_attacher.png | Bin 173 -> 0 bytes .../testtools/textures/testtools_object_editor.png | Bin 180 -> 0 bytes .../testtools/textures/testtools_object_mover.png | Bin 175 -> 0 bytes .../testtools/textures/testtools_param2tool.png | Bin 127 -> 0 bytes .../mods/testtools/textures/testtools_remover.png | Bin 129 -> 0 bytes games/minimal/mods/tiled/init.lua | 33 - games/minimal/mods/tiled/mod.conf | 3 - games/minimal/mods/tiled/textures/tiled_tiled.png | Bin 410 -> 0 bytes games/minimal/mods/unittests/crafting.lua | 120 ---- games/minimal/mods/unittests/crafting_prepare.lua | 88 --- games/minimal/mods/unittests/init.lua | 16 - games/minimal/mods/unittests/mod.conf | 2 - games/minimal/mods/unittests/player.lua | 73 --- games/minimal/mods/unittests/random.lua | 10 - .../unittests/textures/unittests_coal_lump.png | Bin 160 -> 0 bytes .../unittests/textures/unittests_iron_lump.png | Bin 154 -> 0 bytes .../textures/unittests_repairable_tool.png | Bin 160 -> 0 bytes .../unittests/textures/unittests_steel_ingot.png | Bin 159 -> 0 bytes .../mods/unittests/textures/unittests_stick.png | Bin 147 -> 0 bytes .../mods/unittests/textures/unittests_torch.png | Bin 155 -> 0 bytes .../textures/unittests_unrepairable_tool.png | Bin 157 -> 0 bytes games/minimal/mods/util_commands/init.lua | 137 ---- games/minimal/mods/util_commands/mod.conf | 2 - games/minimal/screenshot.png | Bin 133364 -> 0 bytes games/minimal/settingtypes.txt | 37 -- src/unittest/CMakeLists.txt | 2 +- src/unittest/test_servermodmanager.cpp | 10 +- util/test_multiplayer.sh | 2 +- 731 files changed, 5299 insertions(+), 5299 deletions(-) create mode 100644 games/devtest/LICENSE.txt create mode 100644 games/devtest/README.md create mode 100644 games/devtest/game.conf create mode 100644 games/devtest/menu/background.png create mode 100644 games/devtest/menu/header.png create mode 100644 games/devtest/menu/icon.png create mode 100644 games/devtest/mods/basenodes/init.lua create mode 100644 games/devtest/mods/basenodes/mod.conf create mode 100644 games/devtest/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png create mode 100644 games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow.png create mode 100644 games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png create mode 100644 games/devtest/mods/basenodes/textures/basenodes_snow_sheet.png create mode 100644 games/devtest/mods/basenodes/textures/default_apple.png create mode 100644 games/devtest/mods/basenodes/textures/default_cobble.png create mode 100644 games/devtest/mods/basenodes/textures/default_desert_sand.png create mode 100644 games/devtest/mods/basenodes/textures/default_desert_stone.png create mode 100644 games/devtest/mods/basenodes/textures/default_dirt.png create mode 100644 games/devtest/mods/basenodes/textures/default_grass.png create mode 100644 games/devtest/mods/basenodes/textures/default_grass_side.png create mode 100644 games/devtest/mods/basenodes/textures/default_gravel.png create mode 100644 games/devtest/mods/basenodes/textures/default_ice.png create mode 100644 games/devtest/mods/basenodes/textures/default_junglegrass.png create mode 100644 games/devtest/mods/basenodes/textures/default_jungleleaves.png create mode 100644 games/devtest/mods/basenodes/textures/default_jungletree.png create mode 100644 games/devtest/mods/basenodes/textures/default_jungletree_top.png create mode 100644 games/devtest/mods/basenodes/textures/default_lava.png create mode 100644 games/devtest/mods/basenodes/textures/default_lava_flowing.png create mode 100644 games/devtest/mods/basenodes/textures/default_leaves.png create mode 100644 games/devtest/mods/basenodes/textures/default_mossycobble.png create mode 100644 games/devtest/mods/basenodes/textures/default_pine_needles.png create mode 100644 games/devtest/mods/basenodes/textures/default_pine_tree.png create mode 100644 games/devtest/mods/basenodes/textures/default_pine_tree_top.png create mode 100644 games/devtest/mods/basenodes/textures/default_river_water.png create mode 100644 games/devtest/mods/basenodes/textures/default_river_water_flowing.png create mode 100644 games/devtest/mods/basenodes/textures/default_sand.png create mode 100644 games/devtest/mods/basenodes/textures/default_snow.png create mode 100644 games/devtest/mods/basenodes/textures/default_snow_side.png create mode 100644 games/devtest/mods/basenodes/textures/default_stone.png create mode 100644 games/devtest/mods/basenodes/textures/default_tree.png create mode 100644 games/devtest/mods/basenodes/textures/default_tree_top.png create mode 100644 games/devtest/mods/basenodes/textures/default_water.png create mode 100644 games/devtest/mods/basenodes/textures/default_water_flowing.png create mode 100644 games/devtest/mods/basetools/init.lua create mode 100644 games/devtest/mods/basetools/mod.conf create mode 100644 games/devtest/mods/basetools/textures/basetools_dirtpick.png create mode 100644 games/devtest/mods/basetools/textures/basetools_firesword.png create mode 100644 games/devtest/mods/basetools/textures/basetools_icesword.png create mode 100644 games/devtest/mods/basetools/textures/basetools_mesepick.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelaxe.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steeldagger.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelpick.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelpick_l1.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelpick_l2.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelshears.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelshovel.png create mode 100644 games/devtest/mods/basetools/textures/basetools_steelsword.png create mode 100644 games/devtest/mods/basetools/textures/basetools_stoneaxe.png create mode 100644 games/devtest/mods/basetools/textures/basetools_stonepick.png create mode 100644 games/devtest/mods/basetools/textures/basetools_stoneshears.png create mode 100644 games/devtest/mods/basetools/textures/basetools_stoneshovel.png create mode 100644 games/devtest/mods/basetools/textures/basetools_stonesword.png create mode 100644 games/devtest/mods/basetools/textures/basetools_woodaxe.png create mode 100644 games/devtest/mods/basetools/textures/basetools_woodpick.png create mode 100644 games/devtest/mods/basetools/textures/basetools_woodshears.png create mode 100644 games/devtest/mods/basetools/textures/basetools_woodshovel.png create mode 100644 games/devtest/mods/basetools/textures/basetools_woodsword.png create mode 100644 games/devtest/mods/bucket/init.lua create mode 100644 games/devtest/mods/bucket/mod.conf create mode 100644 games/devtest/mods/bucket/textures/bucket.png create mode 100644 games/devtest/mods/bucket/textures/bucket_lava.png create mode 100644 games/devtest/mods/bucket/textures/bucket_water.png create mode 100644 games/devtest/mods/chest/init.lua create mode 100644 games/devtest/mods/chest/mod.conf create mode 100644 games/devtest/mods/chest/textures/chest_chest.png create mode 100644 games/devtest/mods/chest_of_everything/init.lua create mode 100644 games/devtest/mods/chest_of_everything/mod.conf create mode 100644 games/devtest/mods/chest_of_everything/textures/chest_of_everything_chest.png create mode 100644 games/devtest/mods/dignodes/init.lua create mode 100644 games/devtest/mods/dignodes/mod.conf create mode 100644 games/devtest/mods/dignodes/textures/dignodes_choppy.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_cracky.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_crumbly.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_dig_immediate.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_none.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_rating1.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_rating2.png create mode 100644 games/devtest/mods/dignodes/textures/dignodes_rating3.png create mode 100644 games/devtest/mods/experimental/commands.lua create mode 100644 games/devtest/mods/experimental/detached.lua create mode 100644 games/devtest/mods/experimental/init.lua create mode 100644 games/devtest/mods/experimental/items.lua create mode 100644 games/devtest/mods/experimental/mod.conf create mode 100644 games/devtest/mods/experimental/textures/experimental_callback_node.png create mode 100644 games/devtest/mods/experimental/textures/experimental_particle_sheet.png create mode 100644 games/devtest/mods/experimental/textures/experimental_particle_vertical.png create mode 100644 games/devtest/mods/experimental/textures/experimental_tester_tool_1.png create mode 100644 games/devtest/mods/give_initial_stuff/init.lua create mode 100644 games/devtest/mods/give_initial_stuff/mod.conf create mode 100644 games/devtest/mods/initial_message/init.lua create mode 100644 games/devtest/mods/initial_message/mod.conf create mode 100644 games/devtest/mods/mapgen/init.lua create mode 100644 games/devtest/mods/mapgen/mod.conf create mode 100644 games/devtest/mods/modchannels/init.lua create mode 100644 games/devtest/mods/modchannels/mod.conf create mode 100644 games/devtest/mods/soundstuff/init.lua create mode 100644 games/devtest/mods/soundstuff/mod.conf create mode 100644 games/devtest/mods/soundstuff/sounds/soundstuff_mono.ogg create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_eat.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_blank.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_climbable.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_dig.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_dug.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_fall.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_footstep.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_place.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_place_failed.png create mode 100644 games/devtest/mods/soundstuff/textures/soundstuff_node_sound.png create mode 100644 games/devtest/mods/stairs/init.lua create mode 100644 games/devtest/mods/stairs/mod.conf create mode 100644 games/devtest/mods/testentities/armor.lua create mode 100644 games/devtest/mods/testentities/callbacks.lua create mode 100644 games/devtest/mods/testentities/init.lua create mode 100644 games/devtest/mods/testentities/mod.conf create mode 100644 games/devtest/mods/testentities/textures/testentities_armorball.png create mode 100644 games/devtest/mods/testentities/textures/testentities_callback.png create mode 100644 games/devtest/mods/testentities/textures/testentities_callback_step.png create mode 100644 games/devtest/mods/testentities/textures/testentities_cube1.png create mode 100644 games/devtest/mods/testentities/textures/testentities_cube2.png create mode 100644 games/devtest/mods/testentities/textures/testentities_cube3.png create mode 100644 games/devtest/mods/testentities/textures/testentities_cube4.png create mode 100644 games/devtest/mods/testentities/textures/testentities_cube5.png create mode 100644 games/devtest/mods/testentities/textures/testentities_cube6.png create mode 100644 games/devtest/mods/testentities/textures/testentities_dungeon_master.png create mode 100644 games/devtest/mods/testentities/textures/testentities_sprite.png create mode 100644 games/devtest/mods/testentities/textures/testentities_upright_sprite1.png create mode 100644 games/devtest/mods/testentities/textures/testentities_upright_sprite2.png create mode 100644 games/devtest/mods/testentities/visuals.lua create mode 100644 games/devtest/mods/testfood/init.lua create mode 100644 games/devtest/mods/testfood/mod.conf create mode 100644 games/devtest/mods/testfood/textures/testfood_bad.png create mode 100644 games/devtest/mods/testfood/textures/testfood_bad2.png create mode 100644 games/devtest/mods/testfood/textures/testfood_good.png create mode 100644 games/devtest/mods/testfood/textures/testfood_good2.png create mode 100644 games/devtest/mods/testformspec/callbacks.lua create mode 100644 games/devtest/mods/testformspec/dummy_items.lua create mode 100644 games/devtest/mods/testformspec/formspec.lua create mode 100644 games/devtest/mods/testformspec/init.lua create mode 100644 games/devtest/mods/testformspec/mod.conf create mode 100644 games/devtest/mods/testformspec/textures/testformspec_animation.jpg create mode 100644 games/devtest/mods/testformspec/textures/testformspec_animation.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_bg.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_bg_9slice.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_bg_9slice_hovered.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_bg_9slice_pressed.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_bg_hovered.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_bg_pressed.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_button_image.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_hovered.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_item.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_node.png create mode 100644 games/devtest/mods/testformspec/textures/testformspec_pressed.png create mode 100644 games/devtest/mods/testnodes/README.md create mode 100644 games/devtest/mods/testnodes/drawtypes.lua create mode 100644 games/devtest/mods/testnodes/init.lua create mode 100644 games/devtest/mods/testnodes/light.lua create mode 100644 games/devtest/mods/testnodes/liquids.lua create mode 100644 games/devtest/mods/testnodes/meshes.lua create mode 100644 games/devtest/mods/testnodes/mod.conf create mode 100644 games/devtest/mods/testnodes/models/testnodes_ocorner.obj create mode 100644 games/devtest/mods/testnodes/models/testnodes_pyramid.obj create mode 100644 games/devtest/mods/testnodes/nodeboxes.lua create mode 100644 games/devtest/mods/testnodes/param2.lua create mode 100644 games/devtest/mods/testnodes/properties.lua create mode 100644 games/devtest/mods/testnodes/settingtypes.txt create mode 100644 games/devtest/mods/testnodes/textures.lua create mode 100644 games/devtest/mods/testnodes/textures/testnodes_1.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_1g.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_1w.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_1wg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_2g.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_2w.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_2wg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_3.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_3g.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_3w.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_3wg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_4.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_4g.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_4w.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_4wg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_5.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_5g.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_5w.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_5wg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_6.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_6g.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_6w.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_6wg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_airlike.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_allfaces.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_allfaces_optional.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_alpha.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_alpha128.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_alpha191.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_alpha64.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_anim.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_attached_bottom.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_attached_side.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_attached_top.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_attachedw_bottom.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_attachedw_side.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_attachedw_top.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_bouncy.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_buildable_to.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_climbable_nojump_side.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_climbable_side.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_damage.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_damage_neg.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_drowning.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_fall_damage_minus.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_fall_damage_plus.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_fencelike.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_firelike.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_glasslike.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_glasslike_detail.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_glasslike_framed.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_glasslike_framed2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_glasslike_framed_optional.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_glasslikeliquid.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_1.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_10.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_11.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_12.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_13.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_14.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_3.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_4.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_5.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_6.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_7.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_8.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_light_9.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_line_crossing.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_line_curved.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_line_straight.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_line_t_junction.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquid.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r0.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r1.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r3.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r4.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r5.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r6.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r7.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r8.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r0.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r1.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r3.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r4.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r5.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r6.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r7.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_liquidsource_r8.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_mesh_stripes.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_mesh_stripes2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_mesh_stripes3.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_mesh_stripes4.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_node.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_node_falling.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_nodebox.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_nojump_side.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_nojump_top.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal1.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal2.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal3.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal4.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal5.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_normal6.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_palette_facedir.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_palette_full.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_palette_wallmounted.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_degrotate.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_leveled.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_meshoptions.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_plantlike_waving.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail2_crossing.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail2_curved.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail2_straight.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail2_t_junction.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail_crossing.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail_curved.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail_straight.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_rail_t_junction.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_signlike.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_slippery.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_street_crossing.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_street_curved.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_street_straight.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_street_t_junction.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_sunlight_filter.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_torchlike_ceiling.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_torchlike_floor.png create mode 100644 games/devtest/mods/testnodes/textures/testnodes_torchlike_wall.png create mode 100644 games/devtest/mods/testpathfinder/README.md create mode 100644 games/devtest/mods/testpathfinder/init.lua create mode 100644 games/devtest/mods/testpathfinder/mod.conf create mode 100644 games/devtest/mods/testpathfinder/textures/testpathfinder_testpathfinder.png create mode 100644 games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint.png create mode 100644 games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_end.png create mode 100644 games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_start.png create mode 100644 games/devtest/mods/testtools/README.md create mode 100644 games/devtest/mods/testtools/init.lua create mode 100644 games/devtest/mods/testtools/mod.conf create mode 100644 games/devtest/mods/testtools/textures/testtools_entity_rotator.png create mode 100644 games/devtest/mods/testtools/textures/testtools_entity_scaler.png create mode 100644 games/devtest/mods/testtools/textures/testtools_entity_spawner.png create mode 100644 games/devtest/mods/testtools/textures/testtools_falling_node_tool.png create mode 100644 games/devtest/mods/testtools/textures/testtools_node_setter.png create mode 100644 games/devtest/mods/testtools/textures/testtools_object_attacher.png create mode 100644 games/devtest/mods/testtools/textures/testtools_object_editor.png create mode 100644 games/devtest/mods/testtools/textures/testtools_object_mover.png create mode 100644 games/devtest/mods/testtools/textures/testtools_param2tool.png create mode 100644 games/devtest/mods/testtools/textures/testtools_remover.png create mode 100644 games/devtest/mods/tiled/init.lua create mode 100644 games/devtest/mods/tiled/mod.conf create mode 100644 games/devtest/mods/tiled/textures/tiled_tiled.png create mode 100644 games/devtest/mods/unittests/crafting.lua create mode 100644 games/devtest/mods/unittests/crafting_prepare.lua create mode 100644 games/devtest/mods/unittests/init.lua create mode 100644 games/devtest/mods/unittests/mod.conf create mode 100644 games/devtest/mods/unittests/player.lua create mode 100644 games/devtest/mods/unittests/random.lua create mode 100644 games/devtest/mods/unittests/textures/unittests_coal_lump.png create mode 100644 games/devtest/mods/unittests/textures/unittests_iron_lump.png create mode 100644 games/devtest/mods/unittests/textures/unittests_repairable_tool.png create mode 100644 games/devtest/mods/unittests/textures/unittests_steel_ingot.png create mode 100644 games/devtest/mods/unittests/textures/unittests_stick.png create mode 100644 games/devtest/mods/unittests/textures/unittests_torch.png create mode 100644 games/devtest/mods/unittests/textures/unittests_unrepairable_tool.png create mode 100644 games/devtest/mods/util_commands/init.lua create mode 100644 games/devtest/mods/util_commands/mod.conf create mode 100644 games/devtest/screenshot.png create mode 100644 games/devtest/settingtypes.txt delete mode 100644 games/minimal/LICENSE.txt delete mode 100644 games/minimal/README.md delete mode 100644 games/minimal/game.conf delete mode 100644 games/minimal/menu/background.png delete mode 100644 games/minimal/menu/header.png delete mode 100644 games/minimal/menu/icon.png delete mode 100644 games/minimal/mods/basenodes/init.lua delete mode 100644 games/minimal/mods/basenodes/mod.conf delete mode 100644 games/minimal/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png delete mode 100644 games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow.png delete mode 100644 games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png delete mode 100644 games/minimal/mods/basenodes/textures/basenodes_snow_sheet.png delete mode 100644 games/minimal/mods/basenodes/textures/default_apple.png delete mode 100644 games/minimal/mods/basenodes/textures/default_cobble.png delete mode 100644 games/minimal/mods/basenodes/textures/default_desert_sand.png delete mode 100644 games/minimal/mods/basenodes/textures/default_desert_stone.png delete mode 100644 games/minimal/mods/basenodes/textures/default_dirt.png delete mode 100644 games/minimal/mods/basenodes/textures/default_grass.png delete mode 100644 games/minimal/mods/basenodes/textures/default_grass_side.png delete mode 100644 games/minimal/mods/basenodes/textures/default_gravel.png delete mode 100644 games/minimal/mods/basenodes/textures/default_ice.png delete mode 100644 games/minimal/mods/basenodes/textures/default_junglegrass.png delete mode 100644 games/minimal/mods/basenodes/textures/default_jungleleaves.png delete mode 100644 games/minimal/mods/basenodes/textures/default_jungletree.png delete mode 100644 games/minimal/mods/basenodes/textures/default_jungletree_top.png delete mode 100644 games/minimal/mods/basenodes/textures/default_lava.png delete mode 100644 games/minimal/mods/basenodes/textures/default_lava_flowing.png delete mode 100644 games/minimal/mods/basenodes/textures/default_leaves.png delete mode 100644 games/minimal/mods/basenodes/textures/default_mossycobble.png delete mode 100644 games/minimal/mods/basenodes/textures/default_pine_needles.png delete mode 100644 games/minimal/mods/basenodes/textures/default_pine_tree.png delete mode 100644 games/minimal/mods/basenodes/textures/default_pine_tree_top.png delete mode 100644 games/minimal/mods/basenodes/textures/default_river_water.png delete mode 100644 games/minimal/mods/basenodes/textures/default_river_water_flowing.png delete mode 100644 games/minimal/mods/basenodes/textures/default_sand.png delete mode 100644 games/minimal/mods/basenodes/textures/default_snow.png delete mode 100644 games/minimal/mods/basenodes/textures/default_snow_side.png delete mode 100644 games/minimal/mods/basenodes/textures/default_stone.png delete mode 100644 games/minimal/mods/basenodes/textures/default_tree.png delete mode 100644 games/minimal/mods/basenodes/textures/default_tree_top.png delete mode 100644 games/minimal/mods/basenodes/textures/default_water.png delete mode 100644 games/minimal/mods/basenodes/textures/default_water_flowing.png delete mode 100644 games/minimal/mods/basetools/init.lua delete mode 100644 games/minimal/mods/basetools/mod.conf delete mode 100644 games/minimal/mods/basetools/textures/basetools_dirtpick.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_firesword.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_icesword.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_mesepick.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelaxe.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steeldagger.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelpick.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelpick_l1.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelpick_l2.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelshears.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelshovel.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_steelsword.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_stoneaxe.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_stonepick.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_stoneshears.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_stoneshovel.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_stonesword.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_woodaxe.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_woodpick.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_woodshears.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_woodshovel.png delete mode 100644 games/minimal/mods/basetools/textures/basetools_woodsword.png delete mode 100644 games/minimal/mods/bucket/init.lua delete mode 100644 games/minimal/mods/bucket/mod.conf delete mode 100644 games/minimal/mods/bucket/textures/bucket.png delete mode 100644 games/minimal/mods/bucket/textures/bucket_lava.png delete mode 100644 games/minimal/mods/bucket/textures/bucket_water.png delete mode 100644 games/minimal/mods/chest/init.lua delete mode 100644 games/minimal/mods/chest/mod.conf delete mode 100644 games/minimal/mods/chest/textures/chest_chest.png delete mode 100644 games/minimal/mods/chest_of_everything/init.lua delete mode 100644 games/minimal/mods/chest_of_everything/mod.conf delete mode 100644 games/minimal/mods/chest_of_everything/textures/chest_of_everything_chest.png delete mode 100644 games/minimal/mods/dignodes/init.lua delete mode 100644 games/minimal/mods/dignodes/mod.conf delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_choppy.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_cracky.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_crumbly.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_dig_immediate.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_none.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_rating1.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_rating2.png delete mode 100644 games/minimal/mods/dignodes/textures/dignodes_rating3.png delete mode 100644 games/minimal/mods/experimental/commands.lua delete mode 100644 games/minimal/mods/experimental/detached.lua delete mode 100644 games/minimal/mods/experimental/init.lua delete mode 100644 games/minimal/mods/experimental/items.lua delete mode 100644 games/minimal/mods/experimental/mod.conf delete mode 100644 games/minimal/mods/experimental/textures/experimental_callback_node.png delete mode 100644 games/minimal/mods/experimental/textures/experimental_particle_sheet.png delete mode 100644 games/minimal/mods/experimental/textures/experimental_particle_vertical.png delete mode 100644 games/minimal/mods/experimental/textures/experimental_tester_tool_1.png delete mode 100644 games/minimal/mods/give_initial_stuff/init.lua delete mode 100644 games/minimal/mods/give_initial_stuff/mod.conf delete mode 100644 games/minimal/mods/initial_message/init.lua delete mode 100644 games/minimal/mods/initial_message/mod.conf delete mode 100644 games/minimal/mods/mapgen/init.lua delete mode 100644 games/minimal/mods/mapgen/mod.conf delete mode 100644 games/minimal/mods/modchannels/init.lua delete mode 100644 games/minimal/mods/modchannels/mod.conf delete mode 100644 games/minimal/mods/soundstuff/init.lua delete mode 100644 games/minimal/mods/soundstuff/mod.conf delete mode 100644 games/minimal/mods/soundstuff/sounds/soundstuff_mono.ogg delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_eat.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_blank.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_climbable.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_dig.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_dug.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_fall.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_footstep.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_place.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_place_failed.png delete mode 100644 games/minimal/mods/soundstuff/textures/soundstuff_node_sound.png delete mode 100644 games/minimal/mods/stairs/init.lua delete mode 100644 games/minimal/mods/stairs/mod.conf delete mode 100644 games/minimal/mods/testentities/armor.lua delete mode 100644 games/minimal/mods/testentities/callbacks.lua delete mode 100644 games/minimal/mods/testentities/init.lua delete mode 100644 games/minimal/mods/testentities/mod.conf delete mode 100644 games/minimal/mods/testentities/textures/testentities_armorball.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_callback.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_callback_step.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_cube1.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_cube2.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_cube3.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_cube4.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_cube5.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_cube6.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_dungeon_master.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_sprite.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_upright_sprite1.png delete mode 100644 games/minimal/mods/testentities/textures/testentities_upright_sprite2.png delete mode 100644 games/minimal/mods/testentities/visuals.lua delete mode 100644 games/minimal/mods/testfood/init.lua delete mode 100644 games/minimal/mods/testfood/mod.conf delete mode 100644 games/minimal/mods/testfood/textures/testfood_bad.png delete mode 100644 games/minimal/mods/testfood/textures/testfood_bad2.png delete mode 100644 games/minimal/mods/testfood/textures/testfood_good.png delete mode 100644 games/minimal/mods/testfood/textures/testfood_good2.png delete mode 100644 games/minimal/mods/testformspec/callbacks.lua delete mode 100644 games/minimal/mods/testformspec/dummy_items.lua delete mode 100644 games/minimal/mods/testformspec/formspec.lua delete mode 100644 games/minimal/mods/testformspec/init.lua delete mode 100644 games/minimal/mods/testformspec/mod.conf delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_animation.jpg delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_animation.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_bg.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_bg_9slice.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_bg_9slice_hovered.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_bg_9slice_pressed.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_bg_hovered.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_bg_pressed.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_button_image.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_hovered.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_item.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_node.png delete mode 100644 games/minimal/mods/testformspec/textures/testformspec_pressed.png delete mode 100644 games/minimal/mods/testnodes/README.md delete mode 100644 games/minimal/mods/testnodes/drawtypes.lua delete mode 100644 games/minimal/mods/testnodes/init.lua delete mode 100644 games/minimal/mods/testnodes/light.lua delete mode 100644 games/minimal/mods/testnodes/liquids.lua delete mode 100644 games/minimal/mods/testnodes/meshes.lua delete mode 100644 games/minimal/mods/testnodes/mod.conf delete mode 100644 games/minimal/mods/testnodes/models/testnodes_ocorner.obj delete mode 100644 games/minimal/mods/testnodes/models/testnodes_pyramid.obj delete mode 100644 games/minimal/mods/testnodes/nodeboxes.lua delete mode 100644 games/minimal/mods/testnodes/param2.lua delete mode 100644 games/minimal/mods/testnodes/properties.lua delete mode 100644 games/minimal/mods/testnodes/settingtypes.txt delete mode 100644 games/minimal/mods/testnodes/textures.lua delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_1.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_1g.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_1w.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_1wg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_2g.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_2w.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_2wg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_3.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_3g.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_3w.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_3wg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_4.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_4g.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_4w.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_4wg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_5.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_5g.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_5w.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_5wg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_6.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_6g.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_6w.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_6wg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_airlike.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_allfaces.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_allfaces_optional.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_alpha.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_alpha128.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_alpha191.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_alpha64.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_anim.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_attached_bottom.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_attached_side.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_attached_top.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_attachedw_bottom.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_attachedw_side.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_attachedw_top.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_bouncy.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_buildable_to.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_climbable_nojump_side.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_climbable_side.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_damage.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_damage_neg.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_drowning.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_fall_damage_minus.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_fall_damage_plus.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_fencelike.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_firelike.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_glasslike.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_glasslike_detail.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_glasslike_framed.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_glasslike_framed2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_glasslike_framed_optional.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_glasslikeliquid.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_1.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_10.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_11.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_12.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_13.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_14.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_3.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_4.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_5.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_6.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_7.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_8.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_light_9.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_line_crossing.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_line_curved.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_line_straight.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_line_t_junction.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquid.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r0.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r1.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r3.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r4.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r5.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r6.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r7.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r8.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r0.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r1.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r3.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r4.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r5.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r6.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r7.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_liquidsource_r8.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_mesh_stripes.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_mesh_stripes2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_mesh_stripes3.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_mesh_stripes4.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_node.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_node_falling.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_nodebox.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_nojump_side.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_nojump_top.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal1.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal2.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal3.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal4.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal5.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_normal6.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_palette_facedir.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_palette_full.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_palette_wallmounted.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_degrotate.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_leveled.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_meshoptions.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_plantlike_waving.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail2_crossing.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail2_curved.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail2_straight.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail2_t_junction.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail_crossing.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail_curved.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail_straight.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_rail_t_junction.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_signlike.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_slippery.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_street_crossing.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_street_curved.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_street_straight.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_street_t_junction.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_sunlight_filter.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_torchlike_ceiling.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_torchlike_floor.png delete mode 100644 games/minimal/mods/testnodes/textures/testnodes_torchlike_wall.png delete mode 100644 games/minimal/mods/testpathfinder/README.md delete mode 100644 games/minimal/mods/testpathfinder/init.lua delete mode 100644 games/minimal/mods/testpathfinder/mod.conf delete mode 100644 games/minimal/mods/testpathfinder/textures/testpathfinder_testpathfinder.png delete mode 100644 games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint.png delete mode 100644 games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_end.png delete mode 100644 games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_start.png delete mode 100644 games/minimal/mods/testtools/README.md delete mode 100644 games/minimal/mods/testtools/init.lua delete mode 100644 games/minimal/mods/testtools/mod.conf delete mode 100644 games/minimal/mods/testtools/textures/testtools_entity_rotator.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_entity_scaler.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_entity_spawner.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_falling_node_tool.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_node_setter.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_object_attacher.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_object_editor.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_object_mover.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_param2tool.png delete mode 100644 games/minimal/mods/testtools/textures/testtools_remover.png delete mode 100644 games/minimal/mods/tiled/init.lua delete mode 100644 games/minimal/mods/tiled/mod.conf delete mode 100644 games/minimal/mods/tiled/textures/tiled_tiled.png delete mode 100644 games/minimal/mods/unittests/crafting.lua delete mode 100644 games/minimal/mods/unittests/crafting_prepare.lua delete mode 100644 games/minimal/mods/unittests/init.lua delete mode 100644 games/minimal/mods/unittests/mod.conf delete mode 100644 games/minimal/mods/unittests/player.lua delete mode 100644 games/minimal/mods/unittests/random.lua delete mode 100644 games/minimal/mods/unittests/textures/unittests_coal_lump.png delete mode 100644 games/minimal/mods/unittests/textures/unittests_iron_lump.png delete mode 100644 games/minimal/mods/unittests/textures/unittests_repairable_tool.png delete mode 100644 games/minimal/mods/unittests/textures/unittests_steel_ingot.png delete mode 100644 games/minimal/mods/unittests/textures/unittests_stick.png delete mode 100644 games/minimal/mods/unittests/textures/unittests_torch.png delete mode 100644 games/minimal/mods/unittests/textures/unittests_unrepairable_tool.png delete mode 100644 games/minimal/mods/util_commands/init.lua delete mode 100644 games/minimal/mods/util_commands/mod.conf delete mode 100644 games/minimal/screenshot.png delete mode 100644 games/minimal/settingtypes.txt (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index ae842918b..a5f644652 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,7 +167,7 @@ endif() install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minetest_game" DESTINATION "${SHAREDIR}/games/" COMPONENT "SUBGAME_MINETEST_GAME" OPTIONAL PATTERN ".git*" EXCLUDE ) -install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/minimal" DESTINATION "${SHAREDIR}/games/" +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/games/devtest" DESTINATION "${SHAREDIR}/games/" COMPONENT "SUBGAME_MINIMAL" OPTIONAL PATTERN ".git*" EXCLUDE ) if(BUILD_CLIENT) @@ -254,8 +254,8 @@ cpack_add_component(SUBGAME_MINETEST_GAME ) cpack_add_component(SUBGAME_MINIMAL - DISPLAY_NAME "Minimal development test" - DESCRIPTION "A minimal subgame helping to develop the engine." + DISPLAY_NAME "Development Test" + DESCRIPTION "A minimal test game helping to develop the engine." DISABLED #DISABLED does not mean it is disabled, and is just not selected by default. GROUP "Subgames" ) diff --git a/README.md b/README.md index 202ba4fe2..6a3c11f40 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ Download source (this is the URL to the latest of source repository, which might git clone --depth 1 https://github.com/minetest/minetest.git cd minetest -Download minetest_game (otherwise only the "Minimal development test" game is available) using Git: +Download minetest_game (otherwise only the "Development Test" game is available) using Git: git clone --depth 1 https://github.com/minetest/minetest_game.git games/minetest_game diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index 0d977a17c..36df23cce 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -304,13 +304,13 @@ local function create_world_formspec(dialogdata) label_spflags = "label[0,"..y_start..";" .. fgettext("Mapgen-specific flags") .. "]" end - -- Warning if only minimal is installed - local minimal_only = "" + -- Warning if only devtest is installed + local devtest_only = "" local gamelist_height = 2.3 - if #pkgmgr.games == 1 and pkgmgr.games[1].id == "minimal" then - minimal_only = "box[0,0;5.8,1.7;#ff8800]" .. + if #pkgmgr.games == 1 and pkgmgr.games[1].id == "devtest" then + devtest_only = "box[0,0;5.8,1.7;#ff8800]" .. "textarea[0.3,0;6,1.8;;;".. - fgettext("Warning: The minimal development test is meant for developers.") .. "\n" .. + fgettext("Warning: The Development Test is meant for developers.") .. "\n" .. fgettext("Download a game, such as Minetest Game, from minetest.net") .. "]" gamelist_height = 0.5 end @@ -335,7 +335,7 @@ local function create_world_formspec(dialogdata) "textlist[0,3.85;5.8,"..gamelist_height..";games;" .. pkgmgr.gamelist() .. ";" .. gameidx .. ";false]" .. "container[0,4.5]" .. - minimal_only .. + devtest_only .. "container_end[]" .. "container_end[]" .. diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a77c7567e..c4310aa5b 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1069,7 +1069,7 @@ Node drawtypes There are a bunch of different looking node types. -Look for examples in `games/minimal` or `games/minetest_game`. +Look for examples in `games/devtest` or `games/minetest_game`. * `normal` * A node-sized cube. diff --git a/games/devtest/LICENSE.txt b/games/devtest/LICENSE.txt new file mode 100644 index 000000000..71bd0e596 --- /dev/null +++ b/games/devtest/LICENSE.txt @@ -0,0 +1,4 @@ +License information for Development Test +---------------------------------------- + +The same license as for Minetest applies. diff --git a/games/devtest/README.md b/games/devtest/README.md new file mode 100644 index 000000000..a7e93cf11 --- /dev/null +++ b/games/devtest/README.md @@ -0,0 +1,52 @@ +# Development Test (devtest) + +This is a basic testing environment that contains a bunch of things to test the engine, but it could also be used as a minimal testbed for testing out mods. + +## Features + +* Basic nodes for mapgen +* Basic, minimal map generator +* Lots of example nodes for testing drawtypes, param2, light level, and many other node properties +* Example entities +* Other example items +* Formspec test (via `/test_formspec` command) +* Automated unit tests (disabled by default) +* Tools for manipulating nodes and entities, like the "Param2 Tool" + +## Getting started + +Basically, just create a world and start. A few important things to note: + +* Items are gotten from the “Chest of Everything” (`chest_of_everything:chest`) +* When you lost your initial items, type in `/stuff` command to get them back +* By default, Creative Mode activates infinite node placement. This behavior can be changed with the `devtest_infplace` setting +* Use the `/infplace` command to toggle infinite node placement in-game +* Use the Param2 Tool to change the param2 of nodes; it's useful to experiment with the various drawtype test nodes +* Check out the game settings and server commands for additional tests and features +* Creative Mode does nothing (apart from default engine behavior) + +Confused by a certain node or item? Check out for inline code comments. + +### Example tests + +* You can use this to test what happens if a player is simultaneously in 2 nodes with `damage_per_second` but with a different value. +* Or use the Falling Node Tool on various test nodes to see how they behave when falling. +* You could also use this as a testbed for dependency-free mods, e.g. to test out how your formspecs behave without theming. + +## Random notes + +* Experimental/strange/unstructured tests can be found in the `experimental` mod +* Textures of drawtype test nodes have a red dot at the top left corner. This is to see whether the textures are oriented properly + +## Design philosophy + +This should loosely follow the following principles: + +* Engine testing: The main focus of this is to aid testing of *engine* features, such as mapgen or node drawtypes +* Mod testing: The secondary focus is to help modders as well, either as a minimal testbed for mods or even as a code example +* Minimal interference: Under default settings, it shall not interfere with APIs except on explicit user wish. Non-trivial tests and features need to be enabled by a setting first +* Convenience: Have various tools to make usage easier and more convenient +* Reproducing engine bugs: When an engine bug was found, consider creating a test case +* Clarity: Textures and names need to be designed to keep different things clearly visually apart at a glance +* Low loading time: It must load blazing-fast so stuff can be tested quickly + diff --git a/games/devtest/game.conf b/games/devtest/game.conf new file mode 100644 index 000000000..d6e382ad7 --- /dev/null +++ b/games/devtest/game.conf @@ -0,0 +1,2 @@ +name = Development Test +description = Testing environment to help with testing the engine features of Minetest. It can also be helpful in mod development. diff --git a/games/devtest/menu/background.png b/games/devtest/menu/background.png new file mode 100644 index 000000000..415bb3d14 Binary files /dev/null and b/games/devtest/menu/background.png differ diff --git a/games/devtest/menu/header.png b/games/devtest/menu/header.png new file mode 100644 index 000000000..c80ed71f1 Binary files /dev/null and b/games/devtest/menu/header.png differ diff --git a/games/devtest/menu/icon.png b/games/devtest/menu/icon.png new file mode 100644 index 000000000..f854b9c31 Binary files /dev/null and b/games/devtest/menu/icon.png differ diff --git a/games/devtest/mods/basenodes/init.lua b/games/devtest/mods/basenodes/init.lua new file mode 100644 index 000000000..8156c4bec --- /dev/null +++ b/games/devtest/mods/basenodes/init.lua @@ -0,0 +1,334 @@ +local WATER_ALPHA = 160 +local WATER_VISC = 1 +local LAVA_VISC = 7 + +-- +-- Node definitions +-- + +-- Register nodes + +minetest.register_node("basenodes:stone", { + description = "Stone", + tiles = {"default_stone.png"}, + groups = {cracky=3}, +}) + +minetest.register_node("basenodes:desert_stone", { + description = "Desert Stone", + tiles = {"default_desert_stone.png"}, + groups = {cracky=3}, +}) + +minetest.register_node("basenodes:dirt_with_grass", { + description = "Dirt with Grass", + tiles ={"default_grass.png", + -- a little dot on the bottom to distinguish it from dirt + "default_dirt.png^basenodes_dirt_with_grass_bottom.png", + {name = "default_dirt.png^default_grass_side.png", + tileable_vertical = false}}, + groups = {crumbly=3, soil=1}, +}) + +minetest.register_node("basenodes:dirt_with_snow", { + description = "Dirt with Snow", + tiles ={"basenodes_dirt_with_snow.png", + -- a little dot on the bottom to distinguish it from dirt + "default_dirt.png^basenodes_dirt_with_snow_bottom.png", + {name = "default_dirt.png^default_snow_side.png", + tileable_vertical = false}}, + groups = {crumbly=3, soil=1}, +}) + +minetest.register_node("basenodes:dirt", { + description = "Dirt", + tiles ={"default_dirt.png"}, + groups = {crumbly=3, soil=1}, +}) + +minetest.register_node("basenodes:sand", { + description = "Sand", + tiles ={"default_sand.png"}, + groups = {crumbly=3}, +}) + +minetest.register_node("basenodes:desert_sand", { + description = "Desert Sand", + tiles ={"default_desert_sand.png"}, + groups = {crumbly=3}, +}) + +minetest.register_node("basenodes:gravel", { + description = "Gravel", + tiles ={"default_gravel.png"}, + groups = {crumbly=2}, +}) + +minetest.register_node("basenodes:junglegrass", { + description = "Jungle Grass", + drawtype = "plantlike", + tiles ={"default_junglegrass.png"}, + inventory_image = "default_junglegrass.png", + wield_image = "default_junglegrass.png", + paramtype = "light", + walkable = false, + groups = {snappy=3}, +}) + +minetest.register_node("basenodes:tree", { + description = "Normal Tree Trunk", + tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}, + is_ground_content = false, + groups = {choppy=2,oddly_breakable_by_hand=1}, +}) + +minetest.register_node("basenodes:leaves", { + description = "Normal Leaves", + drawtype = "allfaces_optional", + tiles = {"default_leaves.png"}, + paramtype = "light", + is_ground_content = false, + groups = {snappy=3}, +}) + +minetest.register_node("basenodes:jungletree", { + description = "Jungle Tree Trunk", + tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"}, + is_ground_content = false, + groups = {choppy=2,oddly_breakable_by_hand=1}, +}) + +minetest.register_node("basenodes:jungleleaves", { + description = "Jungle Leaves", + drawtype = "allfaces_optional", + tiles = {"default_jungleleaves.png"}, + paramtype = "light", + is_ground_content = false, + groups = {snappy=3}, +}) + +minetest.register_node("basenodes:pine_tree", { + description = "Pine Tree Trunk", + tiles = {"default_pine_tree_top.png", "default_pine_tree_top.png", "default_pine_tree.png"}, + is_ground_content = false, + groups = {choppy=2,oddly_breakable_by_hand=1}, +}) + +minetest.register_node("basenodes:pine_needles", { + description = "Pine Needles", + drawtype = "allfaces_optional", + tiles = {"default_pine_needles.png"}, + paramtype = "light", + is_ground_content = false, + groups = {snappy=3}, +}) + +minetest.register_node("basenodes:water_source", { + description = "Water Source", + drawtype = "liquid", + tiles = {"default_water.png"}, + special_tiles = { + {name = "default_water.png", backface_culling = false}, + {name = "default_water.png", backface_culling = true}, + }, + alpha = WATER_ALPHA, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drowning = 1, + liquidtype = "source", + liquid_alternative_flowing = "basenodes:water_flowing", + liquid_alternative_source = "basenodes:water_source", + liquid_viscosity = WATER_VISC, + post_effect_color = {a = 64, r = 100, g = 100, b = 200}, + groups = {water = 3, liquid = 3}, +}) + +minetest.register_node("basenodes:water_flowing", { + description = "Flowing Water", + drawtype = "flowingliquid", + tiles = {"default_water_flowing.png"}, + special_tiles = { + {name = "default_water_flowing.png", backface_culling = false}, + {name = "default_water_flowing.png", backface_culling = false}, + }, + alpha = WATER_ALPHA, + paramtype = "light", + paramtype2 = "flowingliquid", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drowning = 1, + liquidtype = "flowing", + liquid_alternative_flowing = "basenodes:water_flowing", + liquid_alternative_source = "basenodes:water_source", + liquid_viscosity = WATER_VISC, + post_effect_color = {a = 64, r = 100, g = 100, b = 200}, + groups = {water = 3, liquid = 3}, +}) + +minetest.register_node("basenodes:river_water_source", { + description = "River Water Source", + drawtype = "liquid", + tiles = { "default_river_water.png" }, + special_tiles = { + {name = "default_river_water.png", backface_culling = false}, + {name = "default_river_water.png", backface_culling = true}, + }, + alpha = WATER_ALPHA, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drowning = 1, + liquidtype = "source", + liquid_alternative_flowing = "basenodes:river_water_flowing", + liquid_alternative_source = "basenodes:river_water_source", + liquid_viscosity = 1, + liquid_renewable = false, + liquid_range = 2, + post_effect_color = {a = 103, r = 30, g = 76, b = 90}, + groups = {water = 3, liquid = 3, }, +}) + +minetest.register_node("basenodes:river_water_flowing", { + description = "Flowing River Water", + drawtype = "flowingliquid", + tiles = {"default_river_water_flowing.png"}, + special_tiles = { + {name = "default_river_water_flowing.png", backface_culling = false}, + {name = "default_river_water_flowing.png", backface_culling = false}, + }, + alpha = WATER_ALPHA, + paramtype = "light", + paramtype2 = "flowingliquid", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drowning = 1, + liquidtype = "flowing", + liquid_alternative_flowing = "basenodes:river_water_flowing", + liquid_alternative_source = "basenodes:river_water_source", + liquid_viscosity = 1, + liquid_renewable = false, + liquid_range = 2, + post_effect_color = {a = 103, r = 30, g = 76, b = 90}, + groups = {water = 3, liquid = 3, }, +}) + +minetest.register_node("basenodes:lava_flowing", { + description = "Flowing Lava", + drawtype = "flowingliquid", + tiles = {"default_lava_flowing.png"}, + special_tiles = { + {name="default_lava_flowing.png", backface_culling = false}, + {name="default_lava_flowing.png", backface_culling = false}, + }, + paramtype = "light", + light_source = minetest.LIGHT_MAX, + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drowning = 1, + damage_per_second = 4, + liquidtype = "flowing", + liquid_alternative_flowing = "basenodes:lava_flowing", + liquid_alternative_source = "basenodes:lava_source", + liquid_viscosity = LAVA_VISC, + post_effect_color = {a=192, r=255, g=64, b=0}, + groups = {lava=3, liquid=1}, +}) + +minetest.register_node("basenodes:lava_source", { + description = "Lava Source", + drawtype = "liquid", + tiles = { "default_lava.png" }, + special_tiles = { + {name = "default_lava.png", backface_culling = false}, + {name = "default_lava.png", backface_culling = true}, + }, + paramtype = "light", + light_source = minetest.LIGHT_MAX, + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + drowning = 1, + damage_per_second = 4, + liquidtype = "source", + liquid_alternative_flowing = "basenodes:lava_flowing", + liquid_alternative_source = "basenodes:lava_source", + liquid_viscosity = LAVA_VISC, + post_effect_color = {a=192, r=255, g=64, b=0}, + groups = {lava=3, liquid=1}, +}) + +minetest.register_node("basenodes:cobble", { + description = "Cobblestone", + tiles ={"default_cobble.png"}, + is_ground_content = false, + groups = {cracky=3}, +}) + +minetest.register_node("basenodes:mossycobble", { + description = "Mossy Cobblestone", + tiles ={"default_mossycobble.png"}, + is_ground_content = false, + groups = {cracky=3}, +}) + +minetest.register_node("basenodes:apple", { + description = "Apple", + drawtype = "plantlike", + tiles ={"default_apple.png"}, + inventory_image = "default_apple.png", + paramtype = "light", + is_ground_content = false, + sunlight_propagates = true, + walkable = false, + groups = {dig_immediate=3}, + + -- Make eatable because why not? + on_use = minetest.item_eat(2), +}) + +minetest.register_node("basenodes:ice", { + description = "Ice", + tiles ={"default_ice.png"}, + groups = {cracky=3}, +}) + +-- The snow nodes intentionally have different tints to make them more +-- distinguishable +minetest.register_node("basenodes:snow", { + description = "Snow Sheet", + tiles = {"basenodes_snow_sheet.png"}, + groups = {crumbly=3}, + walkable = false, + paramtype = "light", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5}, + }, +}) + +minetest.register_node("basenodes:snowblock", { + description = "Snow Block", + tiles ={"default_snow.png"}, + groups = {crumbly=3}, +}) + + diff --git a/games/devtest/mods/basenodes/mod.conf b/games/devtest/mods/basenodes/mod.conf new file mode 100644 index 000000000..25024dc63 --- /dev/null +++ b/games/devtest/mods/basenodes/mod.conf @@ -0,0 +1,2 @@ +name = basenodes +description = Contains basic nodes for mapgen diff --git a/games/devtest/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png b/games/devtest/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png new file mode 100644 index 000000000..5e8fc41a9 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png differ diff --git a/games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow.png b/games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow.png new file mode 100644 index 000000000..7ea2d8d31 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow.png differ diff --git a/games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png b/games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png new file mode 100644 index 000000000..447c94e98 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png differ diff --git a/games/devtest/mods/basenodes/textures/basenodes_snow_sheet.png b/games/devtest/mods/basenodes/textures/basenodes_snow_sheet.png new file mode 100644 index 000000000..455332093 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/basenodes_snow_sheet.png differ diff --git a/games/devtest/mods/basenodes/textures/default_apple.png b/games/devtest/mods/basenodes/textures/default_apple.png new file mode 100644 index 000000000..9c115dae4 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_apple.png differ diff --git a/games/devtest/mods/basenodes/textures/default_cobble.png b/games/devtest/mods/basenodes/textures/default_cobble.png new file mode 100644 index 000000000..5b859e9c2 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_cobble.png differ diff --git a/games/devtest/mods/basenodes/textures/default_desert_sand.png b/games/devtest/mods/basenodes/textures/default_desert_sand.png new file mode 100644 index 000000000..19ec87dc0 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_desert_sand.png differ diff --git a/games/devtest/mods/basenodes/textures/default_desert_stone.png b/games/devtest/mods/basenodes/textures/default_desert_stone.png new file mode 100644 index 000000000..5126fb61c Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_desert_stone.png differ diff --git a/games/devtest/mods/basenodes/textures/default_dirt.png b/games/devtest/mods/basenodes/textures/default_dirt.png new file mode 100644 index 000000000..58670305d Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_dirt.png differ diff --git a/games/devtest/mods/basenodes/textures/default_grass.png b/games/devtest/mods/basenodes/textures/default_grass.png new file mode 100644 index 000000000..3d6397186 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_grass.png differ diff --git a/games/devtest/mods/basenodes/textures/default_grass_side.png b/games/devtest/mods/basenodes/textures/default_grass_side.png new file mode 100644 index 000000000..04770b6f6 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_grass_side.png differ diff --git a/games/devtest/mods/basenodes/textures/default_gravel.png b/games/devtest/mods/basenodes/textures/default_gravel.png new file mode 100644 index 000000000..7e5ff616f Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_gravel.png differ diff --git a/games/devtest/mods/basenodes/textures/default_ice.png b/games/devtest/mods/basenodes/textures/default_ice.png new file mode 100644 index 000000000..c4bddd223 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_ice.png differ diff --git a/games/devtest/mods/basenodes/textures/default_junglegrass.png b/games/devtest/mods/basenodes/textures/default_junglegrass.png new file mode 100644 index 000000000..d64e33abc Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_junglegrass.png differ diff --git a/games/devtest/mods/basenodes/textures/default_jungleleaves.png b/games/devtest/mods/basenodes/textures/default_jungleleaves.png new file mode 100644 index 000000000..1fa67e83a Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_jungleleaves.png differ diff --git a/games/devtest/mods/basenodes/textures/default_jungletree.png b/games/devtest/mods/basenodes/textures/default_jungletree.png new file mode 100644 index 000000000..053850fa7 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_jungletree.png differ diff --git a/games/devtest/mods/basenodes/textures/default_jungletree_top.png b/games/devtest/mods/basenodes/textures/default_jungletree_top.png new file mode 100644 index 000000000..e80de8a69 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_jungletree_top.png differ diff --git a/games/devtest/mods/basenodes/textures/default_lava.png b/games/devtest/mods/basenodes/textures/default_lava.png new file mode 100644 index 000000000..a4cf649f1 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_lava.png differ diff --git a/games/devtest/mods/basenodes/textures/default_lava_flowing.png b/games/devtest/mods/basenodes/textures/default_lava_flowing.png new file mode 100644 index 000000000..07066a6e3 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_lava_flowing.png differ diff --git a/games/devtest/mods/basenodes/textures/default_leaves.png b/games/devtest/mods/basenodes/textures/default_leaves.png new file mode 100644 index 000000000..c0475d4d2 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_leaves.png differ diff --git a/games/devtest/mods/basenodes/textures/default_mossycobble.png b/games/devtest/mods/basenodes/textures/default_mossycobble.png new file mode 100644 index 000000000..69585e37b Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_mossycobble.png differ diff --git a/games/devtest/mods/basenodes/textures/default_pine_needles.png b/games/devtest/mods/basenodes/textures/default_pine_needles.png new file mode 100644 index 000000000..137caa2a3 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_pine_needles.png differ diff --git a/games/devtest/mods/basenodes/textures/default_pine_tree.png b/games/devtest/mods/basenodes/textures/default_pine_tree.png new file mode 100644 index 000000000..5743183c0 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_pine_tree.png differ diff --git a/games/devtest/mods/basenodes/textures/default_pine_tree_top.png b/games/devtest/mods/basenodes/textures/default_pine_tree_top.png new file mode 100644 index 000000000..cc18f3462 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_pine_tree_top.png differ diff --git a/games/devtest/mods/basenodes/textures/default_river_water.png b/games/devtest/mods/basenodes/textures/default_river_water.png new file mode 100644 index 000000000..e1074d2ef Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_river_water.png differ diff --git a/games/devtest/mods/basenodes/textures/default_river_water_flowing.png b/games/devtest/mods/basenodes/textures/default_river_water_flowing.png new file mode 100644 index 000000000..4a756b2bd Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_river_water_flowing.png differ diff --git a/games/devtest/mods/basenodes/textures/default_sand.png b/games/devtest/mods/basenodes/textures/default_sand.png new file mode 100644 index 000000000..0ed0e4ceb Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_sand.png differ diff --git a/games/devtest/mods/basenodes/textures/default_snow.png b/games/devtest/mods/basenodes/textures/default_snow.png new file mode 100644 index 000000000..c42e0eecb Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_snow.png differ diff --git a/games/devtest/mods/basenodes/textures/default_snow_side.png b/games/devtest/mods/basenodes/textures/default_snow_side.png new file mode 100644 index 000000000..f34d10991 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_snow_side.png differ diff --git a/games/devtest/mods/basenodes/textures/default_stone.png b/games/devtest/mods/basenodes/textures/default_stone.png new file mode 100644 index 000000000..763b4396a Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_stone.png differ diff --git a/games/devtest/mods/basenodes/textures/default_tree.png b/games/devtest/mods/basenodes/textures/default_tree.png new file mode 100644 index 000000000..189ec1593 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_tree.png differ diff --git a/games/devtest/mods/basenodes/textures/default_tree_top.png b/games/devtest/mods/basenodes/textures/default_tree_top.png new file mode 100644 index 000000000..d1a4fa704 Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_tree_top.png differ diff --git a/games/devtest/mods/basenodes/textures/default_water.png b/games/devtest/mods/basenodes/textures/default_water.png new file mode 100644 index 000000000..3e385ae8b Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_water.png differ diff --git a/games/devtest/mods/basenodes/textures/default_water_flowing.png b/games/devtest/mods/basenodes/textures/default_water_flowing.png new file mode 100644 index 000000000..7cdafd51d Binary files /dev/null and b/games/devtest/mods/basenodes/textures/default_water_flowing.png differ diff --git a/games/devtest/mods/basetools/init.lua b/games/devtest/mods/basetools/init.lua new file mode 100644 index 000000000..d9d9afb07 --- /dev/null +++ b/games/devtest/mods/basetools/init.lua @@ -0,0 +1,295 @@ +-- +-- Tool definitions +-- + +--[[ TOOLS SUMMARY: + +Tool types: + +* Hand: basic tool/weapon (just for convenience, not optimized for testing) +* Pickaxe: dig cracky +* Axe: dig choppy +* Shovel: dig crumbly +* Shears: dig snappy +* Sword: deal damage +* Dagger: deal damage, but faster + +Tool materials: + +* Dirt: dig nodes of rating 3, one use only +* Wood: dig nodes of rating 3 +* Stone: dig nodes of rating 3 or 2 +* Steel: dig nodes of rating 3, 2 or 1 +* Mese: dig "everything" instantly +]] + +-- The hand +minetest.register_item(":", { + type = "none", + wield_image = "wieldhand.png", + wield_scale = {x=1,y=1,z=2.5}, + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level = 0, + groupcaps = { + crumbly = {times={[3]=1.50}, uses=0, maxlevel=0}, + snappy = {times={[3]=1.50}, uses=0, maxlevel=0}, + oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=2.00}, uses=0, maxlevel=0}, + }, + damage_groups = {fleshy=1}, + } +}) + +-- Mese Pickaxe: special tool that digs "everything" instantly +minetest.register_tool("basetools:pick_mese", { + description = "Mese Pickaxe", + inventory_image = "basetools_mesepick.png", + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level=3, + groupcaps={ + cracky={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, + crumbly={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, + snappy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, + choppy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, + dig_immediate={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, + }, + }, +}) + + +-- +-- Pickaxes: Dig cracky +-- + +-- This should break after only 1 use +minetest.register_tool("basetools:pick_dirt", { + description = "Dirt Pickaxe", + inventory_image = "basetools_dirtpick.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + cracky={times={[3]=2.00}, uses=1, maxlevel=0} + }, + }, +}) + +minetest.register_tool("basetools:pick_wood", { + description = "Wooden Pickaxe", + inventory_image = "basetools_woodpick.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + cracky={times={[3]=2.00}, uses=30, maxlevel=0} + }, + }, +}) +minetest.register_tool("basetools:pick_stone", { + description = "Stone Pickaxe", + inventory_image = "basetools_stonepick.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + cracky={times={[2]=1.20, [3]=0.80}, uses=60, maxlevel=0} + }, + }, +}) +minetest.register_tool("basetools:pick_steel", { + description = "Steel Pickaxe", + inventory_image = "basetools_steelpick.png", + tool_capabilities = { + max_drop_level=1, + groupcaps={ + cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=0} + }, + }, +}) +minetest.register_tool("basetools:pick_steel_l1", { + description = "Steel Pickaxe Level 1", + inventory_image = "basetools_steelpick_l1.png", + tool_capabilities = { + max_drop_level=1, + groupcaps={ + cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=1} + }, + }, +}) +minetest.register_tool("basetools:pick_steel_l2", { + description = "Steel Pickaxe Level 2", + inventory_image = "basetools_steelpick_l2.png", + tool_capabilities = { + max_drop_level=1, + groupcaps={ + cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=2} + }, + }, +}) + +-- +-- Shovels (dig crumbly) +-- + +minetest.register_tool("basetools:shovel_wood", { + description = "Wooden Shovel", + inventory_image = "basetools_woodshovel.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + crumbly={times={[3]=0.50}, uses=30, maxlevel=0} + }, + }, +}) +minetest.register_tool("basetools:shovel_stone", { + description = "Stone Shovel", + inventory_image = "basetools_stoneshovel.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + crumbly={times={[2]=0.50, [3]=0.30}, uses=60, maxlevel=0} + }, + }, +}) +minetest.register_tool("basetools:shovel_steel", { + description = "Steel Shovel", + inventory_image = "basetools_steelshovel.png", + tool_capabilities = { + max_drop_level=1, + groupcaps={ + crumbly={times={[1]=1.00, [2]=0.70, [3]=0.60}, uses=90, maxlevel=0} + }, + }, +}) + +-- +-- Axes (dig choppy) +-- + +minetest.register_tool("basetools:axe_wood", { + description = "Wooden Axe", + inventory_image = "basetools_woodaxe.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + choppy={times={[3]=0.80}, uses=30, maxlevel=0}, + }, + }, +}) +minetest.register_tool("basetools:axe_stone", { + description = "Stone Axe", + inventory_image = "basetools_stoneaxe.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + choppy={times={[2]=1.00, [3]=0.60}, uses=60, maxlevel=0}, + }, + }, +}) +minetest.register_tool("basetools:axe_steel", { + description = "Steel Axe", + inventory_image = "basetools_steelaxe.png", + tool_capabilities = { + max_drop_level=1, + groupcaps={ + choppy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=90, maxlevel=0}, + }, + }, +}) + +-- +-- Shears (dig snappy) +-- + +minetest.register_tool("basetools:shears_wood", { + description = "Wooden Shears", + inventory_image = "basetools_woodshears.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + snappy={times={[3]=1.00}, uses=30, maxlevel=0}, + }, + }, +}) +minetest.register_tool("basetools:shears_stone", { + description = "Stone Shears", + inventory_image = "basetools_stoneshears.png", + tool_capabilities = { + max_drop_level=0, + groupcaps={ + snappy={times={[2]=1.00, [3]=0.50}, uses=60, maxlevel=0}, + }, + }, +}) +minetest.register_tool("basetools:shears_steel", { + description = "Steel Shears", + inventory_image = "basetools_steelshears.png", + tool_capabilities = { + max_drop_level=1, + groupcaps={ + snappy={times={[1]=1.00, [2]=0.50, [3]=0.25}, uses=90, maxlevel=0}, + }, + }, +}) + +-- +-- Swords (deal damage) +-- + +minetest.register_tool("basetools:sword_wood", { + description = "Wooden Sword", + inventory_image = "basetools_woodsword.png", + tool_capabilities = { + full_punch_interval = 1.0, + damage_groups = {fleshy=2}, + } +}) +minetest.register_tool("basetools:sword_stone", { + description = "Stone Sword", + inventory_image = "basetools_stonesword.png", + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level=0, + damage_groups = {fleshy=4}, + } +}) +minetest.register_tool("basetools:sword_steel", { + description = "Steel Sword", + inventory_image = "basetools_steelsword.png", + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level=1, + damage_groups = {fleshy=6}, + } +}) + +-- Fire/Ice sword: Deal damage to non-fleshy damage groups +minetest.register_tool("basetools:sword_fire", { + description = "Fire Sword", + inventory_image = "basetools_firesword.png", + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level=0, + damage_groups = {icy=6}, + } +}) +minetest.register_tool("basetools:sword_ice", { + description = "Ice Sword", + inventory_image = "basetools_icesword.png", + tool_capabilities = { + full_punch_interval = 1.0, + max_drop_level=0, + damage_groups = {firy=6}, + } +}) + +-- +-- Dagger: Low damage, fast punch interval +-- +minetest.register_tool("basetools:dagger_steel", { + description = "Steel Dagger", + inventory_image = "basetools_steeldagger.png", + tool_capabilities = { + full_punch_interval = 0.5, + max_drop_level=0, + damage_groups = {fleshy=2}, + } +}) diff --git a/games/devtest/mods/basetools/mod.conf b/games/devtest/mods/basetools/mod.conf new file mode 100644 index 000000000..f0d9f657d --- /dev/null +++ b/games/devtest/mods/basetools/mod.conf @@ -0,0 +1,2 @@ +name = basetools +description = Contains basic digging tools diff --git a/games/devtest/mods/basetools/textures/basetools_dirtpick.png b/games/devtest/mods/basetools/textures/basetools_dirtpick.png new file mode 100644 index 000000000..20a021d72 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_dirtpick.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_firesword.png b/games/devtest/mods/basetools/textures/basetools_firesword.png new file mode 100644 index 000000000..ee2809ab7 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_firesword.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_icesword.png b/games/devtest/mods/basetools/textures/basetools_icesword.png new file mode 100644 index 000000000..35ba8214b Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_icesword.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_mesepick.png b/games/devtest/mods/basetools/textures/basetools_mesepick.png new file mode 100644 index 000000000..2b5e12cdb Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_mesepick.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelaxe.png b/games/devtest/mods/basetools/textures/basetools_steelaxe.png new file mode 100644 index 000000000..aac594d84 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelaxe.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steeldagger.png b/games/devtest/mods/basetools/textures/basetools_steeldagger.png new file mode 100644 index 000000000..4c9173094 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steeldagger.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelpick.png b/games/devtest/mods/basetools/textures/basetools_steelpick.png new file mode 100644 index 000000000..bc02aac3e Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelpick.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelpick_l1.png b/games/devtest/mods/basetools/textures/basetools_steelpick_l1.png new file mode 100644 index 000000000..dc03f3f65 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelpick_l1.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelpick_l2.png b/games/devtest/mods/basetools/textures/basetools_steelpick_l2.png new file mode 100644 index 000000000..011df4584 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelpick_l2.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelshears.png b/games/devtest/mods/basetools/textures/basetools_steelshears.png new file mode 100644 index 000000000..04c86c370 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelshears.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelshovel.png b/games/devtest/mods/basetools/textures/basetools_steelshovel.png new file mode 100644 index 000000000..8cab60784 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelshovel.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_steelsword.png b/games/devtest/mods/basetools/textures/basetools_steelsword.png new file mode 100644 index 000000000..9909365c3 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_steelsword.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_stoneaxe.png b/games/devtest/mods/basetools/textures/basetools_stoneaxe.png new file mode 100644 index 000000000..a374c547d Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_stoneaxe.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_stonepick.png b/games/devtest/mods/basetools/textures/basetools_stonepick.png new file mode 100644 index 000000000..d9156ee3a Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_stonepick.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_stoneshears.png b/games/devtest/mods/basetools/textures/basetools_stoneshears.png new file mode 100644 index 000000000..0b4bd3b74 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_stoneshears.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_stoneshovel.png b/games/devtest/mods/basetools/textures/basetools_stoneshovel.png new file mode 100644 index 000000000..3c1bb48cb Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_stoneshovel.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_stonesword.png b/games/devtest/mods/basetools/textures/basetools_stonesword.png new file mode 100644 index 000000000..6f3e94cda Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_stonesword.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_woodaxe.png b/games/devtest/mods/basetools/textures/basetools_woodaxe.png new file mode 100644 index 000000000..4015e910f Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_woodaxe.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_woodpick.png b/games/devtest/mods/basetools/textures/basetools_woodpick.png new file mode 100644 index 000000000..15c61f408 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_woodpick.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_woodshears.png b/games/devtest/mods/basetools/textures/basetools_woodshears.png new file mode 100644 index 000000000..4ff92fd7c Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_woodshears.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_woodshovel.png b/games/devtest/mods/basetools/textures/basetools_woodshovel.png new file mode 100644 index 000000000..6cc52f8a1 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_woodshovel.png differ diff --git a/games/devtest/mods/basetools/textures/basetools_woodsword.png b/games/devtest/mods/basetools/textures/basetools_woodsword.png new file mode 100644 index 000000000..364016ed6 Binary files /dev/null and b/games/devtest/mods/basetools/textures/basetools_woodsword.png differ diff --git a/games/devtest/mods/bucket/init.lua b/games/devtest/mods/bucket/init.lua new file mode 100644 index 000000000..3189d4aa6 --- /dev/null +++ b/games/devtest/mods/bucket/init.lua @@ -0,0 +1,26 @@ +-- Bucket: Punch liquid source or flowing liquid to collect it + +minetest.register_tool("bucket:bucket", { + description = "Bucket", + inventory_image = "bucket.png", + stack_max = 1, + liquids_pointable = true, + groups = { disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + -- Must be pointing to node + if pointed_thing.type ~= "node" then + return + end + -- Check if pointing to a liquid + local n = minetest.get_node(pointed_thing.under) + local def = minetest.registered_nodes[n.name] + if def ~= nil and (def.liquidtype == "source" or def.liquidtype == "flowing") then + minetest.add_node(pointed_thing.under, {name="air"}) + local inv = user:get_inventory() + if inv then + inv:add_item("main", ItemStack(n.name)) + end + end + end, +}) + diff --git a/games/devtest/mods/bucket/mod.conf b/games/devtest/mods/bucket/mod.conf new file mode 100644 index 000000000..d14deb4ea --- /dev/null +++ b/games/devtest/mods/bucket/mod.conf @@ -0,0 +1,2 @@ +name = bucket +description = Minimal bucket to pick up liquids diff --git a/games/devtest/mods/bucket/textures/bucket.png b/games/devtest/mods/bucket/textures/bucket.png new file mode 100644 index 000000000..677952875 Binary files /dev/null and b/games/devtest/mods/bucket/textures/bucket.png differ diff --git a/games/devtest/mods/bucket/textures/bucket_lava.png b/games/devtest/mods/bucket/textures/bucket_lava.png new file mode 100644 index 000000000..dfcae65fb Binary files /dev/null and b/games/devtest/mods/bucket/textures/bucket_lava.png differ diff --git a/games/devtest/mods/bucket/textures/bucket_water.png b/games/devtest/mods/bucket/textures/bucket_water.png new file mode 100644 index 000000000..e164b0a50 Binary files /dev/null and b/games/devtest/mods/bucket/textures/bucket_water.png differ diff --git a/games/devtest/mods/chest/init.lua b/games/devtest/mods/chest/init.lua new file mode 100644 index 000000000..c44522cb9 --- /dev/null +++ b/games/devtest/mods/chest/init.lua @@ -0,0 +1,27 @@ +minetest.register_node("chest:chest", { + description = "Chest", + tiles ={"chest_chest.png^[sheet:2x2:0,0", "chest_chest.png^[sheet:2x2:0,0", + "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:1,0", + "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:0,1"}, + paramtype2 = "facedir", + groups = {dig_immediate=2,choppy=3}, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", + "size[8,9]".. + "list[current_name;main;0,0;8,4;]".. + "list[current_player;main;0,5;8,4;]" .. + "listring[]") + meta:set_string("infotext", "Chest") + local inv = meta:get_inventory() + inv:set_size("main", 8*4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("main") + end, +}) + + diff --git a/games/devtest/mods/chest/mod.conf b/games/devtest/mods/chest/mod.conf new file mode 100644 index 000000000..0d7500164 --- /dev/null +++ b/games/devtest/mods/chest/mod.conf @@ -0,0 +1,2 @@ +name = chest +description = A simple chest to store items diff --git a/games/devtest/mods/chest/textures/chest_chest.png b/games/devtest/mods/chest/textures/chest_chest.png new file mode 100644 index 000000000..824b4d502 Binary files /dev/null and b/games/devtest/mods/chest/textures/chest_chest.png differ diff --git a/games/devtest/mods/chest_of_everything/init.lua b/games/devtest/mods/chest_of_everything/init.lua new file mode 100644 index 000000000..7d61abebf --- /dev/null +++ b/games/devtest/mods/chest_of_everything/init.lua @@ -0,0 +1,135 @@ +local F = minetest.formspec_escape + +-- Create a detached inventory +local inv_everything = minetest.create_detached_inventory("everything", { + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) + return 0 + end, + allow_put = function(inv, listname, index, stack, player) + return 0 + end, + allow_take = function(inv, listname, index, stack, player) + return -1 + end, +}) +local inv_trash = minetest.create_detached_inventory("trash", { + allow_take = function(inv, listname, index, stack, player) + return 0 + end, + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) + return 0 + end, + on_put = function(inv, listname, index, stack, player) + inv:set_list("main", {}) + end, +}) +inv_trash:set_size("main", 1) + +local max_page = 1 + +local function get_chest_formspec(page) + local start = 0 + (page-1)*32 + return "size[8,9]".. + "list[detached:everything;main;0,0;8,4;"..start.."]".. + "list[current_player;main;0,5;8,4;]" .. + "label[6,4;Trash:]" .. + "list[detached:trash;main;7,4;1,1]" .. + "button[0,4;1,1;chest_of_everything_prev;"..F("<").."]".. + "button[1,4;1,1;chest_of_everything_next;"..F(">").."]".. + "label[2,4;"..F("Page: "..page).."]".. + "listring[detached:everything;main]".. + "listring[current_player;main]".. + "listring[detached:trash;main]" +end + +minetest.register_node("chest_of_everything:chest", { + description = "Chest of Everything", + tiles ={"chest_of_everything_chest.png^[sheet:2x2:0,0", "chest_of_everything_chest.png^[sheet:2x2:0,0", + "chest_of_everything_chest.png^[sheet:2x2:1,0", "chest_of_everything_chest.png^[sheet:2x2:1,0", + "chest_of_everything_chest.png^[sheet:2x2:1,0", "chest_of_everything_chest.png^[sheet:2x2:0,1"}, + paramtype2 = "facedir", + groups = {dig_immediate=2,choppy=3}, + is_ground_content = false, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", "Chest of Everything") + meta:set_int("page", 1) + meta:set_string("formspec", get_chest_formspec(1)) + end, + on_receive_fields = function(pos, formname, fields, sender) + if formname == "" then + local meta = minetest.get_meta(pos) + local page = meta:get_int("page") + if fields.chest_of_everything_prev then + page = page - 1 + elseif fields.chest_of_everything_next then + page = page + 1 + end + if page < 1 then + page = 1 + end + if page > max_page then + page = max_page + end + meta:set_int("page", page) + meta:set_string("formspec", get_chest_formspec(page)) + end + end, +}) + +minetest.register_on_mods_loaded(function() + local items = {} + for itemstring,_ in pairs(minetest.registered_items) do + if itemstring ~= "" and itemstring ~= "unknown" and itemstring ~= "ignore" then + table.insert(items, itemstring) + end + end + --[[ Sort items in this order: + * Chest of Everything + * Test tools + * Other tools + * Craftitems + * Other items + * Dummy items ]] + local function compare(item1, item2) + local def1 = minetest.registered_items[item1] + local def2 = minetest.registered_items[item2] + local tool1 = def1.type == "tool" + local tool2 = def2.type == "tool" + local testtool1 = minetest.get_item_group(item1, "testtool") == 1 + local testtool2 = minetest.get_item_group(item2, "testtool") == 1 + local dummy1 = minetest.get_item_group(item1, "dummy") == 1 + local dummy2 = minetest.get_item_group(item2, "dummy") == 1 + local craftitem1 = def1.type == "craft" + local craftitem2 = def2.type == "craft" + if item1 == "chest_of_everything:chest" then + return true + elseif item2 == "chest_of_everything:chest" then + return false + elseif dummy1 and not dummy2 then + return false + elseif not dummy1 and dummy2 then + return true + elseif testtool1 and not testtool2 then + return true + elseif not testtool1 and testtool2 then + return false + elseif tool1 and not tool2 then + return true + elseif not tool1 and tool2 then + return false + elseif craftitem1 and not craftitem2 then + return true + elseif not craftitem1 and craftitem2 then + return false + else + return item1 < item2 + end + end + table.sort(items, compare) + inv_everything:set_size("main", #items) + max_page = math.ceil(#items / 32) + for i=1, #items do + inv_everything:add_item("main", items[i]) + end +end) diff --git a/games/devtest/mods/chest_of_everything/mod.conf b/games/devtest/mods/chest_of_everything/mod.conf new file mode 100644 index 000000000..4a4425e05 --- /dev/null +++ b/games/devtest/mods/chest_of_everything/mod.conf @@ -0,0 +1,2 @@ +name = chest_of_everything +description = Adds the chest of everything from which you can take all items diff --git a/games/devtest/mods/chest_of_everything/textures/chest_of_everything_chest.png b/games/devtest/mods/chest_of_everything/textures/chest_of_everything_chest.png new file mode 100644 index 000000000..6b2fd58d5 Binary files /dev/null and b/games/devtest/mods/chest_of_everything/textures/chest_of_everything_chest.png differ diff --git a/games/devtest/mods/dignodes/init.lua b/games/devtest/mods/dignodes/init.lua new file mode 100644 index 000000000..833150873 --- /dev/null +++ b/games/devtest/mods/dignodes/init.lua @@ -0,0 +1,37 @@ +local groups = { + "cracky", "dig_immediate" +} + +-- Register dig nodes with 1 digging group, a rating between 1-3 and a level between 0-2 +for g=1, #groups do + local gr = groups[g] + for r=1, 3 do + for l=0, 2 do + if not (gr=="dig_immediate" and (l>0 or r==1)) then + local d + if l > 0 then + d = string.format("Dig Test Node: %s=%d, level=%d", gr, r, l) + else + d = string.format("Dig Test Node: %s=%d", gr, r) + end + local tile = "dignodes_"..gr..".png^dignodes_rating"..r..".png" + if l==1 then + tile = tile .. "^[colorize:#FFFF00:127" + elseif l==2 then + tile = tile .. "^[colorize:#FF0000:127" + end + minetest.register_node("dignodes:"..gr.."_"..r.."_"..l, { + description = d, + tiles = { tile }, + groups = { [gr] = r, level = l }, + }) + end + end + end +end + +-- Node without any digging groups +minetest.register_node("dignodes:none", { + description = "Dig Test Node: groupless", + tiles = {"dignodes_none.png"}, +}) diff --git a/games/devtest/mods/dignodes/mod.conf b/games/devtest/mods/dignodes/mod.conf new file mode 100644 index 000000000..52a80d66e --- /dev/null +++ b/games/devtest/mods/dignodes/mod.conf @@ -0,0 +1,2 @@ +name = dignodes +description = Nodes with different digging groups diff --git a/games/devtest/mods/dignodes/textures/dignodes_choppy.png b/games/devtest/mods/dignodes/textures/dignodes_choppy.png new file mode 100644 index 000000000..a73fc2424 Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_choppy.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_cracky.png b/games/devtest/mods/dignodes/textures/dignodes_cracky.png new file mode 100644 index 000000000..eb84e3079 Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_cracky.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_crumbly.png b/games/devtest/mods/dignodes/textures/dignodes_crumbly.png new file mode 100644 index 000000000..23f2f7c71 Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_crumbly.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_dig_immediate.png b/games/devtest/mods/dignodes/textures/dignodes_dig_immediate.png new file mode 100644 index 000000000..a532ad90b Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_dig_immediate.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_none.png b/games/devtest/mods/dignodes/textures/dignodes_none.png new file mode 100644 index 000000000..60f13650b Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_none.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_rating1.png b/games/devtest/mods/dignodes/textures/dignodes_rating1.png new file mode 100644 index 000000000..d2fee3a23 Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_rating1.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_rating2.png b/games/devtest/mods/dignodes/textures/dignodes_rating2.png new file mode 100644 index 000000000..15329b93f Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_rating2.png differ diff --git a/games/devtest/mods/dignodes/textures/dignodes_rating3.png b/games/devtest/mods/dignodes/textures/dignodes_rating3.png new file mode 100644 index 000000000..37216bfd1 Binary files /dev/null and b/games/devtest/mods/dignodes/textures/dignodes_rating3.png differ diff --git a/games/devtest/mods/experimental/commands.lua b/games/devtest/mods/experimental/commands.lua new file mode 100644 index 000000000..96f8cbe39 --- /dev/null +++ b/games/devtest/mods/experimental/commands.lua @@ -0,0 +1,215 @@ +minetest.register_chatcommand("test_inv", { + params = "", + description = "Test: Modify player's inventory formspec", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + player:set_inventory_formspec( + "size[13,7.5]".. + "image[6,0.6;1,2;player.png]".. + "list[current_player;main;5,3.5;8,4;]".. + "list[current_player;craft;8,0;3,3;]".. + "list[current_player;craftpreview;12,1;1,1;]".. + "list[detached:test_inventory;main;0,0;4,6;0]".. + "button[0.5,7;2,1;button1;Button 1]".. + "button_exit[2.5,7;2,1;button2;Exit Button]") + return true, "Done." + end, +}) + +minetest.register_chatcommand("test_bulk_set_node", { + params = "", + description = "Test: Bulk-set 9×9×9 stone nodes", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local pos_list = {} + local ppos = player:get_pos() + local i = 1 + for x=2,10 do + for y=2,10 do + for z=2,10 do + pos_list[i] = {x=ppos.x + x,y = ppos.y + y,z = ppos.z + z} + i = i + 1 + end + end + end + minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) + return true, "Done." + end, +}) + +minetest.register_chatcommand("bench_bulk_set_node", { + params = "", + description = "Benchmark: Bulk-set 99×99×99 stone nodes", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local pos_list = {} + local ppos = player:get_pos() + local i = 1 + for x=2,100 do + for y=2,100 do + for z=2,100 do + pos_list[i] = {x=ppos.x + x,y = ppos.y + y,z = ppos.z + z} + i = i + 1 + end + end + end + + minetest.chat_send_player(name, "Benchmarking minetest.bulk_set_node. Warming up ..."); + + -- warm up with stone to prevent having different callbacks + -- due to different node topology + minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) + + minetest.chat_send_player(name, "Warming up finished, now benchmarking ..."); + + local start_time = minetest.get_us_time() + for i=1,#pos_list do + minetest.set_node(pos_list[i], {name = "mapgen_stone"}) + end + local middle_time = minetest.get_us_time() + minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) + local end_time = minetest.get_us_time() + local msg = string.format("Benchmark results: minetest.set_node loop: %.2f ms; minetest.bulk_set_node: %.2f ms", + ((middle_time - start_time)) / 1000, + ((end_time - middle_time)) / 1000 + ) + return true, msg + end, +}) + +local function advance_pos(pos, start_pos, advance_z) + if advance_z then + pos.z = pos.z + 2 + pos.x = start_pos.x + else + pos.x = pos.x + 2 + end + if pos.x > 30900 or pos.x - start_pos.x > 46 then + pos.x = start_pos.x + pos.z = pos.z + 2 + end + if pos.z > 30900 then + -- We ran out of space! Aborting + aborted = true + return false + end + return pos +end + +local function place_nodes(param) + local nodes = param.nodes + local name = param.name + local pos = param.pos + local start_pos = param.start_pos + table.sort(nodes) + minetest.chat_send_player(name, "Placing nodes …") + local nodes_placed = 0 + for n=1, #nodes do + local itemstring = nodes[n] + local def = minetest.registered_nodes[itemstring] + local p2_max = 0 + if param.param ~= "no_param2" then + -- Also test the param2 values of the nodes + -- ... but we only use permissible param2 values + if def.paramtype2 == "wallmounted" then + p2_max = 5 + elseif def.paramtype2 == "facedir" then + p2_max = 23 + elseif def.paramtype2 == "glasslikeliquidlevel" then + p2_max = 63 + elseif def.paramtype2 == "meshoptions" and def.drawtype == "plantlike" then + p2_max = 63 + elseif def.paramtype2 == "leveled" then + p2_max = 127 + elseif def.paramtype2 == "degrotate" and def.drawtype == "plantlike" then + p2_max = 179 + elseif def.paramtype2 == "colorfacedir" or + def.paramtype2 == "colorwallmounted" or + def.paramtype2 == "color" then + p2_max = 255 + end + end + for p2 = 0, p2_max do + -- Skip undefined param2 values + if not ((def.paramtype2 == "meshoptions" and p2 % 8 > 4) or + (def.paramtype2 == "colorwallmounted" and p2 % 8 > 5) or + (def.paramtype2 == "colorfacedir" and p2 % 32 > 23)) then + + minetest.set_node(pos, { name = itemstring, param2 = p2 }) + nodes_placed = nodes_placed + 1 + pos = advance_pos(pos, start_pos) + if not pos then + aborted = true + break + end + end + end + if aborted then + break + end + end + if aborted then + minetest.chat_send_player(name, "Not all nodes could be placed, please move further away from the world boundary. Nodes placed: "..nodes_placed) + end + minetest.chat_send_player(name, "Nodes placed: "..nodes_placed..".") +end + +local function after_emerge(blockpos, action, calls_remaining, param) + if calls_remaining == 0 then + place_nodes(param) + end +end + +minetest.register_chatcommand("test_place_nodes", { + params = "[ no_param2 ]", + description = "Test: Place all non-experimental nodes and optionally their permissible param2 variants", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local pos = vector.floor(player:get_pos()) + pos.x = math.ceil(pos.x + 3) + pos.z = math.ceil(pos.z + 3) + pos.y = math.ceil(pos.y + 1) + local start_pos = table.copy(pos) + if pos.x > 30800 then + return false, "Too close to world boundary (+X). Please move to X < 30800." + end + if pos.z > 30800 then + return false, "Too close to world boundary (+Z). Please move to Z < 30800." + end + + local aborted = false + local nodes = {} + local emerge_estimate = 0 + for itemstring, def in pairs(minetest.registered_nodes) do + if itemstring ~= "ignore" and string.sub(itemstring, 1, 13) ~= "experimental:" then + table.insert(nodes, itemstring) + if def.paramtype2 == 0 then + emerge_estimate = emerge_estimate + 1 + else + emerge_estimate = emerge_estimate + 255 + end + end + end + -- Emerge area to make sure that all nodes are being placed. + -- Note we will emerge much more than we need to (overestimation), + -- the estimation code could be improved performance-wise … + local length = 16 + math.ceil(emerge_estimate / 24) * 2 + minetest.emerge_area(start_pos, + { x = start_pos.x + 46, y = start_pos.y, z = start_pos.z + length }, + after_emerge, { nodes = nodes, name = name, pos = pos, start_pos = start_pos, param = param }) + return true, "Emerging area …" + end, +}) + diff --git a/games/devtest/mods/experimental/detached.lua b/games/devtest/mods/experimental/detached.lua new file mode 100644 index 000000000..673adfdd4 --- /dev/null +++ b/games/devtest/mods/experimental/detached.lua @@ -0,0 +1,29 @@ +-- Create a detached inventory +local inv = minetest.create_detached_inventory("test_inventory", { + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) + experimental.print_to_everything("allow move asked") + return count -- Allow all + end, + allow_put = function(inv, listname, index, stack, player) + experimental.print_to_everything("allow put asked") + return 1 -- Allow only 1 + end, + allow_take = function(inv, listname, index, stack, player) + experimental.print_to_everything("allow take asked") + return 4 -- Allow 4 at max + end, + on_move = function(inv, from_list, from_index, to_list, to_index, count, player) + experimental.print_to_everything(player:get_player_name().." moved items") + end, + on_put = function(inv, listname, index, stack, player) + experimental.print_to_everything(player:get_player_name().." put items") + end, + on_take = function(inv, listname, index, stack, player) + experimental.print_to_everything(player:get_player_name().." took items") + end, +}) +inv:set_size("main", 4*6) +inv:add_item("main", "experimental:callback_node") +inv:add_item("main", "experimental:particle_spawner") + + diff --git a/games/devtest/mods/experimental/init.lua b/games/devtest/mods/experimental/init.lua new file mode 100644 index 000000000..b292f792e --- /dev/null +++ b/games/devtest/mods/experimental/init.lua @@ -0,0 +1,23 @@ +-- +-- Experimental things +-- + +experimental = {} + +dofile(minetest.get_modpath("experimental").."/detached.lua") +dofile(minetest.get_modpath("experimental").."/items.lua") +dofile(minetest.get_modpath("experimental").."/commands.lua") + +function experimental.print_to_everything(msg) + minetest.log("action", msg) + minetest.chat_send_all(msg) +end + +minetest.log("info", "[experimental] modname="..dump(minetest.get_current_modname())) +minetest.log("info", "[experimental] modpath="..dump(minetest.get_modpath("experimental"))) +minetest.log("info", "[experimental] worldpath="..dump(minetest.get_worldpath())) + + +minetest.register_on_mods_loaded(function() + minetest.log("action", "[experimental] on_mods_loaded()") +end) diff --git a/games/devtest/mods/experimental/items.lua b/games/devtest/mods/experimental/items.lua new file mode 100644 index 000000000..51b063ba2 --- /dev/null +++ b/games/devtest/mods/experimental/items.lua @@ -0,0 +1,103 @@ +minetest.register_node("experimental:callback_node", { + description = "Callback Test Node (construct/destruct/timer)", + tiles = {"experimental_callback_node.png"}, + groups = {dig_immediate=3}, + -- This was known to cause a bug in minetest.item_place_node() when used + -- via minetest.place_node(), causing a placer with no position + paramtype2 = "facedir", + drop = "", + + on_construct = function(pos) + experimental.print_to_everything("experimental:callback_node:on_construct("..minetest.pos_to_string(pos)..")") + local meta = minetest.get_meta(pos) + meta:set_string("mine", "test") + local timer = minetest.get_node_timer(pos) + timer:start(4, 3) + end, + + after_place_node = function(pos, placer) + experimental.print_to_everything("experimental:callback_node:after_place_node("..minetest.pos_to_string(pos)..")") + local meta = minetest.get_meta(pos) + if meta:get_string("mine") == "test" then + experimental.print_to_everything("correct metadata found") + else + experimental.print_to_everything("incorrect metadata found") + end + end, + + on_destruct = function(pos) + experimental.print_to_everything("experimental:callback_node:on_destruct("..minetest.pos_to_string(pos)..")") + end, + + after_destruct = function(pos) + experimental.print_to_everything("experimental:callback_node:after_destruct("..minetest.pos_to_string(pos)..")") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + experimental.print_to_everything("experimental:callback_node:after_dig_node("..minetest.pos_to_string(pos)..")") + end, + + on_timer = function(pos, elapsed) + experimental.print_to_everything("on_timer(): elapsed="..dump(elapsed)) + return true + end, +}) + +minetest.register_tool("experimental:privatizer", { + description = "Node Meta Privatizer", + inventory_image = "experimental_tester_tool_1.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type == "node" then + local node = minetest.get_node(pointed_thing.under) + if node.name == "chest:chest" then + local p = pointed_thing.under + minetest.log("action", "Privatizer used at "..minetest.pos_to_string(p)) + minetest.get_meta(p):mark_as_private({"infotext", "formspec"}) + if user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), "Chest metadata (infotext, formspec) set private!") + end + return + end + end + if user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), "Privatizer can only be used on chest!") + end + end, +}) + +minetest.register_tool("experimental:particle_spawner", { + description = "Particle Spawner", + inventory_image = "experimental_tester_tool_1.png^[invert:g", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing, true) + if pos == nil then + if user then + pos = user:get_pos() + end + end + pos = vector.add(pos, {x=0, y=0.5, z=0}) + local tex, anim + if math.random(0, 1) == 0 then + tex = "experimental_particle_sheet.png" + anim = {type="sheet_2d", frames_w=3, frames_h=2, frame_length=0.5} + else + tex = "experimental_particle_vertical.png" + anim = {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.3} + end + + minetest.add_particle({ + pos = pos, + velocity = {x=0, y=0, z=0}, + acceleration = {x=0, y=0.04, z=0}, + expirationtime = 6, + collisiondetection = true, + texture = tex, + animation = anim, + size = 4, + glow = math.random(0, 5), + }) + end, +}) + diff --git a/games/devtest/mods/experimental/mod.conf b/games/devtest/mods/experimental/mod.conf new file mode 100644 index 000000000..cf0f9cb42 --- /dev/null +++ b/games/devtest/mods/experimental/mod.conf @@ -0,0 +1,2 @@ +name = experimental +description = Chaotic mod containing unstructured tests for testing out engine features. The features in this mod should be moved to other mods. diff --git a/games/devtest/mods/experimental/textures/experimental_callback_node.png b/games/devtest/mods/experimental/textures/experimental_callback_node.png new file mode 100644 index 000000000..e9d87434c Binary files /dev/null and b/games/devtest/mods/experimental/textures/experimental_callback_node.png differ diff --git a/games/devtest/mods/experimental/textures/experimental_particle_sheet.png b/games/devtest/mods/experimental/textures/experimental_particle_sheet.png new file mode 100644 index 000000000..6d70394e4 Binary files /dev/null and b/games/devtest/mods/experimental/textures/experimental_particle_sheet.png differ diff --git a/games/devtest/mods/experimental/textures/experimental_particle_vertical.png b/games/devtest/mods/experimental/textures/experimental_particle_vertical.png new file mode 100644 index 000000000..0320b7545 Binary files /dev/null and b/games/devtest/mods/experimental/textures/experimental_particle_vertical.png differ diff --git a/games/devtest/mods/experimental/textures/experimental_tester_tool_1.png b/games/devtest/mods/experimental/textures/experimental_tester_tool_1.png new file mode 100644 index 000000000..5df416a58 Binary files /dev/null and b/games/devtest/mods/experimental/textures/experimental_tester_tool_1.png differ diff --git a/games/devtest/mods/give_initial_stuff/init.lua b/games/devtest/mods/give_initial_stuff/init.lua new file mode 100644 index 000000000..491a531e4 --- /dev/null +++ b/games/devtest/mods/give_initial_stuff/init.lua @@ -0,0 +1,37 @@ +local give_if_not_gotten_already = function(inv, list, item) + if not inv:contains_item(list, item) then + inv:add_item(list, item) + end +end + +local give_initial_stuff = function(player) + local inv = player:get_inventory() + give_if_not_gotten_already(inv, "main", "basetools:pick_mese") + give_if_not_gotten_already(inv, "main", "basetools:axe_steel") + give_if_not_gotten_already(inv, "main", "basetools:shovel_steel") + give_if_not_gotten_already(inv, "main", "bucket:bucket") + give_if_not_gotten_already(inv, "main", "testnodes:light14") + give_if_not_gotten_already(inv, "main", "chest_of_everything:chest") + minetest.log("action", "[give_initial_stuff] Giving initial stuff to "..player:get_player_name()) +end + +minetest.register_on_newplayer(function(player) + if minetest.settings:get_bool("give_initial_stuff", true) then + give_initial_stuff(player) + end +end) + +minetest.register_chatcommand("stuff", { + params = "", + privs = { give = true }, + description = "Give yourself initial items", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player or not player:is_player() then + return false, "No player." + end + give_initial_stuff(player) + return true + end, +}) + diff --git a/games/devtest/mods/give_initial_stuff/mod.conf b/games/devtest/mods/give_initial_stuff/mod.conf new file mode 100644 index 000000000..1ba49f52a --- /dev/null +++ b/games/devtest/mods/give_initial_stuff/mod.conf @@ -0,0 +1,3 @@ +name = give_initial_stuff +description = Gives items to players on join +depends = basetools, bucket, chest_of_everything, testnodes diff --git a/games/devtest/mods/initial_message/init.lua b/games/devtest/mods/initial_message/init.lua new file mode 100644 index 000000000..59e9f5f4b --- /dev/null +++ b/games/devtest/mods/initial_message/init.lua @@ -0,0 +1,9 @@ +minetest.register_on_joinplayer(function(player) + local cb = function(player) + if not player or not player:is_player() then + return + end + minetest.chat_send_player(player:get_player_name(), "This is the \"Development Test\" [devtest], meant only for testing and development. Use Minetest Game for the real thing.") + end + minetest.after(2.0, cb, player) +end) diff --git a/games/devtest/mods/initial_message/mod.conf b/games/devtest/mods/initial_message/mod.conf new file mode 100644 index 000000000..32aa2ac4e --- /dev/null +++ b/games/devtest/mods/initial_message/mod.conf @@ -0,0 +1,2 @@ +name = initial_message +description = Show message to joining players explaining what this testing game is about diff --git a/games/devtest/mods/mapgen/init.lua b/games/devtest/mods/mapgen/init.lua new file mode 100644 index 000000000..13a186a50 --- /dev/null +++ b/games/devtest/mods/mapgen/init.lua @@ -0,0 +1,81 @@ +-- +-- Aliases for map generator outputs +-- + +-- ESSENTIAL node aliases +-- Basic nodes +minetest.register_alias("mapgen_stone", "basenodes:stone") +minetest.register_alias("mapgen_water_source", "basenodes:water_source") +minetest.register_alias("mapgen_river_water_source", "basenodes:river_water_source") + +-- Additional essential aliases for v6 +minetest.register_alias("mapgen_lava_source", "basenodes:lava_source") +minetest.register_alias("mapgen_dirt", "basenodes:dirt") +minetest.register_alias("mapgen_dirt_with_grass", "basenodes:dirt_with_grass") +minetest.register_alias("mapgen_sand", "basenodes:sand") +minetest.register_alias("mapgen_tree", "basenodes:tree") +minetest.register_alias("mapgen_leaves", "basenodes:leaves") +minetest.register_alias("mapgen_apple", "basenodes:apple") + +-- Essential alias for dungeons +minetest.register_alias("mapgen_cobble", "basenodes:cobble") + +-- Optional aliases for v6 (they all have fallback values in the engine) +if minetest.settings:get_bool("devtest_v6_mapgen_aliases", false) then + minetest.register_alias("mapgen_gravel", "basenodes:gravel") + minetest.register_alias("mapgen_desert_stone", "basenodes:desert_stone") + minetest.register_alias("mapgen_desert_sand", "basenodes:desert_sand") + minetest.register_alias("mapgen_dirt_with_snow", "basenodes:dirt_with_snow") + minetest.register_alias("mapgen_snowblock", "basenodes:snowblock") + minetest.register_alias("mapgen_snow", "basenodes:snow") + minetest.register_alias("mapgen_ice", "basenodes:ice") + minetest.register_alias("mapgen_junglegrass", "basenodes:junglegrass") + minetest.register_alias("mapgen_jungletree", "basenodes:jungletree") + minetest.register_alias("mapgen_jungleleaves", "basenodes:jungleleaves") + minetest.register_alias("mapgen_pine_tree", "basenodes:pine_tree") + minetest.register_alias("mapgen_pine_needles", "basenodes:pine_needles") +end +-- Optional alias for mossycobble (should fall back to cobble) +if minetest.settings:get_bool("devtest_dungeon_mossycobble", false) then + minetest.register_alias("mapgen_mossycobble", "basenodes:mossycobble") +end +-- Optional aliases for dungeon stairs (should fall back to full nodes) +if minetest.settings:get_bool("devtest_dungeon_stairs", false) then + minetest.register_alias("mapgen_stair_cobble", "stairs:stair_cobble") + if minetest.settings:get_bool("devtest_v6_mapgen_aliases", false) then + minetest.register_alias("mapgen_stair_desert_stone", "stairs:stair_desert_stone") + end +end + +-- +-- Register biomes for biome API +-- + +minetest.clear_registered_biomes() +minetest.clear_registered_decorations() + +if minetest.settings:get_bool("devtest_register_biomes", true) then + minetest.register_biome({ + name = "mapgen:grassland", + node_top = "basenodes:dirt_with_grass", + depth_top = 1, + node_filler = "basenodes:dirt", + depth_filler = 1, + y_min = 5, + y_max = 31000, + heat_point = 50, + humidity_point = 50, + }) + + minetest.register_biome({ + name = "mapgen:grassland_ocean", + node_top = "basenodes:sand", + depth_top = 1, + node_filler = "basenodes:sand", + depth_filler = 2, + y_min = -31000, + y_max = 4, + heat_point = 50, + humidity_point = 50, + }) +end diff --git a/games/devtest/mods/mapgen/mod.conf b/games/devtest/mods/mapgen/mod.conf new file mode 100644 index 000000000..15750ccbe --- /dev/null +++ b/games/devtest/mods/mapgen/mod.conf @@ -0,0 +1,3 @@ +name = mapgen +description = Minimal map generator +depends = basenodes diff --git a/games/devtest/mods/modchannels/init.lua b/games/devtest/mods/modchannels/init.lua new file mode 100644 index 000000000..ee925f09b --- /dev/null +++ b/games/devtest/mods/modchannels/init.lua @@ -0,0 +1,14 @@ +-- +-- Mod channels experimental handlers +-- +local mod_channel = minetest.mod_channel_join("experimental_preview") + +minetest.register_on_modchannel_message(function(channel, sender, message) + minetest.log("action", "[modchannels] Server received message `" .. message + .. "` on channel `" .. channel .. "` from sender `" .. sender .. "`") + + if mod_channel:is_writeable() then + mod_channel:send_all("experimental answers to preview") + mod_channel:leave() + end +end) diff --git a/games/devtest/mods/modchannels/mod.conf b/games/devtest/mods/modchannels/mod.conf new file mode 100644 index 000000000..7c13aadfb --- /dev/null +++ b/games/devtest/mods/modchannels/mod.conf @@ -0,0 +1,2 @@ +name = modchannels +description = Add experimental mod channel handlers diff --git a/games/devtest/mods/soundstuff/init.lua b/games/devtest/mods/soundstuff/init.lua new file mode 100644 index 000000000..22012ba14 --- /dev/null +++ b/games/devtest/mods/soundstuff/init.lua @@ -0,0 +1,170 @@ +local simple_nodes = { + footstep = { "Footstep Sound Node", "soundstuff_node_footstep.png" }, + dig = { "Dig Sound Node", "soundstuff_node_dig.png" }, + dug = { "Dug Sound Node", "soundstuff_node_dug.png" }, + place = { "Place Sound Node", "soundstuff_node_place.png" }, + place_failed = { "Place Failed Sound Node", "soundstuff_node_place_failed.png" }, +} + +for k,v in pairs(simple_nodes) do + minetest.register_node("soundstuff:"..k, { + description = v[1], + tiles = {"soundstuff_node_sound.png","soundstuff_node_sound.png",v[2]}, + groups = {dig_immediate=2}, + sounds = { + [k] = { name = "soundstuff_mono", gain = 1.0 }, + } + }) +end + +minetest.register_node("soundstuff:place_failed_attached", { + description = "Attached Place Failed Sound Node", + tiles = {"soundstuff_node_sound.png", "soundstuff_node_sound.png", "soundstuff_node_place_failed.png"}, + groups = {dig_immediate=2, attached_node=1}, + drawtype = "nodebox", + paramtype = "light", + node_box = { type = "fixed", fixed = { + { -7/16, -7/16, -7/16, 7/16, 7/16, 7/16 }, + { -0.5, -0.5, -0.5, 0.5, -7/16, 0.5 }, + }}, + sounds = { + place_failed = { name = "soundstuff_mono", gain = 1.0 }, + }, +}) + +minetest.register_node("soundstuff:fall", { + description = "Fall Sound Node", + tiles = {"soundstuff_node_sound.png", "soundstuff_node_sound.png", "soundstuff_node_fall.png"}, + groups = {dig_immediate=2, falling_node=1}, + sounds = { + fall = { name = "soundstuff_mono", gain = 1.0 }, + } +}) + +minetest.register_node("soundstuff:fall_attached", { + description = "Attached Fall Sound Node", + tiles = {"soundstuff_node_sound.png", "soundstuff_node_sound.png", "soundstuff_node_fall.png"}, + groups = {dig_immediate=2, attached_node=1}, + drawtype = "nodebox", + paramtype = "light", + node_box = { type = "fixed", fixed = { + { -7/16, -7/16, -7/16, 7/16, 7/16, 7/16 }, + { -0.5, -0.5, -0.5, 0.5, -7/16, 0.5 }, + }}, + sounds = { + fall = { name = "soundstuff_mono", gain = 1.0 }, + } +}) + +minetest.register_node("soundstuff:footstep_liquid", { + description = "Liquid Footstep Sound Node", + drawtype = "liquid", + tiles = { + "soundstuff_node_sound.png^[colorize:#0000FF:127", + }, + special_tiles = { + {name = "soundstuff_node_sound.png^[colorize:#0000FF:127", backface_culling = false}, + {name = "soundstuff_node_sound.png^[colorize:#0000FF:127", backface_culling = true}, + }, + liquids_pointable = true, + liquidtype = "source", + liquid_alternative_flowing = "soundstuff:footstep_liquid", + liquid_alternative_source = "soundstuff:footstep_liquid", + liquid_renewable = false, + liquid_range = 0, + liquid_viscosity = 0, + alpha = 190, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + post_effect_color = {a = 64, r = 0, g = 0, b = 200}, + sounds = { + footstep = { name = "soundstuff_mono", gain = 1.0 }, + } +}) + +minetest.register_node("soundstuff:footstep_climbable", { + description = "Climbable Footstep Sound Node", + drawtype = "allfaces", + tiles = { + "soundstuff_node_climbable.png", + }, + alpha = 120, + paramtype = "light", + sunlight_propagates = true, + walkable = false, + climbable = true, + is_ground_content = false, + groups = { dig_immediate = 2 }, + sounds = { + footstep = { name = "soundstuff_mono", gain = 1.0 }, + } +}) + + + +minetest.register_craftitem("soundstuff:eat", { + description = "Eat Sound Item", + inventory_image = "soundstuff_eat.png", + on_use = minetest.item_eat(0), + sound = { + eat = { name = "soundstuff_mono", gain = 1.0 }, + } +}) + +minetest.register_tool("soundstuff:breaks", { + description = "Break Sound Tool", + inventory_image = "soundstuff_node_dug.png", + sound = { + breaks = { name = "soundstuff_mono", gain = 1.0 }, + }, + tool_capabilities = { + max_drop_level=0, + groupcaps={ + cracky={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, + choppy={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, + snappy={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, + crumbly={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, + }, + }, +}) + +-- Plays sound repeatedly +minetest.register_node("soundstuff:positional", { + description = "Positional Sound Node", + on_construct = function(pos) + local timer = minetest.get_node_timer(pos) + timer:start(0) + end, + on_timer = function(pos, elapsed) + local node = minetest.get_node(pos) + local dist = node.param2 + if dist == 0 then + dist = nil + end + minetest.sound_play("soundstuff_mono", { pos = pos, max_hear_distance = dist }) + local timer = minetest.get_node_timer(pos) + timer:start(0.7) + end, + on_rightclick = function(pos, node, clicker) + node.param2 = (node.param2 + 1) % 64 + minetest.set_node(pos, node) + if clicker and clicker:is_player() then + local dist = node.param2 + local diststr + if dist == 0 then + diststr = "" + else + diststr = tostring(dist) + end + minetest.chat_send_player(clicker:get_player_name(), "max_hear_distance = " .. diststr) + end + end, + + groups = { dig_immediate = 2 }, + tiles = { "soundstuff_node_sound.png" }, +}) + diff --git a/games/devtest/mods/soundstuff/mod.conf b/games/devtest/mods/soundstuff/mod.conf new file mode 100644 index 000000000..2c631e2da --- /dev/null +++ b/games/devtest/mods/soundstuff/mod.conf @@ -0,0 +1,2 @@ +name = soundstuff +description = Example items and nodes for testing sound effects diff --git a/games/devtest/mods/soundstuff/sounds/soundstuff_mono.ogg b/games/devtest/mods/soundstuff/sounds/soundstuff_mono.ogg new file mode 100644 index 000000000..43428d566 Binary files /dev/null and b/games/devtest/mods/soundstuff/sounds/soundstuff_mono.ogg differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_eat.png b/games/devtest/mods/soundstuff/textures/soundstuff_eat.png new file mode 100644 index 000000000..aed205422 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_eat.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_blank.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_blank.png new file mode 100644 index 000000000..4dffacc4c Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_blank.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_climbable.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_climbable.png new file mode 100644 index 000000000..3888f793c Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_climbable.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_dig.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_dig.png new file mode 100644 index 000000000..67ba111d8 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_dig.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_dug.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_dug.png new file mode 100644 index 000000000..bab5fbe51 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_dug.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_fall.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_fall.png new file mode 100644 index 000000000..17b14f1e4 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_fall.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_footstep.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_footstep.png new file mode 100644 index 000000000..6367ae909 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_footstep.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_place.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_place.png new file mode 100644 index 000000000..d159ad533 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_place.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_place_failed.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_place_failed.png new file mode 100644 index 000000000..780ba946d Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_place_failed.png differ diff --git a/games/devtest/mods/soundstuff/textures/soundstuff_node_sound.png b/games/devtest/mods/soundstuff/textures/soundstuff_node_sound.png new file mode 100644 index 000000000..0592a0299 Binary files /dev/null and b/games/devtest/mods/soundstuff/textures/soundstuff_node_sound.png differ diff --git a/games/devtest/mods/stairs/init.lua b/games/devtest/mods/stairs/init.lua new file mode 100644 index 000000000..2701cabab --- /dev/null +++ b/games/devtest/mods/stairs/init.lua @@ -0,0 +1,65 @@ +stairs = {} + +-- Node will be called stairs:stair_ +function stairs.register_stair(subname, recipeitem, groups, images, description) + minetest.register_node(":stairs:stair_" .. subname, { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = true, + groups = groups, + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + {-0.5, 0, 0, 0.5, 0.5, 0.5}, + }, + }, + }) +end + +-- Node will be called stairs:slab_ +function stairs.register_slab(subname, recipeitem, groups, images, description) + minetest.register_node(":stairs:slab_" .. subname, { + description = description, + drawtype = "nodebox", + tiles = images, + paramtype = "light", + is_ground_content = true, + groups = groups, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + }) +end + +-- Nodes will be called stairs:{stair,slab}_ +function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab) + stairs.register_stair(subname, recipeitem, groups, images, desc_stair) + stairs.register_slab(subname, recipeitem, groups, images, desc_slab) +end + +stairs.register_stair_and_slab("stone", "basenodes:stone", + {cracky=3}, + {"default_stone.png"}, + "Stone Stair", + "Stone Slab") + +stairs.register_stair_and_slab("desert_stone", "basenodes:desert_stone", + {cracky=3}, + {"default_desert_stone.png"}, + "Desert Stone Stair", + "Desert Stone Slab") + +stairs.register_stair_and_slab("cobble", "basenodes:cobble", + {cracky=3}, + {"default_cobble.png"}, + "Cobblestone Stair", + "Cobblestone Slab") diff --git a/games/devtest/mods/stairs/mod.conf b/games/devtest/mods/stairs/mod.conf new file mode 100644 index 000000000..724bff881 --- /dev/null +++ b/games/devtest/mods/stairs/mod.conf @@ -0,0 +1,3 @@ +name = stairs +description = Adds stairs and slabs +depends = basenodes diff --git a/games/devtest/mods/testentities/armor.lua b/games/devtest/mods/testentities/armor.lua new file mode 100644 index 000000000..4c30cec8d --- /dev/null +++ b/games/devtest/mods/testentities/armor.lua @@ -0,0 +1,41 @@ +-- Armorball: Test entity for testing armor groups +-- Rightclick to change armor group + +local phasearmor = { + [0]={icy=100}, + [1]={firy=100}, + [2]={fleshy=100}, + [3]={immortal=1}, + [4]={punch_operable=1}, +} + +minetest.register_entity("testentities:armorball", { + initial_properties = { + hp_max = 20, + physical = false, + collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4}, + visual = "sprite", + visual_size = {x=1, y=1}, + textures = {"testentities_armorball.png"}, + spritediv = {x=1, y=5}, + initial_sprite_basepos = {x=0, y=0}, + }, + + _phase = 2, + + on_activate = function(self, staticdata) + minetest.log("action", "[testentities] armorball.on_activate") + self.object:set_armor_groups(phasearmor[self._phase]) + self.object:set_sprite({x=0, y=self._phase}) + end, + + on_rightclick = function(self, clicker) + -- Change armor group and sprite + self._phase = self._phase + 1 + if self._phase >= 5 then + self._phase = 0 + end + self.object:set_sprite({x=0, y=self._phase}) + self.object:set_armor_groups(phasearmor[self._phase]) + end, +}) diff --git a/games/devtest/mods/testentities/callbacks.lua b/games/devtest/mods/testentities/callbacks.lua new file mode 100644 index 000000000..711079f87 --- /dev/null +++ b/games/devtest/mods/testentities/callbacks.lua @@ -0,0 +1,75 @@ +-- Entities that test their callbacks + +local message = function(msg) + minetest.log("action", msg) + minetest.chat_send_all(msg) +end + +local get_object_name = function(obj) + local name = "" + if obj then + if obj:is_player() then + name = obj:get_player_name() + else + name = "" + end + end + return name +end + +local spos = function(self) + return minetest.pos_to_string(vector.round(self.object:get_pos())) +end + +-- Callback test entity (all callbacks except on_step) +minetest.register_entity("testentities:callback", { + initial_properties = { + visual = "upright_sprite", + textures = { "testentities_callback.png" }, + }, + + on_activate = function(self, staticdata, dtime_s) + message("Callback entity: on_activate! pos="..spos(self).."; dtime_s="..dtime_s) + end, + on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage) + local name = get_object_name(puncher) + message( + "Callback entity: on_punch! ".. + "pos="..spos(self).."; puncher="..name.."; ".. + "time_from_last_punch="..time_from_last_punch.."; ".. + "tool_capabilities="..tostring(dump(tool_capabilities)).."; ".. + "dir="..tostring(dump(dir)).."; damage="..damage) + end, + on_rightclick = function(self, clicker) + local name = get_object_name(clicker) + message("Callback entity: on_rightclick! pos="..spos(self).."; clicker="..name) + end, + on_death = function(self, killer) + local name = get_object_name(killer) + message("Callback entity: on_death! pos="..spos(self).."; killer="..name) + end, + on_attach_child = function(self, child) + local name = get_object_name(child) + message("Callback entity: on_attach_child! pos="..spos(self).."; child="..name) + end, + on_detach_child = function(self, child) + local name = get_object_name(child) + message("Callback entity: on_detach_child! pos="..spos(self).."; child="..name) + end, + on_detach = function(self, parent) + local name = get_object_name(parent) + message("Callback entity: on_detach! pos="..spos(self).."; parent="..name) + end, + get_staticdata = function(self) + message("Callback entity: get_staticdata! pos="..spos(self)) + end, +}) + +-- Only test on_step callback +minetest.register_entity("testentities:callback_step", { + visual = "upright_sprite", + textures = { "testentities_callback_step.png" }, + on_step = function(self, dtime) + message("on_step callback entity: on_step! pos="..spos(self).."; dtime="..dtime) + end, +}) diff --git a/games/devtest/mods/testentities/init.lua b/games/devtest/mods/testentities/init.lua new file mode 100644 index 000000000..df8c72ea7 --- /dev/null +++ b/games/devtest/mods/testentities/init.lua @@ -0,0 +1,3 @@ +dofile(minetest.get_modpath("testentities").."/visuals.lua") +dofile(minetest.get_modpath("testentities").."/armor.lua") +dofile(minetest.get_modpath("testentities").."/callbacks.lua") diff --git a/games/devtest/mods/testentities/mod.conf b/games/devtest/mods/testentities/mod.conf new file mode 100644 index 000000000..7a8cb5a3e --- /dev/null +++ b/games/devtest/mods/testentities/mod.conf @@ -0,0 +1,2 @@ +name = testentities +description = Example entities for testing diff --git a/games/devtest/mods/testentities/textures/testentities_armorball.png b/games/devtest/mods/testentities/textures/testentities_armorball.png new file mode 100644 index 000000000..88147bd1f Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_armorball.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_callback.png b/games/devtest/mods/testentities/textures/testentities_callback.png new file mode 100644 index 000000000..c4c9066d1 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_callback.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_callback_step.png b/games/devtest/mods/testentities/textures/testentities_callback_step.png new file mode 100644 index 000000000..b67506a97 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_callback_step.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_cube1.png b/games/devtest/mods/testentities/textures/testentities_cube1.png new file mode 100644 index 000000000..c667e425f Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_cube1.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_cube2.png b/games/devtest/mods/testentities/textures/testentities_cube2.png new file mode 100644 index 000000000..481823420 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_cube2.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_cube3.png b/games/devtest/mods/testentities/textures/testentities_cube3.png new file mode 100644 index 000000000..03b5daa15 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_cube3.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_cube4.png b/games/devtest/mods/testentities/textures/testentities_cube4.png new file mode 100644 index 000000000..639204896 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_cube4.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_cube5.png b/games/devtest/mods/testentities/textures/testentities_cube5.png new file mode 100644 index 000000000..d8acdf0b6 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_cube5.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_cube6.png b/games/devtest/mods/testentities/textures/testentities_cube6.png new file mode 100644 index 000000000..5f81a64d9 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_cube6.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_dungeon_master.png b/games/devtest/mods/testentities/textures/testentities_dungeon_master.png new file mode 100644 index 000000000..1e3107746 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_dungeon_master.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_sprite.png b/games/devtest/mods/testentities/textures/testentities_sprite.png new file mode 100644 index 000000000..a4b019699 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_sprite.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_upright_sprite1.png b/games/devtest/mods/testentities/textures/testentities_upright_sprite1.png new file mode 100644 index 000000000..6242511df Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_upright_sprite1.png differ diff --git a/games/devtest/mods/testentities/textures/testentities_upright_sprite2.png b/games/devtest/mods/testentities/textures/testentities_upright_sprite2.png new file mode 100644 index 000000000..a79a760e3 Binary files /dev/null and b/games/devtest/mods/testentities/textures/testentities_upright_sprite2.png differ diff --git a/games/devtest/mods/testentities/visuals.lua b/games/devtest/mods/testentities/visuals.lua new file mode 100644 index 000000000..de346fd68 --- /dev/null +++ b/games/devtest/mods/testentities/visuals.lua @@ -0,0 +1,74 @@ +-- Minimal test entities to test visuals + +minetest.register_entity("testentities:sprite", { + initial_properties = { + visual = "sprite", + textures = { "testentities_sprite.png" }, + }, +}) + +minetest.register_entity("testentities:upright_sprite", { + initial_properties = { + visual = "upright_sprite", + textures = { + "testentities_upright_sprite1.png", + "testentities_upright_sprite2.png", + }, + }, +}) + +minetest.register_entity("testentities:cube", { + initial_properties = { + visual = "cube", + textures = { + "testentities_cube1.png", + "testentities_cube2.png", + "testentities_cube3.png", + "testentities_cube4.png", + "testentities_cube5.png", + "testentities_cube6.png", + }, + }, +}) + +minetest.register_entity("testentities:item", { + initial_properties = { + visual = "item", + wield_item = "testnodes:normal", + }, +}) + +minetest.register_entity("testentities:wielditem", { + initial_properties = { + visual = "wielditem", + wield_item = "testnodes:normal", + }, +}) + +minetest.register_entity("testentities:mesh", { + initial_properties = { + visual = "mesh", + mesh = "testnodes_pyramid.obj", + textures = { + "testnodes_mesh_stripes2.png" + }, + }, +}) + +-- Advanced visual tests + +-- A test entity for testing animated and yaw-modulated sprites +minetest.register_entity("testentities:yawsprite", { + initial_properties = { + selectionbox = {-0.3, -0.5, -0.3, 0.3, 0.3, 0.3}, + visual = "sprite", + visual_size = {x=0.6666, y=1}, + textures = {"testentities_dungeon_master.png^[makealpha:128,0,0^[makealpha:128,128,0"}, + spritediv = {x=6, y=5}, + initial_sprite_basepos = {x=0, y=0}, + on_activate = function(self, staticdata) + self.object:set_sprite({x=0, y=0}, 1, 0, true) + end, + }, +}) + diff --git a/games/devtest/mods/testfood/init.lua b/games/devtest/mods/testfood/init.lua new file mode 100644 index 000000000..a6236ff68 --- /dev/null +++ b/games/devtest/mods/testfood/init.lua @@ -0,0 +1,24 @@ +local S = minetest.get_translator("testfood") + +minetest.register_craftitem("testfood:good1", { + description = S("Good Food (+1)"), + inventory_image = "testfood_good.png", + on_use = minetest.item_eat(1), +}) +minetest.register_craftitem("testfood:good5", { + description = S("Good Food (+5)"), + inventory_image = "testfood_good2.png", + on_use = minetest.item_eat(5), +}) + +minetest.register_craftitem("testfood:bad1", { + description = S("Bad Food (-1)"), + inventory_image = "testfood_bad.png", + on_use = minetest.item_eat(-1), +}) +minetest.register_craftitem("testfood:bad5", { + description = S("Bad Food (-5)"), + inventory_image = "testfood_bad2.png", + on_use = minetest.item_eat(-5), +}) + diff --git a/games/devtest/mods/testfood/mod.conf b/games/devtest/mods/testfood/mod.conf new file mode 100644 index 000000000..7bff21b6e --- /dev/null +++ b/games/devtest/mods/testfood/mod.conf @@ -0,0 +1,2 @@ +name = testfood +description = For testing food items diff --git a/games/devtest/mods/testfood/textures/testfood_bad.png b/games/devtest/mods/testfood/textures/testfood_bad.png new file mode 100644 index 000000000..6e9251440 Binary files /dev/null and b/games/devtest/mods/testfood/textures/testfood_bad.png differ diff --git a/games/devtest/mods/testfood/textures/testfood_bad2.png b/games/devtest/mods/testfood/textures/testfood_bad2.png new file mode 100644 index 000000000..22b567890 Binary files /dev/null and b/games/devtest/mods/testfood/textures/testfood_bad2.png differ diff --git a/games/devtest/mods/testfood/textures/testfood_good.png b/games/devtest/mods/testfood/textures/testfood_good.png new file mode 100644 index 000000000..31df7f5dd Binary files /dev/null and b/games/devtest/mods/testfood/textures/testfood_good.png differ diff --git a/games/devtest/mods/testfood/textures/testfood_good2.png b/games/devtest/mods/testfood/textures/testfood_good2.png new file mode 100644 index 000000000..e43dda209 Binary files /dev/null and b/games/devtest/mods/testfood/textures/testfood_good2.png differ diff --git a/games/devtest/mods/testformspec/callbacks.lua b/games/devtest/mods/testformspec/callbacks.lua new file mode 100644 index 000000000..559380580 --- /dev/null +++ b/games/devtest/mods/testformspec/callbacks.lua @@ -0,0 +1,51 @@ +local callback_test = 0 + +local out = function(player, formname, fields, number) + local snum = "" + if number then + snum = " "..number + end + local msg = "Formspec callback"..snum..": player="..player:get_player_name()..", formname=\""..tostring(formname).."\", fields="..dump(fields) + minetest.chat_send_player(player:get_player_name(), msg) + minetest.log("action", msg) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if callback_test == 1 then + out(player, formname, fields) + elseif callback_test == 2 then + out(player, formname, fields, 1) + end +end) +minetest.register_on_player_receive_fields(function(player, formname, fields) + if callback_test == 2 then + out(player, formname, fields, 2) + return true -- Disable the first callback + end +end) +minetest.register_on_player_receive_fields(function(player, formname, fields) + if callback_test == 2 then + out(player, formname, fields, 3) + end +end) + +minetest.register_chatcommand("test_formspec_callbacks", { + params = "[ 0 | 1 | 2 ]", + description = "Test: Change formspec callbacks testing mode", + func = function(name, param) + local mode = tonumber(param) + if not mode then + callback_test = (callback_test + 1 % 3) + else + callback_test = mode + end + if callback_test == 1 then + minetest.chat_send_player(name, "Formspec callback test mode 1 enabled: Logging only") + elseif callback_test == 2 then + minetest.chat_send_player(name, "Formspec callback test mode 2 enabled: Three callbacks, disable pre-registered callbacks") + else + callback_test = 0 + minetest.chat_send_player(name, "Formspec callback test disabled!") + end + end +}) diff --git a/games/devtest/mods/testformspec/dummy_items.lua b/games/devtest/mods/testformspec/dummy_items.lua new file mode 100644 index 000000000..2037ae9cf --- /dev/null +++ b/games/devtest/mods/testformspec/dummy_items.lua @@ -0,0 +1,14 @@ +-- This code adds dummy items that are supposed to be used in formspecs +-- for testing item_image formspec elements. + +minetest.register_node("testformspec:node", { + description = "Formspec Test Node", + tiles = { "testformspec_node.png" }, + groups = { dig_immediate = 3, dummy = 1 }, +}) + +minetest.register_craftitem("testformspec:item", { + description = "Formspec Test Item", + inventory_image = "testformspec_item.png", + groups = { dummy = 1 }, +}) diff --git a/games/devtest/mods/testformspec/formspec.lua b/games/devtest/mods/testformspec/formspec.lua new file mode 100644 index 000000000..08c1b6dc0 --- /dev/null +++ b/games/devtest/mods/testformspec/formspec.lua @@ -0,0 +1,381 @@ +local color = minetest.colorize + +local clip_fs = [[ + style_type[label,button,image_button,item_image_button, + tabheader,scrollbar,table,animated_image + ,field,textarea,checkbox,dropdown;noclip=%c] + + label[0,0;A clipping test] + button[0,1;3,0.8;clip_button;A clipping test] + image_button[0,2;3,0.8;testformspec_button_image.png;clip_image_button;A clipping test] + item_image_button[0,3;3,0.8;testformspec:item;clip_item_image_button;A clipping test] + tabheader[0,4.7;3,0.63;clip_tabheader;Clip,Test,Text,Tabs;1;false;false] + field[0,5;3,0.8;clip_field;Title;] + textarea[0,6;3,1;clip_textarea;Title;] + checkbox[0,7.5;clip_checkbox;This is a test;true] + dropdown[0,8;3,0.8;clip_dropdown;Select An Item,One,Two,Three,Four,Five;1] + scrollbar[0,9;3,0.8;horizontal;clip_scrollbar;3] + tablecolumns[text;text] + table[0,10;3,1;clip_table;one,two,three,four;1] + animated_image[-0.5,11;4.5,1;clip_animated_image;testformspec_animation.png;4;100] +]] + +local tabheaders_fs = [[ + tabheader[0,0;10,0.63;tabs_opaque;Opaque,Without,Border;1;false;false] + tabheader[0,1;10,0.63;tabs_opaque_border;Opaque,With,Border;1;false;true] + tabheader[0,2;10,0.63;tabs_transparent;Transparent,Without,Border;1;true;false] + tabheader[0,3;10,0.63;tabs_transparent_border;Transparent,With,Border;1;true;true] + tabheader[0,4;tabs_default;Default,Tabs;1] + tabheader[0,6;10,0.5;tabs_size1;Height=0.5;1;false;false] + tabheader[2,6;10,0.75;tabs_size1;Height=0.75;1;false;false] + tabheader[4,6;10,1;tabs_size2;Height=1;1;false;false] + tabheader[6,6;10,1.25;tabs_size2;Height=1.25;1;false;false] + tabheader[8,6;10,1.5;tabs_size2;Height=1.5;1;false;false] +]] + +local hypertext_basic = [[ +Normal test +This is a normal text. + +style test + + . + + +Tag test +normal +mono +bold +italic +underlined +big +bigger +left +
center
+right +justify. Here comes a blind text: Lorem testum dolor sit amet consecutor celeron fiftifahivus e shadoninia e smalus jokus anrus relsocutoti rubenwardus. Erasputinus hara holisti dominus wusi. Grumarinsti erltusmuate ol fortitusti fla flo, blani burki e sfani fahif. Ultae ratii, e megus gigae don anonimus. Grinus dimondus krockus e nore. Endus finalus nowus comus endus o blindus tekstus. + +Custom tag test + + + + + +color=green +Action: color=green +Action: hovercolor=yellow +size=24 +font=mono +color=green font=mono size=24 + +action test +action + +img test +Normal: + +width=48 height=48: + +float=left: + +float=right: + + +item test +Normal: + +width=48 height=48 + +angle=30,0,0: + +angle=0,30,0: + +angle=0,0,30: + +rotate=yes: + +rotate=100,0,0: + +rotate=0,100,0: + +rotate=0,0,100: + +rotate=50,75,100: + +angle=-30,-45,90 rotate=100,150,-50: +]] + +local hypertext_global = [[ + +This is a test of the global tag. The parameters are: +background=gray margin=20 valign=bottom halign=right color=pink hovercolor=purple size=12 font=mono +action]] + +local hypertext_fs = "hypertext[0,0;11,9;hypertext;"..minetest.formspec_escape(hypertext_basic).."]".. + "hypertext[0,9.5;11,2.5;hypertext;"..minetest.formspec_escape(hypertext_global).."]" + +local style_fs = [[ + style[one_btn1;bgcolor=red;textcolor=yellow;bgcolor_hovered=orange; + bgcolor_pressed=purple] + button[0,0;2.5,0.8;one_btn1;Button] + + style[one_btn2;border=false;textcolor=cyan] ]].. + "button[0,1.05;2.5,0.8;one_btn2;Text " .. color("#FF0", "Yellow") .. [[] + + style[one_btn3;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png; + bgimg_pressed=testformspec_pressed.png] + button[0,2.1;1,1;one_btn3;Border] + + style[one_btn4;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png; + bgimg_pressed=testformspec_pressed.png;border=false] + button[1.25,2.1;1,1;one_btn4;NoBor] + + style[one_btn5;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png; + bgimg_pressed=testformspec_pressed.png;border=false;alpha=false] + button[0,3.35;1,1;one_btn5;Alph] + + style[one_btn6;border=true] + image_button[0,4.6;1,1;testformspec_button_image.png;one_btn6;Border] + + style[one_btn7;border=false] + image_button[1.25,4.6;1,1;testformspec_button_image.png;one_btn7;NoBor] + + style[one_btn8;border=false] + image_button[0,5.85;1,1;testformspec_button_image.png;one_btn8;Border;false;true;testformspec_pressed.png] + + style[one_btn9;border=true] + image_button[1.25,5.85;1,1;testformspec_button_image.png;one_btn9;NoBor;false;false;testformspec_pressed.png] + + style[one_btn10;alpha=false] + image_button[0,7.1;1,1;testformspec_button_image.png;one_btn10;NoAlpha] + + style[one_btn11;alpha=true] + image_button[1.25,7.1;1,1;testformspec_button_image.png;one_btn11;Alpha] + + style[one_btn12;border=true] + item_image_button[0,8.35;1,1;testformspec:item;one_btn12;Border] + + style[one_btn13;border=false] + item_image_button[1.25,8.35;1,1;testformspec:item;one_btn13;NoBor] + + style[one_btn14;border=false;bgimg=testformspec_bg.png;fgimg=testformspec_button_image.png] + style[one_btn14:hovered;bgimg=testformspec_bg_hovered.png;fgimg=testformspec_hovered.png;textcolor=yellow] + style[one_btn14:pressed;bgimg=testformspec_bg_pressed.png;fgimg=testformspec_pressed.png;textcolor=blue] + style[one_btn14:hovered+pressed;textcolor=purple] + image_button[0,9.6;1,1;testformspec_button_image.png;one_btn14;Bg] + + style[one_btn15;border=false;bgimg=testformspec_bg.png;bgimg_hovered=testformspec_bg_hovered.png;bgimg_pressed=testformspec_bg_pressed.png] + item_image_button[1.25,9.6;1,1;testformspec:item;one_btn15;Bg] + + style[one_btn16;border=false;bgimg=testformspec_bg_9slice.png;bgimg_hovered=testformspec_bg_9slice_hovered.png;bgimg_pressed=testformspec_bg_9slice_pressed.png;bgimg_middle=4,6] + button[2.5,9.6;2,1;one_btn16;9-Slice Bg] + + + + container[2.75,0] + + style[one_tb1;textcolor=Yellow] + tabheader[0,3;2.5,0.63;one_tb1;Yellow,Text,Tabs;1;false;false] + + style[one_f1;textcolor=yellow] + field[0,4.25;2.5,0.8;one_f1;Field One;Yellow Text] + + style[one_f2;border=false;textcolor=cyan] + field[0,5.75;2.5,0.8;one_f2;Field Two;Borderless Cyan Text] + + style[one_f3;textcolor=yellow] + textarea[0,7.025;2.5,0.8;one_f3;Label;]] .. + minetest.formspec_escape("Yellow Text\nLine two") .. [[ ] + + style[one_f4;border=false;textcolor=cyan] + textarea[0,8.324999999999999;2.5,0.8;one_f4;Label;]] .. + minetest.formspec_escape("Borderless Cyan Text\nLine two") .. [[ ] + + container_end[] +]] + +local scroll_fs = + "button[8.5,1;4,1;outside;Outside of container]".. + "box[1,1;8,6;#00aa]".. + "scroll_container[1,1;8,6;scrbar;vertical]".. + "button[0,1;1,1;lorem;Lorem]".. + "button[0,10;1,1;ipsum;Ipsum]".. + "pwdfield[2,2;1,1;lorem2;Lorem]".. + "list[current_player;main;4,4;1,5;]".. + "box[2,5;3,2;#ffff00]".. + "image[1,10;3,2;testformspec_item.png]".. + "image[3,1;testformspec_item.png]".. + "item_image[2,6;3,2;testformspec:node]".. + "label[2,15;bla Bli\nfoo bar]".. + "item_image_button[2,3;1,1;testformspec:node;itemimagebutton;ItemImageButton]".. + "tooltip[0,11;3,2;Buz;#f00;#000]".. + "box[0,11;3,2;#00ff00]".. + "hypertext[3,13;3,3;;" .. hypertext_basic .. "]" .. + "container[0,18]".. + "box[1,2;3,2;#0a0a]".. + "scroll_container[1,2;3,2;scrbar2;horizontal;0.06]".. + "button[0,0;6,1;butnest;Nest]".. + "label[10,0.5;nest]".. + "scroll_container_end[]".. + "scrollbar[1,0;3.5,0.3;horizontal;scrbar2;0]".. + "container_end[]".. + "dropdown[0,6;2;hmdrpdwn;apple,bulb;1]".. + "image_button[0,4;2,2;testformspec_button_image.png;imagebutton;bbbbtt;false;true;testformspec_pressed.png]".. + "box[1,22.5;4,1;#a00a]".. + "scroll_container_end[]".. + "scrollbaroptions[max=170]".. -- lowest seen pos is: 0.1*170+6=23 (factor*max+height) + "scrollbar[7.5,0;0.3,4;vertical;scrbar;0]".. + "scrollbar[8,0;0.3,4;vertical;scrbarhmmm;0]".. + "dropdown[0,6;2;hmdrpdwnnn;Outside,of,container;1]" + +--style_type[label;textcolor=green] +--label[0,0;Green] +--style_type[label;textcolor=blue] +--label[0,1;Blue] +--style_type[label;textcolor=;border=true] +--label[1.2,0;Border] +--style_type[label;border=true;bgcolor=red] +--label[1.2,1;Background] +--style_type[label;border=;bgcolor=] +--label[0.75,2;Reset] + + +local pages = { + -- Real Coordinates + [[ + formspec_version[3] + size[12,13] + image_button[0,0;1,1;logo.png;rc_image_button_1x1;1x1] + image_button[1,0;2,2;logo.png;rc_image_button_2x2;2x2] + button[0,2;1,1;rc_button_1x1;1x1] + button[1,2;2,2;rc_button_2x2;2x2] + item_image[0,4;1,1;air] + item_image[1,4;2,2;air] + item_image_button[0,6;1,1;testformspec:node;rc_item_image_button_1x1;1x1] + item_image_button[1,6;2,2;testformspec:node;rc_item_image_button_2x2;2x2] + field[3,.5;3,.5;rc_field;Field;text] + pwdfield[6,.5;3,1;rc_pwdfield;Password Field] + field[3,1;3,1;;Read-Only Field;text] + textarea[3,2;3,.5;rc_textarea_small;Textarea;text] + textarea[6,2;3,2;rc_textarea_big;Textarea;text\nmore text] + textarea[3,3;3,1;;Read-Only Textarea;text\nmore text] + textlist[3,4;3,2;rc_textlist;Textlist,Perfect Coordinates;1;false] + tableoptions[highlight=#ABCDEF75;background=#00000055;border=false] + table[6,4;3,2;rc_table;Table,Cool Stuff,Foo,Bar;2] + dropdown[3,6;3,1;rc_dropdown_small;This,is,a,dropdown;1] + dropdown[6,6;3,2;rc_dropdown_big;I,am,a,bigger,dropdown;5] + image[0,8;3,2;ignore.png] + box[3,7;3,1;#00A3FF] + checkbox[3,8;rc_checkbox_1;Check me!;false] + checkbox[3,9;rc_checkbox_2;Uncheck me now!;true] + scrollbar[0,11.5;11.5,.5;horizontal;rc_scrollbar_horizontal;500] + scrollbar[11.5,0;.5,11.5;vertical;rc_scrollbar_vertical;0] + list[current_player;main;6,8;3,2;1] + button[9,0;2.5,1;rc_empty_button_1;] + button[9,1;2.5,1;rc_empty_button_2;] + button[9,2;2.5,1;rc_empty_button_3;] ]].. + "label[9,0.5;This is a label.\nLine\nLine\nLine\nEnd]".. + [[button[9,3;1,1;rc_empty_button_4;] + vertlabel[9,4;VERT] + label[10,3;HORIZ] + tabheader[8,0;6,0.65;rc_tabheader;Tab 1,Tab 2,Tab 3,Secrets;1;false;false] + ]], + -- Style + + "formspec_version[3]size[12,13]" .. + ("label[0.375,0.375;Styled - %s %s]"):format( + color("#F00", "red text"), + color("#77FF00CC", "green text")) .. + "label[6.375,0.375;Unstyled]" .. + "box[0,0.75;12,0.1;#999]" .. + "box[6,0.85;0.1,11.15;#999]" .. + "container[0.375,1.225]" .. + style_fs .. + "container_end[]container[6.375,1.225]" .. + style_fs:gsub("one_", "two_"):gsub("style%[[^%]]+%]", ""):gsub("style_type%[[^%]]+%]", "") .. + "container_end[]", + + -- Noclip + "formspec_version[3]size[12,13]" .. + "label[0.1,0.5;Clip]" .. + "container[-2.5,1]" .. clip_fs:gsub("%%c", "false") .. "container_end[]" .. + "label[11,0.5;Noclip]" .. + "container[11.5,1]" .. clip_fs:gsub("%%c", "true") .. "container_end[]", + + -- Hypertext + "size[12,13]real_coordinates[true]" .. + "container[0.5,0.5]" .. hypertext_fs .. "container_end[]", + + -- Tabheaders + "size[12,13]real_coordinates[true]" .. + "container[0.5,1.5]" .. tabheaders_fs .. "container_end[]", + + -- Animation + [[ + formspec_version[3] + size[12,13] + animated_image[0.5,0.5;1,1;;testformspec_animation.png;4;100] + animated_image[0.5,1.75;1,1;;testformspec_animation.jpg;4;100] + animated_image[1.75,0.5;1,1;;testformspec_animation.png;100;100] + animated_image[3,0.5;1,1;ani_img_1;testformspec_animation.png;4;1000] + button[4.25,0.5;1,1;ani_btn_1;Current +Number] + animated_image[3,1.75;1,1;ani_img_2;testformspec_animation.png;4;1000;2] + button[4.25,1.75;1,1;ani_btn_2;Current +Number] + animated_image[3,3;1,1;;testformspec_animation.png;4;0] + animated_image[3,4.25;1,1;;testformspec_animation.png;4;0;3] + animated_image[5.5,0.5;5,2;;testformspec_animation.png;4;100] + animated_image[5.5,2.75;5,2;;testformspec_animation.jpg;4;100] + ]], + + -- Scroll containers + "formspec_version[3]size[12,13]" .. + scroll_fs, +} + +local function show_test_formspec(pname, page_id) + page_id = page_id or 2 + + local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Anim,ScrollC;" .. page_id .. ";false;false]" + + minetest.show_formspec(pname, "testformspec:formspec", fs) +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "testformspec:formspec" then + return false + end + + + if fields.maintabs then + show_test_formspec(player:get_player_name(), tonumber(fields.maintabs)) + return true + end + + if fields.ani_img_1 and fields.ani_btn_1 then + minetest.chat_send_player(player:get_player_name(), "ani_img_1 = " .. tostring(fields.ani_img_1)) + return true + elseif fields.ani_img_2 and fields.ani_btn_2 then + minetest.chat_send_player(player:get_player_name(), "ani_img_2 = " .. tostring(fields.ani_img_2)) + return true + end + + if fields.hypertext then + minetest.chat_send_player(player:get_player_name(), "Hypertext action received: " .. tostring(fields.hypertext)) + return true + end +end) + +minetest.register_chatcommand("test_formspec", { + params = "", + description = "Open the test formspec", + func = function(name) + if not minetest.get_player_by_name(name) then + return false, "You need to be online!" + end + + show_test_formspec(name) + return true + end, +}) diff --git a/games/devtest/mods/testformspec/init.lua b/games/devtest/mods/testformspec/init.lua new file mode 100644 index 000000000..23b565f08 --- /dev/null +++ b/games/devtest/mods/testformspec/init.lua @@ -0,0 +1,3 @@ +dofile(minetest.get_modpath("testformspec").."/dummy_items.lua") +dofile(minetest.get_modpath("testformspec").."/formspec.lua") +dofile(minetest.get_modpath("testformspec").."/callbacks.lua") diff --git a/games/devtest/mods/testformspec/mod.conf b/games/devtest/mods/testformspec/mod.conf new file mode 100644 index 000000000..00eac307a --- /dev/null +++ b/games/devtest/mods/testformspec/mod.conf @@ -0,0 +1,2 @@ +name = testformspec +description = Contains an example formspec to test all the features of formspecs diff --git a/games/devtest/mods/testformspec/textures/testformspec_animation.jpg b/games/devtest/mods/testformspec/textures/testformspec_animation.jpg new file mode 100644 index 000000000..b98ca2677 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_animation.jpg differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_animation.png b/games/devtest/mods/testformspec/textures/testformspec_animation.png new file mode 100644 index 000000000..b972e5dbb Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_animation.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_bg.png b/games/devtest/mods/testformspec/textures/testformspec_bg.png new file mode 100644 index 000000000..cd1e50900 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_bg.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_bg_9slice.png b/games/devtest/mods/testformspec/textures/testformspec_bg_9slice.png new file mode 100644 index 000000000..34433ac82 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_bg_9slice.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_bg_9slice_hovered.png b/games/devtest/mods/testformspec/textures/testformspec_bg_9slice_hovered.png new file mode 100644 index 000000000..01c2dc777 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_bg_9slice_hovered.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_bg_9slice_pressed.png b/games/devtest/mods/testformspec/textures/testformspec_bg_9slice_pressed.png new file mode 100644 index 000000000..0cbac7536 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_bg_9slice_pressed.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_bg_hovered.png b/games/devtest/mods/testformspec/textures/testformspec_bg_hovered.png new file mode 100644 index 000000000..3ebbb988c Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_bg_hovered.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_bg_pressed.png b/games/devtest/mods/testformspec/textures/testformspec_bg_pressed.png new file mode 100644 index 000000000..2fb5fc21e Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_bg_pressed.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_button_image.png b/games/devtest/mods/testformspec/textures/testformspec_button_image.png new file mode 100644 index 000000000..75c438a9a Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_button_image.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_hovered.png b/games/devtest/mods/testformspec/textures/testformspec_hovered.png new file mode 100644 index 000000000..3ccad30a2 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_hovered.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_item.png b/games/devtest/mods/testformspec/textures/testformspec_item.png new file mode 100644 index 000000000..4fd823b55 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_item.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_node.png b/games/devtest/mods/testformspec/textures/testformspec_node.png new file mode 100644 index 000000000..c107f28a3 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_node.png differ diff --git a/games/devtest/mods/testformspec/textures/testformspec_pressed.png b/games/devtest/mods/testformspec/textures/testformspec_pressed.png new file mode 100644 index 000000000..45c504f27 Binary files /dev/null and b/games/devtest/mods/testformspec/textures/testformspec_pressed.png differ diff --git a/games/devtest/mods/testnodes/README.md b/games/devtest/mods/testnodes/README.md new file mode 100644 index 000000000..13ed972c0 --- /dev/null +++ b/games/devtest/mods/testnodes/README.md @@ -0,0 +1,11 @@ +# Test Nodes + +This mod contains a bunch of basic nodes to test development stuff. +Most nodes are kept as minimal as possible in order to show off one particular feature of the engine, to make testing stuff easier. + +This mod includes tests for: + +* drawtypes +* paramtype2's +* node properties such as damage, drowning, falling, etc. +* other random stuff diff --git a/games/devtest/mods/testnodes/drawtypes.lua b/games/devtest/mods/testnodes/drawtypes.lua new file mode 100644 index 000000000..35fda960f --- /dev/null +++ b/games/devtest/mods/testnodes/drawtypes.lua @@ -0,0 +1,517 @@ +--[[ Drawtype Test: This file tests out and provides examples for +all drawtypes in Minetest. It is attempted to keep the node +definitions as simple and minimal as possible to keep +side-effects to a minimum. + +How to read the node definitions: +There are two parts which are separated by 2 newlines: +The first part contains the things that are more or less essential +for defining the drawtype (except description, which is +at the top for readability). +The second part (after the 2 newlines) contains stuff that are +unrelated to the drawtype, stuff that is mostly there to make +testing this node easier and more convenient. +]] + +local S = minetest.get_translator("testnodes") + +-- If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. +-- This is due to . +-- This is only added to make the items more visible to avoid confusion, but you will no longer see +-- the default inventory images for these items. When you want to test the default inventory image of drawtypes, +-- this should be turned off. +-- TODO: Remove support for fallback inventory image as soon #9209 is fixed. +local SHOW_FALLBACK_IMAGE = minetest.settings:get_bool("testnodes_show_fallback_image", false) + +local fallback_image = function(img) + if SHOW_FALLBACK_IMAGE then + return img + else + return nil + end +end + +-- A regular cube +minetest.register_node("testnodes:normal", { + description = S("Normal Drawtype Test Node"), + drawtype = "normal", + tiles = { "testnodes_normal.png" }, + + groups = { dig_immediate = 3 }, +}) + +-- Standard glasslike node +minetest.register_node("testnodes:glasslike", { + description = S("Glasslike Drawtype Test Node"), + drawtype = "glasslike", + paramtype = "light", + tiles = { "testnodes_glasslike.png" }, + + groups = { dig_immediate = 3 }, +}) + +-- Glasslike framed with the two textures (normal and "detail") +minetest.register_node("testnodes:glasslike_framed", { + description = S("Glasslike Framed Drawtype Test Node"), + drawtype = "glasslike_framed", + paramtype = "light", + tiles = { + "testnodes_glasslike_framed.png", + "testnodes_glasslike_detail.png", + }, + + + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + +-- Like the one above, but without the "detail" texture (texture 2). +-- This node was added to see how the engine behaves when the "detail" texture +-- is missing. +minetest.register_node("testnodes:glasslike_framed_no_detail", { + description = S("Glasslike Framed without Detail Drawtype Test Node"), + drawtype = "glasslike_framed", + paramtype = "light", + tiles = { "testnodes_glasslike_framed2.png" }, + + + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + + +minetest.register_node("testnodes:glasslike_framed_optional", { + description = S("Glasslike Framed Optional Drawtype Test Node"), + drawtype = "glasslike_framed_optional", + paramtype = "light", + tiles = { + "testnodes_glasslike_framed_optional.png", + "testnodes_glasslike_detail.png", + }, + + + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + + + +minetest.register_node("testnodes:allfaces", { + description = S("Allfaces Drawtype Test Node"), + drawtype = "allfaces", + paramtype = "light", + tiles = { "testnodes_allfaces.png" }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:allfaces_optional", { + description = S("Allfaces Optional Drawtype Test Node"), + drawtype = "allfaces_optional", + paramtype = "light", + tiles = { "testnodes_allfaces_optional.png" }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:allfaces_optional_waving", { + description = S("Waving Allfaces Optional Drawtype Test Node"), + drawtype = "allfaces_optional", + paramtype = "light", + tiles = { "testnodes_allfaces_optional.png^[brighten" }, + waving = 2, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:firelike", { + description = S("Firelike Drawtype Test Node"), + drawtype = "firelike", + paramtype = "light", + tiles = { "testnodes_firelike.png" }, + + + walkable = false, + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:fencelike", { + description = S("Fencelike Drawtype Test Node"), + drawtype = "fencelike", + paramtype = "light", + tiles = { "testnodes_fencelike.png" }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:torchlike", { + description = S("Wallmounted Torchlike Drawtype Test Node"), + drawtype = "torchlike", + paramtype = "light", + paramtype2 = "wallmounted", + tiles = { + "testnodes_torchlike_floor.png", + "testnodes_torchlike_ceiling.png", + "testnodes_torchlike_wall.png", + }, + + + walkable = false, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, + inventory_image = fallback_image("testnodes_torchlike_floor.png"), +}) + +minetest.register_node("testnodes:signlike", { + description = S("Wallmounted Signlike Drawtype Test Node"), + drawtype = "signlike", + paramtype = "light", + paramtype2 = "wallmounted", + tiles = { "testnodes_signlike.png" }, + + + walkable = false, + groups = { dig_immediate = 3 }, + sunlight_propagates = true, + inventory_image = fallback_image("testnodes_signlike.png"), +}) + +minetest.register_node("testnodes:plantlike", { + description = S("Plantlike Drawtype Test Node"), + drawtype = "plantlike", + paramtype = "light", + tiles = { "testnodes_plantlike.png" }, + + + walkable = false, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:plantlike_waving", { + description = S("Waving Plantlike Drawtype Test Node"), + drawtype = "plantlike", + paramtype = "light", + tiles = { "testnodes_plantlike_waving.png" }, + waving = 1, + + + walkable = false, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + + + +-- param2 will rotate +minetest.register_node("testnodes:plantlike_degrotate", { + description = S("Degrotate Plantlike Drawtype Test Node"), + drawtype = "plantlike", + paramtype = "light", + paramtype2 = "degrotate", + tiles = { "testnodes_plantlike_degrotate.png" }, + + + walkable = false, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + +-- param2 will change height +minetest.register_node("testnodes:plantlike_leveled", { + description = S("Leveled Plantlike Drawtype Test Node"), + drawtype = "plantlike", + paramtype = "light", + paramtype2 = "leveled", + tiles = { + { name = "testnodes_plantlike_leveled.png", tileable_vertical = true }, + }, + + + -- We set a default param2 here only for convenience, to make the "plant" visible after placement + place_param2 = 8, + walkable = false, + sunlight_propagates = true, + groups = { dig_immediate = 3 }, +}) + +-- param2 changes shape +minetest.register_node("testnodes:plantlike_meshoptions", { + description = S("Meshoptions Plantlike Drawtype Test Node"), + drawtype = "plantlike", + paramtype = "light", + paramtype2 = "meshoptions", + tiles = { "testnodes_plantlike_meshoptions.png" }, + + + walkable = false, + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:plantlike_rooted", { + description = S("Rooted Plantlike Drawtype Test Node"), + drawtype = "plantlike_rooted", + paramtype = "light", + tiles = { "testnodes_plantlike_rooted_base.png" }, + special_tiles = { "testnodes_plantlike_rooted.png" }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:plantlike_rooted_waving", { + description = S("Waving Rooted Plantlike Drawtype Test Node"), + drawtype = "plantlike_rooted", + paramtype = "light", + tiles = { + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base_side_waving.png", + }, + special_tiles = { "testnodes_plantlike_rooted_waving.png" }, + waving = 1, + + groups = { dig_immediate = 3 }, +}) + +-- param2 changes height +minetest.register_node("testnodes:plantlike_rooted_leveled", { + description = S("Leveled Rooted Plantlike Drawtype Test Node"), + drawtype = "plantlike_rooted", + paramtype = "light", + paramtype2 = "leveled", + tiles = { + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base_side_leveled.png", + }, + special_tiles = { + { name = "testnodes_plantlike_rooted_leveled.png", tileable_vertical = true }, + }, + + + -- We set a default param2 here only for convenience, to make the "plant" visible after placement + place_param2 = 8, + groups = { dig_immediate = 3 }, +}) + +-- param2 changes shape +minetest.register_node("testnodes:plantlike_rooted_meshoptions", { + description = S("Meshoptions Rooted Plantlike Drawtype Test Node"), + drawtype = "plantlike_rooted", + paramtype = "light", + paramtype2 = "meshoptions", + tiles = { + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base_side_meshoptions.png", + }, + special_tiles = { + "testnodes_plantlike_rooted_meshoptions.png", + }, + + groups = { dig_immediate = 3 }, +}) + +-- param2 changes rotation +minetest.register_node("testnodes:plantlike_rooted_degrotate", { + description = S("Degrotate Rooted Plantlike Drawtype Test Node"), + drawtype = "plantlike_rooted", + paramtype = "light", + paramtype2 = "degrotate", + tiles = { + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base.png", + "testnodes_plantlike_rooted_base_side_degrotate.png", + }, + special_tiles = { + "testnodes_plantlike_rooted_degrotate.png", + }, + + groups = { dig_immediate = 3 }, +}) + +-- Demonstrative liquid nodes, source and flowing form. This is only the +-- drawtype, no physical liquid properties are used +minetest.register_node("testnodes:liquid", { + description = S("Source Liquid Drawtype Test Node"), + drawtype = "liquid", + paramtype = "light", + tiles = { + "testnodes_liquidsource.png", + }, + special_tiles = { + {name="testnodes_liquidsource.png", backface_culling=false}, + {name="testnodes_liquidsource.png", backface_culling=true}, + }, + use_texture_alpha = true, + + + walkable = false, + liquid_alternative_flowing = "testnodes:liquid_flowing", + liquid_alternative_source = "testnodes:liquid", + groups = { dig_immediate = 3 }, +}) +minetest.register_node("testnodes:liquid_flowing", { + description = S("Flowing Liquid Drawtype Test Node"), + drawtype = "flowingliquid", + paramtype = "light", + paramtype2 = "flowingliquid", + tiles = { + "testnodes_liquidflowing.png", + }, + special_tiles = { + {name="testnodes_liquidflowing.png", backface_culling=false}, + {name="testnodes_liquidflowing.png", backface_culling=false}, + }, + use_texture_alpha = true, + + + walkable = false, + liquid_alternative_flowing = "testnodes:liquid_flowing", + liquid_alternative_source = "testnodes:liquid", + groups = { dig_immediate = 3 }, +}) +minetest.register_node("testnodes:liquid_waving", { + description = S("Waving Source Liquid Drawtype Test Node"), + drawtype = "liquid", + paramtype = "light", + tiles = { + "testnodes_liquidsource.png^[brighten", + }, + special_tiles = { + {name="testnodes_liquidsource.png^[brighten", backface_culling=false}, + {name="testnodes_liquidsource.png^[brighten", backface_culling=true}, + }, + use_texture_alpha = true, + waving = 3, + + + walkable = false, + liquid_alternative_flowing = "testnodes:liquid_flowing", + liquid_alternative_source = "testnodes:liquid", + groups = { dig_immediate = 3 }, +}) +minetest.register_node("testnodes:liquid_flowing_waving", { + description = S("Waving Flowing Liquid Drawtype Test Node"), + drawtype = "flowingliquid", + paramtype = "light", + paramtype2 = "flowingliquid", + tiles = { + "testnodes_liquidflowing.png^[brighten", + }, + special_tiles = { + {name="testnodes_liquidflowing.png^[brighten", backface_culling=false}, + {name="testnodes_liquidflowing.png^[brighten", backface_culling=false}, + }, + use_texture_alpha = true, + waving = 3, + + + walkable = false, + liquid_alternative_flowing = "testnodes:liquid_flowing", + liquid_alternative_source = "testnodes:liquid", + groups = { dig_immediate = 3 }, +}) + + + +-- Invisible node +minetest.register_node("testnodes:airlike", { + description = S("Airlike Drawtype Test Node"), + drawtype = "airlike", + paramtype = "light", + + + walkable = false, + groups = { dig_immediate = 3 }, + sunlight_propagates = true, + inventory_image = fallback_image("testnodes_airlike.png"), +}) + +-- param2 changes liquid height +minetest.register_node("testnodes:glassliquid", { + description = S("Glasslike Liquid Level Drawtype Test Node"), + drawtype = "glasslike_framed", + paramtype = "light", + paramtype2 = "glasslikeliquidlevel", + tiles = { + "testnodes_glasslikeliquid.png", + }, + special_tiles = { + "testnodes_liquid.png", + }, + + groups = { dig_immediate = 3 }, +}) + +-- Adding many raillike examples, primarily to demonstrate the behavior of +-- "raillike groups". Nodes of the same type (rail, groupless, line, street) +-- should connect to nodes of the same "rail type" (=same shape, different +-- color) only. +local rails = { + { "rail", {"testnodes_rail_straight.png", "testnodes_rail_curved.png", "testnodes_rail_t_junction.png", "testnodes_rail_crossing.png"} }, + { "line", {"testnodes_line_straight.png", "testnodes_line_curved.png", "testnodes_line_t_junction.png", "testnodes_line_crossing.png"}, }, + { "street", {"testnodes_street_straight.png", "testnodes_street_curved.png", "testnodes_street_t_junction.png", "testnodes_street_crossing.png"}, }, + -- the "groupless" nodes are nodes in which the "connect_to_raillike" group is not set + { "groupless", {"testnodes_rail2_straight.png", "testnodes_rail2_curved.png", "testnodes_rail2_t_junction.png", "testnodes_rail2_crossing.png"} }, +} +local colors = { "", "cyan", "red" } + +for r=1, #rails do + local id = rails[r][1] + local tiles = rails[r][2] + local raillike_group + if id ~= "groupless" then + raillike_group = minetest.raillike_group(id) + end + for c=1, #colors do + local color + if colors[c] ~= "" then + color = colors[c] + end + minetest.register_node("testnodes:raillike_"..id..c, { + description = S("Raillike Drawtype Test Node: @1 @2", id, c), + drawtype = "raillike", + paramtype = "light", + tiles = tiles, + groups = { connect_to_raillike = raillike_group, dig_immediate = 3 }, + + + color = color, + selection_box = { + type = "fixed", + fixed = {{-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}}, + }, + sunlight_propagates = true, + walkable = false, + }) + end +end + + + +-- Add visual_scale variants of previous nodes for half and double size +local scale = function(subname, desc_double, desc_half) + local original = "testnodes:"..subname + local def = table.copy(minetest.registered_items[original]) + def.visual_scale = 2.0 + def.description = desc_double + minetest.register_node("testnodes:"..subname.."_double", def) + def = table.copy(minetest.registered_items[original]) + def.visual_scale = 0.5 + def.description = desc_half + minetest.register_node("testnodes:"..subname.."_half", def) +end + +scale("plantlike", + S("Double-sized Plantlike Drawtype Test Node"), + S("Half-sized Plantlike Drawtype Test Node")) +scale("torchlike", + S("Double-sized Wallmounted Torchlike Drawtype Test Node"), + S("Half-sized Wallmounted Torchlike Drawtype Test Node")) +scale("signlike", + S("Double-sized Wallmounted Signlike Drawtype Test Node"), + S("Half-sized Wallmounted Signlike Drawtype Test Node")) +scale("firelike", + S("Double-sized Firelike Drawtype Test Node"), + S("Half-sized Firelike Drawtype Test Node")) diff --git a/games/devtest/mods/testnodes/init.lua b/games/devtest/mods/testnodes/init.lua new file mode 100644 index 000000000..92e2c5630 --- /dev/null +++ b/games/devtest/mods/testnodes/init.lua @@ -0,0 +1,10 @@ +local path = minetest.get_modpath(minetest.get_current_modname()) + +dofile(path.."/drawtypes.lua") +dofile(path.."/meshes.lua") +dofile(path.."/nodeboxes.lua") +dofile(path.."/param2.lua") +dofile(path.."/properties.lua") +dofile(path.."/liquids.lua") +dofile(path.."/light.lua") +dofile(path.."/textures.lua") diff --git a/games/devtest/mods/testnodes/light.lua b/games/devtest/mods/testnodes/light.lua new file mode 100644 index 000000000..94409e83f --- /dev/null +++ b/games/devtest/mods/testnodes/light.lua @@ -0,0 +1,48 @@ +-- Test Nodes: Light test + +local S = minetest.get_translator("testnodes") + +-- All possible light levels +for i=1, minetest.LIGHT_MAX do + minetest.register_node("testnodes:light"..i, { + description = S("Light Source (@1)", i), + paramtype = "light", + light_source = i, + + + tiles ={"testnodes_light_"..i..".png"}, + drawtype = "glasslike", + walkable = false, + sunlight_propagates = true, + is_ground_content = false, + groups = {dig_immediate=3}, + }) +end + +-- Lets light through, but not sunlight, leading to a +-- reduction in light level when light passes through +minetest.register_node("testnodes:sunlight_filter", { + description = S("Sunlight Filter"), + paramtype = "light", + + + drawtype = "glasslike", + tiles = { + "testnodes_sunlight_filter.png", + }, + groups = { dig_immediate = 3 }, +}) + +-- Lets light and sunlight through without obstruction +minetest.register_node("testnodes:sunlight_propagator", { + description = S("Sunlight Propagator"), + paramtype = "light", + sunlight_propagates = true, + + + drawtype = "glasslike", + tiles = { + "testnodes_sunlight_filter.png^[brighten", + }, + groups = { dig_immediate = 3 }, +}) diff --git a/games/devtest/mods/testnodes/liquids.lua b/games/devtest/mods/testnodes/liquids.lua new file mode 100644 index 000000000..e316782ad --- /dev/null +++ b/games/devtest/mods/testnodes/liquids.lua @@ -0,0 +1,91 @@ +-- Add liquids for ranges and viscosity levels 0-8 + +for d=0, 8 do + minetest.register_node("testnodes:rliquid_"..d, { + description = "Test Liquid Source, Range "..d, + drawtype = "liquid", + tiles = {"testnodes_liquidsource_r"..d..".png"}, + special_tiles = { + {name = "testnodes_liquidsource_r"..d..".png", backface_culling = false}, + {name = "testnodes_liquidsource_r"..d..".png", backface_culling = true}, + }, + alpha = 192, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + liquidtype = "source", + liquid_alternative_flowing = "testnodes:rliquid_flowing_"..d, + liquid_alternative_source = "testnodes:rliquid_"..d, + liquid_range = d, + }) + + minetest.register_node("testnodes:rliquid_flowing_"..d, { + description = "Flowing Test Liquid, Range "..d, + drawtype = "flowingliquid", + tiles = {"testnodes_liquidflowing_r"..d..".png"}, + special_tiles = { + {name = "testnodes_liquidflowing_r"..d..".png", backface_culling = false}, + {name = "testnodes_liquidflowing_r"..d..".png", backface_culling = false}, + }, + alpha = 192, + paramtype = "light", + paramtype2 = "flowingliquid", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + liquidtype = "flowing", + liquid_alternative_flowing = "testnodes:rliquid_flowing_"..d, + liquid_alternative_source = "testnodes:rliquid_"..d, + liquid_range = d, + }) + + local mod = "^[colorize:#000000:127" + minetest.register_node("testnodes:vliquid_"..d, { + description = "Test Liquid Source, Viscosity "..d, + drawtype = "liquid", + tiles = {"testnodes_liquidsource_r"..d..".png"..mod}, + special_tiles = { + {name = "testnodes_liquidsource_r"..d..".png"..mod, backface_culling = false}, + {name = "testnodes_liquidsource_r"..d..".png"..mod, backface_culling = true}, + }, + alpha = 192, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + liquidtype = "source", + liquid_alternative_flowing = "testnodes:vliquid_flowing_"..d, + liquid_alternative_source = "testnodes:vliquid_"..d, + liquid_viscosity = d, + }) + + minetest.register_node("testnodes:vliquid_flowing_"..d, { + description = "Flowing Test Liquid, Viscosity "..d, + drawtype = "flowingliquid", + tiles = {"testnodes_liquidflowing_r"..d..".png"..mod}, + special_tiles = { + {name = "testnodes_liquidflowing_r"..d..".png"..mod, backface_culling = false}, + {name = "testnodes_liquidflowing_r"..d..".png"..mod, backface_culling = false}, + }, + alpha = 192, + paramtype = "light", + paramtype2 = "flowingliquid", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + is_ground_content = false, + liquidtype = "flowing", + liquid_alternative_flowing = "testnodes:vliquid_flowing_"..d, + liquid_alternative_source = "testnodes:vliquid_"..d, + liquid_viscosity = d, + }) + +end diff --git a/games/devtest/mods/testnodes/meshes.lua b/games/devtest/mods/testnodes/meshes.lua new file mode 100644 index 000000000..900abc180 --- /dev/null +++ b/games/devtest/mods/testnodes/meshes.lua @@ -0,0 +1,145 @@ +-- Meshes + +local S = minetest.get_translator("testnodes") + +local ocorner_cbox = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5}, + {-0.5, -0.25, -0.25, 0.25, 0, 0.5}, + {-0.5, 0, 0, 0, 0.25, 0.5}, + {-0.5, 0.25, 0.25, -0.25, 0.5, 0.5} + } +} + +local tall_pyr_cbox = { + type = "fixed", + fixed = { + { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }, + { -0.375, -0.25, -0.375, 0.375, 0, 0.375}, + { -0.25, 0, -0.25, 0.25, 0.25, 0.25}, + { -0.125, 0.25, -0.125, 0.125, 0.5, 0.125} + } +} + +-- Normal mesh +minetest.register_node("testnodes:mesh", { + description = S("Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes2.png"}, + paramtype = "light", + collision_box = tall_pyr_cbox, + + groups = {dig_immediate=3}, +}) + +-- Facedir mesh: outer corner slope +minetest.register_node("testnodes:mesh_facedir", { + description = S("Facedir Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_ocorner.obj", + tiles = {"testnodes_mesh_stripes.png"}, + paramtype = "light", + paramtype2 = "facedir", + collision_box = ocorner_cbox, + + groups = {dig_immediate=3}, +}) + +minetest.register_node("testnodes:mesh_colorfacedir", { + description = S("Color Facedir Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_ocorner.obj", + tiles = {"testnodes_mesh_stripes3.png"}, + paramtype = "light", + paramtype2 = "colorfacedir", + palette = "testnodes_palette_facedir.png", + collision_box = ocorner_cbox, + + groups = {dig_immediate=3}, +}) + +-- Wallmounted mesh: pyramid +minetest.register_node("testnodes:mesh_wallmounted", { + description = S("Wallmounted Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes2.png"}, + paramtype = "light", + paramtype2 = "wallmounted", + collision_box = tall_pyr_cbox, + + groups = {dig_immediate=3}, +}) + +minetest.register_node("testnodes:mesh_colorwallmounted", { + description = S("Color Wallmounted Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes3.png"}, + paramtype = "light", + paramtype2 = "colorwallmounted", + palette = "testnodes_palette_wallmounted.png", + collision_box = tall_pyr_cbox, + + groups = {dig_immediate=3}, +}) + + +minetest.register_node("testnodes:mesh_double", { + description = S("Double-sized Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes2.png"}, + paramtype = "light", + collision_box = tall_pyr_cbox, + visual_scale = 2, + + groups = {dig_immediate=3}, +}) +minetest.register_node("testnodes:mesh_half", { + description = S("Half-sized Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes2.png"}, + paramtype = "light", + collision_box = tall_pyr_cbox, + visual_scale = 0.5, + + groups = {dig_immediate=3}, +}) + +minetest.register_node("testnodes:mesh_waving1", { + description = S("Plantlike-waving Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes4.png^[multiply:#B0FFB0"}, + paramtype = "light", + collision_box = tall_pyr_cbox, + waving = 1, + + groups = {dig_immediate=3}, +}) +minetest.register_node("testnodes:mesh_waving2", { + description = S("Leaflike-waving Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes4.png^[multiply:#FFFFB0"}, + paramtype = "light", + collision_box = tall_pyr_cbox, + waving = 2, + + groups = {dig_immediate=3}, +}) +minetest.register_node("testnodes:mesh_waving3", { + description = S("Liquidlike-waving Mesh Test Node"), + drawtype = "mesh", + mesh = "testnodes_pyramid.obj", + tiles = {"testnodes_mesh_stripes4.png^[multiply:#B0B0FF"}, + paramtype = "light", + collision_box = tall_pyr_cbox, + waving = 3, + + groups = {dig_immediate=3}, +}) diff --git a/games/devtest/mods/testnodes/mod.conf b/games/devtest/mods/testnodes/mod.conf new file mode 100644 index 000000000..4824c6ed0 --- /dev/null +++ b/games/devtest/mods/testnodes/mod.conf @@ -0,0 +1,2 @@ +name = testnodes +description = Contains a bunch of basic example nodes for demonstrative purposes, development and testing diff --git a/games/devtest/mods/testnodes/models/testnodes_ocorner.obj b/games/devtest/mods/testnodes/models/testnodes_ocorner.obj new file mode 100644 index 000000000..231d7056b --- /dev/null +++ b/games/devtest/mods/testnodes/models/testnodes_ocorner.obj @@ -0,0 +1,23 @@ +# Blender v2.73 (sub 0) OBJ File: 'slope_test_ocorner_onetexture.blend' +# www.blender.org +o Cube_Cube.002 +v 0.500000 0.500000 0.500000 +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vt 1.000000 0.000000 +vn 0.000000 -1.000000 -0.000000 +vn 1.000000 0.000000 0.000000 +vn 0.000000 -0.000000 1.000000 +vn -0.707100 0.707100 0.000000 +vn 0.000000 0.707100 -0.707100 +s off +f 3/1/1 2/2/1 4/3/1 5/4/1 +f 1/2/2 3/3/2 5/4/2 +f 1/1/3 2/3/3 3/4/3 +f 1/1/4 4/3/4 2/4/4 +f 1/2/5 5/3/5 4/4/5 diff --git a/games/devtest/mods/testnodes/models/testnodes_pyramid.obj b/games/devtest/mods/testnodes/models/testnodes_pyramid.obj new file mode 100644 index 000000000..b305af2f8 --- /dev/null +++ b/games/devtest/mods/testnodes/models/testnodes_pyramid.obj @@ -0,0 +1,24 @@ +# Blender v2.73 (sub 0) OBJ File: 'slope_test_pyramid_onetexture.blend' +# www.blender.org +o Cube +v 0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 -0.500000 0.500000 +v -0.500000 -0.500000 -0.500000 +v -0.000000 0.500000 -0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vt 1.000000 0.000000 +vt 0.500000 1.000000 +vn 0.000000 -1.000000 0.000000 +vn -0.894400 0.447200 -0.000000 +vn 0.000000 0.447200 -0.894400 +vn 0.894400 0.447200 0.000000 +vn -0.000000 0.447200 0.894400 +s off +f 1/1/1 2/2/1 3/3/1 4/4/1 +f 3/4/2 5/5/2 4/3/2 +f 5/5/3 1/3/3 4/4/3 +f 1/4/4 5/5/4 2/3/4 +f 2/4/5 5/5/5 3/3/5 diff --git a/games/devtest/mods/testnodes/nodeboxes.lua b/games/devtest/mods/testnodes/nodeboxes.lua new file mode 100644 index 000000000..ebd858337 --- /dev/null +++ b/games/devtest/mods/testnodes/nodeboxes.lua @@ -0,0 +1,80 @@ +local S = minetest.get_translator("testnodes") + +-- Nodebox examples and tests. + +-- An simple example nodebox with one centered box +minetest.register_node("testnodes:nodebox_fixed", { + description = S("Fixed Nodebox Test Node"), + tiles = {"testnodes_nodebox.png"}, + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}, + }, + + groups = {dig_immediate=3}, +}) + +-- 50% higher than a regular node +minetest.register_node("testnodes:nodebox_overhigh", { + description = S("Overhigh Nodebox Test Node"), + tiles = {"testnodes_nodebox.png"}, + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 1, 0.5}, + }, + + groups = {dig_immediate=3}, +}) + +-- 100% higher than a regular node +minetest.register_node("testnodes:nodebox_overhigh2", { + description = S("Double-height Nodebox Test Node"), + tiles = {"testnodes_nodebox.png"}, + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}, + }, + + groups = {dig_immediate=3}, +}) + +-- Height of nodebox changes with its param2 value +minetest.register_node("testnodes:nodebox_leveled", { + description = S("Leveled Nodebox Test Node"), + tiles = {"testnodes_nodebox.png"}, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "leveled", + node_box = { + type = "leveled", + fixed = {-0.5, 0.0, -0.5, 0.5, -0.499, 0.5}, + }, + + groups = {dig_immediate=3}, +}) + +-- Wall-like nodebox that connects to neighbors +minetest.register_node("testnodes:nodebox_connected", { + description = S("Connected Nodebox Test Node"), + tiles = {"testnodes_nodebox.png"}, + groups = {connected_nodebox=1, dig_immediate=3}, + drawtype = "nodebox", + paramtype = "light", + connects_to = {"group:connected_nodebox"}, + connect_sides = {"front", "back", "left", "right"}, + node_box = { + type = "connected", + fixed = {-0.125, -0.500, -0.125, 0.125, 0.500, 0.125}, + connect_front = {-0.125, -0.500, -0.500, 0.125, 0.400, -0.125}, + connect_back = {-0.125, -0.500, 0.125, 0.125, 0.400, 0.500}, + connect_left = {-0.500, -0.500, -0.125, -0.125, 0.400, 0.125}, + connect_right = {0.125, -0.500, -0.125, 0.500, 0.400, 0.125}, + }, +}) + diff --git a/games/devtest/mods/testnodes/param2.lua b/games/devtest/mods/testnodes/param2.lua new file mode 100644 index 000000000..5d64376fa --- /dev/null +++ b/games/devtest/mods/testnodes/param2.lua @@ -0,0 +1,168 @@ +-- This file is for misc. param2 tests that aren't covered in drawtypes.lua already. + +local S = minetest.get_translator("testnodes") + +minetest.register_node("testnodes:facedir", { + description = S("Facedir Test Node"), + paramtype2 = "facedir", + tiles = { + "testnodes_1.png", + "testnodes_2.png", + "testnodes_3.png", + "testnodes_4.png", + "testnodes_5.png", + "testnodes_6.png", + }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:facedir_nodebox", { + description = S("Facedir Nodebox Test Node"), + tiles = { + "testnodes_1.png", + "testnodes_2.png", + "testnodes_3.png", + "testnodes_4.png", + "testnodes_5.png", + "testnodes_6.png", + }, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.2, 0.2, 0.2}, + }, + + groups = {dig_immediate=3}, +}) + +minetest.register_node("testnodes:wallmounted", { + description = S("Wallmounted Test Node"), + paramtype2 = "wallmounted", + tiles = { + "testnodes_1w.png", + "testnodes_2w.png", + "testnodes_3w.png", + "testnodes_4w.png", + "testnodes_5w.png", + "testnodes_6w.png", + }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:wallmounted_nodebox", { + description = S("Wallmounted Nodebox Test Node"), + paramtype2 = "wallmounted", + paramtype = "light", + tiles = { + "testnodes_1w.png", + "testnodes_2w.png", + "testnodes_3w.png", + "testnodes_4w.png", + "testnodes_5w.png", + "testnodes_6w.png", + }, + drawtype = "nodebox", + node_box = { + type = "wallmounted", + wall_top = { -0.5, 0, -0.5, 0.5, 0.5, 0.5 }, + wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }, + wall_side = { -0.5, -0.5, -0.5, 0, 0.5, 0.5 }, + }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:color", { + description = S("Color Test Node"), + paramtype2 = "color", + palette = "testnodes_palette_full.png", + tiles = { + "testnodes_node.png", + }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:colorfacedir", { + description = S("Color Facedir Test Node"), + paramtype2 = "colorfacedir", + palette = "testnodes_palette_facedir.png", + tiles = { + "testnodes_1g.png", + "testnodes_2g.png", + "testnodes_3g.png", + "testnodes_4g.png", + "testnodes_5g.png", + "testnodes_6g.png", + }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:colorfacedir_nodebox", { + description = S("Color Facedir Nodebox Test Node"), + tiles = { + "testnodes_1g.png", + "testnodes_2g.png", + "testnodes_3g.png", + "testnodes_4g.png", + "testnodes_5g.png", + "testnodes_6g.png", + }, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "colorfacedir", + palette = "testnodes_palette_facedir.png", + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.2, 0.2, 0.2}, + }, + + groups = {dig_immediate=3}, +}) + +minetest.register_node("testnodes:colorwallmounted", { + description = S("Color Wallmounted Test Node"), + paramtype2 = "colorwallmounted", + paramtype = "light", + palette = "testnodes_palette_wallmounted.png", + tiles = { + "testnodes_1wg.png", + "testnodes_2wg.png", + "testnodes_3wg.png", + "testnodes_4wg.png", + "testnodes_5wg.png", + "testnodes_6wg.png", + }, + + groups = { dig_immediate = 3 }, +}) + +minetest.register_node("testnodes:colorwallmounted_nodebox", { + description = S("Color Wallmounted Nodebox Test Node"), + paramtype2 = "colorwallmounted", + paramtype = "light", + palette = "testnodes_palette_wallmounted.png", + tiles = { + "testnodes_1wg.png", + "testnodes_2wg.png", + "testnodes_3wg.png", + "testnodes_4wg.png", + "testnodes_5wg.png", + "testnodes_6wg.png", + }, + drawtype = "nodebox", + node_box = { + type = "wallmounted", + wall_top = { -0.5, 0, -0.5, 0.5, 0.5, 0.5 }, + wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }, + wall_side = { -0.5, -0.5, -0.5, 0, 0.5, 0.5 }, + }, + + groups = { dig_immediate = 3 }, +}) + diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua new file mode 100644 index 000000000..e169d4b08 --- /dev/null +++ b/games/devtest/mods/testnodes/properties.lua @@ -0,0 +1,270 @@ +-- Test Nodes: Node property tests + +local S = minetest.get_translator("testnodes") + +-- Is supposed to fall when it doesn't rest on solid ground +minetest.register_node("testnodes:falling", { + description = S("Falling Node"), + tiles = { + "testnodes_node.png", + "testnodes_node.png", + "testnodes_node_falling.png", + }, + groups = { falling_node = 1, dig_immediate = 3 }, +}) + +-- Same as falling node, but will stop falling on top of liquids +minetest.register_node("testnodes:falling_float", { + description = S("Falling+Floating Node"), + groups = { falling_node = 1, float = 1, dig_immediate = 3 }, + + + tiles = { + "testnodes_node.png", + "testnodes_node.png", + "testnodes_node_falling.png", + }, + color = "cyan", +}) + +-- This node attaches to the floor and drops as item +-- when the floor is gone. +minetest.register_node("testnodes:attached", { + description = S("Floor-Attached Node"), + tiles = { + "testnodes_attached_top.png", + "testnodes_attached_bottom.png", + "testnodes_attached_side.png", + }, + groups = { attached_node = 1, dig_immediate = 3 }, +}) + +-- This node attaches to the side of a node and drops as item +-- when the node it attaches to is gone. +minetest.register_node("testnodes:attached_wallmounted", { + description = S("Wallmounted Attached Node"), + paramtype2 = "wallmounted", + tiles = { + "testnodes_attachedw_top.png", + "testnodes_attachedw_bottom.png", + "testnodes_attachedw_side.png", + }, + groups = { attached_node = 1, dig_immediate = 3 }, +}) + +-- Jump disabled +minetest.register_node("testnodes:nojump", { + description = S("Non-jumping Node"), + groups = {disable_jump=1, dig_immediate=3}, + + + tiles = {"testnodes_nojump_top.png", "testnodes_nojump_side.png"}, +}) + +-- Climbable up and down with jump and sneak keys +minetest.register_node("testnodes:climbable", { + description = S("Climbable Node"), + climbable = true, + walkable = false, + + + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + tiles ={"testnodes_climbable_side.png"}, + drawtype = "glasslike", + groups = {dig_immediate=3}, +}) + +-- Climbable only downwards with sneak key +minetest.register_node("testnodes:climbable_nojump", { + description = S("Downwards-climbable Node"), + climbable = true, + walkable = false, + + groups = {disable_jump=1, dig_immediate=3}, + drawtype = "glasslike", + tiles ={"testnodes_climbable_nojump_side.png"}, + paramtype = "light", + sunlight_propagates = true, +}) + +-- A liquid in which you can't rise +minetest.register_node("testnodes:liquid_nojump", { + description = S("Non-jumping Liquid Source Node"), + liquidtype = "source", + liquid_range = 1, + liquid_viscosity = 0, + liquid_alternative_flowing = "testnodes:liquidflowing_nojump", + liquid_alternative_source = "testnodes:liquid_nojump", + liquid_renewable = false, + groups = {disable_jump=1, dig_immediate=3}, + walkable = false, + + drawtype = "liquid", + tiles = {"testnodes_liquidsource.png^[colorize:#FF0000:127"}, + special_tiles = { + {name = "testnodes_liquidsource.png^[colorize:#FF0000:127", backface_culling = false}, + {name = "testnodes_liquidsource.png^[colorize:#FF0000:127", backface_culling = true}, + }, + use_texture_alpha = true, + paramtype = "light", + pointable = false, + liquids_pointable = true, + diggable = false, + buildable_to = true, + is_ground_content = false, + post_effect_color = {a = 70, r = 255, g = 0, b = 200}, +}) + +-- A liquid in which you can't rise (flowing variant) +minetest.register_node("testnodes:liquidflowing_nojump", { + description = S("Non-jumping Flowing Liquid Node"), + liquidtype = "flowing", + liquid_range = 1, + liquid_viscosity = 0, + liquid_alternative_flowing = "testnodes:liquidflowing_nojump", + liquid_alternative_source = "testnodes:liquid_nojump", + liquid_renewable = false, + groups = {disable_jump=1, dig_immediate=3}, + walkable = false, + + + drawtype = "flowingliquid", + tiles = {"testnodes_liquidflowing.png^[colorize:#FF0000:127"}, + special_tiles = { + {name = "testnodes_liquidflowing.png^[colorize:#FF0000:127", backface_culling = false}, + {name = "testnodes_liquidflowing.png^[colorize:#FF0000:127", backface_culling = false}, + }, + use_texture_alpha = true, + paramtype = "light", + paramtype2 = "flowingliquid", + pointable = false, + liquids_pointable = true, + diggable = false, + buildable_to = true, + is_ground_content = false, + post_effect_color = {a = 70, r = 255, g = 0, b = 200}, +}) + +-- Nodes that modify fall damage (various damage modifiers) +for i=-100, 100, 25 do + if i ~= 0 then + local subname, descnum + if i < 0 then + subname = "m"..math.abs(i) + descnum = tostring(i) + else + subname = tostring(i) + descnum = S("+@1", i) + end + local tex, color, desc + if i > 0 then + local val = math.floor((i/100)*255) + tex = "testnodes_fall_damage_plus.png" + color = { b=0, g=255-val, r=255, a=255 } + desc = S("Fall Damage Node (+@1%)", i) + else + tex = "testnodes_fall_damage_minus.png" + if i == -100 then + color = { r=0, b=0, g=255, a=255 } + else + local val = math.floor((math.abs(i)/100)*255) + color = { r=0, b=255, g=255-val, a=255 } + end + desc = S("Fall Damage Node (-@1%)", math.abs(i)) + end + minetest.register_node("testnodes:damage"..subname, { + description = desc, + groups = {fall_damage_add_percent=i, dig_immediate=3}, + + + tiles = { tex }, + is_ground_content = false, + color = color, + }) + end +end + +-- Bouncy nodes (various bounce levels) +for i=20, 180, 20 do + local val = math.floor(((i-20)/200)*255) + minetest.register_node("testnodes:bouncy"..i, { + description = S("Bouncy Node (@1%)", i), + groups = {bouncy=i, dig_immediate=3}, + + + tiles ={"testnodes_bouncy.png"}, + is_ground_content = false, + color = { r=255, g=255-val, b=val, a=255 }, + }) +end + +-- Slippery nodes (various slippery levels) +for i=1, 5 do + minetest.register_node("testnodes:slippery"..i, { + description = S("Slippery Node (@1)", i), + tiles ={"testnodes_slippery.png"}, + is_ground_content = false, + groups = {slippery=i, dig_immediate=3}, + color = { r=0, g=255, b=math.floor((i/5)*255), a=255 }, + }) +end + +-- By placing something on the node, the node itself will be replaced +minetest.register_node("testnodes:buildable_to", { + description = S("Replacable Node"), + buildable_to = true, + tiles = {"testnodes_buildable_to.png"}, + is_ground_content = false, + groups = {dig_immediate=3}, +}) + +-- Nodes that deal damage to players that are inside them. +-- Negative damage nodes should heal. +for d=-3,3 do + if d ~= 0 then + local sub, tile + if d > 0 then + sub = tostring(d) + tile = "testnodes_damage.png" + else + sub = "m" .. tostring(math.abs(d)) + tile = "testnodes_damage_neg.png" + end + if math.abs(d) == 2 then + tile = tile .. "^[colorize:#000000:70" + elseif math.abs(d) == 3 then + tile = tile .. "^[colorize:#000000:140" + end + minetest.register_node("testnodes:damage_"..sub, { + description = S("Damage Node (@1 damage per second)", d), + damage_per_second = d, + + + walkable = false, + is_ground_content = false, + drawtype = "allfaces", + paramtype = "light", + sunlight_propagates = true, + tiles = { tile }, + groups = {dig_immediate=3}, + }) + end +end + +-- Causes drowning damage +minetest.register_node("testnodes:drowning_1", { + description = S("Drowning Node (@1 damage)", 1), + drowning = 1, + + + walkable = false, + is_ground_content = false, + drawtype = "allfaces", + paramtype = "light", + sunlight_propagates = true, + tiles = { "testnodes_drowning.png" }, + groups = {dig_immediate=3}, +}) + diff --git a/games/devtest/mods/testnodes/settingtypes.txt b/games/devtest/mods/testnodes/settingtypes.txt new file mode 100644 index 000000000..7f753bf3e --- /dev/null +++ b/games/devtest/mods/testnodes/settingtypes.txt @@ -0,0 +1,4 @@ +# If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. +# This is due to . +# This is only added to make the items more visible to avoid confusion, but you will no longer see the default inventory images for these items. When you want to test the default inventory image of drawtypes, this should be turned off. +testnodes_show_fallback_image (Use fallback inventory images) bool false diff --git a/games/devtest/mods/testnodes/textures.lua b/games/devtest/mods/testnodes/textures.lua new file mode 100644 index 000000000..f5db9ccbf --- /dev/null +++ b/games/devtest/mods/testnodes/textures.lua @@ -0,0 +1,67 @@ +-- Node texture tests + +local S = minetest.get_translator("testnodes") + +minetest.register_node("testnodes:6sides", { + description = S("Six Textures Test Node"), + tiles = { + "testnodes_normal1.png", + "testnodes_normal2.png", + "testnodes_normal3.png", + "testnodes_normal4.png", + "testnodes_normal5.png", + "testnodes_normal6.png", + }, + + groups = { dig_immediate = 2 }, +}) + +minetest.register_node("testnodes:anim", { + description = S("Animated Test Node"), + tiles = { + { name = "testnodes_anim.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 4.0, + }, }, + }, + + groups = { dig_immediate = 2 }, +}) + +-- Node texture transparency test + +local alphas = { 64, 128, 191 } + +for a=1,#alphas do + local alpha = alphas[a] + + -- Transparency taken from texture + minetest.register_node("testnodes:alpha_texture_"..alpha, { + description = S("Texture Alpha Test Node (@1)", alpha), + drawtype = "glasslike", + paramtype = "light", + tiles = { + "testnodes_alpha"..alpha..".png", + }, + use_texture_alpha = true, + + groups = { dig_immediate = 3 }, + }) + + -- Transparency set via "alpha" parameter + minetest.register_node("testnodes:alpha_"..alpha, { + description = S("Alpha Test Node (@1)", alpha), + -- It seems that only the liquid drawtype supports the alpha parameter + drawtype = "liquid", + paramtype = "light", + tiles = { + "testnodes_alpha.png", + }, + alpha = alpha, + + groups = { dig_immediate = 3 }, + }) +end diff --git a/games/devtest/mods/testnodes/textures/testnodes_1.png b/games/devtest/mods/testnodes/textures/testnodes_1.png new file mode 100644 index 000000000..6730997e2 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_1.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_1g.png b/games/devtest/mods/testnodes/textures/testnodes_1g.png new file mode 100644 index 000000000..529298ece Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_1g.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_1w.png b/games/devtest/mods/testnodes/textures/testnodes_1w.png new file mode 100644 index 000000000..d24e571cc Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_1w.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_1wg.png b/games/devtest/mods/testnodes/textures/testnodes_1wg.png new file mode 100644 index 000000000..b2eba0e9a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_1wg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_2.png b/games/devtest/mods/testnodes/textures/testnodes_2.png new file mode 100644 index 000000000..6c87c868d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_2g.png b/games/devtest/mods/testnodes/textures/testnodes_2g.png new file mode 100644 index 000000000..cb9060f7b Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_2g.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_2w.png b/games/devtest/mods/testnodes/textures/testnodes_2w.png new file mode 100644 index 000000000..b56874ee1 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_2w.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_2wg.png b/games/devtest/mods/testnodes/textures/testnodes_2wg.png new file mode 100644 index 000000000..108dc87bb Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_2wg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_3.png b/games/devtest/mods/testnodes/textures/testnodes_3.png new file mode 100644 index 000000000..05b45629a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_3.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_3g.png b/games/devtest/mods/testnodes/textures/testnodes_3g.png new file mode 100644 index 000000000..5c84f5882 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_3g.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_3w.png b/games/devtest/mods/testnodes/textures/testnodes_3w.png new file mode 100644 index 000000000..8b435cf01 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_3w.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_3wg.png b/games/devtest/mods/testnodes/textures/testnodes_3wg.png new file mode 100644 index 000000000..9ee900667 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_3wg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_4.png b/games/devtest/mods/testnodes/textures/testnodes_4.png new file mode 100644 index 000000000..15e6ffec7 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_4.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_4g.png b/games/devtest/mods/testnodes/textures/testnodes_4g.png new file mode 100644 index 000000000..8f144fae0 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_4g.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_4w.png b/games/devtest/mods/testnodes/textures/testnodes_4w.png new file mode 100644 index 000000000..214e0df9d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_4w.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_4wg.png b/games/devtest/mods/testnodes/textures/testnodes_4wg.png new file mode 100644 index 000000000..888b3d482 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_4wg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_5.png b/games/devtest/mods/testnodes/textures/testnodes_5.png new file mode 100644 index 000000000..1ef1c728c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_5.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_5g.png b/games/devtest/mods/testnodes/textures/testnodes_5g.png new file mode 100644 index 000000000..30da4793a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_5g.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_5w.png b/games/devtest/mods/testnodes/textures/testnodes_5w.png new file mode 100644 index 000000000..b4cb42426 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_5w.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_5wg.png b/games/devtest/mods/testnodes/textures/testnodes_5wg.png new file mode 100644 index 000000000..fac9db28e Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_5wg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_6.png b/games/devtest/mods/testnodes/textures/testnodes_6.png new file mode 100644 index 000000000..805813e57 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_6.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_6g.png b/games/devtest/mods/testnodes/textures/testnodes_6g.png new file mode 100644 index 000000000..a88f4c9f8 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_6g.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_6w.png b/games/devtest/mods/testnodes/textures/testnodes_6w.png new file mode 100644 index 000000000..e6bbf97d9 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_6w.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_6wg.png b/games/devtest/mods/testnodes/textures/testnodes_6wg.png new file mode 100644 index 000000000..29ca933e0 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_6wg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_airlike.png b/games/devtest/mods/testnodes/textures/testnodes_airlike.png new file mode 100644 index 000000000..5a5664a2a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_airlike.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_allfaces.png b/games/devtest/mods/testnodes/textures/testnodes_allfaces.png new file mode 100644 index 000000000..c0a7dc550 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_allfaces.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_allfaces_optional.png b/games/devtest/mods/testnodes/textures/testnodes_allfaces_optional.png new file mode 100644 index 000000000..1f6a17313 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_allfaces_optional.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_alpha.png b/games/devtest/mods/testnodes/textures/testnodes_alpha.png new file mode 100644 index 000000000..157fa7386 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_alpha.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_alpha128.png b/games/devtest/mods/testnodes/textures/testnodes_alpha128.png new file mode 100644 index 000000000..16babf6c7 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_alpha128.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_alpha191.png b/games/devtest/mods/testnodes/textures/testnodes_alpha191.png new file mode 100644 index 000000000..f165d2887 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_alpha191.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_alpha64.png b/games/devtest/mods/testnodes/textures/testnodes_alpha64.png new file mode 100644 index 000000000..c343c32c3 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_alpha64.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_anim.png b/games/devtest/mods/testnodes/textures/testnodes_anim.png new file mode 100644 index 000000000..d321fe857 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_anim.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_attached_bottom.png b/games/devtest/mods/testnodes/textures/testnodes_attached_bottom.png new file mode 100644 index 000000000..e01ae576f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_attached_bottom.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_attached_side.png b/games/devtest/mods/testnodes/textures/testnodes_attached_side.png new file mode 100644 index 000000000..9459cbb05 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_attached_side.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_attached_top.png b/games/devtest/mods/testnodes/textures/testnodes_attached_top.png new file mode 100644 index 000000000..0148b41e0 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_attached_top.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_attachedw_bottom.png b/games/devtest/mods/testnodes/textures/testnodes_attachedw_bottom.png new file mode 100644 index 000000000..488ad23a9 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_attachedw_bottom.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_attachedw_side.png b/games/devtest/mods/testnodes/textures/testnodes_attachedw_side.png new file mode 100644 index 000000000..a02facbc7 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_attachedw_side.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_attachedw_top.png b/games/devtest/mods/testnodes/textures/testnodes_attachedw_top.png new file mode 100644 index 000000000..1f4fc7b85 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_attachedw_top.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_bouncy.png b/games/devtest/mods/testnodes/textures/testnodes_bouncy.png new file mode 100644 index 000000000..eabbbdfe4 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_bouncy.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_buildable_to.png b/games/devtest/mods/testnodes/textures/testnodes_buildable_to.png new file mode 100644 index 000000000..23b5e54d2 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_buildable_to.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_climbable_nojump_side.png b/games/devtest/mods/testnodes/textures/testnodes_climbable_nojump_side.png new file mode 100644 index 000000000..d5ca13033 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_climbable_nojump_side.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_climbable_side.png b/games/devtest/mods/testnodes/textures/testnodes_climbable_side.png new file mode 100644 index 000000000..c56ea90d7 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_climbable_side.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_damage.png b/games/devtest/mods/testnodes/textures/testnodes_damage.png new file mode 100644 index 000000000..9de2ab5e8 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_damage.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_damage_neg.png b/games/devtest/mods/testnodes/textures/testnodes_damage_neg.png new file mode 100644 index 000000000..85811bc8e Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_damage_neg.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_drowning.png b/games/devtest/mods/testnodes/textures/testnodes_drowning.png new file mode 100644 index 000000000..57ffc8fcf Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_drowning.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_fall_damage_minus.png b/games/devtest/mods/testnodes/textures/testnodes_fall_damage_minus.png new file mode 100644 index 000000000..88d3bdf58 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_fall_damage_minus.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_fall_damage_plus.png b/games/devtest/mods/testnodes/textures/testnodes_fall_damage_plus.png new file mode 100644 index 000000000..61fdec2e3 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_fall_damage_plus.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_fencelike.png b/games/devtest/mods/testnodes/textures/testnodes_fencelike.png new file mode 100644 index 000000000..84dea1b7c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_fencelike.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_firelike.png b/games/devtest/mods/testnodes/textures/testnodes_firelike.png new file mode 100644 index 000000000..ee59b0db1 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_firelike.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_glasslike.png b/games/devtest/mods/testnodes/textures/testnodes_glasslike.png new file mode 100644 index 000000000..cf3e35414 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_glasslike.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_glasslike_detail.png b/games/devtest/mods/testnodes/textures/testnodes_glasslike_detail.png new file mode 100644 index 000000000..30c9586e8 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_glasslike_detail.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed.png b/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed.png new file mode 100644 index 000000000..8a513f21c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed2.png b/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed2.png new file mode 100644 index 000000000..4ea839c8b Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed_optional.png b/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed_optional.png new file mode 100644 index 000000000..37de77dd1 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_glasslike_framed_optional.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_glasslikeliquid.png b/games/devtest/mods/testnodes/textures/testnodes_glasslikeliquid.png new file mode 100644 index 000000000..e1e96ffb9 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_glasslikeliquid.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light.png b/games/devtest/mods/testnodes/textures/testnodes_light.png new file mode 100644 index 000000000..4ba0081c3 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_1.png b/games/devtest/mods/testnodes/textures/testnodes_light_1.png new file mode 100644 index 000000000..57adf5a4a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_1.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_10.png b/games/devtest/mods/testnodes/textures/testnodes_light_10.png new file mode 100644 index 000000000..483834770 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_10.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_11.png b/games/devtest/mods/testnodes/textures/testnodes_light_11.png new file mode 100644 index 000000000..4c423d9b4 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_11.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_12.png b/games/devtest/mods/testnodes/textures/testnodes_light_12.png new file mode 100644 index 000000000..bc7946d09 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_12.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_13.png b/games/devtest/mods/testnodes/textures/testnodes_light_13.png new file mode 100644 index 000000000..0b63c84a6 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_13.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_14.png b/games/devtest/mods/testnodes/textures/testnodes_light_14.png new file mode 100644 index 000000000..a817bd394 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_14.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_2.png b/games/devtest/mods/testnodes/textures/testnodes_light_2.png new file mode 100644 index 000000000..852eaeff1 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_3.png b/games/devtest/mods/testnodes/textures/testnodes_light_3.png new file mode 100644 index 000000000..79fc834cc Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_3.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_4.png b/games/devtest/mods/testnodes/textures/testnodes_light_4.png new file mode 100644 index 000000000..75f8c6136 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_4.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_5.png b/games/devtest/mods/testnodes/textures/testnodes_light_5.png new file mode 100644 index 000000000..b6eede0ae Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_5.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_6.png b/games/devtest/mods/testnodes/textures/testnodes_light_6.png new file mode 100644 index 000000000..ef54addec Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_6.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_7.png b/games/devtest/mods/testnodes/textures/testnodes_light_7.png new file mode 100644 index 000000000..4a885b0f6 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_7.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_8.png b/games/devtest/mods/testnodes/textures/testnodes_light_8.png new file mode 100644 index 000000000..b283301e3 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_8.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_light_9.png b/games/devtest/mods/testnodes/textures/testnodes_light_9.png new file mode 100644 index 000000000..2aa902358 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_light_9.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_line_crossing.png b/games/devtest/mods/testnodes/textures/testnodes_line_crossing.png new file mode 100644 index 000000000..e566f2793 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_line_crossing.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_line_curved.png b/games/devtest/mods/testnodes/textures/testnodes_line_curved.png new file mode 100644 index 000000000..ab9f8e720 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_line_curved.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_line_straight.png b/games/devtest/mods/testnodes/textures/testnodes_line_straight.png new file mode 100644 index 000000000..4f33d9c6d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_line_straight.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_line_t_junction.png b/games/devtest/mods/testnodes/textures/testnodes_line_t_junction.png new file mode 100644 index 000000000..5668f6ea3 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_line_t_junction.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquid.png b/games/devtest/mods/testnodes/textures/testnodes_liquid.png new file mode 100644 index 000000000..98ab270c2 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquid.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing.png new file mode 100644 index 000000000..1736b89ba Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r0.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r0.png new file mode 100644 index 000000000..e8a61039d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r0.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r1.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r1.png new file mode 100644 index 000000000..b4e45b42f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r1.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r2.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r2.png new file mode 100644 index 000000000..e064b8f2d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r3.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r3.png new file mode 100644 index 000000000..bef773968 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r3.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r4.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r4.png new file mode 100644 index 000000000..de1001b2d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r4.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r5.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r5.png new file mode 100644 index 000000000..97b422e9a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r5.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r6.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r6.png new file mode 100644 index 000000000..4cd8e4e8e Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r6.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r7.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r7.png new file mode 100644 index 000000000..711dd961c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r7.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r8.png b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r8.png new file mode 100644 index 000000000..9cf22b8ca Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidflowing_r8.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource.png new file mode 100644 index 000000000..b3f29b702 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r0.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r0.png new file mode 100644 index 000000000..da0a99623 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r0.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r1.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r1.png new file mode 100644 index 000000000..66bf2be8f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r1.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r2.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r2.png new file mode 100644 index 000000000..fc5f65cb6 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r3.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r3.png new file mode 100644 index 000000000..0f46e291e Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r3.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r4.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r4.png new file mode 100644 index 000000000..0693a04d7 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r4.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r5.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r5.png new file mode 100644 index 000000000..cc9d03992 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r5.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r6.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r6.png new file mode 100644 index 000000000..e276a07ae Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r6.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r7.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r7.png new file mode 100644 index 000000000..3534a4b15 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r7.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r8.png b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r8.png new file mode 100644 index 000000000..ee1a8b169 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_liquidsource_r8.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes.png b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes.png new file mode 100644 index 000000000..51b8e0025 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes2.png b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes2.png new file mode 100644 index 000000000..9ea65c1ec Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes3.png b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes3.png new file mode 100644 index 000000000..96bc55ac5 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes3.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes4.png b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes4.png new file mode 100644 index 000000000..fca33727d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_mesh_stripes4.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_node.png b/games/devtest/mods/testnodes/textures/testnodes_node.png new file mode 100644 index 000000000..145099b3a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_node.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_node_falling.png b/games/devtest/mods/testnodes/textures/testnodes_node_falling.png new file mode 100644 index 000000000..44153185c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_node_falling.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_nodebox.png b/games/devtest/mods/testnodes/textures/testnodes_nodebox.png new file mode 100644 index 000000000..66e8dd663 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_nodebox.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_nojump_side.png b/games/devtest/mods/testnodes/textures/testnodes_nojump_side.png new file mode 100644 index 000000000..6a64cfff0 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_nojump_side.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_nojump_top.png b/games/devtest/mods/testnodes/textures/testnodes_nojump_top.png new file mode 100644 index 000000000..fe770838f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_nojump_top.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal.png b/games/devtest/mods/testnodes/textures/testnodes_normal.png new file mode 100644 index 000000000..a1acfd9fd Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal1.png b/games/devtest/mods/testnodes/textures/testnodes_normal1.png new file mode 100644 index 000000000..edaba77e4 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal1.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal2.png b/games/devtest/mods/testnodes/textures/testnodes_normal2.png new file mode 100644 index 000000000..0080a9ee7 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal2.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal3.png b/games/devtest/mods/testnodes/textures/testnodes_normal3.png new file mode 100644 index 000000000..0426ab216 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal3.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal4.png b/games/devtest/mods/testnodes/textures/testnodes_normal4.png new file mode 100644 index 000000000..0d1922eb6 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal4.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal5.png b/games/devtest/mods/testnodes/textures/testnodes_normal5.png new file mode 100644 index 000000000..0b7dcd2da Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal5.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_normal6.png b/games/devtest/mods/testnodes/textures/testnodes_normal6.png new file mode 100644 index 000000000..f34a67d71 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_normal6.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_palette_facedir.png b/games/devtest/mods/testnodes/textures/testnodes_palette_facedir.png new file mode 100644 index 000000000..8cf47bbbe Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_palette_facedir.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_palette_full.png b/games/devtest/mods/testnodes/textures/testnodes_palette_full.png new file mode 100644 index 000000000..e0a5f8b34 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_palette_full.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_palette_wallmounted.png b/games/devtest/mods/testnodes/textures/testnodes_palette_wallmounted.png new file mode 100644 index 000000000..682f3ac84 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_palette_wallmounted.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike.png new file mode 100644 index 000000000..cc464444d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_degrotate.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_degrotate.png new file mode 100644 index 000000000..01c81da8e Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_degrotate.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_leveled.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_leveled.png new file mode 100644 index 000000000..53504dbcd Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_leveled.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_meshoptions.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_meshoptions.png new file mode 100644 index 000000000..d504d459f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_meshoptions.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted.png new file mode 100644 index 000000000..79cf2125e Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base.png new file mode 100644 index 000000000..b9ee9e5be Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png new file mode 100644 index 000000000..85311cb2c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png new file mode 100644 index 000000000..bc602bafe Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png new file mode 100644 index 000000000..d10002375 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png new file mode 100644 index 000000000..527817bc1 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png new file mode 100644 index 000000000..45e75bdd3 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png new file mode 100644 index 000000000..8954b2c34 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png new file mode 100644 index 000000000..a782d4874 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png new file mode 100644 index 000000000..112a0540f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_plantlike_waving.png b/games/devtest/mods/testnodes/textures/testnodes_plantlike_waving.png new file mode 100644 index 000000000..b584a8dc9 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_plantlike_waving.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail2_crossing.png b/games/devtest/mods/testnodes/textures/testnodes_rail2_crossing.png new file mode 100644 index 000000000..530bbba7a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail2_crossing.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail2_curved.png b/games/devtest/mods/testnodes/textures/testnodes_rail2_curved.png new file mode 100644 index 000000000..4ed1ca00f Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail2_curved.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail2_straight.png b/games/devtest/mods/testnodes/textures/testnodes_rail2_straight.png new file mode 100644 index 000000000..8749330d8 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail2_straight.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail2_t_junction.png b/games/devtest/mods/testnodes/textures/testnodes_rail2_t_junction.png new file mode 100644 index 000000000..0517f6570 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail2_t_junction.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail_crossing.png b/games/devtest/mods/testnodes/textures/testnodes_rail_crossing.png new file mode 100644 index 000000000..3916ce1ef Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail_crossing.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail_curved.png b/games/devtest/mods/testnodes/textures/testnodes_rail_curved.png new file mode 100644 index 000000000..e44419848 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail_curved.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail_straight.png b/games/devtest/mods/testnodes/textures/testnodes_rail_straight.png new file mode 100644 index 000000000..872d04fb9 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail_straight.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_rail_t_junction.png b/games/devtest/mods/testnodes/textures/testnodes_rail_t_junction.png new file mode 100644 index 000000000..7e4af5182 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_rail_t_junction.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_signlike.png b/games/devtest/mods/testnodes/textures/testnodes_signlike.png new file mode 100644 index 000000000..33ffcba6c Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_signlike.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_slippery.png b/games/devtest/mods/testnodes/textures/testnodes_slippery.png new file mode 100644 index 000000000..b990468a1 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_slippery.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_street_crossing.png b/games/devtest/mods/testnodes/textures/testnodes_street_crossing.png new file mode 100644 index 000000000..d6e35ad7a Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_street_crossing.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_street_curved.png b/games/devtest/mods/testnodes/textures/testnodes_street_curved.png new file mode 100644 index 000000000..251b7fb71 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_street_curved.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_street_straight.png b/games/devtest/mods/testnodes/textures/testnodes_street_straight.png new file mode 100644 index 000000000..639e24b93 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_street_straight.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_street_t_junction.png b/games/devtest/mods/testnodes/textures/testnodes_street_t_junction.png new file mode 100644 index 000000000..713621e06 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_street_t_junction.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_sunlight_filter.png b/games/devtest/mods/testnodes/textures/testnodes_sunlight_filter.png new file mode 100644 index 000000000..b38ea4072 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_sunlight_filter.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_torchlike_ceiling.png b/games/devtest/mods/testnodes/textures/testnodes_torchlike_ceiling.png new file mode 100644 index 000000000..5d9862cc9 Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_torchlike_ceiling.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_torchlike_floor.png b/games/devtest/mods/testnodes/textures/testnodes_torchlike_floor.png new file mode 100644 index 000000000..adf1e002d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_torchlike_floor.png differ diff --git a/games/devtest/mods/testnodes/textures/testnodes_torchlike_wall.png b/games/devtest/mods/testnodes/textures/testnodes_torchlike_wall.png new file mode 100644 index 000000000..cb442b22d Binary files /dev/null and b/games/devtest/mods/testnodes/textures/testnodes_torchlike_wall.png differ diff --git a/games/devtest/mods/testpathfinder/README.md b/games/devtest/mods/testpathfinder/README.md new file mode 100644 index 000000000..2b9d46e70 --- /dev/null +++ b/games/devtest/mods/testpathfinder/README.md @@ -0,0 +1,15 @@ +# Pathfinder Tester + +Usage: + +Use the Pathfinder Tester tool (`testpathfinder:testpathfinder`). +Here's how it works: + +* Place on node: Set destination position +* Punch: Find path +* Sneak+punch: Select pathfinding algorithm + +Information will be shown in chat. If a path was found, all waypoints +will be shown for a few seconds. + +See `init.lua` for config variables. diff --git a/games/devtest/mods/testpathfinder/init.lua b/games/devtest/mods/testpathfinder/init.lua new file mode 100644 index 000000000..f94848236 --- /dev/null +++ b/games/devtest/mods/testpathfinder/init.lua @@ -0,0 +1,132 @@ +local S = minetest.get_translator("testpathfinder") + +-- Config parameters + +-- Maximum direct distance between start and end +local MAX_DIRECT_DISTANCE = 64 +-- Maximum search distance +local MAX_SEARCH_DISTANCE = 32 +-- Maximum permitted jump height +local MAX_JUMP = 1 +-- Maximum permitted drop height +local MAX_DROP = 5 +-- If true, mod won't refuse to run pathfinder even at long distances +local IGNORE_MAX_DISTANCE_SAFEGUARD = false + +-- End of config parameters + +local timer = 0 +local algorithms = { + "A*_noprefetch", + "A*", + "Dijkstra", +} + +local function find_path_for_player(player, itemstack) + local meta = itemstack:get_meta() + if not meta then + return + end + local x = meta:get_int("pos_x") + local y = meta:get_int("pos_y") + local z = meta:get_int("pos_z") + local algo = meta:get_int("algorithm") + if x and y and z then + local pos2 = {x=x, y=y, z=z} + algo = algorithms[algo+1] + local pos1 = vector.round(player:get_pos()) + -- Don't bother calling pathfinder for high distance to avoid freezing + if (not IGNORE_MAX_DISTANCE_SAFEGUARD) and (vector.distance(pos1, pos2) > MAX_DIRECT_DISTANCE) then + minetest.chat_send_player(player:get_player_name(), S("Destination too far away! Set a destination (via placing) within a distance of @1 and try again!", MAX_DIRECT_DISTANCE)) + return + end + local str = S("Path from @1 to @2:", + minetest.pos_to_string(pos1), + minetest.pos_to_string(pos2)) + + minetest.chat_send_player(player:get_player_name(), str) + local time_start = minetest.get_us_time() + local path = minetest.find_path(pos1, pos2, MAX_SEARCH_DISTANCE, MAX_JUMP, MAX_DROP, algo) + local time_end = minetest.get_us_time() + local time_diff = time_end - time_start + str = "" + if not path then + minetest.chat_send_player(player:get_player_name(), S("No path!")) + minetest.chat_send_player(player:get_player_name(), S("Time: @1 ms", time_diff/1000)) + return + end + for s=1, #path do + str = str .. minetest.pos_to_string(path[s]) .. "\n" + local t + if s == #path then + t = "testpathfinder_waypoint_end.png" + elseif s == 1 then + t = "testpathfinder_waypoint_start.png" + else + local c = math.floor(((#path-s)/#path)*255) + t = string.format("testpathfinder_waypoint.png^[multiply:#%02x%02x00", 0xFF-c, c) + end + minetest.add_particle({ + pos = path[s], + expirationtime = 5 + 0.2 * s, + playername = player:get_player_name(), + glow = minetest.LIGHT_MAX, + texture = t, + size = 3, + }) + end + minetest.chat_send_player(player:get_player_name(), str) + minetest.chat_send_player(player:get_player_name(), S("Path length: @1", #path)) + minetest.chat_send_player(player:get_player_name(), S("Time: @1 ms", time_diff/1000)) + end +end + +local function set_destination(itemstack, user, pointed_thing) + if not (user and user:is_player()) then + return + end + local name = user:get_player_name() + local obj + local meta = itemstack:get_meta() + if pointed_thing.type == "node" then + local pos = pointed_thing.above + meta:set_int("pos_x", pos.x) + meta:set_int("pos_y", pos.y) + meta:set_int("pos_z", pos.z) + minetest.chat_send_player(user:get_player_name(), S("Destination set to @1", minetest.pos_to_string(pos))) + return itemstack + end +end + +local function find_path_or_set_algorithm(itemstack, user, pointed_thing) + if not (user and user:is_player()) then + return + end + local ctrl = user:get_player_control() + -- No sneak: Find path + if not ctrl.sneak then + find_path_for_player(user, itemstack) + else + -- Sneak: Set algorithm + local meta = itemstack:get_meta() + local algo = meta:get_int("algorithm") + algo = (algo + 1) % #algorithms + meta:set_int("algorithm", algo) + minetest.chat_send_player(user:get_player_name(), S("Algorithm: @1", algorithms[algo+1])) + return itemstack + end +end + +-- Punch: Find path +-- Sneak+punch: Select pathfinding algorithm +-- Place: Select destination node +minetest.register_tool("testpathfinder:testpathfinder", { + description = S("Pathfinder Tester"), + inventory_image = "testpathfinder_testpathfinder.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = find_path_or_set_algorithm, + on_secondary_use = set_destination, + on_place = set_destination, +}) + + diff --git a/games/devtest/mods/testpathfinder/mod.conf b/games/devtest/mods/testpathfinder/mod.conf new file mode 100644 index 000000000..e6034ae8c --- /dev/null +++ b/games/devtest/mods/testpathfinder/mod.conf @@ -0,0 +1,2 @@ +name = testpathfinder +description = Tool to test Minetest's pathfinder function diff --git a/games/devtest/mods/testpathfinder/textures/testpathfinder_testpathfinder.png b/games/devtest/mods/testpathfinder/textures/testpathfinder_testpathfinder.png new file mode 100644 index 000000000..37eef0565 Binary files /dev/null and b/games/devtest/mods/testpathfinder/textures/testpathfinder_testpathfinder.png differ diff --git a/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint.png b/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint.png new file mode 100644 index 000000000..661dcf906 Binary files /dev/null and b/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint.png differ diff --git a/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_end.png b/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_end.png new file mode 100644 index 000000000..41a1cc549 Binary files /dev/null and b/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_end.png differ diff --git a/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_start.png b/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_start.png new file mode 100644 index 000000000..a22e31c3b Binary files /dev/null and b/games/devtest/mods/testpathfinder/textures/testpathfinder_waypoint_start.png differ diff --git a/games/devtest/mods/testtools/README.md b/games/devtest/mods/testtools/README.md new file mode 100644 index 000000000..9cfe29ea4 --- /dev/null +++ b/games/devtest/mods/testtools/README.md @@ -0,0 +1,99 @@ +# Test Tools readme + +Test Tools is a mod for developers that adds a bunch of tools to directly manipulate nodes and entities. This is great for quickly testing out stuff. + +Here's the list of tools: + +## Remover +Removes nodes and non-player entities that you punch. + +## Node Setter +Replace a node with another one. + +First, punch a node you want to remember. +Then rightclick any other node to replace it with the node you remembered. + +If you rightclick while pointing nothing, you can manually enter the node and param2. + +## Param2 Tool +Change the value param2 of nodes. + +* Punch: Add 1 to param2 +* Sneak+Punch: Add 8 to param2 +* Place: Subtract 1 from param2 +* Sneak+Place: Subtract 8 from param2 + +Note: Use the debug screen (F5) to see the param2 of the pointed node. + +## Falling Node Tool +Turns nodes into falling nodes. + +Usage: + +* Punch node: Make it fall +* Place: Try to teleport up to 2 units upwards, then make it fall + +## Entity Rotator +Changes the entity rotation (with `set_rotation`). + +Usage: + +* Punch entity: Rotate yaw +* Punch entity while holding down “Sneak” key: Rotate pitch +* Punch entity while holding down “Special” key (aka “Aux”): Rotate roll + +Each usage rotates the entity by 22.5°. + +## Entity Spawner +Spawns entities. + +Usage: + +* Punch to select entity or spawn one directly +* Place to place selected entity + +## Object Property Editor +Edits properties of objects. + +Usage: + +* Punch object to open a formspec that allows you to view and edit properties +* Punch air to edit properties of your own player object + +To edit a property, select it in the list, enter a new value (in Lua syntax) +and hit “Submit”. + +## Object Attacher +Allows you to attach an object to another one. + +Basic usage: +* First select the parent object, then the child object that should be attached +* Selecting an object is done by punching it +* Sneak+punch to detach selected object +* If you punch air, you select yourself + +Configuration: +* Place: Increase attachment Y position +* Sneak+place: decrease attachment Y position +* Aux+place: Increase attachment X rotation +* Aux+Sneak+Rightclick: Decrease attachment X rotation + +Hint: To detach all objects nearby you (including on yourself), use the +`/detach` server command. + +## Object Mover +Move an object by a given distance. + +Usage: +* Punch object into the direction you want to move it +* Sneak+punch: Move object towards you +* Place: Increase move distance +* Sneak+place: Decrease move distance + +## Entity Visual Scaler +Change visual size of entities + +Usage: + +* Punch entity to increase visual size +* Sneak+punch entity to decrease visual size diff --git a/games/devtest/mods/testtools/init.lua b/games/devtest/mods/testtools/init.lua new file mode 100644 index 000000000..a63c98377 --- /dev/null +++ b/games/devtest/mods/testtools/init.lua @@ -0,0 +1,691 @@ +local S = minetest.get_translator("testtools") +local F = minetest.formspec_escape + +-- TODO: Add a Node Metadata tool + +-- Param 2 Tool: Set param2 value of tools +-- Punch: +1 +-- Punch+Shift: +8 +-- Place: -1 +-- Place+Shift: -8 +minetest.register_tool("testtools:param2tool", { + description = S("Param2 Tool"), + inventory_image = "testtools_param2tool.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing) + if pointed_thing.type ~= "node" or (not pos) then + return + end + local add = 1 + if user then + local ctrl = user:get_player_control() + if ctrl.sneak then + add = 8 + end + end + local node = minetest.get_node(pos) + node.param2 = node.param2 + add + minetest.swap_node(pos, node) + end, + on_place = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing) + if pointed_thing.type ~= "node" or (not pos) then + return + end + local add = -1 + if user then + local ctrl = user:get_player_control() + if ctrl.sneak then + add = -8 + end + end + local node = minetest.get_node(pos) + node.param2 = node.param2 + add + minetest.swap_node(pos, node) + end, +}) + +minetest.register_tool("testtools:node_setter", { + description = S("Node Setter"), + inventory_image = "testtools_node_setter.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing) + if pointed_thing.type == "nothing" then + local meta = itemstack:get_meta() + meta:set_string("node", "air") + meta:set_int("node_param2", 0) + if user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), S("Now placing: @1 (param2=@2)", "air", 0)) + end + return itemstack + elseif pointed_thing.type ~= "node" or (not pos) then + return + end + local node = minetest.get_node(pos) + local meta = itemstack:get_meta() + meta:set_string("node", node.name) + meta:set_int("node_param2", node.param2) + if user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), S("Now placing: @1 (param2=@2)", node.name, node.param2)) + end + return itemstack + end, + on_secondary_use = function(itemstack, user, pointed_thing) + local meta = itemstack:get_meta() + local nodename = meta:get_string("node") or "" + local param2 = meta:get_int("node_param2") or 0 + + minetest.show_formspec(user:get_player_name(), "testtools:node_setter", + "size[4,4]".. + "field[0.5,1;3,1;nodename;"..F(S("Node name (itemstring):"))..";"..F(nodename).."]".. + "field[0.5,2;3,1;param2;"..F(S("param2:"))..";"..F(tostring(param2)).."]".. + "button_exit[0.5,3;3,1;submit;"..F(S("Submit")).."]" + ) + end, + on_place = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing) + local meta = itemstack:get_meta() + local nodename = meta:get_string("node") + if nodename == "" and user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), S("Punch a node first!")) + return + end + local param2 = meta:get_int("node_param2") + if not param2 then + param2 = 0 + end + local node = { name = nodename, param2 = param2 } + if not minetest.registered_nodes[nodename] then + minetest.chat_send_player(user:get_player_name(), S("Cannot set unknown node: @1", nodename)) + return + end + minetest.set_node(pos, node) + end, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "testtools:node_setter" then + local playername = player:get_player_name() + local witem = player:get_wielded_item() + if witem:get_name() == "testtools:node_setter" then + if fields.nodename and fields.param2 then + local param2 = tonumber(fields.param2) + if not param2 then + return + end + local meta = witem:get_meta() + meta:set_string("node", fields.nodename) + meta:set_int("node_param2", param2) + player:set_wielded_item(witem) + end + end + end +end) + +minetest.register_tool("testtools:remover", { + description = S("Remover"), + inventory_image = "testtools_remover.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing) + if pointed_thing.type == "node" and pos ~= nil then + minetest.remove_node(pos) + elseif pointed_thing.type == "object" then + local obj = pointed_thing.ref + if not obj:is_player() then + obj:remove() + end + end + end, +}) + +minetest.register_tool("testtools:falling_node_tool", { + description = S("Falling Node Tool"), + inventory_image = "testtools_falling_node_tool.png", + groups = { testtool = 1, disable_repair = 1 }, + on_place = function(itemstack, user, pointed_thing) + -- Teleport node 1-2 units upwards (if possible) and make it fall + local pos = minetest.get_pointed_thing_position(pointed_thing) + if pointed_thing.type ~= "node" or (not pos) then + return + end + local ok = false + local highest + for i=1,2 do + local above = {x=pos.x,y=pos.y+i,z=pos.z} + local n2 = minetest.get_node(above) + local def2 = minetest.registered_nodes[n2.name] + if def2 and (not def2.walkable) then + highest = above + else + break + end + end + if highest then + local node = minetest.get_node(pos) + local metatable = minetest.get_meta(pos):to_table() + minetest.remove_node(pos) + minetest.set_node(highest, node) + local meta_highest = minetest.get_meta(highest) + meta_highest:from_table(metatable) + ok = minetest.spawn_falling_node(highest) + else + ok = minetest.spawn_falling_node(pos) + end + if not ok and user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), S("Falling node could not be spawned!")) + end + end, + on_use = function(itemstack, user, pointed_thing) + local pos = minetest.get_pointed_thing_position(pointed_thing) + if pointed_thing.type ~= "node" or (not pos) then + return + end + local ok = minetest.spawn_falling_node(pos) + if not ok and user and user:is_player() then + minetest.chat_send_player(user:get_player_name(), S("Falling node could not be spawned!")) + end + end, +}) + +minetest.register_tool("testtools:rotator", { + description = S("Entity Rotator"), + inventory_image = "testtools_entity_rotator.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "object" then + return + end + local obj = pointed_thing.ref + if obj:is_player() then + -- No player rotation + return + else + local axis = "y" + if user and user:is_player() then + local ctrl = user:get_player_control() + if ctrl.sneak then + axis = "x" + elseif ctrl.aux1 then + axis = "z" + end + end + local rot = obj:get_rotation() + rot[axis] = rot[axis] + math.pi/8 + if rot[axis] > math.pi*2 then + rot[axis] = rot[axis] - math.pi*2 + end + obj:set_rotation(rot) + end + end, +}) + +local mover_config = function(itemstack, user, pointed_thing) + if not (user and user:is_player()) then + return + end + local name = user:get_player_name() + local ctrl = user:get_player_control() + local meta = itemstack:get_meta() + local dist = 1.0 + if meta:contains("distance") then + dist = meta:get_int("distance") + end + if ctrl.sneak then + dist = dist - 1 + else + dist = dist + 1 + end + meta:set_int("distance", dist) + minetest.chat_send_player(user:get_player_name(), S("distance=@1/10", dist*2)) + return itemstack +end + +minetest.register_tool("testtools:object_mover", { + description = S("Object Mover"), + inventory_image = "testtools_object_mover.png", + groups = { testtool = 1, disable_repair = 1 }, + on_place = mover_config, + on_secondary_use = mover_config, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "object" then + return + end + local obj = pointed_thing.ref + if not (user and user:is_player()) then + return + end + local yaw = user:get_look_horizontal() + local dir = minetest.yaw_to_dir(yaw) + local pos = obj:get_pos() + local pitch = user:get_look_vertical() + if pitch > 0.25 * math.pi then + dir.y = -1 + dir.x = 0 + dir.z = 0 + elseif pitch < -0.25 * math.pi then + dir.y = 1 + dir.x = 0 + dir.z = 0 + end + local ctrl = user:get_player_control() + if ctrl.sneak then + dir = vector.multiply(dir, -1) + end + local meta = itemstack:get_meta() + if meta:contains("distance") then + local dist = meta:get_int("distance") + dir = vector.multiply(dir, dist*0.2) + end + pos = vector.add(pos, dir) + obj:set_pos(pos) + end, +}) + + + +minetest.register_tool("testtools:entity_scaler", { + description = S("Entity Visual Scaler"), + inventory_image = "testtools_entity_scaler.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "object" then + return + end + local obj = pointed_thing.ref + if obj:is_player() then + -- No player scaling + return + else + local diff = 0.1 + if user and user:is_player() then + local ctrl = user:get_player_control() + if ctrl.sneak then + diff = -0.1 + end + end + local prop = obj:get_properties() + if not prop.visual_size then + prop.visual_size = { x=1, y=1, z=1 } + else + prop.visual_size = { x=prop.visual_size.x+diff, y=prop.visual_size.y+diff, z=prop.visual_size.z+diff } + if prop.visual_size.x <= 0.1 then + prop.visual_size.x = 0.1 + end + if prop.visual_size.y <= 0.1 then + prop.visual_size.y = 0.1 + end + if prop.visual_size.z <= 0.1 then + prop.visual_size.z = 0.1 + end + end + obj:set_properties(prop) + end + end, +}) + +local selections = {} +local entity_list +local function get_entity_list() + if entity_list then + return entity_list + end + local ents = minetest.registered_entities + local list = {} + for k,_ in pairs(ents) do + table.insert(list, k) + end + table.sort(list) + entity_list = list + return entity_list +end +minetest.register_tool("testtools:entity_spawner", { + description = S("Entity Spawner"), + inventory_image = "testtools_entity_spawner.png", + groups = { testtool = 1, disable_repair = 1 }, + on_place = function(itemstack, user, pointed_thing) + local name = user:get_player_name() + if selections[name] and pointed_thing.type == "node" then + local pos = pointed_thing.above + minetest.add_entity(pos, get_entity_list()[selections[name]]) + end + end, + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type == "object" then + return + end + if user and user:is_player() then + local list = table.concat(get_entity_list(), ",") + local name = user:get_player_name() + local sel = selections[name] or "" + minetest.show_formspec(name, "testtools:entity_list", + "size[9,9]".. + "textlist[0,0;9,8;entity_list;"..list..";"..sel..";false]".. + "button[0,8;4,1;spawn;Spawn entity]" + ) + end + end, +}) + +local function prop_to_string(property) + if type(property) == "string" then + return "\"" .. property .. "\"" + elseif type(property) == "table" then + return tostring(dump(property)):gsub("\n", "") + else + return tostring(property) + end +end + +local property_formspec_data = {} +local property_formspec_index = {} +local selected_objects = {} +local function get_object_properties_form(obj, playername) + if not playername then return "" end + local props = obj:get_properties() + local str = "" + property_formspec_data[playername] = {} + local proplist = {} + for k,_ in pairs(props) do + table.insert(proplist, k) + end + table.sort(proplist) + for p=1, #proplist do + local k = proplist[p] + local v = props[k] + local newline = "" + newline = k .. " = " + newline = newline .. prop_to_string(v) + str = str .. F(newline) + if p < #proplist then + str = str .. "," + end + table.insert(property_formspec_data[playername], k) + end + return str +end + +local editor_formspec_selindex = {} + +local editor_formspec = function(playername, obj, value, sel) + if not value then + value = "" + end + if not sel then + sel = "" + end + local list = get_object_properties_form(obj, playername) + local title + if obj:is_player() then + title = S("Object properties of player “@1”", obj:get_player_name()) + else + local ent = obj:get_luaentity() + title = S("Object properties of @1", ent.name) + end + minetest.show_formspec(playername, "testtools:object_editor", + "size[9,9]".. + "label[0,0;"..F(title).."]".. + "textlist[0,0.5;9,7.5;object_props;"..list..";"..sel..";false]".. + "field[0.2,8.75;8,1;value;"..F(S("Value"))..";"..F(value).."]".. + "button[8,8.5;1,1;submit;"..F(S("Submit")).."]" + ) +end + +minetest.register_tool("testtools:object_editor", { + description = S("Object Property Editor"), + inventory_image = "testtools_object_editor.png", + groups = { testtool = 1, disable_repair = 1 }, + on_use = function(itemstack, user, pointed_thing) + if user and user:is_player() then + local name = user:get_player_name() + + if pointed_thing.type == "object" then + selected_objects[name] = pointed_thing.ref + elseif pointed_thing.type == "nothing" then + -- Use on yourself if pointing nothing + selected_objects[name] = user + else + -- Unsupported pointed thing + return + end + + local sel = editor_formspec_selindex[name] + local val + if selected_objects[name] and selected_objects[name]:get_properties() then + local props = selected_objects[name]:get_properties() + local keys = property_formspec_data[name] + if property_formspec_index[name] and props then + local key = keys[property_formspec_index[name]] + val = prop_to_string(props[key]) + end + end + + editor_formspec(name, selected_objects[name], val, sel) + end + end, +}) + +local ent_parent = {} +local ent_child = {} +local DEFAULT_ATTACH_OFFSET_Y = 11 + +local attacher_config = function(itemstack, user, pointed_thing) + if not (user and user:is_player()) then + return + end + if pointed_thing.type == "object" then + return + end + local name = user:get_player_name() + local ctrl = user:get_player_control() + local meta = itemstack:get_meta() + if ctrl.aux1 then + local rot_x = meta:get_float("rot_x") + if ctrl.sneak then + rot_x = rot_x - math.pi/8 + else + rot_x = rot_x + math.pi/8 + end + if rot_x > 6.2 then + rot_x = 0 + elseif rot_x < 0 then + rot_x = math.pi * (15/8) + end + minetest.chat_send_player(name, S("rotation=@1", minetest.pos_to_string({x=rot_x,y=0,z=0}))) + meta:set_float("rot_x", rot_x) + else + local pos_y + if meta:contains("pos_y") then + pos_y = meta:get_int("pos_y") + else + pos_y = DEFAULT_ATTACH_OFFSET_Y + end + if ctrl.sneak then + pos_y = pos_y - 1 + else + pos_y = pos_y + 1 + end + minetest.chat_send_player(name, S("position=@1", minetest.pos_to_string({x=0,y=pos_y,z=0}))) + meta:set_int("pos_y", pos_y) + end + return itemstack +end + +minetest.register_tool("testtools:object_attacher", { + description = S("Object Attacher"), + inventory_image = "testtools_object_attacher.png", + groups = { testtool = 1, disable_repair = 1 }, + on_place = attacher_config, + on_secondary_use = attacher_config, + on_use = function(itemstack, user, pointed_thing) + if user and user:is_player() then + local name = user:get_player_name() + local selected_object + if pointed_thing.type == "object" then + selected_object = pointed_thing.ref + elseif pointed_thing.type == "nothing" then + selected_object = user + else + return + end + local ctrl = user:get_player_control() + if ctrl.sneak then + if selected_object:get_attach() then + selected_object:set_detach() + minetest.chat_send_player(name, S("Object detached!")) + else + minetest.chat_send_player(name, S("Object is not attached!")) + end + return + end + local parent = ent_parent[name] + local child = ent_child[name] + local ename = S("") + if not parent then + parent = selected_object + ent_parent[name] = parent + elseif not child then + child = selected_object + ent_child[name] = child + end + local entity = selected_object:get_luaentity() + if entity then + ename = entity.name + elseif selected_object:is_player() then + ename = selected_object:get_player_name() + end + if selected_object == parent then + minetest.chat_send_player(name, S("Parent object selected: @1", ename)) + elseif selected_object == child then + minetest.chat_send_player(name, S("Child object selected: @1", ename)) + end + if parent and child then + if parent == child then + minetest.chat_send_player(name, S("Can't attach an object to itself!")) + ent_parent[name] = nil + ent_child[name] = nil + return + end + local meta = itemstack:get_meta() + local y + if meta:contains("pos_y") then + y = meta:get_int("pos_y") + else + y = DEFAULT_ATTACH_OFFSET_Y + end + local rx = meta:get_float("rot_x") or 0 + local offset = {x=0,y=y,z=0} + local angle = {x=rx,y=0,z=0} + child:set_attach(parent, "", offset, angle) + local check_parent = child:get_attach() + if check_parent then + minetest.chat_send_player(name, S("Object attached! position=@1, rotation=@2", + minetest.pos_to_string(offset), minetest.pos_to_string(angle))) + else + minetest.chat_send_player(name, S("Attachment failed!")) + end + ent_parent[name] = nil + ent_child[name] = nil + end + end + end, +}) + +-- Use loadstring to parse param as a Lua value +local function use_loadstring(param, player) + -- For security reasons, require 'server' priv, just in case + -- someone is actually crazy enough to run this on a public server. + local privs = minetest.get_player_privs(player:get_player_name()) + if not privs.server then + return false, "You need 'server' privilege to change object properties!" + end + if not param then + return false, "Failed: parameter is nil" + end + --[[ DANGER ZONE ]] + -- Interpret string as Lua value + local func, errormsg = loadstring("return (" .. param .. ")") + if not func then + return false, "Failed: " .. errormsg + end + + -- Apply sandbox here using setfenv + setfenv(func, {}) + + -- Run it + local good, errOrResult = pcall(func) + if not good then + -- A Lua error was thrown + return false, "Failed: " .. errOrResult + end + + -- errOrResult will be the value + return true, errOrResult +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if not (player and player:is_player()) then + return + end + if formname == "testtools:entity_list" then + local name = player:get_player_name() + if fields.entity_list then + local expl = minetest.explode_textlist_event(fields.entity_list) + if expl.type == "DCL" then + local pos = vector.add(player:get_pos(), {x=0,y=1,z=0}) + selections[name] = expl.index + minetest.add_entity(pos, get_entity_list()[expl.index]) + return + elseif expl.type == "CHG" then + selections[name] = expl.index + return + end + elseif fields.spawn and selections[name] then + local pos = vector.add(player:get_pos(), {x=0,y=1,z=0}) + minetest.add_entity(pos, get_entity_list()[selections[name]]) + return + end + elseif formname == "testtools:object_editor" then + local name = player:get_player_name() + if fields.object_props then + local expl = minetest.explode_textlist_event(fields.object_props) + if expl.type == "DCL" or expl.type == "CHG" then + property_formspec_index[name] = expl.index + + local props = selected_objects[name]:get_properties() + local keys = property_formspec_data[name] + if (not property_formspec_index[name]) or (not props) then + return + end + local key = keys[property_formspec_index[name]] + editor_formspec_selindex[name] = expl.index + editor_formspec(name, selected_objects[name], prop_to_string(props[key]), expl.index) + return + end + end + if fields.submit then + local props = selected_objects[name]:get_properties() + local keys = property_formspec_data[name] + if (not property_formspec_index[name]) or (not props) then + return + end + local key = keys[property_formspec_index[name]] + if not key then + return + end + local success, str = use_loadstring(fields.value, player) + if success then + props[key] = str + else + minetest.chat_send_player(name, str) + return + end + selected_objects[name]:set_properties(props) + local sel = editor_formspec_selindex[name] + editor_formspec(name, selected_objects[name], prop_to_string(props[key]), sel) + return + end + end +end) diff --git a/games/devtest/mods/testtools/mod.conf b/games/devtest/mods/testtools/mod.conf new file mode 100644 index 000000000..cde1b2685 --- /dev/null +++ b/games/devtest/mods/testtools/mod.conf @@ -0,0 +1,2 @@ +name = testtools +description = Some tools to directly manipulate nodes and entities. Great for development and testing diff --git a/games/devtest/mods/testtools/textures/testtools_entity_rotator.png b/games/devtest/mods/testtools/textures/testtools_entity_rotator.png new file mode 100644 index 000000000..17ebb2d35 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_entity_rotator.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_entity_scaler.png b/games/devtest/mods/testtools/textures/testtools_entity_scaler.png new file mode 100644 index 000000000..4909c25b0 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_entity_scaler.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_entity_spawner.png b/games/devtest/mods/testtools/textures/testtools_entity_spawner.png new file mode 100644 index 000000000..6199e0145 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_entity_spawner.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_falling_node_tool.png b/games/devtest/mods/testtools/textures/testtools_falling_node_tool.png new file mode 100644 index 000000000..30099a7ef Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_falling_node_tool.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_node_setter.png b/games/devtest/mods/testtools/textures/testtools_node_setter.png new file mode 100644 index 000000000..8599438de Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_node_setter.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_object_attacher.png b/games/devtest/mods/testtools/textures/testtools_object_attacher.png new file mode 100644 index 000000000..4d9bf6fd1 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_object_attacher.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_object_editor.png b/games/devtest/mods/testtools/textures/testtools_object_editor.png new file mode 100644 index 000000000..d1ce9cecd Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_object_editor.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_object_mover.png b/games/devtest/mods/testtools/textures/testtools_object_mover.png new file mode 100644 index 000000000..8b14e9fb2 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_object_mover.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_param2tool.png b/games/devtest/mods/testtools/textures/testtools_param2tool.png new file mode 100644 index 000000000..dbc663575 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_param2tool.png differ diff --git a/games/devtest/mods/testtools/textures/testtools_remover.png b/games/devtest/mods/testtools/textures/testtools_remover.png new file mode 100644 index 000000000..73f14cd54 Binary files /dev/null and b/games/devtest/mods/testtools/textures/testtools_remover.png differ diff --git a/games/devtest/mods/tiled/init.lua b/games/devtest/mods/tiled/init.lua new file mode 100644 index 000000000..68ead8e3a --- /dev/null +++ b/games/devtest/mods/tiled/init.lua @@ -0,0 +1,33 @@ +minetest.register_node("tiled:tiled", { + description = "Tiled Node (world-aligned)", + tiles = {{ + name = "tiled_tiled.png", + align_style = "world", + scale = 8, + }}, + groups = {cracky=3}, +}) + +minetest.register_node("tiled:tiled_n", { + description = "Tiled Node (node-aligned)", + tiles = {{ + name = "tiled_tiled.png", + align_style = "node", + scale = 8, + }}, + groups = {cracky=3}, +}) + +stairs.register_stair_and_slab("tiled_n", "tiled:tiled", + {cracky=3}, + {{name="tiled_tiled.png", align_style="node", scale=8}}, + "Tiled Stair (node-aligned)", + "Tiled Slab (node-aligned)") + +stairs.register_stair_and_slab("tiled", "tiled:tiled", + {cracky=3}, + {{name="tiled_tiled.png", align_style="world", scale=8}}, + "Tiled Stair (world-aligned)", + "Tiled Slab (world-aligned)") + + diff --git a/games/devtest/mods/tiled/mod.conf b/games/devtest/mods/tiled/mod.conf new file mode 100644 index 000000000..78b19f93b --- /dev/null +++ b/games/devtest/mods/tiled/mod.conf @@ -0,0 +1,3 @@ +name = tiled +description = Add nodes with a special texture that spans multiple nodes (aka "world-aligned") +depends = stairs diff --git a/games/devtest/mods/tiled/textures/tiled_tiled.png b/games/devtest/mods/tiled/textures/tiled_tiled.png new file mode 100644 index 000000000..363a26487 Binary files /dev/null and b/games/devtest/mods/tiled/textures/tiled_tiled.png differ diff --git a/games/devtest/mods/unittests/crafting.lua b/games/devtest/mods/unittests/crafting.lua new file mode 100644 index 000000000..eff13ce09 --- /dev/null +++ b/games/devtest/mods/unittests/crafting.lua @@ -0,0 +1,120 @@ +-- Test minetest.clear_craft function +local function test_clear_craft() + minetest.log("info", "[unittests] Testing minetest.clear_craft") + -- Clearing by output + minetest.register_craft({ + output = "foo", + recipe = {{"bar"}} + }) + minetest.register_craft({ + output = "foo 4", + recipe = {{"foo", "bar"}} + }) + assert(#minetest.get_all_craft_recipes("foo") == 2) + minetest.clear_craft({output="foo"}) + assert(minetest.get_all_craft_recipes("foo") == nil) + -- Clearing by input + minetest.register_craft({ + output = "foo 4", + recipe = {{"foo", "bar"}} + }) + assert(#minetest.get_all_craft_recipes("foo") == 1) + minetest.clear_craft({recipe={{"foo", "bar"}}}) + assert(minetest.get_all_craft_recipes("foo") == nil) +end + +-- Test minetest.get_craft_result function +local function test_get_craft_result() + minetest.log("info", "[unittests] Testing minetest.get_craft_result") + + -- normal + local input = { + method = "normal", + width = 2, + items = {"", "unittests:coal_lump", "", "unittests:stick"} + } + minetest.log("info", "[unittests] torch crafting input: "..dump(input)) + local output, decremented_input = minetest.get_craft_result(input) + minetest.log("info", "[unittests] torch crafting output: "..dump(output)) + minetest.log("info", "[unittests] torch crafting decremented input: "..dump(decremented_input)) + assert(output.item) + minetest.log("info", "[unittests] torch crafting output.item:to_table(): "..dump(output.item:to_table())) + assert(output.item:get_name() == "unittests:torch") + assert(output.item:get_count() == 4) + + -- fuel + input = { + method = "fuel", + width = 1, + items = {"unittests:coal_lump"} + } + minetest.log("info", "[unittests] coal fuel input: "..dump(input)) + output, decremented_input = minetest.get_craft_result(input) + minetest.log("info", "[unittests] coal fuel output: "..dump(output)) + minetest.log("info", "[unittests] coal fuel decremented input: "..dump(decremented_input)) + assert(output.time) + assert(output.time > 0) + + -- cooking + input = { + method = "cooking", + width = 1, + items = {"unittests:iron_lump"} + } + minetest.log("info", "[unittests] iron lump cooking input: "..dump(output)) + output, decremented_input = minetest.get_craft_result(input) + minetest.log("info", "[unittests] iron lump cooking output: "..dump(output)) + minetest.log("info", "[unittests] iron lump cooking decremented input: "..dump(decremented_input)) + assert(output.time) + assert(output.time > 0) + assert(output.item) + minetest.log("info", "[unittests] iron lump cooking output.item:to_table(): "..dump(output.item:to_table())) + assert(output.item:get_name() == "unittests:steel_ingot") + assert(output.item:get_count() == 1) + + -- tool repair (repairable) + input = { + method = "normal", + width = 2, + -- Using a wear of 60000 + items = {"unittests:repairable_tool 1 60000", "unittests:repairable_tool 1 60000"} + } + minetest.log("info", "[unittests] repairable tool crafting input: "..dump(input)) + output, decremented_input = minetest.get_craft_result(input) + minetest.log("info", "[unittests] repairable tool crafting output: "..dump(output)) + minetest.log("info", "[unittests] repairable tool crafting decremented input: "..dump(decremented_input)) + assert(output.item) + minetest.log("info", "[unittests] repairable tool crafting output.item:to_table(): "..dump(output.item:to_table())) + assert(output.item:get_name() == "unittests:repairable_tool") + -- Test the wear value. + -- See src/craftdef.cpp in Minetest source code for the formula. The formula to calculate + -- the value 51187 is: + -- 65536 - ((65536-60000)+(65536-60000)) + floor(additonal_wear * 65536 + 0.5) = 51187 + -- where additional_wear = 0.05 + assert(output.item:get_wear() == 51187) + assert(output.item:get_count() == 1) + + -- failing tool repair (unrepairable) + input = { + method = "normal", + width = 2, + items = {"unittests:unrepairable_tool 1 60000", "unittests:unrepairable_tool 1 60000"} + } + minetest.log("info", "[unittests] unrepairable tool crafting input: "..dump(input)) + output, decremented_input = minetest.get_craft_result(input) + minetest.log("info", "[unittests] unrepairable tool crafting output: "..dump(output)) + minetest.log("info", "[unittests] unrepairable tool crafting decremented input: "..dump(decremented_input)) + assert(output.item) + minetest.log("info", "[unittests] unrepairable tool crafting output.item:to_table(): "..dump(output.item:to_table())) + -- unrepairable tool must not yield any output + assert(output.item:get_name() == "") + +end + +function unittests.test_crafting() + test_clear_craft() + test_get_craft_result() + minetest.log("action", "[unittests] Crafting tests passed!") + return true +end + diff --git a/games/devtest/mods/unittests/crafting_prepare.lua b/games/devtest/mods/unittests/crafting_prepare.lua new file mode 100644 index 000000000..a09734827 --- /dev/null +++ b/games/devtest/mods/unittests/crafting_prepare.lua @@ -0,0 +1,88 @@ +-- Registering some dummy items and recipes for the crafting tests + +minetest.register_craftitem("unittests:torch", { + description = "Crafting Test Item: Torch", + inventory_image = "unittests_torch.png", + + groups = { dummy = 1 }, +}) +minetest.register_craftitem("unittests:coal_lump", { + description = "Crafting Test Item: Coal Lump", + inventory_image = "unittests_coal_lump.png", + + groups = { dummy = 1 }, +}) +minetest.register_craftitem("unittests:stick", { + description = "Crafting Test Item: Stick", + inventory_image = "unittests_stick.png", + + groups = { dummy = 1 }, +}) +minetest.register_craftitem("unittests:iron_lump", { + description = "Crafting Test Item: Iron Lump", + inventory_image = "unittests_iron_lump.png", + + groups = { dummy = 1 }, +}) +minetest.register_craftitem("unittests:steel_ingot", { + description = "Crafting Test Item: Steel Ingot", + inventory_image = "unittests_steel_ingot.png", + + groups = { dummy = 1 }, +}) + +-- Recipes for tests: Normal crafting, cooking and fuel + +minetest.register_craft({ + output = 'unittests:torch 4', + recipe = { + {'unittests:coal_lump'}, + {'unittests:stick'}, + } +}) + +minetest.register_craft({ + type = "cooking", + output = "unittests:steel_ingot", + recipe = "unittests:iron_lump", +}) + +minetest.register_craft({ + type = "fuel", + recipe = "unittests:coal_lump", + burntime = 40, +}) + +-- Test tool repair +minetest.register_craft({ + type = "toolrepair", + additional_wear = -0.05, +}) + +-- Test the disable_repair=1 group +minetest.register_tool("unittests:unrepairable_tool", { + description = "Crafting Test Item: Unrepairable Tool", + inventory_image = "unittests_unrepairable_tool.png", + tool_capabilities = { + groupcaps = { + cracky = { + times = {3, 2, 1}, + } + } + }, + groups = { disable_repair = 1, dummy = 1 } +}) + +minetest.register_tool("unittests:repairable_tool", { + description = "Crafting Test Item: Repairable Tool", + inventory_image = "unittests_repairable_tool.png", + tool_capabilities = { + groupcaps = { + cracky = { + times = {3, 2, 1}, + } + } + }, + + groups = { dummy = 1 }, +}) diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua new file mode 100644 index 000000000..6c1728420 --- /dev/null +++ b/games/devtest/mods/unittests/init.lua @@ -0,0 +1,16 @@ +unittests = {} + +local modpath = minetest.get_modpath("unittests") +dofile(modpath .. "/random.lua") +dofile(modpath .. "/player.lua") +dofile(modpath .. "/crafting_prepare.lua") +dofile(modpath .. "/crafting.lua") + +if minetest.settings:get_bool("devtest_unittests_autostart", false) then + unittests.test_random() + unittests.test_crafting() + minetest.register_on_joinplayer(function(player) + unittests.test_player(player) + end) +end + diff --git a/games/devtest/mods/unittests/mod.conf b/games/devtest/mods/unittests/mod.conf new file mode 100644 index 000000000..0d5e3c959 --- /dev/null +++ b/games/devtest/mods/unittests/mod.conf @@ -0,0 +1,2 @@ +name = unittests +description = Adds automated unit tests for the engine diff --git a/games/devtest/mods/unittests/player.lua b/games/devtest/mods/unittests/player.lua new file mode 100644 index 000000000..10781a95f --- /dev/null +++ b/games/devtest/mods/unittests/player.lua @@ -0,0 +1,73 @@ +-- +-- HP Change Reasons +-- +local expect = nil +local function run_hpchangereason_tests(player) + expect = { type = "set_hp", from = "mod" } + player:set_hp(3) + assert(expect == nil) + + expect = { a = 234, type = "set_hp", from = "mod" } + player:set_hp(7, { a= 234 }) + assert(expect == nil) + + expect = { df = 3458973454, type = "fall", from = "mod" } + player:set_hp(10, { type = "fall", df = 3458973454 }) + assert(expect == nil) + + player:set_hp(20) +end + +local function run_player_meta_tests(player) + local meta = player:get_meta() + meta:set_string("foo", "bar") + assert(meta:contains("foo")) + assert(meta:get_string("foo") == "bar") + assert(meta:get("foo") == "bar") + + local meta2 = player:get_meta() + assert(meta2:get_string("foo") == "bar") + assert(meta2:get("foo") == "bar") + assert(meta:equals(meta2)) + + meta:set_string("bob", "dillan") + assert(meta:get_string("foo") == "bar") + assert(meta:get_string("bob") == "dillan") + assert(meta:get("bob") == "dillan") + assert(meta2:get_string("foo") == "bar") + assert(meta2:get_string("bob") == "dillan") + assert(meta2:get("bob") == "dillan") + assert(meta:equals(meta2)) + + meta:set_string("foo", "") + assert(not meta:contains("foo")) + assert(meta:get("foo") == nil) + assert(meta:get_string("foo") == "") + assert(meta:equals(meta2)) +end + +function unittests.test_player(player) + minetest.register_on_player_hpchange(function(player, hp, reason) + if not expect then + return + end + + for key, value in pairs(reason) do + assert(expect[key] == value) + end + + for key, value in pairs(expect) do + assert(reason[key] == value) + end + + expect = nil + end) + + run_hpchangereason_tests(player) + run_player_meta_tests(player) + local msg = "Player tests passed for player '"..player:get_player_name().."'!" + minetest.chat_send_all(msg) + minetest.log("action", "[unittests] "..msg) + return true +end + diff --git a/games/devtest/mods/unittests/random.lua b/games/devtest/mods/unittests/random.lua new file mode 100644 index 000000000..f94f0a88e --- /dev/null +++ b/games/devtest/mods/unittests/random.lua @@ -0,0 +1,10 @@ +function unittests.test_random() + -- Try out PseudoRandom + minetest.log("action", "[unittests] Testing PseudoRandom ...") + local pseudo = PseudoRandom(13) + assert(pseudo:next() == 22290) + assert(pseudo:next() == 13854) + minetest.log("action", "[unittests] PseudoRandom test passed!") + return true +end + diff --git a/games/devtest/mods/unittests/textures/unittests_coal_lump.png b/games/devtest/mods/unittests/textures/unittests_coal_lump.png new file mode 100644 index 000000000..f460d909e Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_coal_lump.png differ diff --git a/games/devtest/mods/unittests/textures/unittests_iron_lump.png b/games/devtest/mods/unittests/textures/unittests_iron_lump.png new file mode 100644 index 000000000..22f43e9cc Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_iron_lump.png differ diff --git a/games/devtest/mods/unittests/textures/unittests_repairable_tool.png b/games/devtest/mods/unittests/textures/unittests_repairable_tool.png new file mode 100644 index 000000000..46fbbaa74 Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_repairable_tool.png differ diff --git a/games/devtest/mods/unittests/textures/unittests_steel_ingot.png b/games/devtest/mods/unittests/textures/unittests_steel_ingot.png new file mode 100644 index 000000000..6977696a2 Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_steel_ingot.png differ diff --git a/games/devtest/mods/unittests/textures/unittests_stick.png b/games/devtest/mods/unittests/textures/unittests_stick.png new file mode 100644 index 000000000..ffdce70d4 Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_stick.png differ diff --git a/games/devtest/mods/unittests/textures/unittests_torch.png b/games/devtest/mods/unittests/textures/unittests_torch.png new file mode 100644 index 000000000..ba5eebef0 Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_torch.png differ diff --git a/games/devtest/mods/unittests/textures/unittests_unrepairable_tool.png b/games/devtest/mods/unittests/textures/unittests_unrepairable_tool.png new file mode 100644 index 000000000..c676213a5 Binary files /dev/null and b/games/devtest/mods/unittests/textures/unittests_unrepairable_tool.png differ diff --git a/games/devtest/mods/util_commands/init.lua b/games/devtest/mods/util_commands/init.lua new file mode 100644 index 000000000..ad8d3f9ba --- /dev/null +++ b/games/devtest/mods/util_commands/init.lua @@ -0,0 +1,137 @@ +minetest.register_chatcommand("hotbar", { + params = "", + description = "Set hotbar size", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local size = tonumber(param) + if not size then + return false, "Missing or incorrect size parameter!" + end + local ok = player:hud_set_hotbar_itemcount(size) + if ok then + return true + else + return false, "Invalid item count!" + end + end, +}) + +minetest.register_chatcommand("hp", { + params = "", + description = "Set your health", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local hp = tonumber(param) + if not hp then + return false, "Missing or incorrect hp parameter!" + end + player:set_hp(hp) + return true + end, +}) + +minetest.register_chatcommand("zoom", { + params = "[]", + description = "Set or display your zoom_fov", + func = function(name, param) + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + if param == "" then + local fov = player:get_properties().zoom_fov + return true, "zoom_fov = "..tostring(fov) + end + local fov = tonumber(param) + if not fov then + return false, "Missing or incorrect zoom_fov parameter!" + end + player:set_properties({zoom_fov = fov}) + fov = player:get_properties().zoom_fov + return true, "zoom_fov = "..tostring(fov) + end, +}) + + + +local s_infplace = minetest.settings:get("devtest_infplace") +if s_infplace == "true" then + infplace = true +elseif s_infplace == "false" then + infplace = false +else + infplace = minetest.settings:get_bool("creative_mode", false) +end + +minetest.register_chatcommand("infplace", { + params = "", + description = "Toggle infinite node placement", + func = function(name, param) + infplace = not infplace + if infplace then + minetest.chat_send_all("Infinite node placement enabled!") + minetest.log("action", "Infinite node placement enabled") + else + minetest.chat_send_all("Infinite node placement disabled!") + minetest.log("action", "Infinite node placement disabled") + end + return true + end, +}) + +minetest.register_chatcommand("detach", { + params = "[]", + description = "Detach all objects nearby", + func = function(name, param) + local radius = tonumber(param) + if type(radius) ~= "number" then + radius = 8 + end + if radius < 1 then + radius = 1 + end + local player = minetest.get_player_by_name(name) + if not player then + return false, "No player." + end + local objs = minetest.get_objects_inside_radius(player:get_pos(), radius) + local num = 0 + for o=1, #objs do + if objs[o]:get_attach() then + objs[o]:set_detach() + num = num + 1 + end + end + return true, string.format("%d object(s) detached.", num) + end, +}) + + +-- Unlimited node placement +minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) + if placer and placer:is_player() then + return infplace + end +end) + +-- Don't pick up if the item is already in the inventory +local old_handle_node_drops = minetest.handle_node_drops +function minetest.handle_node_drops(pos, drops, digger) + if not digger or not digger:is_player() or not infplace then + return old_handle_node_drops(pos, drops, digger) + end + local inv = digger:get_inventory() + if inv then + for _, item in ipairs(drops) do + if not inv:contains_item("main", item, true) then + inv:add_item("main", item) + end + end + end +end diff --git a/games/devtest/mods/util_commands/mod.conf b/games/devtest/mods/util_commands/mod.conf new file mode 100644 index 000000000..fea6dd3e9 --- /dev/null +++ b/games/devtest/mods/util_commands/mod.conf @@ -0,0 +1,2 @@ +name = util_commands +description = Random server commands to make testing easier and more convenient diff --git a/games/devtest/screenshot.png b/games/devtest/screenshot.png new file mode 100644 index 000000000..7324883f6 Binary files /dev/null and b/games/devtest/screenshot.png differ diff --git a/games/devtest/settingtypes.txt b/games/devtest/settingtypes.txt new file mode 100644 index 000000000..40ee5845b --- /dev/null +++ b/games/devtest/settingtypes.txt @@ -0,0 +1,37 @@ +# If enabled, nodes won't be used up when placed. +# Note: This behavior can also be toggled in-game with the /infplace command. +# +# - true: enabled +# - false: disabled +# - auto: only enabled when Creative Mode is enabled (default) +devtest_infplace (Infinite node placement) enum auto true,false,auto + +# If enabled, new players receive some initial items when joining for the first time. +give_initial_stuff (Give initial stuff) bool true + +# If enabled, automated tests of the Lua API such as player health, crafting and PseudoRandom will be performed on startup. +devtest_unittests_autostart (Perform unit tests) bool false + +# If enabled, the game will use all mapgen aliases for the v6 mapgen. +# If disabled, it will only use a minimal set of mapgen aliases. +# If enabled, there should be biome-specific tree, leaves and ground nodes. If disabled, stuff should use fallback nodes (like stone instead of desert stone). +# +# Many mapgen aliases have fallback values when no value is provided. Having this setting disabled can be useful to test whether those fallback values are functional. +devtest_v6_mapgen_aliases (Use all v6 mapgen aliases) bool false + +# If enabled, the game will use dungeon stairs by enabling the corresponding mapgen aliases. +# +# Disabling this setting can be useful to test whether dungeons still work when stairs are not defined. +devtest_dungeon_stairs (Generate dungeon stairs) bool false + +# If enabled, the mapgen alias 'mapgen_mossycobble' will be used. This should enable random mossy cobblestone in dungeons. +# If disabled, it won't be used. The engine should fall back to cobble instead. +devtest_dungeon_mossycobble (Generate mossy cobblestone) bool false + +# If enabled, some very basic biomes will be registered. +devtest_register_biomes (Register biomes) bool true + +# If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. +# This is due to . +# This is only added to make the items more visible to avoid confusion, but you will no longer see the default inventory images for these items. When you want to test the default inventory image of drawtypes, this should be turned off. +testnodes_show_fallback_image (Use fallback inventory images) bool false diff --git a/games/minimal/LICENSE.txt b/games/minimal/LICENSE.txt deleted file mode 100644 index 108c66abf..000000000 --- a/games/minimal/LICENSE.txt +++ /dev/null @@ -1,4 +0,0 @@ -License information for Developer Test --------------------------------------- - -The same license as for Minetest applies. diff --git a/games/minimal/README.md b/games/minimal/README.md deleted file mode 100644 index a94530498..000000000 --- a/games/minimal/README.md +++ /dev/null @@ -1,52 +0,0 @@ -# Minimal development test - -This is a basic testing environment that contains a bunch of things to test the engine, but it could also be used as a minimal testbed for testing out mods. - -## Features - -* Basic nodes for mapgen -* Basic, minimal map generator -* Lots of example nodes for testing drawtypes, param2, light level, and many other node properties -* Example entities -* Other example items -* Formspec test (via `/test_formspec` command) -* Automated unit tests (disabled by default) -* Tools for manipulating nodes and entities, like the "Param2 Tool" - -## Getting started - -Basically, just create a world and start. A few important things to note: - -* Items are gotten from the “Chest of Everything” (`chest_of_everything:chest`) -* When you lost your initial items, type in `/stuff` command to get them back -* By default, Creative Mode activates infinite node placement. This behavior can be changed with the `devtest_infplace` setting -* Use the `/infplace` command to toggle infinite node placement in-game -* Use the Param2 Tool to change the param2 of nodes; it's useful to experiment with the various drawtype test nodes -* Check out the game settings and server commands for additional tests and features -* Creative Mode does nothing (apart from default engine behavior) - -Confused by a certain node or item? Check out for inline code comments. - -### Example tests - -* You can use this to test what happens if a player is simultaneously in 2 nodes with `damage_per_second` but with a different value. -* Or use the Falling Node Tool on various test nodes to see how they behave when falling. -* You could also use this as a testbed for dependency-free mods, e.g. to test out how your formspecs behave without theming. - -## Random notes - -* Experimental/strange/unstructured tests can be found in the `experimental` mod -* Textures of drawtype test nodes have a red dot at the top left corner. This is to see whether the textures are oriented properly - -## Design philosophy - -This should loosely follow the following principles: - -* Engine testing: The main focus of this is to aid testing of *engine* features, such as mapgen or node drawtypes -* Mod testing: The secondary focus is to help modders as well, either as a minimal testbed for mods or even as a code example -* Minimal interference: Under default settings, it shall not interfere with APIs except on explicit user wish. Non-trivial tests and features need to be enabled by a setting first -* Convenience: Have various tools to make usage easier and more convenient -* Reproducing engine bugs: When an engine bug was found, consider creating a test case -* Clarity: Textures and names need to be designed to keep different things clearly visually apart at a glance -* Low loading time: It must load blazing-fast so stuff can be tested quickly - diff --git a/games/minimal/game.conf b/games/minimal/game.conf deleted file mode 100644 index ae76cf7ad..000000000 --- a/games/minimal/game.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = Minimal development test -description = Testing environment to help with testing the engine features of Minetest. It can also be helpful in mod development. diff --git a/games/minimal/menu/background.png b/games/minimal/menu/background.png deleted file mode 100644 index 415bb3d14..000000000 Binary files a/games/minimal/menu/background.png and /dev/null differ diff --git a/games/minimal/menu/header.png b/games/minimal/menu/header.png deleted file mode 100644 index db864d6b7..000000000 Binary files a/games/minimal/menu/header.png and /dev/null differ diff --git a/games/minimal/menu/icon.png b/games/minimal/menu/icon.png deleted file mode 100644 index f854b9c31..000000000 Binary files a/games/minimal/menu/icon.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/init.lua b/games/minimal/mods/basenodes/init.lua deleted file mode 100644 index 8156c4bec..000000000 --- a/games/minimal/mods/basenodes/init.lua +++ /dev/null @@ -1,334 +0,0 @@ -local WATER_ALPHA = 160 -local WATER_VISC = 1 -local LAVA_VISC = 7 - --- --- Node definitions --- - --- Register nodes - -minetest.register_node("basenodes:stone", { - description = "Stone", - tiles = {"default_stone.png"}, - groups = {cracky=3}, -}) - -minetest.register_node("basenodes:desert_stone", { - description = "Desert Stone", - tiles = {"default_desert_stone.png"}, - groups = {cracky=3}, -}) - -minetest.register_node("basenodes:dirt_with_grass", { - description = "Dirt with Grass", - tiles ={"default_grass.png", - -- a little dot on the bottom to distinguish it from dirt - "default_dirt.png^basenodes_dirt_with_grass_bottom.png", - {name = "default_dirt.png^default_grass_side.png", - tileable_vertical = false}}, - groups = {crumbly=3, soil=1}, -}) - -minetest.register_node("basenodes:dirt_with_snow", { - description = "Dirt with Snow", - tiles ={"basenodes_dirt_with_snow.png", - -- a little dot on the bottom to distinguish it from dirt - "default_dirt.png^basenodes_dirt_with_snow_bottom.png", - {name = "default_dirt.png^default_snow_side.png", - tileable_vertical = false}}, - groups = {crumbly=3, soil=1}, -}) - -minetest.register_node("basenodes:dirt", { - description = "Dirt", - tiles ={"default_dirt.png"}, - groups = {crumbly=3, soil=1}, -}) - -minetest.register_node("basenodes:sand", { - description = "Sand", - tiles ={"default_sand.png"}, - groups = {crumbly=3}, -}) - -minetest.register_node("basenodes:desert_sand", { - description = "Desert Sand", - tiles ={"default_desert_sand.png"}, - groups = {crumbly=3}, -}) - -minetest.register_node("basenodes:gravel", { - description = "Gravel", - tiles ={"default_gravel.png"}, - groups = {crumbly=2}, -}) - -minetest.register_node("basenodes:junglegrass", { - description = "Jungle Grass", - drawtype = "plantlike", - tiles ={"default_junglegrass.png"}, - inventory_image = "default_junglegrass.png", - wield_image = "default_junglegrass.png", - paramtype = "light", - walkable = false, - groups = {snappy=3}, -}) - -minetest.register_node("basenodes:tree", { - description = "Normal Tree Trunk", - tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}, - is_ground_content = false, - groups = {choppy=2,oddly_breakable_by_hand=1}, -}) - -minetest.register_node("basenodes:leaves", { - description = "Normal Leaves", - drawtype = "allfaces_optional", - tiles = {"default_leaves.png"}, - paramtype = "light", - is_ground_content = false, - groups = {snappy=3}, -}) - -minetest.register_node("basenodes:jungletree", { - description = "Jungle Tree Trunk", - tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"}, - is_ground_content = false, - groups = {choppy=2,oddly_breakable_by_hand=1}, -}) - -minetest.register_node("basenodes:jungleleaves", { - description = "Jungle Leaves", - drawtype = "allfaces_optional", - tiles = {"default_jungleleaves.png"}, - paramtype = "light", - is_ground_content = false, - groups = {snappy=3}, -}) - -minetest.register_node("basenodes:pine_tree", { - description = "Pine Tree Trunk", - tiles = {"default_pine_tree_top.png", "default_pine_tree_top.png", "default_pine_tree.png"}, - is_ground_content = false, - groups = {choppy=2,oddly_breakable_by_hand=1}, -}) - -minetest.register_node("basenodes:pine_needles", { - description = "Pine Needles", - drawtype = "allfaces_optional", - tiles = {"default_pine_needles.png"}, - paramtype = "light", - is_ground_content = false, - groups = {snappy=3}, -}) - -minetest.register_node("basenodes:water_source", { - description = "Water Source", - drawtype = "liquid", - tiles = {"default_water.png"}, - special_tiles = { - {name = "default_water.png", backface_culling = false}, - {name = "default_water.png", backface_culling = true}, - }, - alpha = WATER_ALPHA, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drowning = 1, - liquidtype = "source", - liquid_alternative_flowing = "basenodes:water_flowing", - liquid_alternative_source = "basenodes:water_source", - liquid_viscosity = WATER_VISC, - post_effect_color = {a = 64, r = 100, g = 100, b = 200}, - groups = {water = 3, liquid = 3}, -}) - -minetest.register_node("basenodes:water_flowing", { - description = "Flowing Water", - drawtype = "flowingliquid", - tiles = {"default_water_flowing.png"}, - special_tiles = { - {name = "default_water_flowing.png", backface_culling = false}, - {name = "default_water_flowing.png", backface_culling = false}, - }, - alpha = WATER_ALPHA, - paramtype = "light", - paramtype2 = "flowingliquid", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drowning = 1, - liquidtype = "flowing", - liquid_alternative_flowing = "basenodes:water_flowing", - liquid_alternative_source = "basenodes:water_source", - liquid_viscosity = WATER_VISC, - post_effect_color = {a = 64, r = 100, g = 100, b = 200}, - groups = {water = 3, liquid = 3}, -}) - -minetest.register_node("basenodes:river_water_source", { - description = "River Water Source", - drawtype = "liquid", - tiles = { "default_river_water.png" }, - special_tiles = { - {name = "default_river_water.png", backface_culling = false}, - {name = "default_river_water.png", backface_culling = true}, - }, - alpha = WATER_ALPHA, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drowning = 1, - liquidtype = "source", - liquid_alternative_flowing = "basenodes:river_water_flowing", - liquid_alternative_source = "basenodes:river_water_source", - liquid_viscosity = 1, - liquid_renewable = false, - liquid_range = 2, - post_effect_color = {a = 103, r = 30, g = 76, b = 90}, - groups = {water = 3, liquid = 3, }, -}) - -minetest.register_node("basenodes:river_water_flowing", { - description = "Flowing River Water", - drawtype = "flowingliquid", - tiles = {"default_river_water_flowing.png"}, - special_tiles = { - {name = "default_river_water_flowing.png", backface_culling = false}, - {name = "default_river_water_flowing.png", backface_culling = false}, - }, - alpha = WATER_ALPHA, - paramtype = "light", - paramtype2 = "flowingliquid", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drowning = 1, - liquidtype = "flowing", - liquid_alternative_flowing = "basenodes:river_water_flowing", - liquid_alternative_source = "basenodes:river_water_source", - liquid_viscosity = 1, - liquid_renewable = false, - liquid_range = 2, - post_effect_color = {a = 103, r = 30, g = 76, b = 90}, - groups = {water = 3, liquid = 3, }, -}) - -minetest.register_node("basenodes:lava_flowing", { - description = "Flowing Lava", - drawtype = "flowingliquid", - tiles = {"default_lava_flowing.png"}, - special_tiles = { - {name="default_lava_flowing.png", backface_culling = false}, - {name="default_lava_flowing.png", backface_culling = false}, - }, - paramtype = "light", - light_source = minetest.LIGHT_MAX, - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drowning = 1, - damage_per_second = 4, - liquidtype = "flowing", - liquid_alternative_flowing = "basenodes:lava_flowing", - liquid_alternative_source = "basenodes:lava_source", - liquid_viscosity = LAVA_VISC, - post_effect_color = {a=192, r=255, g=64, b=0}, - groups = {lava=3, liquid=1}, -}) - -minetest.register_node("basenodes:lava_source", { - description = "Lava Source", - drawtype = "liquid", - tiles = { "default_lava.png" }, - special_tiles = { - {name = "default_lava.png", backface_culling = false}, - {name = "default_lava.png", backface_culling = true}, - }, - paramtype = "light", - light_source = minetest.LIGHT_MAX, - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drowning = 1, - damage_per_second = 4, - liquidtype = "source", - liquid_alternative_flowing = "basenodes:lava_flowing", - liquid_alternative_source = "basenodes:lava_source", - liquid_viscosity = LAVA_VISC, - post_effect_color = {a=192, r=255, g=64, b=0}, - groups = {lava=3, liquid=1}, -}) - -minetest.register_node("basenodes:cobble", { - description = "Cobblestone", - tiles ={"default_cobble.png"}, - is_ground_content = false, - groups = {cracky=3}, -}) - -minetest.register_node("basenodes:mossycobble", { - description = "Mossy Cobblestone", - tiles ={"default_mossycobble.png"}, - is_ground_content = false, - groups = {cracky=3}, -}) - -minetest.register_node("basenodes:apple", { - description = "Apple", - drawtype = "plantlike", - tiles ={"default_apple.png"}, - inventory_image = "default_apple.png", - paramtype = "light", - is_ground_content = false, - sunlight_propagates = true, - walkable = false, - groups = {dig_immediate=3}, - - -- Make eatable because why not? - on_use = minetest.item_eat(2), -}) - -minetest.register_node("basenodes:ice", { - description = "Ice", - tiles ={"default_ice.png"}, - groups = {cracky=3}, -}) - --- The snow nodes intentionally have different tints to make them more --- distinguishable -minetest.register_node("basenodes:snow", { - description = "Snow Sheet", - tiles = {"basenodes_snow_sheet.png"}, - groups = {crumbly=3}, - walkable = false, - paramtype = "light", - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5}, - }, -}) - -minetest.register_node("basenodes:snowblock", { - description = "Snow Block", - tiles ={"default_snow.png"}, - groups = {crumbly=3}, -}) - - diff --git a/games/minimal/mods/basenodes/mod.conf b/games/minimal/mods/basenodes/mod.conf deleted file mode 100644 index 25024dc63..000000000 --- a/games/minimal/mods/basenodes/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = basenodes -description = Contains basic nodes for mapgen diff --git a/games/minimal/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png b/games/minimal/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png deleted file mode 100644 index 5e8fc41a9..000000000 Binary files a/games/minimal/mods/basenodes/textures/basenodes_dirt_with_grass_bottom.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow.png b/games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow.png deleted file mode 100644 index 7ea2d8d31..000000000 Binary files a/games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png b/games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png deleted file mode 100644 index 447c94e98..000000000 Binary files a/games/minimal/mods/basenodes/textures/basenodes_dirt_with_snow_bottom.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/basenodes_snow_sheet.png b/games/minimal/mods/basenodes/textures/basenodes_snow_sheet.png deleted file mode 100644 index 455332093..000000000 Binary files a/games/minimal/mods/basenodes/textures/basenodes_snow_sheet.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_apple.png b/games/minimal/mods/basenodes/textures/default_apple.png deleted file mode 100644 index 9c115dae4..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_apple.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_cobble.png b/games/minimal/mods/basenodes/textures/default_cobble.png deleted file mode 100644 index 5b859e9c2..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_cobble.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_desert_sand.png b/games/minimal/mods/basenodes/textures/default_desert_sand.png deleted file mode 100644 index 19ec87dc0..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_desert_sand.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_desert_stone.png b/games/minimal/mods/basenodes/textures/default_desert_stone.png deleted file mode 100644 index 5126fb61c..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_desert_stone.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_dirt.png b/games/minimal/mods/basenodes/textures/default_dirt.png deleted file mode 100644 index 58670305d..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_dirt.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_grass.png b/games/minimal/mods/basenodes/textures/default_grass.png deleted file mode 100644 index 3d6397186..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_grass.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_grass_side.png b/games/minimal/mods/basenodes/textures/default_grass_side.png deleted file mode 100644 index 04770b6f6..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_grass_side.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_gravel.png b/games/minimal/mods/basenodes/textures/default_gravel.png deleted file mode 100644 index 7e5ff616f..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_gravel.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_ice.png b/games/minimal/mods/basenodes/textures/default_ice.png deleted file mode 100644 index c4bddd223..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_ice.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_junglegrass.png b/games/minimal/mods/basenodes/textures/default_junglegrass.png deleted file mode 100644 index d64e33abc..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_junglegrass.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_jungleleaves.png b/games/minimal/mods/basenodes/textures/default_jungleleaves.png deleted file mode 100644 index 1fa67e83a..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_jungleleaves.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_jungletree.png b/games/minimal/mods/basenodes/textures/default_jungletree.png deleted file mode 100644 index 053850fa7..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_jungletree.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_jungletree_top.png b/games/minimal/mods/basenodes/textures/default_jungletree_top.png deleted file mode 100644 index e80de8a69..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_jungletree_top.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_lava.png b/games/minimal/mods/basenodes/textures/default_lava.png deleted file mode 100644 index a4cf649f1..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_lava.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_lava_flowing.png b/games/minimal/mods/basenodes/textures/default_lava_flowing.png deleted file mode 100644 index 07066a6e3..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_lava_flowing.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_leaves.png b/games/minimal/mods/basenodes/textures/default_leaves.png deleted file mode 100644 index c0475d4d2..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_leaves.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_mossycobble.png b/games/minimal/mods/basenodes/textures/default_mossycobble.png deleted file mode 100644 index 69585e37b..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_mossycobble.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_pine_needles.png b/games/minimal/mods/basenodes/textures/default_pine_needles.png deleted file mode 100644 index 137caa2a3..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_pine_needles.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_pine_tree.png b/games/minimal/mods/basenodes/textures/default_pine_tree.png deleted file mode 100644 index 5743183c0..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_pine_tree.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_pine_tree_top.png b/games/minimal/mods/basenodes/textures/default_pine_tree_top.png deleted file mode 100644 index cc18f3462..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_pine_tree_top.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_river_water.png b/games/minimal/mods/basenodes/textures/default_river_water.png deleted file mode 100644 index e1074d2ef..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_river_water.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_river_water_flowing.png b/games/minimal/mods/basenodes/textures/default_river_water_flowing.png deleted file mode 100644 index 4a756b2bd..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_river_water_flowing.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_sand.png b/games/minimal/mods/basenodes/textures/default_sand.png deleted file mode 100644 index 0ed0e4ceb..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_sand.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_snow.png b/games/minimal/mods/basenodes/textures/default_snow.png deleted file mode 100644 index c42e0eecb..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_snow.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_snow_side.png b/games/minimal/mods/basenodes/textures/default_snow_side.png deleted file mode 100644 index f34d10991..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_snow_side.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_stone.png b/games/minimal/mods/basenodes/textures/default_stone.png deleted file mode 100644 index 763b4396a..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_stone.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_tree.png b/games/minimal/mods/basenodes/textures/default_tree.png deleted file mode 100644 index 189ec1593..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_tree.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_tree_top.png b/games/minimal/mods/basenodes/textures/default_tree_top.png deleted file mode 100644 index d1a4fa704..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_tree_top.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_water.png b/games/minimal/mods/basenodes/textures/default_water.png deleted file mode 100644 index 3e385ae8b..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_water.png and /dev/null differ diff --git a/games/minimal/mods/basenodes/textures/default_water_flowing.png b/games/minimal/mods/basenodes/textures/default_water_flowing.png deleted file mode 100644 index 7cdafd51d..000000000 Binary files a/games/minimal/mods/basenodes/textures/default_water_flowing.png and /dev/null differ diff --git a/games/minimal/mods/basetools/init.lua b/games/minimal/mods/basetools/init.lua deleted file mode 100644 index d9d9afb07..000000000 --- a/games/minimal/mods/basetools/init.lua +++ /dev/null @@ -1,295 +0,0 @@ --- --- Tool definitions --- - ---[[ TOOLS SUMMARY: - -Tool types: - -* Hand: basic tool/weapon (just for convenience, not optimized for testing) -* Pickaxe: dig cracky -* Axe: dig choppy -* Shovel: dig crumbly -* Shears: dig snappy -* Sword: deal damage -* Dagger: deal damage, but faster - -Tool materials: - -* Dirt: dig nodes of rating 3, one use only -* Wood: dig nodes of rating 3 -* Stone: dig nodes of rating 3 or 2 -* Steel: dig nodes of rating 3, 2 or 1 -* Mese: dig "everything" instantly -]] - --- The hand -minetest.register_item(":", { - type = "none", - wield_image = "wieldhand.png", - wield_scale = {x=1,y=1,z=2.5}, - tool_capabilities = { - full_punch_interval = 1.0, - max_drop_level = 0, - groupcaps = { - crumbly = {times={[3]=1.50}, uses=0, maxlevel=0}, - snappy = {times={[3]=1.50}, uses=0, maxlevel=0}, - oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=2.00}, uses=0, maxlevel=0}, - }, - damage_groups = {fleshy=1}, - } -}) - --- Mese Pickaxe: special tool that digs "everything" instantly -minetest.register_tool("basetools:pick_mese", { - description = "Mese Pickaxe", - inventory_image = "basetools_mesepick.png", - tool_capabilities = { - full_punch_interval = 1.0, - max_drop_level=3, - groupcaps={ - cracky={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, - crumbly={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, - snappy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, - choppy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, - dig_immediate={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, - }, - }, -}) - - --- --- Pickaxes: Dig cracky --- - --- This should break after only 1 use -minetest.register_tool("basetools:pick_dirt", { - description = "Dirt Pickaxe", - inventory_image = "basetools_dirtpick.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - cracky={times={[3]=2.00}, uses=1, maxlevel=0} - }, - }, -}) - -minetest.register_tool("basetools:pick_wood", { - description = "Wooden Pickaxe", - inventory_image = "basetools_woodpick.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - cracky={times={[3]=2.00}, uses=30, maxlevel=0} - }, - }, -}) -minetest.register_tool("basetools:pick_stone", { - description = "Stone Pickaxe", - inventory_image = "basetools_stonepick.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - cracky={times={[2]=1.20, [3]=0.80}, uses=60, maxlevel=0} - }, - }, -}) -minetest.register_tool("basetools:pick_steel", { - description = "Steel Pickaxe", - inventory_image = "basetools_steelpick.png", - tool_capabilities = { - max_drop_level=1, - groupcaps={ - cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=0} - }, - }, -}) -minetest.register_tool("basetools:pick_steel_l1", { - description = "Steel Pickaxe Level 1", - inventory_image = "basetools_steelpick_l1.png", - tool_capabilities = { - max_drop_level=1, - groupcaps={ - cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=1} - }, - }, -}) -minetest.register_tool("basetools:pick_steel_l2", { - description = "Steel Pickaxe Level 2", - inventory_image = "basetools_steelpick_l2.png", - tool_capabilities = { - max_drop_level=1, - groupcaps={ - cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=2} - }, - }, -}) - --- --- Shovels (dig crumbly) --- - -minetest.register_tool("basetools:shovel_wood", { - description = "Wooden Shovel", - inventory_image = "basetools_woodshovel.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - crumbly={times={[3]=0.50}, uses=30, maxlevel=0} - }, - }, -}) -minetest.register_tool("basetools:shovel_stone", { - description = "Stone Shovel", - inventory_image = "basetools_stoneshovel.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - crumbly={times={[2]=0.50, [3]=0.30}, uses=60, maxlevel=0} - }, - }, -}) -minetest.register_tool("basetools:shovel_steel", { - description = "Steel Shovel", - inventory_image = "basetools_steelshovel.png", - tool_capabilities = { - max_drop_level=1, - groupcaps={ - crumbly={times={[1]=1.00, [2]=0.70, [3]=0.60}, uses=90, maxlevel=0} - }, - }, -}) - --- --- Axes (dig choppy) --- - -minetest.register_tool("basetools:axe_wood", { - description = "Wooden Axe", - inventory_image = "basetools_woodaxe.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - choppy={times={[3]=0.80}, uses=30, maxlevel=0}, - }, - }, -}) -minetest.register_tool("basetools:axe_stone", { - description = "Stone Axe", - inventory_image = "basetools_stoneaxe.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - choppy={times={[2]=1.00, [3]=0.60}, uses=60, maxlevel=0}, - }, - }, -}) -minetest.register_tool("basetools:axe_steel", { - description = "Steel Axe", - inventory_image = "basetools_steelaxe.png", - tool_capabilities = { - max_drop_level=1, - groupcaps={ - choppy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=90, maxlevel=0}, - }, - }, -}) - --- --- Shears (dig snappy) --- - -minetest.register_tool("basetools:shears_wood", { - description = "Wooden Shears", - inventory_image = "basetools_woodshears.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - snappy={times={[3]=1.00}, uses=30, maxlevel=0}, - }, - }, -}) -minetest.register_tool("basetools:shears_stone", { - description = "Stone Shears", - inventory_image = "basetools_stoneshears.png", - tool_capabilities = { - max_drop_level=0, - groupcaps={ - snappy={times={[2]=1.00, [3]=0.50}, uses=60, maxlevel=0}, - }, - }, -}) -minetest.register_tool("basetools:shears_steel", { - description = "Steel Shears", - inventory_image = "basetools_steelshears.png", - tool_capabilities = { - max_drop_level=1, - groupcaps={ - snappy={times={[1]=1.00, [2]=0.50, [3]=0.25}, uses=90, maxlevel=0}, - }, - }, -}) - --- --- Swords (deal damage) --- - -minetest.register_tool("basetools:sword_wood", { - description = "Wooden Sword", - inventory_image = "basetools_woodsword.png", - tool_capabilities = { - full_punch_interval = 1.0, - damage_groups = {fleshy=2}, - } -}) -minetest.register_tool("basetools:sword_stone", { - description = "Stone Sword", - inventory_image = "basetools_stonesword.png", - tool_capabilities = { - full_punch_interval = 1.0, - max_drop_level=0, - damage_groups = {fleshy=4}, - } -}) -minetest.register_tool("basetools:sword_steel", { - description = "Steel Sword", - inventory_image = "basetools_steelsword.png", - tool_capabilities = { - full_punch_interval = 1.0, - max_drop_level=1, - damage_groups = {fleshy=6}, - } -}) - --- Fire/Ice sword: Deal damage to non-fleshy damage groups -minetest.register_tool("basetools:sword_fire", { - description = "Fire Sword", - inventory_image = "basetools_firesword.png", - tool_capabilities = { - full_punch_interval = 1.0, - max_drop_level=0, - damage_groups = {icy=6}, - } -}) -minetest.register_tool("basetools:sword_ice", { - description = "Ice Sword", - inventory_image = "basetools_icesword.png", - tool_capabilities = { - full_punch_interval = 1.0, - max_drop_level=0, - damage_groups = {firy=6}, - } -}) - --- --- Dagger: Low damage, fast punch interval --- -minetest.register_tool("basetools:dagger_steel", { - description = "Steel Dagger", - inventory_image = "basetools_steeldagger.png", - tool_capabilities = { - full_punch_interval = 0.5, - max_drop_level=0, - damage_groups = {fleshy=2}, - } -}) diff --git a/games/minimal/mods/basetools/mod.conf b/games/minimal/mods/basetools/mod.conf deleted file mode 100644 index f0d9f657d..000000000 --- a/games/minimal/mods/basetools/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = basetools -description = Contains basic digging tools diff --git a/games/minimal/mods/basetools/textures/basetools_dirtpick.png b/games/minimal/mods/basetools/textures/basetools_dirtpick.png deleted file mode 100644 index 20a021d72..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_dirtpick.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_firesword.png b/games/minimal/mods/basetools/textures/basetools_firesword.png deleted file mode 100644 index ee2809ab7..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_firesword.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_icesword.png b/games/minimal/mods/basetools/textures/basetools_icesword.png deleted file mode 100644 index 35ba8214b..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_icesword.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_mesepick.png b/games/minimal/mods/basetools/textures/basetools_mesepick.png deleted file mode 100644 index 2b5e12cdb..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_mesepick.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelaxe.png b/games/minimal/mods/basetools/textures/basetools_steelaxe.png deleted file mode 100644 index aac594d84..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelaxe.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steeldagger.png b/games/minimal/mods/basetools/textures/basetools_steeldagger.png deleted file mode 100644 index 4c9173094..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steeldagger.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelpick.png b/games/minimal/mods/basetools/textures/basetools_steelpick.png deleted file mode 100644 index bc02aac3e..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelpick.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelpick_l1.png b/games/minimal/mods/basetools/textures/basetools_steelpick_l1.png deleted file mode 100644 index dc03f3f65..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelpick_l1.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelpick_l2.png b/games/minimal/mods/basetools/textures/basetools_steelpick_l2.png deleted file mode 100644 index 011df4584..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelpick_l2.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelshears.png b/games/minimal/mods/basetools/textures/basetools_steelshears.png deleted file mode 100644 index 04c86c370..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelshears.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelshovel.png b/games/minimal/mods/basetools/textures/basetools_steelshovel.png deleted file mode 100644 index 8cab60784..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelshovel.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_steelsword.png b/games/minimal/mods/basetools/textures/basetools_steelsword.png deleted file mode 100644 index 9909365c3..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_steelsword.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_stoneaxe.png b/games/minimal/mods/basetools/textures/basetools_stoneaxe.png deleted file mode 100644 index a374c547d..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_stoneaxe.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_stonepick.png b/games/minimal/mods/basetools/textures/basetools_stonepick.png deleted file mode 100644 index d9156ee3a..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_stonepick.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_stoneshears.png b/games/minimal/mods/basetools/textures/basetools_stoneshears.png deleted file mode 100644 index 0b4bd3b74..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_stoneshears.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_stoneshovel.png b/games/minimal/mods/basetools/textures/basetools_stoneshovel.png deleted file mode 100644 index 3c1bb48cb..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_stoneshovel.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_stonesword.png b/games/minimal/mods/basetools/textures/basetools_stonesword.png deleted file mode 100644 index 6f3e94cda..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_stonesword.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_woodaxe.png b/games/minimal/mods/basetools/textures/basetools_woodaxe.png deleted file mode 100644 index 4015e910f..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_woodaxe.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_woodpick.png b/games/minimal/mods/basetools/textures/basetools_woodpick.png deleted file mode 100644 index 15c61f408..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_woodpick.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_woodshears.png b/games/minimal/mods/basetools/textures/basetools_woodshears.png deleted file mode 100644 index 4ff92fd7c..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_woodshears.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_woodshovel.png b/games/minimal/mods/basetools/textures/basetools_woodshovel.png deleted file mode 100644 index 6cc52f8a1..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_woodshovel.png and /dev/null differ diff --git a/games/minimal/mods/basetools/textures/basetools_woodsword.png b/games/minimal/mods/basetools/textures/basetools_woodsword.png deleted file mode 100644 index 364016ed6..000000000 Binary files a/games/minimal/mods/basetools/textures/basetools_woodsword.png and /dev/null differ diff --git a/games/minimal/mods/bucket/init.lua b/games/minimal/mods/bucket/init.lua deleted file mode 100644 index 3189d4aa6..000000000 --- a/games/minimal/mods/bucket/init.lua +++ /dev/null @@ -1,26 +0,0 @@ --- Bucket: Punch liquid source or flowing liquid to collect it - -minetest.register_tool("bucket:bucket", { - description = "Bucket", - inventory_image = "bucket.png", - stack_max = 1, - liquids_pointable = true, - groups = { disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - -- Must be pointing to node - if pointed_thing.type ~= "node" then - return - end - -- Check if pointing to a liquid - local n = minetest.get_node(pointed_thing.under) - local def = minetest.registered_nodes[n.name] - if def ~= nil and (def.liquidtype == "source" or def.liquidtype == "flowing") then - minetest.add_node(pointed_thing.under, {name="air"}) - local inv = user:get_inventory() - if inv then - inv:add_item("main", ItemStack(n.name)) - end - end - end, -}) - diff --git a/games/minimal/mods/bucket/mod.conf b/games/minimal/mods/bucket/mod.conf deleted file mode 100644 index d14deb4ea..000000000 --- a/games/minimal/mods/bucket/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = bucket -description = Minimal bucket to pick up liquids diff --git a/games/minimal/mods/bucket/textures/bucket.png b/games/minimal/mods/bucket/textures/bucket.png deleted file mode 100644 index 677952875..000000000 Binary files a/games/minimal/mods/bucket/textures/bucket.png and /dev/null differ diff --git a/games/minimal/mods/bucket/textures/bucket_lava.png b/games/minimal/mods/bucket/textures/bucket_lava.png deleted file mode 100644 index dfcae65fb..000000000 Binary files a/games/minimal/mods/bucket/textures/bucket_lava.png and /dev/null differ diff --git a/games/minimal/mods/bucket/textures/bucket_water.png b/games/minimal/mods/bucket/textures/bucket_water.png deleted file mode 100644 index e164b0a50..000000000 Binary files a/games/minimal/mods/bucket/textures/bucket_water.png and /dev/null differ diff --git a/games/minimal/mods/chest/init.lua b/games/minimal/mods/chest/init.lua deleted file mode 100644 index c44522cb9..000000000 --- a/games/minimal/mods/chest/init.lua +++ /dev/null @@ -1,27 +0,0 @@ -minetest.register_node("chest:chest", { - description = "Chest", - tiles ={"chest_chest.png^[sheet:2x2:0,0", "chest_chest.png^[sheet:2x2:0,0", - "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:1,0", - "chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:0,1"}, - paramtype2 = "facedir", - groups = {dig_immediate=2,choppy=3}, - is_ground_content = false, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", - "size[8,9]".. - "list[current_name;main;0,0;8,4;]".. - "list[current_player;main;0,5;8,4;]" .. - "listring[]") - meta:set_string("infotext", "Chest") - local inv = meta:get_inventory() - inv:set_size("main", 8*4) - end, - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - return inv:is_empty("main") - end, -}) - - diff --git a/games/minimal/mods/chest/mod.conf b/games/minimal/mods/chest/mod.conf deleted file mode 100644 index 0d7500164..000000000 --- a/games/minimal/mods/chest/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = chest -description = A simple chest to store items diff --git a/games/minimal/mods/chest/textures/chest_chest.png b/games/minimal/mods/chest/textures/chest_chest.png deleted file mode 100644 index 824b4d502..000000000 Binary files a/games/minimal/mods/chest/textures/chest_chest.png and /dev/null differ diff --git a/games/minimal/mods/chest_of_everything/init.lua b/games/minimal/mods/chest_of_everything/init.lua deleted file mode 100644 index 7d61abebf..000000000 --- a/games/minimal/mods/chest_of_everything/init.lua +++ /dev/null @@ -1,135 +0,0 @@ -local F = minetest.formspec_escape - --- Create a detached inventory -local inv_everything = minetest.create_detached_inventory("everything", { - allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) - return 0 - end, - allow_put = function(inv, listname, index, stack, player) - return 0 - end, - allow_take = function(inv, listname, index, stack, player) - return -1 - end, -}) -local inv_trash = minetest.create_detached_inventory("trash", { - allow_take = function(inv, listname, index, stack, player) - return 0 - end, - allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) - return 0 - end, - on_put = function(inv, listname, index, stack, player) - inv:set_list("main", {}) - end, -}) -inv_trash:set_size("main", 1) - -local max_page = 1 - -local function get_chest_formspec(page) - local start = 0 + (page-1)*32 - return "size[8,9]".. - "list[detached:everything;main;0,0;8,4;"..start.."]".. - "list[current_player;main;0,5;8,4;]" .. - "label[6,4;Trash:]" .. - "list[detached:trash;main;7,4;1,1]" .. - "button[0,4;1,1;chest_of_everything_prev;"..F("<").."]".. - "button[1,4;1,1;chest_of_everything_next;"..F(">").."]".. - "label[2,4;"..F("Page: "..page).."]".. - "listring[detached:everything;main]".. - "listring[current_player;main]".. - "listring[detached:trash;main]" -end - -minetest.register_node("chest_of_everything:chest", { - description = "Chest of Everything", - tiles ={"chest_of_everything_chest.png^[sheet:2x2:0,0", "chest_of_everything_chest.png^[sheet:2x2:0,0", - "chest_of_everything_chest.png^[sheet:2x2:1,0", "chest_of_everything_chest.png^[sheet:2x2:1,0", - "chest_of_everything_chest.png^[sheet:2x2:1,0", "chest_of_everything_chest.png^[sheet:2x2:0,1"}, - paramtype2 = "facedir", - groups = {dig_immediate=2,choppy=3}, - is_ground_content = false, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("infotext", "Chest of Everything") - meta:set_int("page", 1) - meta:set_string("formspec", get_chest_formspec(1)) - end, - on_receive_fields = function(pos, formname, fields, sender) - if formname == "" then - local meta = minetest.get_meta(pos) - local page = meta:get_int("page") - if fields.chest_of_everything_prev then - page = page - 1 - elseif fields.chest_of_everything_next then - page = page + 1 - end - if page < 1 then - page = 1 - end - if page > max_page then - page = max_page - end - meta:set_int("page", page) - meta:set_string("formspec", get_chest_formspec(page)) - end - end, -}) - -minetest.register_on_mods_loaded(function() - local items = {} - for itemstring,_ in pairs(minetest.registered_items) do - if itemstring ~= "" and itemstring ~= "unknown" and itemstring ~= "ignore" then - table.insert(items, itemstring) - end - end - --[[ Sort items in this order: - * Chest of Everything - * Test tools - * Other tools - * Craftitems - * Other items - * Dummy items ]] - local function compare(item1, item2) - local def1 = minetest.registered_items[item1] - local def2 = minetest.registered_items[item2] - local tool1 = def1.type == "tool" - local tool2 = def2.type == "tool" - local testtool1 = minetest.get_item_group(item1, "testtool") == 1 - local testtool2 = minetest.get_item_group(item2, "testtool") == 1 - local dummy1 = minetest.get_item_group(item1, "dummy") == 1 - local dummy2 = minetest.get_item_group(item2, "dummy") == 1 - local craftitem1 = def1.type == "craft" - local craftitem2 = def2.type == "craft" - if item1 == "chest_of_everything:chest" then - return true - elseif item2 == "chest_of_everything:chest" then - return false - elseif dummy1 and not dummy2 then - return false - elseif not dummy1 and dummy2 then - return true - elseif testtool1 and not testtool2 then - return true - elseif not testtool1 and testtool2 then - return false - elseif tool1 and not tool2 then - return true - elseif not tool1 and tool2 then - return false - elseif craftitem1 and not craftitem2 then - return true - elseif not craftitem1 and craftitem2 then - return false - else - return item1 < item2 - end - end - table.sort(items, compare) - inv_everything:set_size("main", #items) - max_page = math.ceil(#items / 32) - for i=1, #items do - inv_everything:add_item("main", items[i]) - end -end) diff --git a/games/minimal/mods/chest_of_everything/mod.conf b/games/minimal/mods/chest_of_everything/mod.conf deleted file mode 100644 index 4a4425e05..000000000 --- a/games/minimal/mods/chest_of_everything/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = chest_of_everything -description = Adds the chest of everything from which you can take all items diff --git a/games/minimal/mods/chest_of_everything/textures/chest_of_everything_chest.png b/games/minimal/mods/chest_of_everything/textures/chest_of_everything_chest.png deleted file mode 100644 index 6b2fd58d5..000000000 Binary files a/games/minimal/mods/chest_of_everything/textures/chest_of_everything_chest.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/init.lua b/games/minimal/mods/dignodes/init.lua deleted file mode 100644 index 833150873..000000000 --- a/games/minimal/mods/dignodes/init.lua +++ /dev/null @@ -1,37 +0,0 @@ -local groups = { - "cracky", "dig_immediate" -} - --- Register dig nodes with 1 digging group, a rating between 1-3 and a level between 0-2 -for g=1, #groups do - local gr = groups[g] - for r=1, 3 do - for l=0, 2 do - if not (gr=="dig_immediate" and (l>0 or r==1)) then - local d - if l > 0 then - d = string.format("Dig Test Node: %s=%d, level=%d", gr, r, l) - else - d = string.format("Dig Test Node: %s=%d", gr, r) - end - local tile = "dignodes_"..gr..".png^dignodes_rating"..r..".png" - if l==1 then - tile = tile .. "^[colorize:#FFFF00:127" - elseif l==2 then - tile = tile .. "^[colorize:#FF0000:127" - end - minetest.register_node("dignodes:"..gr.."_"..r.."_"..l, { - description = d, - tiles = { tile }, - groups = { [gr] = r, level = l }, - }) - end - end - end -end - --- Node without any digging groups -minetest.register_node("dignodes:none", { - description = "Dig Test Node: groupless", - tiles = {"dignodes_none.png"}, -}) diff --git a/games/minimal/mods/dignodes/mod.conf b/games/minimal/mods/dignodes/mod.conf deleted file mode 100644 index 52a80d66e..000000000 --- a/games/minimal/mods/dignodes/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = dignodes -description = Nodes with different digging groups diff --git a/games/minimal/mods/dignodes/textures/dignodes_choppy.png b/games/minimal/mods/dignodes/textures/dignodes_choppy.png deleted file mode 100644 index a73fc2424..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_choppy.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_cracky.png b/games/minimal/mods/dignodes/textures/dignodes_cracky.png deleted file mode 100644 index eb84e3079..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_cracky.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_crumbly.png b/games/minimal/mods/dignodes/textures/dignodes_crumbly.png deleted file mode 100644 index 23f2f7c71..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_crumbly.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_dig_immediate.png b/games/minimal/mods/dignodes/textures/dignodes_dig_immediate.png deleted file mode 100644 index a532ad90b..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_dig_immediate.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_none.png b/games/minimal/mods/dignodes/textures/dignodes_none.png deleted file mode 100644 index 60f13650b..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_none.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_rating1.png b/games/minimal/mods/dignodes/textures/dignodes_rating1.png deleted file mode 100644 index d2fee3a23..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_rating1.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_rating2.png b/games/minimal/mods/dignodes/textures/dignodes_rating2.png deleted file mode 100644 index 15329b93f..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_rating2.png and /dev/null differ diff --git a/games/minimal/mods/dignodes/textures/dignodes_rating3.png b/games/minimal/mods/dignodes/textures/dignodes_rating3.png deleted file mode 100644 index 37216bfd1..000000000 Binary files a/games/minimal/mods/dignodes/textures/dignodes_rating3.png and /dev/null differ diff --git a/games/minimal/mods/experimental/commands.lua b/games/minimal/mods/experimental/commands.lua deleted file mode 100644 index 96f8cbe39..000000000 --- a/games/minimal/mods/experimental/commands.lua +++ /dev/null @@ -1,215 +0,0 @@ -minetest.register_chatcommand("test_inv", { - params = "", - description = "Test: Modify player's inventory formspec", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - player:set_inventory_formspec( - "size[13,7.5]".. - "image[6,0.6;1,2;player.png]".. - "list[current_player;main;5,3.5;8,4;]".. - "list[current_player;craft;8,0;3,3;]".. - "list[current_player;craftpreview;12,1;1,1;]".. - "list[detached:test_inventory;main;0,0;4,6;0]".. - "button[0.5,7;2,1;button1;Button 1]".. - "button_exit[2.5,7;2,1;button2;Exit Button]") - return true, "Done." - end, -}) - -minetest.register_chatcommand("test_bulk_set_node", { - params = "", - description = "Test: Bulk-set 9×9×9 stone nodes", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - local pos_list = {} - local ppos = player:get_pos() - local i = 1 - for x=2,10 do - for y=2,10 do - for z=2,10 do - pos_list[i] = {x=ppos.x + x,y = ppos.y + y,z = ppos.z + z} - i = i + 1 - end - end - end - minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) - return true, "Done." - end, -}) - -minetest.register_chatcommand("bench_bulk_set_node", { - params = "", - description = "Benchmark: Bulk-set 99×99×99 stone nodes", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - local pos_list = {} - local ppos = player:get_pos() - local i = 1 - for x=2,100 do - for y=2,100 do - for z=2,100 do - pos_list[i] = {x=ppos.x + x,y = ppos.y + y,z = ppos.z + z} - i = i + 1 - end - end - end - - minetest.chat_send_player(name, "Benchmarking minetest.bulk_set_node. Warming up ..."); - - -- warm up with stone to prevent having different callbacks - -- due to different node topology - minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) - - minetest.chat_send_player(name, "Warming up finished, now benchmarking ..."); - - local start_time = minetest.get_us_time() - for i=1,#pos_list do - minetest.set_node(pos_list[i], {name = "mapgen_stone"}) - end - local middle_time = minetest.get_us_time() - minetest.bulk_set_node(pos_list, {name = "mapgen_stone"}) - local end_time = minetest.get_us_time() - local msg = string.format("Benchmark results: minetest.set_node loop: %.2f ms; minetest.bulk_set_node: %.2f ms", - ((middle_time - start_time)) / 1000, - ((end_time - middle_time)) / 1000 - ) - return true, msg - end, -}) - -local function advance_pos(pos, start_pos, advance_z) - if advance_z then - pos.z = pos.z + 2 - pos.x = start_pos.x - else - pos.x = pos.x + 2 - end - if pos.x > 30900 or pos.x - start_pos.x > 46 then - pos.x = start_pos.x - pos.z = pos.z + 2 - end - if pos.z > 30900 then - -- We ran out of space! Aborting - aborted = true - return false - end - return pos -end - -local function place_nodes(param) - local nodes = param.nodes - local name = param.name - local pos = param.pos - local start_pos = param.start_pos - table.sort(nodes) - minetest.chat_send_player(name, "Placing nodes …") - local nodes_placed = 0 - for n=1, #nodes do - local itemstring = nodes[n] - local def = minetest.registered_nodes[itemstring] - local p2_max = 0 - if param.param ~= "no_param2" then - -- Also test the param2 values of the nodes - -- ... but we only use permissible param2 values - if def.paramtype2 == "wallmounted" then - p2_max = 5 - elseif def.paramtype2 == "facedir" then - p2_max = 23 - elseif def.paramtype2 == "glasslikeliquidlevel" then - p2_max = 63 - elseif def.paramtype2 == "meshoptions" and def.drawtype == "plantlike" then - p2_max = 63 - elseif def.paramtype2 == "leveled" then - p2_max = 127 - elseif def.paramtype2 == "degrotate" and def.drawtype == "plantlike" then - p2_max = 179 - elseif def.paramtype2 == "colorfacedir" or - def.paramtype2 == "colorwallmounted" or - def.paramtype2 == "color" then - p2_max = 255 - end - end - for p2 = 0, p2_max do - -- Skip undefined param2 values - if not ((def.paramtype2 == "meshoptions" and p2 % 8 > 4) or - (def.paramtype2 == "colorwallmounted" and p2 % 8 > 5) or - (def.paramtype2 == "colorfacedir" and p2 % 32 > 23)) then - - minetest.set_node(pos, { name = itemstring, param2 = p2 }) - nodes_placed = nodes_placed + 1 - pos = advance_pos(pos, start_pos) - if not pos then - aborted = true - break - end - end - end - if aborted then - break - end - end - if aborted then - minetest.chat_send_player(name, "Not all nodes could be placed, please move further away from the world boundary. Nodes placed: "..nodes_placed) - end - minetest.chat_send_player(name, "Nodes placed: "..nodes_placed..".") -end - -local function after_emerge(blockpos, action, calls_remaining, param) - if calls_remaining == 0 then - place_nodes(param) - end -end - -minetest.register_chatcommand("test_place_nodes", { - params = "[ no_param2 ]", - description = "Test: Place all non-experimental nodes and optionally their permissible param2 variants", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - local pos = vector.floor(player:get_pos()) - pos.x = math.ceil(pos.x + 3) - pos.z = math.ceil(pos.z + 3) - pos.y = math.ceil(pos.y + 1) - local start_pos = table.copy(pos) - if pos.x > 30800 then - return false, "Too close to world boundary (+X). Please move to X < 30800." - end - if pos.z > 30800 then - return false, "Too close to world boundary (+Z). Please move to Z < 30800." - end - - local aborted = false - local nodes = {} - local emerge_estimate = 0 - for itemstring, def in pairs(minetest.registered_nodes) do - if itemstring ~= "ignore" and string.sub(itemstring, 1, 13) ~= "experimental:" then - table.insert(nodes, itemstring) - if def.paramtype2 == 0 then - emerge_estimate = emerge_estimate + 1 - else - emerge_estimate = emerge_estimate + 255 - end - end - end - -- Emerge area to make sure that all nodes are being placed. - -- Note we will emerge much more than we need to (overestimation), - -- the estimation code could be improved performance-wise … - local length = 16 + math.ceil(emerge_estimate / 24) * 2 - minetest.emerge_area(start_pos, - { x = start_pos.x + 46, y = start_pos.y, z = start_pos.z + length }, - after_emerge, { nodes = nodes, name = name, pos = pos, start_pos = start_pos, param = param }) - return true, "Emerging area …" - end, -}) - diff --git a/games/minimal/mods/experimental/detached.lua b/games/minimal/mods/experimental/detached.lua deleted file mode 100644 index 673adfdd4..000000000 --- a/games/minimal/mods/experimental/detached.lua +++ /dev/null @@ -1,29 +0,0 @@ --- Create a detached inventory -local inv = minetest.create_detached_inventory("test_inventory", { - allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) - experimental.print_to_everything("allow move asked") - return count -- Allow all - end, - allow_put = function(inv, listname, index, stack, player) - experimental.print_to_everything("allow put asked") - return 1 -- Allow only 1 - end, - allow_take = function(inv, listname, index, stack, player) - experimental.print_to_everything("allow take asked") - return 4 -- Allow 4 at max - end, - on_move = function(inv, from_list, from_index, to_list, to_index, count, player) - experimental.print_to_everything(player:get_player_name().." moved items") - end, - on_put = function(inv, listname, index, stack, player) - experimental.print_to_everything(player:get_player_name().." put items") - end, - on_take = function(inv, listname, index, stack, player) - experimental.print_to_everything(player:get_player_name().." took items") - end, -}) -inv:set_size("main", 4*6) -inv:add_item("main", "experimental:callback_node") -inv:add_item("main", "experimental:particle_spawner") - - diff --git a/games/minimal/mods/experimental/init.lua b/games/minimal/mods/experimental/init.lua deleted file mode 100644 index b292f792e..000000000 --- a/games/minimal/mods/experimental/init.lua +++ /dev/null @@ -1,23 +0,0 @@ --- --- Experimental things --- - -experimental = {} - -dofile(minetest.get_modpath("experimental").."/detached.lua") -dofile(minetest.get_modpath("experimental").."/items.lua") -dofile(minetest.get_modpath("experimental").."/commands.lua") - -function experimental.print_to_everything(msg) - minetest.log("action", msg) - minetest.chat_send_all(msg) -end - -minetest.log("info", "[experimental] modname="..dump(minetest.get_current_modname())) -minetest.log("info", "[experimental] modpath="..dump(minetest.get_modpath("experimental"))) -minetest.log("info", "[experimental] worldpath="..dump(minetest.get_worldpath())) - - -minetest.register_on_mods_loaded(function() - minetest.log("action", "[experimental] on_mods_loaded()") -end) diff --git a/games/minimal/mods/experimental/items.lua b/games/minimal/mods/experimental/items.lua deleted file mode 100644 index 51b063ba2..000000000 --- a/games/minimal/mods/experimental/items.lua +++ /dev/null @@ -1,103 +0,0 @@ -minetest.register_node("experimental:callback_node", { - description = "Callback Test Node (construct/destruct/timer)", - tiles = {"experimental_callback_node.png"}, - groups = {dig_immediate=3}, - -- This was known to cause a bug in minetest.item_place_node() when used - -- via minetest.place_node(), causing a placer with no position - paramtype2 = "facedir", - drop = "", - - on_construct = function(pos) - experimental.print_to_everything("experimental:callback_node:on_construct("..minetest.pos_to_string(pos)..")") - local meta = minetest.get_meta(pos) - meta:set_string("mine", "test") - local timer = minetest.get_node_timer(pos) - timer:start(4, 3) - end, - - after_place_node = function(pos, placer) - experimental.print_to_everything("experimental:callback_node:after_place_node("..minetest.pos_to_string(pos)..")") - local meta = minetest.get_meta(pos) - if meta:get_string("mine") == "test" then - experimental.print_to_everything("correct metadata found") - else - experimental.print_to_everything("incorrect metadata found") - end - end, - - on_destruct = function(pos) - experimental.print_to_everything("experimental:callback_node:on_destruct("..minetest.pos_to_string(pos)..")") - end, - - after_destruct = function(pos) - experimental.print_to_everything("experimental:callback_node:after_destruct("..minetest.pos_to_string(pos)..")") - end, - - after_dig_node = function(pos, oldnode, oldmetadata, digger) - experimental.print_to_everything("experimental:callback_node:after_dig_node("..minetest.pos_to_string(pos)..")") - end, - - on_timer = function(pos, elapsed) - experimental.print_to_everything("on_timer(): elapsed="..dump(elapsed)) - return true - end, -}) - -minetest.register_tool("experimental:privatizer", { - description = "Node Meta Privatizer", - inventory_image = "experimental_tester_tool_1.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type == "node" then - local node = minetest.get_node(pointed_thing.under) - if node.name == "chest:chest" then - local p = pointed_thing.under - minetest.log("action", "Privatizer used at "..minetest.pos_to_string(p)) - minetest.get_meta(p):mark_as_private({"infotext", "formspec"}) - if user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), "Chest metadata (infotext, formspec) set private!") - end - return - end - end - if user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), "Privatizer can only be used on chest!") - end - end, -}) - -minetest.register_tool("experimental:particle_spawner", { - description = "Particle Spawner", - inventory_image = "experimental_tester_tool_1.png^[invert:g", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing, true) - if pos == nil then - if user then - pos = user:get_pos() - end - end - pos = vector.add(pos, {x=0, y=0.5, z=0}) - local tex, anim - if math.random(0, 1) == 0 then - tex = "experimental_particle_sheet.png" - anim = {type="sheet_2d", frames_w=3, frames_h=2, frame_length=0.5} - else - tex = "experimental_particle_vertical.png" - anim = {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.3} - end - - minetest.add_particle({ - pos = pos, - velocity = {x=0, y=0, z=0}, - acceleration = {x=0, y=0.04, z=0}, - expirationtime = 6, - collisiondetection = true, - texture = tex, - animation = anim, - size = 4, - glow = math.random(0, 5), - }) - end, -}) - diff --git a/games/minimal/mods/experimental/mod.conf b/games/minimal/mods/experimental/mod.conf deleted file mode 100644 index cf0f9cb42..000000000 --- a/games/minimal/mods/experimental/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = experimental -description = Chaotic mod containing unstructured tests for testing out engine features. The features in this mod should be moved to other mods. diff --git a/games/minimal/mods/experimental/textures/experimental_callback_node.png b/games/minimal/mods/experimental/textures/experimental_callback_node.png deleted file mode 100644 index e9d87434c..000000000 Binary files a/games/minimal/mods/experimental/textures/experimental_callback_node.png and /dev/null differ diff --git a/games/minimal/mods/experimental/textures/experimental_particle_sheet.png b/games/minimal/mods/experimental/textures/experimental_particle_sheet.png deleted file mode 100644 index 6d70394e4..000000000 Binary files a/games/minimal/mods/experimental/textures/experimental_particle_sheet.png and /dev/null differ diff --git a/games/minimal/mods/experimental/textures/experimental_particle_vertical.png b/games/minimal/mods/experimental/textures/experimental_particle_vertical.png deleted file mode 100644 index 0320b7545..000000000 Binary files a/games/minimal/mods/experimental/textures/experimental_particle_vertical.png and /dev/null differ diff --git a/games/minimal/mods/experimental/textures/experimental_tester_tool_1.png b/games/minimal/mods/experimental/textures/experimental_tester_tool_1.png deleted file mode 100644 index 5df416a58..000000000 Binary files a/games/minimal/mods/experimental/textures/experimental_tester_tool_1.png and /dev/null differ diff --git a/games/minimal/mods/give_initial_stuff/init.lua b/games/minimal/mods/give_initial_stuff/init.lua deleted file mode 100644 index 491a531e4..000000000 --- a/games/minimal/mods/give_initial_stuff/init.lua +++ /dev/null @@ -1,37 +0,0 @@ -local give_if_not_gotten_already = function(inv, list, item) - if not inv:contains_item(list, item) then - inv:add_item(list, item) - end -end - -local give_initial_stuff = function(player) - local inv = player:get_inventory() - give_if_not_gotten_already(inv, "main", "basetools:pick_mese") - give_if_not_gotten_already(inv, "main", "basetools:axe_steel") - give_if_not_gotten_already(inv, "main", "basetools:shovel_steel") - give_if_not_gotten_already(inv, "main", "bucket:bucket") - give_if_not_gotten_already(inv, "main", "testnodes:light14") - give_if_not_gotten_already(inv, "main", "chest_of_everything:chest") - minetest.log("action", "[give_initial_stuff] Giving initial stuff to "..player:get_player_name()) -end - -minetest.register_on_newplayer(function(player) - if minetest.settings:get_bool("give_initial_stuff", true) then - give_initial_stuff(player) - end -end) - -minetest.register_chatcommand("stuff", { - params = "", - privs = { give = true }, - description = "Give yourself initial items", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player or not player:is_player() then - return false, "No player." - end - give_initial_stuff(player) - return true - end, -}) - diff --git a/games/minimal/mods/give_initial_stuff/mod.conf b/games/minimal/mods/give_initial_stuff/mod.conf deleted file mode 100644 index 1ba49f52a..000000000 --- a/games/minimal/mods/give_initial_stuff/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = give_initial_stuff -description = Gives items to players on join -depends = basetools, bucket, chest_of_everything, testnodes diff --git a/games/minimal/mods/initial_message/init.lua b/games/minimal/mods/initial_message/init.lua deleted file mode 100644 index f92f4d3cf..000000000 --- a/games/minimal/mods/initial_message/init.lua +++ /dev/null @@ -1,9 +0,0 @@ -minetest.register_on_joinplayer(function(player) - local cb = function(player) - if not player or not player:is_player() then - return - end - minetest.chat_send_player(player:get_player_name(), "This is the \"Minimal development Test\" [minimal], meant only for testing and development. Use Minetest Game for the real thing.") - end - minetest.after(2.0, cb, player) -end) diff --git a/games/minimal/mods/initial_message/mod.conf b/games/minimal/mods/initial_message/mod.conf deleted file mode 100644 index 32aa2ac4e..000000000 --- a/games/minimal/mods/initial_message/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = initial_message -description = Show message to joining players explaining what this testing game is about diff --git a/games/minimal/mods/mapgen/init.lua b/games/minimal/mods/mapgen/init.lua deleted file mode 100644 index 13a186a50..000000000 --- a/games/minimal/mods/mapgen/init.lua +++ /dev/null @@ -1,81 +0,0 @@ --- --- Aliases for map generator outputs --- - --- ESSENTIAL node aliases --- Basic nodes -minetest.register_alias("mapgen_stone", "basenodes:stone") -minetest.register_alias("mapgen_water_source", "basenodes:water_source") -minetest.register_alias("mapgen_river_water_source", "basenodes:river_water_source") - --- Additional essential aliases for v6 -minetest.register_alias("mapgen_lava_source", "basenodes:lava_source") -minetest.register_alias("mapgen_dirt", "basenodes:dirt") -minetest.register_alias("mapgen_dirt_with_grass", "basenodes:dirt_with_grass") -minetest.register_alias("mapgen_sand", "basenodes:sand") -minetest.register_alias("mapgen_tree", "basenodes:tree") -minetest.register_alias("mapgen_leaves", "basenodes:leaves") -minetest.register_alias("mapgen_apple", "basenodes:apple") - --- Essential alias for dungeons -minetest.register_alias("mapgen_cobble", "basenodes:cobble") - --- Optional aliases for v6 (they all have fallback values in the engine) -if minetest.settings:get_bool("devtest_v6_mapgen_aliases", false) then - minetest.register_alias("mapgen_gravel", "basenodes:gravel") - minetest.register_alias("mapgen_desert_stone", "basenodes:desert_stone") - minetest.register_alias("mapgen_desert_sand", "basenodes:desert_sand") - minetest.register_alias("mapgen_dirt_with_snow", "basenodes:dirt_with_snow") - minetest.register_alias("mapgen_snowblock", "basenodes:snowblock") - minetest.register_alias("mapgen_snow", "basenodes:snow") - minetest.register_alias("mapgen_ice", "basenodes:ice") - minetest.register_alias("mapgen_junglegrass", "basenodes:junglegrass") - minetest.register_alias("mapgen_jungletree", "basenodes:jungletree") - minetest.register_alias("mapgen_jungleleaves", "basenodes:jungleleaves") - minetest.register_alias("mapgen_pine_tree", "basenodes:pine_tree") - minetest.register_alias("mapgen_pine_needles", "basenodes:pine_needles") -end --- Optional alias for mossycobble (should fall back to cobble) -if minetest.settings:get_bool("devtest_dungeon_mossycobble", false) then - minetest.register_alias("mapgen_mossycobble", "basenodes:mossycobble") -end --- Optional aliases for dungeon stairs (should fall back to full nodes) -if minetest.settings:get_bool("devtest_dungeon_stairs", false) then - minetest.register_alias("mapgen_stair_cobble", "stairs:stair_cobble") - if minetest.settings:get_bool("devtest_v6_mapgen_aliases", false) then - minetest.register_alias("mapgen_stair_desert_stone", "stairs:stair_desert_stone") - end -end - --- --- Register biomes for biome API --- - -minetest.clear_registered_biomes() -minetest.clear_registered_decorations() - -if minetest.settings:get_bool("devtest_register_biomes", true) then - minetest.register_biome({ - name = "mapgen:grassland", - node_top = "basenodes:dirt_with_grass", - depth_top = 1, - node_filler = "basenodes:dirt", - depth_filler = 1, - y_min = 5, - y_max = 31000, - heat_point = 50, - humidity_point = 50, - }) - - minetest.register_biome({ - name = "mapgen:grassland_ocean", - node_top = "basenodes:sand", - depth_top = 1, - node_filler = "basenodes:sand", - depth_filler = 2, - y_min = -31000, - y_max = 4, - heat_point = 50, - humidity_point = 50, - }) -end diff --git a/games/minimal/mods/mapgen/mod.conf b/games/minimal/mods/mapgen/mod.conf deleted file mode 100644 index 15750ccbe..000000000 --- a/games/minimal/mods/mapgen/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = mapgen -description = Minimal map generator -depends = basenodes diff --git a/games/minimal/mods/modchannels/init.lua b/games/minimal/mods/modchannels/init.lua deleted file mode 100644 index ee925f09b..000000000 --- a/games/minimal/mods/modchannels/init.lua +++ /dev/null @@ -1,14 +0,0 @@ --- --- Mod channels experimental handlers --- -local mod_channel = minetest.mod_channel_join("experimental_preview") - -minetest.register_on_modchannel_message(function(channel, sender, message) - minetest.log("action", "[modchannels] Server received message `" .. message - .. "` on channel `" .. channel .. "` from sender `" .. sender .. "`") - - if mod_channel:is_writeable() then - mod_channel:send_all("experimental answers to preview") - mod_channel:leave() - end -end) diff --git a/games/minimal/mods/modchannels/mod.conf b/games/minimal/mods/modchannels/mod.conf deleted file mode 100644 index 7c13aadfb..000000000 --- a/games/minimal/mods/modchannels/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = modchannels -description = Add experimental mod channel handlers diff --git a/games/minimal/mods/soundstuff/init.lua b/games/minimal/mods/soundstuff/init.lua deleted file mode 100644 index 22012ba14..000000000 --- a/games/minimal/mods/soundstuff/init.lua +++ /dev/null @@ -1,170 +0,0 @@ -local simple_nodes = { - footstep = { "Footstep Sound Node", "soundstuff_node_footstep.png" }, - dig = { "Dig Sound Node", "soundstuff_node_dig.png" }, - dug = { "Dug Sound Node", "soundstuff_node_dug.png" }, - place = { "Place Sound Node", "soundstuff_node_place.png" }, - place_failed = { "Place Failed Sound Node", "soundstuff_node_place_failed.png" }, -} - -for k,v in pairs(simple_nodes) do - minetest.register_node("soundstuff:"..k, { - description = v[1], - tiles = {"soundstuff_node_sound.png","soundstuff_node_sound.png",v[2]}, - groups = {dig_immediate=2}, - sounds = { - [k] = { name = "soundstuff_mono", gain = 1.0 }, - } - }) -end - -minetest.register_node("soundstuff:place_failed_attached", { - description = "Attached Place Failed Sound Node", - tiles = {"soundstuff_node_sound.png", "soundstuff_node_sound.png", "soundstuff_node_place_failed.png"}, - groups = {dig_immediate=2, attached_node=1}, - drawtype = "nodebox", - paramtype = "light", - node_box = { type = "fixed", fixed = { - { -7/16, -7/16, -7/16, 7/16, 7/16, 7/16 }, - { -0.5, -0.5, -0.5, 0.5, -7/16, 0.5 }, - }}, - sounds = { - place_failed = { name = "soundstuff_mono", gain = 1.0 }, - }, -}) - -minetest.register_node("soundstuff:fall", { - description = "Fall Sound Node", - tiles = {"soundstuff_node_sound.png", "soundstuff_node_sound.png", "soundstuff_node_fall.png"}, - groups = {dig_immediate=2, falling_node=1}, - sounds = { - fall = { name = "soundstuff_mono", gain = 1.0 }, - } -}) - -minetest.register_node("soundstuff:fall_attached", { - description = "Attached Fall Sound Node", - tiles = {"soundstuff_node_sound.png", "soundstuff_node_sound.png", "soundstuff_node_fall.png"}, - groups = {dig_immediate=2, attached_node=1}, - drawtype = "nodebox", - paramtype = "light", - node_box = { type = "fixed", fixed = { - { -7/16, -7/16, -7/16, 7/16, 7/16, 7/16 }, - { -0.5, -0.5, -0.5, 0.5, -7/16, 0.5 }, - }}, - sounds = { - fall = { name = "soundstuff_mono", gain = 1.0 }, - } -}) - -minetest.register_node("soundstuff:footstep_liquid", { - description = "Liquid Footstep Sound Node", - drawtype = "liquid", - tiles = { - "soundstuff_node_sound.png^[colorize:#0000FF:127", - }, - special_tiles = { - {name = "soundstuff_node_sound.png^[colorize:#0000FF:127", backface_culling = false}, - {name = "soundstuff_node_sound.png^[colorize:#0000FF:127", backface_culling = true}, - }, - liquids_pointable = true, - liquidtype = "source", - liquid_alternative_flowing = "soundstuff:footstep_liquid", - liquid_alternative_source = "soundstuff:footstep_liquid", - liquid_renewable = false, - liquid_range = 0, - liquid_viscosity = 0, - alpha = 190, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - post_effect_color = {a = 64, r = 0, g = 0, b = 200}, - sounds = { - footstep = { name = "soundstuff_mono", gain = 1.0 }, - } -}) - -minetest.register_node("soundstuff:footstep_climbable", { - description = "Climbable Footstep Sound Node", - drawtype = "allfaces", - tiles = { - "soundstuff_node_climbable.png", - }, - alpha = 120, - paramtype = "light", - sunlight_propagates = true, - walkable = false, - climbable = true, - is_ground_content = false, - groups = { dig_immediate = 2 }, - sounds = { - footstep = { name = "soundstuff_mono", gain = 1.0 }, - } -}) - - - -minetest.register_craftitem("soundstuff:eat", { - description = "Eat Sound Item", - inventory_image = "soundstuff_eat.png", - on_use = minetest.item_eat(0), - sound = { - eat = { name = "soundstuff_mono", gain = 1.0 }, - } -}) - -minetest.register_tool("soundstuff:breaks", { - description = "Break Sound Tool", - inventory_image = "soundstuff_node_dug.png", - sound = { - breaks = { name = "soundstuff_mono", gain = 1.0 }, - }, - tool_capabilities = { - max_drop_level=0, - groupcaps={ - cracky={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, - choppy={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, - snappy={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, - crumbly={times={[2]=2.00, [3]=1.20}, uses=1, maxlevel=0}, - }, - }, -}) - --- Plays sound repeatedly -minetest.register_node("soundstuff:positional", { - description = "Positional Sound Node", - on_construct = function(pos) - local timer = minetest.get_node_timer(pos) - timer:start(0) - end, - on_timer = function(pos, elapsed) - local node = minetest.get_node(pos) - local dist = node.param2 - if dist == 0 then - dist = nil - end - minetest.sound_play("soundstuff_mono", { pos = pos, max_hear_distance = dist }) - local timer = minetest.get_node_timer(pos) - timer:start(0.7) - end, - on_rightclick = function(pos, node, clicker) - node.param2 = (node.param2 + 1) % 64 - minetest.set_node(pos, node) - if clicker and clicker:is_player() then - local dist = node.param2 - local diststr - if dist == 0 then - diststr = "" - else - diststr = tostring(dist) - end - minetest.chat_send_player(clicker:get_player_name(), "max_hear_distance = " .. diststr) - end - end, - - groups = { dig_immediate = 2 }, - tiles = { "soundstuff_node_sound.png" }, -}) - diff --git a/games/minimal/mods/soundstuff/mod.conf b/games/minimal/mods/soundstuff/mod.conf deleted file mode 100644 index 2c631e2da..000000000 --- a/games/minimal/mods/soundstuff/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = soundstuff -description = Example items and nodes for testing sound effects diff --git a/games/minimal/mods/soundstuff/sounds/soundstuff_mono.ogg b/games/minimal/mods/soundstuff/sounds/soundstuff_mono.ogg deleted file mode 100644 index 43428d566..000000000 Binary files a/games/minimal/mods/soundstuff/sounds/soundstuff_mono.ogg and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_eat.png b/games/minimal/mods/soundstuff/textures/soundstuff_eat.png deleted file mode 100644 index aed205422..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_eat.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_blank.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_blank.png deleted file mode 100644 index 4dffacc4c..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_blank.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_climbable.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_climbable.png deleted file mode 100644 index 3888f793c..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_climbable.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_dig.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_dig.png deleted file mode 100644 index 67ba111d8..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_dig.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_dug.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_dug.png deleted file mode 100644 index bab5fbe51..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_dug.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_fall.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_fall.png deleted file mode 100644 index 17b14f1e4..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_fall.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_footstep.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_footstep.png deleted file mode 100644 index 6367ae909..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_footstep.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_place.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_place.png deleted file mode 100644 index d159ad533..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_place.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_place_failed.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_place_failed.png deleted file mode 100644 index 780ba946d..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_place_failed.png and /dev/null differ diff --git a/games/minimal/mods/soundstuff/textures/soundstuff_node_sound.png b/games/minimal/mods/soundstuff/textures/soundstuff_node_sound.png deleted file mode 100644 index 0592a0299..000000000 Binary files a/games/minimal/mods/soundstuff/textures/soundstuff_node_sound.png and /dev/null differ diff --git a/games/minimal/mods/stairs/init.lua b/games/minimal/mods/stairs/init.lua deleted file mode 100644 index 2701cabab..000000000 --- a/games/minimal/mods/stairs/init.lua +++ /dev/null @@ -1,65 +0,0 @@ -stairs = {} - --- Node will be called stairs:stair_ -function stairs.register_stair(subname, recipeitem, groups, images, description) - minetest.register_node(":stairs:stair_" .. subname, { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = true, - groups = groups, - node_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - {-0.5, 0, 0, 0.5, 0.5, 0.5}, - }, - }, - }) -end - --- Node will be called stairs:slab_ -function stairs.register_slab(subname, recipeitem, groups, images, description) - minetest.register_node(":stairs:slab_" .. subname, { - description = description, - drawtype = "nodebox", - tiles = images, - paramtype = "light", - is_ground_content = true, - groups = groups, - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - }, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - }, - }) -end - --- Nodes will be called stairs:{stair,slab}_ -function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab) - stairs.register_stair(subname, recipeitem, groups, images, desc_stair) - stairs.register_slab(subname, recipeitem, groups, images, desc_slab) -end - -stairs.register_stair_and_slab("stone", "basenodes:stone", - {cracky=3}, - {"default_stone.png"}, - "Stone Stair", - "Stone Slab") - -stairs.register_stair_and_slab("desert_stone", "basenodes:desert_stone", - {cracky=3}, - {"default_desert_stone.png"}, - "Desert Stone Stair", - "Desert Stone Slab") - -stairs.register_stair_and_slab("cobble", "basenodes:cobble", - {cracky=3}, - {"default_cobble.png"}, - "Cobblestone Stair", - "Cobblestone Slab") diff --git a/games/minimal/mods/stairs/mod.conf b/games/minimal/mods/stairs/mod.conf deleted file mode 100644 index 724bff881..000000000 --- a/games/minimal/mods/stairs/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = stairs -description = Adds stairs and slabs -depends = basenodes diff --git a/games/minimal/mods/testentities/armor.lua b/games/minimal/mods/testentities/armor.lua deleted file mode 100644 index 4c30cec8d..000000000 --- a/games/minimal/mods/testentities/armor.lua +++ /dev/null @@ -1,41 +0,0 @@ --- Armorball: Test entity for testing armor groups --- Rightclick to change armor group - -local phasearmor = { - [0]={icy=100}, - [1]={firy=100}, - [2]={fleshy=100}, - [3]={immortal=1}, - [4]={punch_operable=1}, -} - -minetest.register_entity("testentities:armorball", { - initial_properties = { - hp_max = 20, - physical = false, - collisionbox = {-0.4,-0.4,-0.4, 0.4,0.4,0.4}, - visual = "sprite", - visual_size = {x=1, y=1}, - textures = {"testentities_armorball.png"}, - spritediv = {x=1, y=5}, - initial_sprite_basepos = {x=0, y=0}, - }, - - _phase = 2, - - on_activate = function(self, staticdata) - minetest.log("action", "[testentities] armorball.on_activate") - self.object:set_armor_groups(phasearmor[self._phase]) - self.object:set_sprite({x=0, y=self._phase}) - end, - - on_rightclick = function(self, clicker) - -- Change armor group and sprite - self._phase = self._phase + 1 - if self._phase >= 5 then - self._phase = 0 - end - self.object:set_sprite({x=0, y=self._phase}) - self.object:set_armor_groups(phasearmor[self._phase]) - end, -}) diff --git a/games/minimal/mods/testentities/callbacks.lua b/games/minimal/mods/testentities/callbacks.lua deleted file mode 100644 index 711079f87..000000000 --- a/games/minimal/mods/testentities/callbacks.lua +++ /dev/null @@ -1,75 +0,0 @@ --- Entities that test their callbacks - -local message = function(msg) - minetest.log("action", msg) - minetest.chat_send_all(msg) -end - -local get_object_name = function(obj) - local name = "" - if obj then - if obj:is_player() then - name = obj:get_player_name() - else - name = "" - end - end - return name -end - -local spos = function(self) - return minetest.pos_to_string(vector.round(self.object:get_pos())) -end - --- Callback test entity (all callbacks except on_step) -minetest.register_entity("testentities:callback", { - initial_properties = { - visual = "upright_sprite", - textures = { "testentities_callback.png" }, - }, - - on_activate = function(self, staticdata, dtime_s) - message("Callback entity: on_activate! pos="..spos(self).."; dtime_s="..dtime_s) - end, - on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage) - local name = get_object_name(puncher) - message( - "Callback entity: on_punch! ".. - "pos="..spos(self).."; puncher="..name.."; ".. - "time_from_last_punch="..time_from_last_punch.."; ".. - "tool_capabilities="..tostring(dump(tool_capabilities)).."; ".. - "dir="..tostring(dump(dir)).."; damage="..damage) - end, - on_rightclick = function(self, clicker) - local name = get_object_name(clicker) - message("Callback entity: on_rightclick! pos="..spos(self).."; clicker="..name) - end, - on_death = function(self, killer) - local name = get_object_name(killer) - message("Callback entity: on_death! pos="..spos(self).."; killer="..name) - end, - on_attach_child = function(self, child) - local name = get_object_name(child) - message("Callback entity: on_attach_child! pos="..spos(self).."; child="..name) - end, - on_detach_child = function(self, child) - local name = get_object_name(child) - message("Callback entity: on_detach_child! pos="..spos(self).."; child="..name) - end, - on_detach = function(self, parent) - local name = get_object_name(parent) - message("Callback entity: on_detach! pos="..spos(self).."; parent="..name) - end, - get_staticdata = function(self) - message("Callback entity: get_staticdata! pos="..spos(self)) - end, -}) - --- Only test on_step callback -minetest.register_entity("testentities:callback_step", { - visual = "upright_sprite", - textures = { "testentities_callback_step.png" }, - on_step = function(self, dtime) - message("on_step callback entity: on_step! pos="..spos(self).."; dtime="..dtime) - end, -}) diff --git a/games/minimal/mods/testentities/init.lua b/games/minimal/mods/testentities/init.lua deleted file mode 100644 index df8c72ea7..000000000 --- a/games/minimal/mods/testentities/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -dofile(minetest.get_modpath("testentities").."/visuals.lua") -dofile(minetest.get_modpath("testentities").."/armor.lua") -dofile(minetest.get_modpath("testentities").."/callbacks.lua") diff --git a/games/minimal/mods/testentities/mod.conf b/games/minimal/mods/testentities/mod.conf deleted file mode 100644 index 7a8cb5a3e..000000000 --- a/games/minimal/mods/testentities/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = testentities -description = Example entities for testing diff --git a/games/minimal/mods/testentities/textures/testentities_armorball.png b/games/minimal/mods/testentities/textures/testentities_armorball.png deleted file mode 100644 index 88147bd1f..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_armorball.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_callback.png b/games/minimal/mods/testentities/textures/testentities_callback.png deleted file mode 100644 index c4c9066d1..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_callback.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_callback_step.png b/games/minimal/mods/testentities/textures/testentities_callback_step.png deleted file mode 100644 index b67506a97..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_callback_step.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_cube1.png b/games/minimal/mods/testentities/textures/testentities_cube1.png deleted file mode 100644 index c667e425f..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_cube1.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_cube2.png b/games/minimal/mods/testentities/textures/testentities_cube2.png deleted file mode 100644 index 481823420..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_cube2.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_cube3.png b/games/minimal/mods/testentities/textures/testentities_cube3.png deleted file mode 100644 index 03b5daa15..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_cube3.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_cube4.png b/games/minimal/mods/testentities/textures/testentities_cube4.png deleted file mode 100644 index 639204896..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_cube4.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_cube5.png b/games/minimal/mods/testentities/textures/testentities_cube5.png deleted file mode 100644 index d8acdf0b6..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_cube5.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_cube6.png b/games/minimal/mods/testentities/textures/testentities_cube6.png deleted file mode 100644 index 5f81a64d9..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_cube6.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_dungeon_master.png b/games/minimal/mods/testentities/textures/testentities_dungeon_master.png deleted file mode 100644 index 1e3107746..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_dungeon_master.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_sprite.png b/games/minimal/mods/testentities/textures/testentities_sprite.png deleted file mode 100644 index a4b019699..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_sprite.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_upright_sprite1.png b/games/minimal/mods/testentities/textures/testentities_upright_sprite1.png deleted file mode 100644 index 6242511df..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_upright_sprite1.png and /dev/null differ diff --git a/games/minimal/mods/testentities/textures/testentities_upright_sprite2.png b/games/minimal/mods/testentities/textures/testentities_upright_sprite2.png deleted file mode 100644 index a79a760e3..000000000 Binary files a/games/minimal/mods/testentities/textures/testentities_upright_sprite2.png and /dev/null differ diff --git a/games/minimal/mods/testentities/visuals.lua b/games/minimal/mods/testentities/visuals.lua deleted file mode 100644 index de346fd68..000000000 --- a/games/minimal/mods/testentities/visuals.lua +++ /dev/null @@ -1,74 +0,0 @@ --- Minimal test entities to test visuals - -minetest.register_entity("testentities:sprite", { - initial_properties = { - visual = "sprite", - textures = { "testentities_sprite.png" }, - }, -}) - -minetest.register_entity("testentities:upright_sprite", { - initial_properties = { - visual = "upright_sprite", - textures = { - "testentities_upright_sprite1.png", - "testentities_upright_sprite2.png", - }, - }, -}) - -minetest.register_entity("testentities:cube", { - initial_properties = { - visual = "cube", - textures = { - "testentities_cube1.png", - "testentities_cube2.png", - "testentities_cube3.png", - "testentities_cube4.png", - "testentities_cube5.png", - "testentities_cube6.png", - }, - }, -}) - -minetest.register_entity("testentities:item", { - initial_properties = { - visual = "item", - wield_item = "testnodes:normal", - }, -}) - -minetest.register_entity("testentities:wielditem", { - initial_properties = { - visual = "wielditem", - wield_item = "testnodes:normal", - }, -}) - -minetest.register_entity("testentities:mesh", { - initial_properties = { - visual = "mesh", - mesh = "testnodes_pyramid.obj", - textures = { - "testnodes_mesh_stripes2.png" - }, - }, -}) - --- Advanced visual tests - --- A test entity for testing animated and yaw-modulated sprites -minetest.register_entity("testentities:yawsprite", { - initial_properties = { - selectionbox = {-0.3, -0.5, -0.3, 0.3, 0.3, 0.3}, - visual = "sprite", - visual_size = {x=0.6666, y=1}, - textures = {"testentities_dungeon_master.png^[makealpha:128,0,0^[makealpha:128,128,0"}, - spritediv = {x=6, y=5}, - initial_sprite_basepos = {x=0, y=0}, - on_activate = function(self, staticdata) - self.object:set_sprite({x=0, y=0}, 1, 0, true) - end, - }, -}) - diff --git a/games/minimal/mods/testfood/init.lua b/games/minimal/mods/testfood/init.lua deleted file mode 100644 index a6236ff68..000000000 --- a/games/minimal/mods/testfood/init.lua +++ /dev/null @@ -1,24 +0,0 @@ -local S = minetest.get_translator("testfood") - -minetest.register_craftitem("testfood:good1", { - description = S("Good Food (+1)"), - inventory_image = "testfood_good.png", - on_use = minetest.item_eat(1), -}) -minetest.register_craftitem("testfood:good5", { - description = S("Good Food (+5)"), - inventory_image = "testfood_good2.png", - on_use = minetest.item_eat(5), -}) - -minetest.register_craftitem("testfood:bad1", { - description = S("Bad Food (-1)"), - inventory_image = "testfood_bad.png", - on_use = minetest.item_eat(-1), -}) -minetest.register_craftitem("testfood:bad5", { - description = S("Bad Food (-5)"), - inventory_image = "testfood_bad2.png", - on_use = minetest.item_eat(-5), -}) - diff --git a/games/minimal/mods/testfood/mod.conf b/games/minimal/mods/testfood/mod.conf deleted file mode 100644 index 7bff21b6e..000000000 --- a/games/minimal/mods/testfood/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = testfood -description = For testing food items diff --git a/games/minimal/mods/testfood/textures/testfood_bad.png b/games/minimal/mods/testfood/textures/testfood_bad.png deleted file mode 100644 index 6e9251440..000000000 Binary files a/games/minimal/mods/testfood/textures/testfood_bad.png and /dev/null differ diff --git a/games/minimal/mods/testfood/textures/testfood_bad2.png b/games/minimal/mods/testfood/textures/testfood_bad2.png deleted file mode 100644 index 22b567890..000000000 Binary files a/games/minimal/mods/testfood/textures/testfood_bad2.png and /dev/null differ diff --git a/games/minimal/mods/testfood/textures/testfood_good.png b/games/minimal/mods/testfood/textures/testfood_good.png deleted file mode 100644 index 31df7f5dd..000000000 Binary files a/games/minimal/mods/testfood/textures/testfood_good.png and /dev/null differ diff --git a/games/minimal/mods/testfood/textures/testfood_good2.png b/games/minimal/mods/testfood/textures/testfood_good2.png deleted file mode 100644 index e43dda209..000000000 Binary files a/games/minimal/mods/testfood/textures/testfood_good2.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/callbacks.lua b/games/minimal/mods/testformspec/callbacks.lua deleted file mode 100644 index 559380580..000000000 --- a/games/minimal/mods/testformspec/callbacks.lua +++ /dev/null @@ -1,51 +0,0 @@ -local callback_test = 0 - -local out = function(player, formname, fields, number) - local snum = "" - if number then - snum = " "..number - end - local msg = "Formspec callback"..snum..": player="..player:get_player_name()..", formname=\""..tostring(formname).."\", fields="..dump(fields) - minetest.chat_send_player(player:get_player_name(), msg) - minetest.log("action", msg) -end - -minetest.register_on_player_receive_fields(function(player, formname, fields) - if callback_test == 1 then - out(player, formname, fields) - elseif callback_test == 2 then - out(player, formname, fields, 1) - end -end) -minetest.register_on_player_receive_fields(function(player, formname, fields) - if callback_test == 2 then - out(player, formname, fields, 2) - return true -- Disable the first callback - end -end) -minetest.register_on_player_receive_fields(function(player, formname, fields) - if callback_test == 2 then - out(player, formname, fields, 3) - end -end) - -minetest.register_chatcommand("test_formspec_callbacks", { - params = "[ 0 | 1 | 2 ]", - description = "Test: Change formspec callbacks testing mode", - func = function(name, param) - local mode = tonumber(param) - if not mode then - callback_test = (callback_test + 1 % 3) - else - callback_test = mode - end - if callback_test == 1 then - minetest.chat_send_player(name, "Formspec callback test mode 1 enabled: Logging only") - elseif callback_test == 2 then - minetest.chat_send_player(name, "Formspec callback test mode 2 enabled: Three callbacks, disable pre-registered callbacks") - else - callback_test = 0 - minetest.chat_send_player(name, "Formspec callback test disabled!") - end - end -}) diff --git a/games/minimal/mods/testformspec/dummy_items.lua b/games/minimal/mods/testformspec/dummy_items.lua deleted file mode 100644 index 2037ae9cf..000000000 --- a/games/minimal/mods/testformspec/dummy_items.lua +++ /dev/null @@ -1,14 +0,0 @@ --- This code adds dummy items that are supposed to be used in formspecs --- for testing item_image formspec elements. - -minetest.register_node("testformspec:node", { - description = "Formspec Test Node", - tiles = { "testformspec_node.png" }, - groups = { dig_immediate = 3, dummy = 1 }, -}) - -minetest.register_craftitem("testformspec:item", { - description = "Formspec Test Item", - inventory_image = "testformspec_item.png", - groups = { dummy = 1 }, -}) diff --git a/games/minimal/mods/testformspec/formspec.lua b/games/minimal/mods/testformspec/formspec.lua deleted file mode 100644 index 08c1b6dc0..000000000 --- a/games/minimal/mods/testformspec/formspec.lua +++ /dev/null @@ -1,381 +0,0 @@ -local color = minetest.colorize - -local clip_fs = [[ - style_type[label,button,image_button,item_image_button, - tabheader,scrollbar,table,animated_image - ,field,textarea,checkbox,dropdown;noclip=%c] - - label[0,0;A clipping test] - button[0,1;3,0.8;clip_button;A clipping test] - image_button[0,2;3,0.8;testformspec_button_image.png;clip_image_button;A clipping test] - item_image_button[0,3;3,0.8;testformspec:item;clip_item_image_button;A clipping test] - tabheader[0,4.7;3,0.63;clip_tabheader;Clip,Test,Text,Tabs;1;false;false] - field[0,5;3,0.8;clip_field;Title;] - textarea[0,6;3,1;clip_textarea;Title;] - checkbox[0,7.5;clip_checkbox;This is a test;true] - dropdown[0,8;3,0.8;clip_dropdown;Select An Item,One,Two,Three,Four,Five;1] - scrollbar[0,9;3,0.8;horizontal;clip_scrollbar;3] - tablecolumns[text;text] - table[0,10;3,1;clip_table;one,two,three,four;1] - animated_image[-0.5,11;4.5,1;clip_animated_image;testformspec_animation.png;4;100] -]] - -local tabheaders_fs = [[ - tabheader[0,0;10,0.63;tabs_opaque;Opaque,Without,Border;1;false;false] - tabheader[0,1;10,0.63;tabs_opaque_border;Opaque,With,Border;1;false;true] - tabheader[0,2;10,0.63;tabs_transparent;Transparent,Without,Border;1;true;false] - tabheader[0,3;10,0.63;tabs_transparent_border;Transparent,With,Border;1;true;true] - tabheader[0,4;tabs_default;Default,Tabs;1] - tabheader[0,6;10,0.5;tabs_size1;Height=0.5;1;false;false] - tabheader[2,6;10,0.75;tabs_size1;Height=0.75;1;false;false] - tabheader[4,6;10,1;tabs_size2;Height=1;1;false;false] - tabheader[6,6;10,1.25;tabs_size2;Height=1.25;1;false;false] - tabheader[8,6;10,1.5;tabs_size2;Height=1.5;1;false;false] -]] - -local hypertext_basic = [[ -Normal test -This is a normal text. - -style test - - . - - -Tag test -normal -mono -bold -italic -underlined -big -bigger -left -
center
-right -justify. Here comes a blind text: Lorem testum dolor sit amet consecutor celeron fiftifahivus e shadoninia e smalus jokus anrus relsocutoti rubenwardus. Erasputinus hara holisti dominus wusi. Grumarinsti erltusmuate ol fortitusti fla flo, blani burki e sfani fahif. Ultae ratii, e megus gigae don anonimus. Grinus dimondus krockus e nore. Endus finalus nowus comus endus o blindus tekstus. - -Custom tag test - - - - - -color=green -Action: color=green -Action: hovercolor=yellow -size=24 -font=mono -color=green font=mono size=24 - -action test -action - -img test -Normal: - -width=48 height=48: - -float=left: - -float=right: - - -item test -Normal: - -width=48 height=48 - -angle=30,0,0: - -angle=0,30,0: - -angle=0,0,30: - -rotate=yes: - -rotate=100,0,0: - -rotate=0,100,0: - -rotate=0,0,100: - -rotate=50,75,100: - -angle=-30,-45,90 rotate=100,150,-50: -]] - -local hypertext_global = [[ - -This is a test of the global tag. The parameters are: -background=gray margin=20 valign=bottom halign=right color=pink hovercolor=purple size=12 font=mono -action]] - -local hypertext_fs = "hypertext[0,0;11,9;hypertext;"..minetest.formspec_escape(hypertext_basic).."]".. - "hypertext[0,9.5;11,2.5;hypertext;"..minetest.formspec_escape(hypertext_global).."]" - -local style_fs = [[ - style[one_btn1;bgcolor=red;textcolor=yellow;bgcolor_hovered=orange; - bgcolor_pressed=purple] - button[0,0;2.5,0.8;one_btn1;Button] - - style[one_btn2;border=false;textcolor=cyan] ]].. - "button[0,1.05;2.5,0.8;one_btn2;Text " .. color("#FF0", "Yellow") .. [[] - - style[one_btn3;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png; - bgimg_pressed=testformspec_pressed.png] - button[0,2.1;1,1;one_btn3;Border] - - style[one_btn4;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png; - bgimg_pressed=testformspec_pressed.png;border=false] - button[1.25,2.1;1,1;one_btn4;NoBor] - - style[one_btn5;bgimg=testformspec_button_image.png;bgimg_hovered=testformspec_hovered.png; - bgimg_pressed=testformspec_pressed.png;border=false;alpha=false] - button[0,3.35;1,1;one_btn5;Alph] - - style[one_btn6;border=true] - image_button[0,4.6;1,1;testformspec_button_image.png;one_btn6;Border] - - style[one_btn7;border=false] - image_button[1.25,4.6;1,1;testformspec_button_image.png;one_btn7;NoBor] - - style[one_btn8;border=false] - image_button[0,5.85;1,1;testformspec_button_image.png;one_btn8;Border;false;true;testformspec_pressed.png] - - style[one_btn9;border=true] - image_button[1.25,5.85;1,1;testformspec_button_image.png;one_btn9;NoBor;false;false;testformspec_pressed.png] - - style[one_btn10;alpha=false] - image_button[0,7.1;1,1;testformspec_button_image.png;one_btn10;NoAlpha] - - style[one_btn11;alpha=true] - image_button[1.25,7.1;1,1;testformspec_button_image.png;one_btn11;Alpha] - - style[one_btn12;border=true] - item_image_button[0,8.35;1,1;testformspec:item;one_btn12;Border] - - style[one_btn13;border=false] - item_image_button[1.25,8.35;1,1;testformspec:item;one_btn13;NoBor] - - style[one_btn14;border=false;bgimg=testformspec_bg.png;fgimg=testformspec_button_image.png] - style[one_btn14:hovered;bgimg=testformspec_bg_hovered.png;fgimg=testformspec_hovered.png;textcolor=yellow] - style[one_btn14:pressed;bgimg=testformspec_bg_pressed.png;fgimg=testformspec_pressed.png;textcolor=blue] - style[one_btn14:hovered+pressed;textcolor=purple] - image_button[0,9.6;1,1;testformspec_button_image.png;one_btn14;Bg] - - style[one_btn15;border=false;bgimg=testformspec_bg.png;bgimg_hovered=testformspec_bg_hovered.png;bgimg_pressed=testformspec_bg_pressed.png] - item_image_button[1.25,9.6;1,1;testformspec:item;one_btn15;Bg] - - style[one_btn16;border=false;bgimg=testformspec_bg_9slice.png;bgimg_hovered=testformspec_bg_9slice_hovered.png;bgimg_pressed=testformspec_bg_9slice_pressed.png;bgimg_middle=4,6] - button[2.5,9.6;2,1;one_btn16;9-Slice Bg] - - - - container[2.75,0] - - style[one_tb1;textcolor=Yellow] - tabheader[0,3;2.5,0.63;one_tb1;Yellow,Text,Tabs;1;false;false] - - style[one_f1;textcolor=yellow] - field[0,4.25;2.5,0.8;one_f1;Field One;Yellow Text] - - style[one_f2;border=false;textcolor=cyan] - field[0,5.75;2.5,0.8;one_f2;Field Two;Borderless Cyan Text] - - style[one_f3;textcolor=yellow] - textarea[0,7.025;2.5,0.8;one_f3;Label;]] .. - minetest.formspec_escape("Yellow Text\nLine two") .. [[ ] - - style[one_f4;border=false;textcolor=cyan] - textarea[0,8.324999999999999;2.5,0.8;one_f4;Label;]] .. - minetest.formspec_escape("Borderless Cyan Text\nLine two") .. [[ ] - - container_end[] -]] - -local scroll_fs = - "button[8.5,1;4,1;outside;Outside of container]".. - "box[1,1;8,6;#00aa]".. - "scroll_container[1,1;8,6;scrbar;vertical]".. - "button[0,1;1,1;lorem;Lorem]".. - "button[0,10;1,1;ipsum;Ipsum]".. - "pwdfield[2,2;1,1;lorem2;Lorem]".. - "list[current_player;main;4,4;1,5;]".. - "box[2,5;3,2;#ffff00]".. - "image[1,10;3,2;testformspec_item.png]".. - "image[3,1;testformspec_item.png]".. - "item_image[2,6;3,2;testformspec:node]".. - "label[2,15;bla Bli\nfoo bar]".. - "item_image_button[2,3;1,1;testformspec:node;itemimagebutton;ItemImageButton]".. - "tooltip[0,11;3,2;Buz;#f00;#000]".. - "box[0,11;3,2;#00ff00]".. - "hypertext[3,13;3,3;;" .. hypertext_basic .. "]" .. - "container[0,18]".. - "box[1,2;3,2;#0a0a]".. - "scroll_container[1,2;3,2;scrbar2;horizontal;0.06]".. - "button[0,0;6,1;butnest;Nest]".. - "label[10,0.5;nest]".. - "scroll_container_end[]".. - "scrollbar[1,0;3.5,0.3;horizontal;scrbar2;0]".. - "container_end[]".. - "dropdown[0,6;2;hmdrpdwn;apple,bulb;1]".. - "image_button[0,4;2,2;testformspec_button_image.png;imagebutton;bbbbtt;false;true;testformspec_pressed.png]".. - "box[1,22.5;4,1;#a00a]".. - "scroll_container_end[]".. - "scrollbaroptions[max=170]".. -- lowest seen pos is: 0.1*170+6=23 (factor*max+height) - "scrollbar[7.5,0;0.3,4;vertical;scrbar;0]".. - "scrollbar[8,0;0.3,4;vertical;scrbarhmmm;0]".. - "dropdown[0,6;2;hmdrpdwnnn;Outside,of,container;1]" - ---style_type[label;textcolor=green] ---label[0,0;Green] ---style_type[label;textcolor=blue] ---label[0,1;Blue] ---style_type[label;textcolor=;border=true] ---label[1.2,0;Border] ---style_type[label;border=true;bgcolor=red] ---label[1.2,1;Background] ---style_type[label;border=;bgcolor=] ---label[0.75,2;Reset] - - -local pages = { - -- Real Coordinates - [[ - formspec_version[3] - size[12,13] - image_button[0,0;1,1;logo.png;rc_image_button_1x1;1x1] - image_button[1,0;2,2;logo.png;rc_image_button_2x2;2x2] - button[0,2;1,1;rc_button_1x1;1x1] - button[1,2;2,2;rc_button_2x2;2x2] - item_image[0,4;1,1;air] - item_image[1,4;2,2;air] - item_image_button[0,6;1,1;testformspec:node;rc_item_image_button_1x1;1x1] - item_image_button[1,6;2,2;testformspec:node;rc_item_image_button_2x2;2x2] - field[3,.5;3,.5;rc_field;Field;text] - pwdfield[6,.5;3,1;rc_pwdfield;Password Field] - field[3,1;3,1;;Read-Only Field;text] - textarea[3,2;3,.5;rc_textarea_small;Textarea;text] - textarea[6,2;3,2;rc_textarea_big;Textarea;text\nmore text] - textarea[3,3;3,1;;Read-Only Textarea;text\nmore text] - textlist[3,4;3,2;rc_textlist;Textlist,Perfect Coordinates;1;false] - tableoptions[highlight=#ABCDEF75;background=#00000055;border=false] - table[6,4;3,2;rc_table;Table,Cool Stuff,Foo,Bar;2] - dropdown[3,6;3,1;rc_dropdown_small;This,is,a,dropdown;1] - dropdown[6,6;3,2;rc_dropdown_big;I,am,a,bigger,dropdown;5] - image[0,8;3,2;ignore.png] - box[3,7;3,1;#00A3FF] - checkbox[3,8;rc_checkbox_1;Check me!;false] - checkbox[3,9;rc_checkbox_2;Uncheck me now!;true] - scrollbar[0,11.5;11.5,.5;horizontal;rc_scrollbar_horizontal;500] - scrollbar[11.5,0;.5,11.5;vertical;rc_scrollbar_vertical;0] - list[current_player;main;6,8;3,2;1] - button[9,0;2.5,1;rc_empty_button_1;] - button[9,1;2.5,1;rc_empty_button_2;] - button[9,2;2.5,1;rc_empty_button_3;] ]].. - "label[9,0.5;This is a label.\nLine\nLine\nLine\nEnd]".. - [[button[9,3;1,1;rc_empty_button_4;] - vertlabel[9,4;VERT] - label[10,3;HORIZ] - tabheader[8,0;6,0.65;rc_tabheader;Tab 1,Tab 2,Tab 3,Secrets;1;false;false] - ]], - -- Style - - "formspec_version[3]size[12,13]" .. - ("label[0.375,0.375;Styled - %s %s]"):format( - color("#F00", "red text"), - color("#77FF00CC", "green text")) .. - "label[6.375,0.375;Unstyled]" .. - "box[0,0.75;12,0.1;#999]" .. - "box[6,0.85;0.1,11.15;#999]" .. - "container[0.375,1.225]" .. - style_fs .. - "container_end[]container[6.375,1.225]" .. - style_fs:gsub("one_", "two_"):gsub("style%[[^%]]+%]", ""):gsub("style_type%[[^%]]+%]", "") .. - "container_end[]", - - -- Noclip - "formspec_version[3]size[12,13]" .. - "label[0.1,0.5;Clip]" .. - "container[-2.5,1]" .. clip_fs:gsub("%%c", "false") .. "container_end[]" .. - "label[11,0.5;Noclip]" .. - "container[11.5,1]" .. clip_fs:gsub("%%c", "true") .. "container_end[]", - - -- Hypertext - "size[12,13]real_coordinates[true]" .. - "container[0.5,0.5]" .. hypertext_fs .. "container_end[]", - - -- Tabheaders - "size[12,13]real_coordinates[true]" .. - "container[0.5,1.5]" .. tabheaders_fs .. "container_end[]", - - -- Animation - [[ - formspec_version[3] - size[12,13] - animated_image[0.5,0.5;1,1;;testformspec_animation.png;4;100] - animated_image[0.5,1.75;1,1;;testformspec_animation.jpg;4;100] - animated_image[1.75,0.5;1,1;;testformspec_animation.png;100;100] - animated_image[3,0.5;1,1;ani_img_1;testformspec_animation.png;4;1000] - button[4.25,0.5;1,1;ani_btn_1;Current -Number] - animated_image[3,1.75;1,1;ani_img_2;testformspec_animation.png;4;1000;2] - button[4.25,1.75;1,1;ani_btn_2;Current -Number] - animated_image[3,3;1,1;;testformspec_animation.png;4;0] - animated_image[3,4.25;1,1;;testformspec_animation.png;4;0;3] - animated_image[5.5,0.5;5,2;;testformspec_animation.png;4;100] - animated_image[5.5,2.75;5,2;;testformspec_animation.jpg;4;100] - ]], - - -- Scroll containers - "formspec_version[3]size[12,13]" .. - scroll_fs, -} - -local function show_test_formspec(pname, page_id) - page_id = page_id or 2 - - local fs = pages[page_id] .. "tabheader[0,0;8,0.65;maintabs;Real Coord,Styles,Noclip,Hypertext,Tabs,Anim,ScrollC;" .. page_id .. ";false;false]" - - minetest.show_formspec(pname, "testformspec:formspec", fs) -end - -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "testformspec:formspec" then - return false - end - - - if fields.maintabs then - show_test_formspec(player:get_player_name(), tonumber(fields.maintabs)) - return true - end - - if fields.ani_img_1 and fields.ani_btn_1 then - minetest.chat_send_player(player:get_player_name(), "ani_img_1 = " .. tostring(fields.ani_img_1)) - return true - elseif fields.ani_img_2 and fields.ani_btn_2 then - minetest.chat_send_player(player:get_player_name(), "ani_img_2 = " .. tostring(fields.ani_img_2)) - return true - end - - if fields.hypertext then - minetest.chat_send_player(player:get_player_name(), "Hypertext action received: " .. tostring(fields.hypertext)) - return true - end -end) - -minetest.register_chatcommand("test_formspec", { - params = "", - description = "Open the test formspec", - func = function(name) - if not minetest.get_player_by_name(name) then - return false, "You need to be online!" - end - - show_test_formspec(name) - return true - end, -}) diff --git a/games/minimal/mods/testformspec/init.lua b/games/minimal/mods/testformspec/init.lua deleted file mode 100644 index 23b565f08..000000000 --- a/games/minimal/mods/testformspec/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -dofile(minetest.get_modpath("testformspec").."/dummy_items.lua") -dofile(minetest.get_modpath("testformspec").."/formspec.lua") -dofile(minetest.get_modpath("testformspec").."/callbacks.lua") diff --git a/games/minimal/mods/testformspec/mod.conf b/games/minimal/mods/testformspec/mod.conf deleted file mode 100644 index 00eac307a..000000000 --- a/games/minimal/mods/testformspec/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = testformspec -description = Contains an example formspec to test all the features of formspecs diff --git a/games/minimal/mods/testformspec/textures/testformspec_animation.jpg b/games/minimal/mods/testformspec/textures/testformspec_animation.jpg deleted file mode 100644 index b98ca2677..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_animation.jpg and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_animation.png b/games/minimal/mods/testformspec/textures/testformspec_animation.png deleted file mode 100644 index b972e5dbb..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_animation.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_bg.png b/games/minimal/mods/testformspec/textures/testformspec_bg.png deleted file mode 100644 index cd1e50900..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_bg.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_bg_9slice.png b/games/minimal/mods/testformspec/textures/testformspec_bg_9slice.png deleted file mode 100644 index 34433ac82..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_bg_9slice.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_bg_9slice_hovered.png b/games/minimal/mods/testformspec/textures/testformspec_bg_9slice_hovered.png deleted file mode 100644 index 01c2dc777..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_bg_9slice_hovered.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_bg_9slice_pressed.png b/games/minimal/mods/testformspec/textures/testformspec_bg_9slice_pressed.png deleted file mode 100644 index 0cbac7536..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_bg_9slice_pressed.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_bg_hovered.png b/games/minimal/mods/testformspec/textures/testformspec_bg_hovered.png deleted file mode 100644 index 3ebbb988c..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_bg_hovered.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_bg_pressed.png b/games/minimal/mods/testformspec/textures/testformspec_bg_pressed.png deleted file mode 100644 index 2fb5fc21e..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_bg_pressed.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_button_image.png b/games/minimal/mods/testformspec/textures/testformspec_button_image.png deleted file mode 100644 index 75c438a9a..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_button_image.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_hovered.png b/games/minimal/mods/testformspec/textures/testformspec_hovered.png deleted file mode 100644 index 3ccad30a2..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_hovered.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_item.png b/games/minimal/mods/testformspec/textures/testformspec_item.png deleted file mode 100644 index 4fd823b55..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_item.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_node.png b/games/minimal/mods/testformspec/textures/testformspec_node.png deleted file mode 100644 index c107f28a3..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_node.png and /dev/null differ diff --git a/games/minimal/mods/testformspec/textures/testformspec_pressed.png b/games/minimal/mods/testformspec/textures/testformspec_pressed.png deleted file mode 100644 index 45c504f27..000000000 Binary files a/games/minimal/mods/testformspec/textures/testformspec_pressed.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/README.md b/games/minimal/mods/testnodes/README.md deleted file mode 100644 index 13ed972c0..000000000 --- a/games/minimal/mods/testnodes/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Test Nodes - -This mod contains a bunch of basic nodes to test development stuff. -Most nodes are kept as minimal as possible in order to show off one particular feature of the engine, to make testing stuff easier. - -This mod includes tests for: - -* drawtypes -* paramtype2's -* node properties such as damage, drowning, falling, etc. -* other random stuff diff --git a/games/minimal/mods/testnodes/drawtypes.lua b/games/minimal/mods/testnodes/drawtypes.lua deleted file mode 100644 index 35fda960f..000000000 --- a/games/minimal/mods/testnodes/drawtypes.lua +++ /dev/null @@ -1,517 +0,0 @@ ---[[ Drawtype Test: This file tests out and provides examples for -all drawtypes in Minetest. It is attempted to keep the node -definitions as simple and minimal as possible to keep -side-effects to a minimum. - -How to read the node definitions: -There are two parts which are separated by 2 newlines: -The first part contains the things that are more or less essential -for defining the drawtype (except description, which is -at the top for readability). -The second part (after the 2 newlines) contains stuff that are -unrelated to the drawtype, stuff that is mostly there to make -testing this node easier and more convenient. -]] - -local S = minetest.get_translator("testnodes") - --- If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. --- This is due to . --- This is only added to make the items more visible to avoid confusion, but you will no longer see --- the default inventory images for these items. When you want to test the default inventory image of drawtypes, --- this should be turned off. --- TODO: Remove support for fallback inventory image as soon #9209 is fixed. -local SHOW_FALLBACK_IMAGE = minetest.settings:get_bool("testnodes_show_fallback_image", false) - -local fallback_image = function(img) - if SHOW_FALLBACK_IMAGE then - return img - else - return nil - end -end - --- A regular cube -minetest.register_node("testnodes:normal", { - description = S("Normal Drawtype Test Node"), - drawtype = "normal", - tiles = { "testnodes_normal.png" }, - - groups = { dig_immediate = 3 }, -}) - --- Standard glasslike node -minetest.register_node("testnodes:glasslike", { - description = S("Glasslike Drawtype Test Node"), - drawtype = "glasslike", - paramtype = "light", - tiles = { "testnodes_glasslike.png" }, - - groups = { dig_immediate = 3 }, -}) - --- Glasslike framed with the two textures (normal and "detail") -minetest.register_node("testnodes:glasslike_framed", { - description = S("Glasslike Framed Drawtype Test Node"), - drawtype = "glasslike_framed", - paramtype = "light", - tiles = { - "testnodes_glasslike_framed.png", - "testnodes_glasslike_detail.png", - }, - - - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - --- Like the one above, but without the "detail" texture (texture 2). --- This node was added to see how the engine behaves when the "detail" texture --- is missing. -minetest.register_node("testnodes:glasslike_framed_no_detail", { - description = S("Glasslike Framed without Detail Drawtype Test Node"), - drawtype = "glasslike_framed", - paramtype = "light", - tiles = { "testnodes_glasslike_framed2.png" }, - - - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - - -minetest.register_node("testnodes:glasslike_framed_optional", { - description = S("Glasslike Framed Optional Drawtype Test Node"), - drawtype = "glasslike_framed_optional", - paramtype = "light", - tiles = { - "testnodes_glasslike_framed_optional.png", - "testnodes_glasslike_detail.png", - }, - - - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - - - -minetest.register_node("testnodes:allfaces", { - description = S("Allfaces Drawtype Test Node"), - drawtype = "allfaces", - paramtype = "light", - tiles = { "testnodes_allfaces.png" }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:allfaces_optional", { - description = S("Allfaces Optional Drawtype Test Node"), - drawtype = "allfaces_optional", - paramtype = "light", - tiles = { "testnodes_allfaces_optional.png" }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:allfaces_optional_waving", { - description = S("Waving Allfaces Optional Drawtype Test Node"), - drawtype = "allfaces_optional", - paramtype = "light", - tiles = { "testnodes_allfaces_optional.png^[brighten" }, - waving = 2, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:firelike", { - description = S("Firelike Drawtype Test Node"), - drawtype = "firelike", - paramtype = "light", - tiles = { "testnodes_firelike.png" }, - - - walkable = false, - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:fencelike", { - description = S("Fencelike Drawtype Test Node"), - drawtype = "fencelike", - paramtype = "light", - tiles = { "testnodes_fencelike.png" }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:torchlike", { - description = S("Wallmounted Torchlike Drawtype Test Node"), - drawtype = "torchlike", - paramtype = "light", - paramtype2 = "wallmounted", - tiles = { - "testnodes_torchlike_floor.png", - "testnodes_torchlike_ceiling.png", - "testnodes_torchlike_wall.png", - }, - - - walkable = false, - sunlight_propagates = true, - groups = { dig_immediate = 3 }, - inventory_image = fallback_image("testnodes_torchlike_floor.png"), -}) - -minetest.register_node("testnodes:signlike", { - description = S("Wallmounted Signlike Drawtype Test Node"), - drawtype = "signlike", - paramtype = "light", - paramtype2 = "wallmounted", - tiles = { "testnodes_signlike.png" }, - - - walkable = false, - groups = { dig_immediate = 3 }, - sunlight_propagates = true, - inventory_image = fallback_image("testnodes_signlike.png"), -}) - -minetest.register_node("testnodes:plantlike", { - description = S("Plantlike Drawtype Test Node"), - drawtype = "plantlike", - paramtype = "light", - tiles = { "testnodes_plantlike.png" }, - - - walkable = false, - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:plantlike_waving", { - description = S("Waving Plantlike Drawtype Test Node"), - drawtype = "plantlike", - paramtype = "light", - tiles = { "testnodes_plantlike_waving.png" }, - waving = 1, - - - walkable = false, - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - - - --- param2 will rotate -minetest.register_node("testnodes:plantlike_degrotate", { - description = S("Degrotate Plantlike Drawtype Test Node"), - drawtype = "plantlike", - paramtype = "light", - paramtype2 = "degrotate", - tiles = { "testnodes_plantlike_degrotate.png" }, - - - walkable = false, - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - --- param2 will change height -minetest.register_node("testnodes:plantlike_leveled", { - description = S("Leveled Plantlike Drawtype Test Node"), - drawtype = "plantlike", - paramtype = "light", - paramtype2 = "leveled", - tiles = { - { name = "testnodes_plantlike_leveled.png", tileable_vertical = true }, - }, - - - -- We set a default param2 here only for convenience, to make the "plant" visible after placement - place_param2 = 8, - walkable = false, - sunlight_propagates = true, - groups = { dig_immediate = 3 }, -}) - --- param2 changes shape -minetest.register_node("testnodes:plantlike_meshoptions", { - description = S("Meshoptions Plantlike Drawtype Test Node"), - drawtype = "plantlike", - paramtype = "light", - paramtype2 = "meshoptions", - tiles = { "testnodes_plantlike_meshoptions.png" }, - - - walkable = false, - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:plantlike_rooted", { - description = S("Rooted Plantlike Drawtype Test Node"), - drawtype = "plantlike_rooted", - paramtype = "light", - tiles = { "testnodes_plantlike_rooted_base.png" }, - special_tiles = { "testnodes_plantlike_rooted.png" }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:plantlike_rooted_waving", { - description = S("Waving Rooted Plantlike Drawtype Test Node"), - drawtype = "plantlike_rooted", - paramtype = "light", - tiles = { - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base_side_waving.png", - }, - special_tiles = { "testnodes_plantlike_rooted_waving.png" }, - waving = 1, - - groups = { dig_immediate = 3 }, -}) - --- param2 changes height -minetest.register_node("testnodes:plantlike_rooted_leveled", { - description = S("Leveled Rooted Plantlike Drawtype Test Node"), - drawtype = "plantlike_rooted", - paramtype = "light", - paramtype2 = "leveled", - tiles = { - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base_side_leveled.png", - }, - special_tiles = { - { name = "testnodes_plantlike_rooted_leveled.png", tileable_vertical = true }, - }, - - - -- We set a default param2 here only for convenience, to make the "plant" visible after placement - place_param2 = 8, - groups = { dig_immediate = 3 }, -}) - --- param2 changes shape -minetest.register_node("testnodes:plantlike_rooted_meshoptions", { - description = S("Meshoptions Rooted Plantlike Drawtype Test Node"), - drawtype = "plantlike_rooted", - paramtype = "light", - paramtype2 = "meshoptions", - tiles = { - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base_side_meshoptions.png", - }, - special_tiles = { - "testnodes_plantlike_rooted_meshoptions.png", - }, - - groups = { dig_immediate = 3 }, -}) - --- param2 changes rotation -minetest.register_node("testnodes:plantlike_rooted_degrotate", { - description = S("Degrotate Rooted Plantlike Drawtype Test Node"), - drawtype = "plantlike_rooted", - paramtype = "light", - paramtype2 = "degrotate", - tiles = { - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base.png", - "testnodes_plantlike_rooted_base_side_degrotate.png", - }, - special_tiles = { - "testnodes_plantlike_rooted_degrotate.png", - }, - - groups = { dig_immediate = 3 }, -}) - --- Demonstrative liquid nodes, source and flowing form. This is only the --- drawtype, no physical liquid properties are used -minetest.register_node("testnodes:liquid", { - description = S("Source Liquid Drawtype Test Node"), - drawtype = "liquid", - paramtype = "light", - tiles = { - "testnodes_liquidsource.png", - }, - special_tiles = { - {name="testnodes_liquidsource.png", backface_culling=false}, - {name="testnodes_liquidsource.png", backface_culling=true}, - }, - use_texture_alpha = true, - - - walkable = false, - liquid_alternative_flowing = "testnodes:liquid_flowing", - liquid_alternative_source = "testnodes:liquid", - groups = { dig_immediate = 3 }, -}) -minetest.register_node("testnodes:liquid_flowing", { - description = S("Flowing Liquid Drawtype Test Node"), - drawtype = "flowingliquid", - paramtype = "light", - paramtype2 = "flowingliquid", - tiles = { - "testnodes_liquidflowing.png", - }, - special_tiles = { - {name="testnodes_liquidflowing.png", backface_culling=false}, - {name="testnodes_liquidflowing.png", backface_culling=false}, - }, - use_texture_alpha = true, - - - walkable = false, - liquid_alternative_flowing = "testnodes:liquid_flowing", - liquid_alternative_source = "testnodes:liquid", - groups = { dig_immediate = 3 }, -}) -minetest.register_node("testnodes:liquid_waving", { - description = S("Waving Source Liquid Drawtype Test Node"), - drawtype = "liquid", - paramtype = "light", - tiles = { - "testnodes_liquidsource.png^[brighten", - }, - special_tiles = { - {name="testnodes_liquidsource.png^[brighten", backface_culling=false}, - {name="testnodes_liquidsource.png^[brighten", backface_culling=true}, - }, - use_texture_alpha = true, - waving = 3, - - - walkable = false, - liquid_alternative_flowing = "testnodes:liquid_flowing", - liquid_alternative_source = "testnodes:liquid", - groups = { dig_immediate = 3 }, -}) -minetest.register_node("testnodes:liquid_flowing_waving", { - description = S("Waving Flowing Liquid Drawtype Test Node"), - drawtype = "flowingliquid", - paramtype = "light", - paramtype2 = "flowingliquid", - tiles = { - "testnodes_liquidflowing.png^[brighten", - }, - special_tiles = { - {name="testnodes_liquidflowing.png^[brighten", backface_culling=false}, - {name="testnodes_liquidflowing.png^[brighten", backface_culling=false}, - }, - use_texture_alpha = true, - waving = 3, - - - walkable = false, - liquid_alternative_flowing = "testnodes:liquid_flowing", - liquid_alternative_source = "testnodes:liquid", - groups = { dig_immediate = 3 }, -}) - - - --- Invisible node -minetest.register_node("testnodes:airlike", { - description = S("Airlike Drawtype Test Node"), - drawtype = "airlike", - paramtype = "light", - - - walkable = false, - groups = { dig_immediate = 3 }, - sunlight_propagates = true, - inventory_image = fallback_image("testnodes_airlike.png"), -}) - --- param2 changes liquid height -minetest.register_node("testnodes:glassliquid", { - description = S("Glasslike Liquid Level Drawtype Test Node"), - drawtype = "glasslike_framed", - paramtype = "light", - paramtype2 = "glasslikeliquidlevel", - tiles = { - "testnodes_glasslikeliquid.png", - }, - special_tiles = { - "testnodes_liquid.png", - }, - - groups = { dig_immediate = 3 }, -}) - --- Adding many raillike examples, primarily to demonstrate the behavior of --- "raillike groups". Nodes of the same type (rail, groupless, line, street) --- should connect to nodes of the same "rail type" (=same shape, different --- color) only. -local rails = { - { "rail", {"testnodes_rail_straight.png", "testnodes_rail_curved.png", "testnodes_rail_t_junction.png", "testnodes_rail_crossing.png"} }, - { "line", {"testnodes_line_straight.png", "testnodes_line_curved.png", "testnodes_line_t_junction.png", "testnodes_line_crossing.png"}, }, - { "street", {"testnodes_street_straight.png", "testnodes_street_curved.png", "testnodes_street_t_junction.png", "testnodes_street_crossing.png"}, }, - -- the "groupless" nodes are nodes in which the "connect_to_raillike" group is not set - { "groupless", {"testnodes_rail2_straight.png", "testnodes_rail2_curved.png", "testnodes_rail2_t_junction.png", "testnodes_rail2_crossing.png"} }, -} -local colors = { "", "cyan", "red" } - -for r=1, #rails do - local id = rails[r][1] - local tiles = rails[r][2] - local raillike_group - if id ~= "groupless" then - raillike_group = minetest.raillike_group(id) - end - for c=1, #colors do - local color - if colors[c] ~= "" then - color = colors[c] - end - minetest.register_node("testnodes:raillike_"..id..c, { - description = S("Raillike Drawtype Test Node: @1 @2", id, c), - drawtype = "raillike", - paramtype = "light", - tiles = tiles, - groups = { connect_to_raillike = raillike_group, dig_immediate = 3 }, - - - color = color, - selection_box = { - type = "fixed", - fixed = {{-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}}, - }, - sunlight_propagates = true, - walkable = false, - }) - end -end - - - --- Add visual_scale variants of previous nodes for half and double size -local scale = function(subname, desc_double, desc_half) - local original = "testnodes:"..subname - local def = table.copy(minetest.registered_items[original]) - def.visual_scale = 2.0 - def.description = desc_double - minetest.register_node("testnodes:"..subname.."_double", def) - def = table.copy(minetest.registered_items[original]) - def.visual_scale = 0.5 - def.description = desc_half - minetest.register_node("testnodes:"..subname.."_half", def) -end - -scale("plantlike", - S("Double-sized Plantlike Drawtype Test Node"), - S("Half-sized Plantlike Drawtype Test Node")) -scale("torchlike", - S("Double-sized Wallmounted Torchlike Drawtype Test Node"), - S("Half-sized Wallmounted Torchlike Drawtype Test Node")) -scale("signlike", - S("Double-sized Wallmounted Signlike Drawtype Test Node"), - S("Half-sized Wallmounted Signlike Drawtype Test Node")) -scale("firelike", - S("Double-sized Firelike Drawtype Test Node"), - S("Half-sized Firelike Drawtype Test Node")) diff --git a/games/minimal/mods/testnodes/init.lua b/games/minimal/mods/testnodes/init.lua deleted file mode 100644 index 92e2c5630..000000000 --- a/games/minimal/mods/testnodes/init.lua +++ /dev/null @@ -1,10 +0,0 @@ -local path = minetest.get_modpath(minetest.get_current_modname()) - -dofile(path.."/drawtypes.lua") -dofile(path.."/meshes.lua") -dofile(path.."/nodeboxes.lua") -dofile(path.."/param2.lua") -dofile(path.."/properties.lua") -dofile(path.."/liquids.lua") -dofile(path.."/light.lua") -dofile(path.."/textures.lua") diff --git a/games/minimal/mods/testnodes/light.lua b/games/minimal/mods/testnodes/light.lua deleted file mode 100644 index 94409e83f..000000000 --- a/games/minimal/mods/testnodes/light.lua +++ /dev/null @@ -1,48 +0,0 @@ --- Test Nodes: Light test - -local S = minetest.get_translator("testnodes") - --- All possible light levels -for i=1, minetest.LIGHT_MAX do - minetest.register_node("testnodes:light"..i, { - description = S("Light Source (@1)", i), - paramtype = "light", - light_source = i, - - - tiles ={"testnodes_light_"..i..".png"}, - drawtype = "glasslike", - walkable = false, - sunlight_propagates = true, - is_ground_content = false, - groups = {dig_immediate=3}, - }) -end - --- Lets light through, but not sunlight, leading to a --- reduction in light level when light passes through -minetest.register_node("testnodes:sunlight_filter", { - description = S("Sunlight Filter"), - paramtype = "light", - - - drawtype = "glasslike", - tiles = { - "testnodes_sunlight_filter.png", - }, - groups = { dig_immediate = 3 }, -}) - --- Lets light and sunlight through without obstruction -minetest.register_node("testnodes:sunlight_propagator", { - description = S("Sunlight Propagator"), - paramtype = "light", - sunlight_propagates = true, - - - drawtype = "glasslike", - tiles = { - "testnodes_sunlight_filter.png^[brighten", - }, - groups = { dig_immediate = 3 }, -}) diff --git a/games/minimal/mods/testnodes/liquids.lua b/games/minimal/mods/testnodes/liquids.lua deleted file mode 100644 index e316782ad..000000000 --- a/games/minimal/mods/testnodes/liquids.lua +++ /dev/null @@ -1,91 +0,0 @@ --- Add liquids for ranges and viscosity levels 0-8 - -for d=0, 8 do - minetest.register_node("testnodes:rliquid_"..d, { - description = "Test Liquid Source, Range "..d, - drawtype = "liquid", - tiles = {"testnodes_liquidsource_r"..d..".png"}, - special_tiles = { - {name = "testnodes_liquidsource_r"..d..".png", backface_culling = false}, - {name = "testnodes_liquidsource_r"..d..".png", backface_culling = true}, - }, - alpha = 192, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - liquidtype = "source", - liquid_alternative_flowing = "testnodes:rliquid_flowing_"..d, - liquid_alternative_source = "testnodes:rliquid_"..d, - liquid_range = d, - }) - - minetest.register_node("testnodes:rliquid_flowing_"..d, { - description = "Flowing Test Liquid, Range "..d, - drawtype = "flowingliquid", - tiles = {"testnodes_liquidflowing_r"..d..".png"}, - special_tiles = { - {name = "testnodes_liquidflowing_r"..d..".png", backface_culling = false}, - {name = "testnodes_liquidflowing_r"..d..".png", backface_culling = false}, - }, - alpha = 192, - paramtype = "light", - paramtype2 = "flowingliquid", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - liquidtype = "flowing", - liquid_alternative_flowing = "testnodes:rliquid_flowing_"..d, - liquid_alternative_source = "testnodes:rliquid_"..d, - liquid_range = d, - }) - - local mod = "^[colorize:#000000:127" - minetest.register_node("testnodes:vliquid_"..d, { - description = "Test Liquid Source, Viscosity "..d, - drawtype = "liquid", - tiles = {"testnodes_liquidsource_r"..d..".png"..mod}, - special_tiles = { - {name = "testnodes_liquidsource_r"..d..".png"..mod, backface_culling = false}, - {name = "testnodes_liquidsource_r"..d..".png"..mod, backface_culling = true}, - }, - alpha = 192, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - liquidtype = "source", - liquid_alternative_flowing = "testnodes:vliquid_flowing_"..d, - liquid_alternative_source = "testnodes:vliquid_"..d, - liquid_viscosity = d, - }) - - minetest.register_node("testnodes:vliquid_flowing_"..d, { - description = "Flowing Test Liquid, Viscosity "..d, - drawtype = "flowingliquid", - tiles = {"testnodes_liquidflowing_r"..d..".png"..mod}, - special_tiles = { - {name = "testnodes_liquidflowing_r"..d..".png"..mod, backface_culling = false}, - {name = "testnodes_liquidflowing_r"..d..".png"..mod, backface_culling = false}, - }, - alpha = 192, - paramtype = "light", - paramtype2 = "flowingliquid", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - liquidtype = "flowing", - liquid_alternative_flowing = "testnodes:vliquid_flowing_"..d, - liquid_alternative_source = "testnodes:vliquid_"..d, - liquid_viscosity = d, - }) - -end diff --git a/games/minimal/mods/testnodes/meshes.lua b/games/minimal/mods/testnodes/meshes.lua deleted file mode 100644 index 900abc180..000000000 --- a/games/minimal/mods/testnodes/meshes.lua +++ /dev/null @@ -1,145 +0,0 @@ --- Meshes - -local S = minetest.get_translator("testnodes") - -local ocorner_cbox = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, -0.25, 0.5}, - {-0.5, -0.25, -0.25, 0.25, 0, 0.5}, - {-0.5, 0, 0, 0, 0.25, 0.5}, - {-0.5, 0.25, 0.25, -0.25, 0.5, 0.5} - } -} - -local tall_pyr_cbox = { - type = "fixed", - fixed = { - { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }, - { -0.375, -0.25, -0.375, 0.375, 0, 0.375}, - { -0.25, 0, -0.25, 0.25, 0.25, 0.25}, - { -0.125, 0.25, -0.125, 0.125, 0.5, 0.125} - } -} - --- Normal mesh -minetest.register_node("testnodes:mesh", { - description = S("Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes2.png"}, - paramtype = "light", - collision_box = tall_pyr_cbox, - - groups = {dig_immediate=3}, -}) - --- Facedir mesh: outer corner slope -minetest.register_node("testnodes:mesh_facedir", { - description = S("Facedir Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_ocorner.obj", - tiles = {"testnodes_mesh_stripes.png"}, - paramtype = "light", - paramtype2 = "facedir", - collision_box = ocorner_cbox, - - groups = {dig_immediate=3}, -}) - -minetest.register_node("testnodes:mesh_colorfacedir", { - description = S("Color Facedir Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_ocorner.obj", - tiles = {"testnodes_mesh_stripes3.png"}, - paramtype = "light", - paramtype2 = "colorfacedir", - palette = "testnodes_palette_facedir.png", - collision_box = ocorner_cbox, - - groups = {dig_immediate=3}, -}) - --- Wallmounted mesh: pyramid -minetest.register_node("testnodes:mesh_wallmounted", { - description = S("Wallmounted Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes2.png"}, - paramtype = "light", - paramtype2 = "wallmounted", - collision_box = tall_pyr_cbox, - - groups = {dig_immediate=3}, -}) - -minetest.register_node("testnodes:mesh_colorwallmounted", { - description = S("Color Wallmounted Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes3.png"}, - paramtype = "light", - paramtype2 = "colorwallmounted", - palette = "testnodes_palette_wallmounted.png", - collision_box = tall_pyr_cbox, - - groups = {dig_immediate=3}, -}) - - -minetest.register_node("testnodes:mesh_double", { - description = S("Double-sized Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes2.png"}, - paramtype = "light", - collision_box = tall_pyr_cbox, - visual_scale = 2, - - groups = {dig_immediate=3}, -}) -minetest.register_node("testnodes:mesh_half", { - description = S("Half-sized Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes2.png"}, - paramtype = "light", - collision_box = tall_pyr_cbox, - visual_scale = 0.5, - - groups = {dig_immediate=3}, -}) - -minetest.register_node("testnodes:mesh_waving1", { - description = S("Plantlike-waving Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes4.png^[multiply:#B0FFB0"}, - paramtype = "light", - collision_box = tall_pyr_cbox, - waving = 1, - - groups = {dig_immediate=3}, -}) -minetest.register_node("testnodes:mesh_waving2", { - description = S("Leaflike-waving Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes4.png^[multiply:#FFFFB0"}, - paramtype = "light", - collision_box = tall_pyr_cbox, - waving = 2, - - groups = {dig_immediate=3}, -}) -minetest.register_node("testnodes:mesh_waving3", { - description = S("Liquidlike-waving Mesh Test Node"), - drawtype = "mesh", - mesh = "testnodes_pyramid.obj", - tiles = {"testnodes_mesh_stripes4.png^[multiply:#B0B0FF"}, - paramtype = "light", - collision_box = tall_pyr_cbox, - waving = 3, - - groups = {dig_immediate=3}, -}) diff --git a/games/minimal/mods/testnodes/mod.conf b/games/minimal/mods/testnodes/mod.conf deleted file mode 100644 index 4824c6ed0..000000000 --- a/games/minimal/mods/testnodes/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = testnodes -description = Contains a bunch of basic example nodes for demonstrative purposes, development and testing diff --git a/games/minimal/mods/testnodes/models/testnodes_ocorner.obj b/games/minimal/mods/testnodes/models/testnodes_ocorner.obj deleted file mode 100644 index 231d7056b..000000000 --- a/games/minimal/mods/testnodes/models/testnodes_ocorner.obj +++ /dev/null @@ -1,23 +0,0 @@ -# Blender v2.73 (sub 0) OBJ File: 'slope_test_ocorner_onetexture.blend' -# www.blender.org -o Cube_Cube.002 -v 0.500000 0.500000 0.500000 -v -0.500000 -0.500000 0.500000 -v 0.500000 -0.500000 0.500000 -v -0.500000 -0.500000 -0.500000 -v 0.500000 -0.500000 -0.500000 -vt 1.000000 1.000000 -vt 0.000000 1.000000 -vt 0.000000 0.000000 -vt 1.000000 0.000000 -vn 0.000000 -1.000000 -0.000000 -vn 1.000000 0.000000 0.000000 -vn 0.000000 -0.000000 1.000000 -vn -0.707100 0.707100 0.000000 -vn 0.000000 0.707100 -0.707100 -s off -f 3/1/1 2/2/1 4/3/1 5/4/1 -f 1/2/2 3/3/2 5/4/2 -f 1/1/3 2/3/3 3/4/3 -f 1/1/4 4/3/4 2/4/4 -f 1/2/5 5/3/5 4/4/5 diff --git a/games/minimal/mods/testnodes/models/testnodes_pyramid.obj b/games/minimal/mods/testnodes/models/testnodes_pyramid.obj deleted file mode 100644 index b305af2f8..000000000 --- a/games/minimal/mods/testnodes/models/testnodes_pyramid.obj +++ /dev/null @@ -1,24 +0,0 @@ -# Blender v2.73 (sub 0) OBJ File: 'slope_test_pyramid_onetexture.blend' -# www.blender.org -o Cube -v 0.500000 -0.500000 -0.500000 -v 0.500000 -0.500000 0.500000 -v -0.500000 -0.500000 0.500000 -v -0.500000 -0.500000 -0.500000 -v -0.000000 0.500000 -0.000000 -vt 1.000000 1.000000 -vt 0.000000 1.000000 -vt 0.000000 0.000000 -vt 1.000000 0.000000 -vt 0.500000 1.000000 -vn 0.000000 -1.000000 0.000000 -vn -0.894400 0.447200 -0.000000 -vn 0.000000 0.447200 -0.894400 -vn 0.894400 0.447200 0.000000 -vn -0.000000 0.447200 0.894400 -s off -f 1/1/1 2/2/1 3/3/1 4/4/1 -f 3/4/2 5/5/2 4/3/2 -f 5/5/3 1/3/3 4/4/3 -f 1/4/4 5/5/4 2/3/4 -f 2/4/5 5/5/5 3/3/5 diff --git a/games/minimal/mods/testnodes/nodeboxes.lua b/games/minimal/mods/testnodes/nodeboxes.lua deleted file mode 100644 index ebd858337..000000000 --- a/games/minimal/mods/testnodes/nodeboxes.lua +++ /dev/null @@ -1,80 +0,0 @@ -local S = minetest.get_translator("testnodes") - --- Nodebox examples and tests. - --- An simple example nodebox with one centered box -minetest.register_node("testnodes:nodebox_fixed", { - description = S("Fixed Nodebox Test Node"), - tiles = {"testnodes_nodebox.png"}, - drawtype = "nodebox", - paramtype = "light", - node_box = { - type = "fixed", - fixed = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}, - }, - - groups = {dig_immediate=3}, -}) - --- 50% higher than a regular node -minetest.register_node("testnodes:nodebox_overhigh", { - description = S("Overhigh Nodebox Test Node"), - tiles = {"testnodes_nodebox.png"}, - drawtype = "nodebox", - paramtype = "light", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 1, 0.5}, - }, - - groups = {dig_immediate=3}, -}) - --- 100% higher than a regular node -minetest.register_node("testnodes:nodebox_overhigh2", { - description = S("Double-height Nodebox Test Node"), - tiles = {"testnodes_nodebox.png"}, - drawtype = "nodebox", - paramtype = "light", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}, - }, - - groups = {dig_immediate=3}, -}) - --- Height of nodebox changes with its param2 value -minetest.register_node("testnodes:nodebox_leveled", { - description = S("Leveled Nodebox Test Node"), - tiles = {"testnodes_nodebox.png"}, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "leveled", - node_box = { - type = "leveled", - fixed = {-0.5, 0.0, -0.5, 0.5, -0.499, 0.5}, - }, - - groups = {dig_immediate=3}, -}) - --- Wall-like nodebox that connects to neighbors -minetest.register_node("testnodes:nodebox_connected", { - description = S("Connected Nodebox Test Node"), - tiles = {"testnodes_nodebox.png"}, - groups = {connected_nodebox=1, dig_immediate=3}, - drawtype = "nodebox", - paramtype = "light", - connects_to = {"group:connected_nodebox"}, - connect_sides = {"front", "back", "left", "right"}, - node_box = { - type = "connected", - fixed = {-0.125, -0.500, -0.125, 0.125, 0.500, 0.125}, - connect_front = {-0.125, -0.500, -0.500, 0.125, 0.400, -0.125}, - connect_back = {-0.125, -0.500, 0.125, 0.125, 0.400, 0.500}, - connect_left = {-0.500, -0.500, -0.125, -0.125, 0.400, 0.125}, - connect_right = {0.125, -0.500, -0.125, 0.500, 0.400, 0.125}, - }, -}) - diff --git a/games/minimal/mods/testnodes/param2.lua b/games/minimal/mods/testnodes/param2.lua deleted file mode 100644 index 5d64376fa..000000000 --- a/games/minimal/mods/testnodes/param2.lua +++ /dev/null @@ -1,168 +0,0 @@ --- This file is for misc. param2 tests that aren't covered in drawtypes.lua already. - -local S = minetest.get_translator("testnodes") - -minetest.register_node("testnodes:facedir", { - description = S("Facedir Test Node"), - paramtype2 = "facedir", - tiles = { - "testnodes_1.png", - "testnodes_2.png", - "testnodes_3.png", - "testnodes_4.png", - "testnodes_5.png", - "testnodes_6.png", - }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:facedir_nodebox", { - description = S("Facedir Nodebox Test Node"), - tiles = { - "testnodes_1.png", - "testnodes_2.png", - "testnodes_3.png", - "testnodes_4.png", - "testnodes_5.png", - "testnodes_6.png", - }, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "facedir", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.2, 0.2, 0.2}, - }, - - groups = {dig_immediate=3}, -}) - -minetest.register_node("testnodes:wallmounted", { - description = S("Wallmounted Test Node"), - paramtype2 = "wallmounted", - tiles = { - "testnodes_1w.png", - "testnodes_2w.png", - "testnodes_3w.png", - "testnodes_4w.png", - "testnodes_5w.png", - "testnodes_6w.png", - }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:wallmounted_nodebox", { - description = S("Wallmounted Nodebox Test Node"), - paramtype2 = "wallmounted", - paramtype = "light", - tiles = { - "testnodes_1w.png", - "testnodes_2w.png", - "testnodes_3w.png", - "testnodes_4w.png", - "testnodes_5w.png", - "testnodes_6w.png", - }, - drawtype = "nodebox", - node_box = { - type = "wallmounted", - wall_top = { -0.5, 0, -0.5, 0.5, 0.5, 0.5 }, - wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }, - wall_side = { -0.5, -0.5, -0.5, 0, 0.5, 0.5 }, - }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:color", { - description = S("Color Test Node"), - paramtype2 = "color", - palette = "testnodes_palette_full.png", - tiles = { - "testnodes_node.png", - }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:colorfacedir", { - description = S("Color Facedir Test Node"), - paramtype2 = "colorfacedir", - palette = "testnodes_palette_facedir.png", - tiles = { - "testnodes_1g.png", - "testnodes_2g.png", - "testnodes_3g.png", - "testnodes_4g.png", - "testnodes_5g.png", - "testnodes_6g.png", - }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:colorfacedir_nodebox", { - description = S("Color Facedir Nodebox Test Node"), - tiles = { - "testnodes_1g.png", - "testnodes_2g.png", - "testnodes_3g.png", - "testnodes_4g.png", - "testnodes_5g.png", - "testnodes_6g.png", - }, - drawtype = "nodebox", - paramtype = "light", - paramtype2 = "colorfacedir", - palette = "testnodes_palette_facedir.png", - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.2, 0.2, 0.2}, - }, - - groups = {dig_immediate=3}, -}) - -minetest.register_node("testnodes:colorwallmounted", { - description = S("Color Wallmounted Test Node"), - paramtype2 = "colorwallmounted", - paramtype = "light", - palette = "testnodes_palette_wallmounted.png", - tiles = { - "testnodes_1wg.png", - "testnodes_2wg.png", - "testnodes_3wg.png", - "testnodes_4wg.png", - "testnodes_5wg.png", - "testnodes_6wg.png", - }, - - groups = { dig_immediate = 3 }, -}) - -minetest.register_node("testnodes:colorwallmounted_nodebox", { - description = S("Color Wallmounted Nodebox Test Node"), - paramtype2 = "colorwallmounted", - paramtype = "light", - palette = "testnodes_palette_wallmounted.png", - tiles = { - "testnodes_1wg.png", - "testnodes_2wg.png", - "testnodes_3wg.png", - "testnodes_4wg.png", - "testnodes_5wg.png", - "testnodes_6wg.png", - }, - drawtype = "nodebox", - node_box = { - type = "wallmounted", - wall_top = { -0.5, 0, -0.5, 0.5, 0.5, 0.5 }, - wall_bottom = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }, - wall_side = { -0.5, -0.5, -0.5, 0, 0.5, 0.5 }, - }, - - groups = { dig_immediate = 3 }, -}) - diff --git a/games/minimal/mods/testnodes/properties.lua b/games/minimal/mods/testnodes/properties.lua deleted file mode 100644 index e169d4b08..000000000 --- a/games/minimal/mods/testnodes/properties.lua +++ /dev/null @@ -1,270 +0,0 @@ --- Test Nodes: Node property tests - -local S = minetest.get_translator("testnodes") - --- Is supposed to fall when it doesn't rest on solid ground -minetest.register_node("testnodes:falling", { - description = S("Falling Node"), - tiles = { - "testnodes_node.png", - "testnodes_node.png", - "testnodes_node_falling.png", - }, - groups = { falling_node = 1, dig_immediate = 3 }, -}) - --- Same as falling node, but will stop falling on top of liquids -minetest.register_node("testnodes:falling_float", { - description = S("Falling+Floating Node"), - groups = { falling_node = 1, float = 1, dig_immediate = 3 }, - - - tiles = { - "testnodes_node.png", - "testnodes_node.png", - "testnodes_node_falling.png", - }, - color = "cyan", -}) - --- This node attaches to the floor and drops as item --- when the floor is gone. -minetest.register_node("testnodes:attached", { - description = S("Floor-Attached Node"), - tiles = { - "testnodes_attached_top.png", - "testnodes_attached_bottom.png", - "testnodes_attached_side.png", - }, - groups = { attached_node = 1, dig_immediate = 3 }, -}) - --- This node attaches to the side of a node and drops as item --- when the node it attaches to is gone. -minetest.register_node("testnodes:attached_wallmounted", { - description = S("Wallmounted Attached Node"), - paramtype2 = "wallmounted", - tiles = { - "testnodes_attachedw_top.png", - "testnodes_attachedw_bottom.png", - "testnodes_attachedw_side.png", - }, - groups = { attached_node = 1, dig_immediate = 3 }, -}) - --- Jump disabled -minetest.register_node("testnodes:nojump", { - description = S("Non-jumping Node"), - groups = {disable_jump=1, dig_immediate=3}, - - - tiles = {"testnodes_nojump_top.png", "testnodes_nojump_side.png"}, -}) - --- Climbable up and down with jump and sneak keys -minetest.register_node("testnodes:climbable", { - description = S("Climbable Node"), - climbable = true, - walkable = false, - - - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - tiles ={"testnodes_climbable_side.png"}, - drawtype = "glasslike", - groups = {dig_immediate=3}, -}) - --- Climbable only downwards with sneak key -minetest.register_node("testnodes:climbable_nojump", { - description = S("Downwards-climbable Node"), - climbable = true, - walkable = false, - - groups = {disable_jump=1, dig_immediate=3}, - drawtype = "glasslike", - tiles ={"testnodes_climbable_nojump_side.png"}, - paramtype = "light", - sunlight_propagates = true, -}) - --- A liquid in which you can't rise -minetest.register_node("testnodes:liquid_nojump", { - description = S("Non-jumping Liquid Source Node"), - liquidtype = "source", - liquid_range = 1, - liquid_viscosity = 0, - liquid_alternative_flowing = "testnodes:liquidflowing_nojump", - liquid_alternative_source = "testnodes:liquid_nojump", - liquid_renewable = false, - groups = {disable_jump=1, dig_immediate=3}, - walkable = false, - - drawtype = "liquid", - tiles = {"testnodes_liquidsource.png^[colorize:#FF0000:127"}, - special_tiles = { - {name = "testnodes_liquidsource.png^[colorize:#FF0000:127", backface_culling = false}, - {name = "testnodes_liquidsource.png^[colorize:#FF0000:127", backface_culling = true}, - }, - use_texture_alpha = true, - paramtype = "light", - pointable = false, - liquids_pointable = true, - diggable = false, - buildable_to = true, - is_ground_content = false, - post_effect_color = {a = 70, r = 255, g = 0, b = 200}, -}) - --- A liquid in which you can't rise (flowing variant) -minetest.register_node("testnodes:liquidflowing_nojump", { - description = S("Non-jumping Flowing Liquid Node"), - liquidtype = "flowing", - liquid_range = 1, - liquid_viscosity = 0, - liquid_alternative_flowing = "testnodes:liquidflowing_nojump", - liquid_alternative_source = "testnodes:liquid_nojump", - liquid_renewable = false, - groups = {disable_jump=1, dig_immediate=3}, - walkable = false, - - - drawtype = "flowingliquid", - tiles = {"testnodes_liquidflowing.png^[colorize:#FF0000:127"}, - special_tiles = { - {name = "testnodes_liquidflowing.png^[colorize:#FF0000:127", backface_culling = false}, - {name = "testnodes_liquidflowing.png^[colorize:#FF0000:127", backface_culling = false}, - }, - use_texture_alpha = true, - paramtype = "light", - paramtype2 = "flowingliquid", - pointable = false, - liquids_pointable = true, - diggable = false, - buildable_to = true, - is_ground_content = false, - post_effect_color = {a = 70, r = 255, g = 0, b = 200}, -}) - --- Nodes that modify fall damage (various damage modifiers) -for i=-100, 100, 25 do - if i ~= 0 then - local subname, descnum - if i < 0 then - subname = "m"..math.abs(i) - descnum = tostring(i) - else - subname = tostring(i) - descnum = S("+@1", i) - end - local tex, color, desc - if i > 0 then - local val = math.floor((i/100)*255) - tex = "testnodes_fall_damage_plus.png" - color = { b=0, g=255-val, r=255, a=255 } - desc = S("Fall Damage Node (+@1%)", i) - else - tex = "testnodes_fall_damage_minus.png" - if i == -100 then - color = { r=0, b=0, g=255, a=255 } - else - local val = math.floor((math.abs(i)/100)*255) - color = { r=0, b=255, g=255-val, a=255 } - end - desc = S("Fall Damage Node (-@1%)", math.abs(i)) - end - minetest.register_node("testnodes:damage"..subname, { - description = desc, - groups = {fall_damage_add_percent=i, dig_immediate=3}, - - - tiles = { tex }, - is_ground_content = false, - color = color, - }) - end -end - --- Bouncy nodes (various bounce levels) -for i=20, 180, 20 do - local val = math.floor(((i-20)/200)*255) - minetest.register_node("testnodes:bouncy"..i, { - description = S("Bouncy Node (@1%)", i), - groups = {bouncy=i, dig_immediate=3}, - - - tiles ={"testnodes_bouncy.png"}, - is_ground_content = false, - color = { r=255, g=255-val, b=val, a=255 }, - }) -end - --- Slippery nodes (various slippery levels) -for i=1, 5 do - minetest.register_node("testnodes:slippery"..i, { - description = S("Slippery Node (@1)", i), - tiles ={"testnodes_slippery.png"}, - is_ground_content = false, - groups = {slippery=i, dig_immediate=3}, - color = { r=0, g=255, b=math.floor((i/5)*255), a=255 }, - }) -end - --- By placing something on the node, the node itself will be replaced -minetest.register_node("testnodes:buildable_to", { - description = S("Replacable Node"), - buildable_to = true, - tiles = {"testnodes_buildable_to.png"}, - is_ground_content = false, - groups = {dig_immediate=3}, -}) - --- Nodes that deal damage to players that are inside them. --- Negative damage nodes should heal. -for d=-3,3 do - if d ~= 0 then - local sub, tile - if d > 0 then - sub = tostring(d) - tile = "testnodes_damage.png" - else - sub = "m" .. tostring(math.abs(d)) - tile = "testnodes_damage_neg.png" - end - if math.abs(d) == 2 then - tile = tile .. "^[colorize:#000000:70" - elseif math.abs(d) == 3 then - tile = tile .. "^[colorize:#000000:140" - end - minetest.register_node("testnodes:damage_"..sub, { - description = S("Damage Node (@1 damage per second)", d), - damage_per_second = d, - - - walkable = false, - is_ground_content = false, - drawtype = "allfaces", - paramtype = "light", - sunlight_propagates = true, - tiles = { tile }, - groups = {dig_immediate=3}, - }) - end -end - --- Causes drowning damage -minetest.register_node("testnodes:drowning_1", { - description = S("Drowning Node (@1 damage)", 1), - drowning = 1, - - - walkable = false, - is_ground_content = false, - drawtype = "allfaces", - paramtype = "light", - sunlight_propagates = true, - tiles = { "testnodes_drowning.png" }, - groups = {dig_immediate=3}, -}) - diff --git a/games/minimal/mods/testnodes/settingtypes.txt b/games/minimal/mods/testnodes/settingtypes.txt deleted file mode 100644 index 7f753bf3e..000000000 --- a/games/minimal/mods/testnodes/settingtypes.txt +++ /dev/null @@ -1,4 +0,0 @@ -# If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. -# This is due to . -# This is only added to make the items more visible to avoid confusion, but you will no longer see the default inventory images for these items. When you want to test the default inventory image of drawtypes, this should be turned off. -testnodes_show_fallback_image (Use fallback inventory images) bool false diff --git a/games/minimal/mods/testnodes/textures.lua b/games/minimal/mods/testnodes/textures.lua deleted file mode 100644 index f5db9ccbf..000000000 --- a/games/minimal/mods/testnodes/textures.lua +++ /dev/null @@ -1,67 +0,0 @@ --- Node texture tests - -local S = minetest.get_translator("testnodes") - -minetest.register_node("testnodes:6sides", { - description = S("Six Textures Test Node"), - tiles = { - "testnodes_normal1.png", - "testnodes_normal2.png", - "testnodes_normal3.png", - "testnodes_normal4.png", - "testnodes_normal5.png", - "testnodes_normal6.png", - }, - - groups = { dig_immediate = 2 }, -}) - -minetest.register_node("testnodes:anim", { - description = S("Animated Test Node"), - tiles = { - { name = "testnodes_anim.png", - animation = { - type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, - length = 4.0, - }, }, - }, - - groups = { dig_immediate = 2 }, -}) - --- Node texture transparency test - -local alphas = { 64, 128, 191 } - -for a=1,#alphas do - local alpha = alphas[a] - - -- Transparency taken from texture - minetest.register_node("testnodes:alpha_texture_"..alpha, { - description = S("Texture Alpha Test Node (@1)", alpha), - drawtype = "glasslike", - paramtype = "light", - tiles = { - "testnodes_alpha"..alpha..".png", - }, - use_texture_alpha = true, - - groups = { dig_immediate = 3 }, - }) - - -- Transparency set via "alpha" parameter - minetest.register_node("testnodes:alpha_"..alpha, { - description = S("Alpha Test Node (@1)", alpha), - -- It seems that only the liquid drawtype supports the alpha parameter - drawtype = "liquid", - paramtype = "light", - tiles = { - "testnodes_alpha.png", - }, - alpha = alpha, - - groups = { dig_immediate = 3 }, - }) -end diff --git a/games/minimal/mods/testnodes/textures/testnodes_1.png b/games/minimal/mods/testnodes/textures/testnodes_1.png deleted file mode 100644 index 6730997e2..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_1.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_1g.png b/games/minimal/mods/testnodes/textures/testnodes_1g.png deleted file mode 100644 index 529298ece..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_1g.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_1w.png b/games/minimal/mods/testnodes/textures/testnodes_1w.png deleted file mode 100644 index d24e571cc..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_1w.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_1wg.png b/games/minimal/mods/testnodes/textures/testnodes_1wg.png deleted file mode 100644 index b2eba0e9a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_1wg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_2.png b/games/minimal/mods/testnodes/textures/testnodes_2.png deleted file mode 100644 index 6c87c868d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_2g.png b/games/minimal/mods/testnodes/textures/testnodes_2g.png deleted file mode 100644 index cb9060f7b..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_2g.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_2w.png b/games/minimal/mods/testnodes/textures/testnodes_2w.png deleted file mode 100644 index b56874ee1..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_2w.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_2wg.png b/games/minimal/mods/testnodes/textures/testnodes_2wg.png deleted file mode 100644 index 108dc87bb..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_2wg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_3.png b/games/minimal/mods/testnodes/textures/testnodes_3.png deleted file mode 100644 index 05b45629a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_3.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_3g.png b/games/minimal/mods/testnodes/textures/testnodes_3g.png deleted file mode 100644 index 5c84f5882..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_3g.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_3w.png b/games/minimal/mods/testnodes/textures/testnodes_3w.png deleted file mode 100644 index 8b435cf01..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_3w.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_3wg.png b/games/minimal/mods/testnodes/textures/testnodes_3wg.png deleted file mode 100644 index 9ee900667..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_3wg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_4.png b/games/minimal/mods/testnodes/textures/testnodes_4.png deleted file mode 100644 index 15e6ffec7..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_4.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_4g.png b/games/minimal/mods/testnodes/textures/testnodes_4g.png deleted file mode 100644 index 8f144fae0..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_4g.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_4w.png b/games/minimal/mods/testnodes/textures/testnodes_4w.png deleted file mode 100644 index 214e0df9d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_4w.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_4wg.png b/games/minimal/mods/testnodes/textures/testnodes_4wg.png deleted file mode 100644 index 888b3d482..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_4wg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_5.png b/games/minimal/mods/testnodes/textures/testnodes_5.png deleted file mode 100644 index 1ef1c728c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_5.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_5g.png b/games/minimal/mods/testnodes/textures/testnodes_5g.png deleted file mode 100644 index 30da4793a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_5g.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_5w.png b/games/minimal/mods/testnodes/textures/testnodes_5w.png deleted file mode 100644 index b4cb42426..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_5w.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_5wg.png b/games/minimal/mods/testnodes/textures/testnodes_5wg.png deleted file mode 100644 index fac9db28e..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_5wg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_6.png b/games/minimal/mods/testnodes/textures/testnodes_6.png deleted file mode 100644 index 805813e57..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_6.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_6g.png b/games/minimal/mods/testnodes/textures/testnodes_6g.png deleted file mode 100644 index a88f4c9f8..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_6g.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_6w.png b/games/minimal/mods/testnodes/textures/testnodes_6w.png deleted file mode 100644 index e6bbf97d9..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_6w.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_6wg.png b/games/minimal/mods/testnodes/textures/testnodes_6wg.png deleted file mode 100644 index 29ca933e0..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_6wg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_airlike.png b/games/minimal/mods/testnodes/textures/testnodes_airlike.png deleted file mode 100644 index 5a5664a2a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_airlike.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_allfaces.png b/games/minimal/mods/testnodes/textures/testnodes_allfaces.png deleted file mode 100644 index c0a7dc550..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_allfaces.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_allfaces_optional.png b/games/minimal/mods/testnodes/textures/testnodes_allfaces_optional.png deleted file mode 100644 index 1f6a17313..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_allfaces_optional.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_alpha.png b/games/minimal/mods/testnodes/textures/testnodes_alpha.png deleted file mode 100644 index 157fa7386..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_alpha.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_alpha128.png b/games/minimal/mods/testnodes/textures/testnodes_alpha128.png deleted file mode 100644 index 16babf6c7..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_alpha128.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_alpha191.png b/games/minimal/mods/testnodes/textures/testnodes_alpha191.png deleted file mode 100644 index f165d2887..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_alpha191.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_alpha64.png b/games/minimal/mods/testnodes/textures/testnodes_alpha64.png deleted file mode 100644 index c343c32c3..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_alpha64.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_anim.png b/games/minimal/mods/testnodes/textures/testnodes_anim.png deleted file mode 100644 index d321fe857..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_anim.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_attached_bottom.png b/games/minimal/mods/testnodes/textures/testnodes_attached_bottom.png deleted file mode 100644 index e01ae576f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_attached_bottom.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_attached_side.png b/games/minimal/mods/testnodes/textures/testnodes_attached_side.png deleted file mode 100644 index 9459cbb05..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_attached_side.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_attached_top.png b/games/minimal/mods/testnodes/textures/testnodes_attached_top.png deleted file mode 100644 index 0148b41e0..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_attached_top.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_attachedw_bottom.png b/games/minimal/mods/testnodes/textures/testnodes_attachedw_bottom.png deleted file mode 100644 index 488ad23a9..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_attachedw_bottom.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_attachedw_side.png b/games/minimal/mods/testnodes/textures/testnodes_attachedw_side.png deleted file mode 100644 index a02facbc7..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_attachedw_side.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_attachedw_top.png b/games/minimal/mods/testnodes/textures/testnodes_attachedw_top.png deleted file mode 100644 index 1f4fc7b85..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_attachedw_top.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_bouncy.png b/games/minimal/mods/testnodes/textures/testnodes_bouncy.png deleted file mode 100644 index eabbbdfe4..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_bouncy.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_buildable_to.png b/games/minimal/mods/testnodes/textures/testnodes_buildable_to.png deleted file mode 100644 index 23b5e54d2..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_buildable_to.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_climbable_nojump_side.png b/games/minimal/mods/testnodes/textures/testnodes_climbable_nojump_side.png deleted file mode 100644 index d5ca13033..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_climbable_nojump_side.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_climbable_side.png b/games/minimal/mods/testnodes/textures/testnodes_climbable_side.png deleted file mode 100644 index c56ea90d7..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_climbable_side.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_damage.png b/games/minimal/mods/testnodes/textures/testnodes_damage.png deleted file mode 100644 index 9de2ab5e8..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_damage.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_damage_neg.png b/games/minimal/mods/testnodes/textures/testnodes_damage_neg.png deleted file mode 100644 index 85811bc8e..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_damage_neg.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_drowning.png b/games/minimal/mods/testnodes/textures/testnodes_drowning.png deleted file mode 100644 index 57ffc8fcf..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_drowning.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_fall_damage_minus.png b/games/minimal/mods/testnodes/textures/testnodes_fall_damage_minus.png deleted file mode 100644 index 88d3bdf58..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_fall_damage_minus.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_fall_damage_plus.png b/games/minimal/mods/testnodes/textures/testnodes_fall_damage_plus.png deleted file mode 100644 index 61fdec2e3..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_fall_damage_plus.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_fencelike.png b/games/minimal/mods/testnodes/textures/testnodes_fencelike.png deleted file mode 100644 index 84dea1b7c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_fencelike.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_firelike.png b/games/minimal/mods/testnodes/textures/testnodes_firelike.png deleted file mode 100644 index ee59b0db1..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_firelike.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_glasslike.png b/games/minimal/mods/testnodes/textures/testnodes_glasslike.png deleted file mode 100644 index cf3e35414..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_glasslike.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_glasslike_detail.png b/games/minimal/mods/testnodes/textures/testnodes_glasslike_detail.png deleted file mode 100644 index 30c9586e8..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_glasslike_detail.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed.png b/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed.png deleted file mode 100644 index 8a513f21c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed2.png b/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed2.png deleted file mode 100644 index 4ea839c8b..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed_optional.png b/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed_optional.png deleted file mode 100644 index 37de77dd1..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_glasslike_framed_optional.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_glasslikeliquid.png b/games/minimal/mods/testnodes/textures/testnodes_glasslikeliquid.png deleted file mode 100644 index e1e96ffb9..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_glasslikeliquid.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light.png b/games/minimal/mods/testnodes/textures/testnodes_light.png deleted file mode 100644 index 4ba0081c3..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_1.png b/games/minimal/mods/testnodes/textures/testnodes_light_1.png deleted file mode 100644 index 57adf5a4a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_1.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_10.png b/games/minimal/mods/testnodes/textures/testnodes_light_10.png deleted file mode 100644 index 483834770..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_10.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_11.png b/games/minimal/mods/testnodes/textures/testnodes_light_11.png deleted file mode 100644 index 4c423d9b4..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_11.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_12.png b/games/minimal/mods/testnodes/textures/testnodes_light_12.png deleted file mode 100644 index bc7946d09..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_12.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_13.png b/games/minimal/mods/testnodes/textures/testnodes_light_13.png deleted file mode 100644 index 0b63c84a6..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_13.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_14.png b/games/minimal/mods/testnodes/textures/testnodes_light_14.png deleted file mode 100644 index a817bd394..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_14.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_2.png b/games/minimal/mods/testnodes/textures/testnodes_light_2.png deleted file mode 100644 index 852eaeff1..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_3.png b/games/minimal/mods/testnodes/textures/testnodes_light_3.png deleted file mode 100644 index 79fc834cc..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_3.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_4.png b/games/minimal/mods/testnodes/textures/testnodes_light_4.png deleted file mode 100644 index 75f8c6136..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_4.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_5.png b/games/minimal/mods/testnodes/textures/testnodes_light_5.png deleted file mode 100644 index b6eede0ae..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_5.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_6.png b/games/minimal/mods/testnodes/textures/testnodes_light_6.png deleted file mode 100644 index ef54addec..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_6.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_7.png b/games/minimal/mods/testnodes/textures/testnodes_light_7.png deleted file mode 100644 index 4a885b0f6..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_7.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_8.png b/games/minimal/mods/testnodes/textures/testnodes_light_8.png deleted file mode 100644 index b283301e3..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_8.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_light_9.png b/games/minimal/mods/testnodes/textures/testnodes_light_9.png deleted file mode 100644 index 2aa902358..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_light_9.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_line_crossing.png b/games/minimal/mods/testnodes/textures/testnodes_line_crossing.png deleted file mode 100644 index e566f2793..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_line_crossing.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_line_curved.png b/games/minimal/mods/testnodes/textures/testnodes_line_curved.png deleted file mode 100644 index ab9f8e720..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_line_curved.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_line_straight.png b/games/minimal/mods/testnodes/textures/testnodes_line_straight.png deleted file mode 100644 index 4f33d9c6d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_line_straight.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_line_t_junction.png b/games/minimal/mods/testnodes/textures/testnodes_line_t_junction.png deleted file mode 100644 index 5668f6ea3..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_line_t_junction.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquid.png b/games/minimal/mods/testnodes/textures/testnodes_liquid.png deleted file mode 100644 index 98ab270c2..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquid.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing.png deleted file mode 100644 index 1736b89ba..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r0.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r0.png deleted file mode 100644 index e8a61039d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r0.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r1.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r1.png deleted file mode 100644 index b4e45b42f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r1.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r2.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r2.png deleted file mode 100644 index e064b8f2d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r3.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r3.png deleted file mode 100644 index bef773968..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r3.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r4.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r4.png deleted file mode 100644 index de1001b2d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r4.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r5.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r5.png deleted file mode 100644 index 97b422e9a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r5.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r6.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r6.png deleted file mode 100644 index 4cd8e4e8e..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r6.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r7.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r7.png deleted file mode 100644 index 711dd961c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r7.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r8.png b/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r8.png deleted file mode 100644 index 9cf22b8ca..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidflowing_r8.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource.png deleted file mode 100644 index b3f29b702..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r0.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r0.png deleted file mode 100644 index da0a99623..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r0.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r1.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r1.png deleted file mode 100644 index 66bf2be8f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r1.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r2.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r2.png deleted file mode 100644 index fc5f65cb6..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r3.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r3.png deleted file mode 100644 index 0f46e291e..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r3.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r4.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r4.png deleted file mode 100644 index 0693a04d7..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r4.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r5.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r5.png deleted file mode 100644 index cc9d03992..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r5.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r6.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r6.png deleted file mode 100644 index e276a07ae..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r6.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r7.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r7.png deleted file mode 100644 index 3534a4b15..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r7.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r8.png b/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r8.png deleted file mode 100644 index ee1a8b169..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_liquidsource_r8.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes.png b/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes.png deleted file mode 100644 index 51b8e0025..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes2.png b/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes2.png deleted file mode 100644 index 9ea65c1ec..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes3.png b/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes3.png deleted file mode 100644 index 96bc55ac5..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes3.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes4.png b/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes4.png deleted file mode 100644 index fca33727d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_mesh_stripes4.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_node.png b/games/minimal/mods/testnodes/textures/testnodes_node.png deleted file mode 100644 index 145099b3a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_node.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_node_falling.png b/games/minimal/mods/testnodes/textures/testnodes_node_falling.png deleted file mode 100644 index 44153185c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_node_falling.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_nodebox.png b/games/minimal/mods/testnodes/textures/testnodes_nodebox.png deleted file mode 100644 index 66e8dd663..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_nodebox.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_nojump_side.png b/games/minimal/mods/testnodes/textures/testnodes_nojump_side.png deleted file mode 100644 index 6a64cfff0..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_nojump_side.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_nojump_top.png b/games/minimal/mods/testnodes/textures/testnodes_nojump_top.png deleted file mode 100644 index fe770838f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_nojump_top.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal.png b/games/minimal/mods/testnodes/textures/testnodes_normal.png deleted file mode 100644 index a1acfd9fd..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal1.png b/games/minimal/mods/testnodes/textures/testnodes_normal1.png deleted file mode 100644 index edaba77e4..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal1.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal2.png b/games/minimal/mods/testnodes/textures/testnodes_normal2.png deleted file mode 100644 index 0080a9ee7..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal2.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal3.png b/games/minimal/mods/testnodes/textures/testnodes_normal3.png deleted file mode 100644 index 0426ab216..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal3.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal4.png b/games/minimal/mods/testnodes/textures/testnodes_normal4.png deleted file mode 100644 index 0d1922eb6..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal4.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal5.png b/games/minimal/mods/testnodes/textures/testnodes_normal5.png deleted file mode 100644 index 0b7dcd2da..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal5.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_normal6.png b/games/minimal/mods/testnodes/textures/testnodes_normal6.png deleted file mode 100644 index f34a67d71..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_normal6.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_palette_facedir.png b/games/minimal/mods/testnodes/textures/testnodes_palette_facedir.png deleted file mode 100644 index 8cf47bbbe..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_palette_facedir.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_palette_full.png b/games/minimal/mods/testnodes/textures/testnodes_palette_full.png deleted file mode 100644 index e0a5f8b34..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_palette_full.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_palette_wallmounted.png b/games/minimal/mods/testnodes/textures/testnodes_palette_wallmounted.png deleted file mode 100644 index 682f3ac84..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_palette_wallmounted.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike.png deleted file mode 100644 index cc464444d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_degrotate.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_degrotate.png deleted file mode 100644 index 01c81da8e..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_degrotate.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_leveled.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_leveled.png deleted file mode 100644 index 53504dbcd..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_leveled.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_meshoptions.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_meshoptions.png deleted file mode 100644 index d504d459f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_meshoptions.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted.png deleted file mode 100644 index 79cf2125e..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base.png deleted file mode 100644 index b9ee9e5be..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png deleted file mode 100644 index 85311cb2c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_degrotate.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png deleted file mode 100644 index bc602bafe..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_leveled.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png deleted file mode 100644 index d10002375..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_meshoptions.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png deleted file mode 100644 index 527817bc1..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_base_side_waving.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png deleted file mode 100644 index 45e75bdd3..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_degrotate.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png deleted file mode 100644 index 8954b2c34..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_leveled.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png deleted file mode 100644 index a782d4874..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_meshoptions.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png deleted file mode 100644 index 112a0540f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_rooted_waving.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_plantlike_waving.png b/games/minimal/mods/testnodes/textures/testnodes_plantlike_waving.png deleted file mode 100644 index b584a8dc9..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_plantlike_waving.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail2_crossing.png b/games/minimal/mods/testnodes/textures/testnodes_rail2_crossing.png deleted file mode 100644 index 530bbba7a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail2_crossing.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail2_curved.png b/games/minimal/mods/testnodes/textures/testnodes_rail2_curved.png deleted file mode 100644 index 4ed1ca00f..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail2_curved.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail2_straight.png b/games/minimal/mods/testnodes/textures/testnodes_rail2_straight.png deleted file mode 100644 index 8749330d8..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail2_straight.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail2_t_junction.png b/games/minimal/mods/testnodes/textures/testnodes_rail2_t_junction.png deleted file mode 100644 index 0517f6570..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail2_t_junction.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail_crossing.png b/games/minimal/mods/testnodes/textures/testnodes_rail_crossing.png deleted file mode 100644 index 3916ce1ef..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail_crossing.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail_curved.png b/games/minimal/mods/testnodes/textures/testnodes_rail_curved.png deleted file mode 100644 index e44419848..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail_curved.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail_straight.png b/games/minimal/mods/testnodes/textures/testnodes_rail_straight.png deleted file mode 100644 index 872d04fb9..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail_straight.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_rail_t_junction.png b/games/minimal/mods/testnodes/textures/testnodes_rail_t_junction.png deleted file mode 100644 index 7e4af5182..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_rail_t_junction.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_signlike.png b/games/minimal/mods/testnodes/textures/testnodes_signlike.png deleted file mode 100644 index 33ffcba6c..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_signlike.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_slippery.png b/games/minimal/mods/testnodes/textures/testnodes_slippery.png deleted file mode 100644 index b990468a1..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_slippery.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_street_crossing.png b/games/minimal/mods/testnodes/textures/testnodes_street_crossing.png deleted file mode 100644 index d6e35ad7a..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_street_crossing.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_street_curved.png b/games/minimal/mods/testnodes/textures/testnodes_street_curved.png deleted file mode 100644 index 251b7fb71..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_street_curved.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_street_straight.png b/games/minimal/mods/testnodes/textures/testnodes_street_straight.png deleted file mode 100644 index 639e24b93..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_street_straight.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_street_t_junction.png b/games/minimal/mods/testnodes/textures/testnodes_street_t_junction.png deleted file mode 100644 index 713621e06..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_street_t_junction.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_sunlight_filter.png b/games/minimal/mods/testnodes/textures/testnodes_sunlight_filter.png deleted file mode 100644 index b38ea4072..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_sunlight_filter.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_torchlike_ceiling.png b/games/minimal/mods/testnodes/textures/testnodes_torchlike_ceiling.png deleted file mode 100644 index 5d9862cc9..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_torchlike_ceiling.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_torchlike_floor.png b/games/minimal/mods/testnodes/textures/testnodes_torchlike_floor.png deleted file mode 100644 index adf1e002d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_torchlike_floor.png and /dev/null differ diff --git a/games/minimal/mods/testnodes/textures/testnodes_torchlike_wall.png b/games/minimal/mods/testnodes/textures/testnodes_torchlike_wall.png deleted file mode 100644 index cb442b22d..000000000 Binary files a/games/minimal/mods/testnodes/textures/testnodes_torchlike_wall.png and /dev/null differ diff --git a/games/minimal/mods/testpathfinder/README.md b/games/minimal/mods/testpathfinder/README.md deleted file mode 100644 index 2b9d46e70..000000000 --- a/games/minimal/mods/testpathfinder/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Pathfinder Tester - -Usage: - -Use the Pathfinder Tester tool (`testpathfinder:testpathfinder`). -Here's how it works: - -* Place on node: Set destination position -* Punch: Find path -* Sneak+punch: Select pathfinding algorithm - -Information will be shown in chat. If a path was found, all waypoints -will be shown for a few seconds. - -See `init.lua` for config variables. diff --git a/games/minimal/mods/testpathfinder/init.lua b/games/minimal/mods/testpathfinder/init.lua deleted file mode 100644 index f94848236..000000000 --- a/games/minimal/mods/testpathfinder/init.lua +++ /dev/null @@ -1,132 +0,0 @@ -local S = minetest.get_translator("testpathfinder") - --- Config parameters - --- Maximum direct distance between start and end -local MAX_DIRECT_DISTANCE = 64 --- Maximum search distance -local MAX_SEARCH_DISTANCE = 32 --- Maximum permitted jump height -local MAX_JUMP = 1 --- Maximum permitted drop height -local MAX_DROP = 5 --- If true, mod won't refuse to run pathfinder even at long distances -local IGNORE_MAX_DISTANCE_SAFEGUARD = false - --- End of config parameters - -local timer = 0 -local algorithms = { - "A*_noprefetch", - "A*", - "Dijkstra", -} - -local function find_path_for_player(player, itemstack) - local meta = itemstack:get_meta() - if not meta then - return - end - local x = meta:get_int("pos_x") - local y = meta:get_int("pos_y") - local z = meta:get_int("pos_z") - local algo = meta:get_int("algorithm") - if x and y and z then - local pos2 = {x=x, y=y, z=z} - algo = algorithms[algo+1] - local pos1 = vector.round(player:get_pos()) - -- Don't bother calling pathfinder for high distance to avoid freezing - if (not IGNORE_MAX_DISTANCE_SAFEGUARD) and (vector.distance(pos1, pos2) > MAX_DIRECT_DISTANCE) then - minetest.chat_send_player(player:get_player_name(), S("Destination too far away! Set a destination (via placing) within a distance of @1 and try again!", MAX_DIRECT_DISTANCE)) - return - end - local str = S("Path from @1 to @2:", - minetest.pos_to_string(pos1), - minetest.pos_to_string(pos2)) - - minetest.chat_send_player(player:get_player_name(), str) - local time_start = minetest.get_us_time() - local path = minetest.find_path(pos1, pos2, MAX_SEARCH_DISTANCE, MAX_JUMP, MAX_DROP, algo) - local time_end = minetest.get_us_time() - local time_diff = time_end - time_start - str = "" - if not path then - minetest.chat_send_player(player:get_player_name(), S("No path!")) - minetest.chat_send_player(player:get_player_name(), S("Time: @1 ms", time_diff/1000)) - return - end - for s=1, #path do - str = str .. minetest.pos_to_string(path[s]) .. "\n" - local t - if s == #path then - t = "testpathfinder_waypoint_end.png" - elseif s == 1 then - t = "testpathfinder_waypoint_start.png" - else - local c = math.floor(((#path-s)/#path)*255) - t = string.format("testpathfinder_waypoint.png^[multiply:#%02x%02x00", 0xFF-c, c) - end - minetest.add_particle({ - pos = path[s], - expirationtime = 5 + 0.2 * s, - playername = player:get_player_name(), - glow = minetest.LIGHT_MAX, - texture = t, - size = 3, - }) - end - minetest.chat_send_player(player:get_player_name(), str) - minetest.chat_send_player(player:get_player_name(), S("Path length: @1", #path)) - minetest.chat_send_player(player:get_player_name(), S("Time: @1 ms", time_diff/1000)) - end -end - -local function set_destination(itemstack, user, pointed_thing) - if not (user and user:is_player()) then - return - end - local name = user:get_player_name() - local obj - local meta = itemstack:get_meta() - if pointed_thing.type == "node" then - local pos = pointed_thing.above - meta:set_int("pos_x", pos.x) - meta:set_int("pos_y", pos.y) - meta:set_int("pos_z", pos.z) - minetest.chat_send_player(user:get_player_name(), S("Destination set to @1", minetest.pos_to_string(pos))) - return itemstack - end -end - -local function find_path_or_set_algorithm(itemstack, user, pointed_thing) - if not (user and user:is_player()) then - return - end - local ctrl = user:get_player_control() - -- No sneak: Find path - if not ctrl.sneak then - find_path_for_player(user, itemstack) - else - -- Sneak: Set algorithm - local meta = itemstack:get_meta() - local algo = meta:get_int("algorithm") - algo = (algo + 1) % #algorithms - meta:set_int("algorithm", algo) - minetest.chat_send_player(user:get_player_name(), S("Algorithm: @1", algorithms[algo+1])) - return itemstack - end -end - --- Punch: Find path --- Sneak+punch: Select pathfinding algorithm --- Place: Select destination node -minetest.register_tool("testpathfinder:testpathfinder", { - description = S("Pathfinder Tester"), - inventory_image = "testpathfinder_testpathfinder.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = find_path_or_set_algorithm, - on_secondary_use = set_destination, - on_place = set_destination, -}) - - diff --git a/games/minimal/mods/testpathfinder/mod.conf b/games/minimal/mods/testpathfinder/mod.conf deleted file mode 100644 index e6034ae8c..000000000 --- a/games/minimal/mods/testpathfinder/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = testpathfinder -description = Tool to test Minetest's pathfinder function diff --git a/games/minimal/mods/testpathfinder/textures/testpathfinder_testpathfinder.png b/games/minimal/mods/testpathfinder/textures/testpathfinder_testpathfinder.png deleted file mode 100644 index 37eef0565..000000000 Binary files a/games/minimal/mods/testpathfinder/textures/testpathfinder_testpathfinder.png and /dev/null differ diff --git a/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint.png b/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint.png deleted file mode 100644 index 661dcf906..000000000 Binary files a/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint.png and /dev/null differ diff --git a/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_end.png b/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_end.png deleted file mode 100644 index 41a1cc549..000000000 Binary files a/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_end.png and /dev/null differ diff --git a/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_start.png b/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_start.png deleted file mode 100644 index a22e31c3b..000000000 Binary files a/games/minimal/mods/testpathfinder/textures/testpathfinder_waypoint_start.png and /dev/null differ diff --git a/games/minimal/mods/testtools/README.md b/games/minimal/mods/testtools/README.md deleted file mode 100644 index 9cfe29ea4..000000000 --- a/games/minimal/mods/testtools/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# Test Tools readme - -Test Tools is a mod for developers that adds a bunch of tools to directly manipulate nodes and entities. This is great for quickly testing out stuff. - -Here's the list of tools: - -## Remover -Removes nodes and non-player entities that you punch. - -## Node Setter -Replace a node with another one. - -First, punch a node you want to remember. -Then rightclick any other node to replace it with the node you remembered. - -If you rightclick while pointing nothing, you can manually enter the node and param2. - -## Param2 Tool -Change the value param2 of nodes. - -* Punch: Add 1 to param2 -* Sneak+Punch: Add 8 to param2 -* Place: Subtract 1 from param2 -* Sneak+Place: Subtract 8 from param2 - -Note: Use the debug screen (F5) to see the param2 of the pointed node. - -## Falling Node Tool -Turns nodes into falling nodes. - -Usage: - -* Punch node: Make it fall -* Place: Try to teleport up to 2 units upwards, then make it fall - -## Entity Rotator -Changes the entity rotation (with `set_rotation`). - -Usage: - -* Punch entity: Rotate yaw -* Punch entity while holding down “Sneak” key: Rotate pitch -* Punch entity while holding down “Special” key (aka “Aux”): Rotate roll - -Each usage rotates the entity by 22.5°. - -## Entity Spawner -Spawns entities. - -Usage: - -* Punch to select entity or spawn one directly -* Place to place selected entity - -## Object Property Editor -Edits properties of objects. - -Usage: - -* Punch object to open a formspec that allows you to view and edit properties -* Punch air to edit properties of your own player object - -To edit a property, select it in the list, enter a new value (in Lua syntax) -and hit “Submit”. - -## Object Attacher -Allows you to attach an object to another one. - -Basic usage: -* First select the parent object, then the child object that should be attached -* Selecting an object is done by punching it -* Sneak+punch to detach selected object -* If you punch air, you select yourself - -Configuration: -* Place: Increase attachment Y position -* Sneak+place: decrease attachment Y position -* Aux+place: Increase attachment X rotation -* Aux+Sneak+Rightclick: Decrease attachment X rotation - -Hint: To detach all objects nearby you (including on yourself), use the -`/detach` server command. - -## Object Mover -Move an object by a given distance. - -Usage: -* Punch object into the direction you want to move it -* Sneak+punch: Move object towards you -* Place: Increase move distance -* Sneak+place: Decrease move distance - -## Entity Visual Scaler -Change visual size of entities - -Usage: - -* Punch entity to increase visual size -* Sneak+punch entity to decrease visual size diff --git a/games/minimal/mods/testtools/init.lua b/games/minimal/mods/testtools/init.lua deleted file mode 100644 index a63c98377..000000000 --- a/games/minimal/mods/testtools/init.lua +++ /dev/null @@ -1,691 +0,0 @@ -local S = minetest.get_translator("testtools") -local F = minetest.formspec_escape - --- TODO: Add a Node Metadata tool - --- Param 2 Tool: Set param2 value of tools --- Punch: +1 --- Punch+Shift: +8 --- Place: -1 --- Place+Shift: -8 -minetest.register_tool("testtools:param2tool", { - description = S("Param2 Tool"), - inventory_image = "testtools_param2tool.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing) - if pointed_thing.type ~= "node" or (not pos) then - return - end - local add = 1 - if user then - local ctrl = user:get_player_control() - if ctrl.sneak then - add = 8 - end - end - local node = minetest.get_node(pos) - node.param2 = node.param2 + add - minetest.swap_node(pos, node) - end, - on_place = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing) - if pointed_thing.type ~= "node" or (not pos) then - return - end - local add = -1 - if user then - local ctrl = user:get_player_control() - if ctrl.sneak then - add = -8 - end - end - local node = minetest.get_node(pos) - node.param2 = node.param2 + add - minetest.swap_node(pos, node) - end, -}) - -minetest.register_tool("testtools:node_setter", { - description = S("Node Setter"), - inventory_image = "testtools_node_setter.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing) - if pointed_thing.type == "nothing" then - local meta = itemstack:get_meta() - meta:set_string("node", "air") - meta:set_int("node_param2", 0) - if user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), S("Now placing: @1 (param2=@2)", "air", 0)) - end - return itemstack - elseif pointed_thing.type ~= "node" or (not pos) then - return - end - local node = minetest.get_node(pos) - local meta = itemstack:get_meta() - meta:set_string("node", node.name) - meta:set_int("node_param2", node.param2) - if user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), S("Now placing: @1 (param2=@2)", node.name, node.param2)) - end - return itemstack - end, - on_secondary_use = function(itemstack, user, pointed_thing) - local meta = itemstack:get_meta() - local nodename = meta:get_string("node") or "" - local param2 = meta:get_int("node_param2") or 0 - - minetest.show_formspec(user:get_player_name(), "testtools:node_setter", - "size[4,4]".. - "field[0.5,1;3,1;nodename;"..F(S("Node name (itemstring):"))..";"..F(nodename).."]".. - "field[0.5,2;3,1;param2;"..F(S("param2:"))..";"..F(tostring(param2)).."]".. - "button_exit[0.5,3;3,1;submit;"..F(S("Submit")).."]" - ) - end, - on_place = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing) - local meta = itemstack:get_meta() - local nodename = meta:get_string("node") - if nodename == "" and user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), S("Punch a node first!")) - return - end - local param2 = meta:get_int("node_param2") - if not param2 then - param2 = 0 - end - local node = { name = nodename, param2 = param2 } - if not minetest.registered_nodes[nodename] then - minetest.chat_send_player(user:get_player_name(), S("Cannot set unknown node: @1", nodename)) - return - end - minetest.set_node(pos, node) - end, -}) - -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "testtools:node_setter" then - local playername = player:get_player_name() - local witem = player:get_wielded_item() - if witem:get_name() == "testtools:node_setter" then - if fields.nodename and fields.param2 then - local param2 = tonumber(fields.param2) - if not param2 then - return - end - local meta = witem:get_meta() - meta:set_string("node", fields.nodename) - meta:set_int("node_param2", param2) - player:set_wielded_item(witem) - end - end - end -end) - -minetest.register_tool("testtools:remover", { - description = S("Remover"), - inventory_image = "testtools_remover.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing) - if pointed_thing.type == "node" and pos ~= nil then - minetest.remove_node(pos) - elseif pointed_thing.type == "object" then - local obj = pointed_thing.ref - if not obj:is_player() then - obj:remove() - end - end - end, -}) - -minetest.register_tool("testtools:falling_node_tool", { - description = S("Falling Node Tool"), - inventory_image = "testtools_falling_node_tool.png", - groups = { testtool = 1, disable_repair = 1 }, - on_place = function(itemstack, user, pointed_thing) - -- Teleport node 1-2 units upwards (if possible) and make it fall - local pos = minetest.get_pointed_thing_position(pointed_thing) - if pointed_thing.type ~= "node" or (not pos) then - return - end - local ok = false - local highest - for i=1,2 do - local above = {x=pos.x,y=pos.y+i,z=pos.z} - local n2 = minetest.get_node(above) - local def2 = minetest.registered_nodes[n2.name] - if def2 and (not def2.walkable) then - highest = above - else - break - end - end - if highest then - local node = minetest.get_node(pos) - local metatable = minetest.get_meta(pos):to_table() - minetest.remove_node(pos) - minetest.set_node(highest, node) - local meta_highest = minetest.get_meta(highest) - meta_highest:from_table(metatable) - ok = minetest.spawn_falling_node(highest) - else - ok = minetest.spawn_falling_node(pos) - end - if not ok and user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), S("Falling node could not be spawned!")) - end - end, - on_use = function(itemstack, user, pointed_thing) - local pos = minetest.get_pointed_thing_position(pointed_thing) - if pointed_thing.type ~= "node" or (not pos) then - return - end - local ok = minetest.spawn_falling_node(pos) - if not ok and user and user:is_player() then - minetest.chat_send_player(user:get_player_name(), S("Falling node could not be spawned!")) - end - end, -}) - -minetest.register_tool("testtools:rotator", { - description = S("Entity Rotator"), - inventory_image = "testtools_entity_rotator.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "object" then - return - end - local obj = pointed_thing.ref - if obj:is_player() then - -- No player rotation - return - else - local axis = "y" - if user and user:is_player() then - local ctrl = user:get_player_control() - if ctrl.sneak then - axis = "x" - elseif ctrl.aux1 then - axis = "z" - end - end - local rot = obj:get_rotation() - rot[axis] = rot[axis] + math.pi/8 - if rot[axis] > math.pi*2 then - rot[axis] = rot[axis] - math.pi*2 - end - obj:set_rotation(rot) - end - end, -}) - -local mover_config = function(itemstack, user, pointed_thing) - if not (user and user:is_player()) then - return - end - local name = user:get_player_name() - local ctrl = user:get_player_control() - local meta = itemstack:get_meta() - local dist = 1.0 - if meta:contains("distance") then - dist = meta:get_int("distance") - end - if ctrl.sneak then - dist = dist - 1 - else - dist = dist + 1 - end - meta:set_int("distance", dist) - minetest.chat_send_player(user:get_player_name(), S("distance=@1/10", dist*2)) - return itemstack -end - -minetest.register_tool("testtools:object_mover", { - description = S("Object Mover"), - inventory_image = "testtools_object_mover.png", - groups = { testtool = 1, disable_repair = 1 }, - on_place = mover_config, - on_secondary_use = mover_config, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "object" then - return - end - local obj = pointed_thing.ref - if not (user and user:is_player()) then - return - end - local yaw = user:get_look_horizontal() - local dir = minetest.yaw_to_dir(yaw) - local pos = obj:get_pos() - local pitch = user:get_look_vertical() - if pitch > 0.25 * math.pi then - dir.y = -1 - dir.x = 0 - dir.z = 0 - elseif pitch < -0.25 * math.pi then - dir.y = 1 - dir.x = 0 - dir.z = 0 - end - local ctrl = user:get_player_control() - if ctrl.sneak then - dir = vector.multiply(dir, -1) - end - local meta = itemstack:get_meta() - if meta:contains("distance") then - local dist = meta:get_int("distance") - dir = vector.multiply(dir, dist*0.2) - end - pos = vector.add(pos, dir) - obj:set_pos(pos) - end, -}) - - - -minetest.register_tool("testtools:entity_scaler", { - description = S("Entity Visual Scaler"), - inventory_image = "testtools_entity_scaler.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "object" then - return - end - local obj = pointed_thing.ref - if obj:is_player() then - -- No player scaling - return - else - local diff = 0.1 - if user and user:is_player() then - local ctrl = user:get_player_control() - if ctrl.sneak then - diff = -0.1 - end - end - local prop = obj:get_properties() - if not prop.visual_size then - prop.visual_size = { x=1, y=1, z=1 } - else - prop.visual_size = { x=prop.visual_size.x+diff, y=prop.visual_size.y+diff, z=prop.visual_size.z+diff } - if prop.visual_size.x <= 0.1 then - prop.visual_size.x = 0.1 - end - if prop.visual_size.y <= 0.1 then - prop.visual_size.y = 0.1 - end - if prop.visual_size.z <= 0.1 then - prop.visual_size.z = 0.1 - end - end - obj:set_properties(prop) - end - end, -}) - -local selections = {} -local entity_list -local function get_entity_list() - if entity_list then - return entity_list - end - local ents = minetest.registered_entities - local list = {} - for k,_ in pairs(ents) do - table.insert(list, k) - end - table.sort(list) - entity_list = list - return entity_list -end -minetest.register_tool("testtools:entity_spawner", { - description = S("Entity Spawner"), - inventory_image = "testtools_entity_spawner.png", - groups = { testtool = 1, disable_repair = 1 }, - on_place = function(itemstack, user, pointed_thing) - local name = user:get_player_name() - if selections[name] and pointed_thing.type == "node" then - local pos = pointed_thing.above - minetest.add_entity(pos, get_entity_list()[selections[name]]) - end - end, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type == "object" then - return - end - if user and user:is_player() then - local list = table.concat(get_entity_list(), ",") - local name = user:get_player_name() - local sel = selections[name] or "" - minetest.show_formspec(name, "testtools:entity_list", - "size[9,9]".. - "textlist[0,0;9,8;entity_list;"..list..";"..sel..";false]".. - "button[0,8;4,1;spawn;Spawn entity]" - ) - end - end, -}) - -local function prop_to_string(property) - if type(property) == "string" then - return "\"" .. property .. "\"" - elseif type(property) == "table" then - return tostring(dump(property)):gsub("\n", "") - else - return tostring(property) - end -end - -local property_formspec_data = {} -local property_formspec_index = {} -local selected_objects = {} -local function get_object_properties_form(obj, playername) - if not playername then return "" end - local props = obj:get_properties() - local str = "" - property_formspec_data[playername] = {} - local proplist = {} - for k,_ in pairs(props) do - table.insert(proplist, k) - end - table.sort(proplist) - for p=1, #proplist do - local k = proplist[p] - local v = props[k] - local newline = "" - newline = k .. " = " - newline = newline .. prop_to_string(v) - str = str .. F(newline) - if p < #proplist then - str = str .. "," - end - table.insert(property_formspec_data[playername], k) - end - return str -end - -local editor_formspec_selindex = {} - -local editor_formspec = function(playername, obj, value, sel) - if not value then - value = "" - end - if not sel then - sel = "" - end - local list = get_object_properties_form(obj, playername) - local title - if obj:is_player() then - title = S("Object properties of player “@1”", obj:get_player_name()) - else - local ent = obj:get_luaentity() - title = S("Object properties of @1", ent.name) - end - minetest.show_formspec(playername, "testtools:object_editor", - "size[9,9]".. - "label[0,0;"..F(title).."]".. - "textlist[0,0.5;9,7.5;object_props;"..list..";"..sel..";false]".. - "field[0.2,8.75;8,1;value;"..F(S("Value"))..";"..F(value).."]".. - "button[8,8.5;1,1;submit;"..F(S("Submit")).."]" - ) -end - -minetest.register_tool("testtools:object_editor", { - description = S("Object Property Editor"), - inventory_image = "testtools_object_editor.png", - groups = { testtool = 1, disable_repair = 1 }, - on_use = function(itemstack, user, pointed_thing) - if user and user:is_player() then - local name = user:get_player_name() - - if pointed_thing.type == "object" then - selected_objects[name] = pointed_thing.ref - elseif pointed_thing.type == "nothing" then - -- Use on yourself if pointing nothing - selected_objects[name] = user - else - -- Unsupported pointed thing - return - end - - local sel = editor_formspec_selindex[name] - local val - if selected_objects[name] and selected_objects[name]:get_properties() then - local props = selected_objects[name]:get_properties() - local keys = property_formspec_data[name] - if property_formspec_index[name] and props then - local key = keys[property_formspec_index[name]] - val = prop_to_string(props[key]) - end - end - - editor_formspec(name, selected_objects[name], val, sel) - end - end, -}) - -local ent_parent = {} -local ent_child = {} -local DEFAULT_ATTACH_OFFSET_Y = 11 - -local attacher_config = function(itemstack, user, pointed_thing) - if not (user and user:is_player()) then - return - end - if pointed_thing.type == "object" then - return - end - local name = user:get_player_name() - local ctrl = user:get_player_control() - local meta = itemstack:get_meta() - if ctrl.aux1 then - local rot_x = meta:get_float("rot_x") - if ctrl.sneak then - rot_x = rot_x - math.pi/8 - else - rot_x = rot_x + math.pi/8 - end - if rot_x > 6.2 then - rot_x = 0 - elseif rot_x < 0 then - rot_x = math.pi * (15/8) - end - minetest.chat_send_player(name, S("rotation=@1", minetest.pos_to_string({x=rot_x,y=0,z=0}))) - meta:set_float("rot_x", rot_x) - else - local pos_y - if meta:contains("pos_y") then - pos_y = meta:get_int("pos_y") - else - pos_y = DEFAULT_ATTACH_OFFSET_Y - end - if ctrl.sneak then - pos_y = pos_y - 1 - else - pos_y = pos_y + 1 - end - minetest.chat_send_player(name, S("position=@1", minetest.pos_to_string({x=0,y=pos_y,z=0}))) - meta:set_int("pos_y", pos_y) - end - return itemstack -end - -minetest.register_tool("testtools:object_attacher", { - description = S("Object Attacher"), - inventory_image = "testtools_object_attacher.png", - groups = { testtool = 1, disable_repair = 1 }, - on_place = attacher_config, - on_secondary_use = attacher_config, - on_use = function(itemstack, user, pointed_thing) - if user and user:is_player() then - local name = user:get_player_name() - local selected_object - if pointed_thing.type == "object" then - selected_object = pointed_thing.ref - elseif pointed_thing.type == "nothing" then - selected_object = user - else - return - end - local ctrl = user:get_player_control() - if ctrl.sneak then - if selected_object:get_attach() then - selected_object:set_detach() - minetest.chat_send_player(name, S("Object detached!")) - else - minetest.chat_send_player(name, S("Object is not attached!")) - end - return - end - local parent = ent_parent[name] - local child = ent_child[name] - local ename = S("") - if not parent then - parent = selected_object - ent_parent[name] = parent - elseif not child then - child = selected_object - ent_child[name] = child - end - local entity = selected_object:get_luaentity() - if entity then - ename = entity.name - elseif selected_object:is_player() then - ename = selected_object:get_player_name() - end - if selected_object == parent then - minetest.chat_send_player(name, S("Parent object selected: @1", ename)) - elseif selected_object == child then - minetest.chat_send_player(name, S("Child object selected: @1", ename)) - end - if parent and child then - if parent == child then - minetest.chat_send_player(name, S("Can't attach an object to itself!")) - ent_parent[name] = nil - ent_child[name] = nil - return - end - local meta = itemstack:get_meta() - local y - if meta:contains("pos_y") then - y = meta:get_int("pos_y") - else - y = DEFAULT_ATTACH_OFFSET_Y - end - local rx = meta:get_float("rot_x") or 0 - local offset = {x=0,y=y,z=0} - local angle = {x=rx,y=0,z=0} - child:set_attach(parent, "", offset, angle) - local check_parent = child:get_attach() - if check_parent then - minetest.chat_send_player(name, S("Object attached! position=@1, rotation=@2", - minetest.pos_to_string(offset), minetest.pos_to_string(angle))) - else - minetest.chat_send_player(name, S("Attachment failed!")) - end - ent_parent[name] = nil - ent_child[name] = nil - end - end - end, -}) - --- Use loadstring to parse param as a Lua value -local function use_loadstring(param, player) - -- For security reasons, require 'server' priv, just in case - -- someone is actually crazy enough to run this on a public server. - local privs = minetest.get_player_privs(player:get_player_name()) - if not privs.server then - return false, "You need 'server' privilege to change object properties!" - end - if not param then - return false, "Failed: parameter is nil" - end - --[[ DANGER ZONE ]] - -- Interpret string as Lua value - local func, errormsg = loadstring("return (" .. param .. ")") - if not func then - return false, "Failed: " .. errormsg - end - - -- Apply sandbox here using setfenv - setfenv(func, {}) - - -- Run it - local good, errOrResult = pcall(func) - if not good then - -- A Lua error was thrown - return false, "Failed: " .. errOrResult - end - - -- errOrResult will be the value - return true, errOrResult -end - -minetest.register_on_player_receive_fields(function(player, formname, fields) - if not (player and player:is_player()) then - return - end - if formname == "testtools:entity_list" then - local name = player:get_player_name() - if fields.entity_list then - local expl = minetest.explode_textlist_event(fields.entity_list) - if expl.type == "DCL" then - local pos = vector.add(player:get_pos(), {x=0,y=1,z=0}) - selections[name] = expl.index - minetest.add_entity(pos, get_entity_list()[expl.index]) - return - elseif expl.type == "CHG" then - selections[name] = expl.index - return - end - elseif fields.spawn and selections[name] then - local pos = vector.add(player:get_pos(), {x=0,y=1,z=0}) - minetest.add_entity(pos, get_entity_list()[selections[name]]) - return - end - elseif formname == "testtools:object_editor" then - local name = player:get_player_name() - if fields.object_props then - local expl = minetest.explode_textlist_event(fields.object_props) - if expl.type == "DCL" or expl.type == "CHG" then - property_formspec_index[name] = expl.index - - local props = selected_objects[name]:get_properties() - local keys = property_formspec_data[name] - if (not property_formspec_index[name]) or (not props) then - return - end - local key = keys[property_formspec_index[name]] - editor_formspec_selindex[name] = expl.index - editor_formspec(name, selected_objects[name], prop_to_string(props[key]), expl.index) - return - end - end - if fields.submit then - local props = selected_objects[name]:get_properties() - local keys = property_formspec_data[name] - if (not property_formspec_index[name]) or (not props) then - return - end - local key = keys[property_formspec_index[name]] - if not key then - return - end - local success, str = use_loadstring(fields.value, player) - if success then - props[key] = str - else - minetest.chat_send_player(name, str) - return - end - selected_objects[name]:set_properties(props) - local sel = editor_formspec_selindex[name] - editor_formspec(name, selected_objects[name], prop_to_string(props[key]), sel) - return - end - end -end) diff --git a/games/minimal/mods/testtools/mod.conf b/games/minimal/mods/testtools/mod.conf deleted file mode 100644 index cde1b2685..000000000 --- a/games/minimal/mods/testtools/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = testtools -description = Some tools to directly manipulate nodes and entities. Great for development and testing diff --git a/games/minimal/mods/testtools/textures/testtools_entity_rotator.png b/games/minimal/mods/testtools/textures/testtools_entity_rotator.png deleted file mode 100644 index 17ebb2d35..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_entity_rotator.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_entity_scaler.png b/games/minimal/mods/testtools/textures/testtools_entity_scaler.png deleted file mode 100644 index 4909c25b0..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_entity_scaler.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_entity_spawner.png b/games/minimal/mods/testtools/textures/testtools_entity_spawner.png deleted file mode 100644 index 6199e0145..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_entity_spawner.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_falling_node_tool.png b/games/minimal/mods/testtools/textures/testtools_falling_node_tool.png deleted file mode 100644 index 30099a7ef..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_falling_node_tool.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_node_setter.png b/games/minimal/mods/testtools/textures/testtools_node_setter.png deleted file mode 100644 index 8599438de..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_node_setter.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_object_attacher.png b/games/minimal/mods/testtools/textures/testtools_object_attacher.png deleted file mode 100644 index 4d9bf6fd1..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_object_attacher.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_object_editor.png b/games/minimal/mods/testtools/textures/testtools_object_editor.png deleted file mode 100644 index d1ce9cecd..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_object_editor.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_object_mover.png b/games/minimal/mods/testtools/textures/testtools_object_mover.png deleted file mode 100644 index 8b14e9fb2..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_object_mover.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_param2tool.png b/games/minimal/mods/testtools/textures/testtools_param2tool.png deleted file mode 100644 index dbc663575..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_param2tool.png and /dev/null differ diff --git a/games/minimal/mods/testtools/textures/testtools_remover.png b/games/minimal/mods/testtools/textures/testtools_remover.png deleted file mode 100644 index 73f14cd54..000000000 Binary files a/games/minimal/mods/testtools/textures/testtools_remover.png and /dev/null differ diff --git a/games/minimal/mods/tiled/init.lua b/games/minimal/mods/tiled/init.lua deleted file mode 100644 index 68ead8e3a..000000000 --- a/games/minimal/mods/tiled/init.lua +++ /dev/null @@ -1,33 +0,0 @@ -minetest.register_node("tiled:tiled", { - description = "Tiled Node (world-aligned)", - tiles = {{ - name = "tiled_tiled.png", - align_style = "world", - scale = 8, - }}, - groups = {cracky=3}, -}) - -minetest.register_node("tiled:tiled_n", { - description = "Tiled Node (node-aligned)", - tiles = {{ - name = "tiled_tiled.png", - align_style = "node", - scale = 8, - }}, - groups = {cracky=3}, -}) - -stairs.register_stair_and_slab("tiled_n", "tiled:tiled", - {cracky=3}, - {{name="tiled_tiled.png", align_style="node", scale=8}}, - "Tiled Stair (node-aligned)", - "Tiled Slab (node-aligned)") - -stairs.register_stair_and_slab("tiled", "tiled:tiled", - {cracky=3}, - {{name="tiled_tiled.png", align_style="world", scale=8}}, - "Tiled Stair (world-aligned)", - "Tiled Slab (world-aligned)") - - diff --git a/games/minimal/mods/tiled/mod.conf b/games/minimal/mods/tiled/mod.conf deleted file mode 100644 index 78b19f93b..000000000 --- a/games/minimal/mods/tiled/mod.conf +++ /dev/null @@ -1,3 +0,0 @@ -name = tiled -description = Add nodes with a special texture that spans multiple nodes (aka "world-aligned") -depends = stairs diff --git a/games/minimal/mods/tiled/textures/tiled_tiled.png b/games/minimal/mods/tiled/textures/tiled_tiled.png deleted file mode 100644 index 363a26487..000000000 Binary files a/games/minimal/mods/tiled/textures/tiled_tiled.png and /dev/null differ diff --git a/games/minimal/mods/unittests/crafting.lua b/games/minimal/mods/unittests/crafting.lua deleted file mode 100644 index eff13ce09..000000000 --- a/games/minimal/mods/unittests/crafting.lua +++ /dev/null @@ -1,120 +0,0 @@ --- Test minetest.clear_craft function -local function test_clear_craft() - minetest.log("info", "[unittests] Testing minetest.clear_craft") - -- Clearing by output - minetest.register_craft({ - output = "foo", - recipe = {{"bar"}} - }) - minetest.register_craft({ - output = "foo 4", - recipe = {{"foo", "bar"}} - }) - assert(#minetest.get_all_craft_recipes("foo") == 2) - minetest.clear_craft({output="foo"}) - assert(minetest.get_all_craft_recipes("foo") == nil) - -- Clearing by input - minetest.register_craft({ - output = "foo 4", - recipe = {{"foo", "bar"}} - }) - assert(#minetest.get_all_craft_recipes("foo") == 1) - minetest.clear_craft({recipe={{"foo", "bar"}}}) - assert(minetest.get_all_craft_recipes("foo") == nil) -end - --- Test minetest.get_craft_result function -local function test_get_craft_result() - minetest.log("info", "[unittests] Testing minetest.get_craft_result") - - -- normal - local input = { - method = "normal", - width = 2, - items = {"", "unittests:coal_lump", "", "unittests:stick"} - } - minetest.log("info", "[unittests] torch crafting input: "..dump(input)) - local output, decremented_input = minetest.get_craft_result(input) - minetest.log("info", "[unittests] torch crafting output: "..dump(output)) - minetest.log("info", "[unittests] torch crafting decremented input: "..dump(decremented_input)) - assert(output.item) - minetest.log("info", "[unittests] torch crafting output.item:to_table(): "..dump(output.item:to_table())) - assert(output.item:get_name() == "unittests:torch") - assert(output.item:get_count() == 4) - - -- fuel - input = { - method = "fuel", - width = 1, - items = {"unittests:coal_lump"} - } - minetest.log("info", "[unittests] coal fuel input: "..dump(input)) - output, decremented_input = minetest.get_craft_result(input) - minetest.log("info", "[unittests] coal fuel output: "..dump(output)) - minetest.log("info", "[unittests] coal fuel decremented input: "..dump(decremented_input)) - assert(output.time) - assert(output.time > 0) - - -- cooking - input = { - method = "cooking", - width = 1, - items = {"unittests:iron_lump"} - } - minetest.log("info", "[unittests] iron lump cooking input: "..dump(output)) - output, decremented_input = minetest.get_craft_result(input) - minetest.log("info", "[unittests] iron lump cooking output: "..dump(output)) - minetest.log("info", "[unittests] iron lump cooking decremented input: "..dump(decremented_input)) - assert(output.time) - assert(output.time > 0) - assert(output.item) - minetest.log("info", "[unittests] iron lump cooking output.item:to_table(): "..dump(output.item:to_table())) - assert(output.item:get_name() == "unittests:steel_ingot") - assert(output.item:get_count() == 1) - - -- tool repair (repairable) - input = { - method = "normal", - width = 2, - -- Using a wear of 60000 - items = {"unittests:repairable_tool 1 60000", "unittests:repairable_tool 1 60000"} - } - minetest.log("info", "[unittests] repairable tool crafting input: "..dump(input)) - output, decremented_input = minetest.get_craft_result(input) - minetest.log("info", "[unittests] repairable tool crafting output: "..dump(output)) - minetest.log("info", "[unittests] repairable tool crafting decremented input: "..dump(decremented_input)) - assert(output.item) - minetest.log("info", "[unittests] repairable tool crafting output.item:to_table(): "..dump(output.item:to_table())) - assert(output.item:get_name() == "unittests:repairable_tool") - -- Test the wear value. - -- See src/craftdef.cpp in Minetest source code for the formula. The formula to calculate - -- the value 51187 is: - -- 65536 - ((65536-60000)+(65536-60000)) + floor(additonal_wear * 65536 + 0.5) = 51187 - -- where additional_wear = 0.05 - assert(output.item:get_wear() == 51187) - assert(output.item:get_count() == 1) - - -- failing tool repair (unrepairable) - input = { - method = "normal", - width = 2, - items = {"unittests:unrepairable_tool 1 60000", "unittests:unrepairable_tool 1 60000"} - } - minetest.log("info", "[unittests] unrepairable tool crafting input: "..dump(input)) - output, decremented_input = minetest.get_craft_result(input) - minetest.log("info", "[unittests] unrepairable tool crafting output: "..dump(output)) - minetest.log("info", "[unittests] unrepairable tool crafting decremented input: "..dump(decremented_input)) - assert(output.item) - minetest.log("info", "[unittests] unrepairable tool crafting output.item:to_table(): "..dump(output.item:to_table())) - -- unrepairable tool must not yield any output - assert(output.item:get_name() == "") - -end - -function unittests.test_crafting() - test_clear_craft() - test_get_craft_result() - minetest.log("action", "[unittests] Crafting tests passed!") - return true -end - diff --git a/games/minimal/mods/unittests/crafting_prepare.lua b/games/minimal/mods/unittests/crafting_prepare.lua deleted file mode 100644 index a09734827..000000000 --- a/games/minimal/mods/unittests/crafting_prepare.lua +++ /dev/null @@ -1,88 +0,0 @@ --- Registering some dummy items and recipes for the crafting tests - -minetest.register_craftitem("unittests:torch", { - description = "Crafting Test Item: Torch", - inventory_image = "unittests_torch.png", - - groups = { dummy = 1 }, -}) -minetest.register_craftitem("unittests:coal_lump", { - description = "Crafting Test Item: Coal Lump", - inventory_image = "unittests_coal_lump.png", - - groups = { dummy = 1 }, -}) -minetest.register_craftitem("unittests:stick", { - description = "Crafting Test Item: Stick", - inventory_image = "unittests_stick.png", - - groups = { dummy = 1 }, -}) -minetest.register_craftitem("unittests:iron_lump", { - description = "Crafting Test Item: Iron Lump", - inventory_image = "unittests_iron_lump.png", - - groups = { dummy = 1 }, -}) -minetest.register_craftitem("unittests:steel_ingot", { - description = "Crafting Test Item: Steel Ingot", - inventory_image = "unittests_steel_ingot.png", - - groups = { dummy = 1 }, -}) - --- Recipes for tests: Normal crafting, cooking and fuel - -minetest.register_craft({ - output = 'unittests:torch 4', - recipe = { - {'unittests:coal_lump'}, - {'unittests:stick'}, - } -}) - -minetest.register_craft({ - type = "cooking", - output = "unittests:steel_ingot", - recipe = "unittests:iron_lump", -}) - -minetest.register_craft({ - type = "fuel", - recipe = "unittests:coal_lump", - burntime = 40, -}) - --- Test tool repair -minetest.register_craft({ - type = "toolrepair", - additional_wear = -0.05, -}) - --- Test the disable_repair=1 group -minetest.register_tool("unittests:unrepairable_tool", { - description = "Crafting Test Item: Unrepairable Tool", - inventory_image = "unittests_unrepairable_tool.png", - tool_capabilities = { - groupcaps = { - cracky = { - times = {3, 2, 1}, - } - } - }, - groups = { disable_repair = 1, dummy = 1 } -}) - -minetest.register_tool("unittests:repairable_tool", { - description = "Crafting Test Item: Repairable Tool", - inventory_image = "unittests_repairable_tool.png", - tool_capabilities = { - groupcaps = { - cracky = { - times = {3, 2, 1}, - } - } - }, - - groups = { dummy = 1 }, -}) diff --git a/games/minimal/mods/unittests/init.lua b/games/minimal/mods/unittests/init.lua deleted file mode 100644 index 6c1728420..000000000 --- a/games/minimal/mods/unittests/init.lua +++ /dev/null @@ -1,16 +0,0 @@ -unittests = {} - -local modpath = minetest.get_modpath("unittests") -dofile(modpath .. "/random.lua") -dofile(modpath .. "/player.lua") -dofile(modpath .. "/crafting_prepare.lua") -dofile(modpath .. "/crafting.lua") - -if minetest.settings:get_bool("devtest_unittests_autostart", false) then - unittests.test_random() - unittests.test_crafting() - minetest.register_on_joinplayer(function(player) - unittests.test_player(player) - end) -end - diff --git a/games/minimal/mods/unittests/mod.conf b/games/minimal/mods/unittests/mod.conf deleted file mode 100644 index 0d5e3c959..000000000 --- a/games/minimal/mods/unittests/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = unittests -description = Adds automated unit tests for the engine diff --git a/games/minimal/mods/unittests/player.lua b/games/minimal/mods/unittests/player.lua deleted file mode 100644 index 10781a95f..000000000 --- a/games/minimal/mods/unittests/player.lua +++ /dev/null @@ -1,73 +0,0 @@ --- --- HP Change Reasons --- -local expect = nil -local function run_hpchangereason_tests(player) - expect = { type = "set_hp", from = "mod" } - player:set_hp(3) - assert(expect == nil) - - expect = { a = 234, type = "set_hp", from = "mod" } - player:set_hp(7, { a= 234 }) - assert(expect == nil) - - expect = { df = 3458973454, type = "fall", from = "mod" } - player:set_hp(10, { type = "fall", df = 3458973454 }) - assert(expect == nil) - - player:set_hp(20) -end - -local function run_player_meta_tests(player) - local meta = player:get_meta() - meta:set_string("foo", "bar") - assert(meta:contains("foo")) - assert(meta:get_string("foo") == "bar") - assert(meta:get("foo") == "bar") - - local meta2 = player:get_meta() - assert(meta2:get_string("foo") == "bar") - assert(meta2:get("foo") == "bar") - assert(meta:equals(meta2)) - - meta:set_string("bob", "dillan") - assert(meta:get_string("foo") == "bar") - assert(meta:get_string("bob") == "dillan") - assert(meta:get("bob") == "dillan") - assert(meta2:get_string("foo") == "bar") - assert(meta2:get_string("bob") == "dillan") - assert(meta2:get("bob") == "dillan") - assert(meta:equals(meta2)) - - meta:set_string("foo", "") - assert(not meta:contains("foo")) - assert(meta:get("foo") == nil) - assert(meta:get_string("foo") == "") - assert(meta:equals(meta2)) -end - -function unittests.test_player(player) - minetest.register_on_player_hpchange(function(player, hp, reason) - if not expect then - return - end - - for key, value in pairs(reason) do - assert(expect[key] == value) - end - - for key, value in pairs(expect) do - assert(reason[key] == value) - end - - expect = nil - end) - - run_hpchangereason_tests(player) - run_player_meta_tests(player) - local msg = "Player tests passed for player '"..player:get_player_name().."'!" - minetest.chat_send_all(msg) - minetest.log("action", "[unittests] "..msg) - return true -end - diff --git a/games/minimal/mods/unittests/random.lua b/games/minimal/mods/unittests/random.lua deleted file mode 100644 index f94f0a88e..000000000 --- a/games/minimal/mods/unittests/random.lua +++ /dev/null @@ -1,10 +0,0 @@ -function unittests.test_random() - -- Try out PseudoRandom - minetest.log("action", "[unittests] Testing PseudoRandom ...") - local pseudo = PseudoRandom(13) - assert(pseudo:next() == 22290) - assert(pseudo:next() == 13854) - minetest.log("action", "[unittests] PseudoRandom test passed!") - return true -end - diff --git a/games/minimal/mods/unittests/textures/unittests_coal_lump.png b/games/minimal/mods/unittests/textures/unittests_coal_lump.png deleted file mode 100644 index f460d909e..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_coal_lump.png and /dev/null differ diff --git a/games/minimal/mods/unittests/textures/unittests_iron_lump.png b/games/minimal/mods/unittests/textures/unittests_iron_lump.png deleted file mode 100644 index 22f43e9cc..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_iron_lump.png and /dev/null differ diff --git a/games/minimal/mods/unittests/textures/unittests_repairable_tool.png b/games/minimal/mods/unittests/textures/unittests_repairable_tool.png deleted file mode 100644 index 46fbbaa74..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_repairable_tool.png and /dev/null differ diff --git a/games/minimal/mods/unittests/textures/unittests_steel_ingot.png b/games/minimal/mods/unittests/textures/unittests_steel_ingot.png deleted file mode 100644 index 6977696a2..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_steel_ingot.png and /dev/null differ diff --git a/games/minimal/mods/unittests/textures/unittests_stick.png b/games/minimal/mods/unittests/textures/unittests_stick.png deleted file mode 100644 index ffdce70d4..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_stick.png and /dev/null differ diff --git a/games/minimal/mods/unittests/textures/unittests_torch.png b/games/minimal/mods/unittests/textures/unittests_torch.png deleted file mode 100644 index ba5eebef0..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_torch.png and /dev/null differ diff --git a/games/minimal/mods/unittests/textures/unittests_unrepairable_tool.png b/games/minimal/mods/unittests/textures/unittests_unrepairable_tool.png deleted file mode 100644 index c676213a5..000000000 Binary files a/games/minimal/mods/unittests/textures/unittests_unrepairable_tool.png and /dev/null differ diff --git a/games/minimal/mods/util_commands/init.lua b/games/minimal/mods/util_commands/init.lua deleted file mode 100644 index ad8d3f9ba..000000000 --- a/games/minimal/mods/util_commands/init.lua +++ /dev/null @@ -1,137 +0,0 @@ -minetest.register_chatcommand("hotbar", { - params = "", - description = "Set hotbar size", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - local size = tonumber(param) - if not size then - return false, "Missing or incorrect size parameter!" - end - local ok = player:hud_set_hotbar_itemcount(size) - if ok then - return true - else - return false, "Invalid item count!" - end - end, -}) - -minetest.register_chatcommand("hp", { - params = "", - description = "Set your health", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - local hp = tonumber(param) - if not hp then - return false, "Missing or incorrect hp parameter!" - end - player:set_hp(hp) - return true - end, -}) - -minetest.register_chatcommand("zoom", { - params = "[]", - description = "Set or display your zoom_fov", - func = function(name, param) - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - if param == "" then - local fov = player:get_properties().zoom_fov - return true, "zoom_fov = "..tostring(fov) - end - local fov = tonumber(param) - if not fov then - return false, "Missing or incorrect zoom_fov parameter!" - end - player:set_properties({zoom_fov = fov}) - fov = player:get_properties().zoom_fov - return true, "zoom_fov = "..tostring(fov) - end, -}) - - - -local s_infplace = minetest.settings:get("devtest_infplace") -if s_infplace == "true" then - infplace = true -elseif s_infplace == "false" then - infplace = false -else - infplace = minetest.settings:get_bool("creative_mode", false) -end - -minetest.register_chatcommand("infplace", { - params = "", - description = "Toggle infinite node placement", - func = function(name, param) - infplace = not infplace - if infplace then - minetest.chat_send_all("Infinite node placement enabled!") - minetest.log("action", "Infinite node placement enabled") - else - minetest.chat_send_all("Infinite node placement disabled!") - minetest.log("action", "Infinite node placement disabled") - end - return true - end, -}) - -minetest.register_chatcommand("detach", { - params = "[]", - description = "Detach all objects nearby", - func = function(name, param) - local radius = tonumber(param) - if type(radius) ~= "number" then - radius = 8 - end - if radius < 1 then - radius = 1 - end - local player = minetest.get_player_by_name(name) - if not player then - return false, "No player." - end - local objs = minetest.get_objects_inside_radius(player:get_pos(), radius) - local num = 0 - for o=1, #objs do - if objs[o]:get_attach() then - objs[o]:set_detach() - num = num + 1 - end - end - return true, string.format("%d object(s) detached.", num) - end, -}) - - --- Unlimited node placement -minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) - if placer and placer:is_player() then - return infplace - end -end) - --- Don't pick up if the item is already in the inventory -local old_handle_node_drops = minetest.handle_node_drops -function minetest.handle_node_drops(pos, drops, digger) - if not digger or not digger:is_player() or not infplace then - return old_handle_node_drops(pos, drops, digger) - end - local inv = digger:get_inventory() - if inv then - for _, item in ipairs(drops) do - if not inv:contains_item("main", item, true) then - inv:add_item("main", item) - end - end - end -end diff --git a/games/minimal/mods/util_commands/mod.conf b/games/minimal/mods/util_commands/mod.conf deleted file mode 100644 index fea6dd3e9..000000000 --- a/games/minimal/mods/util_commands/mod.conf +++ /dev/null @@ -1,2 +0,0 @@ -name = util_commands -description = Random server commands to make testing easier and more convenient diff --git a/games/minimal/screenshot.png b/games/minimal/screenshot.png deleted file mode 100644 index 7324883f6..000000000 Binary files a/games/minimal/screenshot.png and /dev/null differ diff --git a/games/minimal/settingtypes.txt b/games/minimal/settingtypes.txt deleted file mode 100644 index 40ee5845b..000000000 --- a/games/minimal/settingtypes.txt +++ /dev/null @@ -1,37 +0,0 @@ -# If enabled, nodes won't be used up when placed. -# Note: This behavior can also be toggled in-game with the /infplace command. -# -# - true: enabled -# - false: disabled -# - auto: only enabled when Creative Mode is enabled (default) -devtest_infplace (Infinite node placement) enum auto true,false,auto - -# If enabled, new players receive some initial items when joining for the first time. -give_initial_stuff (Give initial stuff) bool true - -# If enabled, automated tests of the Lua API such as player health, crafting and PseudoRandom will be performed on startup. -devtest_unittests_autostart (Perform unit tests) bool false - -# If enabled, the game will use all mapgen aliases for the v6 mapgen. -# If disabled, it will only use a minimal set of mapgen aliases. -# If enabled, there should be biome-specific tree, leaves and ground nodes. If disabled, stuff should use fallback nodes (like stone instead of desert stone). -# -# Many mapgen aliases have fallback values when no value is provided. Having this setting disabled can be useful to test whether those fallback values are functional. -devtest_v6_mapgen_aliases (Use all v6 mapgen aliases) bool false - -# If enabled, the game will use dungeon stairs by enabling the corresponding mapgen aliases. -# -# Disabling this setting can be useful to test whether dungeons still work when stairs are not defined. -devtest_dungeon_stairs (Generate dungeon stairs) bool false - -# If enabled, the mapgen alias 'mapgen_mossycobble' will be used. This should enable random mossy cobblestone in dungeons. -# If disabled, it won't be used. The engine should fall back to cobble instead. -devtest_dungeon_mossycobble (Generate mossy cobblestone) bool false - -# If enabled, some very basic biomes will be registered. -devtest_register_biomes (Register biomes) bool true - -# If set to true, will show an inventory image for nodes that have no inventory image as of Minetest 5.1.0. -# This is due to . -# This is only added to make the items more visible to avoid confusion, but you will no longer see the default inventory images for these items. When you want to test the default inventory image of drawtypes, this should be turned off. -testnodes_show_fallback_image (Use fallback inventory images) bool false diff --git a/src/unittest/CMakeLists.txt b/src/unittest/CMakeLists.txt index 82f9a4a13..5703b8906 100644 --- a/src/unittest/CMakeLists.txt +++ b/src/unittest/CMakeLists.txt @@ -43,7 +43,7 @@ set (UNITTEST_CLIENT_SRCS PARENT_SCOPE) set (TEST_WORLDDIR ${CMAKE_CURRENT_SOURCE_DIR}/test_world) -set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/minimal) +set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/devtest) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in" diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp index 0757323f4..799936757 100644 --- a/src/unittest/test_servermodmanager.cpp +++ b/src/unittest/test_servermodmanager.cpp @@ -88,7 +88,7 @@ void TestServerModManager::testCreation() { std::string path = std::string(TEST_WORLDDIR) + DIR_DELIM + "world.mt"; Settings world_config; - world_config.set("gameid", "minimal"); + world_config.set("gameid", "devtest"); UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true); ServerModManager sm(TEST_WORLDDIR); } @@ -118,10 +118,10 @@ void TestServerModManager::testGetMods() const auto &mods = sm.getMods(); UASSERTEQ(bool, mods.empty(), false); - // Ensure we found default mod inside the test folder + // Ensure we found basenodes mod (part of devtest) bool default_found = false; for (const auto &m : mods) { - if (m.name == "default") + if (m.name == "basenodes") default_found = true; // Verify if paths are not empty @@ -135,7 +135,7 @@ void TestServerModManager::testGetModspec() { ServerModManager sm(std::string(TEST_WORLDDIR)); UASSERTEQ(const ModSpec *, sm.getModSpec("wrongmod"), NULL); - UASSERT(sm.getModSpec("default") != NULL); + UASSERT(sm.getModSpec("basenodes") != NULL); } void TestServerModManager::testGetModNamesWrongDir() @@ -152,7 +152,7 @@ void TestServerModManager::testGetModNames() std::vector result; sm.getModNames(result); UASSERTEQ(bool, result.empty(), false); - UASSERT(std::find(result.begin(), result.end(), "default") != result.end()); + UASSERT(std::find(result.begin(), result.end(), "basenodes") != result.end()); } void TestServerModManager::testGetModMediaPathsWrongDir() diff --git a/util/test_multiplayer.sh b/util/test_multiplayer.sh index 9ebfe73be..176cf11d9 100755 --- a/util/test_multiplayer.sh +++ b/util/test_multiplayer.sh @@ -1,6 +1,6 @@ #!/bin/bash dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -gameid=minimal +gameid=devtest minetest=$dir/../bin/minetest testspath=$dir/../tests worldpath=$testspath/testworld_$gameid -- cgit v1.2.3 From 58f523e363099d377d2927f16244073d104c07e9 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 27 May 2020 00:17:23 +0200 Subject: Fix liquids refusing to flow in X+ or Z+ in some cases (#9874) Applies when a different: - falling liquid is neighboring - liquid is below --- src/map.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/map.cpp b/src/map.cpp index 677cbc869..7c776b070 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -478,6 +478,16 @@ void Map::PrintInfo(std::ostream &out) #define WATER_DROP_BOOST 4 +const static v3s16 liquid_6dirs[6] = { + // order: upper before same level before lower + v3s16( 0, 1, 0), + v3s16( 0, 0, 1), + v3s16( 1, 0, 0), + v3s16( 0, 0,-1), + v3s16(-1, 0, 0), + v3s16( 0,-1, 0) +}; + enum NeighborType : u8 { NEIGHBOR_UPPER, NEIGHBOR_SAME_LEVEL, @@ -587,7 +597,6 @@ void Map::transformLiquids(std::map &modified_blocks, /* Collect information about the environment */ - const v3s16 *dirs = g_6dirs; NodeNeighbor sources[6]; // surrounding sources int num_sources = 0; NodeNeighbor flows[6]; // surrounding flowing liquid nodes @@ -601,16 +610,16 @@ void Map::transformLiquids(std::map &modified_blocks, for (u16 i = 0; i < 6; i++) { NeighborType nt = NEIGHBOR_SAME_LEVEL; switch (i) { - case 1: + case 0: nt = NEIGHBOR_UPPER; break; - case 4: + case 5: nt = NEIGHBOR_LOWER; break; default: break; } - v3s16 npos = p0 + dirs[i]; + v3s16 npos = p0 + liquid_6dirs[i]; NodeNeighbor nb(getNode(npos), nt, npos); const ContentFeatures &cfnb = m_nodedef->get(nb.n); switch (m_nodedef->get(nb.n.getContent()).liquid_type) { @@ -646,14 +655,18 @@ void Map::transformLiquids(std::map &modified_blocks, neutrals[num_neutrals++] = nb; } else { // Do not count bottom source, it will screw things up - if(dirs[i].Y != -1) + if(nt != NEIGHBOR_LOWER) sources[num_sources++] = nb; } break; case LIQUID_FLOWING: - // if this node is not (yet) of a liquid type, choose the first liquid type we encounter - if (liquid_kind == CONTENT_AIR) - liquid_kind = cfnb.liquid_alternative_flowing_id; + if (nb.t != NEIGHBOR_SAME_LEVEL || + (nb.n.param2 & LIQUID_FLOW_DOWN_MASK) != LIQUID_FLOW_DOWN_MASK) { + // if this node is not (yet) of a liquid type, choose the first liquid type we encounter + // but exclude falling liquids on the same level, they cannot flow here anyway + if (liquid_kind == CONTENT_AIR) + liquid_kind = cfnb.liquid_alternative_flowing_id; + } if (cfnb.liquid_alternative_flowing_id != liquid_kind) { neutrals[num_neutrals++] = nb; } else { -- cgit v1.2.3 From 471e567657dfd75a994a1b54d7a23cf4541a6bed Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 26 May 2020 17:38:31 +0200 Subject: Value copy / allocation optimizations mostly in server, SAO and serialize code --- src/client/game.cpp | 2 +- src/client/sky.cpp | 4 ++-- src/client/sky.h | 2 +- src/content/mods.cpp | 2 +- src/content/mods.h | 2 +- src/script/cpp_api/s_node.cpp | 2 +- src/script/cpp_api/s_node.h | 2 +- src/server.cpp | 43 ++++++++++++++++++--------------------- src/server/luaentity_sao.cpp | 15 +++++--------- src/server/player_sao.cpp | 7 ++----- src/server/serveractiveobject.cpp | 2 +- src/server/serverinventorymgr.h | 2 +- src/serverenvironment.cpp | 8 ++++---- src/serverenvironment.h | 4 ++-- src/tool.cpp | 2 +- src/util/serialize.cpp | 17 ++++++++-------- 16 files changed, 52 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index e7663a113..cdf4da21e 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2806,7 +2806,7 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) // Shows the mesh skybox sky->setVisible(true); // Update mesh based skybox colours if applicable. - sky->setSkyColors(*event->set_sky); + sky->setSkyColors(event->set_sky->sky_color); sky->setHorizonTint( event->set_sky->fog_sun_tint, event->set_sky->fog_moon_tint, diff --git a/src/client/sky.cpp b/src/client/sky.cpp index d21b56fcc..2e0cbca86 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -907,9 +907,9 @@ void Sky::setStarCount(u16 star_count, bool force_update) } } -void Sky::setSkyColors(const SkyboxParams sky) +void Sky::setSkyColors(const SkyColor &sky_color) { - m_sky_params.sky_color = sky.sky_color; + m_sky_params.sky_color = sky_color; } void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint, diff --git a/src/client/sky.h b/src/client/sky.h index 8637f96d4..3227e8f59 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -94,7 +94,7 @@ public: m_bgcolor = bgcolor; m_skycolor = skycolor; } - void setSkyColors(const SkyboxParams sky); + void setSkyColors(const SkyColor &sky_color); void setHorizonTint(video::SColor sun_tint, video::SColor moon_tint, std::string use_sun_tint); void setInClouds(bool clouds) { m_in_clouds = clouds; } diff --git a/src/content/mods.cpp b/src/content/mods.cpp index 676666f78..95ab0290a 100644 --- a/src/content/mods.cpp +++ b/src/content/mods.cpp @@ -167,7 +167,7 @@ std::map getModsInPath( return result; } -std::vector flattenMods(std::map mods) +std::vector flattenMods(const std::map &mods) { std::vector result; for (const auto &it : mods) { diff --git a/src/content/mods.h b/src/content/mods.h index 6e2506dbf..b3500fbc8 100644 --- a/src/content/mods.h +++ b/src/content/mods.h @@ -68,7 +68,7 @@ std::map getModsInPath( const std::string &path, bool part_of_modpack = false); // replaces modpack Modspecs with their content -std::vector flattenMods(std::map mods); +std::vector flattenMods(const std::map &mods); // a ModConfiguration is a subset of installed mods, expected to have // all dependencies fullfilled, so it can be used as a list of mods to diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index d93a4c3ad..e0f9bcd78 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -94,7 +94,7 @@ struct EnumString ScriptApiNode::es_NodeBoxType[] = }; bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, - ServerActiveObject *puncher, PointedThing pointed) + ServerActiveObject *puncher, const PointedThing &pointed) { SCRIPTAPI_PRECHECKHEADER diff --git a/src/script/cpp_api/s_node.h b/src/script/cpp_api/s_node.h index e7c0c01d1..81b44f0f0 100644 --- a/src/script/cpp_api/s_node.h +++ b/src/script/cpp_api/s_node.h @@ -36,7 +36,7 @@ public: virtual ~ScriptApiNode() = default; bool node_on_punch(v3s16 p, MapNode node, - ServerActiveObject *puncher, PointedThing pointed); + ServerActiveObject *puncher, const PointedThing &pointed); bool node_on_dig(v3s16 p, MapNode node, ServerActiveObject *digger); void node_on_construct(v3s16 p, MapNode node); diff --git a/src/server.cpp b/src/server.cpp index 8c62584c8..6ecbd7097 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -718,34 +718,35 @@ void Server::AsyncRunStep(bool initial_step) std::unordered_map*> buffered_messages; // Get active object messages from environment + ActiveObjectMessage aom(0); + u32 aom_count = 0; for(;;) { - ActiveObjectMessage aom = m_env->getActiveObjectMessage(); - if (aom.id == 0) + if (!m_env->getActiveObjectMessage(&aom)) break; std::vector* message_list = nullptr; - std::unordered_map* >::iterator n; - n = buffered_messages.find(aom.id); + auto n = buffered_messages.find(aom.id); if (n == buffered_messages.end()) { message_list = new std::vector; buffered_messages[aom.id] = message_list; - } - else { + } else { message_list = n->second; } - message_list->push_back(aom); + message_list->push_back(std::move(aom)); + aom_count++; } - m_aom_buffer_counter->increment(buffered_messages.size()); + m_aom_buffer_counter->increment(aom_count); m_clients.lock(); const RemoteClientMap &clients = m_clients.getClientList(); // Route data to every client + std::string reliable_data, unreliable_data; for (const auto &client_it : clients) { + reliable_data.clear(); + unreliable_data.clear(); RemoteClient *client = client_it.second; PlayerSAO *player = getPlayerSAO(client->peer_id); - std::string reliable_data; - std::string unreliable_data; // Go through all objects in message buffer for (const auto &buffered_message : buffered_messages) { // If object does not exist or is not known by client, skip it @@ -770,19 +771,15 @@ void Server::AsyncRunStep(bool initial_step) client->m_known_objects.end()) continue; } - // Compose the full new data with header - std::string new_data; - // Add object id - char buf[2]; - writeU16((u8*)&buf[0], aom.id); - new_data.append(buf, 2); - // Add data - new_data += serializeString(aom.datastring); - // Add data to buffer - if (aom.reliable) - reliable_data += new_data; - else - unreliable_data += new_data; + + // Add full new data to appropriate buffer + std::string &buffer = aom.reliable ? reliable_data : unreliable_data; + char idbuf[2]; + writeU16((u8*) idbuf, aom.id); + // u16 id + // std::string data + buffer.append(idbuf, sizeof(idbuf)); + buffer.append(serializeString(aom.datastring)); } } /* diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index 51e1ca90e..8174da265 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -119,8 +119,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) m_properties_sent = true; std::string str = getPropertyPacket(); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } // If attached, check that our parent is still there. If it isn't, detach. @@ -228,16 +227,14 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) m_animation_sent = true; std::string str = generateUpdateAnimationCommand(); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } if (!m_animation_speed_sent) { m_animation_speed_sent = true; std::string str = generateUpdateAnimationSpeedCommand(); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } if (!m_bone_position_sent) { @@ -247,8 +244,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) std::string str = generateUpdateBonePositionCommand((*ii).first, (*ii).second.X, (*ii).second.Y); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } } @@ -256,8 +252,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) m_attachment_sent = true; std::string str = generateUpdateAttachmentCommand(); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); } } diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index a4d0f4ce7..3ea3536e2 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -223,8 +223,7 @@ void PlayerSAO::step(float dtime, bool send_recommended) m_properties_sent = true; std::string str = getPropertyPacket(); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, str); m_env->getScriptIface()->player_event(this, "properties_changed"); } @@ -324,10 +323,8 @@ void PlayerSAO::step(float dtime, bool send_recommended) if (!m_attachment_sent) { m_attachment_sent = true; - std::string str = generateUpdateAttachmentCommand(); // create message and add to list - ActiveObjectMessage aom(getId(), true, str); - m_messages_out.push(aom); + m_messages_out.emplace(getId(), true, generateUpdateAttachmentCommand()); } } diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp index 8345ebd47..fdcb13bd8 100644 --- a/src/server/serveractiveobject.cpp +++ b/src/server/serveractiveobject.cpp @@ -75,7 +75,7 @@ std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const vid void ServerActiveObject::dumpAOMessagesToQueue(std::queue &queue) { while (!m_messages_out.empty()) { - queue.push(m_messages_out.front()); + queue.push(std::move(m_messages_out.front())); m_messages_out.pop(); } } \ No newline at end of file diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h index d0aac4dae..ccf6d3b2e 100644 --- a/src/server/serverinventorymgr.h +++ b/src/server/serverinventorymgr.h @@ -57,4 +57,4 @@ private: ServerEnvironment *m_env = nullptr; std::unordered_map m_detached_inventories; -}; \ No newline at end of file +}; diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index d485c32e8..222b4d203 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1603,14 +1603,14 @@ void ServerEnvironment::setStaticForActiveObjectsInBlock( } } -ActiveObjectMessage ServerEnvironment::getActiveObjectMessage() +bool ServerEnvironment::getActiveObjectMessage(ActiveObjectMessage *dest) { if(m_active_object_messages.empty()) - return ActiveObjectMessage(0); + return false; - ActiveObjectMessage message = m_active_object_messages.front(); + *dest = std::move(m_active_object_messages.front()); m_active_object_messages.pop(); - return message; + return true; } void ServerEnvironment::getSelectedActiveObjects( diff --git a/src/serverenvironment.h b/src/serverenvironment.h index e2f1a3784..4b453d39a 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -289,9 +289,9 @@ public: /* Get the next message emitted by some active object. - Returns a message with id=0 if no messages are available. + Returns false if no messages are available, true otherwise. */ - ActiveObjectMessage getActiveObjectMessage(); + bool getActiveObjectMessage(ActiveObjectMessage *dest); virtual void getSelectedActiveObjects( const core::line3d &shootline_on_map, diff --git a/src/tool.cpp b/src/tool.cpp index d911c518f..22e41d28e 100644 --- a/src/tool.cpp +++ b/src/tool.cpp @@ -130,7 +130,7 @@ void ToolCapabilities::serializeJson(std::ostream &os) const root["punch_attack_uses"] = punch_attack_uses; Json::Value groupcaps_object; - for (auto groupcap : groupcaps) { + for (const auto &groupcap : groupcaps) { groupcap.second.toJson(groupcaps_object[groupcap.first]); } root["groupcaps"] = groupcaps_object; diff --git a/src/util/serialize.cpp b/src/util/serialize.cpp index f0e177d57..5b276668d 100644 --- a/src/util/serialize.cpp +++ b/src/util/serialize.cpp @@ -110,6 +110,7 @@ std::string serializeString(const std::string &plain) if (plain.size() > STRING_MAX_LEN) throw SerializationError("String too long for serializeString"); + s.reserve(2 + plain.size()); writeU16((u8 *)&buf[0], plain.size()); s.append(buf, 2); @@ -131,13 +132,11 @@ std::string deSerializeString(std::istream &is) if (s_size == 0) return s; - Buffer buf2(s_size); - is.read(&buf2[0], s_size); + s.resize(s_size); + is.read(&s[0], s_size); if (is.gcount() != s_size) throw SerializationError("deSerializeString: couldn't read all chars"); - s.reserve(s_size); - s.append(&buf2[0], s_size); return s; } @@ -152,6 +151,7 @@ std::string serializeWideString(const std::wstring &plain) if (plain.size() > WIDE_STRING_MAX_LEN) throw SerializationError("String too long for serializeWideString"); + s.reserve(2 + 2 * plain.size()); writeU16((u8 *)buf, plain.size()); s.append(buf, 2); @@ -196,13 +196,14 @@ std::wstring deSerializeWideString(std::istream &is) std::string serializeLongString(const std::string &plain) { + std::string s; char buf[4]; if (plain.size() > LONG_STRING_MAX_LEN) throw SerializationError("String too long for serializeLongString"); + s.reserve(4 + plain.size()); writeU32((u8*)&buf[0], plain.size()); - std::string s; s.append(buf, 4); s.append(plain); return s; @@ -227,13 +228,11 @@ std::string deSerializeLongString(std::istream &is) "string too long: " + itos(s_size) + " bytes"); } - Buffer buf2(s_size); - is.read(&buf2[0], s_size); + s.resize(s_size); + is.read(&s[0], s_size); if ((u32)is.gcount() != s_size) throw SerializationError("deSerializeLongString: couldn't read all chars"); - s.reserve(s_size); - s.append(&buf2[0], s_size); return s; } -- cgit v1.2.3 From 34862a644256f2717923de6d35288114a84acd19 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Wed, 11 Dec 2019 20:03:12 +0100 Subject: Add disable_jump check for the player's feet --- doc/lua_api.txt | 1 + games/devtest/mods/testnodes/properties.lua | 11 +++++++++-- src/client/localplayer.cpp | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index bb9df5373..8c81b7020 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1666,6 +1666,7 @@ to games. * `2`: the node always gets the digging time 0.5 seconds (rail, sign) * `3`: the node always gets the digging time 0 seconds (torch) * `disable_jump`: Player (and possibly other things) cannot jump from node + or if their feet are in the node. Note: not supported for `new_move = false` * `fall_damage_add_percent`: damage speed = `speed * (1 + value/100)` * `falling_node`: if there is no walkable block under the node it will fall * `float`: the node will not fall through liquids diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua index e169d4b08..01846a5f0 100644 --- a/games/devtest/mods/testnodes/properties.lua +++ b/games/devtest/mods/testnodes/properties.lua @@ -56,11 +56,18 @@ minetest.register_node("testnodes:attached_wallmounted", { minetest.register_node("testnodes:nojump", { description = S("Non-jumping Node"), groups = {disable_jump=1, dig_immediate=3}, - - tiles = {"testnodes_nojump_top.png", "testnodes_nojump_side.png"}, }) +-- Jump disabled plant +minetest.register_node("testnodes:nojump_walkable", { + description = S("Non-jumping Plant Node"), + drawtype = "plantlike", + groups = {disable_jump=1, dig_immediate=3}, + walkable = false, + tiles = {"testnodes_nojump_top.png"}, +}) + -- Climbable up and down with jump and sneak keys minetest.register_node("testnodes:climbable", { description = S("Climbable Node"), diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index c20c3619f..011898bcf 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -436,9 +436,11 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, Check properties of the node on which the player is standing */ const ContentFeatures &f = nodemgr->get(map->getNode(m_standing_node)); + const ContentFeatures &f1 = nodemgr->get(map->getNode(m_standing_node + v3s16(0, 1, 0))); // Determine if jumping is possible - m_disable_jump = itemgroup_get(f.groups, "disable_jump"); + m_disable_jump = itemgroup_get(f.groups, "disable_jump") || + itemgroup_get(f1.groups, "disable_jump"); m_can_jump = ((touching_ground && !is_climbing) || sneak_can_jump) && !m_disable_jump; // Jump key pressed while jumping off from a bouncy block -- cgit v1.2.3 From db7c262ee85c5bcae68354280848218dbf14bf55 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 25 May 2020 23:36:45 +0200 Subject: content_cao: Do not expire visuals when not necessary fixes #6572 --- src/client/content_cao.cpp | 42 ++++++++++++++++++++++++++++++++---------- src/client/content_cao.h | 3 ++- 2 files changed, 34 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index cdc12f041..947c1a279 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1457,13 +1457,23 @@ void GenericCAO::updateAttachments() } } -void GenericCAO::readAOMessageProperties(std::istream &is) +bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const { - // Reset object properties first - m_prop = ObjectProperties(); - - // Then read the whole new stream - m_prop.deSerialize(is); + const ObjectProperties &old = m_prop; + // Ordered to compare primitive types before std::vectors + return old.backface_culling != new_.backface_culling || + old.initial_sprite_basepos != new_.initial_sprite_basepos || + old.is_visible != new_.is_visible || + old.mesh != new_.mesh || + old.nametag != new_.nametag || + old.nametag_color != new_.nametag_color || + old.spritediv != new_.spritediv || + old.use_texture_alpha != new_.use_texture_alpha || + old.visual != new_.visual || + old.visual_size != new_.visual_size || + old.wield_item != new_.wield_item || + old.colors != new_.colors || + old.textures != new_.textures; } void GenericCAO::processMessage(const std::string &data) @@ -1473,14 +1483,21 @@ void GenericCAO::processMessage(const std::string &data) // command u8 cmd = readU8(is); if (cmd == AO_CMD_SET_PROPERTIES) { - readAOMessageProperties(is); + ObjectProperties newprops; + newprops.deSerialize(is); + + // Check what exactly changed + bool expire_visuals = visualExpiryRequired(newprops); + + // Apply changes + m_prop = std::move(newprops); m_selection_box = m_prop.selectionbox; m_selection_box.MinEdge *= BS; m_selection_box.MaxEdge *= BS; - m_tx_size.X = 1.0 / m_prop.spritediv.X; - m_tx_size.Y = 1.0 / m_prop.spritediv.Y; + m_tx_size.X = 1.0f / m_prop.spritediv.X; + m_tx_size.Y = 1.0f / m_prop.spritediv.Y; if(!m_initial_tx_basepos_set){ m_initial_tx_basepos_set = true; @@ -1500,7 +1517,12 @@ void GenericCAO::processMessage(const std::string &data) if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty()) m_prop.nametag = m_name; - expireVisuals(); + if (expire_visuals) { + expireVisuals(); + } else { + infostream << "GenericCAO: properties updated but expiring visuals" + << " not necessary" << std::endl; + } } else if (cmd == AO_CMD_UPDATE_POSITION) { // Not sent by the server if this object is an attachment. // We might however get here if the server notices the object being detached before the client. diff --git a/src/client/content_cao.h b/src/client/content_cao.h index c53b81433..03a355204 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -68,7 +68,6 @@ struct SmoothTranslatorWrappedv3f : SmoothTranslator class GenericCAO : public ClientActiveObject { private: - void readAOMessageProperties(std::istream &is); // Only set at initialization std::string m_name = ""; bool m_is_player = false; @@ -131,6 +130,8 @@ private: // Settings bool m_enable_shaders = false; + bool visualExpiryRequired(const ObjectProperties &newprops) const; + public: GenericCAO(Client *client, ClientEnvironment *env); -- cgit v1.2.3 From 4c8e1c320054ee0dc5d8ec821a6b4cd69002aa09 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 26 May 2020 16:05:06 +0200 Subject: Clean up CAO nametag handling and remove deprecated AO_CMD AO_CMD_UPDATE_NAMETAG_ATTRIBUTES was deprecated in 9eee3c3f465c071bb9908749cf48be3c131a1bdf (0.4.14) --- src/activeobject.h | 3 ++- src/client/content_cao.cpp | 57 ++++++++++++++++++++++++--------------- src/client/content_cao.h | 2 ++ src/server/player_sao.cpp | 4 +-- src/server/serveractiveobject.cpp | 13 +-------- 5 files changed, 42 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/activeobject.h b/src/activeobject.h index c83243f86..85e160d10 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -66,7 +66,8 @@ enum ActiveObjectCommand { AO_CMD_SET_BONE_POSITION, AO_CMD_ATTACH_TO, AO_CMD_SET_PHYSICS_OVERRIDE, - AO_CMD_UPDATE_NAMETAG_ATTRIBUTES, + AO_CMD_OBSOLETE1, + // ^ UPDATE_NAMETAG_ATTRIBUTES deprecated since 0.4.14, removed in 5.3.0 AO_CMD_SPAWN_INFANT, AO_CMD_SET_ANIMATION_SPEED }; diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 947c1a279..dde31899b 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -776,15 +776,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc) if (node && m_matrixnode) node->setParent(m_matrixnode); - if (node && !m_prop.nametag.empty() && !m_is_local_player) { - // Add nametag - v3f pos; - pos.Y = m_prop.selectionbox.MaxEdge.Y + 0.3f; - m_nametag = m_client->getCamera()->addNametag(node, - m_prop.nametag, m_prop.nametag_color, - pos); - } - + updateNametag(); updateNodePos(); updateAnimation(); updateBonePosition(); @@ -872,6 +864,38 @@ v3s16 GenericCAO::getLightPosition() return floatToInt(m_position, BS); } +void GenericCAO::updateNametag() +{ + if (m_is_local_player) // No nametag for local player + return; + + if (m_prop.nametag.empty()) { + // Delete nametag + if (m_nametag) { + m_client->getCamera()->removeNametag(m_nametag); + m_nametag = nullptr; + } + return; + } + + scene::ISceneNode *node = getSceneNode(); + if (!node) + return; + + v3f pos; + pos.Y = m_prop.selectionbox.MaxEdge.Y + 0.3f; + if (!m_nametag) { + // Add nametag + m_nametag = m_client->getCamera()->addNametag(node, + m_prop.nametag, m_prop.nametag_color, pos); + } else { + // Update nametag + m_nametag->nametag_text = m_prop.nametag; + m_nametag->nametag_color = m_prop.nametag_color; + m_nametag->nametag_pos = pos; + } +} + void GenericCAO::updateNodePos() { if (getParent() != NULL) @@ -1465,8 +1489,6 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const old.initial_sprite_basepos != new_.initial_sprite_basepos || old.is_visible != new_.is_visible || old.mesh != new_.mesh || - old.nametag != new_.nametag || - old.nametag_color != new_.nametag_color || old.spritediv != new_.spritediv || old.use_texture_alpha != new_.use_texture_alpha || old.visual != new_.visual || @@ -1516,6 +1538,7 @@ void GenericCAO::processMessage(const std::string &data) if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty()) m_prop.nametag = m_name; + updateNametag(); if (expire_visuals) { expireVisuals(); @@ -1694,22 +1717,14 @@ void GenericCAO::processMessage(const std::string &data) int rating = readS16(is); m_armor_groups[name] = rating; } - } else if (cmd == AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) { - // Deprecated, for backwards compatibility only. - readU8(is); // version - m_prop.nametag_color = readARGB8(is); - if (m_nametag != NULL) { - m_nametag->nametag_color = m_prop.nametag_color; - v3f pos; - pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f; - m_nametag->nametag_pos = pos; - } } else if (cmd == AO_CMD_SPAWN_INFANT) { u16 child_id = readU16(is); u8 type = readU8(is); // maybe this will be useful later (void)type; addAttachmentChild(child_id); + } else if (cmd == AO_CMD_OBSOLETE1) { + // Don't do anything and also don't log a warning } else { warningstream << FUNCTION_NAME << ": unknown command or outdated client \"" diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 03a355204..8e2a13ea8 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -244,6 +244,8 @@ public: v3s16 getLightPosition(); + void updateNametag(); + void updateNodePos(); void step(float dtime, ClientEnvironment *env); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 3ea3536e2..9ea0743f7 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -127,9 +127,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) } msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5 - // (AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only. - msg_os << serializeLongString(generateUpdateNametagAttributesCommand(m_prop.nametag_color)); // 6 - int message_count = 6 + m_bone_position.size(); + int message_count = 5 + m_bone_position.size(); for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); ii != m_attachment_child_ids.end(); ++ii) { if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp index fdcb13bd8..dbf25e3bc 100644 --- a/src/server/serveractiveobject.cpp +++ b/src/server/serveractiveobject.cpp @@ -61,21 +61,10 @@ std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 p return os.str(); } -std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const video::SColor &color) const -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, AO_CMD_UPDATE_NAMETAG_ATTRIBUTES); - // parameters - writeU8(os, 1); // version for forward compatibility - writeARGB8(os, color); - return os.str(); -} - void ServerActiveObject::dumpAOMessagesToQueue(std::queue &queue) { while (!m_messages_out.empty()) { queue.push(std::move(m_messages_out.front())); m_messages_out.pop(); } -} \ No newline at end of file +} -- cgit v1.2.3 From f849917bbe9c5eff51bee0a3125eabed16efb172 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Mon, 1 Jun 2020 09:22:04 -0400 Subject: imageScaleNNAA: Fix image clipping on rect- instead of image dimensions (#9896) Fixes GUI scaling filters applied on animated images and 9slice backgrounds. --- src/client/imagefilters.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/client/imagefilters.cpp b/src/client/imagefilters.cpp index dd029628f..0fa501410 100644 --- a/src/client/imagefilters.cpp +++ b/src/client/imagefilters.cpp @@ -91,7 +91,7 @@ void imageScaleNNAA(video::IImage *src, const core::rect &srcrect, video::I u32 dy, dx; video::SColor pxl; - // Cache rectsngle boundaries. + // Cache rectangle boundaries. double sox = srcrect.UpperLeftCorner.X * 1.0; double soy = srcrect.UpperLeftCorner.Y * 1.0; double sw = srcrect.getWidth() * 1.0; @@ -107,15 +107,15 @@ void imageScaleNNAA(video::IImage *src, const core::rect &srcrect, video::I // Do some basic clipping, and for mirrored/flipped rects, // make sure min/max are in the right order. minsx = sox + (dx * sw / dim.Width); - minsx = rangelim(minsx, 0, sw); + minsx = rangelim(minsx, 0, sox + sw); maxsx = minsx + sw / dim.Width; - maxsx = rangelim(maxsx, 0, sw); + maxsx = rangelim(maxsx, 0, sox + sw); if (minsx > maxsx) SWAP(double, minsx, maxsx); minsy = soy + (dy * sh / dim.Height); - minsy = rangelim(minsy, 0, sh); + minsy = rangelim(minsy, 0, soy + sh); maxsy = minsy + sh / dim.Height; - maxsy = rangelim(maxsy, 0, sh); + maxsy = rangelim(maxsy, 0, soy + sh); if (minsy > maxsy) SWAP(double, minsy, maxsy); -- cgit v1.2.3 From a08d18acad345363780f5286300d65b39ea9c9f9 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 1 Jun 2020 19:01:47 +0200 Subject: ContentCAO: Update light of all attached entities (#9975) --- src/client/clientenvironment.cpp | 30 +++------------------------- src/client/clientobject.h | 6 +++--- src/client/content_cao.cpp | 42 ++++++++++++++-------------------------- src/client/content_cao.h | 4 +--- 4 files changed, 22 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 6840f2db3..44ea1e4a1 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -320,21 +320,8 @@ void ClientEnvironment::step(float dtime) // Step object cao->step(dtime, this); - if (update_lighting) { - // Update lighting - u8 light = 0; - bool pos_ok; - - // Get node at head - v3s16 p = cao->getLightPosition(); - MapNode n = this->m_map->getNode(p, &pos_ok); - if (pos_ok) - light = n.getLightBlend(day_night_ratio, m_client->ndef()); - else - light = blend_light(day_night_ratio, LIGHT_SUN, 0); - - cao->updateLight(light); - } + if (update_lighting) + cao->updateLight(day_night_ratio); }; m_ao_manager.step(dtime, cb_state); @@ -402,18 +389,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) object->addToScene(m_texturesource); // Update lighting immediately - u8 light = 0; - bool pos_ok; - - // Get node at head - v3s16 p = object->getLightPosition(); - MapNode n = m_map->getNode(p, &pos_ok); - if (pos_ok) - light = n.getLightBlend(getDayNightRatio(), m_client->ndef()); - else - light = blend_light(getDayNightRatio(), LIGHT_SUN, 0); - - object->updateLight(light); + object->updateLight(getDayNightRatio()); return object->getId(); } diff --git a/src/client/clientobject.h b/src/client/clientobject.h index 12e0db35b..8e64b8406 100644 --- a/src/client/clientobject.h +++ b/src/client/clientobject.h @@ -41,10 +41,10 @@ public: virtual void addToScene(ITextureSource *tsrc) {} virtual void removeFromScene(bool permanent) {} - // 0 <= light_at_pos <= LIGHT_SUN - virtual void updateLight(u8 light_at_pos) {} - virtual void updateLightNoCheck(u8 light_at_pos) {} + + virtual void updateLight(u32 day_night_ratio) {} virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); } + virtual bool getCollisionBox(aabb3f *toset) const { return false; } virtual bool getSelectionBox(aabb3f *toset) const { return false; } virtual bool collideWithObjects() const { return false; } diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index dde31899b..d0682e51e 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -181,7 +181,7 @@ public: void addToScene(ITextureSource *tsrc); void removeFromScene(bool permanent); - void updateLight(u8 light_at_pos); + void updateLight(u32 day_night_ratio); v3s16 getLightPosition(); void updateNodePos(); @@ -254,7 +254,7 @@ void TestCAO::removeFromScene(bool permanent) m_node = NULL; } -void TestCAO::updateLight(u8 light_at_pos) +void TestCAO::updateLight(u32 day_night_ratio) { } @@ -784,34 +784,22 @@ void GenericCAO::addToScene(ITextureSource *tsrc) setNodeLight(m_last_light); } -void GenericCAO::updateLight(u8 light_at_pos) +void GenericCAO::updateLight(u32 day_night_ratio) { - // Don't update light of attached one - if (getParent() != NULL) { - return; - } - - updateLightNoCheck(light_at_pos); - - // Update light of all children - for (u16 i : m_attachment_child_ids) { - ClientActiveObject *obj = m_env->getActiveObject(i); - if (obj) { - obj->updateLightNoCheck(light_at_pos); - } - } -} - -void GenericCAO::updateLightNoCheck(u8 light_at_pos) -{ - if (m_glow < 0) - return; + u8 light_at_pos = 0; + bool pos_ok; - u8 li = decode_light(light_at_pos + m_glow); + v3s16 p = getLightPosition(); + MapNode n = m_env->getMap().getNode(p, &pos_ok); + if (pos_ok) + light_at_pos = n.getLightBlend(day_night_ratio, m_client->ndef()); + else + light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0); - if (li != m_last_light) { - m_last_light = li; - setNodeLight(li); + u8 light = decode_light(light_at_pos); + if (light != m_last_light) { + m_last_light = light; + setNodeLight(light); } } diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 8e2a13ea8..7693dd3d2 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -236,9 +236,7 @@ public: m_visuals_expired = true; } - void updateLight(u8 light_at_pos); - - void updateLightNoCheck(u8 light_at_pos); + void updateLight(u32 day_night_ratio); void setNodeLight(u8 light); -- cgit v1.2.3 From 42a9b45c21ad407689950e3a4c90cb3894142260 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 1 Jun 2020 19:02:15 +0200 Subject: Lua API: Log incorrect parameter types as error (#9954) Incorrect parameter types are logged as errors, taking coercion into account. This is a workaround to ensure mod compatibility. Duplicate warnings are ignored per server instance. --- src/script/common/c_converter.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 279d8b1a5..de0cdfbf4 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -28,6 +28,7 @@ extern "C" { #include "common/c_converter.h" #include "common/c_internal.h" #include "constants.h" +#include #define CHECK_TYPE(index, name, type) { \ @@ -458,11 +459,36 @@ size_t read_stringlist(lua_State *L, int index, std::vector *result bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname) { - if (lua_isnil(L, index)) + static thread_local std::set warned_msgs; + + int t = lua_type(L, index); + if (t == LUA_TNIL) return false; - CHECK_TYPE(index, std::string("field \"") + fieldname + '"', type); - return true; + if (t == type) + return true; + + // Check coercion types + if (type == LUA_TNUMBER) { + if (lua_isnumber(L, index)) + return true; + } else if (type == LUA_TSTRING) { + if (lua_isstring(L, index)) + return true; + } + + // Types mismatch. Log unique line. + std::string backtrace = std::string("Invalid field ") + fieldname + + " (expected " + lua_typename(L, type) + + " got " + lua_typename(L, t) + ").\n" + script_get_backtrace(L); + + u64 hash = murmur_hash_64_ua(backtrace.data(), backtrace.length(), 0xBADBABE); + if (warned_msgs.find(hash) == warned_msgs.end()) { + errorstream << backtrace << std::endl; + warned_msgs.insert(hash); + } + + return false; } bool getstringfield(lua_State *L, int table, -- cgit v1.2.3 From 0e698e63b3bc27551fda9bd4e66f72501413b4e6 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 1 Jun 2020 21:19:35 +0200 Subject: Fix autoscale_mode segfault if tile doesn't have texture closes #9965 --- src/nodedef.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nodedef.cpp b/src/nodedef.cpp index cb841e544..a84338752 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -608,8 +608,9 @@ static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer, layer->material_type = material_type; bool has_scale = tiledef.scale > 0; - if (((tsettings.autoscale_mode == AUTOSCALE_ENABLE) && !has_scale) || - (tsettings.autoscale_mode == AUTOSCALE_FORCE)) { + bool use_autoscale = tsettings.autoscale_mode == AUTOSCALE_FORCE || + (tsettings.autoscale_mode == AUTOSCALE_ENABLE && !has_scale); + if (use_autoscale && layer->texture) { auto texture_size = layer->texture->getOriginalSize(); float base_size = tsettings.node_texture_size; float size = std::fmin(texture_size.Width, texture_size.Height); -- cgit v1.2.3 From c1e01bc638637efa788b5698238a465406bc3f5e Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 4 Jun 2020 19:31:46 +0200 Subject: Move shared parameters sending to UnitSAO (#9968) Better header sorting by topic Make UnitSAO-specific parameters private Skip redundant recursive entity sending code (since ~5.2.0) --- src/client/content_cao.cpp | 1 + src/server/luaentity_sao.cpp | 71 ++++++++++----------------------------- src/server/player_sao.cpp | 57 +++++++++---------------------- src/server/serveractiveobject.cpp | 7 +++- src/server/unit_sao.cpp | 33 ++++++++++++++++++ src/server/unit_sao.h | 56 +++++++++++++++++++----------- 6 files changed, 110 insertions(+), 115 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index d0682e51e..702d089af 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -475,6 +475,7 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f posit parent->addAttachmentChild(m_id); } + updateAttachments(); } diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index 8174da265..d504c42ca 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -123,12 +123,11 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) } // If attached, check that our parent is still there. If it isn't, detach. - if(m_attachment_parent_id && !isAttached()) - { - m_attachment_parent_id = 0; - m_attachment_bone = ""; - m_attachment_position = v3f(0,0,0); - m_attachment_rotation = v3f(0,0,0); + if (m_attachment_parent_id && !isAttached()) { + // This is handled when objects are removed from the map + warningstream << "LuaEntitySAO::step() id=" << m_id << + " is attached to nonexistent parent. This is a bug." << std::endl; + clearParentAttachment(); sendPosition(false, true); } @@ -217,43 +216,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) } } - if (!m_armor_groups_sent) { - m_armor_groups_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); - } - - if (!m_animation_sent) { - m_animation_sent = true; - std::string str = generateUpdateAnimationCommand(); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } - - if (!m_animation_speed_sent) { - m_animation_speed_sent = true; - std::string str = generateUpdateAnimationSpeedCommand(); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } - - if (!m_bone_position_sent) { - m_bone_position_sent = true; - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - std::string str = generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } - } - - if (!m_attachment_sent) { - m_attachment_sent = true; - std::string str = generateUpdateAttachmentCommand(); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } + sendOutdatedData(); } std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) @@ -273,20 +236,19 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) msg_os << serializeLongString(getPropertyPacket()); // message 1 msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + for (const auto &bone_pos : m_bone_position) { + msg_os << serializeLongString(generateUpdateBonePositionCommand( + bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // m_bone_position.size } msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 + int message_count = 4 + m_bone_position.size(); - for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); - (ii != m_attachment_child_ids.end()); ++ii) { - if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { + + for (const auto &id : getAttachmentChildIds()) { + if (ServerActiveObject *obj = m_env->getActiveObject(id)) { message_count++; - // TODO after a protocol bump: only send the object initialization data - // to older clients (superfluous since this message exists) - msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); + msg_os << serializeLongString(obj->generateUpdateInfantCommand( + id, protocol_version)); } } @@ -294,7 +256,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) message_count++; writeU8(os, message_count); - os.write(msg_os.str().c_str(), msg_os.str().size()); + std::string serialized = msg_os.str(); + os.write(serialized.c_str(), serialized.size()); // return result return os.str(); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 9ea0743f7..67efed210 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -120,24 +120,26 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) msg_os << serializeLongString(getPropertyPacket()); // message 1 msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + for (const auto &bone_pos : m_bone_position) { + msg_os << serializeLongString(generateUpdateBonePositionCommand( + bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // m_bone_position.size } msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5 + int message_count = 5 + m_bone_position.size(); - for (std::unordered_set::const_iterator ii = m_attachment_child_ids.begin(); - ii != m_attachment_child_ids.end(); ++ii) { - if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) { + + for (const auto &id : getAttachmentChildIds()) { + if (ServerActiveObject *obj = m_env->getActiveObject(id)) { message_count++; - msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); + msg_os << serializeLongString(obj->generateUpdateInfantCommand( + id, protocol_version)); } } writeU8(os, message_count); - os.write(msg_os.str().c_str(), msg_os.str().size()); + std::string serialized = msg_os.str(); + os.write(serialized.c_str(), serialized.size()); // return result return os.str(); @@ -227,10 +229,10 @@ void PlayerSAO::step(float dtime, bool send_recommended) // If attached, check that our parent is still there. If it isn't, detach. if (m_attachment_parent_id && !isAttached()) { - m_attachment_parent_id = 0; - m_attachment_bone = ""; - m_attachment_position = v3f(0.0f, 0.0f, 0.0f); - m_attachment_rotation = v3f(0.0f, 0.0f, 0.0f); + // This is handled when objects are removed from the map + warningstream << "PlayerSAO::step() id=" << m_id << + " is attached to nonexistent parent. This is a bug." << std::endl; + clearParentAttachment(); setBasePosition(m_last_good_position); m_env->getGameDef()->SendMovePlayer(m_peer_id); } @@ -290,40 +292,13 @@ void PlayerSAO::step(float dtime, bool send_recommended) m_messages_out.emplace(getId(), false, str); } - if (!m_armor_groups_sent) { - m_armor_groups_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); - } - if (!m_physics_override_sent) { m_physics_override_sent = true; // create message and add to list m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand()); } - if (!m_animation_sent) { - m_animation_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand()); - } - - if (!m_bone_position_sent) { - m_bone_position_sent = true; - for (std::unordered_map>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - std::string str = generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } - } - - if (!m_attachment_sent) { - m_attachment_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateAttachmentCommand()); - } + sendOutdatedData(); } std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const diff --git a/src/server/serveractiveobject.cpp b/src/server/serveractiveobject.cpp index dbf25e3bc..3341dc008 100644 --- a/src/server/serveractiveobject.cpp +++ b/src/server/serveractiveobject.cpp @@ -57,7 +57,12 @@ std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 p // parameters writeU16(os, infant_id); writeU8(os, getSendType()); - os << serializeLongString(getClientInitializationData(protocol_version)); + if (protocol_version < 38) { + // Clients since 4aa9a66 so no longer need this data + // Version 38 is the first bump after that commit. + // See also: ClientEnvironment::addActiveObject + os << serializeLongString(getClientInitializationData(protocol_version)); + } return os.str(); } diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index 74b0508b8..ef0e87f2c 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -88,6 +88,39 @@ void UnitSAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotat *rotation = m_bone_position[bone].Y; } +// clang-format off +void UnitSAO::sendOutdatedData() +{ + if (!m_armor_groups_sent) { + m_armor_groups_sent = true; + m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); + } + + if (!m_animation_sent) { + m_animation_sent = true; + m_animation_speed_sent = true; + m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand()); + } else if (!m_animation_speed_sent) { + // Animation speed is also sent when 'm_animation_sent == false' + m_animation_speed_sent = true; + m_messages_out.emplace(getId(), true, generateUpdateAnimationSpeedCommand()); + } + + if (!m_bone_position_sent) { + m_bone_position_sent = true; + for (const auto &bone_pos : m_bone_position) { + m_messages_out.emplace(getId(), true, generateUpdateBonePositionCommand( + bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); + } + } + + if (!m_attachment_sent) { + m_attachment_sent = true; + m_messages_out.emplace(getId(), true, generateUpdateAttachmentCommand()); + } +} +// clang-format on + void UnitSAO::setAttachment( int parent_id, const std::string &bone, v3f position, v3f rotation) { diff --git a/src/server/unit_sao.h b/src/server/unit_sao.h index c73115855..3cb7f0ad5 100644 --- a/src/server/unit_sao.h +++ b/src/server/unit_sao.h @@ -29,6 +29,11 @@ public: UnitSAO(ServerEnvironment *env, v3f pos); virtual ~UnitSAO() = default; + u16 getHP() const { return m_hp; } + // Use a function, if isDead can be defined by other conditions + bool isDead() const { return m_hp == 0; } + + // Rotation void setRotation(v3f rotation) { m_rotation = rotation; } const v3f &getRotation() const { return m_rotation; } v3f getRadRotation() { return m_rotation * core::DEGTORAD; } @@ -36,26 +41,28 @@ public: // Deprecated f32 getRadYawDep() const { return (m_rotation.Y + 90.) * core::DEGTORAD; } - u16 getHP() const { return m_hp; } - // Use a function, if isDead can be defined by other conditions - bool isDead() const { return m_hp == 0; } - - inline bool isAttached() const { return getParent(); } - + // Armor groups inline bool isImmortal() const { return itemgroup_get(getArmorGroups(), "immortal"); } - void setArmorGroups(const ItemGroupList &armor_groups); const ItemGroupList &getArmorGroups() const; + + // Animation void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop); void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop); void setAnimationSpeed(float frame_speed); + + // Bone position void setBonePosition(const std::string &bone, v3f position, v3f rotation); void getBonePosition(const std::string &bone, v3f *position, v3f *rotation); + + // Attachments + ServerActiveObject *getParent() const; + inline bool isAttached() const { return getParent(); } void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation); void getAttachment(int *parent_id, std::string *bone, v3f *position, @@ -65,10 +72,13 @@ public: void addAttachmentChild(int child_id); void removeAttachmentChild(int child_id); const std::unordered_set &getAttachmentChildIds() const; - ServerActiveObject *getParent() const; + + // Object properties ObjectProperties *accessObjectProperties(); void notifyObjectPropertiesModified(); + void sendOutdatedData(); + // Update packets std::string generateUpdateAttachmentCommand() const; std::string generateUpdateAnimationSpeedCommand() const; std::string generateUpdateAnimationCommand() const; @@ -77,21 +87,36 @@ public: const v3f &velocity, const v3f &acceleration, const v3f &rotation, bool do_interpolate, bool is_movement_end, f32 update_interval); std::string generateSetPropertiesCommand(const ObjectProperties &prop) const; - void sendPunchCommand(); static std::string generateUpdateBonePositionCommand(const std::string &bone, const v3f &position, const v3f &rotation); + void sendPunchCommand(); protected: u16 m_hp = 1; v3f m_rotation; + ItemGroupList m_armor_groups; + + // Object properties bool m_properties_sent = true; ObjectProperties m_prop; - ItemGroupList m_armor_groups; + // Stores position and rotation for each bone name + std::unordered_map> m_bone_position; + + int m_attachment_parent_id = 0; + +private: + void onAttach(int parent_id); + void onDetach(int parent_id); + + std::string generatePunchCommand(u16 result_hp) const; + + // Armor groups bool m_armor_groups_sent = false; + // Animation v2f m_animation_range; float m_animation_speed = 0.0f; float m_animation_blend = 0.0f; @@ -99,20 +124,13 @@ protected: bool m_animation_sent = false; bool m_animation_speed_sent = false; - // Stores position and rotation for each bone name - std::unordered_map> m_bone_position; + // Bone positions bool m_bone_position_sent = false; - int m_attachment_parent_id = 0; + // Attachments std::unordered_set m_attachment_child_ids; std::string m_attachment_bone = ""; v3f m_attachment_position; v3f m_attachment_rotation; bool m_attachment_sent = false; - -private: - void onAttach(int parent_id); - void onDetach(int parent_id); - - std::string generatePunchCommand(u16 result_hp) const; }; -- cgit v1.2.3 From 08c0b7696a8b15759c8fc203cc90fde21c2c76a9 Mon Sep 17 00:00:00 2001 From: ANAND Date: Fri, 5 Jun 2020 23:34:14 +0530 Subject: TestBan: Clean up properly after completing test (#9994) --- src/unittest/test_ban.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/unittest/test_ban.cpp b/src/unittest/test_ban.cpp index 2a95b945f..bab2b9ee8 100644 --- a/src/unittest/test_ban.cpp +++ b/src/unittest/test_ban.cpp @@ -61,6 +61,9 @@ void TestBan::runTests(IGameDef *gamedef) reinitTestEnv(); TEST(testGetBanDescription); + + // Delete leftover files + reinitTestEnv(); } // This module is stateful due to disk writes, add helper to remove files -- cgit v1.2.3 From 7ec0e3df35a11b66b48eababf0123170f2453a50 Mon Sep 17 00:00:00 2001 From: Maksim Date: Fri, 5 Jun 2020 21:42:33 +0200 Subject: Fix HUD scaling (#9721) This resolves HUD scaling issues on Android and desktops with custom DPI settings. --- src/client/hud.cpp | 65 ++++++++++++++++++++++++++++++++++++------------------ src/client/hud.h | 1 + 2 files changed, 44 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 4edc229b2..31e633bc2 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -51,6 +51,7 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player, this->inventory = inventory; m_hud_scaling = g_settings->getFloat("hud_scaling"); + m_scale_factor = m_hud_scaling * RenderingEngine::getDisplayDensity(); m_hotbar_imagesize = std::floor(HOTBAR_IMAGE_SIZE * RenderingEngine::getDisplayDensity() + 0.5f); m_hotbar_imagesize *= m_hud_scaling; @@ -213,9 +214,7 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount, } // Position of upper left corner of bar - v2s32 pos = screen_offset; - pos.X *= m_hud_scaling * RenderingEngine::getDisplayDensity(); - pos.Y *= m_hud_scaling * RenderingEngine::getDisplayDensity(); + v2s32 pos = screen_offset * m_scale_factor; pos += upperleftpos; // Store hotbar_image in member variable, used by drawItem() @@ -320,20 +319,40 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) switch (e->type) { case HUD_ELEM_TEXT: { irr::gui::IGUIFont *textfont = font; + unsigned int font_size = g_fontengine->getDefaultFontSize(); + if (e->size.X > 0) - textfont = g_fontengine->getFont( - e->size.X * g_fontengine->getDefaultFontSize()); + font_size *= e->size.X; + + if (font_size != g_fontengine->getDefaultFontSize()) + textfont = g_fontengine->getFont(font_size); video::SColor color(255, (e->number >> 16) & 0xFF, (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); - core::rect size(0, 0, e->scale.X, text_height * e->scale.Y); std::wstring text = unescape_translate(utf8_to_wide(e->text)); core::dimension2d textsize = textfont->getDimension(text.c_str()); +#ifdef __ANDROID__ + // The text size on Android is not proportional with the actual scaling + irr::gui::IGUIFont *font_scaled = font_size <= 3 ? + textfont : g_fontengine->getFont(font_size - 3); + if (e->offset.X < -20) + textsize = font_scaled->getDimension(text.c_str()); +#endif v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2), (e->align.Y - 1.0) * (textsize.Height / 2)); - v2s32 offs(e->offset.X, e->offset.Y); - textfont->draw(text.c_str(), size + pos + offset + offs, color); + core::rect size(0, 0, e->scale.X * m_scale_factor, + text_height * e->scale.Y * m_scale_factor); + v2s32 offs(e->offset.X * m_scale_factor, + e->offset.Y * m_scale_factor); +#ifdef __ANDROID__ + if (e->offset.X < -20) + font_scaled->draw(text.c_str(), size + pos + offset + offs, color); + else +#endif + { + textfont->draw(text.c_str(), size + pos + offset + offs, color); + } break; } case HUD_ELEM_STATBAR: { v2s32 offs(e->offset.X, e->offset.Y); @@ -385,8 +404,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; core::dimension2di imgsize(texture->getOriginalSize()); - v2s32 dstsize(imgsize.Width * e->scale.X, - imgsize.Height * e->scale.Y); + v2s32 dstsize(imgsize.Width * e->scale.X * m_scale_factor, + imgsize.Height * e->scale.Y * m_scale_factor); if (e->scale.X < 0) dstsize.X = m_screensize.X * (e->scale.X * -0.01); if (e->scale.Y < 0) @@ -394,7 +413,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) v2s32 offset((e->align.X - 1.0) * dstsize.X / 2, (e->align.Y - 1.0) * dstsize.Y / 2); core::rect rect(0, 0, dstsize.X, dstsize.Y); - rect += pos + offset + v2s32(e->offset.X, e->offset.Y); + rect += pos + offset + v2s32(e->offset.X * m_scale_factor, + e->offset.Y * m_scale_factor); draw2DImageFilterScaled(driver, texture, rect, core::rect(core::position2d(0,0), imgsize), NULL, colors, true); @@ -427,12 +447,15 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, core::dimension2di dstd; if (size == v2s32()) { dstd = srcd; + dstd.Height *= m_scale_factor; + dstd.Width *= m_scale_factor; + offset.X *= m_scale_factor; + offset.Y *= m_scale_factor; } else { - float size_factor = m_hud_scaling * RenderingEngine::getDisplayDensity(); - dstd.Height = size.Y * size_factor; - dstd.Width = size.X * size_factor; - offset.X *= size_factor; - offset.Y *= size_factor; + dstd.Height = size.Y * m_scale_factor; + dstd.Width = size.X * m_scale_factor; + offset.X *= m_scale_factor; + offset.Y *= m_scale_factor; } v2s32 p = pos; @@ -555,7 +578,7 @@ void Hud::drawHotbar(u16 playeritem) { v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3); const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); - if ( (float) width / (float) window_size.X <= + if ((float) width / (float) window_size.X <= g_settings->getFloat("hud_hotbar_max_width")) { if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) { drawItems(pos, v2s32(0, 0), hotbar_itemcount, 0, mainlist, playeritem + 1, 0); @@ -607,12 +630,10 @@ void Hud::drawSelectionMesh() // Draw 3D selection boxes video::SMaterial oldmaterial = driver->getMaterial2D(); driver->setMaterial(m_selection_material); - for (std::vector::const_iterator - i = m_selection_boxes.begin(); - i != m_selection_boxes.end(); ++i) { + for (auto & selection_box : m_selection_boxes) { aabb3f box = aabb3f( - i->MinEdge + m_selection_pos_with_offset, - i->MaxEdge + m_selection_pos_with_offset); + selection_box.MinEdge + m_selection_pos_with_offset, + selection_box.MaxEdge + m_selection_pos_with_offset); u32 r = (selectionbox_argb.getRed() * m_selection_mesh_color.getRed() / 255); diff --git a/src/client/hud.h b/src/client/hud.h index e2abf326c..6f4c54626 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -92,6 +92,7 @@ private: void drawItem(const ItemStack &item, const core::rect &rect, bool selected); float m_hud_scaling; // cached minetest setting + float m_scale_factor; v3s16 m_camera_offset; v2u32 m_screensize; v2s32 m_displaycenter; -- cgit v1.2.3 From 60bab8b2d7b61383188c10f5d931dc7b5522d042 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 6 Jun 2020 17:17:08 +0100 Subject: Add HTTP API to main menu (#9998) --- builtin/fstk/dialog.lua | 19 +++ builtin/fstk/ui.lua | 2 +- builtin/init.lua | 1 + builtin/mainmenu/dlg_contentstore.lua | 49 +++--- doc/fst_api.txt | 7 +- doc/menu_lua_api.txt | 273 +++++++++++++++++++++++----------- src/script/lua_api/l_http.cpp | 44 +++++- src/script/lua_api/l_http.h | 6 + src/script/scripting_mainmenu.cpp | 2 + 9 files changed, 290 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/builtin/fstk/dialog.lua b/builtin/fstk/dialog.lua index df887f413..ea57df1d2 100644 --- a/builtin/fstk/dialog.lua +++ b/builtin/fstk/dialog.lua @@ -67,3 +67,22 @@ function dialog_create(name,get_formspec,buttonhandler,eventhandler) ui.add(self) return self end + +function messagebox(name, message) + return dialog_create(name, + function() + return ([[ + formspec_version[3] + size[8,3] + textarea[0.375,0.375;7.25,1.2;;;%s] + button[3,1.825;2,0.8;ok;%s] + ]]):format(message, fgettext("OK")) + end, + function(this, fields) + if fields.ok then + this:delete() + return true + end + end, + nil) +end diff --git a/builtin/fstk/ui.lua b/builtin/fstk/ui.lua index 884100543..6d26aabf0 100644 --- a/builtin/fstk/ui.lua +++ b/builtin/fstk/ui.lua @@ -85,7 +85,7 @@ function ui.update() "box[0.5,1.2;13,5;#000]", ("textarea[0.5,1.2;13,5;;%s;%s]"):format( error_title, error_message), - "button[5,6.6;4,1;btn_error_confirm;" .. fgettext("Ok") .. "]" + "button[5,6.6;4,1;btn_error_confirm;" .. fgettext("OK") .. "]" } else local active_toplevel_ui_elements = 0 diff --git a/builtin/init.lua b/builtin/init.lua index f76174be7..75bb3db85 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -36,6 +36,7 @@ dofile(commonpath .. "misc_helpers.lua") if INIT == "game" then dofile(gamepath .. "init.lua") + assert(not core.get_http_api) elseif INIT == "mainmenu" then local mm_script = core.settings:get("main_menu_script") if mm_script and mm_script ~= "" then diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 8ac4dba68..ae119f48f 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -1,5 +1,5 @@ --Minetest ---Copyright (C) 2018 rubenwardy +--Copyright (C) 2018-20 rubenwardy -- --This program is free software; you can redistribute it and/or modify --it under the terms of the GNU Lesser General Public License as published by @@ -15,8 +15,18 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +if not minetest.get_http_api then + function create_store_dlg() + return messagebox("store", + fgettext("ContentDB is not available when Minetest was compiled without cURL")) + end + return +end + local store = { packages = {}, packages_full = {} } +local http = minetest.get_http_api() + -- Screenshot local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb" assert(core.create_dir(screenshot_dir)) @@ -171,11 +181,6 @@ local function get_screenshot(package) end function store.load() - local tmpdir = os.tempfolder() - local target = tmpdir .. DIR_DELIM .. "packages.json" - - assert(core.create_dir(tmpdir)) - local version = core.get_version() local base_url = core.settings:get("contentdb_url") local url = base_url .. @@ -189,31 +194,29 @@ function store.load() end end - core.download_file(url, target) + local timeout = tonumber(minetest.settings:get("curl_file_download_timeout")) + local response = http.fetch_sync({ url = url, timeout = timeout }) + if not response.succeeded then + return + end - local file = io.open(target, "r") - if file then - store.packages_full = core.parse_json(file:read("*all")) or {} - file:close() + store.packages_full = core.parse_json(response.data) or {} - for _, package in pairs(store.packages_full) do - package.url = base_url .. "/packages/" .. + for _, package in pairs(store.packages_full) do + package.url = base_url .. "/packages/" .. package.author .. "/" .. package.name .. "/releases/" .. package.release .. "/download/" - local name_len = #package.name - if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then - package.id = package.author:lower() .. "/" .. package.name:sub(1, name_len - 5) - else - package.id = package.author:lower() .. "/" .. package.name - end + local name_len = #package.name + if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then + package.id = package.author:lower() .. "/" .. package.name:sub(1, name_len - 5) + else + package.id = package.author:lower() .. "/" .. package.name end - - store.packages = store.packages_full - store.loaded = true end - core.delete_dir(tmpdir) + store.packages = store.packages_full + store.loaded = true end function store.update_paths() diff --git a/doc/fst_api.txt b/doc/fst_api.txt index c8bcb1e91..6f9aa14b3 100644 --- a/doc/fst_api.txt +++ b/doc/fst_api.txt @@ -101,6 +101,9 @@ dialog_create(name, cbf_formspec, cbf_button_handler, cbf_events) ^ cbf_events: function to handle events function(dialog, event) +messagebox(name, message) +^ creates a message dialog + Class reference dialog: methods: @@ -113,13 +116,13 @@ methods: ^ hide dialog - delete() ^ delete dialog from ui - + members: - data ^ variable data attached to this dialog - parent ^ parent component to return to on exit - + File: fst/buttonbar.lua ----------------------- diff --git a/doc/menu_lua_api.txt b/doc/menu_lua_api.txt index 485c50110..4eccf5d10 100644 --- a/doc/menu_lua_api.txt +++ b/doc/menu_lua_api.txt @@ -3,34 +3,53 @@ Minetest Lua Mainmenu API Reference 5.3.0 Introduction ------------- + The main menu is defined as a formspec by Lua in builtin/mainmenu/ Description of formspec language to show your menu is in lua_api.txt + Callbacks --------- + core.buttonhandler(fields): called when a button is pressed. ^ fields = {name1 = value1, name2 = value2, ...} core.event_handler(event) ^ event: "MenuQuit", "KeyEnter", "ExitButton" or "EditBoxEnter" + Gamedata -------- + The "gamedata" table is read when calling core.start(). It should contain: { - playername = , - password = , - address = , - port = , - selected_world = , -- 0 for client mode - singleplayer = , + playername = , + password = , + address = , + port = , + selected_world = , -- 0 for client mode + singleplayer = , } + Functions --------- + core.start() core.close() +core.get_min_supp_proto() +^ returns the minimum supported network protocol version +core.get_max_supp_proto() +^ returns the maximum supported network protocol version +core.open_url(url) +^ opens the URL in a web browser, returns false on failure. +^ Must begin with http:// or https:// +core.get_version() (possible in async calls) +^ returns current core version + + +Filesystem +---------- -Filesystem: core.get_builtin_path() ^ returns path to builtin root core.create_dir(absolute_path) (possible in async calls) @@ -48,12 +67,6 @@ core.extract_zip(zipfile,destination) [unzip within path required] ^ zipfile to extract ^ destination folder to extract to ^ returns true/false -core.download_file(url,target) (possible in async calls) -^ url to download -^ target to store to -^ returns true/false -core.get_version() (possible in async calls) -^ returns current core version core.sound_play(spec, looped) -> handle ^ spec = SimpleSoundSpec (see lua-api.txt) ^ looped = bool @@ -67,7 +80,82 @@ core.get_mapgen_names([include_hidden=false]) -> table of map generator algorith registered in the core (possible in async calls) core.get_cache_path() -> path of cache -Formspec: + +HTTP Requests +------------- + +* core.download_file(url, target) (possible in async calls) + * url to download, and target to store to + * returns true/false +* `minetest.get_http_api()` (possible in async calls) + * returns `HTTPApiTable` containing http functions. + * The returned table contains the functions `fetch_sync`, `fetch_async` and + `fetch_async_get` described below. + * Function only exists if minetest server was built with cURL support. +* `HTTPApiTable.fetch_sync(HTTPRequest req)`: returns HTTPRequestResult + * Performs given request synchronously +* `HTTPApiTable.fetch_async(HTTPRequest req)`: returns handle + * Performs given request asynchronously and returns handle for + `HTTPApiTable.fetch_async_get` +* `HTTPApiTable.fetch_async_get(handle)`: returns HTTPRequestResult + * Return response data for given asynchronous HTTP request + +### `HTTPRequest` definition + +Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`. + + { + url = "http://example.org", + + timeout = 10, + -- Timeout for connection in seconds. Default is 3 seconds. + + post_data = "Raw POST request data string" OR {field1 = "data1", field2 = "data2"}, + -- Optional, if specified a POST request with post_data is performed. + -- Accepts both a string and a table. If a table is specified, encodes + -- table as x-www-form-urlencoded key-value pairs. + -- If post_data is not specified, a GET request is performed instead. + + user_agent = "ExampleUserAgent", + -- Optional, if specified replaces the default minetest user agent with + -- given string + + extra_headers = { "Accept-Language: en-us", "Accept-Charset: utf-8" }, + -- Optional, if specified adds additional headers to the HTTP request. + -- You must make sure that the header strings follow HTTP specification + -- ("Key: Value"). + + multipart = boolean + -- Optional, if true performs a multipart HTTP request. + -- Default is false. + } + +### `HTTPRequestResult` definition + +Passed to `HTTPApiTable.fetch` callback. Returned by +`HTTPApiTable.fetch_async_get`. + + { + completed = true, + -- If true, the request has finished (either succeeded, failed or timed + -- out) + + succeeded = true, + -- If true, the request was successful + + timeout = false, + -- If true, the request timed out + + code = 200, + -- HTTP status code + + data = "response" + } + + +Formspec +-------- + core.update_formspec(formspec) core.get_table_index(tablename) -> index ^ can also handle textlists @@ -82,7 +170,10 @@ core.explode_textlist_event(string) -> table core.set_formspec_prepend(formspec) ^ string to be added to every mainmenu formspec, to be used for theming. -GUI: + +GUI +--- + core.set_background(type, texturepath,[tile],[minsize]) ^ type: "background", "overlay", "header" or "footer" ^ tile: tile the image instead of scaling (background only) @@ -102,86 +193,96 @@ core.show_path_select_dialog(formname, caption, is_file_select) ^ returns nil or selected file/folder core.get_screen_info() ^ returns { - density = , - display_width = , - display_height = , - window_width = , - window_height = - } + density = , + display_width = , + display_height = , + window_width = , + window_height = + } -### Content and Packages + +Content and Packages +-------------------- Content - an installed mod, modpack, game, or texture pack (txt) Package - content which is downloadable from the content db, may or may not be installed. * core.get_modpath() (possible in async calls) - * returns path to global modpath + * returns path to global modpath * core.get_clientmodpath() (possible in async calls) - * returns path to global client-side modpath + * returns path to global client-side modpath * core.get_gamepath() (possible in async calls) - * returns path to global gamepath + * returns path to global gamepath * core.get_texturepath() (possible in async calls) - * returns path to default textures + * returns path to default textures * core.get_game(index) - * returns: - - { - id = , - path = , - gamemods_path = , - name = , - menuicon_path = , - author = "author", - DEPRECATED: - addon_mods_paths = {[1] = ,}, - } + * returns: + + { + id = , + path = , + gamemods_path = , + name = , + menuicon_path = , + author = "author", + DEPRECATED: + addon_mods_paths = {[1] = ,}, + } * core.get_games() -> table of all games in upper format (possible in async calls) * core.get_content_info(path) - * returns + * returns - { - name = "name of content", - type = "mod" or "modpack" or "game" or "txp", - description = "description", - author = "author", - path = "path/to/content", - depends = {"mod", "names"}, -- mods only - optional_depends = {"mod", "names"}, -- mods only - } + { + name = "name of content", + type = "mod" or "modpack" or "game" or "txp", + description = "description", + author = "author", + path = "path/to/content", + depends = {"mod", "names"}, -- mods only + optional_depends = {"mod", "names"}, -- mods only + } -Favorites: +Favorites +--------- + core.get_favorites(location) -> list of favorites (possible in async calls) ^ location: "local" or "online" ^ returns { - [1] = { - clients = , - clients_max = , - version = , - password = , - creative = , - damage = , - pvp = , - description = , - name = , - address =
, - port = - clients_list = - mods = - }, - ... + [1] = { + clients = , + clients_max = , + version = , + password = , + creative = , + damage = , + pvp = , + description = , + name = , + address =
, + port = + clients_list = + mods = + }, + ... } core.delete_favorite(id, location) -> success -Logging: + +Logging +------- + core.debug(line) (possible in async calls) ^ Always printed to stderr and logfile (print() is redirected here) core.log(line) (possible in async calls) core.log(loglevel, line) (possible in async calls) ^ loglevel one of "error", "action", "info", "verbose" -Settings: + +Settings +-------- + core.settings:set(name, value) core.settings:get(name) -> string or nil (possible in async calls) core.settings:set_bool(name, value) @@ -191,19 +292,25 @@ core.settings:save() -> nil, save all settings to config file For a complete list of methods of the Settings object see [lua_api.txt](https://github.com/minetest/minetest/blob/master/doc/lua_api.txt) -Worlds: + +Worlds +------ + core.get_worlds() -> list of worlds (possible in async calls) ^ returns { - [1] = { - path = , - name = , - gameid = , - }, + [1] = { + path = , + name = , + gameid = , + }, } core.create_world(worldname, gameid) core.delete_world(index) -Helpers: + +Helpers +------- + core.get_us_time() ^ returns time with microsecond precision core.gettext(string) -> string @@ -228,18 +335,10 @@ minetest.encode_base64(string) (possible in async calls) minetest.decode_base64(string) (possible in async calls) ^ Decodes a string encoded in base64. -Version compat: -core.get_min_supp_proto() -^ returns the minimum supported network protocol version -core.get_max_supp_proto() -^ returns the maximum supported network protocol version -Other: -core.open_url(url) -^ opens the URL in a web browser, returns false on failure. -^ Must begin with http:// or https:// +Async +----- -Async: core.handle_async(async_job,parameters,finished) ^ execute a function asynchronously ^ async_job is a function receiving one parameter and returning one parameter @@ -250,11 +349,13 @@ core.handle_async(async_job,parameters,finished) Limitations of Async operations -No access to global lua variables, don't even try -Limited set of available functions - e.g. No access to functions modifying menu like core.start,core.close, - core.show_path_select_dialog + e.g. No access to functions modifying menu like core.start,core.close, + core.show_path_select_dialog + Background music ---------------- + The main menu supports background music. It looks for a `main_menu` sound in `$USER_PATH/sounds`. The same naming conventions as for normal sounds apply. diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp index 2ff651cb5..73b4586e0 100644 --- a/src/script/lua_api/l_http.cpp +++ b/src/script/lua_api/l_http.cpp @@ -83,6 +83,24 @@ void ModApiHttp::push_http_fetch_result(lua_State *L, HTTPFetchResult &res, bool setstringfield(L, -1, "data", res.data); } +// http_api.fetch_sync(HTTPRequest definition) +int ModApiHttp::l_http_fetch_sync(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + HTTPFetchRequest req; + read_http_fetch_request(L, req); + + infostream << "Mod performs HTTP request with URL " << req.url << std::endl; + + HTTPFetchResult res; + httpfetch_sync(req, res); + + push_http_fetch_result(L, res, true); + + return 1; +} + // http_api.fetch_async(HTTPRequest definition) int ModApiHttp::l_http_fetch_async(lua_State *L) { @@ -180,11 +198,35 @@ int ModApiHttp::l_request_http_api(lua_State *L) return 1; } + +int ModApiHttp::l_get_http_api(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + lua_newtable(L); + HTTP_API(fetch_async); + HTTP_API(fetch_async_get); + HTTP_API(fetch_sync); + + return 1; +} + #endif void ModApiHttp::Initialize(lua_State *L, int top) { #if USE_CURL - API_FCT(request_http_api); + + bool isMainmenu = false; +#ifndef SERVER + isMainmenu = ModApiBase::getGuiEngine(L) != nullptr; +#endif + + if (isMainmenu) { + API_FCT(get_http_api); + } else { + API_FCT(request_http_api); + } + #endif } diff --git a/src/script/lua_api/l_http.h b/src/script/lua_api/l_http.h index 3d9cdad29..c665235a9 100644 --- a/src/script/lua_api/l_http.h +++ b/src/script/lua_api/l_http.h @@ -32,6 +32,9 @@ private: static void read_http_fetch_request(lua_State *L, HTTPFetchRequest &req); static void push_http_fetch_result(lua_State *L, HTTPFetchResult &res, bool completed = true); + // http_fetch_sync({url=, timeout=, post_data=}) + static int l_http_fetch_sync(lua_State *L); + // http_fetch_async({url=, timeout=, post_data=}) static int l_http_fetch_async(lua_State *L); @@ -40,6 +43,9 @@ private: // request_http_api() static int l_request_http_api(lua_State *L); + + // get_http_api() + static int l_get_http_api(lua_State *L); #endif public: diff --git a/src/script/scripting_mainmenu.cpp b/src/script/scripting_mainmenu.cpp index b6068439a..08858b1a5 100644 --- a/src/script/scripting_mainmenu.cpp +++ b/src/script/scripting_mainmenu.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content/mods.h" #include "cpp_api/s_internal.h" #include "lua_api/l_base.h" +#include "lua_api/l_http.h" #include "lua_api/l_mainmenu.h" #include "lua_api/l_sound.h" #include "lua_api/l_util.h" @@ -67,6 +68,7 @@ void MainMenuScripting::initializeModApi(lua_State *L, int top) ModApiMainMenu::Initialize(L, top); ModApiUtil::Initialize(L, top); ModApiSound::Initialize(L, top); + ModApiHttp::Initialize(L, top); asyncEngine.registerStateInitializer(registerLuaClasses); asyncEngine.registerStateInitializer(ModApiMainMenu::InitializeAsync); -- cgit v1.2.3 From e746607d0f8531e3a8b12cc45294aecf36217b17 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 6 Jun 2020 23:25:18 +0300 Subject: Restore visual_scale support for nodeboxes (and allfaces) (#9906) --- doc/lua_api.txt | 2 +- src/client/content_mapblock.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 8c81b7020..898531880 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6941,7 +6941,7 @@ Used by `minetest.register_node`. visual_scale = 1.0, -- Supported for drawtypes "plantlike", "signlike", "torchlike", - -- "firelike", "mesh". + -- "firelike", "mesh", "nodebox", "allfaces". -- For plantlike and firelike, the image will start at the bottom of the -- node. For torchlike, the image will start at the surface to which the -- node "attaches". For the other drawtypes the image will be centered diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index 50efd2e40..f7d20001f 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -366,6 +366,7 @@ void MapblockMeshGenerator::generateCuboidTextureCoords(const aabb3f &box, f32 * void MapblockMeshGenerator::drawAutoLightedCuboid(aabb3f box, const f32 *txc, TileSpec *tiles, int tile_count) { + bool scale = std::fabs(f->visual_scale - 1.0f) > 1e-3f; f32 texture_coord_buf[24]; f32 dx1 = box.MinEdge.X; f32 dy1 = box.MinEdge.Y; @@ -373,6 +374,14 @@ void MapblockMeshGenerator::drawAutoLightedCuboid(aabb3f box, const f32 *txc, f32 dx2 = box.MaxEdge.X; f32 dy2 = box.MaxEdge.Y; f32 dz2 = box.MaxEdge.Z; + if (scale) { + if (!txc) { // generate texture coords before scaling + generateCuboidTextureCoords(box, texture_coord_buf); + txc = texture_coord_buf; + } + box.MinEdge *= f->visual_scale; + box.MaxEdge *= f->visual_scale; + } box.MinEdge += origin; box.MaxEdge += origin; if (!txc) { @@ -1323,7 +1332,7 @@ void MapblockMeshGenerator::drawNodeboxNode() std::vector boxes; n.getNodeBoxes(nodedef, &boxes, neighbors_set); - for (const auto &box : boxes) + for (auto &box : boxes) drawAutoLightedCuboid(box, nullptr, tiles, 6); } -- cgit v1.2.3 From 8fc9e7eb117849202b87bf3d764cd3eac6f68c74 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 7 Jun 2020 14:17:32 +0200 Subject: GenericCAO: Fix glow not working since a08d18a --- src/client/content_cao.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 702d089af..855729642 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -787,6 +787,9 @@ void GenericCAO::addToScene(ITextureSource *tsrc) void GenericCAO::updateLight(u32 day_night_ratio) { + if (m_glow < 0) + return; + u8 light_at_pos = 0; bool pos_ok; @@ -797,7 +800,7 @@ void GenericCAO::updateLight(u32 day_night_ratio) else light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0); - u8 light = decode_light(light_at_pos); + u8 light = decode_light(light_at_pos + m_glow); if (light != m_last_light) { m_last_light = light; setNodeLight(light); -- cgit v1.2.3 From fe1f72ab0ac8bcc233c91eb5b2d71bd2d2574cf8 Mon Sep 17 00:00:00 2001 From: Danila Shutov Date: Sun, 7 Jun 2020 19:14:00 +0300 Subject: Recalculate mesh normals for CAOs (#10000) --- src/client/content_cao.cpp | 8 ++++++++ src/client/mesh.cpp | 20 ++++++++++++++++++++ src/client/mesh.h | 6 ++++++ 3 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 855729642..a6ce06d20 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -726,6 +726,14 @@ void GenericCAO::addToScene(ITextureSource *tsrc) addAnimatedMeshSceneNode(mesh, m_matrixnode); m_animated_meshnode->grab(); mesh->drop(); // The scene node took hold of it + + if (!checkMeshNormals(mesh)) { + infostream << "GenericCAO: recalculating normals for mesh " + << m_prop.mesh << std::endl; + m_smgr->getMeshManipulator()-> + recalculateNormals(mesh, true, false); + } + m_animated_meshnode->animateJoints(); // Needed for some animations m_animated_meshnode->setScale(m_prop.visual_size); diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index 4d73ead8a..91781373c 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -328,6 +328,26 @@ void recalculateBoundingBox(scene::IMesh *src_mesh) src_mesh->setBoundingBox(bbox); } +bool checkMeshNormals(scene::IMesh *mesh) +{ + u32 buffer_count = mesh->getMeshBufferCount(); + + for (u32 i = 0; i < buffer_count; i++) { + scene::IMeshBuffer *buffer = mesh->getMeshBuffer(i); + + // Here we intentionally check only first normal, assuming that if buffer + // has it valid, then most likely all other ones are fine too. We can + // check all of the normals to have length, but it seems like an overkill + // hurting the performance and covering only really weird broken models. + f32 length = buffer->getNormal(0).getLength(); + + if (!isfinite(length) || fabs(length) < 1e-10) + return false; + } + + return true; +} + scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer) { switch (mesh_buffer->getVertexType()) { diff --git a/src/client/mesh.h b/src/client/mesh.h index 0c4094de2..103c61e45 100644 --- a/src/client/mesh.h +++ b/src/client/mesh.h @@ -121,6 +121,12 @@ scene::IMesh* convertNodeboxesToMesh(const std::vector &boxes, */ void recalculateBoundingBox(scene::IMesh *src_mesh); +/* + Check if mesh has valid normals and return true if it does. + We assume normal to be valid when it's 0 < length < Inf. and not NaN + */ +bool checkMeshNormals(scene::IMesh *mesh); + /* Vertex cache optimization according to the Forsyth paper: http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html -- cgit v1.2.3 From 09f9e465e760cb8fd791222405a9e5e68a676ba0 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Sat, 6 Jun 2020 14:52:26 -0400 Subject: Fix Lua panic when error() message is not a string --- src/script/cpp_api/s_base.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index df07206d7..f965975a3 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -187,7 +187,9 @@ void ScriptApiBase::loadScript(const std::string &script_path) } ok = ok && !lua_pcall(L, 0, 0, error_handler); if (!ok) { - std::string error_msg = readParam(L, -1); + const char *error_msg = lua_tostring(L, -1); + if (!error_msg) + error_msg = "(error object is not a string)"; lua_pop(L, 2); // Pop error message and error handler throw ModError("Failed to load and run script from " + script_path + ":\n" + error_msg); @@ -219,7 +221,9 @@ void ScriptApiBase::loadModFromMemory(const std::string &mod_name) if (ok) ok = !lua_pcall(L, 0, 0, error_handler); if (!ok) { - std::string error_msg = luaL_checkstring(L, -1); + const char *error_msg = lua_tostring(L, -1); + if (!error_msg) + error_msg = "(error object is not a string)"; lua_pop(L, 2); // Pop error message and error handler throw ModError("Failed to load and run mod \"" + mod_name + "\":\n" + error_msg); -- cgit v1.2.3 From 0ab580810c6ccebfd57497b9565e3e396d250d70 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 7 Jun 2020 20:43:42 +0200 Subject: Reset touching_ground when in free_move This corrects local player animation after enabling fly while standing on ground. --- src/client/localplayer.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 011898bcf..1e7040d57 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -200,6 +200,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, if (noclip && free_move) { position += m_speed * dtime; setPosition(position); + + touching_ground = false; added_velocity = v3f(0.0f); // ignored return; } @@ -787,6 +789,8 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, if (free_move) { position += m_speed * dtime; setPosition(position); + + touching_ground = false; m_sneak_node_exists = false; added_velocity = v3f(0.0f); return; -- cgit v1.2.3 From 3cee55f2b4df39fcbf870c2467b51c3d82075874 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Thu, 16 Apr 2020 18:49:30 +0200 Subject: Hide tooltip after ETIE_LEFT_UP (for touch control) --- src/gui/guiFormSpecMenu.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 49133f1cb..0bb401251 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3560,6 +3560,10 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text, tooltip_offset_y = 0; if (m_pointer.X > (s32)screenSize.X / 2) tooltip_offset_x = -(tooltip_offset_x + tooltip_width); + + // Hide tooltip after ETIE_LEFT_UP + if (m_pointer.X == 0) + return; #endif // Calculate and set the tooltip position -- cgit v1.2.3 From 756dc89ede7daa640fe6391ee2c51e78864c0d5c Mon Sep 17 00:00:00 2001 From: Maksim Date: Sun, 31 May 2020 22:27:50 +0200 Subject: Fix real keyboard movements on touchscreen devices --- src/gui/touchscreengui.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 94e331f72..4df5979e1 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -1211,7 +1211,12 @@ void TouchScreenGUI::step(float dtime) } // joystick - applyJoystickStatus(); + for (unsigned int i = 0; i < 4; i++) { + if (m_joystick_status[i]) { + applyJoystickStatus(); + break; + } + } // if a new placed pointer isn't moved for some time start digging if ((m_move_id != -1) && -- cgit v1.2.3 From 0d8e5bf587ab497b3c84a6e0c6bf15c01ae03f0a Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Thu, 16 Apr 2020 18:49:07 +0200 Subject: TouchScreen Control: fix some bugs, cleanup --- src/gui/modalMenu.cpp | 59 +++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/gui/modalMenu.cpp b/src/gui/modalMenu.cpp index 8fb6c6f0f..a6fe7ebaf 100644 --- a/src/gui/modalMenu.cpp +++ b/src/gui/modalMenu.cpp @@ -28,8 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "touchscreengui.h" #endif -// clang-format off -GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, +GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr) : IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, core::rect(0, 0, 100, 100)), @@ -153,8 +152,8 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) if (((gui::IGUIEditBox *)hovered)->isPasswordBox()) type = 3; - porting::showInputDialog(gettext("ok"), "", - wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type); + porting::showInputDialog(gettext("OK"), "", + wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type); return retval; } } @@ -167,18 +166,17 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) if (!root) { errorstream << "GUIModalMenu::preprocessEvent" - << " unable to get root element" << std::endl; + << " unable to get root element" << std::endl; return false; } - gui::IGUIElement *hovered = root->getElementFromPoint( - core::position2d(event.TouchInput.X, event.TouchInput.Y)); + gui::IGUIElement *hovered = + root->getElementFromPoint(core::position2d( + event.TouchInput.X, event.TouchInput.Y)); translated.MouseInput.X = event.TouchInput.X; translated.MouseInput.Y = event.TouchInput.Y; translated.MouseInput.Control = false; - bool dont_send_event = false; - if (event.TouchInput.touchedCount == 1) { switch (event.TouchInput.Event) { case ETIE_PRESSED_DOWN: @@ -205,11 +203,7 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) m_down_pos = v2s32(0, 0); break; default: - dont_send_event = true; - // this is not supposed to happen - errorstream << "GUIModalMenu::preprocessEvent" - << " unexpected usecase Event=" - << event.TouchInput.Event << std::endl; + break; } } else if ((event.TouchInput.touchedCount == 2) && (event.TouchInput.Event == ETIE_PRESSED_DOWN)) { @@ -219,50 +213,37 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) translated.MouseInput.ButtonStates = EMBSM_LEFT | EMBSM_RIGHT; translated.MouseInput.X = m_pointer.X; translated.MouseInput.Y = m_pointer.Y; - if (hovered) { + if (hovered) hovered->OnEvent(translated); - } translated.MouseInput.Event = EMIE_RMOUSE_LEFT_UP; translated.MouseInput.ButtonStates = EMBSM_LEFT; - if (hovered) { + if (hovered) hovered->OnEvent(translated); - } - dont_send_event = true; - } - // ignore unhandled 2 touch events ... accidental moving for example - else if (event.TouchInput.touchedCount == 2) { - dont_send_event = true; - } - else if (event.TouchInput.touchedCount > 2) { - errorstream << "GUIModalMenu::preprocessEvent" - << " to many multitouch events " - << event.TouchInput.touchedCount << " ignoring them" - << std::endl; - } - if (dont_send_event) { + return true; + } else { + // ignore unhandled 2 touch events (accidental moving for example) return true; } // check if translated event needs to be preprocessed again - if (preprocessEvent(translated)) { + if (preprocessEvent(translated)) return true; - } + if (hovered) { grab(); bool retval = hovered->OnEvent(translated); - if (event.TouchInput.Event == ETIE_LEFT_UP) { + if (event.TouchInput.Event == ETIE_LEFT_UP) // reset pointer m_pointer = v2s32(0, 0); - } + drop(); return retval; } } - // clang-format on #endif return false; } @@ -271,14 +252,12 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event) bool GUIModalMenu::hasAndroidUIInput() { // no dialog shown - if (m_jni_field_name.empty()) { + if (m_jni_field_name.empty()) return false; - } // still waiting - if (porting::getInputDialogState() == -1) { + if (porting::getInputDialogState() == -1) return true; - } // no value abort dialog processing if (porting::getInputDialogState() != 0) { -- cgit v1.2.3 From b9f618746c0f673ea1f851bb2473fb3ca9410093 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Thu, 16 Apr 2020 17:37:40 +0200 Subject: TouchScreenGUI: fix some bugs, cleanup --- src/client/game.cpp | 4 + src/gui/touchscreengui.cpp | 414 +++++++++++++++++---------------------------- src/gui/touchscreengui.h | 55 +++--- 3 files changed, 183 insertions(+), 290 deletions(-) (limited to 'src') diff --git a/src/client/game.cpp b/src/client/game.cpp index cdf4da21e..139742cec 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1173,6 +1173,10 @@ void Game::shutdown() if (formspec) formspec->quitMenu(); +#ifdef HAVE_TOUCHSCREENGUI + g_touchscreengui->hide(); +#endif + showOverlayMessage(N_("Shutting down..."), 0, 0, false); if (clouds) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 4df5979e1..3ee9e4a64 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -34,19 +34,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include -// Very slow button repeat frequency (in seconds) -#define SLOW_BUTTON_REPEAT (1.0f) - using namespace irr::core; -const char **touchgui_button_imagenames = (const char *[]) { +const char **button_imagenames = (const char *[]) { "jump_btn.png", "down.png", "zoom.png", "aux_btn.png" }; -const char **touchgui_joystick_imagenames = (const char *[]) { +const char **joystick_imagenames = (const char *[]) { "joystick_off.png", "joystick_bg.png", "joystick_center.png" @@ -113,15 +110,17 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) case range_id: key = "rangeselect"; break; + default: + break; } - assert(key != ""); + assert(!key.empty()); return keyname_to_keycode(g_settings->get("keymap_" + key).c_str()); } TouchScreenGUI *g_touchscreengui; static void load_button_texture(button_info *btn, const char *path, - rect button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver) + const rect &button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver) { unsigned int tid; video::ITexture *texture = guiScalingImageButton(driver, @@ -141,7 +140,7 @@ static void load_button_texture(button_info *btn, const char *path, } btn->guibutton->setDrawBorder(false); btn->guibutton->setText(L""); - } + } } AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device, @@ -153,8 +152,8 @@ AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device, } void AutoHideButtonBar::init(ISimpleTextureSource *tsrc, - const char *starter_img, int button_id, v2s32 UpperLeft, - v2s32 LowerRight, autohide_button_bar_dir dir, float timeout) + const char *starter_img, int button_id, const v2s32 &UpperLeft, + const v2s32 &LowerRight, autohide_button_bar_dir dir, float timeout) { m_texturesource = tsrc; @@ -166,7 +165,7 @@ void AutoHideButtonBar::init(ISimpleTextureSource *tsrc, irr::core::rect current_button = rect(UpperLeft.X, UpperLeft.Y, LowerRight.X, LowerRight.Y); - m_starter.guibutton = m_guienv->addButton(current_button, 0, button_id, L"", 0); + m_starter.guibutton = m_guienv->addButton(current_button, nullptr, button_id, L"", nullptr); m_starter.guibutton->grab(); m_starter.repeatcounter = -1; m_starter.keycode = KEY_OEM_8; // use invalid keycode as it's not relevant @@ -201,16 +200,14 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id, } int button_size = 0; - if ((m_dir == AHBB_Dir_Top_Bottom) || (m_dir == AHBB_Dir_Bottom_Top)) { + if ((m_dir == AHBB_Dir_Top_Bottom) || (m_dir == AHBB_Dir_Bottom_Top)) button_size = m_lower_right.X - m_upper_left.X; - } else { + else button_size = m_lower_right.Y - m_upper_left.Y; - } irr::core::rect current_button; if ((m_dir == AHBB_Dir_Right_Left) || (m_dir == AHBB_Dir_Left_Right)) { - int x_start = 0; int x_end = 0; @@ -227,8 +224,8 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id, current_button = rect(x_start, m_upper_left.Y, x_end, m_lower_right.Y); } else { - int y_start = 0; - int y_end = 0; + double y_start = 0; + double y_end = 0; if (m_dir == AHBB_Dir_Top_Bottom) { y_start = m_lower_right.X + (button_size * 1.25 * m_buttons.size()) @@ -240,12 +237,13 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id, y_start = y_end - button_size; } - current_button = rect(m_upper_left.X, y_start, m_lower_right.Y, - y_end); + current_button = rect(m_upper_left.X, y_start, + m_lower_right.Y, y_end); } - button_info *btn = new button_info(); - btn->guibutton = m_guienv->addButton(current_button, 0, button_id, caption, 0); + auto *btn = new button_info(); + btn->guibutton = m_guienv->addButton(current_button, + nullptr, button_id, caption, nullptr); btn->guibutton->grab(); btn->guibutton->setVisible(false); btn->guibutton->setEnabled(false); @@ -275,26 +273,23 @@ bool AutoHideButtonBar::isButton(const SEvent &event) { IGUIElement *rootguielement = m_guienv->getRootGUIElement(); - if (rootguielement == NULL) { + if (rootguielement == nullptr) return false; - } gui::IGUIElement *element = rootguielement->getElementFromPoint( core::position2d(event.TouchInput.X, event.TouchInput.Y)); - if (element == NULL) { + if (element == nullptr) return false; - } if (m_active) { // check for all buttons in vector - - std::vector::iterator iter = m_buttons.begin(); + auto iter = m_buttons.begin(); while (iter != m_buttons.end()) { if ((*iter)->guibutton == element) { - SEvent *translated = new SEvent(); + auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); translated->EventType = irr::EET_KEY_INPUT_EVENT; translated->KeyInput.Key = (*iter)->keycode; @@ -341,7 +336,7 @@ bool AutoHideButtonBar::isButton(const SEvent &event) m_active = true; m_timeout = 0; - std::vector::iterator iter = m_buttons.begin(); + auto iter = m_buttons.begin(); while (iter != m_buttons.end()) { (*iter)->guibutton->setVisible(true); @@ -355,41 +350,13 @@ bool AutoHideButtonBar::isButton(const SEvent &event) return false; } -bool AutoHideButtonBar::isReleaseButton(int eventID) -{ - std::vector::iterator id = std::find(m_starter.ids.begin(), - m_starter.ids.end(), eventID); - - if (id != m_starter.ids.end()) { - m_starter.ids.erase(id); - return true; - } - - std::vector::iterator iter = m_buttons.begin(); - - while (iter != m_buttons.end()) { - std::vector::iterator id = std::find((*iter)->ids.begin(), - (*iter)->ids.end(), eventID); - - if (id != (*iter)->ids.end()) { - (*iter)->ids.erase(id); - // TODO handle settings button release - return true; - } - ++iter; - } - - return false; -} - void AutoHideButtonBar::step(float dtime) { if (m_active) { m_timeout += dtime; - if (m_timeout > m_timeout_value) { + if (m_timeout > m_timeout_value) deactivate(); - } } } @@ -401,11 +368,11 @@ void AutoHideButtonBar::deactivate() } m_active = false; - std::vector::iterator iter = m_buttons.begin(); + auto iter = m_buttons.begin(); while (iter != m_buttons.end()) { - (*iter)->guibutton->setVisible(false); - (*iter)->guibutton->setEnabled(false); + (*iter)->guibutton->setVisible(false); + (*iter)->guibutton->setEnabled(false); ++iter; } } @@ -416,7 +383,7 @@ void AutoHideButtonBar::hide() m_starter.guibutton->setVisible(false); m_starter.guibutton->setEnabled(false); - std::vector::iterator iter = m_buttons.begin(); + auto iter = m_buttons.begin(); while (iter != m_buttons.end()) { (*iter)->guibutton->setVisible(false); @@ -430,7 +397,7 @@ void AutoHideButtonBar::show() m_visible = true; if (m_active) { - std::vector::iterator iter = m_buttons.begin(); + auto iter = m_buttons.begin(); while (iter != m_buttons.end()) { (*iter)->guibutton->setVisible(true); @@ -450,24 +417,26 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) m_settingsbar(device, receiver), m_rarecontrolsbar(device, receiver) { - for (unsigned int i=0; i < after_last_element_id; i++) { - m_buttons[i].guibutton = 0; - m_buttons[i].repeatcounter = -1; - m_buttons[i].repeatdelay = BUTTON_REPEAT_DELAY; + for (auto &button : m_buttons) { + button.guibutton = nullptr; + button.repeatcounter = -1; + button.repeatdelay = BUTTON_REPEAT_DELAY; } m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold"); m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick"); m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux"); m_screensize = m_device->getVideoDriver()->getScreenSize(); + button_size = MYMIN(m_screensize.Y / 4.5f, + porting::getDisplayDensity() * + g_settings->getFloat("hud_scaling") * 65.0f); } -void TouchScreenGUI::initButton(touch_gui_button_id id, rect button_rect, - std::wstring caption, bool immediate_release, float repeat_delay) +void TouchScreenGUI::initButton(touch_gui_button_id id, const rect &button_rect, + const std::wstring &caption, bool immediate_release, float repeat_delay) { - button_info *btn = &m_buttons[id]; - btn->guibutton = m_guienv->addButton(button_rect, 0, id, caption.c_str()); + btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str()); btn->guibutton->grab(); btn->repeatcounter = -1; btn->repeatdelay = repeat_delay; @@ -475,42 +444,29 @@ void TouchScreenGUI::initButton(touch_gui_button_id id, rect button_rect, btn->immediate_release = immediate_release; btn->ids.clear(); - load_button_texture(btn, touchgui_button_imagenames[id], button_rect, + load_button_texture(btn, button_imagenames[id], button_rect, m_texturesource, m_device->getVideoDriver()); } -button_info *TouchScreenGUI::initJoystickButton(touch_gui_button_id id, rect button_rect, - int texture_id, bool visible) +button_info *TouchScreenGUI::initJoystickButton(touch_gui_button_id id, + const rect &button_rect, int texture_id, bool visible) { - button_info *btn = new button_info(); - btn->guibutton = m_guienv->addButton(button_rect, 0, id, L"O"); + auto *btn = new button_info(); + btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, L"O"); btn->guibutton->setVisible(visible); btn->guibutton->grab(); btn->ids.clear(); - load_button_texture(btn, touchgui_joystick_imagenames[texture_id], button_rect, - m_texturesource, m_device->getVideoDriver()); + load_button_texture(btn, joystick_imagenames[texture_id], + button_rect, m_texturesource, m_device->getVideoDriver()); return btn; } -static int getMaxControlPadSize(float density) { - return 200 * density * g_settings->getFloat("hud_scaling"); -} - -int TouchScreenGUI::getGuiButtonSize() -{ - u32 control_pad_size = MYMIN((2 * m_screensize.Y) / 3, - getMaxControlPadSize(porting::getDisplayDensity())); - - return control_pad_size / 3; -} - void TouchScreenGUI::init(ISimpleTextureSource *tsrc) { assert(tsrc); - u32 button_size = getGuiButtonSize(); m_visible = true; m_texturesource = tsrc; @@ -608,35 +564,31 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) m_rarecontrolsbar.addButton(chat_id, L"Chat", "chat_btn.png"); m_rarecontrolsbar.addButton(inventory_id, L"inv", "inventory_btn.png"); m_rarecontrolsbar.addButton(drop_id, L"drop", "drop_btn.png"); - } touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) { IGUIElement *rootguielement = m_guienv->getRootGUIElement(); - if (rootguielement != NULL) { + if (rootguielement != nullptr) { gui::IGUIElement *element = rootguielement->getElementFromPoint(core::position2d(x, y)); - if (element) { - for (unsigned int i=0; i < after_last_element_id; i++) { - if (element == m_buttons[i].guibutton) { + if (element) + for (unsigned int i = 0; i < after_last_element_id; i++) + if (element == m_buttons[i].guibutton) return (touch_gui_button_id) i; - } - } - } } + return after_last_element_id; } -touch_gui_button_id TouchScreenGUI::getButtonID(int eventID) +touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID) { - for (unsigned int i=0; i < after_last_element_id; i++) { + for (unsigned int i = 0; i < after_last_element_id; i++) { button_info *btn = &m_buttons[i]; - std::vector::iterator id = - std::find(btn->ids.begin(), btn->ids.end(), eventID); + auto id = std::find(btn->ids.begin(), btn->ids.end(), eventID); if (id != btn->ids.end()) return (touch_gui_button_id) i; @@ -648,55 +600,30 @@ touch_gui_button_id TouchScreenGUI::getButtonID(int eventID) bool TouchScreenGUI::isHUDButton(const SEvent &event) { // check if hud item is pressed - for (std::map >::iterator iter = m_hud_rects.begin(); - iter != m_hud_rects.end(); ++iter) { - if (iter->second.isPointInside( - v2s32(event.TouchInput.X, - event.TouchInput.Y) - )) { - if ( iter->first < 8) { - SEvent *translated = new SEvent(); - memset(translated, 0, sizeof(SEvent)); - translated->EventType = irr::EET_KEY_INPUT_EVENT; - translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first); - translated->KeyInput.Control = false; - translated->KeyInput.Shift = false; - translated->KeyInput.PressedDown = true; - m_receiver->OnEvent(*translated); - m_hud_ids[event.TouchInput.ID] = translated->KeyInput.Key; - delete translated; - return true; - } + for (auto &hud_rect : m_hud_rects) { + if (hud_rect.second.isPointInside(v2s32(event.TouchInput.X, + event.TouchInput.Y))) { + auto *translated = new SEvent(); + memset(translated, 0, sizeof(SEvent)); + translated->EventType = irr::EET_KEY_INPUT_EVENT; + translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + hud_rect.first); + translated->KeyInput.Control = false; + translated->KeyInput.Shift = false; + translated->KeyInput.PressedDown = true; + m_receiver->OnEvent(*translated); + m_hud_ids[event.TouchInput.ID] = translated->KeyInput.Key; + delete translated; + return true; } } return false; } -bool TouchScreenGUI::isReleaseHUDButton(int eventID) -{ - std::map::iterator iter = m_hud_ids.find(eventID); - - if (iter != m_hud_ids.end()) { - SEvent *translated = new SEvent(); - memset(translated, 0, sizeof(SEvent)); - translated->EventType = irr::EET_KEY_INPUT_EVENT; - translated->KeyInput.Key = iter->second; - translated->KeyInput.PressedDown = false; - translated->KeyInput.Control = false; - translated->KeyInput.Shift = false; - m_receiver->OnEvent(*translated); - m_hud_ids.erase(iter); - delete translated; - return true; - } - return false; -} - void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button, - int eventID, bool action) + size_t eventID, bool action) { button_info *btn = &m_buttons[button]; - SEvent *translated = new SEvent(); + auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); translated->EventType = irr::EET_KEY_INPUT_EVENT; translated->KeyInput.Key = btn->keycode; @@ -717,16 +644,16 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button, translated->KeyInput.Key = btn->keycode; m_receiver->OnEvent(*translated); } + // remove event if ((!action) || (btn->immediate_release)) { - - std::vector::iterator pos = - std::find(btn->ids.begin(), btn->ids.end(), eventID); + auto pos = std::find(btn->ids.begin(), btn->ids.end(), eventID); // has to be in touch list assert(pos != btn->ids.end()); btn->ids.erase(pos); - if (btn->ids.size() > 0) { return; } + if (!btn->ids.empty()) + return; translated->KeyInput.PressedDown = false; btn->repeatcounter = -1; @@ -735,30 +662,21 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button, delete translated; } - -void TouchScreenGUI::handleReleaseEvent(int evt_id) +void TouchScreenGUI::handleReleaseEvent(size_t evt_id) { touch_gui_button_id button = getButtonID(evt_id); - // handle button events + if (button != after_last_element_id) { + // handle button events handleButtonEvent(button, evt_id, false); - } - // handle hud button events - else if (isReleaseHUDButton(evt_id)) { - // nothing to do here - } else if (m_settingsbar.isReleaseButton(evt_id)) { - // nothing to do here - } else if (m_rarecontrolsbar.isReleaseButton(evt_id)) { - // nothing to do here - } - // handle the point used for moving view - else if (evt_id == m_move_id) { + } else if (evt_id == m_move_id) { + // handle the point used for moving view m_move_id = -1; // if this pointer issued a mouse event issue symmetric release here if (m_move_sent_as_mouse_event) { - SEvent *translated = new SEvent; + auto *translated = new SEvent; memset(translated, 0, sizeof(SEvent)); translated->EventType = EET_MOUSE_INPUT_EVENT; translated->MouseInput.X = m_move_downlocation.X; @@ -769,32 +687,31 @@ void TouchScreenGUI::handleReleaseEvent(int evt_id) translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP; m_receiver->OnEvent(*translated); delete translated; - } - else { + } else { // do double tap detection doubleTapDetection(); } } + // handle joystick else if (evt_id == m_joystick_id) { m_joystick_id = -1; // reset joystick - for (unsigned int i = 0; i < 4; i ++) + for (unsigned int i = 0; i < 4; i++) m_joystick_status[i] = false; applyJoystickStatus(); m_joystick_btn_off->guibutton->setVisible(true); m_joystick_btn_bg->guibutton->setVisible(false); m_joystick_btn_center->guibutton->setVisible(false); - } - else { + } else { infostream << "TouchScreenGUI::translateEvent released unknown button: " << evt_id << std::endl; } - for (std::vector::iterator iter = m_known_ids.begin(); + for (auto iter = m_known_ids.begin(); iter != m_known_ids.end(); ++iter) { if (iter->id == evt_id) { m_known_ids.erase(iter); @@ -806,18 +723,19 @@ void TouchScreenGUI::handleReleaseEvent(int evt_id) void TouchScreenGUI::translateEvent(const SEvent &event) { if (!m_visible) { - infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl; + infostream + << "TouchScreenGUI::translateEvent got event but not visible!" + << std::endl; return; } - if (event.EventType != EET_TOUCH_INPUT_EVENT) { + if (event.EventType != EET_TOUCH_INPUT_EVENT) return; - } if (event.TouchInput.Event == ETIE_PRESSED_DOWN) { - - /* add to own copy of eventlist ... - * android would provide this information but irrlicht guys don't + /* + * Add to own copy of event list... + * android would provide this information but Irrlicht guys don't * wanna design a efficient interface */ id_status toadd; @@ -826,7 +744,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) toadd.Y = event.TouchInput.Y; m_known_ids.push_back(toadd); - int eventID = event.TouchInput.ID; + size_t eventID = event.TouchInput.ID; touch_gui_button_id button = getButtonID(event.TouchInput.X, event.TouchInput.Y); @@ -846,21 +764,19 @@ void TouchScreenGUI::translateEvent(const SEvent &event) } else if (m_rarecontrolsbar.isButton(event)) { m_settingsbar.deactivate(); // already handled in isSettingsBarButton() - } - // handle non button events - else { + } else { + // handle non button events m_settingsbar.deactivate(); m_rarecontrolsbar.deactivate(); - u32 button_size = getGuiButtonSize(); - s32 dxj = event.TouchInput.X - button_size * 5 / 2; - s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5 / 2; + s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f; + s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; /* Select joystick when left 1/3 of screen dragged or * when joystick tapped (fixed joystick position) */ if ((m_fixed_joystick && dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5) || - (!m_fixed_joystick && event.TouchInput.X < m_screensize.X / 3)) { + (!m_fixed_joystick && event.TouchInput.X < m_screensize.X / 3.0f)) { // If we don't already have a starting point for joystick make this the one. if (m_joystick_id == -1) { m_joystick_id = event.TouchInput.ID; @@ -871,14 +787,14 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_joystick_btn_center->guibutton->setVisible(true); // If it's a fixed joystick, don't move the joystick "button". - if (!m_fixed_joystick) { + if (!m_fixed_joystick) m_joystick_btn_bg->guibutton->setRelativePosition(v2s32( - event.TouchInput.X - button_size * 3 / 2, - event.TouchInput.Y - button_size * 3 / 2)); - } + event.TouchInput.X - button_size * 3.0f / 2.0f, + event.TouchInput.Y - button_size * 3.0f / 2.0f)); + m_joystick_btn_center->guibutton->setRelativePosition(v2s32( - event.TouchInput.X - button_size / 2, - event.TouchInput.Y - button_size / 2)); + event.TouchInput.X - button_size / 2.0f, + event.TouchInput.Y - button_size / 2.0f)); } } else { // If we don't already have a moving point make this the moving one. @@ -895,17 +811,15 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y); } else if (event.TouchInput.Event == ETIE_LEFT_UP) { - verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl; + verbosestream + << "Up event for pointerid: " << event.TouchInput.ID << std::endl; handleReleaseEvent(event.TouchInput.ID); - } - else { + } else { assert(event.TouchInput.Event == ETIE_MOVED); - int move_idx = event.TouchInput.ID; if (m_pointerpos[event.TouchInput.ID] == - v2s32(event.TouchInput.X, event.TouchInput.Y)) { + v2s32(event.TouchInput.X, event.TouchInput.Y)) return; - } if (m_move_id != -1) { if ((event.TouchInput.ID == m_move_id) && @@ -928,9 +842,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y; // adapt to similar behaviour as pc screen - double d = g_settings->getFloat("mouse_sensitivity") * 4; - double old_yaw = m_camera_yaw_change; - double old_pitch = m_camera_pitch; + double d = g_settings->getFloat("mouse_sensitivity") * 3.0f; m_camera_yaw_change -= dx * d; m_camera_pitch = MYMIN(MYMAX(m_camera_pitch + (dy * d), -180), 180); @@ -942,8 +854,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) ->getRayFromScreenCoordinates(v2s32(X, Y)); m_pointerpos[event.TouchInput.ID] = v2s32(X, Y); } - } - else if ((event.TouchInput.ID == m_move_id) && + } else if ((event.TouchInput.ID == m_move_id) && (m_move_sent_as_mouse_event)) { m_shootline = m_device ->getSceneManager() @@ -954,7 +865,6 @@ void TouchScreenGUI::translateEvent(const SEvent &event) } if (m_joystick_id != -1 && event.TouchInput.ID == m_joystick_id) { - u32 button_size = getGuiButtonSize(); s32 X = event.TouchInput.X; s32 Y = event.TouchInput.Y; @@ -967,8 +877,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) double distance_sq = dx * dx + dy * dy; - s32 dxj = event.TouchInput.X - button_size * 5 / 2; - s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5 / 2; + s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f; + s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5); if (m_joystick_has_really_moved || @@ -986,8 +896,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) angle = fmod(angle + 180 + 22.5, 360); // reset state before applying - for (unsigned int i = 0; i < 5; i ++) - m_joystick_status[i] = false; + for (bool & joystick_status : m_joystick_status) + joystick_status = false; if (distance <= m_touchscreen_threshold) { // do nothing @@ -1016,8 +926,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) if (distance > button_size) { m_joystick_status[j_special1] = true; // move joystick "button" - s32 ndx = (s32) button_size * dx / distance - (s32) button_size / 2; - s32 ndy = (s32) button_size * dy / distance - (s32) button_size / 2; + s32 ndx = button_size * dx / distance - button_size / 2.0f; + s32 ndy = button_size * dy / distance - button_size / 2.0f; if (m_fixed_joystick) { m_joystick_btn_center->guibutton->setRelativePosition(v2s32( button_size * 5 / 2 + ndx, @@ -1028,64 +938,54 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_pointerpos[event.TouchInput.ID].Y + ndy)); } } else { - m_joystick_btn_center->guibutton->setRelativePosition(v2s32( - X - button_size / 2, Y - button_size / 2)); + m_joystick_btn_center->guibutton->setRelativePosition( + v2s32(X - button_size / 2, Y - button_size / 2)); } } } - if (m_move_id == -1 && m_joystick_id == -1) { + if (m_move_id == -1 && m_joystick_id == -1) handleChangedButton(event); - } } } void TouchScreenGUI::handleChangedButton(const SEvent &event) { for (unsigned int i = 0; i < after_last_element_id; i++) { - - if (m_buttons[i].ids.empty()) { + if (m_buttons[i].ids.empty()) continue; - } - for (std::vector::iterator iter = m_buttons[i].ids.begin(); - iter != m_buttons[i].ids.end(); ++iter) { + for (auto iter = m_buttons[i].ids.begin(); + iter != m_buttons[i].ids.end(); ++iter) { if (event.TouchInput.ID == *iter) { - int current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y); - if (current_button_id == i) { + if (current_button_id == i) continue; - } // remove old button handleButtonEvent((touch_gui_button_id) i, *iter, false); - if (current_button_id == after_last_element_id) { + if (current_button_id == after_last_element_id) return; - } + handleButtonEvent((touch_gui_button_id) current_button_id, *iter, true); return; - } } } int current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y); - if (current_button_id == after_last_element_id) { + if (current_button_id == after_last_element_id) return; - } button_info *btn = &m_buttons[current_button_id]; if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID) == btn->ids.end()) - { handleButtonEvent((touch_gui_button_id) current_button_id, event.TouchInput.ID, true); - } - } bool TouchScreenGUI::doubleTapDetection() @@ -1102,14 +1002,15 @@ bool TouchScreenGUI::doubleTapDetection() return false; double distance = sqrt( - (m_key_events[0].x - m_key_events[1].x) * (m_key_events[0].x - m_key_events[1].x) + - (m_key_events[0].y - m_key_events[1].y) * (m_key_events[0].y - m_key_events[1].y)); - + (m_key_events[0].x - m_key_events[1].x) * + (m_key_events[0].x - m_key_events[1].x) + + (m_key_events[0].y - m_key_events[1].y) * + (m_key_events[0].y - m_key_events[1].y)); if (distance > (20 + m_touchscreen_threshold)) return false; - SEvent *translated = new SEvent(); + auto *translated = new SEvent(); memset(translated, 0, sizeof(SEvent)); translated->EventType = EET_MOUSE_INPUT_EVENT; translated->MouseInput.X = m_key_events[0].x; @@ -1129,21 +1030,20 @@ bool TouchScreenGUI::doubleTapDetection() m_receiver->OnEvent(*translated); translated->MouseInput.ButtonStates = 0; - translated->MouseInput.Event = EMIE_RMOUSE_LEFT_UP; + translated->MouseInput.Event = EMIE_RMOUSE_LEFT_UP; verbosestream << "TouchScreenGUI::translateEvent right click release" << std::endl; m_receiver->OnEvent(*translated); delete translated; return true; - } void TouchScreenGUI::applyJoystickStatus() { - for (unsigned int i = 0; i < 5; i ++) { + for (unsigned int i = 0; i < 5; i++) { if (i == 4 && !m_joystick_triggers_special1) continue; - SEvent translated{}; + SEvent translated; translated.EventType = irr::EET_KEY_INPUT_EVENT; translated.KeyInput.Key = id2keycode(m_joystick_names[i]); translated.KeyInput.PressedDown = false; @@ -1158,50 +1058,48 @@ void TouchScreenGUI::applyJoystickStatus() TouchScreenGUI::~TouchScreenGUI() { - for (unsigned int i = 0; i < after_last_element_id; i++) { - button_info *btn = &m_buttons[i]; - if (btn->guibutton) { - btn->guibutton->drop(); - btn->guibutton = NULL; + for (auto &button : m_buttons) { + if (button.guibutton) { + button.guibutton->drop(); + button.guibutton = nullptr; } } if (m_joystick_btn_off->guibutton) { m_joystick_btn_off->guibutton->drop(); - m_joystick_btn_off->guibutton = NULL; + m_joystick_btn_off->guibutton = nullptr; } if (m_joystick_btn_bg->guibutton) { m_joystick_btn_bg->guibutton->drop(); - m_joystick_btn_bg->guibutton = NULL; + m_joystick_btn_bg->guibutton = nullptr; } if (m_joystick_btn_center->guibutton) { m_joystick_btn_center->guibutton->drop(); - m_joystick_btn_center->guibutton = NULL; + m_joystick_btn_center->guibutton = nullptr; } } void TouchScreenGUI::step(float dtime) { // simulate keyboard repeats - for (unsigned int i = 0; i < after_last_element_id; i++) { - button_info *btn = &m_buttons[i]; - - if (btn->ids.size() > 0) { - btn->repeatcounter += dtime; + for (auto &button : m_buttons) { + if (!button.ids.empty()) { + button.repeatcounter += dtime; // in case we're moving around digging does not happen if (m_move_id != -1) m_move_has_really_moved = true; - if (btn->repeatcounter < btn->repeatdelay) continue; + if (button.repeatcounter < button.repeatdelay) + continue; - btn->repeatcounter = 0; + button.repeatcounter = 0; SEvent translated; memset(&translated, 0, sizeof(SEvent)); translated.EventType = irr::EET_KEY_INPUT_EVENT; - translated.KeyInput.Key = btn->keycode; + translated.KeyInput.Key = button.keycode; translated.KeyInput.PressedDown = false; m_receiver->OnEvent(translated); @@ -1264,22 +1162,18 @@ void TouchScreenGUI::registerHudItem(int index, const rect &rect) void TouchScreenGUI::Toggle(bool visible) { m_visible = visible; - for (unsigned int i = 0; i < after_last_element_id; i++) { - button_info *btn = &m_buttons[i]; - if (btn->guibutton) { - btn->guibutton->setVisible(visible); - } + for (auto &button : m_buttons) { + if (button.guibutton) + button.guibutton->setVisible(visible); } - if (m_joystick_btn_off->guibutton) { + if (m_joystick_btn_off->guibutton) m_joystick_btn_off->guibutton->setVisible(visible); - } // clear all active buttons if (!visible) { - while (m_known_ids.size() > 0) { + while (!m_known_ids.empty()) handleReleaseEvent(m_known_ids.begin()->id); - } m_settingsbar.hide(); m_rarecontrolsbar.hide(); diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 2a3f24a3f..761d33207 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -80,21 +80,22 @@ typedef enum } autohide_button_bar_dir; #define MIN_DIG_TIME_MS 500 -#define MAX_TOUCH_COUNT 64 #define BUTTON_REPEAT_DELAY 0.2f - #define SETTINGS_BAR_Y_OFFSET 5 #define RARE_CONTROLS_BAR_Y_OFFSET 5 -extern const char **touchgui_button_imagenames; -extern const char **touchgui_joystick_imagenames; +// Very slow button repeat frequency +#define SLOW_BUTTON_REPEAT 1.0f + +extern const char **button_imagenames; +extern const char **joystick_imagenames; struct button_info { float repeatcounter; float repeatdelay; irr::EKEY_CODE keycode; - std::vector ids; + std::vector ids; IGUIButton *guibutton = nullptr; bool immediate_release; @@ -109,8 +110,8 @@ public: AutoHideButtonBar(IrrlichtDevice *device, IEventReceiver *receiver); void init(ISimpleTextureSource *tsrc, const char *starter_img, int button_id, - v2s32 UpperLeft, v2s32 LowerRight, autohide_button_bar_dir dir, - float timeout); + const v2s32 &UpperLeft, const v2s32 &LowerRight, + autohide_button_bar_dir dir, float timeout); ~AutoHideButtonBar(); @@ -125,9 +126,6 @@ public: // detect settings bar button events bool isButton(const SEvent &event); - // handle released hud buttons - bool isReleaseButton(int eventID); - // step handler void step(float dtime); @@ -182,7 +180,7 @@ public: double getPitch() { return m_camera_pitch; } - /*! + /* * Returns a line which describes what the player is pointing at. * The starting point and looking direction are significant, * the line should be scaled to match its length to the actual distance @@ -206,9 +204,10 @@ private: IEventReceiver *m_receiver; ISimpleTextureSource *m_texturesource; v2u32 m_screensize; + s32 button_size; double m_touchscreen_threshold; std::map> m_hud_rects; - std::map m_hud_ids; + std::map m_hud_ids; bool m_visible; // is the gui visible // value in degree @@ -220,7 +219,7 @@ private: forward_id, backward_id, left_id, right_id, special1_id}; bool m_joystick_status[5] = {false, false, false, false, false}; - /*! + /* * A line starting at the camera and pointing towards the * selected object. * The line ends on the camera's far plane. @@ -248,23 +247,24 @@ private: touch_gui_button_id getButtonID(s32 x, s32 y); // gui button by eventID - touch_gui_button_id getButtonID(int eventID); + touch_gui_button_id getButtonID(size_t eventID); // check if a button has changed void handleChangedButton(const SEvent &event); // initialize a button - void initButton(touch_gui_button_id id, rect button_rect, - std::wstring caption, bool immediate_release, + void initButton(touch_gui_button_id id, const rect &button_rect, + const std::wstring &caption, bool immediate_release, float repeat_delay = BUTTON_REPEAT_DELAY); // initialize a joystick button - button_info *initJoystickButton(touch_gui_button_id id, rect button_rect, - int texture_id, bool visible = true); + button_info *initJoystickButton(touch_gui_button_id id, + const rect &button_rect, int texture_id, + bool visible = true); struct id_status { - int id; + size_t id; int X; int Y; }; @@ -273,27 +273,21 @@ private: std::vector m_known_ids; // handle a button event - void handleButtonEvent(touch_gui_button_id bID, int eventID, bool action); + void handleButtonEvent(touch_gui_button_id bID, size_t eventID, bool action); // handle pressed hud buttons bool isHUDButton(const SEvent &event); - // handle released hud buttons - bool isReleaseHUDButton(int eventID); - // handle double taps bool doubleTapDetection(); // handle release event - void handleReleaseEvent(int evt_id); + void handleReleaseEvent(size_t evt_id); // apply joystick status void applyJoystickStatus(); - // get size of regular gui control button - int getGuiButtonSize(); - - // doubleclick detection variables + // double-click detection variables struct key_event { u64 down_time; @@ -302,9 +296,9 @@ private: }; // array for saving last known position of a pointer - v2s32 m_pointerpos[MAX_TOUCH_COUNT]; + std::map m_pointerpos; - // array for doubletap detection + // array for double tap detection key_event m_key_events[2]; // settings bar @@ -313,4 +307,5 @@ private: // rare controls bar AutoHideButtonBar m_rarecontrolsbar; }; + extern TouchScreenGUI *g_touchscreengui; -- cgit v1.2.3 From 09e285f38cd96b4278b921ab82c5266082bb1a0d Mon Sep 17 00:00:00 2001 From: hecktest <42101236+hecktest@users.noreply.github.com> Date: Tue, 9 Jun 2020 19:36:47 +0200 Subject: Fix player-to-object attachment teleport bug (#10008) Fixes two bugs: * The camera offset was not applied to an object while detaching, briefly placing the irrlicht matrixnode in world space. * When attaching, the matrixnode's absolute position was evaluated without evaluating the parent first, resulting in zeroed positions. --- src/client/content_cao.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index a6ce06d20..79ecccb6f 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -921,7 +921,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) m_animated_meshnode->animateJoints(); updateBonePosition(); } - + // Handle model animations and update positions instantly to prevent lags if (m_is_local_player) { LocalPlayer *player = m_env->getLocalPlayer(); @@ -1403,7 +1403,7 @@ void GenericCAO::updateBonePosition() bone->setRotation(it.second.Y); } } - + // search through bones to find mistakenly rotated bones due to bug in Irrlicht for (u32 i = 0; i < m_animated_meshnode->getJointCount(); ++i) { irr::scene::IBoneSceneNode *bone = m_animated_meshnode->getJointNode(i); @@ -1427,7 +1427,7 @@ void GenericCAO::updateBonePosition() // and update the bones transformation. v3f bone_rot = bone->getRelativeTransformation().getRotationDegrees(); float offset = fabsf(bone_rot.X - bone->getRotation().X); - if (offset > 179.9f && offset < 180.1f) { + if (offset > 179.9f && offset < 180.1f) { bone->setRotation(bone_rot); bone->updateAbsolutePosition(); } @@ -1454,15 +1454,17 @@ void GenericCAO::updateAttachments() if (!parent) { // Detach or don't attach if (m_matrixnode) { + v3s16 camera_offset = m_env->getCameraOffset(); v3f old_pos = getPosition(); m_matrixnode->setParent(m_smgr->getRootSceneNode()); - getPosRotMatrix().setTranslation(old_pos); + getPosRotMatrix().setTranslation(old_pos - intToFloat(camera_offset, BS)); m_matrixnode->updateAbsolutePosition(); } } else // Attach { + parent->updateAttachments(); scene::ISceneNode *parent_node = parent->getSceneNode(); scene::IAnimatedMeshSceneNode *parent_animated_mesh_node = parent->getAnimatedMeshSceneNode(); @@ -1472,6 +1474,7 @@ void GenericCAO::updateAttachments() if (m_matrixnode && parent_node) { m_matrixnode->setParent(parent_node); + parent_node->updateAbsolutePosition(); getPosRotMatrix().setTranslation(m_attachment_position); //setPitchYawRoll(getPosRotMatrix(), m_attachment_rotation); // use Irrlicht eulers instead -- cgit v1.2.3 From b16f841756ef86e83710ad2fddf2cd5bafdf4bcc Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Tue, 9 Jun 2020 13:37:25 -0400 Subject: LuaItemStack: Add __tostring metamethod (#8785) * LuaItemStack: Add __tostring metamethod * Clean up LuaItemStack::checkobject --- builtin/common/misc_helpers.lua | 2 ++ src/inventory.cpp | 29 ++++++++++++++++------------- src/inventory.h | 4 ++-- src/script/lua_api/l_item.cpp | 25 ++++++++++++++++++------- src/script/lua_api/l_item.h | 3 +++ 5 files changed, 41 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index a88adf96d..e29a9f422 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -20,6 +20,8 @@ local function basic_dump(o) -- dump's output is intended for humans. --elseif tp == "function" then -- return string.format("loadstring(%q)", string.dump(o)) + elseif tp == "userdata" then + return tostring(o) else return string.format("<%s>", tp) end diff --git a/src/inventory.cpp b/src/inventory.cpp index 77ecf5876..349ee503d 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -56,28 +56,31 @@ ItemStack::ItemStack(const std::string &name_, u16 count_, count = 1; } -void ItemStack::serialize(std::ostream &os) const +void ItemStack::serialize(std::ostream &os, bool serialize_meta) const { if (empty()) return; // Check how many parts of the itemstring are needed int parts = 1; - if(count != 1) - parts = 2; - if(wear != 0) - parts = 3; if (!metadata.empty()) parts = 4; + else if (wear != 0) + parts = 3; + else if (count != 1) + parts = 2; - os<= 2) - os<<" "<= 3) - os<<" "<= 2) + os << " " << count; + if (parts >= 3) + os << " " << wear; if (parts >= 4) { os << " "; - metadata.serialize(os); + if (serialize_meta) + metadata.serialize(os); + else + os << ""; } } @@ -240,10 +243,10 @@ void ItemStack::deSerialize(const std::string &str, IItemDefManager *itemdef) deSerialize(is, itemdef); } -std::string ItemStack::getItemString() const +std::string ItemStack::getItemString(bool include_meta) const { std::ostringstream os(std::ios::binary); - serialize(os); + serialize(os, include_meta); return os.str(); } diff --git a/src/inventory.h b/src/inventory.h index 2828d3e5a..67a7859ed 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -40,13 +40,13 @@ struct ItemStack ~ItemStack() = default; // Serialization - void serialize(std::ostream &os) const; + void serialize(std::ostream &os, bool serialize_meta = true) const; // Deserialization. Pass itemdef unless you don't want aliases resolved. void deSerialize(std::istream &is, IItemDefManager *itemdef = NULL); void deSerialize(const std::string &s, IItemDefManager *itemdef = NULL); // Returns the string used for inventory - std::string getItemString() const; + std::string getItemString(bool include_meta = true) const; // Returns the tooltip std::string getDescription(IItemDefManager *itemdef) const; diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index 0a403acbd..d67cab76f 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -37,6 +37,15 @@ int LuaItemStack::gc_object(lua_State *L) return 0; } +// __tostring metamethod +int LuaItemStack::mt_tostring(lua_State *L) +{ + LuaItemStack *o = checkobject(L, 1); + std::string itemstring = o->m_stack.getItemString(false); + lua_pushfstring(L, "ItemStack(\"%s\")", itemstring.c_str()); + return 1; +} + // is_empty(self) -> true/false int LuaItemStack::l_is_empty(lua_State *L) { @@ -433,12 +442,9 @@ int LuaItemStack::create(lua_State *L, const ItemStack &item) return 1; } -LuaItemStack* LuaItemStack::checkobject(lua_State *L, int narg) +LuaItemStack *LuaItemStack::checkobject(lua_State *L, int narg) { - luaL_checktype(L, narg, LUA_TUSERDATA); - void *ud = luaL_checkudata(L, narg, className); - if(!ud) luaL_typerror(L, narg, className); - return *(LuaItemStack**)ud; // unbox pointer + return *(LuaItemStack **)luaL_checkudata(L, narg, className); } void LuaItemStack::Register(lua_State *L) @@ -448,9 +454,10 @@ void LuaItemStack::Register(lua_State *L) luaL_newmetatable(L, className); int metatable = lua_gettop(L); + // hide metatable from Lua getmetatable() lua_pushliteral(L, "__metatable"); lua_pushvalue(L, methodtable); - lua_settable(L, metatable); // hide metatable from Lua getmetatable() + lua_settable(L, metatable); lua_pushliteral(L, "__index"); lua_pushvalue(L, methodtable); @@ -460,12 +467,16 @@ void LuaItemStack::Register(lua_State *L) lua_pushcfunction(L, gc_object); lua_settable(L, metatable); + lua_pushliteral(L, "__tostring"); + lua_pushcfunction(L, mt_tostring); + lua_settable(L, metatable); + lua_pop(L, 1); // drop metatable luaL_openlib(L, 0, methods, 0); // fill methodtable lua_pop(L, 1); // drop methodtable - // Can be created from Lua (LuaItemStack(itemstack or itemstring or table or nil)) + // Can be created from Lua (ItemStack(itemstack or itemstring or table or nil)) lua_register(L, className, create_object); } diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h index 6fab58045..98744c071 100644 --- a/src/script/lua_api/l_item.h +++ b/src/script/lua_api/l_item.h @@ -34,6 +34,9 @@ private: // garbage collector static int gc_object(lua_State *L); + // __tostring metamethod + static int mt_tostring(lua_State *L); + // is_empty(self) -> true/false static int l_is_empty(lua_State *L); -- cgit v1.2.3 From fe3e69eb4029626cd7ef3f7a1c2beaec13ba7364 Mon Sep 17 00:00:00 2001 From: Danila Shutov Date: Tue, 9 Jun 2020 22:38:09 +0300 Subject: Fix broken coloring of wielditems (#9969) Fixes a regression that appeared in 5.3.0-dev. --- client/shaders/object_shader/opengl_fragment.glsl | 4 +++- client/shaders/object_shader/opengl_vertex.glsl | 7 ++++++- src/client/wieldmesh.cpp | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index 32f3e974e..0534dc049 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -145,8 +145,10 @@ void main(void) vec4 col = vec4(color.rgb, base.a); + col.rgb *= gl_Color.rgb; + col.rgb *= emissiveColor.rgb * vIDiff; - + #ifdef ENABLE_TONE_MAPPING col = applyToneMapping(col); #endif diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index 488089392..59171145f 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -38,7 +38,12 @@ void main(void) lightVec = sunPosition - worldPosition; eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; - vIDiff = directional_ambient(normalize(gl_Normal)); + + // This is intentional comparison with zero without any margin. + // If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector + vIDiff = length(gl_Normal) == 0.0 + ? 1.0 + : directional_ambient(normalize(gl_Normal)); gl_FrontColor = gl_BackColor = gl_Color; } diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index 997eb1b5b..8cd3e29a9 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -467,7 +467,11 @@ void WieldMeshSceneNode::setColor(video::SColor c) bc.getGreen() * green / 255, bc.getBlue() * blue / 255); scene::IMeshBuffer *buf = mesh->getMeshBuffer(j); - colorizeMeshBuffer(buf, &buffercolor); + + if (m_enable_shaders) + setMeshBufferColor(buf, buffercolor); + else + colorizeMeshBuffer(buf, &buffercolor); } } @@ -481,9 +485,9 @@ void WieldMeshSceneNode::setNodeLightColor(video::SColor color) video::SMaterial &material = m_meshnode->getMaterial(i); material.EmissiveColor = color; } - } else { - setColor(color); } + + setColor(color); } void WieldMeshSceneNode::render() -- cgit v1.2.3 From 64380cf92e8d0000f75ec372e3e1d09bdccd12e7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 10 Jun 2020 10:58:13 +0200 Subject: Fix build error on Ubuntu 16.04 --- src/client/content_mapblock.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index f7d20001f..3d06584c4 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include "content_mapblock.h" #include "util/numeric.h" #include "util/directiontables.h" -- cgit v1.2.3 From 80d9e9c1834fdc78588ffe2842766c0177227786 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 10 Jun 2020 11:46:14 +0200 Subject: Fix build error on Ubuntu 16.04 (again) --- src/client/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index 91781373c..68832849e 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -341,7 +341,7 @@ bool checkMeshNormals(scene::IMesh *mesh) // hurting the performance and covering only really weird broken models. f32 length = buffer->getNormal(0).getLength(); - if (!isfinite(length) || fabs(length) < 1e-10) + if (!std::isfinite(length) || std::fabs(length) < 1e-10f) return false; } -- cgit v1.2.3 From f89794108c49a7a9e992afb9431ae244e4a4fef1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 10 Jun 2020 16:53:23 +0200 Subject: content_cao: Do not expire visuals for texture updates --- src/client/content_cao.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 79ecccb6f..644a71e6e 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1487,18 +1487,22 @@ void GenericCAO::updateAttachments() bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const { const ObjectProperties &old = m_prop; + /* Visuals do not need to be expired for: + * - nametag props: handled by updateNametag() + * - textures: handled by updateTextures() + * - sprite props: handled by updateTexturePos() + * - glow: handled by updateLight() + * - any other properties that do not change appearance + */ // Ordered to compare primitive types before std::vectors return old.backface_culling != new_.backface_culling || - old.initial_sprite_basepos != new_.initial_sprite_basepos || old.is_visible != new_.is_visible || old.mesh != new_.mesh || - old.spritediv != new_.spritediv || old.use_texture_alpha != new_.use_texture_alpha || old.visual != new_.visual || old.visual_size != new_.visual_size || old.wield_item != new_.wield_item || - old.colors != new_.colors || - old.textures != new_.textures; + old.colors != new_.colors; } void GenericCAO::processMessage(const std::string &data) @@ -1513,6 +1517,7 @@ void GenericCAO::processMessage(const std::string &data) // Check what exactly changed bool expire_visuals = visualExpiryRequired(newprops); + bool textures_changed = m_prop.textures != newprops.textures; // Apply changes m_prop = std::move(newprops); @@ -1541,13 +1546,18 @@ void GenericCAO::processMessage(const std::string &data) if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty()) m_prop.nametag = m_name; - updateNametag(); if (expire_visuals) { expireVisuals(); } else { infostream << "GenericCAO: properties updated but expiring visuals" << " not necessary" << std::endl; + if (textures_changed) { + // don't update while punch texture modifier is active + if (m_reset_textures_timer < 0) + updateTextures(m_current_texture_modifier); + } + updateNametag(); } } else if (cmd == AO_CMD_UPDATE_POSITION) { // Not sent by the server if this object is an attachment. -- cgit v1.2.3 From 3f0cbbc372d5f359af18f5cbad37a1b165d3df4e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 7 Jun 2020 19:58:09 +0200 Subject: Use multiple light positions for CAO lighting --- src/client/clientobject.h | 1 - src/client/content_cao.cpp | 42 ++++++++++++++++++++++++------------------ src/client/content_cao.h | 5 ++++- 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/client/clientobject.h b/src/client/clientobject.h index 8e64b8406..ecd8059ef 100644 --- a/src/client/clientobject.h +++ b/src/client/clientobject.h @@ -43,7 +43,6 @@ public: virtual void removeFromScene(bool permanent) {} virtual void updateLight(u32 day_night_ratio) {} - virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); } virtual bool getCollisionBox(aabb3f *toset) const { return false; } virtual bool getSelectionBox(aabb3f *toset) const { return false; } diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 644a71e6e..eec4e3de0 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -182,7 +182,6 @@ public: void addToScene(ITextureSource *tsrc); void removeFromScene(bool permanent); void updateLight(u32 day_night_ratio); - v3s16 getLightPosition(); void updateNodePos(); void step(float dtime, ClientEnvironment *env); @@ -258,11 +257,6 @@ void TestCAO::updateLight(u32 day_night_ratio) { } -v3s16 TestCAO::getLightPosition() -{ - return floatToInt(m_position, BS); -} - void TestCAO::updateNodePos() { if (!m_node) @@ -799,13 +793,20 @@ void GenericCAO::updateLight(u32 day_night_ratio) return; u8 light_at_pos = 0; - bool pos_ok; - - v3s16 p = getLightPosition(); - MapNode n = m_env->getMap().getNode(p, &pos_ok); - if (pos_ok) - light_at_pos = n.getLightBlend(day_night_ratio, m_client->ndef()); - else + bool pos_ok = false; + + v3s16 pos[3]; + u16 npos = getLightPosition(pos); + for (u16 i = 0; i < npos; i++) { + bool this_ok; + MapNode n = m_env->getMap().getNode(pos[i], &this_ok); + if (this_ok) { + u8 this_light = n.getLightBlend(day_night_ratio, m_client->ndef()); + light_at_pos = MYMAX(light_at_pos, this_light); + pos_ok = true; + } + } + if (!pos_ok) light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0); u8 light = decode_light(light_at_pos + m_glow); @@ -856,12 +857,17 @@ void GenericCAO::setNodeLight(u8 light) } } -v3s16 GenericCAO::getLightPosition() +u16 GenericCAO::getLightPosition(v3s16 *pos) { - if (m_is_player) - return floatToInt(m_position + v3f(0, 0.5 * BS, 0), BS); - - return floatToInt(m_position, BS); + const auto &box = m_prop.collisionbox; + pos[0] = floatToInt(m_position + box.MinEdge * BS, BS); + pos[1] = floatToInt(m_position + box.MaxEdge * BS, BS); + + // Skip center pos if it falls into the same node as Min or MaxEdge + if ((box.MaxEdge - box.MinEdge).getLengthSQ() < 3.0f) + return 2; + pos[2] = floatToInt(m_position + box.getCenter() * BS, BS); + return 3; } void GenericCAO::updateNametag() diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 7693dd3d2..699148c52 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -240,7 +240,10 @@ public: void setNodeLight(u8 light); - v3s16 getLightPosition(); + /* Get light position(s). + * returns number of positions written into pos[], which must have space + * for at least 3 vectors. */ + u16 getLightPosition(v3s16 *pos); void updateNametag(); -- cgit v1.2.3 From 982a030f330bd4f4953ed7d4a7f88286f6fd645d Mon Sep 17 00:00:00 2001 From: luk3yx Date: Sat, 13 Jun 2020 04:54:20 +1200 Subject: Add LevelDB player database (#9982) --- doc/minetest.6 | 6 +- src/database/database-leveldb.cpp | 112 ++++++++++++++++++++++++++++++++++++++ src/database/database-leveldb.h | 15 +++++ src/serverenvironment.cpp | 9 ++- 4 files changed, 138 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/doc/minetest.6 b/doc/minetest.6 index cb5ed57ef..bac70fe1a 100644 --- a/doc/minetest.6 +++ b/doc/minetest.6 @@ -105,12 +105,12 @@ Migrate from current map backend to another. Possible values are sqlite3, leveldb, redis, postgresql, and dummy. .TP .B \-\-migrate-auth -Migrate from current auth backend to another. Possible values are sqlite3 and -files. +Migrate from current auth backend to another. Possible values are sqlite3, +leveldb, and files. .TP .B \-\-migrate-players Migrate from current players backend to another. Possible values are sqlite3, -postgresql, dummy, and files. +leveldb, postgresql, dummy, and files. .TP .B \-\-terminal Display an interactive terminal over ncurses during execution. diff --git a/src/database/database-leveldb.cpp b/src/database/database-leveldb.cpp index 1aab4c43d..1976ae13d 100644 --- a/src/database/database-leveldb.cpp +++ b/src/database/database-leveldb.cpp @@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "filesys.h" #include "exceptions.h" +#include "remoteplayer.h" +#include "server/player_sao.h" #include "util/serialize.h" #include "util/string.h" @@ -98,6 +100,116 @@ void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) delete it; } +PlayerDatabaseLevelDB::PlayerDatabaseLevelDB(const std::string &savedir) +{ + leveldb::Options options; + options.create_if_missing = true; + leveldb::Status status = leveldb::DB::Open(options, + savedir + DIR_DELIM + "players.db", &m_database); + ENSURE_STATUS_OK(status); +} + +PlayerDatabaseLevelDB::~PlayerDatabaseLevelDB() +{ + delete m_database; +} + +void PlayerDatabaseLevelDB::savePlayer(RemotePlayer *player) +{ + /* + u8 version = 1 + u16 hp + v3f position + f32 pitch + f32 yaw + u16 breath + u32 attribute_count + for each attribute { + std::string name + std::string (long) value + } + std::string (long) serialized_inventory + */ + + std::ostringstream os; + writeU8(os, 1); + + PlayerSAO *sao = player->getPlayerSAO(); + sanity_check(sao); + writeU16(os, sao->getHP()); + writeV3F32(os, sao->getBasePosition()); + writeF32(os, sao->getLookPitch()); + writeF32(os, sao->getRotation().Y); + writeU16(os, sao->getBreath()); + + StringMap stringvars = sao->getMeta().getStrings(); + writeU32(os, stringvars.size()); + for (const auto &it : stringvars) { + os << serializeString(it.first); + os << serializeLongString(it.second); + } + + player->inventory.serialize(os); + + leveldb::Status status = m_database->Put(leveldb::WriteOptions(), + player->getName(), os.str()); + ENSURE_STATUS_OK(status); + player->onSuccessfulSave(); +} + +bool PlayerDatabaseLevelDB::removePlayer(const std::string &name) +{ + leveldb::Status s = m_database->Delete(leveldb::WriteOptions(), name); + return s.ok(); +} + +bool PlayerDatabaseLevelDB::loadPlayer(RemotePlayer *player, PlayerSAO *sao) +{ + std::string raw; + leveldb::Status s = m_database->Get(leveldb::ReadOptions(), + player->getName(), &raw); + if (!s.ok()) + return false; + std::istringstream is(raw); + + if (readU8(is) > 1) + return false; + + sao->setHPRaw(readU16(is)); + sao->setBasePosition(readV3F32(is)); + sao->setLookPitch(readF32(is)); + sao->setPlayerYaw(readF32(is)); + sao->setBreath(readU16(is), false); + + u32 attribute_count = readU32(is); + for (u32 i = 0; i < attribute_count; i++) { + std::string name = deSerializeString(is); + std::string value = deSerializeLongString(is); + sao->getMeta().setString(name, value); + } + sao->getMeta().setModified(false); + + // This should always be last. + try { + player->inventory.deSerialize(is); + } catch (SerializationError &e) { + errorstream << "Failed to deserialize player inventory. player_name=" + << player->getName() << " " << e.what() << std::endl; + } + + return true; +} + +void PlayerDatabaseLevelDB::listPlayers(std::vector &res) +{ + leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions()); + res.clear(); + for (it->SeekToFirst(); it->Valid(); it->Next()) { + res.push_back(it->key().ToString()); + } + delete it; +} + AuthDatabaseLevelDB::AuthDatabaseLevelDB(const std::string &savedir) { leveldb::Options options; diff --git a/src/database/database-leveldb.h b/src/database/database-leveldb.h index a9bd0faa4..61def1256 100644 --- a/src/database/database-leveldb.h +++ b/src/database/database-leveldb.h @@ -45,6 +45,21 @@ private: leveldb::DB *m_database; }; +class PlayerDatabaseLevelDB : public PlayerDatabase +{ +public: + PlayerDatabaseLevelDB(const std::string &savedir); + ~PlayerDatabaseLevelDB(); + + void savePlayer(RemotePlayer *player); + bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); + bool removePlayer(const std::string &name); + void listPlayers(std::vector &res); + +private: + leveldb::DB *m_database; +}; + class AuthDatabaseLevelDB : public AuthDatabase { public: diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 222b4d203..2c6a39ee3 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -2089,6 +2089,7 @@ PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name, if (name == "dummy") return new Database_Dummy(); + #if USE_POSTGRESQL if (name == "postgresql") { std::string connect_string; @@ -2096,6 +2097,12 @@ PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name, return new PlayerDatabasePostgreSQL(connect_string); } #endif + +#if USE_LEVELDB + if (name == "leveldb") + return new PlayerDatabaseLevelDB(savedir); +#endif + if (name == "files") return new PlayerDatabaseFiles(savedir + DIR_DELIM + "players"); @@ -2116,7 +2123,7 @@ bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params, if (!world_mt.exists("player_backend")) { errorstream << "Please specify your current backend in world.mt:" << std::endl - << " player_backend = {files|sqlite3|postgresql}" + << " player_backend = {files|sqlite3|leveldb|postgresql}" << std::endl; return false; } -- cgit v1.2.3 From 2424dfe007e451bb02f87884c2b272cf307d6e7c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 13 Jun 2020 19:03:26 +0200 Subject: Server pushing media at runtime (#9961) --- doc/lua_api.txt | 14 +++ src/client/client.cpp | 12 ++- src/client/client.h | 9 +- src/client/clientmedia.cpp | 10 +- src/client/clientmedia.h | 5 + src/client/filecache.cpp | 8 ++ src/client/filecache.h | 1 + src/filesys.cpp | 6 ++ src/network/clientopcodes.cpp | 2 +- src/network/clientpackethandler.cpp | 46 +++++++++ src/network/networkprotocol.h | 9 ++ src/network/serveropcodes.cpp | 2 +- src/script/lua_api/l_server.cpp | 22 +++- src/script/lua_api/l_server.h | 3 + src/server.cpp | 195 +++++++++++++++++++++++------------- src/server.h | 4 + 16 files changed, 263 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index ed060c4ad..cb968958f 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -5217,6 +5217,20 @@ Server * Returns a code (0: successful, 1: no such player, 2: player is connected) * `minetest.remove_player_auth(name)`: remove player authentication data * Returns boolean indicating success (false if player nonexistant) +* `minetest.dynamic_add_media(filepath)` + * Adds the file at the given path to the media sent to clients by the server + on startup and also pushes this file to already connected clients. + The file must be a supported image, sound or model format. It must not be + modified, deleted, moved or renamed after calling this function. + The list of dynamically added media is not persisted. + * Returns boolean indicating success (duplicate files count as error) + * The media will be ready to use (in e.g. entity textures, sound_play) + immediately after calling this function. + Old clients that lack support for this feature will not see the media + unless they reconnect to the server. + * Since media transferred this way does not use client caching or HTTP + transfers, dynamic media should not be used with big files or performance + will suffer. Bans ---- diff --git a/src/client/client.cpp b/src/client/client.cpp index c03c062c6..34f97a9de 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -670,11 +670,9 @@ void Client::step(float dtime) } } -bool Client::loadMedia(const std::string &data, const std::string &filename) +bool Client::loadMedia(const std::string &data, const std::string &filename, + bool from_media_push) { - // Silly irrlicht's const-incorrectness - Buffer data_rw(data.c_str(), data.size()); - std::string name; const char *image_ext[] = { @@ -690,6 +688,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) io::IFileSystem *irrfs = RenderingEngine::get_filesystem(); video::IVideoDriver *vdrv = RenderingEngine::get_video_driver(); + // Silly irrlicht's const-incorrectness + Buffer data_rw(data.c_str(), data.size()); + // Create an irrlicht memory file io::IReadFile *rfile = irrfs->createMemoryReadFile( *data_rw, data_rw.getSize(), "_tempreadfile"); @@ -727,7 +728,6 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) ".x", ".b3d", ".md2", ".obj", NULL }; - name = removeStringEnd(filename, model_ext); if (!name.empty()) { verbosestream<<"Client: Storing model into memory: " @@ -744,6 +744,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename) }; name = removeStringEnd(filename, translate_ext); if (!name.empty()) { + if (from_media_push) + return false; TRACESTREAM(<< "Client: Loading translation: " << "\"" << filename << "\"" << std::endl); g_client_translations->loadTranslation(data); diff --git a/src/client/client.h b/src/client/client.h index 3b1095ac2..733634db1 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -222,6 +222,7 @@ public: void handleCommand_FormspecPrepend(NetworkPacket *pkt); void handleCommand_CSMRestrictionFlags(NetworkPacket *pkt); void handleCommand_PlayerSpeed(NetworkPacket *pkt); + void handleCommand_MediaPush(NetworkPacket *pkt); void ProcessData(NetworkPacket *pkt); @@ -376,7 +377,8 @@ public: // The following set of functions is used by ClientMediaDownloader // Insert a media file appropriately into the appropriate manager - bool loadMedia(const std::string &data, const std::string &filename); + bool loadMedia(const std::string &data, const std::string &filename, + bool from_media_push = false); // Send a request for conventional media transfer void request_media(const std::vector &file_requests); @@ -488,6 +490,7 @@ private: Camera *m_camera = nullptr; Minimap *m_minimap = nullptr; bool m_minimap_disabled_by_server = false; + // Server serialization version u8 m_server_ser_ver; @@ -529,7 +532,6 @@ private: AuthMechanism m_chosen_auth_mech; void *m_auth_data = nullptr; - bool m_access_denied = false; bool m_access_denied_reconnect = false; std::string m_access_denied_reason = ""; @@ -538,7 +540,10 @@ private: bool m_nodedef_received = false; bool m_activeobjects_received = false; bool m_mods_loaded = false; + ClientMediaDownloader *m_media_downloader; + // Set of media filenames pushed by server at runtime + std::unordered_set m_media_pushed_files; // time_of_day speed approximation for old protocol bool m_time_of_day_set = false; diff --git a/src/client/clientmedia.cpp b/src/client/clientmedia.cpp index 6da99bbbf..8cd3b6bcc 100644 --- a/src/client/clientmedia.cpp +++ b/src/client/clientmedia.cpp @@ -35,6 +35,15 @@ static std::string getMediaCacheDir() return porting::path_cache + DIR_DELIM + "media"; } +bool clientMediaUpdateCache(const std::string &raw_hash, const std::string &filedata) +{ + FileCache media_cache(getMediaCacheDir()); + std::string sha1_hex = hex_encode(raw_hash); + if (!media_cache.exists(sha1_hex)) + return media_cache.update(sha1_hex, filedata); + return true; +} + /* ClientMediaDownloader */ @@ -559,7 +568,6 @@ bool ClientMediaDownloader::checkAndLoad( return true; } - /* Minetest Hashset File Format diff --git a/src/client/clientmedia.h b/src/client/clientmedia.h index 92831082c..5a918535b 100644 --- a/src/client/clientmedia.h +++ b/src/client/clientmedia.h @@ -33,6 +33,11 @@ struct HTTPFetchResult; #define MTHASHSET_FILE_SIGNATURE 0x4d544853 // 'MTHS' #define MTHASHSET_FILE_NAME "index.mth" +// Store file into media cache (unless it exists already) +// Validating the hash is responsibility of the caller +bool clientMediaUpdateCache(const std::string &raw_hash, + const std::string &filedata); + class ClientMediaDownloader { public: diff --git a/src/client/filecache.cpp b/src/client/filecache.cpp index 3d1b302a8..46bbe4059 100644 --- a/src/client/filecache.cpp +++ b/src/client/filecache.cpp @@ -82,8 +82,16 @@ bool FileCache::update(const std::string &name, const std::string &data) std::string path = m_dir + DIR_DELIM + name; return updateByPath(path, data); } + bool FileCache::load(const std::string &name, std::ostream &os) { std::string path = m_dir + DIR_DELIM + name; return loadByPath(path, os); } + +bool FileCache::exists(const std::string &name) +{ + std::string path = m_dir + DIR_DELIM + name; + std::ifstream fis(path.c_str(), std::ios_base::binary); + return fis.good(); +} diff --git a/src/client/filecache.h b/src/client/filecache.h index 96e4c8ba1..ea6afc4b2 100644 --- a/src/client/filecache.h +++ b/src/client/filecache.h @@ -33,6 +33,7 @@ public: bool update(const std::string &name, const std::string &data); bool load(const std::string &name, std::ostream &os); + bool exists(const std::string &name); private: std::string m_dir; diff --git a/src/filesys.cpp b/src/filesys.cpp index f61b39b94..0bc351669 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -691,6 +691,12 @@ std::string AbsolutePath(const std::string &path) const char *GetFilenameFromPath(const char *path) { const char *filename = strrchr(path, DIR_DELIM_CHAR); + // Consistent with IsDirDelimiter this function handles '/' too + if (DIR_DELIM_CHAR != '/') { + const char *tmp = strrchr(path, '/'); + if (tmp && tmp > filename) + filename = tmp; + } return filename ? filename + 1 : path; } diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp index 0f20047c0..f812a08a1 100644 --- a/src/network/clientopcodes.cpp +++ b/src/network/clientopcodes.cpp @@ -68,7 +68,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] = { "TOCLIENT_TIME_OF_DAY", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_TimeOfDay }, // 0x29 { "TOCLIENT_CSM_RESTRICTION_FLAGS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CSMRestrictionFlags }, // 0x2A { "TOCLIENT_PLAYER_SPEED", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_PlayerSpeed }, // 0x2B - null_command_handler, + { "TOCLIENT_MEDIA_PUSH", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MediaPush }, // 0x2C null_command_handler, null_command_handler, { "TOCLIENT_CHAT_MESSAGE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ChatMessage }, // 0x2F diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index e000acc92..5934eaf8c 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "script/scripting_client.h" #include "util/serialize.h" #include "util/srp.h" +#include "util/sha1.h" #include "tileanimation.h" #include "gettext.h" #include "skyparams.h" @@ -1471,6 +1472,51 @@ void Client::handleCommand_PlayerSpeed(NetworkPacket *pkt) player->addVelocity(added_vel); } +void Client::handleCommand_MediaPush(NetworkPacket *pkt) +{ + std::string raw_hash, filename, filedata; + bool cached; + + *pkt >> raw_hash >> filename >> cached; + filedata = pkt->readLongString(); + + if (raw_hash.size() != 20 || filedata.empty() || filename.empty() || + !string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) { + throw PacketError("Illegal filename, data or hash"); + } + + verbosestream << "Server pushes media file \"" << filename << "\" with " + << filedata.size() << " bytes of data (cached=" << cached + << ")" << std::endl; + + if (m_media_pushed_files.count(filename) != 0) { + // Silently ignore for synchronization purposes + return; + } + + // Compute and check checksum of data + std::string computed_hash; + { + SHA1 ctx; + ctx.addBytes(filedata.c_str(), filedata.size()); + unsigned char *buf = ctx.getDigest(); + computed_hash.assign((char*) buf, 20); + free(buf); + } + if (raw_hash != computed_hash) { + verbosestream << "Hash of file data mismatches, ignoring." << std::endl; + return; + } + + // Actually load media + loadMedia(filedata, filename, true); + m_media_pushed_files.insert(filename); + + // Cache file for the next time when this client joins the same server + if (cached) + clientMediaUpdateCache(raw_hash, filedata); +} + /* * Mod channels */ diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index ab924f1db..fd683eac9 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -323,6 +323,15 @@ enum ToClientCommand v3f added_vel */ + TOCLIENT_MEDIA_PUSH = 0x2C, + /* + std::string raw_hash + std::string filename + bool should_be_cached + u32 len + char filedata[len] + */ + // (oops, there is some gap here) TOCLIENT_CHAT_MESSAGE = 0x2F, diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp index 6ee4ff256..2fc3197c2 100644 --- a/src/network/serveropcodes.cpp +++ b/src/network/serveropcodes.cpp @@ -167,7 +167,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] = { "TOCLIENT_TIME_OF_DAY", 0, true }, // 0x29 { "TOCLIENT_CSM_RESTRICTION_FLAGS", 0, true }, // 0x2A { "TOCLIENT_PLAYER_SPEED", 0, true }, // 0x2B - null_command_factory, // 0x2C + { "TOCLIENT_MEDIA_PUSH", 0, true }, // 0x2C (sent over channel 1 too) null_command_factory, // 0x2D null_command_factory, // 0x2E { "TOCLIENT_CHAT_MESSAGE", 0, true }, // 0x2F diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index b6754938e..6f934bb9d 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_converter.h" #include "common/c_content.h" #include "cpp_api/s_base.h" +#include "cpp_api/s_security.h" #include "server.h" #include "environment.h" #include "remoteplayer.h" @@ -412,9 +413,6 @@ int ModApiServer::l_get_modnames(lua_State *L) std::vector modlist; getServer(L)->getModNames(modlist); - // Take unsorted items from mods_unsorted and sort them into - // mods_sorted; not great performance but the number of mods on a - // server will likely be small. std::sort(modlist.begin(), modlist.end()); // Package them up for Lua @@ -474,6 +472,23 @@ int ModApiServer::l_sound_fade(lua_State *L) return 0; } +// dynamic_add_media(filepath) +int ModApiServer::l_dynamic_add_media(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + + // Reject adding media before the server has started up + if (!getEnv(L)) + throw LuaError("Dynamic media cannot be added before server has started up"); + + std::string filepath = readParam(L, 1); + CHECK_SECURE_PATH(L, filepath.c_str(), false); + + bool ok = getServer(L)->dynamicAddMedia(filepath); + lua_pushboolean(L, ok); + return 1; +} + // is_singleplayer() int ModApiServer::l_is_singleplayer(lua_State *L) { @@ -538,6 +553,7 @@ void ModApiServer::Initialize(lua_State *L, int top) API_FCT(sound_play); API_FCT(sound_stop); API_FCT(sound_fade); + API_FCT(dynamic_add_media); API_FCT(get_player_information); API_FCT(get_player_privs); diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h index 3aa1785a2..938bfa8ef 100644 --- a/src/script/lua_api/l_server.h +++ b/src/script/lua_api/l_server.h @@ -70,6 +70,9 @@ private: // sound_fade(handle, step, gain) static int l_sound_fade(lua_State *L); + // dynamic_add_media(filepath) + static int l_dynamic_add_media(lua_State *L); + // get_player_privs(name, text) static int l_get_player_privs(lua_State *L); diff --git a/src/server.cpp b/src/server.cpp index 6ecbd7097..fe2bb3840 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2405,9 +2405,87 @@ bool Server::SendBlock(session_t peer_id, const v3s16 &blockpos) return true; } +bool Server::addMediaFile(const std::string &filename, + const std::string &filepath, std::string *filedata_to, + std::string *digest_to) +{ + // If name contains illegal characters, ignore the file + if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) { + infostream << "Server: ignoring illegal file name: \"" + << filename << "\"" << std::endl; + return false; + } + // If name is not in a supported format, ignore it + const char *supported_ext[] = { + ".png", ".jpg", ".bmp", ".tga", + ".pcx", ".ppm", ".psd", ".wal", ".rgb", + ".ogg", + ".x", ".b3d", ".md2", ".obj", + // Custom translation file format + ".tr", + NULL + }; + if (removeStringEnd(filename, supported_ext).empty()) { + infostream << "Server: ignoring unsupported file extension: \"" + << filename << "\"" << std::endl; + return false; + } + // Ok, attempt to load the file and add to cache + + // Read data + std::ifstream fis(filepath.c_str(), std::ios_base::binary); + if (!fis.good()) { + errorstream << "Server::addMediaFile(): Could not open \"" + << filename << "\" for reading" << std::endl; + return false; + } + std::string filedata; + bool bad = false; + for (;;) { + char buf[1024]; + fis.read(buf, sizeof(buf)); + std::streamsize len = fis.gcount(); + filedata.append(buf, len); + if (fis.eof()) + break; + if (!fis.good()) { + bad = true; + break; + } + } + if (bad) { + errorstream << "Server::addMediaFile(): Failed to read \"" + << filename << "\"" << std::endl; + return false; + } else if (filedata.empty()) { + errorstream << "Server::addMediaFile(): Empty file \"" + << filepath << "\"" << std::endl; + return false; + } + + SHA1 sha1; + sha1.addBytes(filedata.c_str(), filedata.length()); + + unsigned char *digest = sha1.getDigest(); + std::string sha1_base64 = base64_encode(digest, 20); + std::string sha1_hex = hex_encode((char*) digest, 20); + if (digest_to) + *digest_to = std::string((char*) digest, 20); + free(digest); + + // Put in list + m_media[filename] = MediaInfo(filepath, sha1_base64); + verbosestream << "Server: " << sha1_hex << " is " << filename + << std::endl; + + if (filedata_to) + *filedata_to = std::move(filedata); + return true; +} + void Server::fillMediaCache() { - infostream<<"Server: Calculating media file checksums"< paths; @@ -2419,80 +2497,15 @@ void Server::fillMediaCache() for (const std::string &mediapath : paths) { std::vector dirlist = fs::GetDirListing(mediapath); for (const fs::DirListNode &dln : dirlist) { - if (dln.dir) // Ignode dirs - continue; - std::string filename = dln.name; - // If name contains illegal characters, ignore the file - if (!string_allowed(filename, TEXTURENAME_ALLOWED_CHARS)) { - infostream<<"Server: ignoring illegal file name: \"" - << filename << "\"" << std::endl; - continue; - } - // If name is not in a supported format, ignore it - const char *supported_ext[] = { - ".png", ".jpg", ".bmp", ".tga", - ".pcx", ".ppm", ".psd", ".wal", ".rgb", - ".ogg", - ".x", ".b3d", ".md2", ".obj", - // Custom translation file format - ".tr", - NULL - }; - if (removeStringEnd(filename, supported_ext).empty()){ - infostream << "Server: ignoring unsupported file extension: \"" - << filename << "\"" << std::endl; + if (dln.dir) // Ignore dirs continue; - } - // Ok, attempt to load the file and add to cache - std::string filepath; - filepath.append(mediapath).append(DIR_DELIM).append(filename); - - // Read data - std::ifstream fis(filepath.c_str(), std::ios_base::binary); - if (!fis.good()) { - errorstream << "Server::fillMediaCache(): Could not open \"" - << filename << "\" for reading" << std::endl; - continue; - } - std::ostringstream tmp_os(std::ios_base::binary); - bool bad = false; - for(;;) { - char buf[1024]; - fis.read(buf, 1024); - std::streamsize len = fis.gcount(); - tmp_os.write(buf, len); - if (fis.eof()) - break; - if (!fis.good()) { - bad = true; - break; - } - } - if(bad) { - errorstream<<"Server::fillMediaCache(): Failed to read \"" - << filename << "\"" << std::endl; - continue; - } - if(tmp_os.str().length() == 0) { - errorstream << "Server::fillMediaCache(): Empty file \"" - << filepath << "\"" << std::endl; - continue; - } - - SHA1 sha1; - sha1.addBytes(tmp_os.str().c_str(), tmp_os.str().length()); - - unsigned char *digest = sha1.getDigest(); - std::string sha1_base64 = base64_encode(digest, 20); - std::string sha1_hex = hex_encode((char*)digest, 20); - free(digest); - - // Put in list - m_media[filename] = MediaInfo(filepath, sha1_base64); - verbosestream << "Server: " << sha1_hex << " is " << filename - << std::endl; + std::string filepath = mediapath; + filepath.append(DIR_DELIM).append(dln.name); + addMediaFile(dln.name, filepath); } } + + infostream << "Server: " << m_media.size() << " media files collected" << std::endl; } void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_code) @@ -3428,6 +3441,44 @@ void Server::deleteParticleSpawner(const std::string &playername, u32 id) SendDeleteParticleSpawner(peer_id, id); } +bool Server::dynamicAddMedia(const std::string &filepath) +{ + std::string filename = fs::GetFilenameFromPath(filepath.c_str()); + if (m_media.find(filename) != m_media.end()) { + errorstream << "Server::dynamicAddMedia(): file \"" << filename + << "\" already exists in media cache" << std::endl; + return false; + } + + // Load the file and add it to our media cache + std::string filedata, raw_hash; + bool ok = addMediaFile(filename, filepath, &filedata, &raw_hash); + if (!ok) + return false; + + // Push file to existing clients + NetworkPacket pkt(TOCLIENT_MEDIA_PUSH, 0); + pkt << raw_hash << filename << (bool) true; + pkt.putLongString(filedata); + + auto client_ids = m_clients.getClientIDs(CS_DefinitionsSent); + for (session_t client_id : client_ids) { + /* + The network layer only guarantees ordered delivery inside a channel. + Since the very next packet could be one that uses the media, we have + to push the media over ALL channels to ensure it is processed before + it is used. + In practice this means we have to send it twice: + - channel 1 (HUD) + - channel 0 (everything else: e.g. play_sound, object messages) + */ + m_clients.send(client_id, 1, &pkt, true); + m_clients.send(client_id, 0, &pkt, true); + } + + return true; +} + // actions: time-reversed list // Return value: success/failure bool Server::rollbackRevertActions(const std::list &actions, diff --git a/src/server.h b/src/server.h index 27943cc29..f44716531 100644 --- a/src/server.h +++ b/src/server.h @@ -236,6 +236,8 @@ public: void deleteParticleSpawner(const std::string &playername, u32 id); + bool dynamicAddMedia(const std::string &filepath); + ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); } void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id); @@ -435,6 +437,8 @@ private: // Sends blocks to clients (locks env and con on its own) void SendBlocks(float dtime); + bool addMediaFile(const std::string &filename, const std::string &filepath, + std::string *filedata = nullptr, std::string *digest = nullptr); void fillMediaCache(); void sendMediaAnnouncement(session_t peer_id, const std::string &lang_code); void sendRequestedMedia(session_t peer_id, -- cgit v1.2.3 From e7e065f553b430173e9112ad55c7046cfc02f2c5 Mon Sep 17 00:00:00 2001 From: Lars Müller <34514239+appgurueu@users.noreply.github.com> Date: Sat, 13 Jun 2020 22:46:20 +0200 Subject: Exposing the zoom key to Lua API (#9903) Co-authored-by: Raul Ferriz --- doc/lua_api.txt | 7 ++++--- src/client/game.cpp | 5 +++-- src/network/serverpackethandler.cpp | 1 + src/script/lua_api/l_object.cpp | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index cb968958f..07e9698e8 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6106,13 +6106,14 @@ object you are working with still exists. * `get_formspec_prepend(formspec)`: returns a formspec string. * `get_player_control()`: returns table with player pressed keys * The table consists of fields with boolean value representing the pressed - keys, the fields are jump, right, left, LMB, RMB, sneak, aux1, down, up. + keys, the fields are jump, right, left, LMB, RMB, sneak, aux1, down, up, zoom. * example: `{jump=false, right=true, left=false, LMB=false, RMB=false, - sneak=true, aux1=false, down=false, up=false}` + sneak=true, aux1=false, down=false, up=false, zoom=false}` + * The `zoom` field is available since 5.3 * `get_player_control_bits()`: returns integer with bit packed player pressed keys. * bit nr/meaning: 0/up, 1/down, 2/left, 3/right, 4/jump, 5/aux1, 6/sneak, - 7/LMB, 8/RMB + 7/LMB, 8/RMB, 9/zoom (zoom available since 5.3) * `set_physics_override(override_table)` * `override_table` is a table with the following fields: * `speed`: multiplier to default walking speed value (default: `1`) diff --git a/src/client/game.cpp b/src/client/game.cpp index 139742cec..069c482ca 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2490,7 +2490,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam) input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE) ); - u32 keypress_bits = + u32 keypress_bits = ( ( (u32)(isKeyDown(KeyType::FORWARD) & 0x1) << 0) | ( (u32)(isKeyDown(KeyType::BACKWARD) & 0x1) << 1) | ( (u32)(isKeyDown(KeyType::LEFT) & 0x1) << 2) | @@ -2499,7 +2499,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam) ( (u32)(isKeyDown(KeyType::SPECIAL1) & 0x1) << 5) | ( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) | ( (u32)(input->getLeftState() & 0x1) << 7) | - ( (u32)(input->getRightState() & 0x1) << 8 + ( (u32)(input->getRightState() & 0x1) << 8) | + ( (u32)(isKeyDown(KeyType::ZOOM) & 0x1) << 9) ); #ifdef ANDROID diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index fed3b6f85..b3008bb50 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -501,6 +501,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, player->control.sneak = (keyPressed & 64); player->control.LMB = (keyPressed & 128); player->control.RMB = (keyPressed & 256); + player->control.zoom = (keyPressed & 512); if (playersao->checkMovementCheat()) { // Call callbacks diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 0a9f3117b..e7394133a 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1459,6 +1459,8 @@ int ObjectRef::l_get_player_control(lua_State *L) lua_setfield(L, -2, "LMB"); lua_pushboolean(L, control.RMB); lua_setfield(L, -2, "RMB"); + lua_pushboolean(L, control.zoom); + lua_setfield(L, -2, "zoom"); return 1; } -- cgit v1.2.3 From 0ba19a08b80459f037f530cf94e25d1caa18e80b Mon Sep 17 00:00:00 2001 From: "updatepo.sh" Date: Sat, 13 Jun 2020 23:17:04 +0200 Subject: Update minetest.conf.example, settings_translation_file.cpp --- minetest.conf.example | 107 ++++++++++++++++++++++++++++++++++---- src/settings_translation_file.cpp | 44 ++++++++++++---- 2 files changed, 129 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/minetest.conf.example b/minetest.conf.example index 17d24a566..a5f98ee5e 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -254,7 +254,7 @@ # Key for toggling display of minimap. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 # type: key -# keymap_minimap = KEY_F9 +# keymap_minimap = KEY_KEY_V # Key for taking screenshots. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 @@ -469,7 +469,7 @@ # Key for switching between first- and third-person camera. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 # type: key -# keymap_camera_mode = KEY_F7 +# keymap_camera_mode = KEY_KEY_C # Key for increasing the viewing range. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 @@ -636,10 +636,6 @@ # type: int min: 0 max: 1 # parallax_occlusion_mode = 1 -# Strength of parallax. -# type: float -# 3d_paralax_strength = 0.025 - # Number of parallax occlusion iterations. # type: int # parallax_occlusion_iterations = 4 @@ -823,6 +819,10 @@ # type: enum values: none, anaglyph, interlaced, topbottom, sidebyside, crossview, pageflip # 3d_mode = none +# Strength of 3D mode parallax. +# type: float +# 3d_paralax_strength = 0.025 + # In-game chat console height, between 0.1 (10%) and 1.0 (100%). # type: float min: 0.1 max: 1 # console_height = 0.6 @@ -1071,9 +1071,15 @@ # type: filepath # fallback_font_path = fonts/DroidSansFallbackFull.ttf -# Path to save screenshots at. +# Font size of the recent chat text and chat prompt in point (pt). +# Value 0 will use the default font size. +# type: int +# chat_font_size = 0 + +# Path to save screenshots at. Can be an absolute or relative path. +# The folder will be created if it doesn't already exist. # type: path -# screenshot_path = +# screenshot_path = screenshots # Format of screenshots. # type: enum values: png, jpg, bmp, pcx, ppm, tga @@ -1136,6 +1142,13 @@ # type: int min: 1 max: 65535 # remote_port = 30000 +# Prometheus listener address. +# If minetest is compiled with ENABLE_PROMETHEUS option enabled, +# enable metrics listener for Prometheus on that address. +# Metrics can be fetch on http://127.0.0.1:30000/metrics +# type: string +# prometheus_listener_address = 127.0.0.1:30000 + # Save the map received by the client on disk. # type: bool # enable_local_map_saving = false @@ -1292,6 +1305,11 @@ # type: int # item_entity_ttl = 900 +# Specifies the default stack size of nodes, items and tools. +# Note that mods or games may explicitly set a stack for certain (or all) items. +# type: int +# default_stack_max = 99 + # Enable players getting damage and dying. # type: bool # enable_damage = false @@ -1382,7 +1400,7 @@ # active block stuff, stated in mapblocks (16 nodes). # In active blocks objects are loaded and ABMs run. # This is also the minimum range in which active objects (mobs) are maintained. -# This should be configured together with active_object_range. +# This should be configured together with active_object_send_range_blocks. # type: int # active_block_range = 3 @@ -1662,7 +1680,7 @@ # Set the language. Leave empty to use the system language. # A restart is required after changing this. -# type: enum values: , ar, ca, cs, da, de, dv, el, eo, es, et, eu, fil, fr, hu, id, it, ja, ja_KS, jbo, kk, kn, lo, lt, ms, my, nb, nl, nn, pl, pt, pt_BR, ro, ru, sl, sr_Cyrl, sv, sw, th, tr, uk, vi +# type: enum values: , ar, ca, cs, da, de, dv, el, en, eo, es, et, eu, fil, fr, hu, id, it, ja, ja_KS, jbo, kk, kn, lo, lt, ms, my, nb, nl, nn, pl, pt, pt_BR, ro, ru, sl, sr_Cyrl, sv, sw, th, tr, uk, vi # language = # Level of logging to be written to debug.txt: @@ -1683,6 +1701,10 @@ # type: int # debug_log_size_max = 50 +# Minimal level of logging to be written to chat. +# type: enum values: , none, error, warning, action, info, verbose +# chat_log_level = error + # Enable IPv6 support (for both client and server). # Required for IPv6 connections to work at all. # type: bool @@ -2149,7 +2171,9 @@ ## Mapgen V7 # Map generation attributes specific to Mapgen v7. -# 'ridges' enables the rivers. +# 'ridges': Rivers. +# 'floatlands': Floating land masses in the atmosphere. +# 'caverns': Giant caves deep underground. # type: flags possible values: mountains, ridges, floatlands, caverns, nomountains, noridges, nofloatlands, nocaverns # mgv7_spflags = mountains,ridges,nofloatlands,caverns @@ -2157,6 +2181,51 @@ # type: int # mgv7_mount_zero_level = 0 +# Lower Y limit of floatlands. +# type: int +# mgv7_floatland_ymin = 1024 + +# Upper Y limit of floatlands. +# type: int +# mgv7_floatland_ymax = 4096 + +# Y-distance over which floatlands taper from full density to nothing. +# Tapering starts at this distance from the Y limit. +# For a solid floatland layer, this controls the height of hills/mountains. +# Must be less than or equal to half the distance between the Y limits. +# type: int +# mgv7_floatland_taper = 256 + +# Exponent of the floatland tapering. Alters the tapering behaviour. +# Value = 1.0 creates a uniform, linear tapering. +# Values > 1.0 create a smooth tapering suitable for the default separated +# floatlands. +# Values < 1.0 (for example 0.25) create a more defined surface level with +# flatter lowlands, suitable for a solid floatland layer. +# type: float +# mgv7_float_taper_exp = 2.0 + +# Adjusts the density of the floatland layer. +# Increase value to increase density. Can be positive or negative. +# Value = 0.0: 50% of volume is floatland. +# Value = 2.0 (can be higher depending on 'mgv7_np_floatland', always test +# to be sure) creates a solid floatland layer. +# type: float +# mgv7_floatland_density = -0.6 + +# Surface level of optional water placed on a solid floatland layer. +# Water is disabled by default and will only be placed if this value is set +# to above 'mgv7_floatland_ymax' - 'mgv7_floatland_taper' (the start of the +# upper tapering). +# ***WARNING, POTENTIAL DANGER TO WORLDS AND SERVER PERFORMANCE***: +# When enabling water placement the floatlands must be configured and tested +# to be a solid layer by setting 'mgv7_floatland_density' to 2.0 (or other +# required value depending on 'mgv7_np_floatland'), to avoid +# server-intensive extreme water flow and to avoid vast flooding of the +# world surface below. +# type: int +# mgv7_floatland_ywater = -31000 + # Controls width of tunnels, a smaller value creates wider tunnels. # Value >= 10.0 completely disables generation of tunnels and avoids the # intensive noise calculations. @@ -2328,6 +2397,22 @@ # flags = # } +# 3D noise defining structure of floatlands. +# If altered from the default, the noise 'scale' (0.7 by default) may need +# to be adjusted, as floatland tapering functions best when this noise has +# a value range of approximately -2.0 to 2.0. +# type: noise_params_3d +# mgv7_np_floatland = { +# offset = 0, +# scale = 0.7, +# spread = (384, 96, 384), +# seed = 1009, +# octaves = 4, +# persistence = 0.75, +# lacunarity = 1.618, +# flags = +# } + # 3D noise defining giant caverns. # type: noise_params_3d # mgv7_np_cavern = { diff --git a/src/settings_translation_file.cpp b/src/settings_translation_file.cpp index 9156580c0..febfbb9d3 100644 --- a/src/settings_translation_file.cpp +++ b/src/settings_translation_file.cpp @@ -254,8 +254,6 @@ fake_function() { gettext("Enables parallax occlusion mapping.\nRequires shaders to be enabled."); gettext("Parallax occlusion mode"); gettext("0 = parallax occlusion with slope information (faster).\n1 = relief mapping (slower, more accurate)."); - gettext("Parallax occlusion strength"); - gettext("Strength of parallax."); gettext("Parallax occlusion iterations"); gettext("Number of parallax occlusion iterations."); gettext("Parallax occlusion scale"); @@ -326,6 +324,8 @@ fake_function() { gettext("Multiplier for fall bobbing.\nFor example: 0 for no view bobbing; 1.0 for normal; 2.0 for double."); gettext("3D mode"); gettext("3D support.\nCurrently supported:\n- none: no 3d output.\n- anaglyph: cyan/magenta color 3d.\n- interlaced: odd/even line based polarisation screen support.\n- topbottom: split screen top/bottom.\n- sidebyside: split screen side by side.\n- crossview: Cross-eyed 3d\n- pageflip: quadbuffer based 3d.\nNote that the interlaced mode requires shaders to be enabled."); + gettext("3D mode parallax strength"); + gettext("Strength of 3D mode parallax."); gettext("Console height"); gettext("In-game chat console height, between 0.1 (10%) and 1.0 (100%)."); gettext("Console color"); @@ -427,8 +427,10 @@ fake_function() { gettext("Opaqueness (alpha) of the shadow behind the fallback font, between 0 and 255."); gettext("Fallback font path"); gettext("Path of the fallback font.\nIf “freetype” setting is enabled: Must be a TrueType font.\nIf “freetype” setting is disabled: Must be a bitmap or XML vectors font.\nThis font will be used for certain languages or if the default font is unavailable."); + gettext("Chat font size"); + gettext("Font size of the recent chat text and chat prompt in point (pt).\nValue 0 will use the default font size."); gettext("Screenshot folder"); - gettext("Path to save screenshots at."); + gettext("Path to save screenshots at. Can be an absolute or relative path.\nThe folder will be created if it doesn't already exist."); gettext("Screenshot format"); gettext("Format of screenshots."); gettext("Screenshot quality"); @@ -451,6 +453,8 @@ fake_function() { gettext("Address to connect to.\nLeave this blank to start a local server.\nNote that the address field in the main menu overrides this setting."); gettext("Remote port"); gettext("Port to connect to (UDP).\nNote that the port field in the main menu overrides this setting."); + gettext("Prometheus listener address"); + gettext("Prometheus listener address.\nIf minetest is compiled with ENABLE_PROMETHEUS option enabled,\nenable metrics listener for Prometheus on that address.\nMetrics can be fetch on http://127.0.0.1:30000/metrics"); gettext("Saving map received from server"); gettext("Save the map received by the client on disk."); gettext("Connect to external media server"); @@ -516,6 +520,8 @@ fake_function() { gettext("World directory (everything in the world is stored here).\nNot needed if starting from the main menu."); gettext("Item entity TTL"); gettext("Time in seconds for item entity (dropped items) to live.\nSetting it to -1 disables the feature."); + gettext("Default stack size"); + gettext("Specifies the default stack size of nodes, items and tools.\nNote that mods or games may explicitly set a stack for certain (or all) items."); gettext("Damage"); gettext("Enable players getting damage and dying."); gettext("Creative"); @@ -555,7 +561,7 @@ fake_function() { gettext("Active object send range"); gettext("From how far clients know about objects, stated in mapblocks (16 nodes).\n\nSetting this larger than active_block_range will also cause the server\nto maintain active objects up to this distance in the direction the\nplayer is looking. (This can avoid mobs suddenly disappearing from view)"); gettext("Active block range"); - gettext("The radius of the volume of blocks around every player that is subject to the\nactive block stuff, stated in mapblocks (16 nodes).\nIn active blocks objects are loaded and ABMs run.\nThis is also the minimum range in which active objects (mobs) are maintained.\nThis should be configured together with active_object_range."); + gettext("The radius of the volume of blocks around every player that is subject to the\nactive block stuff, stated in mapblocks (16 nodes).\nIn active blocks objects are loaded and ABMs run.\nThis is also the minimum range in which active objects (mobs) are maintained.\nThis should be configured together with active_object_send_range_blocks."); gettext("Max block send distance"); gettext("From how far blocks are sent to clients, stated in mapblocks (16 nodes)."); gettext("Maximum forceloaded blocks"); @@ -674,6 +680,8 @@ fake_function() { gettext("Level of logging to be written to debug.txt:\n- (no logging)\n- none (messages with no level)\n- error\n- warning\n- action\n- info\n- verbose"); gettext("Debug log file size threshold"); gettext("If the file size of debug.txt exceeds the number of megabytes specified in\nthis setting when it is opened, the file is moved to debug.txt.1,\ndeleting an older debug.txt.1 if it exists.\ndebug.txt is only moved if this setting is positive."); + gettext("Chat log level"); + gettext("Minimal level of logging to be written to chat."); gettext("IPv6"); gettext("Enable IPv6 support (for both client and server).\nRequired for IPv6 connections to work at all."); gettext("Advanced"); @@ -791,9 +799,21 @@ fake_function() { gettext("Defines areas where trees have apples."); gettext("Mapgen V7"); gettext("Mapgen V7 specific flags"); - gettext("Map generation attributes specific to Mapgen v7.\n'ridges' enables the rivers."); + gettext("Map generation attributes specific to Mapgen v7.\n'ridges': Rivers.\n'floatlands': Floating land masses in the atmosphere.\n'caverns': Giant caves deep underground."); gettext("Mountain zero level"); gettext("Y of mountain density gradient zero level. Used to shift mountains vertically."); + gettext("Floatland minimum Y"); + gettext("Lower Y limit of floatlands."); + gettext("Floatland maximum Y"); + gettext("Upper Y limit of floatlands."); + gettext("Floatland tapering distance"); + gettext("Y-distance over which floatlands taper from full density to nothing.\nTapering starts at this distance from the Y limit.\nFor a solid floatland layer, this controls the height of hills/mountains.\nMust be less than or equal to half the distance between the Y limits."); + gettext("Floatland taper exponent"); + gettext("Exponent of the floatland tapering. Alters the tapering behaviour.\nValue = 1.0 creates a uniform, linear tapering.\nValues > 1.0 create a smooth tapering suitable for the default separated\nfloatlands.\nValues < 1.0 (for example 0.25) create a more defined surface level with\nflatter lowlands, suitable for a solid floatland layer."); + gettext("Floatland density"); + gettext("Adjusts the density of the floatland layer.\nIncrease value to increase density. Can be positive or negative.\nValue = 0.0: 50% of volume is floatland.\nValue = 2.0 (can be higher depending on 'mgv7_np_floatland', always test\nto be sure) creates a solid floatland layer."); + gettext("Floatland water level"); + gettext("Surface level of optional water placed on a solid floatland layer.\nWater is disabled by default and will only be placed if this value is set\nto above 'mgv7_floatland_ymax' - 'mgv7_floatland_taper' (the start of the\nupper tapering).\n***WARNING, POTENTIAL DANGER TO WORLDS AND SERVER PERFORMANCE***:\nWhen enabling water placement the floatlands must be configured and tested\nto be a solid layer by setting 'mgv7_floatland_density' to 2.0 (or other\nrequired value depending on 'mgv7_np_floatland'), to avoid\nserver-intensive extreme water flow and to avoid vast flooding of the\nworld surface below."); gettext("Cave width"); gettext("Controls width of tunnels, a smaller value creates wider tunnels.\nValue >= 10.0 completely disables generation of tunnels and avoids the\nintensive noise calculations."); gettext("Large cave depth"); @@ -837,6 +857,8 @@ fake_function() { gettext("3D noise defining mountain structure and height.\nAlso defines structure of floatland mountain terrain."); gettext("Ridge noise"); gettext("3D noise defining structure of river canyon walls."); + gettext("Floatland noise"); + gettext("3D noise defining structure of floatlands.\nIf altered from the default, the noise 'scale' (0.7 by default) may need\nto be adjusted, as floatland tapering functions best when this noise has\na value range of approximately -2.0 to 2.0."); gettext("Cavern noise"); gettext("3D noise defining giant caverns."); gettext("Cave1 noise"); @@ -1068,14 +1090,14 @@ fake_function() { gettext("Size of mapchunks generated by mapgen, stated in mapblocks (16 nodes).\nWARNING!: There is no benefit, and there are several dangers, in\nincreasing this value above 5.\nReducing this value increases cave and dungeon density.\nAltering this value is for special usage, leaving it unchanged is\nrecommended."); gettext("Mapgen debug"); gettext("Dump the mapgen debug information."); - gettext("Absolute limit of emerge queues"); + gettext("Absolute limit of queued blocks to emerge"); gettext("Maximum number of blocks that can be queued for loading."); - gettext("Limit of emerge queues on disk"); - gettext("Maximum number of blocks to be queued that are to be loaded from file.\nSet to blank for an appropriate amount to be chosen automatically."); - gettext("Limit of emerge queues to generate"); - gettext("Maximum number of blocks to be queued that are to be generated.\nSet to blank for an appropriate amount to be chosen automatically."); + gettext("Per-player limit of queued blocks load from disk"); + gettext("Maximum number of blocks to be queued that are to be loaded from file.\nThis limit is enforced per player."); + gettext("Per-player limit of queued blocks to generate"); + gettext("Maximum number of blocks to be queued that are to be generated.\nThis limit is enforced per player."); gettext("Number of emerge threads"); - gettext("Number of emerge threads to use.\nWARNING: Currently there are multiple bugs that may cause crashes when\n'num_emerge_threads' is larger than 1. Until this warning is removed it is\nstrongly recommended this value is set to the default '1'.\nValue 0:\n- Automatic selection. The number of emerge threads will be\n- 'number of processors - 2', with a lower limit of 1.\nAny other value:\n- Specifies the number of emerge threads, with a lower limit of 1.\nWARNING: Increasing the number of emerge threads increases engine mapgen\nspeed, but this may harm game performance by interfering with other\nprocesses, especially in singleplayer and/or when running Lua code in\n'on_generated'. For many users the optimum setting may be '1'."); + gettext("Number of emerge threads to use.\nValue 0:\n- Automatic selection. The number of emerge threads will be\n- 'number of processors - 2', with a lower limit of 1.\nAny other value:\n- Specifies the number of emerge threads, with a lower limit of 1.\nWARNING: Increasing the number of emerge threads increases engine mapgen\nspeed, but this may harm game performance by interfering with other\nprocesses, especially in singleplayer and/or when running Lua code in\n'on_generated'. For many users the optimum setting may be '1'."); gettext("Online Content Repository"); gettext("ContentDB URL"); gettext("The URL for the content repository"); -- cgit v1.2.3 From 3a6dfda358112e2fb5d6f887a1a1e936eacddadd Mon Sep 17 00:00:00 2001 From: Danila Shutov Date: Tue, 16 Jun 2020 22:48:31 +0300 Subject: Make shading of CAOs optional (#10033) --- client/shaders/object_shader/opengl_vertex.glsl | 4 ++++ doc/lua_api.txt | 3 +++ games/devtest/mods/testentities/visuals.lua | 12 +++++++++++- src/client/content_cao.cpp | 15 +++++++++++---- src/client/mesh.cpp | 2 +- src/client/shader.cpp | 6 +++++- src/client/tile.h | 2 ++ src/object_properties.cpp | 6 ++++++ src/object_properties.h | 1 + src/script/common/c_content.cpp | 3 +++ 10 files changed, 47 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index 59171145f..968a07e22 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -39,11 +39,15 @@ void main(void) lightVec = sunPosition - worldPosition; eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; +#if (MATERIAL_TYPE == TILE_MATERIAL_PLAIN) || (MATERIAL_TYPE == TILE_MATERIAL_PLAIN_ALPHA) + vIDiff = 1.0; +#else // This is intentional comparison with zero without any margin. // If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector vIDiff = length(gl_Normal) == 0.0 ? 1.0 : directional_ambient(normalize(gl_Normal)); +#endif gl_FrontColor = gl_BackColor = gl_Color; } diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 07e9698e8..11c5cfb91 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6644,6 +6644,9 @@ Player properties need to be saved manually. damage_texture_modifier = "^[brighten", -- Texture modifier to be applied for a short duration when object is hit + + shaded = true, + -- Setting this to 'false' disables diffuse lighting of entity } Entity definition diff --git a/games/devtest/mods/testentities/visuals.lua b/games/devtest/mods/testentities/visuals.lua index 314f51657..83f361f16 100644 --- a/games/devtest/mods/testentities/visuals.lua +++ b/games/devtest/mods/testentities/visuals.lua @@ -55,6 +55,17 @@ minetest.register_entity("testentities:mesh", { }, }) +minetest.register_entity("testentities:mesh_unshaded", { + initial_properties = { + visual = "mesh", + mesh = "testnodes_pyramid.obj", + textures = { + "testnodes_mesh_stripes2.png" + }, + shaded = false, + }, +}) + -- Advanced visual tests -- A test entity for testing animated and yaw-modulated sprites @@ -71,4 +82,3 @@ minetest.register_entity("testentities:yawsprite", { self.object:set_sprite({x=0, y=0}, 1, 0, true) end, }) - diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index eec4e3de0..5352c35f4 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -577,10 +577,16 @@ void GenericCAO::addToScene(ITextureSource *tsrc) if (m_enable_shaders) { IShaderSource *shader_source = m_client->getShaderSource(); - u32 shader_id = shader_source->getShader( - "object_shader", - (m_prop.use_texture_alpha) ? TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC, - NDT_NORMAL); + MaterialType material_type; + + if (m_prop.shaded && m_prop.glow == 0) + material_type = (m_prop.use_texture_alpha) ? + TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC; + else + material_type = (m_prop.use_texture_alpha) ? + TILE_MATERIAL_PLAIN_ALPHA : TILE_MATERIAL_PLAIN; + + u32 shader_id = shader_source->getShader("object_shader", material_type, NDT_NORMAL); m_material_type = shader_source->getShaderInfo(shader_id).material; } else { m_material_type = (m_prop.use_texture_alpha) ? @@ -1504,6 +1510,7 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const return old.backface_culling != new_.backface_culling || old.is_visible != new_.is_visible || old.mesh != new_.mesh || + old.shaded != new_.shaded || old.use_texture_alpha != new_.use_texture_alpha || old.visual != new_.visual || old.visual_size != new_.visual_size || diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp index 68832849e..e1ec22068 100644 --- a/src/client/mesh.cpp +++ b/src/client/mesh.cpp @@ -341,7 +341,7 @@ bool checkMeshNormals(scene::IMesh *mesh) // hurting the performance and covering only really weird broken models. f32 length = buffer->getNormal(0).getLength(); - if (!std::isfinite(length) || std::fabs(length) < 1e-10f) + if (!std::isfinite(length) || length < 1e-10f) return false; } diff --git a/src/client/shader.cpp b/src/client/shader.cpp index eda415ce6..ee6079f7a 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -537,11 +537,13 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp shaderinfo.base_material = video::EMT_SOLID; break; case TILE_MATERIAL_ALPHA: + case TILE_MATERIAL_PLAIN_ALPHA: case TILE_MATERIAL_LIQUID_TRANSPARENT: case TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT: shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL; break; case TILE_MATERIAL_BASIC: + case TILE_MATERIAL_PLAIN: case TILE_MATERIAL_WAVING_LEAVES: case TILE_MATERIAL_WAVING_PLANTS: case TILE_MATERIAL_WAVING_LIQUID_BASIC: @@ -644,9 +646,11 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp "TILE_MATERIAL_WAVING_LIQUID_BASIC", "TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT", "TILE_MATERIAL_WAVING_LIQUID_OPAQUE", + "TILE_MATERIAL_PLAIN", + "TILE_MATERIAL_PLAIN_ALPHA", }; - for (int i = 0; i < 10; i++){ + for (int i = 0; i < 12; i++){ shaders_header += "#define "; shaders_header += materialTypes[i]; shaders_header += " "; diff --git a/src/client/tile.h b/src/client/tile.h index 533df676e..52e0a2b2b 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -150,6 +150,8 @@ enum MaterialType{ TILE_MATERIAL_WAVING_LIQUID_BASIC, TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT, TILE_MATERIAL_WAVING_LIQUID_OPAQUE, + TILE_MATERIAL_PLAIN, + TILE_MATERIAL_PLAIN_ALPHA }; // Material flags diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 6ff344dce..8d51bcbfa 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -69,6 +69,7 @@ std::string ObjectProperties::dump() os << ", zoom_fov=" << zoom_fov; os << ", use_texture_alpha=" << use_texture_alpha; os << ", damage_texture_modifier=" << damage_texture_modifier; + os << ", shaded=" << shaded; return os.str(); } @@ -116,6 +117,7 @@ void ObjectProperties::serialize(std::ostream &os) const writeF32(os, zoom_fov); writeU8(os, use_texture_alpha); os << serializeString(damage_texture_modifier); + writeU8(os, shaded); // Add stuff only at the bottom. // Never remove anything, because we don't want new versions of this @@ -170,5 +172,9 @@ void ObjectProperties::deSerialize(std::istream &is) use_texture_alpha = readU8(is); try { damage_texture_modifier = deSerializeString(is); + u8 tmp = readU8(is); + if (is.eof()) + throw SerializationError(""); + shaded = tmp; } catch (SerializationError &e) {} } diff --git a/src/object_properties.h b/src/object_properties.h index f7848f5a2..f010c1daf 100644 --- a/src/object_properties.h +++ b/src/object_properties.h @@ -61,6 +61,7 @@ struct ObjectProperties float eye_height = 1.625f; float zoom_fov = 0.0f; bool use_texture_alpha = false; + bool shaded = true; ObjectProperties(); std::string dump(); diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 2157d087d..3dfd7ce61 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -327,6 +327,7 @@ void read_object_properties(lua_State *L, int index, getfloatfield(L, -1, "zoom_fov", prop->zoom_fov); getboolfield(L, -1, "use_texture_alpha", prop->use_texture_alpha); + getboolfield(L, -1, "shaded", prop->shaded); getstringfield(L, -1, "damage_texture_modifier", prop->damage_texture_modifier); } @@ -411,6 +412,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop) lua_setfield(L, -2, "zoom_fov"); lua_pushboolean(L, prop->use_texture_alpha); lua_setfield(L, -2, "use_texture_alpha"); + lua_pushboolean(L, prop->shaded); + lua_setfield(L, -2, "shaded"); lua_pushlstring(L, prop->damage_texture_modifier.c_str(), prop->damage_texture_modifier.size()); lua_setfield(L, -2, "damage_texture_modifier"); } -- cgit v1.2.3 From 8ebeed53ad01986eea0608cb8b1f583aace9528b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 18 Jun 2020 01:43:43 +0100 Subject: Android: Fix only right strafe working (#10046) --- src/gui/touchscreengui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 3ee9e4a64..0d64aa618 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -738,7 +738,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) * android would provide this information but Irrlicht guys don't * wanna design a efficient interface */ - id_status toadd; + id_status toadd{}; toadd.id = event.TouchInput.ID; toadd.X = event.TouchInput.X; toadd.Y = event.TouchInput.Y; @@ -1043,7 +1043,7 @@ void TouchScreenGUI::applyJoystickStatus() if (i == 4 && !m_joystick_triggers_special1) continue; - SEvent translated; + SEvent translated{}; translated.EventType = irr::EET_KEY_INPUT_EVENT; translated.KeyInput.Key = id2keycode(m_joystick_names[i]); translated.KeyInput.PressedDown = false; -- cgit v1.2.3 From 495f7198ef8336048fd3a03a9705fe45dbd57574 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 18 Jun 2020 15:11:54 +0200 Subject: content_cao: Fix behavior of legacy "textures" field for wielditems --- src/client/content_cao.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 5352c35f4..7f573b5a1 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -1506,6 +1506,9 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const * - glow: handled by updateLight() * - any other properties that do not change appearance */ + + bool uses_legacy_texture = new_.wield_item.empty() && + (new_.visual == "wielditem" || new_.visual == "item"); // Ordered to compare primitive types before std::vectors return old.backface_culling != new_.backface_culling || old.is_visible != new_.is_visible || @@ -1515,7 +1518,8 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const old.visual != new_.visual || old.visual_size != new_.visual_size || old.wield_item != new_.wield_item || - old.colors != new_.colors; + old.colors != new_.colors || + (uses_legacy_texture && old.textures != new_.textures); } void GenericCAO::processMessage(const std::string &data) -- cgit v1.2.3 From 57df895cf93d79293a8b47802f9523bafcaa330f Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 19 Jun 2020 19:29:47 +0200 Subject: ParticleSpawner: Fix crash when attaching to invisible entity --- src/client/content_cao.h | 7 ++++--- src/client/particles.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 699148c52..974ff9a1e 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -188,10 +188,11 @@ public: return m_matrixnode->getRelativeTransformationMatrix(); } - inline const core::matrix4 &getAbsolutePosRotMatrix() const + inline const core::matrix4 *getAbsolutePosRotMatrix() const { - assert(m_matrixnode); - return m_matrixnode->getAbsoluteTransformation(); + if (!m_matrixnode) + return nullptr; + return &m_matrixnode->getAbsoluteTransformation(); } inline f32 getStepHeight() const diff --git a/src/client/particles.cpp b/src/client/particles.cpp index c78a3e71a..7acd996dc 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -349,7 +349,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment *env) const core::matrix4 *attached_absolute_pos_rot_matrix = nullptr; if (m_attached_id) { if (GenericCAO *attached = dynamic_cast(env->getActiveObject(m_attached_id))) { - attached_absolute_pos_rot_matrix = &attached->getAbsolutePosRotMatrix(); + attached_absolute_pos_rot_matrix = attached->getAbsolutePosRotMatrix(); } else { unloaded = true; } -- cgit v1.2.3 From a2199bf62232707e96ece031a00b320d30e34445 Mon Sep 17 00:00:00 2001 From: Maksim Date: Sat, 20 Jun 2020 12:06:30 +0200 Subject: Android: fix TMPFolder path (#10052) --- src/defaultsettings.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 5d1795003..abb6593b7 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -451,6 +451,7 @@ void set_default_settings(Settings *settings) settings->setDefault("high_precision_fpu", "true"); settings->setDefault("enable_console", "false"); + settings->setDefault("screen_dpi", "72"); // Altered settings for macOS #if defined(__MACH__) && defined(__APPLE__) @@ -464,7 +465,7 @@ void set_default_settings(Settings *settings) settings->setDefault("screen_h", "0"); settings->setDefault("fullscreen", "true"); settings->setDefault("touchtarget", "true"); - settings->setDefault("TMPFolder", porting::getDataPath("tmp" DIR_DELIM)); + settings->setDefault("TMPFolder", porting::path_cache); settings->setDefault("touchscreen_threshold","20"); settings->setDefault("fixed_virtual_joystick", "false"); settings->setDefault("virtual_joystick_triggers_aux", "false"); @@ -486,8 +487,8 @@ void set_default_settings(Settings *settings) settings->setDefault("curl_verify_cert","false"); // Apply settings according to screen size - float x_inches = ((double) porting::getDisplaySize().X / - (160 * porting::getDisplayDensity())); + float x_inches = (float) porting::getDisplaySize().X / + (160.f * porting::getDisplayDensity()); if (x_inches < 3.7f) { settings->setDefault("hud_scaling", "0.6"); @@ -503,8 +504,5 @@ void set_default_settings(Settings *settings) settings->setDefault("mono_font_size", "14"); } // Tablets >= 6.0 use non-Android defaults for these settings -#else - settings->setDefault("screen_dpi", "72"); #endif } - -- cgit v1.2.3 From 0f1f8e4a0fed72f0f2223448f34406eeb26f9b7b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 20 Jun 2020 13:21:38 +0100 Subject: Add warning when disabling secure.enable_security (#9943) --- src/script/scripting_server.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/script/scripting_server.cpp b/src/script/scripting_server.cpp index cbf229640..85411ded4 100644 --- a/src/script/scripting_server.cpp +++ b/src/script/scripting_server.cpp @@ -62,6 +62,10 @@ ServerScripting::ServerScripting(Server* server): if (g_settings->getBool("secure.enable_security")) { initializeSecurity(); + } else { + warningstream << "\\!/ Mod security should never be disabled, as it allows any mod to " + << "access the host machine." + << "Mods should use minetest.request_insecure_environment() instead \\!/" << std::endl; } lua_getglobal(L, "core"); -- cgit v1.2.3 From 4cb18d4874126b384ad5faa1b10a208c8fdce4db Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 22 Jun 2020 14:40:04 +0100 Subject: Fix HTTP API not being available in async mainmenu (#10086) --- src/script/lua_api/l_http.cpp | 7 +++++++ src/script/lua_api/l_http.h | 1 + src/script/scripting_mainmenu.cpp | 1 + 3 files changed, 9 insertions(+) (limited to 'src') diff --git a/src/script/lua_api/l_http.cpp b/src/script/lua_api/l_http.cpp index 73b4586e0..ec43bf174 100644 --- a/src/script/lua_api/l_http.cpp +++ b/src/script/lua_api/l_http.cpp @@ -230,3 +230,10 @@ void ModApiHttp::Initialize(lua_State *L, int top) #endif } + +void ModApiHttp::InitializeAsync(lua_State *L, int top) +{ +#if USE_CURL + API_FCT(get_http_api); +#endif +} diff --git a/src/script/lua_api/l_http.h b/src/script/lua_api/l_http.h index c665235a9..de6e51b37 100644 --- a/src/script/lua_api/l_http.h +++ b/src/script/lua_api/l_http.h @@ -50,4 +50,5 @@ private: public: static void Initialize(lua_State *L, int top); + static void InitializeAsync(lua_State *L, int top); }; diff --git a/src/script/scripting_mainmenu.cpp b/src/script/scripting_mainmenu.cpp index 08858b1a5..0f672f917 100644 --- a/src/script/scripting_mainmenu.cpp +++ b/src/script/scripting_mainmenu.cpp @@ -73,6 +73,7 @@ void MainMenuScripting::initializeModApi(lua_State *L, int top) asyncEngine.registerStateInitializer(registerLuaClasses); asyncEngine.registerStateInitializer(ModApiMainMenu::InitializeAsync); asyncEngine.registerStateInitializer(ModApiUtil::InitializeAsync); + asyncEngine.registerStateInitializer(ModApiHttp::InitializeAsync); // Initialize async environment //TODO possibly make number of async threads configurable -- cgit v1.2.3 From ee6c499ff8b9abf0d22ebc817a26f33322ffdd5b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Wed, 24 Jun 2020 11:35:06 +0200 Subject: Fix wrong use of guiScalingImageButton in formspecs buttons (#10094) --- src/gui/guiButton.cpp | 5 ++--- src/gui/guiButtonImage.cpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index ff35958fd..6732a9233 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -789,13 +789,12 @@ void GUIButton::setFromStyle(const StyleSpec& style) setDrawBorder(style.getBool(StyleSpec::BORDER, true)); setUseAlphaChannel(style.getBool(StyleSpec::ALPHA, true)); - const core::position2di buttonCenter(AbsoluteRect.getCenter()); - core::position2d geom(buttonCenter); if (style.isNotDefault(StyleSpec::BGIMG)) { video::ITexture *texture = style.getTexture(StyleSpec::BGIMG, getTextureSource()); setImage(guiScalingImageButton( - Environment->getVideoDriver(), texture, geom.X, geom.Y)); + Environment->getVideoDriver(), texture, + AbsoluteRect.getWidth(), AbsoluteRect.getHeight())); setScaleImage(true); } else { setImage(nullptr); diff --git a/src/gui/guiButtonImage.cpp b/src/gui/guiButtonImage.cpp index 2658ad967..b507ffece 100644 --- a/src/gui/guiButtonImage.cpp +++ b/src/gui/guiButtonImage.cpp @@ -62,13 +62,12 @@ void GUIButtonImage::setFromStyle(const StyleSpec& style) video::IVideoDriver *driver = Environment->getVideoDriver(); - const core::position2di buttonCenter(AbsoluteRect.getCenter()); - core::position2d geom(buttonCenter); if (style.isNotDefault(StyleSpec::FGIMG)) { video::ITexture *texture = style.getTexture(StyleSpec::FGIMG, getTextureSource()); - setForegroundImage(guiScalingImageButton(driver, texture, geom.X, geom.Y)); + setForegroundImage(guiScalingImageButton(driver, texture, + AbsoluteRect.getWidth(), AbsoluteRect.getHeight())); setScaleImage(true); } else { setForegroundImage(nullptr); -- cgit v1.2.3 From 7be082f9a8bb6bd46c226d7ef4c42f0fd9fe7314 Mon Sep 17 00:00:00 2001 From: hecktest <42101236+hecktest@users.noreply.github.com> Date: Fri, 26 Jun 2020 00:06:29 +0200 Subject: Fix bone-attached entities (#10015) --- src/client/content_cao.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 7f573b5a1..4f949f6b0 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -162,6 +162,15 @@ static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill, matrix.setTextureScale(txs, tys); } +// Evaluate transform chain recursively; irrlicht does not do this for us +static void updatePositionRecursive(scene::ISceneNode *node) +{ + scene::ISceneNode *parent = node->getParent(); + if (parent) + updatePositionRecursive(parent); + node->updateAbsolutePosition(); +} + /* TestCAO */ @@ -929,11 +938,6 @@ void GenericCAO::updateNodePos() void GenericCAO::step(float dtime, ClientEnvironment *env) { - if (m_animated_meshnode) { - m_animated_meshnode->animateJoints(); - updateBonePosition(); - } - // Handle model animations and update positions instantly to prevent lags if (m_is_local_player) { LocalPlayer *player = m_env->getLocalPlayer(); @@ -1143,6 +1147,18 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) rot_translator.val_current = m_rotation; updateNodePos(); } + + if (m_animated_meshnode) { + // Everything must be updated; the whole transform + // chain as well as the animated mesh node. + // Otherwise, bone attachments would be relative to + // a position that's one frame old. + if (m_matrixnode) + updatePositionRecursive(m_matrixnode); + m_animated_meshnode->updateAbsolutePosition(); + m_animated_meshnode->animateJoints(); + updateBonePosition(); + } } void GenericCAO::updateTexturePos() @@ -1444,6 +1460,18 @@ void GenericCAO::updateBonePosition() bone->updateAbsolutePosition(); } } + // The following is needed for set_bone_pos to propagate to + // attached objects correctly. + // Irrlicht ought to do this, but doesn't when using EJUOR_CONTROL. + for (u32 i = 0; i < m_animated_meshnode->getJointCount(); ++i) { + auto bone = m_animated_meshnode->getJointNode(i); + // Look for the root bone. + if (bone && bone->getParent() == m_animated_meshnode) { + // Update entire skeleton. + bone->updateAbsolutePositionOfAllChildren(); + break; + } + } } void GenericCAO::updateAttachments() -- cgit v1.2.3 From da71313e1df3326c2b9ddb410b963ec25682319e Mon Sep 17 00:00:00 2001 From: v-rob Date: Fri, 3 Jul 2020 09:33:23 -0700 Subject: Don't stop style parsing on unknown property (#10143) --- src/gui/guiFormSpecMenu.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 0bb401251..37edf3c4b 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -2562,7 +2562,7 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b << "'" << std::endl; property_warned.insert(propname); } - return false; + continue; } spec.set(prop, value); @@ -2603,7 +2603,7 @@ bool GUIFormSpecMenu::parseStyle(parserData *data, const std::string &element, b } } - if(!state_valid) { + if (!state_valid) { // Skip this selector continue; } -- cgit v1.2.3 From dc6318b84aa8c079330b2adc711113f7d4b55961 Mon Sep 17 00:00:00 2001 From: Paramat Date: Sun, 5 Jul 2020 23:45:21 +0100 Subject: Apply camera smoothing to 'air stepheight' (#10025) Recent changes to collision code have changed the behaviour of the 'touching_ground' bool in movement code. This had the effect of disabling camera smoothing when 'air stepheight' occurred when jumping onto a node while pressing forwards against the node, causing an unpleasant sharp camera movement. Rewrite the conditions for camera smoothing such that it is applied when jumping. --- src/client/camera.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 9b311171a..abc55e4b7 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -342,9 +342,13 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r if (player->getParent()) player_position = player->getParent()->getPosition(); - if(player->touching_ground && - player_position.Y > old_player_position.Y) - { + // Smooth the camera movement when the player instantly moves upward due to stepheight. + // To smooth the 'not touching_ground' stepheight, smoothing is necessary when jumping + // or swimming (for when moving from liquid to land). + // Disable smoothing if climbing or flying, to avoid upwards offset of player model + // when seen in 3rd person view. + bool flying = g_settings->getBool("free_move") && m_client->checkLocalPrivilege("fly"); + if (player_position.Y > old_player_position.Y && !player->is_climbing && !flying) { f32 oldy = old_player_position.Y; f32 newy = player_position.Y; f32 t = std::exp(-23 * frametime); @@ -607,14 +611,11 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r const bool walking = movement_XZ && player->touching_ground; const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid; const bool climbing = movement_Y && player->is_climbing; - if ((walking || swimming || climbing) && - (!g_settings->getBool("free_move") || !m_client->checkLocalPrivilege("fly"))) { + if ((walking || swimming || climbing) && !flying) { // Start animation m_view_bobbing_state = 1; m_view_bobbing_speed = MYMIN(speed.getLength(), 70); - } - else if (m_view_bobbing_state == 1) - { + } else if (m_view_bobbing_state == 1) { // Stop animation m_view_bobbing_state = 2; m_view_bobbing_speed = 60; -- cgit v1.2.3 From 6e4d8de10442eecf71ba36ad015872a135a53338 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 7 Jul 2020 17:50:52 +0100 Subject: Revert "Verify database connection on interval (#9665)" Fixes #10113 This reverts commit 5c588f89e79e02cba392abe3d00688772321f88b. --- src/database/database-postgresql.cpp | 40 +++++++++++++++--------------------- src/database/database-postgresql.h | 8 ++------ src/database/database-sqlite3.cpp | 26 +++++++++++------------ src/database/database-sqlite3.h | 12 +++-------- src/database/database.h | 4 ---- src/map.cpp | 5 ----- src/map.h | 1 - src/serverenvironment.cpp | 5 ----- src/serverenvironment.h | 1 - 9 files changed, 35 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index ca750b466..6acfb5937 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -90,19 +90,13 @@ void Database_PostgreSQL::connectToDatabase() initStatements(); } -void Database_PostgreSQL::pingDatabase() -{ - // Verify DB connection with ping - try { - ping(); - } catch (const DatabaseException &e) { - // If ping failed, show the error and try reconnect - PQreset(m_conn); - - errorstream << e.what() << std::endl - << "Reconnecting to database " << m_connect_string << std::endl; - connectToDatabase(); - } +void Database_PostgreSQL::verifyDatabase() +{ + if (PQstatus(m_conn) == CONNECTION_OK) + return; + + PQreset(m_conn); + ping(); } void Database_PostgreSQL::ping() @@ -157,7 +151,7 @@ void Database_PostgreSQL::createTableIfNotExists(const std::string &table_name, void Database_PostgreSQL::beginSave() { - pingDatabase(); + verifyDatabase(); checkResults(PQexec(m_conn, "BEGIN;")); } @@ -238,7 +232,7 @@ bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) return false; } - pingDatabase(); + verifyDatabase(); s32 x, y, z; x = htonl(pos.X); @@ -262,7 +256,7 @@ bool MapDatabasePostgreSQL::saveBlock(const v3s16 &pos, const std::string &data) void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block) { - pingDatabase(); + verifyDatabase(); s32 x, y, z; x = htonl(pos.X); @@ -286,7 +280,7 @@ void MapDatabasePostgreSQL::loadBlock(const v3s16 &pos, std::string *block) bool MapDatabasePostgreSQL::deleteBlock(const v3s16 &pos) { - pingDatabase(); + verifyDatabase(); s32 x, y, z; x = htonl(pos.X); @@ -304,7 +298,7 @@ bool MapDatabasePostgreSQL::deleteBlock(const v3s16 &pos) void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector &dst) { - pingDatabase(); + verifyDatabase(); PGresult *results = execPrepared("list_all_loadable_blocks", 0, NULL, NULL, NULL, false, false); @@ -446,7 +440,7 @@ void PlayerDatabasePostgreSQL::initStatements() bool PlayerDatabasePostgreSQL::playerDataExists(const std::string &playername) { - pingDatabase(); + verifyDatabase(); const char *values[] = { playername.c_str() }; PGresult *results = execPrepared("load_player", 1, values, false); @@ -462,7 +456,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player) if (!sao) return; - pingDatabase(); + verifyDatabase(); v3f pos = sao->getBasePosition(); std::string pitch = ftos(sao->getLookPitch()); @@ -546,7 +540,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player) bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao) { sanity_check(sao); - pingDatabase(); + verifyDatabase(); const char *values[] = { player->getName() }; PGresult *results = execPrepared("load_player", 1, values, false, false); @@ -621,7 +615,7 @@ bool PlayerDatabasePostgreSQL::removePlayer(const std::string &name) if (!playerDataExists(name)) return false; - pingDatabase(); + verifyDatabase(); const char *values[] = { name.c_str() }; execPrepared("remove_player", 1, values); @@ -631,7 +625,7 @@ bool PlayerDatabasePostgreSQL::removePlayer(const std::string &name) void PlayerDatabasePostgreSQL::listPlayers(std::vector &res) { - pingDatabase(); + verifyDatabase(); PGresult *results = execPrepared("load_player_list", 0, NULL, false); diff --git a/src/database/database-postgresql.h b/src/database/database-postgresql.h index 340f0a7b8..409e62fe0 100644 --- a/src/database/database-postgresql.h +++ b/src/database/database-postgresql.h @@ -32,14 +32,13 @@ public: Database_PostgreSQL(const std::string &connect_string); ~Database_PostgreSQL(); - virtual void pingDatabase(); - void beginSave(); void endSave(); void rollback(); bool initialized() const; + protected: // Conversion helpers inline int pg_to_int(PGresult *res, int row, int col) @@ -84,6 +83,7 @@ protected: } void createTableIfNotExists(const std::string &table_name, const std::string &definition); + void verifyDatabase(); // Database initialization void connectToDatabase(); @@ -114,8 +114,6 @@ public: MapDatabasePostgreSQL(const std::string &connect_string); virtual ~MapDatabasePostgreSQL() = default; - virtual void pingDatabase() { Database_PostgreSQL::pingDatabase(); } - bool saveBlock(const v3s16 &pos, const std::string &data); void loadBlock(const v3s16 &pos, std::string *block); bool deleteBlock(const v3s16 &pos); @@ -135,8 +133,6 @@ public: PlayerDatabasePostgreSQL(const std::string &connect_string); virtual ~PlayerDatabasePostgreSQL() = default; - virtual void pingDatabase() { Database_PostgreSQL::pingDatabase(); } - void savePlayer(RemotePlayer *player); bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); bool removePlayer(const std::string &name); diff --git a/src/database/database-sqlite3.cpp b/src/database/database-sqlite3.cpp index 116096f68..4560743b9 100644 --- a/src/database/database-sqlite3.cpp +++ b/src/database/database-sqlite3.cpp @@ -121,7 +121,7 @@ Database_SQLite3::Database_SQLite3(const std::string &savedir, const std::string void Database_SQLite3::beginSave() { - pingDatabase(); + verifyDatabase(); SQLRES(sqlite3_step(m_stmt_begin), SQLITE_DONE, "Failed to start SQLite3 transaction"); sqlite3_reset(m_stmt_begin); @@ -129,7 +129,7 @@ void Database_SQLite3::beginSave() void Database_SQLite3::endSave() { - pingDatabase(); + verifyDatabase(); SQLRES(sqlite3_step(m_stmt_end), SQLITE_DONE, "Failed to commit SQLite3 transaction"); sqlite3_reset(m_stmt_end); @@ -171,7 +171,7 @@ void Database_SQLite3::openDatabase() "Failed to enable sqlite3 foreign key support"); } -void Database_SQLite3::pingDatabase() +void Database_SQLite3::verifyDatabase() { if (m_initialized) return; @@ -247,7 +247,7 @@ inline void MapDatabaseSQLite3::bindPos(sqlite3_stmt *stmt, const v3s16 &pos, in bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) { - pingDatabase(); + verifyDatabase(); bindPos(m_stmt_delete, pos); @@ -263,7 +263,7 @@ bool MapDatabaseSQLite3::deleteBlock(const v3s16 &pos) bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) { - pingDatabase(); + verifyDatabase(); #ifdef __ANDROID__ /** @@ -290,7 +290,7 @@ bool MapDatabaseSQLite3::saveBlock(const v3s16 &pos, const std::string &data) void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) { - pingDatabase(); + verifyDatabase(); bindPos(m_stmt_read, pos); @@ -311,7 +311,7 @@ void MapDatabaseSQLite3::loadBlock(const v3s16 &pos, std::string *block) void MapDatabaseSQLite3::listAllLoadableBlocks(std::vector &dst) { - pingDatabase(); + verifyDatabase(); while (sqlite3_step(m_stmt_list) == SQLITE_ROW) dst.push_back(getIntegerAsBlock(sqlite3_column_int64(m_stmt_list, 0))); @@ -439,7 +439,7 @@ void PlayerDatabaseSQLite3::initStatements() bool PlayerDatabaseSQLite3::playerDataExists(const std::string &name) { - pingDatabase(); + verifyDatabase(); str_to_sqlite(m_stmt_player_load, 1, name); bool res = (sqlite3_step(m_stmt_player_load) == SQLITE_ROW); sqlite3_reset(m_stmt_player_load); @@ -536,7 +536,7 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player) bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao) { - pingDatabase(); + verifyDatabase(); str_to_sqlite(m_stmt_player_load, 1, player->getName()); if (sqlite3_step(m_stmt_player_load) != SQLITE_ROW) { @@ -600,7 +600,7 @@ bool PlayerDatabaseSQLite3::removePlayer(const std::string &name) void PlayerDatabaseSQLite3::listPlayers(std::vector &res) { - pingDatabase(); + verifyDatabase(); while (sqlite3_step(m_stmt_player_list) == SQLITE_ROW) res.push_back(sqlite_to_string(m_stmt_player_list, 0)); @@ -673,7 +673,7 @@ void AuthDatabaseSQLite3::initStatements() bool AuthDatabaseSQLite3::getAuth(const std::string &name, AuthEntry &res) { - pingDatabase(); + verifyDatabase(); str_to_sqlite(m_stmt_read, 1, name); if (sqlite3_step(m_stmt_read) != SQLITE_ROW) { sqlite3_reset(m_stmt_read); @@ -735,7 +735,7 @@ bool AuthDatabaseSQLite3::createAuth(AuthEntry &authEntry) bool AuthDatabaseSQLite3::deleteAuth(const std::string &name) { - pingDatabase(); + verifyDatabase(); str_to_sqlite(m_stmt_delete, 1, name); sqlite3_vrfy(sqlite3_step(m_stmt_delete), SQLITE_DONE); @@ -749,7 +749,7 @@ bool AuthDatabaseSQLite3::deleteAuth(const std::string &name) void AuthDatabaseSQLite3::listNames(std::vector &res) { - pingDatabase(); + verifyDatabase(); while (sqlite3_step(m_stmt_list_names) == SQLITE_ROW) { res.push_back(sqlite_to_string(m_stmt_list_names, 0)); diff --git a/src/database/database-sqlite3.h b/src/database/database-sqlite3.h index 647eddf7a..d7202a918 100644 --- a/src/database/database-sqlite3.h +++ b/src/database/database-sqlite3.h @@ -36,13 +36,13 @@ public: void beginSave(); void endSave(); - // Open and initialize the database if needed - virtual void pingDatabase(); - bool initialized() const { return m_initialized; } protected: Database_SQLite3(const std::string &savedir, const std::string &dbname); + // Open and initialize the database if needed + void verifyDatabase(); + // Convertors inline void str_to_sqlite(sqlite3_stmt *s, int iCol, const std::string &str) const { @@ -146,8 +146,6 @@ public: MapDatabaseSQLite3(const std::string &savedir); virtual ~MapDatabaseSQLite3(); - virtual void pingDatabase() { Database_SQLite3::pingDatabase(); } - bool saveBlock(const v3s16 &pos, const std::string &data); void loadBlock(const v3s16 &pos, std::string *block); bool deleteBlock(const v3s16 &pos); @@ -175,8 +173,6 @@ public: PlayerDatabaseSQLite3(const std::string &savedir); virtual ~PlayerDatabaseSQLite3(); - virtual void pingDatabase() { Database_SQLite3::pingDatabase(); } - void savePlayer(RemotePlayer *player); bool loadPlayer(RemotePlayer *player, PlayerSAO *sao); bool removePlayer(const std::string &name); @@ -212,8 +208,6 @@ public: AuthDatabaseSQLite3(const std::string &savedir); virtual ~AuthDatabaseSQLite3(); - virtual void pingDatabase() { Database_SQLite3::pingDatabase(); } - virtual bool getAuth(const std::string &name, AuthEntry &res); virtual bool saveAuth(const AuthEntry &authEntry); virtual bool createAuth(AuthEntry &authEntry); diff --git a/src/database/database.h b/src/database/database.h index 47605a07e..b7d551935 100644 --- a/src/database/database.h +++ b/src/database/database.h @@ -32,7 +32,6 @@ public: virtual void beginSave() = 0; virtual void endSave() = 0; virtual bool initialized() const { return true; } - virtual void pingDatabase() {} }; class MapDatabase : public Database @@ -58,8 +57,6 @@ class PlayerDatabase public: virtual ~PlayerDatabase() = default; - virtual void pingDatabase() {} - virtual void savePlayer(RemotePlayer *player) = 0; virtual bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) = 0; virtual bool removePlayer(const std::string &name) = 0; @@ -86,5 +83,4 @@ public: virtual bool deleteAuth(const std::string &name) = 0; virtual void listNames(std::vector &res) = 0; virtual void reload() = 0; - virtual void pingDatabase() {} }; diff --git a/src/map.cpp b/src/map.cpp index 7c776b070..b9ab7c066 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1907,11 +1907,6 @@ MapDatabase *ServerMap::createDatabase( throw BaseException(std::string("Database backend ") + name + " not supported."); } -void ServerMap::pingDatabase() -{ - dbase->pingDatabase(); -} - void ServerMap::beginSave() { dbase->beginSave(); diff --git a/src/map.h b/src/map.h index 77ee4da9e..4d9847063 100644 --- a/src/map.h +++ b/src/map.h @@ -387,7 +387,6 @@ public: Database functions */ static MapDatabase *createDatabase(const std::string &name, const std::string &savedir, Settings &conf); - void pingDatabase(); // Call these before and after saving of blocks void beginSave(); diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 2c6a39ee3..ad2ffc9a4 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -1228,11 +1228,6 @@ void ServerEnvironment::step(float dtime) } } - if (m_database_check_interval.step(dtime, 10.0f)) { - m_auth_database->pingDatabase(); - m_player_database->pingDatabase(); - m_map->pingDatabase(); - } /* Manage active block list */ diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 4b453d39a..af742e290 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -436,7 +436,6 @@ private: IntervalLimiter m_object_management_interval; // List of active blocks ActiveBlockList m_active_blocks; - IntervalLimiter m_database_check_interval; IntervalLimiter m_active_blocks_management_interval; IntervalLimiter m_active_block_modifier_interval; IntervalLimiter m_active_blocks_nodemetadata_interval; -- cgit v1.2.3 From ebb721a476ada0350b73fe44efa66850397b9e96 Mon Sep 17 00:00:00 2001 From: TheTermos <55103816+TheTermos@users.noreply.github.com> Date: Fri, 3 Jul 2020 17:21:42 +0200 Subject: Fix player controls only being applied for the first move --- src/client/client.cpp | 5 +---- src/client/clientenvironment.cpp | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/client/client.cpp b/src/client/client.cpp index 34f97a9de..65e5b3d8c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -459,12 +459,9 @@ void Client::step(float dtime) /* Handle environment */ - // Control local player (0ms) LocalPlayer *player = m_env.getLocalPlayer(); - assert(player); - player->applyControl(dtime, &m_env); - // Step environment + // Step environment (also handles player controls) m_env.step(dtime); m_sound->step(dtime); diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 44ea1e4a1..895b0193c 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -216,6 +216,9 @@ void ClientEnvironment::step(float dtime) */ { + // Control local player + lplayer->applyControl(dtime_part, this); + // Apply physics if (!free_move && !is_climbing) { // Gravity -- cgit v1.2.3 From 42b0d612ef488dd5b4836fa303aeebe424f09e92 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 7 Jul 2020 19:30:35 +0100 Subject: Fix build due to revert error --- src/database/database-postgresql.cpp | 10 +++++----- src/database/database-postgresql.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/database/database-postgresql.cpp b/src/database/database-postgresql.cpp index 6acfb5937..e1bb39928 100644 --- a/src/database/database-postgresql.cpp +++ b/src/database/database-postgresql.cpp @@ -678,7 +678,7 @@ void AuthDatabasePostgreSQL::initStatements() bool AuthDatabasePostgreSQL::getAuth(const std::string &name, AuthEntry &res) { - pingDatabase(); + verifyDatabase(); const char *values[] = { name.c_str() }; PGresult *result = execPrepared("auth_read", 1, values, false, false); @@ -710,7 +710,7 @@ bool AuthDatabasePostgreSQL::getAuth(const std::string &name, AuthEntry &res) bool AuthDatabasePostgreSQL::saveAuth(const AuthEntry &authEntry) { - pingDatabase(); + verifyDatabase(); beginSave(); @@ -732,7 +732,7 @@ bool AuthDatabasePostgreSQL::saveAuth(const AuthEntry &authEntry) bool AuthDatabasePostgreSQL::createAuth(AuthEntry &authEntry) { - pingDatabase(); + verifyDatabase(); std::string lastLoginStr = itos(authEntry.last_login); const char *values[] = { @@ -764,7 +764,7 @@ bool AuthDatabasePostgreSQL::createAuth(AuthEntry &authEntry) bool AuthDatabasePostgreSQL::deleteAuth(const std::string &name) { - pingDatabase(); + verifyDatabase(); const char *values[] = { name.c_str() }; execPrepared("auth_delete", 1, values); @@ -775,7 +775,7 @@ bool AuthDatabasePostgreSQL::deleteAuth(const std::string &name) void AuthDatabasePostgreSQL::listNames(std::vector &res) { - pingDatabase(); + verifyDatabase(); PGresult *results = execPrepared("auth_list_names", 0, NULL, NULL, NULL, false, false); diff --git a/src/database/database-postgresql.h b/src/database/database-postgresql.h index 409e62fe0..f47deda33 100644 --- a/src/database/database-postgresql.h +++ b/src/database/database-postgresql.h @@ -152,7 +152,7 @@ public: AuthDatabasePostgreSQL(const std::string &connect_string); virtual ~AuthDatabasePostgreSQL() = default; - virtual void pingDatabase() { Database_PostgreSQL::pingDatabase(); } + virtual void verifyDatabase() { Database_PostgreSQL::verifyDatabase(); } virtual bool getAuth(const std::string &name, AuthEntry &res); virtual bool saveAuth(const AuthEntry &authEntry); -- cgit v1.2.3 From 70df3d54f37c280f7afe60f6e964b8406577f39f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 9 Jul 2020 22:01:46 +0200 Subject: Quick workaround for crashing destructor on Mingw32 closes #10137 --- src/script/common/c_converter.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index de0cdfbf4..eb6ab5331 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -457,9 +457,17 @@ size_t read_stringlist(lua_State *L, int index, std::vector *result Table field getters */ +#if defined(__MINGW32__) && !defined(__MINGW64__) +/* MinGW 32-bit somehow crashes in the std::set destructor when this + * variable is thread-local, so just don't do that. */ +static std::set warned_msgs; +#endif + bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname) { - static thread_local std::set warned_msgs; +#if !defined(__MINGW32__) || defined(__MINGW64__) + thread_local std::set warned_msgs; +#endif int t = lua_type(L, index); if (t == LUA_TNIL) -- cgit v1.2.3 From b1ff04e06da531dc52f6ee91e2967b39743033e6 Mon Sep 17 00:00:00 2001 From: v-rob Date: Fri, 10 Jul 2020 03:11:26 -0700 Subject: Formspec: Make dropdowns optionally return event based on index, not value (#9496) --- doc/lua_api.txt | 15 ++++++++++++--- src/gui/guiFormSpecMenu.cpp | 39 +++++++++++++++++++++++---------------- src/gui/guiFormSpecMenu.h | 1 + src/network/networkprotocol.h | 4 +++- 4 files changed, 39 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index f2a83eca5..2ac4d6766 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2443,7 +2443,7 @@ Elements * `color` is color specified as a `ColorString`. If the alpha component is left blank, the box will be semitransparent. -### `dropdown[,;;;,, ...,;]` +### `dropdown[,;;;,, ...,;;]` * Show a dropdown field * **Important note**: There are two different operation modes: @@ -2454,8 +2454,12 @@ Elements * Fieldname data is transferred to Lua * Items to be shown in dropdown * Index of currently selected dropdown item +* `index event` (optional, allowed parameter since formspec version 4): Specifies the + event field value for selected items. + * `true`: Selected item index + * `false` (default): Selected item value -### `dropdown[,;,;;,, ...,;]` +### `dropdown[,;,;;,, ...,;;]` * Show a dropdown field * **Important note**: This syntax for dropdowns can only be used with the @@ -2468,6 +2472,10 @@ Elements * Fieldname data is transferred to Lua * Items to be shown in dropdown * Index of currently selected dropdown item +* `index event` (optional, allowed parameter since formspec version 4): Specifies the + event field value for selected items. + * `true`: Selected item index + * `false` (default): Selected item value ### `checkbox[,;;