rename Level.chunksStorage to Level.chunks
This commit is contained in:
parent
70370904db
commit
48d94036fd
@ -96,7 +96,7 @@ std::shared_ptr<UINode> 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([&]() {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -124,7 +124,7 @@ bool ChunksController::buildLights(const Player& player, const std::shared_ptr<C
|
||||
}
|
||||
|
||||
void ChunksController::createChunk(const Player& player, int x, int z) const {
|
||||
auto chunk = level.chunksStorage->create(x, z);
|
||||
auto chunk = level.chunks->create(x, z);
|
||||
player.chunks->putChunk(chunk);
|
||||
auto& chunkFlags = chunk->flags;
|
||||
|
||||
|
||||
@ -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<CHUNK_W>(x);
|
||||
int cz = floordiv<CHUNK_D>(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<CHUNK_W>(x);
|
||||
int cz = floordiv<CHUNK_D>(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<size_t>(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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) + " " +
|
||||
|
||||
@ -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[] = {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -459,7 +459,7 @@ void Entities::updatePhysics(float delta) {
|
||||
float vel = glm::length(prevVel);
|
||||
int substeps = static_cast<int>(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) {
|
||||
|
||||
@ -24,7 +24,7 @@ Level::Level(
|
||||
: settings(settings),
|
||||
world(std::move(worldPtr)),
|
||||
content(content),
|
||||
chunksStorage(std::make_unique<GlobalChunks>(this)),
|
||||
chunks(std::make_unique<GlobalChunks>(this)),
|
||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||
events(std::make_unique<LevelEvents>()),
|
||||
entities(std::make_unique<Entities>(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<Inventories>(*this);
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ class Level {
|
||||
public:
|
||||
const Content* const content;
|
||||
|
||||
std::unique_ptr<GlobalChunks> chunksStorage;
|
||||
std::unique_ptr<GlobalChunks> chunks;
|
||||
std::unique_ptr<Inventories> inventories;
|
||||
|
||||
std::unique_ptr<PhysicsSolver> physics;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ std::unique_ptr<VoxelFragment> 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> 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<voxel> voxels(size.x * size.y * size.z);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user