refactor: change pointer parameters to references for Level and Content in various classes

This commit is contained in:
MihailRis
2024-12-25 18:53:53 +03:00
parent ef2c0b2370
commit c1b311f3c4
41 changed files with 258 additions and 251 deletions
+1 -2
View File
@@ -44,8 +44,7 @@ void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
return;
}
if (vox->id != BLOCK_VOID) {
const auto& def =
level.content->getIndices()->blocks.require(vox->id);
const auto& def = level.content.getIndices()->blocks.require(vox->id);
switch (def.model) {
case BlockModel::block:
batch->cube(
+1 -1
View File
@@ -608,7 +608,7 @@ void BlocksRenderer::build(const Chunk* chunk, const Chunks* chunks) {
voxelsBuffer->setPosition(
chunk->x * CHUNK_W - voxelBufferPadding, 0,
chunk->z * CHUNK_D - voxelBufferPadding);
chunks->getVoxels(voxelsBuffer.get(), settings.graphics.backlight.get());
chunks->getVoxels(*voxelsBuffer, settings.graphics.backlight.get());
if (voxelsBuffer->pickBlockId(
chunk->x * CHUNK_W, 0, chunk->z * CHUNK_D
+2 -2
View File
@@ -35,7 +35,7 @@ public:
settings.graphics.denseRender.get()
? settings.graphics.chunkMaxVerticesDense.get()
: settings.graphics.chunkMaxVertices.get(),
*level.content,
level.content,
cache,
settings
) {
@@ -87,7 +87,7 @@ ChunksRenderer::ChunksRenderer(
threadPool.setStopOnFail(false);
renderer = std::make_unique<BlocksRenderer>(
settings.graphics.chunkMaxVertices.get(),
*level->content, cache, settings
level->content, cache, settings
);
logger.info() << "created " << threadPool.getWorkersCount() << " workers";
}
+2 -2
View File
@@ -86,7 +86,7 @@ void Decorator::update(
currentIndex = (currentIndex + BIG_PRIME) % UPDATE_BLOCKS;
const auto& chunks = *player.chunks;
const auto& indices = *level.content->getIndices();
const auto& indices = *level.content.getIndices();
int lx = index % UPDATE_AREA_DIAMETER;
int lz = (index / UPDATE_AREA_DIAMETER) % UPDATE_AREA_DIAMETER;
@@ -108,7 +108,7 @@ void Decorator::update(float delta, const Camera& camera) {
update(delta, pos - glm::ivec3(UPDATE_AREA_DIAMETER / 2), pos);
}
const auto& chunks = *player.chunks;
const auto& indices = *level.content->getIndices();
const auto& indices = *level.content.getIndices();
auto iter = blockEmitters.begin();
while (iter != blockEmitters.end()) {
auto emitter = renderer.particles->getEmitter(iter->second);
+5 -6
View File
@@ -120,7 +120,7 @@ void WorldRenderer::setupWorldShader(
shader.uniform3f("u_cameraPos", camera.position);
shader.uniform1i("u_cubemap", 1);
auto indices = level.content->getIndices();
auto indices = level.content.getIndices();
// Light emission when an emissive item is chosen
{
auto inventory = player.getInventory();
@@ -193,7 +193,7 @@ void WorldRenderer::renderLevel(
void WorldRenderer::renderBlockSelection() {
const auto& selection = player.selection;
auto indices = level.content->getIndices();
auto indices = level.content.getIndices();
blockid_t id = selection.vox.id;
auto& block = indices->blocks.require(id);
const glm::ivec3 pos = player.selection.position;
@@ -241,7 +241,7 @@ void WorldRenderer::renderHands(
const Camera& camera, float delta
) {
auto& entityShader = assets.require<Shader>("entity");
auto indices = level.content->getIndices();
auto indices = level.content.getIndices();
// get current chosen item
const auto& inventory = player.getInventory();
@@ -275,7 +275,7 @@ void WorldRenderer::renderHands(
);
prevRotation = rotation;
auto offset = -(camera.position - player.getPosition());
float angle = glm::radians(player.cam.x - 90);
float angle = glm::radians(player.rotation.x - 90);
float cos = glm::cos(angle);
float sin = glm::sin(angle);
@@ -368,8 +368,7 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx) {
int z = std::floor(player.currentCamera->position.z);
auto block = player.chunks->get(x, y, z);
if (block && block->id) {
const auto& def =
level.content->getIndices()->blocks.require(block->id);
const auto& def = level.content.getIndices()->blocks.require(block->id);
if (def.overlayTexture.empty()) {
return;
}