refactor Content
This commit is contained in:
+10
-10
@@ -66,7 +66,7 @@ const AABB* Chunks::isObstacleAt(float x, float y, float z){
|
||||
return ∅
|
||||
}
|
||||
}
|
||||
const Block* def = indices->getBlockDef(v->id);
|
||||
const auto def = indices->blocks.get(v->id);
|
||||
if (def->obstacle) {
|
||||
glm::ivec3 offset {};
|
||||
if (v->state.segment) {
|
||||
@@ -89,21 +89,21 @@ bool Chunks::isSolidBlock(int32_t x, int32_t y, int32_t z) {
|
||||
voxel* v = get(x, y, z);
|
||||
if (v == nullptr)
|
||||
return false;
|
||||
return indices->getBlockDef(v->id)->rt.solid;
|
||||
return indices->blocks.get(v->id)->rt.solid;
|
||||
}
|
||||
|
||||
bool Chunks::isReplaceableBlock(int32_t x, int32_t y, int32_t z) {
|
||||
voxel* v = get(x, y, z);
|
||||
if (v == nullptr)
|
||||
return false;
|
||||
return indices->getBlockDef(v->id)->replaceable;
|
||||
return indices->blocks.get(v->id)->replaceable;
|
||||
}
|
||||
|
||||
bool Chunks::isObstacleBlock(int32_t x, int32_t y, int32_t z) {
|
||||
voxel* v = get(x, y, z);
|
||||
if (v == nullptr)
|
||||
return false;
|
||||
return indices->getBlockDef(v->id)->obstacle;
|
||||
return indices->blocks.get(v->id)->obstacle;
|
||||
}
|
||||
|
||||
ubyte Chunks::getLight(int32_t x, int32_t y, int32_t z, int channel){
|
||||
@@ -240,7 +240,7 @@ bool Chunks::checkReplaceability(const Block* def, blockstate state, glm::ivec3
|
||||
pos += rotation.axisY * sy;
|
||||
pos += rotation.axisZ * sz;
|
||||
if (auto vox = get(pos.x, pos.y, pos.z)) {
|
||||
auto target = indices->getBlockDef(vox->id);
|
||||
auto target = indices->blocks.get(vox->id);
|
||||
if (!target->replaceable && vox->id != ignore) {
|
||||
return false;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ void Chunks::setRotation(int32_t x, int32_t y, int32_t z, uint8_t index) {
|
||||
if (vox == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto def = indices->getBlockDef(vox->id);
|
||||
auto def = indices->blocks.get(vox->id);
|
||||
if (!def->rotatable || vox->state.rotation == index) {
|
||||
return;
|
||||
}
|
||||
@@ -351,7 +351,7 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state)
|
||||
|
||||
// block finalization
|
||||
voxel& vox = chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx];
|
||||
auto prevdef = indices->getBlockDef(vox.id);
|
||||
auto prevdef = indices->blocks.get(vox.id);
|
||||
if (prevdef->inventorySize == 0) {
|
||||
chunk->removeBlockInventory(lx, y, lz);
|
||||
}
|
||||
@@ -360,7 +360,7 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state)
|
||||
}
|
||||
|
||||
// block initialization
|
||||
auto newdef = indices->getBlockDef(id);
|
||||
auto newdef = indices->blocks.get(id);
|
||||
vox.id = id;
|
||||
vox.state = state;
|
||||
chunk->setModifiedAndUnsaved();
|
||||
@@ -429,7 +429,7 @@ voxel* Chunks::rayCast(
|
||||
if (voxel == nullptr){
|
||||
return nullptr;
|
||||
}
|
||||
const auto def = indices->getBlockDef(voxel->id);
|
||||
const auto def = indices->blocks.get(voxel->id);
|
||||
if (def->selectable){
|
||||
end.x = px + t * dx;
|
||||
end.y = py + t * dy;
|
||||
@@ -553,7 +553,7 @@ glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDis
|
||||
if (voxel == nullptr) {
|
||||
return glm::vec3(px + t * dx, py + t * dy, pz + t * dz);
|
||||
}
|
||||
const auto def = indices->getBlockDef(voxel->id);
|
||||
const auto def = indices->blocks.get(voxel->id);
|
||||
if (def->obstacle) {
|
||||
if (!def->rt.solid) {
|
||||
const std::vector<AABB>& hitboxes = def->rotatable
|
||||
|
||||
@@ -40,7 +40,7 @@ void ChunksStorage::remove(int x, int z) {
|
||||
static void verifyLoadedChunk(ContentIndices* indices, Chunk* chunk) {
|
||||
for (size_t i = 0; i < CHUNK_VOL; i++) {
|
||||
blockid_t id = chunk->voxels[i].id;
|
||||
if (indices->getBlockDef(id) == nullptr) {
|
||||
if (indices->blocks.get(id) == nullptr) {
|
||||
auto logline = logger.error();
|
||||
logline << "corruped block detected at " << i << " of chunk ";
|
||||
logline << chunk->x << "x" << chunk->z;
|
||||
@@ -79,6 +79,7 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
||||
}
|
||||
|
||||
// reduce nesting on next modification
|
||||
// 25.06.2024: not now
|
||||
void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
||||
const Content* content = level->content;
|
||||
auto indices = content->getIndices();
|
||||
@@ -137,7 +138,7 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume, bool backlight) const {
|
||||
voxels[vidx] = cvoxels[cidx];
|
||||
light_t light = clights[cidx];
|
||||
if (backlight) {
|
||||
const Block* block = indices->getBlockDef(voxels[vidx].id);
|
||||
auto block = indices->blocks.get(voxels[vidx].id);
|
||||
if (block->lightPassing) {
|
||||
light = Lightmap::combine(
|
||||
min(15, Lightmap::extract(light, 0)+1),
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "../content/Content.hpp"
|
||||
|
||||
WorldGenerator::WorldGenerator(const Content* content)
|
||||
: idStone(content->requireBlock("base:stone").rt.id),
|
||||
idDirt(content->requireBlock("base:dirt").rt.id),
|
||||
idGrassBlock(content->requireBlock("base:grass_block").rt.id),
|
||||
idSand(content->requireBlock("base:sand").rt.id),
|
||||
idWater(content->requireBlock("base:water").rt.id),
|
||||
idWood(content->requireBlock("base:wood").rt.id),
|
||||
idLeaves(content->requireBlock("base:leaves").rt.id),
|
||||
idGrass(content->requireBlock("base:grass").rt.id),
|
||||
idFlower(content->requireBlock("base:flower").rt.id),
|
||||
idBazalt(content->requireBlock("base:bazalt").rt.id) {}
|
||||
: idStone(content->blocks.require("base:stone").rt.id),
|
||||
idDirt(content->blocks.require("base:dirt").rt.id),
|
||||
idGrassBlock(content->blocks.require("base:grass_block").rt.id),
|
||||
idSand(content->blocks.require("base:sand").rt.id),
|
||||
idWater(content->blocks.require("base:water").rt.id),
|
||||
idWood(content->blocks.require("base:wood").rt.id),
|
||||
idLeaves(content->blocks.require("base:leaves").rt.id),
|
||||
idGrass(content->blocks.require("base:grass").rt.id),
|
||||
idFlower(content->blocks.require("base:flower").rt.id),
|
||||
idBazalt(content->blocks.require("base:bazalt").rt.id) {}
|
||||
|
||||
Reference in New Issue
Block a user