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