move Chunks from Level to Player

This commit is contained in:
MihailRis
2024-12-17 19:40:00 +03:00
parent b7664b4188
commit 1c18c02092
40 changed files with 450 additions and 220 deletions
+3 -1
View File
@@ -40,7 +40,9 @@ static int l_is_solid_at(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
auto z = lua::tointeger(L, 3);
return lua::pushboolean(L, blocks_agent::is_solid_at(*level->chunks, x, y, z));
return lua::pushboolean(
L, blocks_agent::is_solid_at(*level->chunksStorage, x, y, z)
);
}
static int l_count(lua::State* L) {
+10 -2
View File
@@ -9,6 +9,7 @@
#include "physics/Hitbox.hpp"
#include "voxels/Chunks.hpp"
#include "voxels/Block.hpp"
#include "voxels/blocks_agent.hpp"
#include "window/Camera.hpp"
using namespace scripting;
@@ -149,8 +150,15 @@ static int l_raycast(lua::State* L) {
blockid_t block = BLOCK_VOID;
if (auto voxel = level->chunks->rayCast(
start, dir, maxDistance, end, normal, iend, filteredBlocks
if (auto voxel = blocks_agent::raycast(
*level->chunksStorage,
start,
dir,
maxDistance,
end,
normal,
iend,
filteredBlocks
)) {
maxDistance = glm::distance(start, end);
block = voxel->id;
@@ -28,7 +28,7 @@ static int l_create_fragment(lua::State* L) {
bool saveEntities = lua::toboolean(L, 4);
auto fragment =
VoxelFragment::create(level, pointA, pointB, crop, saveEntities);
VoxelFragment::create(*level, pointA, pointB, crop, saveEntities);
return lua::newuserdata<lua::LuaVoxelFragment>(
L, std::shared_ptr<VoxelFragment>(std::move(fragment))
);
+2 -1
View File
@@ -14,6 +14,7 @@
#include "voxels/Block.hpp"
#include "voxels/Chunks.hpp"
#include "voxels/voxel.hpp"
#include "voxels/blocks_agent.hpp"
#include "world/Level.hpp"
#include "api_lua.hpp"
@@ -59,7 +60,7 @@ static int l_open_block(lua::State* L) {
auto z = lua::tointeger(L, 3);
bool playerInventory = !lua::toboolean(L, 4);
auto vox = level->chunks->get(x, y, z);
auto vox = blocks_agent::get(*level->chunksStorage, x, y, z);
if (vox == nullptr) {
throw std::runtime_error(
"block does not exists at " + std::to_string(x) + " " +
+7 -7
View File
@@ -125,7 +125,7 @@ static int l_get_generator(lua::State* L) {
static int l_get_chunk_data(lua::State* L) {
int x = (int)lua::tointeger(L, 1);
int y = (int)lua::tointeger(L, 2);
const auto& chunk = level->chunks->getChunk(x, y);
const auto& chunk = level->chunksStorage->getChunk(x, y);
if (chunk == nullptr) {
lua::pushnil(L);
return 0;
@@ -181,8 +181,8 @@ static int l_set_chunk_data(lua::State* L) {
if (lua::gettop(L) >= 4) {
is_compressed = lua::toboolean(L, 4);
}
auto chunk = level->chunks->getChunk(x, y);
if(chunk== nullptr){
auto chunk = level->chunksStorage->getChunk(x, y);
if (chunk == nullptr) {
return 0;
}
if (is_compressed) {
@@ -217,22 +217,22 @@ static int l_set_chunk_data(lua::State* L) {
chunk->flags.modified = true;
lighting.onChunkLoaded(x, y, true);
chunk = level->chunks->getChunk(x - 1, y);
chunk = level->chunksStorage->getChunk(x - 1, y);
if (chunk != nullptr) {
chunk->flags.modified = true;
lighting.onChunkLoaded(x - 1, y, true);
}
chunk = level->chunks->getChunk(x + 1, y);
chunk = level->chunksStorage->getChunk(x + 1, y);
if (chunk != nullptr) {
chunk->flags.modified = true;
lighting.onChunkLoaded(x + 1, y, true);
}
chunk = level->chunks->getChunk(x, y - 1);
chunk = level->chunksStorage->getChunk(x, y - 1);
if (chunk != nullptr) {
chunk->flags.modified = true;
lighting.onChunkLoaded(x, y - 1, true);
}
chunk = level->chunks->getChunk(x, y + 1);
chunk = level->chunksStorage->getChunk(x, y + 1);
if (chunk != nullptr) {
chunk->flags.modified = true;
lighting.onChunkLoaded(x, y + 1, true);
@@ -26,7 +26,7 @@ static int l_place(lua::State* L) {
auto offset = tovec3(L, 2);
int rotation = tointeger(L, 3) & 0b11;
fragment->getFragment()->place(
*scripting::level->chunks, offset, rotation
*scripting::level->chunksStorage, offset, rotation
);
}
return 0;