Remove old module system

This commit is contained in:
Jiga228
2025-10-07 21:07:54 +07:00
parent bb48fb6dfb
commit d5261561ed
10 changed files with 6 additions and 271 deletions
+3 -73
View File
@@ -13,8 +13,6 @@
#include "Log/Log.h"
#include "Game/SaveMap/SaveMap.h"
CoreInstance* CoreInstance::self = nullptr;
extern GameInstance* GameFactory(CoreInstance&);
std::shared_ptr<SaveMap> CoreInstance::MainConfig::save()
@@ -31,17 +29,8 @@ void CoreInstance::MainConfig::load(std::shared_ptr<SaveMap> save)
min_CPU_count = save->GetInteger("min_CPU_count");
}
void CoreInstance::Quit_callback()
{
self->game_->quit();
}
CoreInstance::CoreInstance()
{
self = this;
callbacks_.Quit = &Quit_callback;
countCPU_ = System::getCountCPU();
memorySize_ = System::getMemorySize();
@@ -87,8 +76,6 @@ CoreInstance::CoreInstance()
CoreInstance::~CoreInstance()
{
for (auto& module : modules_)
System::QuitModule(module.handler);
modules_.clear();
delete render_engine_;
@@ -100,31 +87,11 @@ CoreInstance::~CoreInstance()
void CoreInstance::start()
{
for (auto& name : main_config_.modules_names)
{
try
{
void* handler = System::InitModule(name.c_str(), &callbacks_);
modules_.push_back(Module {name.c_str(), handler});
} catch (const std::exception& e)
{
std::cout << e.what() << '\n';
}
}
for (auto& module : modules_)
{
try
{
System::StartModule(module.handler);
} catch (const std::exception& e)
{
std::cout << e.what() << '\n';
}
}
std::thread game_thread(&GameInstance::start, game_);
// Main thread is render
render_engine_->start();
game_->stop();
game_thread.join();
}
@@ -135,40 +102,3 @@ void CoreInstance::quit()
render_engine_->stop_render();
}
void* CoreInstance::getHandlerModule(const char* name) const
{
for (const auto& module : modules_)
{
if (std::strcmp(module.name, name) == 0)
return module.handler;
}
throw std::runtime_error("Module not found");
}
void* CoreInstance::enableModule(const char* name)
{
for (const auto& module : modules_)
{
if (std::strcmp(module.name, name) == 0)
throw std::runtime_error("Module already enabled");
}
void* module = System::InitModule(name, &callbacks_);
modules_.push_back({ name, module });
return module;
}
void CoreInstance::disableModule(const char* name)
{
for (auto i = modules_.cbegin(); i != modules_.cend(); ++i)
{
if (std::strcmp(i->name, name) == 0)
{
System::QuitModule(i->handler);
modules_.erase(i);
break;
}
}
throw std::runtime_error("Module not found");
}
-25
View File
@@ -44,14 +44,8 @@ class CoreInstance {
RenderEngine* render_engine_;
GameInstance* game_;
static CoreInstance* self;
CoreCallBacks callbacks_;
bool is_ready = false;
#pragma region Callbacks
static void Quit_callback();
#pragma endregion
public:
CoreInstance();
~CoreInstance();
@@ -64,23 +58,4 @@ public:
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);
};
-19
View File
@@ -15,23 +15,4 @@ namespace System {
* @return memory size in MB
*/
double getMemorySize();
/**
* Load module and init handler
* @throws std::runtime_error if module not found
* @return module handler
*/
void* InitModule(const char* ModuleName, CoreCallBacks* callbacks);
/**
* Start module
* @throws std::runtime_error if module not contains StartModule function
*/
void StartModule(void* handler) noexcept(false);
/**
* Call stop module
* @throws std::runtime_error if module not contains QuitModule function
*/
void QuitModule(void* handler) noexcept(false);
}
-34
View File
@@ -41,38 +41,4 @@ double System::getMemorySize() {
return static_cast<double>(memStatus.ullTotalPhys) / 1024. / 1024.;
}
void* System::InitModule(const char* ModuleName, CoreCallBacks* callbacks) {
std::string fileName = ModuleName;
fileName += ".dll";
HMODULE hModule = LoadLibraryA(fileName.c_str());
if(hModule == nullptr)
throw std::runtime_error(std::to_string(GetLastError()).c_str());
void(*load)(CoreCallBacks*) = reinterpret_cast<void(*)(CoreCallBacks*)>(GetProcAddress(hModule, "InitModule"));
if(load == nullptr) {
throw std::runtime_error(std::to_string(GetLastError()).c_str());
}
load(callbacks);
return hModule;
}
void System::StartModule(void* handler) {
void(*start)() = reinterpret_cast<void(*)()>(GetProcAddress(static_cast<HMODULE>(handler), "StartModule"));
if(start == nullptr) {
throw std::runtime_error(std::to_string(GetLastError()).c_str());
}
start();
}
void System::QuitModule(void* handler) {
void(*quit)() = reinterpret_cast<void(*)()>(GetProcAddress(static_cast<HMODULE>(handler), "QuitModule"));
if(quit == nullptr) {
throw std::runtime_error(std::to_string(GetLastError()).c_str());
}
quit();
FreeLibrary(static_cast<HMODULE>(handler));
}
#endif
+2
View File
@@ -17,8 +17,10 @@ class GameInstance
std::atomic<bool> is_running = true;
void start();
// Stop call from core
void stop();
public:
// Stop call from game
void quit();
// Init vulkan