//
// Created by sebastian on 08.02.26.
//

#include "RenderSystem.h"

void RenderSystem::render(EntityManager &entityManager, MasterRenderer &renderer) {
    for (auto id : entityManager.getAllEntities()) {

        auto transform = entityManager.getComponent<TransformComponent>(id);
        auto model = entityManager.getComponent<ModelComponent>(id);
        auto tileRenderingComponent = entityManager.getComponent<TileRenderComponent>(id);

        if (!transform || !model) continue;

        if (tileRenderingComponent) {
            renderer.submitTerrainTile(transform, model, tileRenderingComponent);
        } else {
            Entity entity = Entity(model->model, transform->position, transform->rotation.x, transform->rotation.y, transform->rotation.z, transform->scale);
            renderer.submitEntity(std::make_unique<Entity>(entity));
        }

    }
}
