mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 02:49:46 +00:00
optimize ChunksRenderer by reducing meshes map reads
This commit is contained in:
parent
3895ef020c
commit
156ba02750
2 changed files with 29 additions and 17 deletions
|
|
@ -24,7 +24,6 @@
|
||||||
#include "logic/PlayerController.hpp"
|
#include "logic/PlayerController.hpp"
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "logic/scripting/scripting_hud.hpp"
|
#include "logic/scripting/scripting_hud.hpp"
|
||||||
#include "maths/voxmaths.hpp"
|
|
||||||
#include "objects/Players.hpp"
|
#include "objects/Players.hpp"
|
||||||
#include "objects/Entities.hpp"
|
#include "objects/Entities.hpp"
|
||||||
#include "physics/Hitbox.hpp"
|
#include "physics/Hitbox.hpp"
|
||||||
|
|
@ -258,7 +257,6 @@ void LevelScreen::update(float delta) {
|
||||||
}
|
}
|
||||||
updateAudio();
|
updateAudio();
|
||||||
|
|
||||||
auto menu = gui.getMenu();
|
|
||||||
bool inputLocked =
|
bool inputLocked =
|
||||||
gui.getActiveFrame() || hud->isInventoryOpen() || gui.isFocusCaught();
|
gui.getActiveFrame() || hud->isInventoryOpen() || gui.isFocusCaught();
|
||||||
bool paused = hud->isPause();
|
bool paused = hud->isPause();
|
||||||
|
|
@ -284,7 +282,7 @@ void LevelScreen::update(float delta) {
|
||||||
renderer->update(camera, delta * !hud->isPause());
|
renderer->update(camera, delta * !hud->isPause());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelScreen::draw(float delta) {
|
void LevelScreen::draw(float) {
|
||||||
Camera& camera = *playerController->getPlayer().currentCamera;
|
Camera& camera = *playerController->getPlayer().currentCamera;
|
||||||
|
|
||||||
const DrawContext ctx(nullptr, engine.getWindow(), batch.get());
|
const DrawContext ctx(nullptr, engine.getWindow(), batch.get());
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,19 @@ void ChunksRenderer::drawChunks(
|
||||||
if (chunk == nullptr) {
|
if (chunk == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
int cx = chunk->x;
|
||||||
|
int cz = chunk->z;
|
||||||
|
if (culling) {
|
||||||
|
glm::vec3 min(cx * CHUNK_W, chunk->bottom, cz * CHUNK_D);
|
||||||
|
glm::vec3 max(
|
||||||
|
cx * CHUNK_W + CHUNK_W, chunk->top, cz * CHUNK_D + CHUNK_D
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!frustum.isBoxVisible(min, max)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto found = meshes.find(glm::ivec2(chunk->x, chunk->z));
|
auto found = meshes.find(glm::ivec2(chunk->x, chunk->z));
|
||||||
if (found == meshes.end()) {
|
if (found == meshes.end()) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -323,19 +336,19 @@ void ChunksRenderer::drawChunks(
|
||||||
if (mesh.mesh == nullptr) {
|
if (mesh.mesh == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (culling) {
|
if (culling) {
|
||||||
const auto& meshAABB = mesh.meshAABB;
|
const auto& meshAABB = mesh.meshAABB;
|
||||||
auto aabbMin = meshAABB.min();
|
auto aabbMin = meshAABB.min();
|
||||||
auto aabbMax = meshAABB.max();
|
auto aabbMax = meshAABB.max();
|
||||||
|
|
||||||
glm::vec3 min(
|
glm::vec3 min(
|
||||||
chunk->x * CHUNK_W + std::min(0.0f, aabbMin.x),
|
cx * CHUNK_W + std::min(0.0f, aabbMin.x),
|
||||||
chunk->bottom,
|
chunk->bottom,
|
||||||
chunk->z * CHUNK_D + std::min(0.0f, aabbMin.z)
|
cz * CHUNK_D + std::min(0.0f, aabbMin.z)
|
||||||
);
|
);
|
||||||
glm::vec3 max(
|
glm::vec3 max(
|
||||||
chunk->x * CHUNK_W + aabbMax.x,
|
cx * CHUNK_W + aabbMax.x, chunk->top, cz * CHUNK_D + aabbMax.z
|
||||||
chunk->top,
|
|
||||||
chunk->z * CHUNK_D + aabbMax.z
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!frustum.isBoxVisible(min, max)) {
|
if (!frustum.isBoxVisible(min, max)) {
|
||||||
|
|
@ -388,22 +401,23 @@ void ChunksRenderer::drawSortedMeshes(const Camera& camera, Shader& shader) {
|
||||||
if (chunk == nullptr || !chunk->flags.lighted) {
|
if (chunk == nullptr || !chunk->flags.lighted) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& found = meshes.find(glm::ivec2(chunk->x, chunk->z));
|
|
||||||
if (found == meshes.end() || found->second.sortingMeshData.entries.empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int cx = chunk->x;
|
||||||
|
int cz = chunk->z;
|
||||||
if (culling) {
|
if (culling) {
|
||||||
glm::vec3 min(chunk->x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
glm::vec3 min(cx * CHUNK_W, chunk->bottom, cz * CHUNK_D);
|
||||||
glm::vec3 max(
|
glm::vec3 max(
|
||||||
chunk->x * CHUNK_W + CHUNK_W,
|
cx * CHUNK_W + CHUNK_W, chunk->top, cz * CHUNK_D + CHUNK_D
|
||||||
chunk->top,
|
|
||||||
chunk->z * CHUNK_D + CHUNK_D
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!frustum.isBoxVisible(min, max)) continue;
|
if (!frustum.isBoxVisible(min, max)) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& found = meshes.find(glm::ivec2(cx, cz));
|
||||||
|
if (found == meshes.end() || found->second.sortingMeshData.entries.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto& chunkEntries = found->second.sortingMeshData.entries;
|
auto& chunkEntries = found->second.sortingMeshData.entries;
|
||||||
|
|
||||||
if (chunkEntries.size() == 1) {
|
if (chunkEntries.size() == 1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue