Trim main task queue, recording label, and canvas draw callbacks
This commit is contained in:
65
src/main.cpp
65
src/main.cpp
@@ -54,8 +54,6 @@ struct RetainedState
|
||||
std::map<kKey, int> vkey_map;
|
||||
wchar_t window_title[512]{};
|
||||
std::jthread hmd_renderer;
|
||||
std::deque<std::packaged_task<void()>> main_tasklist;
|
||||
std::mutex main_task_mutex;
|
||||
float timer_stylus = 0;
|
||||
float timer_ink_touch = 0;
|
||||
float timer_ink_pen = 0;
|
||||
@@ -72,6 +70,46 @@ RetainedState& retained_state()
|
||||
return state;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct RetainedMainTaskQueue final
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> tasklist;
|
||||
std::mutex task_mutex;
|
||||
};
|
||||
|
||||
RetainedMainTaskQueue& retained_main_task_queue()
|
||||
{
|
||||
static RetainedMainTaskQueue queue;
|
||||
return queue;
|
||||
}
|
||||
|
||||
template <typename Callable>
|
||||
void enqueue_main_task(Callable&& task)
|
||||
{
|
||||
auto& queue = retained_main_task_queue();
|
||||
std::lock_guard<std::mutex> lock(queue.task_mutex);
|
||||
queue.tasklist.emplace_back(std::forward<Callable>(task));
|
||||
}
|
||||
|
||||
void drain_main_tasks()
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
{
|
||||
auto& queue = retained_main_task_queue();
|
||||
std::lock_guard<std::mutex> lock(queue.task_mutex);
|
||||
working_list = std::move(queue.tasklist);
|
||||
}
|
||||
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::atomic<int> vr_frames{0};
|
||||
std::atomic<int> running{-1};
|
||||
std::atomic_bool vr_running{false};
|
||||
@@ -163,8 +201,7 @@ std::string GetLastErrorAsString()
|
||||
void destroy_window()
|
||||
{
|
||||
auto& state = retained_state();
|
||||
std::lock_guard<std::mutex> lock(state.main_task_mutex);
|
||||
state.main_tasklist.emplace_back([hWnd = state.hWnd] {
|
||||
enqueue_main_task([hWnd = state.hWnd] {
|
||||
PostMessage(hWnd, WM_USER_CLOSE, 0, 0);
|
||||
});
|
||||
}
|
||||
@@ -225,8 +262,7 @@ void win32_update_fps(int frames)
|
||||
swprintf_s(title_fps, L"%s - %d fps", state.window_title, frames);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state.main_task_mutex);
|
||||
state.main_tasklist.emplace_back([hWnd = state.hWnd] {
|
||||
enqueue_main_task([hWnd = state.hWnd] {
|
||||
SetWindowText(hWnd, title_fps);
|
||||
});
|
||||
}
|
||||
@@ -991,22 +1027,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
// list of tasks for the main thread
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state.main_task_mutex);
|
||||
working_list = std::move(state.main_tasklist);
|
||||
}
|
||||
|
||||
if (!working_list.empty())
|
||||
{
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
}
|
||||
}
|
||||
drain_main_tasks();
|
||||
}
|
||||
// Clean up
|
||||
WacomTablet::I.terminate();
|
||||
|
||||
Reference in New Issue
Block a user