//
// Created by m on 12/13/21.
//

#ifndef RLA_IIPP_ALGORITHMMANAGER_HPP
#define RLA_IIPP_ALGORITHMMANAGER_HPP
#include <sol/sol.hpp>
#include <range/v3/view.hpp>
struct DungeonAlgorithm {
    unsigned int frames_per_update=1;
    sol::protected_function update;
    sol::protected_function initialize;
    std::string name;
};

class AlgorithmManager {
private:
    std::vector<DungeonAlgorithm> algorithms;
    unsigned int target_fps=1;
    unsigned int ticks=0;
    DungeonAlgorithm* loaded_algorithm = nullptr;
    bool algorithm_done = false;
public:
    void register_algorithm(std::string name, sol::function initialize, sol::function update, unsigned int updates_per_second);
    ranges::any_view<DungeonAlgorithm*, ranges::category::random_access | ranges::category::sized> get_algorithms();
    void load_algorithm(DungeonAlgorithm* algorithm, int w, int h);
    void tick_algorithm();
    explicit AlgorithmManager(unsigned int targetFps) : target_fps(targetFps) {}
    AlgorithmManager() = default;
};


#endif //RLA_IIPP_ALGORITHMMANAGER_HPP
