migrate blocks interaction (scripting) to global chunks storage (WIP)

This commit is contained in:
MihailRis
2024-12-13 05:54:41 +03:00
parent 53cc8d3c7b
commit e0b3425eff
16 changed files with 227 additions and 144 deletions
+11
View File
@@ -7,6 +7,7 @@
#include "voxels/Chunk.hpp"
#include "voxels/Chunks.hpp"
#include "voxels/voxel.hpp"
#include "voxels/ChunksStorage.hpp"
#include "world/Level.hpp"
#include "maths/voxmaths.hpp"
#include "data/StructLayout.hpp"
@@ -114,6 +115,15 @@ static int l_get(lua::State* L) {
return lua::pushinteger(L, id);
}
static int l_get_slow(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
auto z = lua::tointeger(L, 3);
auto vox = level->chunksStorage->get(x, y, z);
int id = vox == nullptr ? -1 : vox->id;
return lua::pushinteger(L, id);
}
static int l_get_x(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
@@ -598,6 +608,7 @@ const luaL_Reg blocklib[] = {
{"is_replaceable_at", lua::wrap<l_is_replaceable_at>},
{"set", lua::wrap<l_set>},
{"get", lua::wrap<l_get>},
{"get_slow", lua::wrap<l_get_slow>},
{"get_X", lua::wrap<l_get_x>},
{"get_Y", lua::wrap<l_get_y>},
{"get_Z", lua::wrap<l_get_z>},