Merge branch 'MihailRis:main' into main

This commit is contained in:
Xertis 2026-03-02 20:48:35 +03:00 • committed by GitHub
commit 8e2d915dd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 368 additions and 64 deletions

View file

@ -1,16 +1,17 @@
#include "api_lua.hpp"
#include "../usertypes/lua_type_canvas.hpp"
#include "assets/Assets.hpp"
#include "assets/AssetsLoader.hpp"
#include "coders/obj.hpp"
#include "coders/png.hpp"
#include "coders/vcm.hpp"
#include "debug/Logger.hpp"
#include "engine/Engine.hpp"
#include "graphics/commons/Model.hpp"
#include "graphics/core/Texture.hpp"
#include "graphics/core/Atlas.hpp"
#include "graphics/core/Texture.hpp"
#include "util/Buffer.hpp"
#include "../usertypes/lua_type_canvas.hpp"
using namespace scripting;
@ -76,6 +77,11 @@ static int l_parse_model(lua::State* L) {
skeletonName = lua::require_string(L, 4);
}
if (format == "obj") {
assets.store(obj::parse(name, string), name);
return 0;
}
if (format != "xml" && format != "vcm") {
throw std::runtime_error(
"unknown format " + util::quote(std::string(format))

View file

@ -246,11 +246,12 @@ static int l_get_user_bits(lua::State* L) {
}
static int l_get_variant(lua::State* L) {
auto& chunks = *level->chunks;
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
auto z = lua::tointeger(L, 3);
auto vox = blocks_agent::get(*level->chunks, x, y, z);
auto vox = blocks_agent::get(chunks, x, y, z);
if (vox == nullptr) {
return lua::pushinteger(L, 0);
}
@ -258,6 +259,13 @@ static int l_get_variant(lua::State* L) {
if (def.variants == nullptr) {
return lua::pushinteger(L, 0);
}
if (def.rt.extended) {
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
vox = blocks_agent::get(chunks, origin.x, origin.y, origin.z);
if (vox == nullptr) {
return lua::pushinteger(L, 0);
}
}
return lua::pushinteger(
L, (vox->state.userbits >> def.variants->offset) & def.variants->mask
);
@ -290,6 +298,14 @@ static int l_set_user_bits(lua::State* L) {
if (vox == nullptr) {
return 0;
}
int ocx = floordiv<CHUNK_W>(origin.x);
int ocz = floordiv<CHUNK_D>(origin.z);
if (cx != ocx || cz != ocz) {
chunk = blocks_agent::get_chunk(chunks, ocx, ocz);
if (chunk == nullptr) {
return 0;
}
}
}
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
chunk->setModifiedAndUnsaved();
@ -318,8 +334,8 @@ static int l_set_variant(lua::State* L) {
}
auto offset = def.variants->offset;
auto mask = def.variants->mask;
auto value = (lua::tointeger(L, 4) << offset) & mask;
auto mask = def.variants->mask << offset;
auto value = (lua::tointeger(L, 4) << offset);
if (def.rt.extended) {
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
@ -327,6 +343,14 @@ static int l_set_variant(lua::State* L) {
if (vox == nullptr) {
return 0;
}
int ocx = floordiv<CHUNK_W>(origin.x);
int ocz = floordiv<CHUNK_D>(origin.z);
if (cx != ocx || cz != ocz) {
chunk = blocks_agent::get_chunk(chunks, ocx, ocz);
if (chunk == nullptr) {
return 0;
}
}
}
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
chunk->setModifiedAndUnsaved();