Merge branch 'MihailRis:main' into main

This commit is contained in:
Astazium 2026-07-21 13:13:11 +03:00 • committed by GitHub
commit 1f7f2ba097
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 81 additions and 7 deletions

View file

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

View file

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

View file

@ -12,11 +12,30 @@ 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 raw
end
local function grow_buffer(self, elems)
local new_capacity = math.ceil(self.capacity / 0.75 + elems)
local prev = self.bytes

View file

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

View file

@ -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<wrap_slot<l_get_data>>},
{"set_data", lua::wrap<wrap_slot<l_set_data>>},
{"get_all_data", lua::wrap<wrap_slot<l_get_all_data>>},
{"set_all_data", lua::wrap<wrap_slot<l_set_all_data>>},
{"has_data", lua::wrap<wrap_slot<l_has_data>>},
{"create", lua::wrap<l_create>},
{"remove", lua::wrap<l_remove>},

View file

@ -88,12 +88,22 @@ void Skeleton::deserialize(const dv::value& root) {
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> 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<Bone*>& nodes, Bone* node) {

View file

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