Files
UwU-Engine/Core/Core/CoreInstance.h
T
2025-09-19 20:01:00 +07:00

84 lines
2.0 KiB
C++

#pragma once
#include <string>
#include <list>
#include <memory>
#include <vector>
#include "Game/SaveMap/ISave.h"
#include "Core/CoreCallBacks.h"
class SaveMap;
class RenderEngine;
class GameInstance;
struct GLFWwindow;
class CoreInstance {
struct Module {
const char* name;
void* handler;
};
struct MainConfig final : ISave
{
std::string game_name;
std::string base_world;
std::vector<std::string> modules_names;
double min_memory_size = -1;
long long min_CPU_count = -1;
std::shared_ptr<SaveMap> save() override;
void load(std::shared_ptr<SaveMap> save) override;
};
const char* main_config_name = "main_config.conf";
MainConfig main_config_;
int countCPU_;
// Memory in MB
double memorySize_;
std::list<Module> modules_;
GLFWwindow* window_ = nullptr;
RenderEngine* render_engine_;
GameInstance* game_;
static CoreInstance* self;
CoreCallBacks callbacks_;
#pragma region Callbacks
static void Quit_callback();
#pragma endregion
public:
CoreInstance();
~CoreInstance();
void start();
void quit();
int getCountCPU() const { return countCPU_; }
double getMemorySize() const { return memorySize_; }
const std::string& getBaseWorldName() const { return main_config_.base_world; }
const std::string& getGameName() const { return main_config_.game_name; }
/**
* @throws std::runtime_error if module isn't enabled
* @throws std::runtime_error if module not found
* @return module handler
*/
void* getHandlerModule(const char* name) const noexcept(false);
/**
* @throws std::runtime_error if the module already enabled
* @throws std::runtime_error if the module isn't found
* @throws std::runtime_error if the module doesn't contain InitModule or StartModule
* @retuen module handler
*/
void* enableModule(const char* name) noexcept(false);
/**
* @throws std::runtime_error if the module isn't found
* @throws std::runtime_error module isn't contain QuitModule function
*/
void disableModule(const char* name) noexcept(false);
};