This commit is contained in:
Nanako 2025-02-08 21:08:42 +08:00
parent b38aa6d65b
commit df4e8d2aae
3 changed files with 42 additions and 26 deletions

View File

@ -3,6 +3,12 @@ cmake_policy(SET CMP0167 NEW)
project(mirage LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 26)
if (MSVC)
# MSVCC++
add_compile_options(/std:c++latest)
# utf-8
add_compile_options(/utf-8)
endif ()
set(MSDFGEN_USE_SKIA OFF CACHE BOOL "Use Skia for MSDFGen" FORCE)
set(MSDFGEN_USE_VCPKG OFF CACHE BOOL "Use VCPKG for MSDFGen" FORCE)

View File

@ -1,30 +1,35 @@
#include "async/thread_pool.h"
#include "mirage.h"
#include "mirage.h"
using time_type = decltype(std::chrono::high_resolution_clock::now());
std::chrono::duration<double> delta_time = {};
time_type begin_time = {};
time_type last_time = {};
LLGL::RenderSystemPtr renderer = nullptr;
#include "async/thread_pool.h"
mirage::duration_type delta_time = {};
mirage::time_type begin_time = {};
mirage::time_type last_time = {};
LLGL::RenderSystemPtr renderer = nullptr;
namespace mirage {
void on_llgl_log(LLGL::Log::ReportType type, const char* text, void* user_data) {
switch (type) {
case LLGL::Log::ReportType::Default:
spdlog::info(text);
break;
spdlog::info(text);
break;
case LLGL::Log::ReportType::Error:
spdlog::error(text);
break;
spdlog::error(text);
break;
}
}
std::string to_string(renderer_api api) {
switch (api) {
case renderer_api::dx11: return "Direct3D11";
case renderer_api::dx12: return "Direct3D12";
case renderer_api::vulkan: return "Vulkan";
case renderer_api::opengl: return "OpenGL";
case renderer_api::metal: return "Metal";
case renderer_api::dx11:
return "Direct3D11";
case renderer_api::dx12:
return "Direct3D12";
case renderer_api::vulkan:
return "Vulkan";
case renderer_api::opengl:
return "OpenGL";
case renderer_api::metal:
return "Metal";
}
return "Unknown";
}
@ -44,24 +49,24 @@ namespace mirage {
}
bool init(const init_info& in_info) {
spdlog::info("初始化 mirage");
spdlog::info("初始化 mirage");
if (!init_renderer(in_info)) {
return false;
}
begin_time = std::chrono::high_resolution_clock::now();
last_time = std::chrono::high_resolution_clock::now();
last_time = std::chrono::high_resolution_clock::now();
return true;
}
void destroy() {
renderer.reset();
spdlog::info("mirage 销毁");
spdlog::info("mirage 销毁");
}
void update() {
thread_pool::global().process_main_thread_callbacks();
// 更新时间
// 更新时间
const auto& current_time = std::chrono::high_resolution_clock::now();
delta_time = current_time - last_time;
last_time = current_time;
@ -93,9 +98,11 @@ namespace mirage {
return 0;
}
const std::chrono::duration<double>& get_delta_time() { return delta_time; }
const duration_type& get_delta_time() {
return delta_time;
}
std::chrono::duration<double> get_total_time() {
return std::chrono::high_resolution_clock::now() - begin_time;
}
duration_type get_total_time() {
return std::chrono::high_resolution_clock::now() - begin_time;
}
}

View File

@ -7,6 +7,9 @@
#define MIRAGE_VERSION_PATCH 0
namespace mirage {
using time_type = decltype(std::chrono::high_resolution_clock::now());
using duration_type = decltype(std::chrono::high_resolution_clock::now() - std::chrono::high_resolution_clock::now());
enum class renderer_api {
dx11,
dx12,
@ -25,6 +28,6 @@ namespace mirage {
};
int run(const init_info& in_init_info);
const std::chrono::duration<double>& get_delta_time();
std::chrono::duration<double> get_total_time();
const duration_type& get_delta_time();
duration_type get_total_time();
}