basic movement
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <utils.hpp>
|
||||
#include <state/gamestate.hpp>
|
||||
#include <object/entity.hpp>
|
||||
#include <window/window.hpp>
|
||||
#include <object/camera.hpp>
|
||||
|
||||
namespace Game::Renderer {
|
||||
Renderer::Renderer() : mRenderer(nullptr) {}
|
||||
@@ -39,12 +41,20 @@ namespace Game::Renderer {
|
||||
void Renderer::renderFrame() {
|
||||
mClear();
|
||||
|
||||
float camX, camY;
|
||||
Object::Camera::getInstance().getPosition(camX, camY);
|
||||
int screenW, screenH;
|
||||
SDL_GetWindowSizeInPixels(Window::Window::getSDLWindowBackend(), &screenW, &screenH);
|
||||
// Pass the config to avoid wasting time recalculating it for every entity, since it's not gonna change during the frame
|
||||
RendererConfig config{ camX, camY, screenW, screenH };
|
||||
|
||||
try {
|
||||
Game::State::GameState::getInstance().withEntitiesLocked([this](auto& entities) {
|
||||
for (auto& entity : entities) {
|
||||
entity->render(this);
|
||||
auto entities = Game::State::GameState::getInstance().getEntitiesSnapshot(true);
|
||||
for (auto* entity : entities) {
|
||||
if (entity) {
|
||||
entity->render(this, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
ERROR("Exception while rendering frame: " << e.what());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user