Moved window create from RenderEngine to CoreInstance
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "RenderEngine.h"
|
||||
#include "Game/GameInstance.h"
|
||||
#include "Log/Log.h"
|
||||
#include "Game/SaveMap/SaveMap.h"
|
||||
@@ -55,11 +54,19 @@ CoreInstance::CoreInstance()
|
||||
|
||||
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
||||
|
||||
render_engine_ = new RenderEngine();
|
||||
if (glfwInit() == GLFW_FALSE)
|
||||
throw std::runtime_error("Fail init glfw");
|
||||
window_ = glfwCreateWindow(800, 600, main_config_.game_name.c_str(), nullptr, nullptr);
|
||||
if (window_ == nullptr)
|
||||
{
|
||||
glfwTerminate();
|
||||
throw std::runtime_error("Fail create window");
|
||||
}
|
||||
render_engine_ = new RenderEngine(window_);
|
||||
|
||||
game_ = GameFactory(*this);
|
||||
if (game_ == nullptr)
|
||||
throw std::runtime_error("Fail create game instance!");
|
||||
game_ = GameFactory(*this);
|
||||
if (game_ == nullptr)
|
||||
throw std::runtime_error("Fail create game instance!");
|
||||
}
|
||||
|
||||
CoreInstance::~CoreInstance()
|
||||
@@ -99,7 +106,7 @@ void CoreInstance::start()
|
||||
|
||||
std::thread game_thread(&GameInstance::start, game_);
|
||||
render_engine_->start();
|
||||
game_->quit();
|
||||
game_->stop();
|
||||
game_thread.join();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "RenderEngine.h"
|
||||
#include "Game/SaveMap/ISave.h"
|
||||
#include "Core/CoreCallBacks.h"
|
||||
|
||||
@@ -25,7 +26,7 @@ class CoreInstance {
|
||||
std::vector<std::string> modules_names;
|
||||
|
||||
double min_memory_size = -1;
|
||||
int min_CPU_count = -1;
|
||||
long long min_CPU_count = -1;
|
||||
|
||||
std::shared_ptr<SaveMap> save() override;
|
||||
void load(std::shared_ptr<SaveMap> save) override;
|
||||
@@ -39,6 +40,7 @@ class CoreInstance {
|
||||
double memorySize_;
|
||||
std::list<Module> modules_;
|
||||
|
||||
GLFWwindow* window_ = nullptr;
|
||||
RenderEngine* render_engine_;
|
||||
GameInstance* game_;
|
||||
|
||||
@@ -55,11 +57,6 @@ public:
|
||||
void start();
|
||||
void quit();
|
||||
|
||||
/**
|
||||
* This method quit game
|
||||
* Async
|
||||
*/
|
||||
|
||||
int getCountCPU() const { return countCPU_; }
|
||||
double getMemorySize() const { return memorySize_; }
|
||||
|
||||
|
||||
@@ -42,21 +42,11 @@ std::vector<const char*> RenderEngine::get_required_extensions()
|
||||
return extensions;
|
||||
}
|
||||
|
||||
RenderEngine::RenderEngine() : window(nullptr)
|
||||
RenderEngine::RenderEngine(GLFWwindow* window) : window_(window)
|
||||
#ifdef _DEBUG
|
||||
, debug_messenger_(nullptr)
|
||||
#endif
|
||||
{
|
||||
if (glfwInit() == GLFW_FALSE)
|
||||
throw std::runtime_error("Fail init glfw");
|
||||
|
||||
window = glfwCreateWindow(640, 480, "UwU Engine", nullptr, nullptr);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
throw std::runtime_error("Fail create window");
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<const char*> extensions = get_required_extensions();
|
||||
std::vector<const char*> layers = {
|
||||
@@ -121,22 +111,22 @@ RenderEngine::~RenderEngine()
|
||||
if (instance_ != nullptr)
|
||||
vkDestroyInstance(instance_, nullptr);
|
||||
|
||||
if (window != nullptr)
|
||||
glfwDestroyWindow(window);
|
||||
if (window_ != nullptr)
|
||||
glfwDestroyWindow(window_);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void RenderEngine::start()
|
||||
{
|
||||
while (!glfwWindowShouldClose(window))
|
||||
while (!glfwWindowShouldClose(window_))
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
glfwSwapBuffers(window_);
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::stop_render()
|
||||
{
|
||||
if (window != nullptr && !glfwWindowShouldClose(window))
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
if (window_ != nullptr && !glfwWindowShouldClose(window_))
|
||||
glfwSetWindowShouldClose(window_, true);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
class RenderEngine
|
||||
{
|
||||
GLFWwindow* window;
|
||||
GLFWwindow* window_;
|
||||
VkInstance instance_;
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -19,7 +19,7 @@ class RenderEngine
|
||||
static std::vector<const char*> get_required_extensions();
|
||||
|
||||
public:
|
||||
RenderEngine();
|
||||
RenderEngine(GLFWwindow* window);
|
||||
~RenderEngine();
|
||||
|
||||
void start();
|
||||
|
||||
@@ -63,8 +63,13 @@ void GameInstance::start()
|
||||
}
|
||||
}
|
||||
|
||||
void GameInstance::quit()
|
||||
void GameInstance::stop()
|
||||
{
|
||||
is_running = false;
|
||||
}
|
||||
|
||||
void GameInstance::quit()
|
||||
{
|
||||
stop();
|
||||
core.quit();
|
||||
}
|
||||
|
||||
@@ -16,11 +16,8 @@ class GameInstance
|
||||
|
||||
std::atomic<bool> is_running = true;
|
||||
|
||||
// Create a window
|
||||
// Render
|
||||
// Pull events
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
public:
|
||||
void quit();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user