This commit is contained in:
2026-05-02 15:18:39 +02:00
parent 8be2cea49a
commit 56d567b77d
19 changed files with 634 additions and 94 deletions

View File

@@ -1,4 +1,5 @@
#include <renderer/renderer.hpp>
#include <algorithm>
#include <utils.hpp>
#include <state/gamestate.hpp>
#include <object/entity.hpp>
@@ -57,12 +58,26 @@ namespace Game::Renderer {
RendererConfig config{ camX, camY, screenW, screenH };
try {
auto entities = Game::State::GameState::getInstance().getEntitiesSnapshot(true);
for (auto* entity : entities) {
if (entity) {
entity->render(this, config);
Game::State::GameState::getInstance().withEntitiesLocked([&](auto& entities) {
std::vector<Game::Object::Entity*> renderOrder;
renderOrder.reserve(entities.size());
for (auto& [name, entity] : entities) {
(void)name;
if (entity) {
renderOrder.push_back(entity.get());
}
}
}
std::sort(renderOrder.begin(), renderOrder.end(), [](Game::Object::Entity* a, Game::Object::Entity* b) {
return a->getZIndex() < b->getZIndex();
});
for (auto* entity : renderOrder) {
if (entity && entity->isActive()) {
entity->render(this, config);
}
}
});
} catch (const std::exception& e) {
ERROR("Exception while rendering frame: " << e.what());
}