Files
dl_old/dl/dl_system.cpp
T
2023-06-23 23:47:51 +08:00

164 lines
3.9 KiB
C++

#include "dl_system.h"
#include "io/dl_log.h"
#include <GLFW/glfw3.h>
namespace dl
{
System* g_system = nullptr;
void InitEngine()
{
#if (DL_PLATFORM == DL_PLATFORM_WIN32)
system("chcp 65001");
#endif
g_log = new LogSystem;
g_system = new System;
}
void ReleaseEngine()
{
delete g_system;
delete g_log;
}
class SystemImp
{
public:
SystemImp() :
_window{ nullptr },
_bClearCursorDt{ false }
{}
GLFWwindow* _window;
GLFWmonitor* _monitor;//主显示器
//是否清空光标差值
bool _bClearCursorDt;
};
//大小变化回调函数(创建窗口不会调用)
static void CallbackFrameBufferResize(GLFWwindow* window, int width, int height)
{
/*g_vk->SetFrameBufferResize();
Size size = Math::CastU(Point{ width, height });
g_ui->_resize(size);*/
}
static void CallbackKey(GLFWwindow* window, int key, int scancode, int action, int mods)
{
//action GLFW_PRESS
//mods GLFW_MOD_SHIFT
/*if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);*/
//g_input->_set_key(key, action);
}
static void CallbackChar(GLFWwindow* window, unsigned int codepoint)
{
//string str = CodeCvt::cvt_wc_u8(std::wstring_view((wchar_t*)&codepoint, 1));
//debug_test(format("打字:{}", str));
}
static void CallbackCursorPos(GLFWwindow* window, double xpos, double ypos)
{
/*bool& clear = g_system->GetImp()->_bClearCursorDt;
g_input->_set_cursor((int)xpos, (int)ypos, clear);
clear = false;*/
//debug_test(format("光标移动:{}, {}", xpos, ypos));
}
static void CallbackMouseButton(GLFWwindow* window, int button, int action, int mods)
{
/*if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
popup_menu();*/
//g_input->_set_key_mouse(button, action);
}
System::System()
{
_imp = new SystemImp;
}
System::~System()
{
delete _imp;
}
void System::Start()
{
//------------------创建窗口------------------------
if (!glfwInit())
{
log("glfw 初始化失败!");
return;
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);//设置不使用OpenGL
//glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);//设置窗口禁止修改大小
_imp->_monitor = glfwGetPrimaryMonitor();
log(fmt::format("当前显示器:{}", glfwGetMonitorName(_imp->_monitor)));
_imp->_window = glfwCreateWindow((int)800, (int)600,
"dltest", nullptr, nullptr);
if (!_imp->_window)
{
log("窗口创建失败!");
return;
}
//SetWindowCenter();
//按键依赖于glfw窗口句柄
//g_input = new Input;
//设置大小变化回调
glfwSetFramebufferSizeCallback(_imp->_window, CallbackFrameBufferResize);
//设置按键回调
glfwSetKeyCallback(_imp->_window, CallbackKey);
//设置输入回调
glfwSetCharCallback(_imp->_window, CallbackChar);
//设置光标位置回调
glfwSetCursorPosCallback(_imp->_window, CallbackCursorPos);
//设置鼠标按键回调
glfwSetMouseButtonCallback(_imp->_window, CallbackMouseButton);
//------------------创建VK------------------------
//g_vk = new VK(_imp->_window);
//g_factory->_init_path();
//g_factory->_init_defualt_res();
//g_audio->_init_path();
//g_ui->_resize(param._size);//初始化ui大小
//if (_funcInit) _funcInit();//初始化函数
//g_factory->_save_cache();
//g_vk->InitSecond();//依赖用户加载的资源
//-----------------游戏循环-----------------------
while (!glfwWindowShouldClose(_imp->_window))
{
//g_input->_update();//覆盖旧状态
glfwPollEvents();
//g_physics->Update();//计算物理
//g_ui->_run(LogicType::UPDATE);
//if (_funcRun) _funcRun();//帧函数
//g_ui->_run(LogicType::RENDER);
//-----------------vk------------------
//vector<VK::DrawCall> list_dc;
//vector<VK::DrawCall> list_dc_translucent;
//g_vk->Update(list_dc, list_dc_translucent);
//g_vk->Render(_imp->_window, list_dc, list_dc_translucent);
////
//g_time->_update();//计时
}
//----------------资源释放------------------------
//g_vk->Release();
//Imp::DeleteEngine();
glfwDestroyWindow(_imp->_window);
glfwTerminate();
}
}