From f15c8b09cdae60a831d8604a54788a09d646d352 Mon Sep 17 00:00:00 2001 From: Jiga228 Date: Mon, 15 Sep 2025 19:13:39 +0700 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5=D1=80=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8C.=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D1=83=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D0=BC=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D0=B9=20=D0=BA=20=D1=8F=D0=B4=D1=80=D1=83.=20=D0=98?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B1=D0=B0=D0=B3?= =?UTF-8?q?=20=D0=B2=20SaveMap.=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20linux,=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=20=D0=BA=D0=B0=D0=BA=20=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=B4=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=B8=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BE=D0=B1=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=84=D0=BE=D1=80=D0=BC=D1=8B.=20=D0=A3?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20linux.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ubuntu-test.yml | 42 ----------- CMakeLists.txt | 1 + Core/Core/CoreCallBacks.h | 6 ++ Core/Core/CoreInstance.cpp | 35 ++++++++-- Core/Core/CoreInstance.h | 32 +++++---- Core/Core/Linux.cpp | 15 +--- Core/Core/RenderEngine.h | 36 ---------- Core/Core/SystemCalls.h | 16 ++--- Core/Core/Windows.cpp | 19 ++--- Core/Game/GameInstance.cpp | 4 -- Core/Game/GameInstance.h | 2 - Core/Game/SaveMap/SaveMap.cpp | 8 +-- ModuleLib/ModuleInstance.cpp | 57 ++++++--------- ModuleLib/ModuleInstance.h | 18 ++--- RenderModule/CMakeLists.txt | 23 ++++++ {Core/Core => RenderModule}/RenderEngine.cpp | 73 ++++++++++---------- RenderModule/RenderEngine.h | 31 +++++++++ TestGame/main_config.conf | 2 +- 18 files changed, 193 insertions(+), 227 deletions(-) delete mode 100644 .github/workflows/ubuntu-test.yml create mode 100644 Core/Core/CoreCallBacks.h delete mode 100644 Core/Core/RenderEngine.h create mode 100644 RenderModule/CMakeLists.txt rename {Core/Core => RenderModule}/RenderEngine.cpp (83%) create mode 100644 RenderModule/RenderEngine.h diff --git a/.github/workflows/ubuntu-test.yml b/.github/workflows/ubuntu-test.yml deleted file mode 100644 index da63f63..0000000 --- a/.github/workflows/ubuntu-test.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Ubuntu test - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - BUILD_TYPE: Release - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository with submodules - uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 1 - - - name: Проверка содержимого glfw - run: ls -la glfw - - - name: Install dependencies (Wayland, X11, Vulkan, OpenGL) - run: | - sudo apt-get update - sudo apt-get install -y \ - wayland-protocols libwayland-dev libxkbcommon-dev \ - libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \ - libvulkan-dev mesa-common-dev - - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Build - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - #- name: Test - # working-directory: ${{github.workspace}}/build - # run: ctest -C ${{env.BUILD_TYPE}} diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d6e0a6..9bf010c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,5 +20,6 @@ add_subdirectory(FastRTTI) add_subdirectory(glfw) add_subdirectory(Core) add_subdirectory(ModuleLib) +add_subdirectory(RenderModule) add_subdirectory(TestGame) add_subdirectory(ProjectGenerator) diff --git a/Core/Core/CoreCallBacks.h b/Core/Core/CoreCallBacks.h new file mode 100644 index 0000000..9a0ecfd --- /dev/null +++ b/Core/Core/CoreCallBacks.h @@ -0,0 +1,6 @@ +#pragma once + +struct CoreCallBacks +{ + void (*Quit)(); +}; \ No newline at end of file diff --git a/Core/Core/CoreInstance.cpp b/Core/Core/CoreInstance.cpp index 88036b2..30e719b 100644 --- a/Core/Core/CoreInstance.cpp +++ b/Core/Core/CoreInstance.cpp @@ -1,12 +1,17 @@ #include "CoreInstance.h" #include "SystemCalls.h" +#include "GLFW/glfw3.h" #include #include #include #include +#include "Log/Log.h" + +CoreInstance* CoreInstance::self = nullptr; + std::shared_ptr CoreInstance::MainConfig::save() { return std::make_shared("MainConfig"); @@ -17,12 +22,31 @@ void CoreInstance::MainConfig::load(std::shared_ptr save) game_name = save->GetString("game_name"); base_world = save->GetString("base_world"); modules_names = save->GetVectorString("modules_names"); + min_memory_size = save->GetDouble("min_memory_size"); + 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(); + + if (!glfwInit()) + { + std::string msg; + const char* error; + glfwGetError(&error); + throw std::runtime_error("Fail initialize GLFW"); + } std::ifstream main_config_file(main_config_name); if (main_config_file.fail()) @@ -30,15 +54,14 @@ CoreInstance::CoreInstance() std::string payload; std::getline(main_config_file, payload); - std::shared_ptr load_main_config = std::make_shared(payload); + SaveMap load_main_config(payload); - main_config.load(load_main_config); + main_config.load(std::make_shared(load_main_config)); } CoreInstance::~CoreInstance() { - if (game != nullptr) - delete game; + delete game; for (auto& module : modules) System::QuitModule(module.handler); @@ -53,7 +76,7 @@ void CoreInstance::start() { try { - void* handler = System::InitModule(name.c_str(), *this); + void* handler = System::InitModule(name.c_str(), &callbacks_); modules.push_back(Module {name.c_str(), handler}); } catch (const std::exception& e) { @@ -96,7 +119,7 @@ void* CoreInstance::enableModule(const char* name) throw std::runtime_error("Module already enabled"); } - void* module = System::InitModule(name, *this); + void* module = System::InitModule(name, &callbacks_); modules.push_back({ name, module }); return module; } diff --git a/Core/Core/CoreInstance.h b/Core/Core/CoreInstance.h index 8106fd3..9668f1c 100644 --- a/Core/Core/CoreInstance.h +++ b/Core/Core/CoreInstance.h @@ -5,8 +5,10 @@ #include "Game/GameInstance.h" #include "Game/SaveMap/SaveMap.h" +#include "Core/CoreCallBacks.h" class CoreInstance { + static CoreInstance* self; struct Module { const char* name; void* handler; @@ -17,37 +19,41 @@ class CoreInstance { std::string game_name; std::string base_world; std::vector modules_names; + + double min_memory_size = -1; + int min_CPU_count = -1; std::shared_ptr save() override; void load(std::shared_ptr save) override; }; - -#pragma region Key words for main config - const char* key_base_world= "base_world"; - const char* key_modules = "modules"; -#pragma endregion - -#pragma region config parameters + const char* main_config_name = "main_config.conf"; - // std::string base_world; - // std::vector modules_names; - // std::string game_name; MainConfig main_config; -#pragma endregion int countCPU; - unsigned long long memorySize; + // Memory in MB + double memorySize; std::list modules; GameInstance* game = nullptr; + CoreCallBacks callbacks_; + +#pragma region Callbacks + static void Quit_callback(); +#pragma endregion public: CoreInstance(); ~CoreInstance(); void start(); + + /** + * This method quit game + * Async + */ int getCountCPU() const { return countCPU; } - unsigned long long getMemorySize() const { return memorySize; } + double getMemorySize() const { return memorySize; } /** * @throws std::runtime_error if module isn't enabled diff --git a/Core/Core/Linux.cpp b/Core/Core/Linux.cpp index 7a2ad17..4e93d75 100644 --- a/Core/Core/Linux.cpp +++ b/Core/Core/Linux.cpp @@ -18,12 +18,12 @@ int System::getCountCPU() return num_cores; } -unsigned long long System::getMemorySize() +double System::getMemorySize() { struct sysinfo info{}; - if(sysinfo(&info) == -1) + if(sysinfo(&info) == -1) std::runtime_error("Fail get system info"); - return info.totalram; + return info.totalram / 1024 / 1024; } void* System::InitModule(const char* ModuleName, CoreInstance& core) @@ -52,15 +52,6 @@ void System::StartModule(void* handler) start(); } -void System::StopModule(void* handler) -{ - void(*stop)() = reinterpret_cast(dlsym(handler, "StopModule")); - if(stop == nullptr) - std::runtime_error("Module mot contins StopModule"); - stop(); - dlclose(handler); -} - void System::QuitModule(void* handler) { void(*quit)() = reinterpret_cast(dlsym(handler, "QuitModule")); diff --git a/Core/Core/RenderEngine.h b/Core/Core/RenderEngine.h deleted file mode 100644 index 8703a14..0000000 --- a/Core/Core/RenderEngine.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#define GLFW_INCLUDE_VULKAN - -#include "Delegate/Delegate.h" -#include -#include -#include - -#include "GLFW/glfw3.h" - -class RenderEngine -{ - std::thread* render_thread; - - GLFWwindow* window; - VkInstance instance_; - - -#ifdef _DEBUG - VkResult enable_layer_validation(VkInstance instance, VkDebugUtilsMessengerCreateInfoEXT* create_info); - VkDebugUtilsMessengerEXT debug_messenger_; -#endif - - static std::vector get_required_extensions(); - void render_thread_func(); -public: - Delegate onCloseWindow; - - RenderEngine(const std::string& app_name, - int major_app_version, int minor_app_version, int patch_app_version, - int major_engine_version, int minor_engine_version, int patch_engine_version); - ~RenderEngine(); - - void start(); -}; \ No newline at end of file diff --git a/Core/Core/SystemCalls.h b/Core/Core/SystemCalls.h index 49302cb..2a7f8e2 100644 --- a/Core/Core/SystemCalls.h +++ b/Core/Core/SystemCalls.h @@ -2,32 +2,32 @@ class CoreInstance; +struct CoreCallBacks; + namespace System { /** * @throws std::exception if the operation finished with failed * @return count CPU */ int getCountCPU(); - unsigned long long getMemorySize(); + /* + * @throws std::runtime_error + * @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, CoreInstance& core); + 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); - - /** - * Stop the module when unload there - * @throws std::runtime_error if module not contains StopModule function - */ - void StopModule(void* handler) noexcept(false); /** * Call stop module diff --git a/Core/Core/Windows.cpp b/Core/Core/Windows.cpp index b926e23..41ab21c 100644 --- a/Core/Core/Windows.cpp +++ b/Core/Core/Windows.cpp @@ -33,15 +33,15 @@ int System::getCountCPU() { return physicalCoreCount; } -unsigned long long System::getMemorySize() { +double System::getMemorySize() { MEMORYSTATUSEX memStatus{}; memStatus.dwLength = sizeof(memStatus); GlobalMemoryStatusEx(&memStatus); - return memStatus.ullTotalPhys; + return memStatus.ullTotalPhys / 1024 / 1024; } -void* System::InitModule(const char* ModuleName, CoreInstance& core) { +void* System::InitModule(const char* ModuleName, CoreCallBacks* callbacks) { std::string fileName = ModuleName; fileName += ".dll"; @@ -49,11 +49,11 @@ void* System::InitModule(const char* ModuleName, CoreInstance& core) { if(hModule == nullptr) throw std::runtime_error(std::to_string(GetLastError()).c_str()); - void(*load)(CoreInstance&) = reinterpret_cast(GetProcAddress(hModule, "InitModule")); + void(*load)(CoreCallBacks*) = reinterpret_cast(GetProcAddress(hModule, "InitModule")); if(load == nullptr) { throw std::runtime_error(std::to_string(GetLastError()).c_str()); } - load(core); + load(callbacks); return hModule; } @@ -66,15 +66,6 @@ void System::StartModule(void* handler) { start(); } -void System::StopModule(void* handler) { - void(*stop)() = reinterpret_cast(GetProcAddress(static_cast(handler), "StopModule")); - if(stop == nullptr) { - throw std::runtime_error(std::to_string(GetLastError()).c_str()); - } - stop(); - FreeLibrary(static_cast(handler)); -} - void System::QuitModule(void* handler) { void(*quit)() = reinterpret_cast(GetProcAddress(static_cast(handler), "QuitModule")); if(quit == nullptr) { diff --git a/Core/Game/GameInstance.cpp b/Core/Game/GameInstance.cpp index fd428be..7442993 100644 --- a/Core/Game/GameInstance.cpp +++ b/Core/Game/GameInstance.cpp @@ -6,7 +6,6 @@ #include #include "Core/CoreInstance.h" -#include "Core/RenderEngine.h" #include "Game/WorldFactory.h" #include "SaveMap/SaveMap.h" #include "Game/World/World.h" @@ -15,8 +14,6 @@ extern std::vector world_factories; GameInstance::GameInstance(CoreInstance& core) : core(core) { - render_engine_ = std::make_unique(core.getGameName(), 0, 0, 0, 0, 0, 0); - render_engine_->onCloseWindow.bind(this, &GameInstance::quit); const std::string& base_world = core.getBaseWorldName(); // Init directories @@ -51,7 +48,6 @@ GameInstance::~GameInstance() void GameInstance::start() { - render_engine_->start(); world->BeginPlay(); auto first = std::chrono::steady_clock::now(); diff --git a/Core/Game/GameInstance.h b/Core/Game/GameInstance.h index 50415ea..6fc0fc3 100644 --- a/Core/Game/GameInstance.h +++ b/Core/Game/GameInstance.h @@ -5,7 +5,6 @@ class CoreInstance; class World; -class RenderEngine; #define GENERATE_FACTORY_GAME_INSTANCE(Class) \ GameInstance* GameFactory(CoreInstance& core) { return new Class(core); } @@ -14,7 +13,6 @@ class GameInstance { CoreInstance& core; World* world = nullptr; - std::unique_ptr render_engine_; std::atomic is_running = true; diff --git a/Core/Game/SaveMap/SaveMap.cpp b/Core/Game/SaveMap/SaveMap.cpp index 8a81af1..f6df842 100644 --- a/Core/Game/SaveMap/SaveMap.cpp +++ b/Core/Game/SaveMap/SaveMap.cpp @@ -49,17 +49,17 @@ SaveMap::SaveMap(const std::string& json_data) } if (name[0] == 'i') { - size_t begin = json_data.find(':', i) + 1; + size_t begin = json_data.find(':', i) + 2; size_t end = i = json_data.find_first_of(",}", i); i++; - std::string value = json_data.substr(begin, end - begin); + std::string value = json_data.substr(begin, end - begin - 1); save_long[name.c_str() + 1] = std::stoll(value); } else if (name[0] == 'd') { - size_t begin = json_data.find(':', i) + 1; + size_t begin = json_data.find(':', i) + 2; size_t end = i = json_data.find_first_of(",}", i); i++; - std::string value = json_data.substr(begin, end - begin); + std::string value = json_data.substr(begin, end - begin - 1); save_double[name.c_str() + 1] = std::stod(value); } else if (name[0] == 's') { diff --git a/ModuleLib/ModuleInstance.cpp b/ModuleLib/ModuleInstance.cpp index 4711f8a..0de6931 100644 --- a/ModuleLib/ModuleInstance.cpp +++ b/ModuleLib/ModuleInstance.cpp @@ -3,14 +3,18 @@ #include #include -ModuleInstance::ModuleInstance(CoreInstance& core) : core_(core) -{ - // Init instance -} +#include "Core/CoreCallBacks.h" + +extern ModuleInstance* Factory(); + +static std::mutex mModuleInstance; +static ModuleInstance* module = nullptr; +static std::thread* moduleThread; +// Don't free. It's memory free in core +static CoreCallBacks* callbacks_; void ModuleInstance::start() { - // Create thread } void ModuleInstance::stop() @@ -18,51 +22,36 @@ void ModuleInstance::stop() onStop.Call(); } - -extern ModuleInstance* Factory(CoreInstance&); - -static std::mutex mModuleInstance; -static ModuleInstance* module = nullptr; -static std::thread* moduleThread; - -void InitModule(CoreInstance& core) +void ModuleInstance::QuitGame() { - mModuleInstance.lock(); + callbacks_->Quit(); +} + +void InitModule(CoreCallBacks* callbacks) +{ + std::lock_guard lock(mModuleInstance); + callbacks_ = callbacks; if(module == nullptr) - module = Factory(core); - mModuleInstance.unlock(); + module = Factory(); } void StartModule() { - mModuleInstance.lock(); + std::lock_guard lock(mModuleInstance); if (module != nullptr) - moduleThread = new std::thread([&] {module->start(); }); - mModuleInstance.unlock(); -} - -void StopModule() -{ - mModuleInstance.lock(); - if(module != nullptr) - { - delete module; - module = nullptr; - moduleThread->detach(); - delete moduleThread; - } - mModuleInstance.unlock(); + moduleThread = new std::thread(&ModuleInstance::start, module); } void QuitModule() { - mModuleInstance.lock(); + std::lock_guard lock(mModuleInstance); if(module != nullptr) { module->stop(); moduleThread->join(); delete module; module = nullptr; + delete moduleThread; + moduleThread = nullptr; } - mModuleInstance.unlock(); } diff --git a/ModuleLib/ModuleInstance.h b/ModuleLib/ModuleInstance.h index 4cbf820..fc53ca6 100644 --- a/ModuleLib/ModuleInstance.h +++ b/ModuleLib/ModuleInstance.h @@ -17,39 +17,31 @@ extern "C" {\ EXPORT void* protect_init() {return reinterpret_cast(&InitModule);} \ EXPORT void* protect_start() {return reinterpret_cast(&StartModule);} \ -EXPORT void* protect_stop() {return reinterpret_cast(&StopModule);} \ EXPORT void* protect_quit() {return reinterpret_cast(&QuitModule);} \ }\ -ModuleInstance* Factory(CoreInstance& core) { return static_cast(new Class(core)); } +ModuleInstance* Factory() { return static_cast(new Class()); } - -class CoreInstance; +struct CoreCallBacks; class ModuleInstance { - CoreInstance& core_; - public: Delegate onStop; - ModuleInstance(CoreInstance& core); virtual ~ModuleInstance() = default; - - CoreInstance& getCore() const { return core_; } virtual void start(); void stop(); + + void QuitGame(); }; extern "C" { // Create module instance - EXPORT void InitModule(CoreInstance& core); + EXPORT void InitModule(CoreCallBacks* callbacks); // Start module instance EXPORT void StartModule(); - // Destroy module instance when core unloads there - EXPORT void StopModule(); - // Stop module when core calls this EXPORT void QuitModule(); } diff --git a/RenderModule/CMakeLists.txt b/RenderModule/CMakeLists.txt new file mode 100644 index 0000000..7eda801 --- /dev/null +++ b/RenderModule/CMakeLists.txt @@ -0,0 +1,23 @@ +find_package(Vulkan REQUIRED) + +file(GLOB_RECURSE SRC "*.cpp" "*.c" "*.h" "*.hpp") +add_library(RenderModule SHARED ${SRC}) + +target_compile_features(RenderModule PRIVATE cxx_std_17) + +target_include_directories(RenderModule + PRIVATE + ${PROJECT_SOURCE_DIR}/ModuleLib + ${PROJECT_SOURCE_DIR}/Core + ${PROJECT_SOURCE_DIR}/FastRTTI + ${PROJECT_SOURCE_DIR}/Delegate + ${PROJECT_SOURCE_DIR}/glfw/Include + ${Vulkan_INCLUDE_DIRS} +) + +target_link_libraries(RenderModule PRIVATE + ModuleLib + FastRTTI + glfw + Vulkan::Vulkan +) \ No newline at end of file diff --git a/Core/Core/RenderEngine.cpp b/RenderModule/RenderEngine.cpp similarity index 83% rename from Core/Core/RenderEngine.cpp rename to RenderModule/RenderEngine.cpp index dbf351e..ec07447 100644 --- a/Core/Core/RenderEngine.cpp +++ b/RenderModule/RenderEngine.cpp @@ -2,9 +2,14 @@ #include #include +#include + +#include "Core/CoreInstance.h" + +PROTECTION_FROM_GB(RenderEngine) #ifdef _DEBUG -#include "Log/Log.h" +//#include "Log/Log.h" #include #define VK_CHECK(res) assert(res == VK_SUCCESS) @@ -16,7 +21,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( std::string msg = "validation layer: "; msg += pCallbackData->pMessage; - Log(msg); + //Log(msg); return VK_FALSE; } @@ -42,33 +47,16 @@ std::vector RenderEngine::get_required_extensions() return extensions; } -void RenderEngine::render_thread_func() -{ - window = glfwCreateWindow(640, 480, "UwU Engine", nullptr, nullptr); - if (!window) - { - glfwTerminate(); - throw std::runtime_error("Fail create window"); - } - while (!glfwWindowShouldClose(window)) - { - glfwSwapBuffers(window); - glfwPollEvents(); - } - onCloseWindow.Call(); -} - -RenderEngine::RenderEngine(const std::string& app_name, - int major_app_version, int minor_app_version, int patch_app_version, - int major_engine_version, int minor_engine_version, int patch_engine_version) : - render_thread(nullptr), window(nullptr) +RenderEngine::RenderEngine() : window(nullptr) #ifdef _DEBUG , debug_messenger_(nullptr) #endif { - if (!glfwInit()) - throw std::runtime_error("Fail initialize GLFW"); - + onStop.bind(this, &RenderEngine::stop_render); + + if (glfwInit() == GLFW_FALSE) + throw std::runtime_error("Fail init glfw"); + { std::vector extensions = get_required_extensions(); std::vector layers = { @@ -80,10 +68,10 @@ RenderEngine::RenderEngine(const std::string& app_name, VkApplicationInfo app_info{}; app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app_info.apiVersion = VK_API_VERSION_1_0; - app_info.applicationVersion = VK_MAKE_VERSION(major_app_version, minor_app_version, patch_app_version); - app_info.pApplicationName = app_name.c_str(); + app_info.applicationVersion = VK_MAKE_VERSION(0, 0, 0); + app_info.pApplicationName = "UwU Engine"; app_info.pEngineName = "UwU Engine"; - app_info.engineVersion = VK_MAKE_VERSION(major_engine_version, minor_engine_version, patch_engine_version); + app_info.engineVersion = VK_MAKE_VERSION(0, 0, 0); VkInstanceCreateInfo instance_create_info{}; @@ -123,15 +111,6 @@ RenderEngine::RenderEngine(const std::string& app_name, RenderEngine::~RenderEngine() { - if (window != nullptr && !glfwWindowShouldClose(window)) - glfwSetWindowShouldClose(window, true); - - if (render_thread != nullptr) - { - render_thread->join(); - delete render_thread; - } - #ifdef _DEBUG if (debug_messenger_ != nullptr && instance_ != nullptr) { PFN_vkDestroyDebugUtilsMessengerEXT destroyer_messenger = reinterpret_cast(vkGetInstanceProcAddr(instance_, "vkDestroyDebugUtilsMessengerEXT")); @@ -149,5 +128,23 @@ RenderEngine::~RenderEngine() void RenderEngine::start() { - render_thread = new std::thread(&RenderEngine::render_thread_func, this); + window = glfwCreateWindow(640, 480, "UwU Engine", nullptr, nullptr); + if (!window) + { + glfwTerminate(); + throw std::runtime_error("Fail create window"); + } + + while (!glfwWindowShouldClose(window)) + { + glfwSwapBuffers(window); + glfwPollEvents(); + } + QuitGame(); +} + +void RenderEngine::stop_render() +{ + if (window != nullptr && !glfwWindowShouldClose(window)) + glfwSetWindowShouldClose(window, true); } diff --git a/RenderModule/RenderEngine.h b/RenderModule/RenderEngine.h new file mode 100644 index 0000000..3551b85 --- /dev/null +++ b/RenderModule/RenderEngine.h @@ -0,0 +1,31 @@ +#pragma once + +#define GLFW_INCLUDE_VULKAN +#include "GLFW/glfw3.h" + +#include "ModuleInstance.h" + +#include + +template +class Delegate; + +class RenderEngine : public ModuleInstance +{ + GLFWwindow* window; + VkInstance instance_; + +#ifdef _DEBUG + VkResult enable_layer_validation(VkInstance instance, VkDebugUtilsMessengerCreateInfoEXT* create_info); + VkDebugUtilsMessengerEXT debug_messenger_; +#endif + + static std::vector get_required_extensions(); + + void stop_render(); +public: + RenderEngine(); + ~RenderEngine() override; + + void start() override; +}; \ No newline at end of file diff --git a/TestGame/main_config.conf b/TestGame/main_config.conf index b49aa65..c99154d 100644 --- a/TestGame/main_config.conf +++ b/TestGame/main_config.conf @@ -1 +1 @@ -{"Class name":"MainConfig","sgame_name":"Test Game","sbase_world":"TestWorld","vsmodules_names":[]} \ No newline at end of file +{"Class name":"MainConfig","dmin_memory_size":"4096.0","imin_CPU_count":"1","sgame_name":"Test Game","sbase_world":"TestWorld","vsmodules_names":["RenderModule"]} \ No newline at end of file