igra
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user