// Copyright 2025 Steven Le Rouzic
//
// SPDX-License-Identifier: BSD-3-Clause

#include <asl/logging/logging.hpp>

#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>

#include "hk21/game/gpu.hpp"

int SDL_main(int /* argc */, char* /* argv */[])
{
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow("HK-21 - 460nm", 1280, 720, SDL_WINDOW_VULKAN);

    SDL_ShowWindow(window);

    auto gpu_opt = gpu::init(window);
    if (!gpu_opt.ok())
    {
        ASL_LOG_ERROR("Couldn't initialize GPU: {}", gpu_opt);
        return 1;
    }
    auto gpu = std::move(gpu_opt).value();

    bool running = true;
    while (running)
    {
        SDL_Event e;
        while (SDL_PollEvent(&e))
        {
            if (e.type == SDL_EVENT_QUIT || (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE))
            {
                running = false;
            }
        }

        gpu->frame();

        SDL_Delay(16);
    }

    gpu->destroy();
    
    SDL_DestroyWindow(window);
    SDL_Quit();
    
    return 0;
}