FCT
载入中...
搜索中...
未找到
GLFW_UICommon.cpp
浏览该文件的文档.
1//
2// Created by Administrator on 2025/3/22.
3//
4#include "../FCTAPI.h"
5namespace FCT
6{
8 {
9 m_running = true;
10 bool inited = false;
11 m_uiThread = std::thread([this,&inited]()
12 {
13 m_uiThreadId = std::this_thread::get_id();
14 glfwInit();
15 glfwSwapInterval(0);
16 inited = true;
17 uint8_t count = 0;
18 while (m_running)
19 {
20 count = 0;
21 while (!m_taskQueue.empty() && m_running && count < 10) {
22 UITaskTrans trans;
23 m_taskQueue.pop(trans);
24 UiTaskData* task = trans.data;
25 task->task(task->param);
26 *task->waiting = false;
27 delete task;
28 count++;
29 }
30 for (auto it : m_ticker)
31 {
32 it.second.operator()();
33 }
34 glfwPollEvents();
35 }
36 glfwTerminate();
37 });
38 while (!inited)
39 std::this_thread::sleep_for(std::chrono::milliseconds(1));
40 }
41
43 {
44 m_running = false;
45 m_uiThread.join();
46 }
47
48 void GLFW_UICommon::postUiTask(UITaskFunction task, void* param, bool waited)
49 {
50 UiTaskData* data = new UiTaskData();
51 std::shared_ptr<bool> waiting = std::make_shared<bool>(waited);
52 data->task = task;
53 data->param = param;
54 data->waiting = waiting;
55 m_taskQueue.push(UITaskTrans(data));
56 while (*waiting) {
57 std::this_thread::sleep_for(std::chrono::milliseconds(0));
58 }
59 }
60
61}
void postUiTask(UITaskFunction task, void *param=nullptr, bool waited=true)
std::unordered_map< uint32_t, UiTicker > m_ticker
boost::lockfree::queue< UITaskTrans, boost::lockfree::capacity< 1024 > > m_taskQueue
std::thread::id m_uiThreadId
std::function< void(void *)> UITaskFunction
std::shared_ptr< bool > waiting