rename Level.chunksStorage to Level.chunks
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user