From 8164a16db830ee1a22ab2bd922c664a43fb95dcb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 19 Jul 2026 19:41:52 +0300 Subject: [PATCH 1/5] add counter-based manual gc trigger for FFIBytearray --- res/modules/internal/bytearray.lua | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/res/modules/internal/bytearray.lua b/res/modules/internal/bytearray.lua index 739bb7cea..bc0907869 100644 --- a/res/modules/internal/bytearray.lua +++ b/res/modules/internal/bytearray.lua @@ -12,18 +12,34 @@ FFI.cdef[[ } bytearray_t; ]] -local malloc = FFI.C.malloc -local free = FFI.C.free local FFIBytearray local bytearray_type +local allocated_bytes = 0 +local GC_THRESHOLD = 50 * 1024 * 1024 + +local function malloc(size) + local raw = FFI.C.malloc(size) + if raw == nil then + return nil + end + + allocated_bytes = allocated_bytes + size + + if allocated_bytes >= GC_THRESHOLD then + collectgarbage("step", 200) + allocated_bytes = 0 + end + + return FFI.gc(raw, FFI.C.free) +end + local function grow_buffer(self, elems) local new_capacity = math.ceil(self.capacity / 0.75 + elems) local prev = self.bytes self.bytes = malloc(new_capacity) FFI.copy(self.bytes, prev, self.size) self.capacity = new_capacity - free(prev) end local function trim_buffer(self) @@ -35,7 +51,6 @@ local function trim_buffer(self) self.bytes = malloc(size) FFI.copy(self.bytes, prev, self.size) self.capacity = size - free(prev) end local function count_elements(b) @@ -114,7 +129,6 @@ local function reserve(self, new_capacity) self.bytes = malloc(new_capacity) FFI.copy(self.bytes, prev, self.size) self.capacity = new_capacity - free(prev) end local function get_capacity(self) @@ -173,9 +187,7 @@ local bytearray_mt = { __len = function(self) return tonumber(self.size) end, - __gc = function(self) - free(self.bytes) - end, + __gc = function(self) end, __ipairs = function(self) local i = 0 return function() From 46b4aab6dce9e7c195b5c29584168f8e5b8fbb52 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 19 Jul 2026 22:20:23 +0300 Subject: [PATCH 2/5] fix newly created raycast bug --- src/voxels/blocks_agent.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/voxels/blocks_agent.cpp b/src/voxels/blocks_agent.cpp index 9d1f0cc17..d72ddcceb 100644 --- a/src/voxels/blocks_agent.cpp +++ b/src/voxels/blocks_agent.cpp @@ -309,7 +309,9 @@ static inline voxel* raycast_blocks( } else { iend = {ix, iy, iz}; norm = {0, 0, 0}; - norm[steppedIndex] = -step[steppedIndex]; + if (steppedIndex != -1) { + norm[steppedIndex] = -step[steppedIndex]; + } return voxel; } } From 8e719eace65bae6578849fd57c50895c19d0f05f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 19 Jul 2026 22:43:50 +0300 Subject: [PATCH 3/5] add missing inventory function --- doc/en/scripting/builtins/libinventory.md | 14 +++++++++++++- doc/ru/scripting/builtins/libinventory.md | 16 ++++++++++++++-- src/items/ItemStack.hpp | 10 ++++++++++ src/logic/scripting/lua/libs/libinventory.cpp | 9 +++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/doc/en/scripting/builtins/libinventory.md b/doc/en/scripting/builtins/libinventory.md index 8cf2d7c3e..172ec63e6 100644 --- a/doc/en/scripting/builtins/libinventory.md +++ b/doc/en/scripting/builtins/libinventory.md @@ -162,7 +162,19 @@ inventory.get_all_data( invid: int, -- slot index slot: int, -) -> table +) -> table | nil + +-- Sets the values ​​of all local item properties. +inventory.set_all_data( + -- inventory id + invid: int, + -- slot index + slot: int, + -- property:value table + fields: table, + -- clear other property values + [optional] clear: boolean = false +) ``` ```lua diff --git a/doc/ru/scripting/builtins/libinventory.md b/doc/ru/scripting/builtins/libinventory.md index 50ed8dccb..4a836f83b 100644 --- a/doc/ru/scripting/builtins/libinventory.md +++ b/doc/ru/scripting/builtins/libinventory.md @@ -170,7 +170,19 @@ inventory.get_all_data( invid: int, -- индекс слота slot: int, -) -> table +) -> table | nil + +-- Устанавливает значения локальных cвойств предмета. +inventory.set_all_data( + -- id инвентаря + invid: int, + -- индекс слота + slot: int, + -- таблица cвойство:значение + fields: table, + -- удалить остальные значения свойств + [опционально] clear: boolean = false +) ``` ```lua @@ -222,4 +234,4 @@ inventory.use( -- индекс слота slot: int ) -``` \ No newline at end of file +``` diff --git a/src/items/ItemStack.hpp b/src/items/ItemStack.hpp index 91f2d3e74..4896bc39e 100644 --- a/src/items/ItemStack.hpp +++ b/src/items/ItemStack.hpp @@ -55,6 +55,16 @@ public: return fields; } + void setFields(dv::value&& table, bool clear) { + if (clear) { + fields = std::move(table); + return; + } + for (auto&& [key, value] : table.asObject()) { + fields[std::move(key)] = std::move(value); + } + } + bool hasFields() const { return fields != nullptr; } diff --git a/src/logic/scripting/lua/libs/libinventory.cpp b/src/logic/scripting/lua/libs/libinventory.cpp index 3ec9d2ca3..2aea52394 100644 --- a/src/logic/scripting/lua/libs/libinventory.cpp +++ b/src/logic/scripting/lua/libs/libinventory.cpp @@ -237,6 +237,14 @@ static int l_get_all_data(lua::State* L, ItemStack& stack) { return lua::pushvalue(L, stack.getFields()); } +static int l_set_all_data(lua::State* L, ItemStack& stack) { + if (!lua::istable(L, 3)) { + throw std::runtime_error("table expected as argument 1"); + } + stack.setFields(lua::tovalue(L, 3), lua::toboolean(L, 4)); + return 0; +} + static int l_has_data(lua::State* L, ItemStack& stack) { auto key = lua::tostring(L, 3); if (key == nullptr) { @@ -267,6 +275,7 @@ const luaL_Reg inventorylib[] = { {"get_data", lua::wrap>}, {"set_data", lua::wrap>}, {"get_all_data", lua::wrap>}, + {"set_all_data", lua::wrap>}, {"has_data", lua::wrap>}, {"create", lua::wrap}, {"remove", lua::wrap}, From d55b494bb0a2c21e3f95f4f232c51ff1509abf20 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 20 Jul 2026 00:05:50 +0300 Subject: [PATCH 4/5] update bytearray,lua --- res/modules/internal/bytearray.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/res/modules/internal/bytearray.lua b/res/modules/internal/bytearray.lua index bc0907869..58b33a520 100644 --- a/res/modules/internal/bytearray.lua +++ b/res/modules/internal/bytearray.lua @@ -12,6 +12,8 @@ FFI.cdef[[ } bytearray_t; ]] +local free = FFI.C.free + local FFIBytearray local bytearray_type @@ -31,7 +33,7 @@ local function malloc(size) allocated_bytes = 0 end - return FFI.gc(raw, FFI.C.free) + return raw end local function grow_buffer(self, elems) @@ -40,6 +42,7 @@ local function grow_buffer(self, elems) self.bytes = malloc(new_capacity) FFI.copy(self.bytes, prev, self.size) self.capacity = new_capacity + free(prev) end local function trim_buffer(self) @@ -51,6 +54,7 @@ local function trim_buffer(self) self.bytes = malloc(size) FFI.copy(self.bytes, prev, self.size) self.capacity = size + free(prev) end local function count_elements(b) @@ -129,6 +133,7 @@ local function reserve(self, new_capacity) self.bytes = malloc(new_capacity) FFI.copy(self.bytes, prev, self.size) self.capacity = new_capacity + free(prev) end local function get_capacity(self) @@ -187,7 +192,9 @@ local bytearray_mt = { __len = function(self) return tonumber(self.size) end, - __gc = function(self) end, + __gc = function(self) + free(self.bytes) + end, __ipairs = function(self) local i = 0 return function() From a0b7e81a94d8a4f2750fbbd507ba6bd2e688f8b4 Mon Sep 17 00:00:00 2001 From: Onran Date: Wed, 1 Jul 2026 20:34:35 +0900 Subject: [PATCH 5/5] fix Skeleton::setConfig --- src/objects/rigging.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/objects/rigging.cpp b/src/objects/rigging.cpp index f686bfbcf..f47f7c733 100644 --- a/src/objects/rigging.cpp +++ b/src/objects/rigging.cpp @@ -88,12 +88,22 @@ void Skeleton::deserialize(const dv::value& root) { void Skeleton::setConfig(std::shared_ptr rigConfig) { config = std::move(rigConfig); + + const auto& bones = config->getBones(); + pose.matrices.resize( - config->getBones().size(), glm::mat4(1.0f) + bones.size(), glm::mat4(1.0f) ); calculated.matrices.resize( - config->getBones().size(), glm::mat4(1.0f) + bones.size(), glm::mat4(1.0f) ); + + modelOverrides.resize(bones.size()); + flags.resize(bones.size()); + + for (size_t i = 0; i < bones.size(); i++) { + flags[i].visible = true; + } } static void get_all_nodes(std::vector& nodes, Bone* node) {