1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Merge branch 'minetest:master' into master

This commit is contained in:
DustyBagel 2024-07-04 22:28:34 -05:00 committed by GitHub
commit a8163f6d25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 319 additions and 76 deletions

View file

@ -3987,8 +3987,12 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
runData.nodig_delay_timer =
runData.dig_time_complete / (float)crack_animation_length;
// Don't add a corresponding delay to very time consuming nodes.
runData.nodig_delay_timer = std::min(runData.nodig_delay_timer, 0.3f);
// We don't want a corresponding delay to very time consuming nodes
// and nodes without digging time (e.g. torches) get a fixed delay.
if (runData.nodig_delay_timer > 0.3f)
runData.nodig_delay_timer = 0.3f;
else if (runData.dig_instantly)
runData.nodig_delay_timer = 0.15f;
// Ensure that the delay between breaking nodes
// (dig_time_complete + nodig_delay_timer) is at least the
@ -4392,8 +4396,8 @@ void Game::readSettings()
m_cache_enable_fog = g_settings->getBool("enable_fog");
m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f);
m_cache_joystick_frustum_sensitivity = std::max(g_settings->getFloat("joystick_frustum_sensitivity"), 0.001f);
m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.15f, 2.0f);
m_repeat_dig_time = g_settings->getFloat("repeat_dig_time", 0.15f, 2.0f);
m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.16f, 2.0f);
m_repeat_dig_time = g_settings->getFloat("repeat_dig_time", 0.0f, 2.0f);
m_cache_enable_noclip = g_settings->getBool("noclip");
m_cache_enable_free_move = g_settings->getBool("free_move");

View file

@ -359,7 +359,7 @@ void set_default_settings()
settings->setDefault("invert_hotbar_mouse_wheel", "false");
settings->setDefault("mouse_sensitivity", "0.2");
settings->setDefault("repeat_place_time", "0.25");
settings->setDefault("repeat_dig_time", "0.15");
settings->setDefault("repeat_dig_time", "0.0");
settings->setDefault("safe_dig_and_place", "false");
settings->setDefault("random_input", "false");
settings->setDefault("aux1_descends", "false");

View file

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUIFont.h>
#include "client/renderingengine.h"
#include "debug.h"
#include "irrlicht_changes/CGUITTFont.h"
#include "log.h"
#include "client/texturesource.h"
#include "gettime.h"
@ -227,6 +228,8 @@ void GUITable::setTable(const TableOptions &options,
s32 content_index;
// Next cell: Width in pixels
s32 content_width;
// Next cell: Image scale (only for "image" column type)
f32 image_scale;
// Vector of completed cells in this row
std::vector<Cell> cells;
// Stores colors and how long they last (maximum column index)
@ -236,6 +239,17 @@ void GUITable::setTable(const TableOptions &options,
};
TempRow *rows = new TempRow[rowcount];
CGUITTFont *ttfont = dynamic_cast<CGUITTFont *>(m_font);
f32 desired_image_scale = 1.0f;
if (ttfont) {
// This gives us the effective font size, which is chosen taking display
// density and gui_scaling into account.
// Since row height scales with font size, this gives better results than
// just using display density and gui_scaling when a non-standard font
// size is used (e.g. Android default of 14).
desired_image_scale = std::max(1.0f, ttfont->getFontSize() / 16.0f);
}
// Get em width. Pedantically speaking, the width of "M" is not
// necessarily the same as the em width, but whatever, close enough.
s32 em = 6;
@ -373,8 +387,18 @@ void GUITable::setTable(const TableOptions &options,
if (row->content_index >= 0)
image = m_images[row->content_index];
row->image_scale = 1.0f;
row->content_width = 0;
if (image) {
f32 max_image_scale = (f32)m_rowheight / (f32)image->getOriginalSize().Height;
// Scale with display density and make sure it fits into the row
row->image_scale = std::min(desired_image_scale, max_image_scale);
// When upscaling, fractional factors would cause artifacts
if (row->image_scale > 1.0f)
row->image_scale = std::floor(row->image_scale);
row->content_width = image->getOriginalSize().Width * row->image_scale;
}
// Get content width and update xmax
row->content_width = image ? image->getOriginalSize().Width : 0;
row->content_width = MYMAX(row->content_width, width);
s32 row_xmax = row->x + padding + row->content_width;
xmax = MYMAX(xmax, row_xmax);
@ -384,6 +408,7 @@ void GUITable::setTable(const TableOptions &options,
newcell.xmin = rows[i].x + padding;
alignContent(&newcell, xmax, rows[i].content_width, align);
newcell.content_index = rows[i].content_index;
newcell.image_scale = rows[i].image_scale;
rows[i].cells.push_back(newcell);
rows[i].x = newcell.xmax;
}
@ -740,23 +765,23 @@ void GUITable::drawCell(const Cell *cell, video::SColor color,
video::ITexture *image = m_images[cell->content_index];
if (image) {
core::position2d<s32> dest_pos =
row_rect.UpperLeftCorner;
dest_pos.X += cell->xpos;
core::rect<s32> source_rect(
core::position2d<s32>(0, 0),
image->getOriginalSize());
s32 imgh = source_rect.LowerRightCorner.Y;
core::rect<s32> dest_rect(
0, 0,
image->getOriginalSize().Width * cell->image_scale,
image->getOriginalSize().Height * cell->image_scale);
dest_rect += row_rect.UpperLeftCorner + v2s32(cell->xpos, 0);
s32 imgh = dest_rect.getHeight();
s32 rowh = row_rect.getHeight();
// Center vertically if needed
if (imgh < rowh)
dest_pos.Y += (rowh - imgh) / 2;
else
source_rect.LowerRightCorner.Y = rowh;
dest_rect += v2s32(0, (rowh - imgh) / 2);
video::SColor color(255, 255, 255, 255);
driver->draw2DImage(image, dest_pos, source_rect,
&client_clip, color, true);
driver->draw2DImage(image, dest_rect, source_rect,
&client_clip, nullptr, true);
}
}
}

View file

@ -166,6 +166,7 @@ protected:
video::SColor color;
bool color_defined;
s32 reported_column;
f32 image_scale; // only for "image" type columns
};
struct Row {

View file

@ -59,14 +59,8 @@ GUIModalMenu::GUIModalMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent,
m_menumgr(menumgr),
m_remap_click_outside(remap_click_outside)
{
m_gui_scale = std::max(g_settings->getFloat("gui_scaling"), 0.5f);
const float screen_dpi_scale = RenderingEngine::getDisplayDensity();
if (g_settings->getBool("enable_touch")) {
m_gui_scale *= 1.1f - 0.3f * screen_dpi_scale + 0.2f * screen_dpi_scale * screen_dpi_scale;
} else {
m_gui_scale *= screen_dpi_scale;
}
m_gui_scale = g_settings->getFloat("gui_scaling", 0.5f, 20.0f) *
RenderingEngine::getDisplayDensity();
setVisible(true);
m_menumgr->createdMenu(this);

View file

@ -197,7 +197,8 @@ enum class ParticleTextureFlags : u8 {
* decltype everywhere */
using FlagT = std::underlying_type_t<ParticleTextureFlags>;
void ServerParticleTexture::serialize(std::ostream &os, u16 protocol_ver, bool newPropertiesOnly) const
void ServerParticleTexture::serialize(std::ostream &os, u16 protocol_ver,
bool newPropertiesOnly, bool skipAnimation) const
{
/* newPropertiesOnly is used to de/serialize parameters of the legacy texture
* field, which are encoded separately from the texspec string */
@ -213,14 +214,19 @@ void ServerParticleTexture::serialize(std::ostream &os, u16 protocol_ver, bool n
if (!newPropertiesOnly)
os << serializeString32(string);
if (animated)
if (!skipAnimation && animated)
animation.serialize(os, protocol_ver);
}
void ServerParticleTexture::deSerialize(std::istream &is, u16 protocol_ver, bool newPropertiesOnly)
void ServerParticleTexture::deSerialize(std::istream &is, u16 protocol_ver,
bool newPropertiesOnly, bool skipAnimation)
{
FlagT flags = 0;
deSerializeParameterValue(is, flags);
// new texture properties were missing in ParticleParameters::serialize
// before Minetest 5.9.0
if (is.eof())
return;
animated = !!(flags & FlagT(ParticleTextureFlags::animated));
blendmode = BlendMode((flags & FlagT(ParticleTextureFlags::blend)) >> 1);
@ -230,7 +236,7 @@ void ServerParticleTexture::deSerialize(std::istream &is, u16 protocol_ver, bool
if (!newPropertiesOnly)
string = deSerializeString32(is);
if (animated)
if (!skipAnimation && animated)
animation.deSerialize(is, protocol_ver);
}
@ -254,6 +260,7 @@ void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const
writeV3F32(os, drag);
jitter.serialize(os);
bounce.serialize(os);
texture.serialize(os, protocol_ver, true, true);
}
template <typename T, T (reader)(std::istream& is)>
@ -291,4 +298,5 @@ void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver)
return;
jitter.deSerialize(is);
bounce.deSerialize(is);
texture.deSerialize(is, protocol_ver, true, true);
}

View file

@ -276,8 +276,10 @@ struct ParticleTexture
struct ServerParticleTexture : public ParticleTexture
{
std::string string;
void serialize(std::ostream &os, u16 protocol_ver, bool newPropertiesOnly = false) const;
void deSerialize(std::istream &is, u16 protocol_ver, bool newPropertiesOnly = false);
void serialize(std::ostream &os, u16 protocol_ver, bool newPropertiesOnly = false,
bool skipAnimation = false) const;
void deSerialize(std::istream &is, u16 protocol_ver, bool newPropertiesOnly = false,
bool skipAnimation = false);
};
struct CommonParticleParams

View file

@ -760,7 +760,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
f.setDefaultAlphaMode();
warn_if_field_exists(L, index, "alpha",
warn_if_field_exists(L, index, "alpha", "node " + f.name,
"Obsolete, only limited compatibility provided; "
"replaced by \"use_texture_alpha\"");
if (getintfield_default(L, index, "alpha", 255) != 255)
@ -768,7 +768,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
lua_getfield(L, index, "use_texture_alpha");
if (lua_isboolean(L, -1)) {
warn_if_field_exists(L, index, "use_texture_alpha",
warn_if_field_exists(L, index, "use_texture_alpha", "node " + f.name,
"Boolean values are deprecated; use the new choices");
if (lua_toboolean(L, -1))
f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND;
@ -1315,13 +1315,16 @@ void pushnode(lua_State *L, const MapNode &n)
}
/******************************************************************************/
void warn_if_field_exists(lua_State *L, int table,
const char *name, const std::string &message)
void warn_if_field_exists(lua_State *L, int table, const char *fieldname,
std::string_view name, std::string_view message)
{
lua_getfield(L, table, name);
lua_getfield(L, table, fieldname);
if (!lua_isnil(L, -1)) {
warningstream << "Field \"" << name << "\": "
<< message << std::endl;
warningstream << "Field \"" << fieldname << "\"";
if (!name.empty()) {
warningstream << " on " << name;
}
warningstream << ": " << message << std::endl;
infostream << script_get_backtrace(L) << std::endl;
}
lua_pop(L, 1);

View file

@ -120,7 +120,8 @@ void push_aabb3f_vector (lua_State *L, const std::vector<aabb3f>
void warn_if_field_exists(lua_State *L, int table,
const char *fieldname,
const std::string &message);
std::string_view name,
std::string_view message);
size_t write_array_slice_float(lua_State *L, int table_index, float *data,
v3u16 data_size, v3u16 slice_offset, v3u16 slice_size);

View file

@ -155,6 +155,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p,
int LuaRaycast::l_next(lua_State *L)
{
GET_PLAIN_ENV_PTR;
ServerEnvironment *senv = dynamic_cast<ServerEnvironment*>(env);
bool csm = false;
#ifndef SERVER
@ -163,7 +164,17 @@ int LuaRaycast::l_next(lua_State *L)
LuaRaycast *o = checkObject<LuaRaycast>(L, 1);
PointedThing pointed;
env->continueRaycast(&o->state, &pointed);
for (;;) {
env->continueRaycast(&o->state, &pointed);
if (pointed.type != POINTEDTHING_OBJECT)
break;
if (!senv)
break;
const auto *obj = senv->getActiveObject(pointed.object_id);
if (obj && !obj->isGone())
break;
// skip gone object
}
if (pointed.type == POINTEDTHING_NOTHING)
lua_pushnil(L);
else

View file

@ -1354,7 +1354,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->flags = 0;
//// Get noise_threshold
warn_if_field_exists(L, index, "noise_threshhold",
warn_if_field_exists(L, index, "noise_threshhold", "ore " + ore->name,
"Deprecated: new name is \"noise_threshold\".");
float nthresh;
@ -1364,9 +1364,9 @@ int ModApiMapgen::l_register_ore(lua_State *L)
ore->nthresh = nthresh;
//// Get y_min/y_max
warn_if_field_exists(L, index, "height_min",
warn_if_field_exists(L, index, "height_min", "ore " + ore->name,
"Deprecated: new name is \"y_min\".");
warn_if_field_exists(L, index, "height_max",
warn_if_field_exists(L, index, "height_max", "ore " + ore->name,
"Deprecated: new name is \"y_max\".");
int ymin, ymax;

View file

@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_object.h"
#include <cmath>
#include <lua.h>
#include "lua_api/l_internal.h"
#include "lua_api/l_inventory.h"
#include "lua_api/l_item.h"
@ -106,6 +107,13 @@ int ObjectRef::l_remove(lua_State *L)
return 0;
}
// is_valid(self)
int ObjectRef::l_is_valid(lua_State *L)
{
lua_pushboolean(L, getobject(checkObject<ObjectRef>(L, 1)) != nullptr);
return 1;
}
// get_pos(self)
int ObjectRef::l_get_pos(lua_State *L)
{
@ -2646,6 +2654,7 @@ const char ObjectRef::className[] = "ObjectRef";
luaL_Reg ObjectRef::methods[] = {
// ServerActiveObject
luamethod(ObjectRef, remove),
luamethod(ObjectRef, is_valid),
luamethod_aliased(ObjectRef, get_pos, getpos),
luamethod_aliased(ObjectRef, set_pos, setpos),
luamethod(ObjectRef, add_pos),

View file

@ -67,6 +67,9 @@ private:
// remove(self)
static int l_remove(lua_State *L);
// is_valid(self)
static int l_is_valid(lua_State *L);
// get_pos(self)
static int l_get_pos(lua_State *L);