mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
Merge branch 'MihailRis:main' into main
This commit is contained in:
commit
8e2d915dd7
26 changed files with 368 additions and 64 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue