mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
Merge branch 'MihailRis:main' into main
This commit is contained in:
commit
1f7f2ba097
7 changed files with 81 additions and 7 deletions
|
|
@ -162,7 +162,19 @@ inventory.get_all_data(
|
||||||
invid: int,
|
invid: int,
|
||||||
-- slot index
|
-- slot index
|
||||||
slot: int,
|
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
|
```lua
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,19 @@ inventory.get_all_data(
|
||||||
invid: int,
|
invid: int,
|
||||||
-- индекс слота
|
-- индекс слота
|
||||||
slot: int,
|
slot: int,
|
||||||
) -> table
|
) -> table | nil
|
||||||
|
|
||||||
|
-- Устанавливает значения локальных cвойств предмета.
|
||||||
|
inventory.set_all_data(
|
||||||
|
-- id инвентаря
|
||||||
|
invid: int,
|
||||||
|
-- индекс слота
|
||||||
|
slot: int,
|
||||||
|
-- таблица cвойство:значение
|
||||||
|
fields: table,
|
||||||
|
-- удалить остальные значения свойств
|
||||||
|
[опционально] clear: boolean = false
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|
@ -222,4 +234,4 @@ inventory.use(
|
||||||
-- индекс слота
|
-- индекс слота
|
||||||
slot: int
|
slot: int
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,30 @@ FFI.cdef[[
|
||||||
} bytearray_t;
|
} bytearray_t;
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local malloc = FFI.C.malloc
|
|
||||||
local free = FFI.C.free
|
local free = FFI.C.free
|
||||||
|
|
||||||
local FFIBytearray
|
local FFIBytearray
|
||||||
local bytearray_type
|
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 function grow_buffer(self, elems)
|
||||||
local new_capacity = math.ceil(self.capacity / 0.75 + elems)
|
local new_capacity = math.ceil(self.capacity / 0.75 + elems)
|
||||||
local prev = self.bytes
|
local prev = self.bytes
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,16 @@ public:
|
||||||
return fields;
|
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 {
|
bool hasFields() const {
|
||||||
return fields != nullptr;
|
return fields != nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,14 @@ static int l_get_all_data(lua::State* L, ItemStack& stack) {
|
||||||
return lua::pushvalue(L, stack.getFields());
|
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) {
|
static int l_has_data(lua::State* L, ItemStack& stack) {
|
||||||
auto key = lua::tostring(L, 3);
|
auto key = lua::tostring(L, 3);
|
||||||
if (key == nullptr) {
|
if (key == nullptr) {
|
||||||
|
|
@ -267,6 +275,7 @@ const luaL_Reg inventorylib[] = {
|
||||||
{"get_data", lua::wrap<wrap_slot<l_get_data>>},
|
{"get_data", lua::wrap<wrap_slot<l_get_data>>},
|
||||||
{"set_data", lua::wrap<wrap_slot<l_set_data>>},
|
{"set_data", lua::wrap<wrap_slot<l_set_data>>},
|
||||||
{"get_all_data", lua::wrap<wrap_slot<l_get_all_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>>},
|
{"has_data", lua::wrap<wrap_slot<l_has_data>>},
|
||||||
{"create", lua::wrap<l_create>},
|
{"create", lua::wrap<l_create>},
|
||||||
{"remove", lua::wrap<l_remove>},
|
{"remove", lua::wrap<l_remove>},
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,22 @@ void Skeleton::deserialize(const dv::value& root) {
|
||||||
|
|
||||||
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
|
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
|
||||||
config = std::move(rigConfig);
|
config = std::move(rigConfig);
|
||||||
|
|
||||||
|
const auto& bones = config->getBones();
|
||||||
|
|
||||||
pose.matrices.resize(
|
pose.matrices.resize(
|
||||||
config->getBones().size(), glm::mat4(1.0f)
|
bones.size(), glm::mat4(1.0f)
|
||||||
);
|
);
|
||||||
calculated.matrices.resize(
|
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) {
|
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,9 @@ static inline voxel* raycast_blocks(
|
||||||
} else {
|
} else {
|
||||||
iend = {ix, iy, iz};
|
iend = {ix, iy, iz};
|
||||||
norm = {0, 0, 0};
|
norm = {0, 0, 0};
|
||||||
norm[steppedIndex] = -step[steppedIndex];
|
if (steppedIndex != -1) {
|
||||||
|
norm[steppedIndex] = -step[steppedIndex];
|
||||||
|
}
|
||||||
return voxel;
|
return voxel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue