Skip to content

Commit

Permalink
Move imgui logic into UEngine::Tick if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 22, 2023
1 parent 2809c4b commit 275dc71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,15 @@ Framework::~Framework() {

m_terminating = true;
m_d3d_monitor_thread->request_stop();
m_command_thread->request_stop();
if (m_d3d_monitor_thread->joinable()) {
m_d3d_monitor_thread->join();
}

if (m_command_thread->joinable()) {
m_command_thread->join();
}

if (m_is_d3d11) {
deinit_d3d11();
}
Expand Down Expand Up @@ -470,7 +475,9 @@ void Framework::on_frame_d3d11() {

ImGui_ImplDX11_NewFrame();
// hooks don't run until after initialization, so we just render the imgui window while initalizing.
run_imgui_frame(false);
if (!m_has_engine_thread) {
run_imgui_frame(false);
}
/* } else {
return;
}
Expand Down Expand Up @@ -573,7 +580,9 @@ void Framework::on_frame_d3d12() {
invalidate_device_objects();
ImGui_ImplDX12_NewFrame();
// hooks don't run until after initialization, so we just render the imgui window while initalizing.
run_imgui_frame(false);
if (!m_has_engine_thread) {
run_imgui_frame(false);
}
/* } else {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ class Framework {
return m_uevr_shared_memory;
}

void enable_engine_thread() {
m_has_engine_thread = true;
}

private:
void consume_input();
void update_fonts();
Expand Down Expand Up @@ -278,6 +282,7 @@ class Framework {

bool m_sent_message{false};
bool m_message_hook_requested{false};
bool m_has_engine_thread{false};

RendererType m_renderer_type{RendererType::D3D11};

Expand Down
4 changes: 4 additions & 0 deletions src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ void FFakeStereoRenderingHook::attempt_hook_game_engine_tick(uintptr_t return_ad
}
}

// TODO: move this to a better place
m_tick_hook = safetyhook::create_inline((void*)*func, +[](sdk::UGameEngine* engine, float delta, bool idle) -> void* {
ZoneScopedN("UGameEngine::Tick Hook");
FrameMarkStart("UGameEngine::Tick");
Expand Down Expand Up @@ -270,6 +271,9 @@ void FFakeStereoRenderingHook::attempt_hook_game_engine_tick(uintptr_t return_ad
hook->m_ignore_next_engine_tick = false;
return nullptr;
}

g_framework->enable_engine_thread();
g_framework->run_imgui_frame(false);

delta += hook->m_ignored_engine_delta;
hook->m_ignored_engine_delta = 0.0f;
Expand Down

0 comments on commit 275dc71

Please sign in to comment.