diff --git a/src/frontend/debug_panel.cpp b/src/frontend/debug_panel.cpp index 3470cdb1..d1ad6231 100644 --- a/src/frontend/debug_panel.cpp +++ b/src/frontend/debug_panel.cpp @@ -96,7 +96,7 @@ std::shared_ptr create_debug_panel( std::to_wstring(ParticlesRenderer::aliveEmitters); })); panel->add(create_label([&]() { - return L"chunks: "+std::to_wstring(level.chunksStorage->size())+ + return L"chunks: "+std::to_wstring(level.chunks->size())+ L" visible: "+std::to_wstring(ChunksRenderer::visibleChunks); })); panel->add(create_label([&]() { diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index e6b1ecb9..d078b1c6 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -296,7 +296,7 @@ void Hud::updateWorldGenDebugVisualization() { data[(flippedZ * width + x) * 4 + 1] = chunks.getChunk(ax + ox, az + oz) ? 255 : 0; data[(flippedZ * width + x) * 4 + 0] = - level.chunksStorage->fetch(ax + ox, az + oz) ? 255 : 0; + level.chunks->fetch(ax + ox, az + oz) ? 255 : 0; if (ax < 0 || az < 0 || ax >= areaWidth || az >= areaHeight) { diff --git a/src/logic/BlocksController.cpp b/src/logic/BlocksController.cpp index 3c0b64c0..0a70910f 100644 --- a/src/logic/BlocksController.cpp +++ b/src/logic/BlocksController.cpp @@ -21,7 +21,7 @@ BlocksController::BlocksController(const Level& level, Lighting* lighting, uint padding) : level(level), - chunks(*level.chunksStorage), + chunks(*level.chunks), lighting(lighting), randTickClock(20, 3), blocksTickClock(20, 1), diff --git a/src/logic/ChunksController.cpp b/src/logic/ChunksController.cpp index 13c7ab86..a8041f8d 100644 --- a/src/logic/ChunksController.cpp +++ b/src/logic/ChunksController.cpp @@ -124,7 +124,7 @@ bool ChunksController::buildLights(const Player& player, const std::shared_ptrcreate(x, z); + auto chunk = level.chunks->create(x, z); player.chunks->putChunk(chunk); auto& chunkFlags = chunk->flags; diff --git a/src/logic/scripting/lua/libs/libblock.cpp b/src/logic/scripting/lua/libs/libblock.cpp index 180a959f..8d1e0897 100644 --- a/src/logic/scripting/lua/libs/libblock.cpp +++ b/src/logic/scripting/lua/libs/libblock.cpp @@ -41,7 +41,7 @@ static int l_is_solid_at(lua::State* L) { auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); return lua::pushboolean( - L, blocks_agent::is_solid_at(*level->chunksStorage, x, y, z) + L, blocks_agent::is_solid_at(*level->chunks, x, y, z) ); } @@ -72,7 +72,7 @@ static int l_is_segment(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - const auto& vox = blocks_agent::require(*level->chunksStorage, x, y, z); + const auto& vox = blocks_agent::require(*level->chunks, x, y, z); return lua::pushboolean(L, vox.state.segment); } @@ -80,13 +80,10 @@ static int l_seek_origin(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - const auto& vox = blocks_agent::require(*level->chunksStorage, x, y, z); + const auto& vox = blocks_agent::require(*level->chunks, x, y, z); auto& def = indices->blocks.require(vox.id); return lua::pushivec_stack( - L, - blocks_agent::seek_origin( - *level->chunksStorage, {x, y, z}, def, vox.state - ) + L, blocks_agent::seek_origin(*level->chunks, {x, y, z}, def, vox.state) ); } @@ -102,10 +99,10 @@ static int l_set(lua::State* L) { } int cx = floordiv(x); int cz = floordiv(z); - if (!blocks_agent::get_chunk(*level->chunksStorage, cx, cz)) { + if (!blocks_agent::get_chunk(*level->chunks, cx, cz)) { return 0; } - blocks_agent::set(*level->chunksStorage, x, y, z, id, int2blockstate(state)); + blocks_agent::set(*level->chunks, x, y, z, id, int2blockstate(state)); auto chunksController = controller->getChunksController(); if (chunksController == nullptr) { @@ -123,7 +120,7 @@ static int l_get(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); int id = vox == nullptr ? -1 : vox->id; return lua::pushinteger(L, id); } @@ -132,7 +129,7 @@ static int l_get_x(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); if (vox == nullptr) { return lua::pushivec_stack(L, glm::ivec3(1, 0, 0)); } @@ -149,7 +146,7 @@ static int l_get_y(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); if (vox == nullptr) { return lua::pushivec_stack(L, glm::ivec3(0, 1, 0)); } @@ -166,7 +163,7 @@ static int l_get_z(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); if (vox == nullptr) { return lua::pushivec_stack(L, glm::ivec3(0, 0, 1)); } @@ -183,7 +180,7 @@ static int l_get_rotation(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); int rotation = vox == nullptr ? 0 : vox->state.rotation; return lua::pushinteger(L, rotation); } @@ -193,7 +190,7 @@ static int l_set_rotation(lua::State* L) { auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); auto value = lua::tointeger(L, 4); - blocks_agent::set_rotation(*level->chunksStorage, x, y, z, value); + blocks_agent::set_rotation(*level->chunks, x, y, z, value); return 0; } @@ -201,7 +198,7 @@ static int l_get_states(lua::State* L) { auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); int states = vox == nullptr ? 0 : blockstate2int(vox->state); return lua::pushinteger(L, states); } @@ -216,7 +213,7 @@ static int l_set_states(lua::State* L) { } int cx = floordiv(x); int cz = floordiv(z); - auto chunk = blocks_agent::get_chunk(*level->chunksStorage, cx, cz); + auto chunk = blocks_agent::get_chunk(*level->chunks, cx, cz); if (chunk == nullptr) { return 0; } @@ -235,18 +232,16 @@ static int l_get_user_bits(lua::State* L) { auto offset = lua::tointeger(L, 4) + VOXEL_USER_BITS_OFFSET; auto bits = lua::tointeger(L, 5); - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); if (vox == nullptr) { return lua::pushinteger(L, 0); } const auto& def = content->getIndices()->blocks.require(vox->id); if (def.rt.extended) { auto origin = blocks_agent::seek_origin( - *level->chunksStorage, {x, y, z}, def, vox->state - ); - vox = blocks_agent::get( - *level->chunksStorage, origin.x, origin.y, origin.z + *level->chunks, {x, y, z}, def, vox->state ); + vox = blocks_agent::get(*level->chunks, origin.x, origin.y, origin.z); if (vox == nullptr) { return lua::pushinteger(L, 0); } @@ -257,7 +252,7 @@ static int l_get_user_bits(lua::State* L) { } static int l_set_user_bits(lua::State* L) { - auto& chunks = *level->chunksStorage; + auto& chunks = *level->chunks; auto x = lua::tointeger(L, 1); auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); @@ -294,7 +289,7 @@ static int l_is_replaceable_at(lua::State* L) { auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); return lua::pushboolean( - L, blocks_agent::is_replaceable_at(*level->chunksStorage, x, y, z) + L, blocks_agent::is_replaceable_at(*level->chunks, x, y, z) ); } @@ -369,7 +364,7 @@ static int l_place(lua::State* L) { if (static_cast(id) >= indices->blocks.count()) { return 0; } - if (!blocks_agent::get(*level->chunksStorage, x, y, z)) { + if (!blocks_agent::get(*level->chunks, x, y, z)) { return 0; } const auto def = level->content->getIndices()->blocks.get(id); @@ -390,7 +385,7 @@ static int l_destruct(lua::State* L) { auto y = lua::tointeger(L, 2); auto z = lua::tointeger(L, 3); auto playerid = lua::gettop(L) >= 4 ? lua::tointeger(L, 4) : -1; - auto vox = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); if (vox == nullptr) { return 0; } @@ -425,7 +420,7 @@ static int l_raycast(lua::State* L) { glm::ivec3 normal; glm::ivec3 iend; if (auto voxel = blocks_agent::raycast( - *level->chunksStorage, + *level->chunks, start, dir, maxDistance, @@ -528,7 +523,7 @@ static int l_get_field(lua::State* L) { } auto cx = floordiv(x, CHUNK_W); auto cz = floordiv(z, CHUNK_D); - auto chunk = blocks_agent::get_chunk(*level->chunksStorage, cx, cz); + auto chunk = blocks_agent::get_chunk(*level->chunks, cx, cz); if (chunk == nullptr || y < 0 || y >= CHUNK_H) { return 0; } @@ -599,7 +594,7 @@ static int l_set_field(lua::State* L) { auto cz = floordiv(z, CHUNK_D); auto lx = x - cx * CHUNK_W; auto lz = z - cz * CHUNK_W; - auto chunk = blocks_agent::get_chunk(*level->chunksStorage, cx, cz); + auto chunk = blocks_agent::get_chunk(*level->chunks, cx, cz); if (chunk == nullptr || y < 0 || y >= CHUNK_H) { return 0; } diff --git a/src/logic/scripting/lua/libs/libentity.cpp b/src/logic/scripting/lua/libs/libentity.cpp index bf547f95..ce394fb5 100644 --- a/src/logic/scripting/lua/libs/libentity.cpp +++ b/src/logic/scripting/lua/libs/libentity.cpp @@ -151,7 +151,7 @@ static int l_raycast(lua::State* L) { blockid_t block = BLOCK_VOID; if (auto voxel = blocks_agent::raycast( - *level->chunksStorage, + *level->chunks, start, dir, maxDistance, diff --git a/src/logic/scripting/lua/libs/libhud.cpp b/src/logic/scripting/lua/libs/libhud.cpp index f12ba0a7..90cb57d4 100644 --- a/src/logic/scripting/lua/libs/libhud.cpp +++ b/src/logic/scripting/lua/libs/libhud.cpp @@ -60,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 = blocks_agent::get(*level->chunksStorage, x, y, z); + auto vox = blocks_agent::get(*level->chunks, x, y, z); if (vox == nullptr) { throw std::runtime_error( "block does not exists at " + std::to_string(x) + " " + diff --git a/src/logic/scripting/lua/libs/libworld.cpp b/src/logic/scripting/lua/libs/libworld.cpp index 16e81d56..e13d8c0f 100644 --- a/src/logic/scripting/lua/libs/libworld.cpp +++ b/src/logic/scripting/lua/libs/libworld.cpp @@ -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->chunksStorage->getChunk(x, y); + const auto& chunk = level->chunks->getChunk(x, y); if (chunk == nullptr) { lua::pushnil(L); return 0; @@ -181,7 +181,7 @@ static int l_set_chunk_data(lua::State* L) { if (lua::gettop(L) >= 4) { is_compressed = lua::toboolean(L, 4); } - auto chunk = level->chunksStorage->getChunk(x, y); + auto chunk = level->chunks->getChunk(x, y); if (chunk == nullptr) { return 0; } @@ -217,22 +217,22 @@ static int l_set_chunk_data(lua::State* L) { chunk->flags.modified = true; lighting.onChunkLoaded(x, y, true); - chunk = level->chunksStorage->getChunk(x - 1, y); + chunk = level->chunks->getChunk(x - 1, y); if (chunk != nullptr) { chunk->flags.modified = true; lighting.onChunkLoaded(x - 1, y, true); } - chunk = level->chunksStorage->getChunk(x + 1, y); + chunk = level->chunks->getChunk(x + 1, y); if (chunk != nullptr) { chunk->flags.modified = true; lighting.onChunkLoaded(x + 1, y, true); } - chunk = level->chunksStorage->getChunk(x, y - 1); + chunk = level->chunks->getChunk(x, y - 1); if (chunk != nullptr) { chunk->flags.modified = true; lighting.onChunkLoaded(x, y - 1, true); } - chunk = level->chunksStorage->getChunk(x, y + 1); + chunk = level->chunks->getChunk(x, y + 1); if (chunk != nullptr) { chunk->flags.modified = true; lighting.onChunkLoaded(x, y + 1, true); @@ -245,7 +245,7 @@ static int l_count_chunks(lua::State* L) { if (level == nullptr) { return 0; } - return lua::pushinteger(L, level->chunksStorage->size()); + return lua::pushinteger(L, level->chunks->size()); } const luaL_Reg worldlib[] = { diff --git a/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp b/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp index 4a7af971..f123be6f 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_voxelfragment.cpp @@ -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->chunksStorage, offset, rotation + *scripting::level->chunks, offset, rotation ); } return 0; diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index d2e5742d..1a27243f 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -459,7 +459,7 @@ void Entities::updatePhysics(float delta) { float vel = glm::length(prevVel); int substeps = static_cast(delta * vel * 20); substeps = std::min(100, std::max(2, substeps)); - physics->step(*level->chunksStorage, &hitbox, delta, substeps, eid.uid); + physics->step(*level->chunks, &hitbox, delta, substeps, eid.uid); hitbox.linearDamping = hitbox.grounded * 24; transform.setPos(hitbox.position); if (hitbox.grounded && !grounded) { diff --git a/src/world/Level.cpp b/src/world/Level.cpp index 3625f62e..28a8dab5 100644 --- a/src/world/Level.cpp +++ b/src/world/Level.cpp @@ -24,7 +24,7 @@ Level::Level( : settings(settings), world(std::move(worldPtr)), content(content), - chunksStorage(std::make_unique(this)), + chunks(std::make_unique(this)), physics(std::make_unique(glm::vec3(0, -22.6f, 0))), events(std::make_unique()), entities(std::make_unique(this)), @@ -53,10 +53,10 @@ Level::Level( } events->listen(LevelEventType::EVT_CHUNK_SHOWN, [this](LevelEventType, Chunk* chunk) { - chunksStorage->incref(chunk); + chunks->incref(chunk); }); events->listen(LevelEventType::EVT_CHUNK_HIDDEN, [this](LevelEventType, Chunk* chunk) { - chunksStorage->decref(chunk); + chunks->decref(chunk); }); inventories = std::make_unique(*this); } diff --git a/src/world/Level.hpp b/src/world/Level.hpp index 9994c01d..63a724c9 100644 --- a/src/world/Level.hpp +++ b/src/world/Level.hpp @@ -25,7 +25,7 @@ class Level { public: const Content* const content; - std::unique_ptr chunksStorage; + std::unique_ptr chunks; std::unique_ptr inventories; std::unique_ptr physics; diff --git a/src/world/World.cpp b/src/world/World.cpp index eb8c33bf..d8ef2ed5 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -66,7 +66,7 @@ void World::writeResources(const Content* content) { void World::write(Level* level) { const Content* content = level->content; - level->chunksStorage->saveAll(); + level->chunks->saveAll(); info.nextEntityId = level->entities->peekNextID(); wfile->write(this, content); diff --git a/src/world/generator/VoxelFragment.cpp b/src/world/generator/VoxelFragment.cpp index af92dc7e..9a739a2a 100644 --- a/src/world/generator/VoxelFragment.cpp +++ b/src/world/generator/VoxelFragment.cpp @@ -27,7 +27,7 @@ std::unique_ptr VoxelFragment::create( if (crop) { VoxelsVolume volume(size.x, size.y, size.z); volume.setPosition(start.x, start.y, start.z); - blocks_agent::get_voxels(*level.chunksStorage, &volume); + blocks_agent::get_voxels(*level.chunks, &volume); auto end = start + size; @@ -52,7 +52,7 @@ std::unique_ptr VoxelFragment::create( VoxelsVolume volume(size.x, size.y, size.z); volume.setPosition(start.x, start.y, start.z); - blocks_agent::get_voxels(*level.chunksStorage, &volume); + blocks_agent::get_voxels(*level.chunks, &volume); auto volVoxels = volume.getVoxels(); std::vector voxels(size.x * size.y * size.z);